Guest User

Untitled

a guest
May 23rd, 2018
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. describe 'trying to update attributes on an invalid user' do
  2. before(:each) do
  3. @zz_user = mock_basic_user
  4.  
  5. User.stub!(:authenticate).and_return(@zz_user)
  6. @current_user.stub!(:merge_facebook_game_data).and_return(true)
  7. @zz_user.stub!(:update_attributes!).and_raise(ActiveRecord::RecordInvalid)
  8. end
  9.  
  10. def act!
  11. facebook_post :merge_facebook_user_with_zazengo_user,
  12. :user => {:username => 'test', :password => 'password'}
  13. end
  14.  
  15. it_should_facebook_redirect_to { new_user_url }
  16.  
  17. it 'should call authenticate on User' do
  18. User.should_receive(:authenticate).with('test', 'password').and_return(@zz_user)
  19. act!
  20. end
  21.  
  22. it 'should merge facebook game data to the existing zazengo user' do
  23. @current_user.should_receive(:merge_facebook_game_data).with(@zz_user.id).and_return(true)
  24. act!
  25. end
  26.  
  27. it 'should destroy the user that was originally associated with the facebook_id' do
  28. @current_user.should_receive(:destroy).once.and_return(@current_user)
  29. act!
  30. end
  31.  
  32. it 'should raise an error when trying to update the attributes' do
  33. @zz_user.should_receive(:update_attributes!).with(:facebook_id => @current_user.facebook_id, :session_key => @current_user.session_key).and_raise(ActiveRecord::RecordInvalid)
  34. act!
  35. end
  36.  
  37. it 'should set a flash error message' do
  38. act!
  39. flash[:error].should eql("There was a problem merging your account.")
  40. end
  41. end
  42. end
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51. def merge_facebook_user_with_zazengo_user
  52. begin
  53. unless params[:user].nil?
  54. zz_user = User.authenticate(params[:user][:username], params[:user][:password])
  55. else
  56. raise LoginError
  57. end
  58.  
  59. User.transaction do
  60. @current_user.merge_facebook_game_data(zz_user.id)
  61. facebook_id = @current_user.facebook_id
  62. session_key = @current_user.session_key
  63. @current_user.destroy
  64. zz_user.update_attributes!(:facebook_id => facebook_id, :session_key => session_key)
  65. end
  66.  
  67. redirect_to facebook_user_url(@facebook_user)
  68.  
  69. rescue ActiveRecord::RecordInvalid
  70. flash[:error] = "There was a problem merging your account."
  71. redirect_to new_user_url
  72. rescue LoginError
  73. flash[:error] = "Username and password are incorrect."
  74. redirect_to new_user_url
  75. end
  76. end
Add Comment
Please, Sign In to add comment