Conversation
…und color to yellow
Media RankerWhat We're Looking For
|
| expect(albums[1].votes.length).must_equal 1 | ||
| end | ||
|
|
||
| it "returns at most 10 items" do |
| expect(Work.spotlight.votes.length).must_equal 1 | ||
|
|
||
| aj.works << harry2 | ||
| kim.works << harry2 |
There was a problem hiding this comment.
I'm not sure what this line is accomplishing.
| @@ -0,0 +1,9 @@ | |||
| require "test_helper" | |||
|
|
|||
| describe Vote do | |||
There was a problem hiding this comment.
You really should have a test that ensures that the combination of User and Work is unique, so that the same user can't vote on the same work.
| validates :creator, presence: true | ||
|
|
||
| def self.top_ten(category) | ||
| top_works = self.top_voted(category) |
There was a problem hiding this comment.
This is a good use of one method in another
| def self.spotlight | ||
| works = self.all | ||
|
|
||
| spotlight = works.sort_by { |work| work.votes.length } |
There was a problem hiding this comment.
Just a note, this works, but it's more efficient to use the database to sort them, using .order
| end | ||
|
|
||
| def update | ||
| work = Work.find_by(id: params[:id]) |
There was a problem hiding this comment.
What about if you don't find the work?
| @work = Work.find_by(id: params[:work_id]) | ||
| @user = User.find_by(id: session[:user_id]) | ||
|
|
||
| if !@user |
There was a problem hiding this comment.
This logic would be great as a model method. I suggest creating an upvote method in the Work model.
| "#{work_hash[:work][:category]}!" | ||
| end | ||
|
|
||
| it "will return a bad request when asked to update with invalid data" do |
There was a problem hiding this comment.
You also need a test with an invalid work_id
| describe VotesController do | ||
| let(:work) { works(:harry_one) } | ||
|
|
||
| describe "create" do |
| Rails.application.routes.draw do | ||
| root to: "homepages#index" | ||
|
|
||
| resources :works do |
Media Ranker
Congratulations! You're submitting your assignment!
Comprehension Questions
sessionandflash? What is the difference between them?