-
Notifications
You must be signed in to change notification settings - Fork 47
Ports - Ngoc #43
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
base: master
Are you sure you want to change the base?
Ports - Ngoc #43
Conversation
…controller test file
Media RankerWhat We're Looking For
|
| album.destroy | ||
|
|
||
| # Act | ||
| get work_path(invalid_album_id) |
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 test is failing
app/controllers/works_controller.rb
Outdated
| end | ||
|
|
||
| def show | ||
| @votes = @work.votes.order(created_at: :desc) |
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 need to check to see if you could not find @work.
| require "test_helper" | ||
|
|
||
| describe VotesController do | ||
| before do |
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 use of a before block
| post work_votes_path(@work.id) | ||
| }.must_change "Vote.count", 1 | ||
|
|
||
| expect(flash[:success]).must_equal "Successfully upvoted!" |
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 also test redirection
| expect(album_to_update.creator).must_equal @input_creator | ||
| expect(album_to_update.publication_year).must_equal @input_publication_year | ||
| expect(album_to_update.description).must_equal @input_description | ||
| must_respond_with :redirect |
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 also test where they redirect to.
| @@ -0,0 +1,4 @@ | |||
| require "test_helper" | |||
|
|
|||
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.
no validations for votes? You could make one to require a unique combination of user-work.
| def self.find_most_voted | ||
| max_votes = 0 | ||
| most_voted = nil | ||
| Work.all.each do |work| |
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 could do this with .order or .sort_by instead
| let(:books) { Work.where(category: "book") } | ||
|
|
||
| it "should return a list of works that belong to book category" do | ||
| expect(Work.find_top_ten("book")).must_be_kind_of Array |
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 also verify that each element is a Work and is in the right category.
| end | ||
|
|
||
| it "should return an empty list if no books exist" do | ||
| books.each do |book| |
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.
There is also a destroy_all method.
| @@ -0,0 +1,30 @@ | |||
| class VotesController < ApplicationController | |||
| def create | |||
| if session[:user_id] | |||
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.
There's a lot of business logic here, I suggest moving some of it to the Work model so you could just call: work.upvote(user). You could also put the upvote method in the User model
Media Ranker
Congratulations! You're submitting your assignment!
Comprehension Questions
sessionandflash? What is the difference between them?