Conversation
…egory.......... validations?
Votes and users
Media RankerWhat We're Looking For
|
| get 'users/create' | ||
| get 'users/new' | ||
| get 'users/show' | ||
| get 'users/destroy' |
There was a problem hiding this comment.
I don't think you need all these routes for users - only index and show are needed for this project.
| <% @album.each do |work| %> | ||
| <tr> | ||
| <td><%=work.votes.length%></td> | ||
| <td><%= link_to "#{work.title}", work_path(work.id) %></td><td> |
There was a problem hiding this comment.
You have the same code to show a list of works repeated 3 times. Could you use a view partial or a loop to DRY this up?
| @@ -0,0 +1,6 @@ | |||
| class Vote < ApplicationRecord | |||
| validates :user, uniqueness: { scope: :user_id, | |||
| message: "should happen once per user" } | |||
There was a problem hiding this comment.
I think you misinterpreted the request we had. We wanted person to be able to vote for more than one work, but we didn't want users to be able to vote for a single work more than once.
Put another way, if I upvote DAMN by Kendrick Lamar, I can still upvote Titanic, but I can't vote for DAMN again.
| @@ -0,0 +1,8 @@ | |||
| class Work < ApplicationRecord | |||
| has_many :votes | |||
| CATEGORIES = %w(album book movie) | |||
There was a problem hiding this comment.
Nice job with this, you can actually leverage this EVEN MORE! Think about what this gives you on your works/index page!
|
|
||
| it "must be valid" do | ||
| value(vote).must_be :valid? | ||
| end |
There was a problem hiding this comment.
You should be testing the uniqueness constraint here! Specific test cases I'd want to see:
- A user can have votes for two different works
- A work can have votes from two different users
- A user cannot vote for the same work twice
| expect(work).must_equal :valid? | ||
| end | ||
| end | ||
|
|
There was a problem hiding this comment.
This is where I would expect tests for the code that picks your top 10 works to live.
For implementing those I would wonder:
- What happens if there are no works?
- What happens if there are works but no votes?
- What happens if two works have the same number of votes?
Similarly for you category and top ten methods, I would ask:
- What if there are no works of that category?
- What if there are less than 10 works?
- What if there's a tie for last place, e.g. works 9, 10 and 11 all have 0 votes?
Media Ranker
Congratulations! You're submitting your assignment!
Comprehension Questions
sessionandflash? What is the difference between them?