Guest User

Untitled

a guest
Jun 19th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. class RatingsController < ApplicationController
  2. before_filter :require_user_json
  3.  
  4. def create
  5. @rating = Rating.new(:rating => params[:rating])
  6. @rating.user = current_user
  7. @rating.album = Album.find(params[:id])
  8. @rating.save!
  9.  
  10. render :json => {}.to_json
  11. end
  12. end
  13.  
  14. describe RatingsController
  15. before(:all) do
  16. @valid_user = User.make(:login => 'ratings_user')
  17. end
  18.  
  19. after(:all) do
  20. @valid_user.destroy
  21. end
  22.  
  23. describe "create" do
  24. it "should create a rating if you don't already have one" do
  25. activate_authlogic
  26. UserSession.create(@valid_user)
  27.  
  28. album = mock_model(Album, :null_object => true)
  29. Album.should_receive(:find).with('1').and_return(album)
  30.  
  31. xhr :post,
  32. :create,
  33. :id => 1,
  34. :rating => 5
  35.  
  36. assigns[:rating].should be_valid
  37. response.code.should == '200'
  38. end
  39. end
  40. end
Add Comment
Please, Sign In to add comment