Advertisement
Guest User

Untitled

a guest
Apr 18th, 2015
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. require 'rails_helper'
  2. require 'authenticate_helper'
  3.  
  4. describe Api::V1::UsersController do
  5. before { authenticate_user! }
  6.  
  7. describe '#update_user' do
  8. let(:user_role) { user.user_roles.build }
  9. let(:user_params) { user.as_json }
  10. let(:current_user) { double 'current_user', admin?: admin? }
  11. before { allow(controller).to receive(:response).and_return response }
  12. before { allow(controller).to receive(:user_params).and_return user_params }
  13. before { allow(controller).to receive(:user_params_with_company).and_return user_params }
  14. before { allow(controller).to receive(:user_roles).and_return [user_role] }
  15. before { allow(controller).to receive(:current_user).and_return current_user }
  16.  
  17. context 'admin' do
  18. let(:user) { build :user }
  19. let(:admin?) { true }
  20.  
  21. it 'updates user without password validation' do
  22. expect(controller).to receive(:user).exactly(4).times.and_return user
  23. expect(user).to receive(:skip_password=).with true
  24. expect(user).to receive(:update!).with user_params
  25. end
  26.  
  27. end
  28.  
  29. context 'user' do
  30. let(:user) { build :user }
  31. let(:admin?) { false }
  32.  
  33. it 'updates user with password validation' do
  34. expect(controller).to receive(:user).exactly(3).times.and_return user
  35. expect(user).not_to receive :skip_password=
  36. expect(user).to receive(:update!).and_return user_params
  37. end
  38. end
  39.  
  40. after { controller.send :update_user }
  41. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement