migrations_controller_spec.rb 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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(:account, moved_to_account: moved_to_account).user }
  17. before { sign_in user, scope: :user }
  18. context 'when user does not have moved to account' do
  19. let(:moved_to_account) { nil }
  20. it 'renders show page' do
  21. is_expected.to have_http_status 200
  22. is_expected.to render_template :show
  23. end
  24. end
  25. context 'when user has a moved to account' do
  26. let(:moved_to_account) { Fabricate(:account) }
  27. it 'renders show page' do
  28. is_expected.to have_http_status 200
  29. is_expected.to render_template :show
  30. end
  31. end
  32. end
  33. end
  34. describe 'POST #create' do
  35. context 'when user is not sign in' do
  36. subject { post :create }
  37. it_behaves_like 'authenticate user'
  38. end
  39. context 'when user is signed in' do
  40. subject { post :create, params: { account_migration: { acct: acct, current_password: '12345678' } } }
  41. let(:user) { Fabricate(:user, password: '12345678') }
  42. before { sign_in user, scope: :user }
  43. context 'when migration account is changed' do
  44. let(:acct) { Fabricate(:account, also_known_as: [ActivityPub::TagManager.instance.uri_for(user.account)]) }
  45. it 'updates moved to account' do
  46. is_expected.to redirect_to settings_migration_path
  47. expect(user.account.reload.moved_to_account_id).to eq acct.id
  48. end
  49. end
  50. context 'when acct is the current account' do
  51. let(:acct) { user.account }
  52. it 'renders show' do
  53. is_expected.to render_template :show
  54. end
  55. it 'does not update the moved account' do
  56. expect(user.account.reload.moved_to_account_id).to be_nil
  57. end
  58. end
  59. context 'when target account does not reference the account being moved from' do
  60. let(:acct) { Fabricate(:account, also_known_as: []) }
  61. it 'renders show' do
  62. is_expected.to render_template :show
  63. end
  64. it 'does not update the moved account' do
  65. expect(user.account.reload.moved_to_account_id).to be_nil
  66. end
  67. end
  68. context 'when a recent migration already exists ' do
  69. let(:acct) { Fabricate(:account, also_known_as: [ActivityPub::TagManager.instance.uri_for(user.account)]) }
  70. before do
  71. moved_to = Fabricate(:account, also_known_as: [ActivityPub::TagManager.instance.uri_for(user.account)])
  72. user.account.migrations.create!(acct: moved_to.acct)
  73. end
  74. it 'renders show' do
  75. is_expected.to render_template :show
  76. end
  77. it 'does not update the moved account' do
  78. expect(user.account.reload.moved_to_account_id).to be_nil
  79. end
  80. end
  81. end
  82. end
  83. end