You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
2.0 KiB

  1. require 'rails_helper'
  2. describe Settings::MigrationsController do
  3. render_views
  4. shared_examples 'authenticate user' do
  5. it 'redirects to sign_in page' do
  6. is_expected.to redirect_to new_user_session_path
  7. end
  8. end
  9. describe 'GET #show' do
  10. context 'when user is not sign in' do
  11. subject { get :show }
  12. it_behaves_like 'authenticate user'
  13. end
  14. context 'when user is sign in' do
  15. subject { get :show }
  16. let(:user) { Fabricate(:user, account: account) }
  17. let(:account) { Fabricate(:account, moved_to_account: moved_to_account) }
  18. before { sign_in user, scope: :user }
  19. context 'when user does not have moved to account' do
  20. let(:moved_to_account) { nil }
  21. it 'renders show page' do
  22. is_expected.to have_http_status 200
  23. is_expected.to render_template :show
  24. end
  25. end
  26. context 'when user does not have moved to account' do
  27. let(:moved_to_account) { Fabricate(:account) }
  28. it 'renders show page' do
  29. is_expected.to have_http_status 200
  30. is_expected.to render_template :show
  31. end
  32. end
  33. end
  34. end
  35. describe 'PUT #update' do
  36. context 'when user is not sign in' do
  37. subject { put :update }
  38. it_behaves_like 'authenticate user'
  39. end
  40. context 'when user is sign in' do
  41. subject { put :update, params: { migration: { acct: acct } } }
  42. let(:user) { Fabricate(:user) }
  43. before { sign_in user, scope: :user }
  44. context 'when migration account is changed' do
  45. let(:acct) { Fabricate(:account) }
  46. it 'updates moved to account' do
  47. is_expected.to redirect_to settings_migration_path
  48. expect(user.account.reload.moved_to_account_id).to eq acct.id
  49. end
  50. end
  51. context 'when acct is a current account' do
  52. let(:acct) { user.account }
  53. it 'renders show' do
  54. is_expected.to render_template :show
  55. end
  56. end
  57. end
  58. end
  59. end