migrations_controller_spec.rb 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 has a 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 'POST #create' do
  36. context 'when user is not sign in' do
  37. subject { post :create }
  38. it_behaves_like 'authenticate user'
  39. end
  40. context 'when user is sign in' do
  41. subject { post :create, params: { account_migration: { acct: acct, current_password: '12345678' } } }
  42. let(:user) { Fabricate(:user, password: '12345678') }
  43. before { sign_in user, scope: :user }
  44. context 'when migration account is changed' do
  45. let(:acct) { Fabricate(:account, also_known_as: [ActivityPub::TagManager.instance.uri_for(user.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