Conversation
Media RankerWhat We're Looking For
|
CheezItMan
left a comment
There was a problem hiding this comment.
Not bad, not perfect, but mostly working. Things to improve: Testing in all categories. Some things seem broken on Heroku.
|
|
||
| it "should get logout" do | ||
| post logout_path | ||
| must_respond_with :success |
There was a problem hiding this comment.
This test is failing: Logout should respond with :redirect
You should also test the flash notices.
| get login_path | ||
| must_respond_with :success | ||
| end | ||
|
|
There was a problem hiding this comment.
You're missing a test for submitting the login form.
| let(:user) { users(:one) } | ||
|
|
||
| describe 'validations' do | ||
| it 'is valid when all fields are present' do |
There was a problem hiding this comment.
You should also be testing the reasons the validations fail.
| end | ||
| end | ||
|
|
||
| describe 'has_voted?' do |
| expect(result).must_equal true | ||
| end | ||
|
|
||
| it 'requires user_id' do |
There was a problem hiding this comment.
These validations come with the relationships.
You should however have a validation to ensure that the combination of user_id and work_id is unique.
| @@ -0,0 +1,79 @@ | |||
| class WorksController < ApplicationController | |||
| before_action :find_work, only: [:show, :edit, :update, :destroy, :upvote] | |||
| end | ||
|
|
||
| def update | ||
| if @work.update(work_params) |
There was a problem hiding this comment.
You should also check to see if @work.nil just to see if it found that work.
| def upvote | ||
| if @super_user.nil? | ||
| flash[:warning] = "Please log in so your vote can be counted." | ||
| redirect_to login_path |
There was a problem hiding this comment.
For some reason Heroku is crashing here, not sure why. I would also suggest using redirect_back, but I'm not sure why.
| post 'works/:id/upvote', to: 'works#upvote', as: 'upvote' | ||
| resources :works | ||
|
|
||
| resources :users, only: [:index, :show] |
| flash[:warning] = "Sorry, you can't vote twice on the same work." | ||
| redirect_back fallback_location: works_path | ||
| else | ||
| Vote.create(user_id: @super_user.id, work_id: @work.id) |
There was a problem hiding this comment.
This is failing because it's complaining about can't write unknown attribute vote_count``
Media Ranker
Congratulations! You're submitting your assignment!
Comprehension Questions
sessionandflash? What is the difference between them?