migrations_controller_spec.rb 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 signed 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 the current account' do
  52. let(:acct) { user.account }
  53. it 'renders show' do
  54. is_expected.to render_template :show
  55. end
  56. it 'does not update the moved account' do
  57. expect(user.account.reload.moved_to_account_id).to be_nil
  58. end
  59. end
  60. context 'when target account does not reference the account being moved from' do
  61. let(:acct) { Fabricate(:account, also_known_as: []) }
  62. it 'renders show' do
  63. is_expected.to render_template :show
  64. end
  65. it 'does not update the moved account' do
  66. expect(user.account.reload.moved_to_account_id).to be_nil
  67. end
  68. end
  69. context 'when a recent migration already exists ' do
  70. let(:acct) { Fabricate(:account, also_known_as: [ActivityPub::TagManager.instance.uri_for(user.account)]) }
  71. before do
  72. moved_to = Fabricate(:account, also_known_as: [ActivityPub::TagManager.instance.uri_for(user.account)])
  73. user.account.migrations.create!(acct: moved_to.acct)
  74. end
  75. it 'renders show' do
  76. is_expected.to render_template :show
  77. end
  78. it 'does not update the moved account' do
  79. expect(user.account.reload.moved_to_account_id).to be_nil
  80. end
  81. end
  82. end
  83. end
  84. end