migrations_controller_spec.rb 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 'renders show' do
  54. expect(subject).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. expect(subject).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. expect(subject).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