Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- describe 'trying to update attributes on an invalid user' do
- before(:each) do
- @zz_user = mock_basic_user
- User.stub!(:authenticate).and_return(@zz_user)
- @current_user.stub!(:merge_facebook_game_data).and_return(true)
- @zz_user.stub!(:update_attributes!).and_raise(ActiveRecord::RecordInvalid)
- end
- def act!
- facebook_post :merge_facebook_user_with_zazengo_user,
- :user => {:username => 'test', :password => 'password'}
- end
- it_should_facebook_redirect_to { new_user_url }
- it 'should call authenticate on User' do
- User.should_receive(:authenticate).with('test', 'password').and_return(@zz_user)
- act!
- end
- it 'should merge facebook game data to the existing zazengo user' do
- @current_user.should_receive(:merge_facebook_game_data).with(@zz_user.id).and_return(true)
- act!
- end
- it 'should destroy the user that was originally associated with the facebook_id' do
- @current_user.should_receive(:destroy).once.and_return(@current_user)
- act!
- end
- it 'should raise an error when trying to update the attributes' do
- @zz_user.should_receive(:update_attributes!).with(:facebook_id => @current_user.facebook_id, :session_key => @current_user.session_key).and_raise(ActiveRecord::RecordInvalid)
- act!
- end
- it 'should set a flash error message' do
- act!
- flash[:error].should eql("There was a problem merging your account.")
- end
- end
- end
- def merge_facebook_user_with_zazengo_user
- begin
- unless params[:user].nil?
- zz_user = User.authenticate(params[:user][:username], params[:user][:password])
- else
- raise LoginError
- end
- User.transaction do
- @current_user.merge_facebook_game_data(zz_user.id)
- facebook_id = @current_user.facebook_id
- session_key = @current_user.session_key
- @current_user.destroy
- zz_user.update_attributes!(:facebook_id => facebook_id, :session_key => session_key)
- end
- redirect_to facebook_user_url(@facebook_user)
- rescue ActiveRecord::RecordInvalid
- flash[:error] = "There was a problem merging your account."
- redirect_to new_user_url
- rescue LoginError
- flash[:error] = "Username and password are incorrect."
- redirect_to new_user_url
- end
- end
Add Comment
Please, Sign In to add comment