Open
Conversation
…controller test file
Media RankerWhat We're Looking For
|
CheezItMan
reviewed
May 3, 2019
| album.destroy | ||
|
|
||
| # Act | ||
| get work_path(invalid_album_id) |
| end | ||
|
|
||
| def show | ||
| @votes = @work.votes.order(created_at: :desc) |
There was a problem hiding this comment.
You need to check to see if you could not find @work.
| require "test_helper" | ||
|
|
||
| describe VotesController do | ||
| before do |
| post work_votes_path(@work.id) | ||
| }.must_change "Vote.count", 1 | ||
|
|
||
| expect(flash[:success]).must_equal "Successfully upvoted!" |
| 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.
You should also test where they redirect to.
| @@ -0,0 +1,4 @@ | |||
| require "test_helper" | |||
|
|
|||
There was a problem hiding this comment.
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.
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.
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| |
| @@ -0,0 +1,30 @@ | |||
| class VotesController < ApplicationController | |||
| def create | |||
| if session[:user_id] | |||
There was a problem hiding this comment.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Media Ranker
Congratulations! You're submitting your assignment!
Comprehension Questions
sessionandflash? What is the difference between them?