-
Notifications
You must be signed in to change notification settings - Fork 47
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
Time - Emily #46
base: master
Are you sure you want to change the base?
Time - Emily #46
Conversation
…s have yet to be made functional.
…em valid input test is now failing.
Create works
Media RankerFunctional Requirements: Manual Testing
Major Learning Goals/Code Review
Previous Rails learning, Building Complex Model Logic, DRYing up Rails Code
Testing Rails Apps
Overall Feedback
Code Style Bonus AwardsWas the code particularly impressive in code style for any of these reasons (or more...?)
SummaryYou got the basic functionality completed Emily. See my comments in your code below. From this I think you need more practice with testing including fixtures, custom methods and controller tests. You also need more practice writing flash notices and styling. That said you have the relationships working and you have some custom validations and business logic methods. I'm glad you got this in and if you push any further commits and want my feedback just ping me in slack. |
|
||
describe 'validations' do | ||
before do | ||
@vote = Vote.new(user_id: 1, work_id: 1) |
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 won't work because you can't guarantee that the test database will have a user and work with id 1.
Either:
- Create fixtures for your test database and use them or
- Do something like this
@vote = Vote.new(user_id: 1, work_id: 1) | |
@user = User.create(username: 'bob'); | |
@user = User.create(username: 'bob'); | |
@work = Work.create(category: 'book', title: 'Wizard of Oz', creator: 'Someone', publication_year: "1920", description: 'a book about a girl who got hit on the head') | |
@vote = Vote.new(user_id: @user.id, work_id: @work.id) |
expect(result).must_equal true | ||
end | ||
|
||
it 'is invalid without a category' do |
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.
Just a note, that you can loop through the required fields, you don't have to make a test for each one.
required_fields = [:category, :title, :creator, :publication_year]
required_fields.each do |field|
old_value = @work[field]
@work[field] = nil
expect(@work.valid?).must_equal false
@work[field] = old_value
end
end | ||
end | ||
|
||
describe 'work model methods' do |
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.
Just noting these aren't done yet.
end | ||
end | ||
|
||
# describe 'relations' do |
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.
Just noting these are missing.
validates :user_id, presence: true | ||
validates :work_id, presence: 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 don't need to have these, the relationships require them anyway.
However you do need a validation to prevent a duplicate combination user_id and work_id.
validates :user_id, presence: true | |
validates :work_id, presence: true | |
# Requires every combination work_id and user_id to be unique. | |
validates :user_id, uniqueness: {scope: :work_id} |
@work = Work.find_by(id: params[:id]) | ||
|
||
if @work.nil? | ||
head :not_found |
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.
head :not_found | |
flash[:notice] = "Work not found" | |
redirect_to root_path |
head :not_found | ||
return | ||
elsif @work.update(work_params) | ||
redirect_to work_path(@work.id) |
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 suggest adding a flash notice here.
end | ||
end | ||
|
||
def destroy |
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.
Flash notices would be good here.
<header> | ||
<div><h2 class="nav justify-content-center">Media Ranker | Ranking the Best of Everything</h2></div> | ||
</header> | ||
|
||
<ul class="nav justify-content-center"> | ||
<li class="nav-item"> | ||
<a><%= link_to "Top Media", root_path %> |</a> | ||
</li> | ||
<li class="nav-item"> | ||
<a><%= link_to "View all Media", works_path %> |</a> | ||
</li> | ||
<li class="nav-item"> | ||
<a><%= link_to "Add a New Work", new_work_path %> |</a> | ||
</li> | ||
<li class="nav-item"> | ||
<a><%= link_to "View All Users", users_path %> |</a> | ||
</li> | ||
<% if session[:user_id] == nil %> | ||
<li class="nav-item"> | ||
<a><%= link_to "Log In |", login_path %></a> | ||
</li> | ||
<% else %> | ||
<li class="nav-item"> | ||
<a>Logged in as: <%= User.find_by(id: session[:user_id]).username %> |</a> | ||
</li> | ||
<% end %> | ||
<% if session[:user_id] %> | ||
<li class="nav-item"> | ||
<a><%= link_to "Log Out", logout_path, method: :post%></a> | ||
</li> | ||
<% end %> | ||
</ul> |
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 content should be in the body
tag to be proper HTML.
@@ -0,0 +1,36 @@ | |||
<body> |
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.
The body tag is in the layout file and there should only be one body in the HTML document.
Perhaps you meant main
Media Ranker
Congratulations! You're submitting your assignment!
Comprehension Questions
session
andflash
? What is the difference between them?My model tests are not currently complete. I'll be updating my PR with the completed tests this evening. Thanks :)