-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Author to Article Show Page #19
base: develop
Are you sure you want to change the base?
Changes from 6 commits
823c6d8
899d977
4115a2d
4242955
e9bdf75
43c3821
b4f7f63
adf0782
88cf87c
77ec4b5
c3d613e
dd938b9
ae54e9f
1df15f3
d44b104
9dc83cf
8943240
92d36d6
9d66c96
7ac0835
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
class Article < ApplicationRecord | ||
validates :title, :content, presence: true | ||
validates :title, :content, :author, presence: true | ||
|
||
belongs_to :author | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class Author < ApplicationRecord | ||
validates :author, presence: true | ||
|
||
has_many :articles | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to create an Author class. User can do |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,10 @@ | |
= form.label :title | ||
%br/ | ||
= form.text_field :title, id: :article_title | ||
%p | ||
= form.label :author | ||
%br/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to add this field. Whoever’s logged in should be assigned as the author of the article. You can deal with it in the controller There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i thought that the requirements for the author part of the assignment was to be able to assign multiple authors to a piece. Would using an author form field be a bad way approaching this? |
||
= form.text_field :author, id: :article_author | ||
%p | ||
= form.label :content | ||
%br/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
%p | ||
%strong Title: | ||
= @article.title | ||
%p | ||
%strong Authors: | ||
[email protected] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it is authors then use plural form |
||
%p | ||
%strong Text: | ||
= @article.content |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class CreateAuthor < ActiveRecord::Migration[5.2] | ||
def change | ||
create_table :authors do |t| | ||
t.string :author | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddAuthorRefToArticle < ActiveRecord::Migration[5.2] | ||
def change | ||
add_reference :articles, :author, foreign_key: true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You probably want to have a has_many relationship between Article and User |
||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
Warden.test_mode! | ||
World Warden::Test::Helpers | ||
After { Warden.test_reset! } | ||
After { Warden.test_reset! } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
FactoryBot.define do | ||
factory :author do | ||
author 'Man McMaster' | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,12 +8,16 @@ | |
|
||
describe 'Factory' do | ||
it 'should have valid Factory' do | ||
expect(create(:article)).to be_valid | ||
expect(create(:author)).to be_valid | ||
end | ||
end | ||
|
||
describe 'Validations' do | ||
it { is_expected.to validate_presence_of :title } | ||
it { is_expected.to validate_presence_of :content } | ||
end | ||
|
||
describe 'Associations' do | ||
it { should belong_to :author } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have many |
||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe Author, type: :model do | ||
describe 'Associations' do | ||
it { should have_many :articles} | ||
end | ||
|
||
describe 'Validations' do | ||
it { is_expected.to validate_presence_of :author } | ||
end | ||
|
||
describe 'Factory' do | ||
it 'should have valid Factory' do | ||
expect(create(:author)).to be_valid | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to make this change