-
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?
Conversation
add author column to article db display author on article show page validate and sanitze author params
add validation for author add tests for associations
add author ref to article fix author tests
add author ref to article fix author tests
rspec all green
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.
You have to rethink the entire approach to this
@@ -8,7 +8,7 @@ def create | |||
@article = Article.new(article_params) | |||
if @article.save | |||
flash[:success] = "Article was successfully created." | |||
redirect_to @article | |||
redirect_to article_path(@article) |
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
app/models/author.rb
Outdated
validates :author, presence: true | ||
|
||
has_many :articles | ||
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 create an Author class. User can do
app/views/articles/new.html.haml
Outdated
@@ -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 comment
The 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 comment
The 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?
app/views/articles/show.html.haml
Outdated
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
If it is authors then use plural form
@@ -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 comment
The 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
spec/models/article_spec.rb
Outdated
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Have many
change unnecessary code
make correct assocations between user and articles
add user logged in to create article tests
all tests green
take out show page from tests
add optional user assocation with article
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.
... Try to be a bit descriptive with your PR titles. When you say Author
? what about it? 🤔
spec/models/article_spec.rb
Outdated
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 :user } |
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.
Prefer expect
syntax over should
spec/models/user_spec.rb
Outdated
@@ -11,4 +11,8 @@ | |||
expect(create(:user)).to be_valid | |||
end | |||
end | |||
|
|||
describe 'Associations' do | |||
it { should have_many :articles } |
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.
Prefer expect
syntax over should
edit rspec syntax to is expected add author feature test
spec/models/article_spec.rb
Outdated
@@ -8,12 +8,16 @@ | |||
|
|||
describe 'Factory' do | |||
it 'should have valid Factory' do | |||
expect(create(:article)).to be_valid | |||
expect(create(:user)).to be_valid |
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.
This should be article. You are testing the article factory :)
If you are getting an error maybe you forgot to add user to the factory?
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.
Looked at the article factory and it's missing the user. :) See comment above.
spec/models/article_spec.rb
Outdated
@@ -8,12 +8,16 @@ | |||
|
|||
describe 'Factory' do | |||
it 'should have valid Factory' do | |||
expect(create(:article)).to be_valid | |||
expect(create(:user)).to be_valid |
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.
Looked at the article factory and it's missing the user. :) See comment above.
PT Story: https://www.pivotaltracker.com/story/show/155970828
Description
Changes proposed in this pull request:
What I have learned working on this feature: