migrations_controller_spec.rb 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe Settings::MigrationsController do
  4. render_views
  5. shared_examples 'authenticate user' do
  6. it 'redirects to sign_in page' do
  7. expect(subject).to redirect_to new_user_session_path
  8. end
  9. end
  10. describe 'GET #show' do
  11. context 'when user is not sign in' do
  12. subject { get :show }
  13. it_behaves_like 'authenticate user'
  14. end
  15. context 'when user is sign in' do
  16. subject { get :show }
  17. let(:user) { Fabricate(:account, moved_to_account: moved_to_account).user }
  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. expect(subject).to have_http_status 200
  23. expect(subject).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. expect(subject).to have_http_status 200
  30. expect(subject).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. expect(subject).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 'does not update the moved account', :aggregate_failures do
  54. subject
  55. expect(user.account.reload.moved_to_account_id).to be_nil
  56. expect(response).to render_template :show
  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 'does not update the moved account', :aggregate_failures do
  62. subject
  63. expect(user.account.reload.moved_to_account_id).to be_nil
  64. expect(response).to render_template :show
  65. end
  66. end
  67. context 'when a recent migration already exists' do
  68. let(:acct) { Fabricate(:account, also_known_as: [ActivityPub::TagManager.instance.uri_for(user.account)]) }
  69. before do
  70. moved_to = Fabricate(:account, also_known_as: [ActivityPub::TagManager.instance.uri_for(user.account)])
  71. user.account.migrations.create!(acct: moved_to.acct)
  72. end
  73. it 'does not update the moved account', :aggregate_failures do
  74. subject
  75. expect(user.account.reload.moved_to_account_id).to be_nil
  76. expect(response).to render_template :show
  77. end
  78. end
  79. end
  80. end
  81. end