-
Notifications
You must be signed in to change notification settings - Fork 48
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
Laura MediaRanker #49
base: master
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
session
andflash
? What is the difference between them?