Conversation
Media RankerWhat We're Looking For
|
| root :to => "main#index" | ||
| post "works/:id/upvote", to: "works#upvote", as:"upvote" | ||
| resources :works | ||
| resources :users |
There was a problem hiding this comment.
You probably don't need the full resources :users here. Make sure to only generate routes you're planning to use.
|
|
||
| def self.top_n_in_category(category, count) | ||
| return Work.left_outer_joins(:votes).select('works.*, COUNT(votes.*) AS votes_count').group('works.id').where(category: category).order('votes_count desc').limit(count) | ||
| end |
There was a problem hiding this comment.
Good work figuring out these database operations.
| res = Work.top_n_in_category(:movie, 10) | ||
| res.must_include Work.find_by_title("Jurassic_Park") | ||
| res.size.must_equal 1 | ||
| end |
There was a problem hiding this comment.
I would also be interested to see:
- What happens if there are no works?
- What if there are more than n works?
| it "returns all works ordered by vote count" do | ||
| res = Work.all_with_vote_count | ||
| expected = [ | ||
| Work.find_by_title("Countdown to Ecstasy"), |
There was a problem hiding this comment.
This test ends up being very fragile - if your fixtures change, this test will probably break.
Instead of requiring specific works to be returned, you might check that the right number of works are there, and that each work has a vote count equal to or less than the vote before it.
|
|
||
| must_respond_with :not_found # Assert | ||
| Work.count.must_equal work_count | ||
| end |
There was a problem hiding this comment.
What if you try to destroy a work with associated votes? Does it work? What happens to the votes?
Media Ranker
Congratulations! You're submitting your assignment!
Comprehension Questions
sessionandflash? What is the difference between them?