Conversation
…es for works and users
Media RankerWhat We're Looking For
|
| Rails.application.routes.draw do | ||
| root "works#index" | ||
|
|
||
| resources :users |
There was a problem hiding this comment.
I don't think you need all 7 restful routes for users - only index and show are needed for this project.
| <% if cat_list.empty? %> | ||
| <h4>No <%=cat.pluralize%> have been added to the database.</h4> | ||
| <% else %> | ||
| <% cat_list.each do |item| %> |
There was a problem hiding this comment.
Nice work on this! very DRY and clean
| has_many :users, through: :votes | ||
|
|
||
| # validation | ||
| CATS = %w(album movie book) |
There was a problem hiding this comment.
Nice work here, this keeps your code very clean.
| get votes_create_url | ||
| value(response).must_be :success? | ||
| 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
| end | ||
|
|
||
| def self.spotlight? | ||
| spot = self.all.sample |
| # pub year must be number in year range 0 - 2018 | ||
| validates :publication_year, numericality: true, inclusion: 0..2018 | ||
|
|
||
| def self.top?(category) |
There was a problem hiding this comment.
the question mark here has a semantic meaning that you aren't using correctly. A question mark at the end of a method signature implies that it returns a boolean.
| delete work_url(work) | ||
| }.must_change "Work.count", -1 | ||
|
|
||
| must_redirect_to works_path |
There was a problem hiding this comment.
There's a lot of interesting test cases for your custom Work methods missing here. For top?, 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 your 'sample' method, 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?