migrations_controller_spec.rb 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe Settings::MigrationsController do
  4. render_views
  5. describe 'GET #show' do
  6. context 'when user is not sign in' do
  7. subject { get :show }
  8. it { is_expected.to redirect_to new_user_session_path }
  9. end
  10. context 'when user is sign in' do
  11. subject { get :show }
  12. let(:user) { Fabricate(:account, moved_to_account: moved_to_account).user }
  13. before { sign_in user, scope: :user }
  14. context 'when user does not have moved to account' do
  15. let(:moved_to_account) { nil }
  16. it 'renders show page' do
  17. expect(subject).to have_http_status 200
  18. expect(subject).to render_template :show
  19. end
  20. end
  21. context 'when user has a moved to account' do
  22. let(:moved_to_account) { Fabricate(:account) }
  23. it 'renders show page' do
  24. expect(subject).to have_http_status 200
  25. expect(subject).to render_template :show
  26. end
  27. end
  28. end
  29. end
  30. describe 'POST #create' do
  31. context 'when user is not sign in' do
  32. subject { post :create }
  33. it { is_expected.to redirect_to new_user_session_path }
  34. end
  35. context 'when user is signed in' do
  36. subject { post :create, params: { account_migration: { acct: acct, current_password: '12345678' } } }
  37. let(:user) { Fabricate(:user, password: '12345678') }
  38. before { sign_in user, scope: :user }
  39. context 'when migration account is changed' do
  40. let(:acct) { Fabricate(:account, also_known_as: [ActivityPub::TagManager.instance.uri_for(user.account)]) }
  41. it 'updates moved to account' do
  42. expect(subject).to redirect_to settings_migration_path
  43. expect(user.account.reload.moved_to_account_id).to eq acct.id
  44. end
  45. end
  46. context 'when acct is the current account' do
  47. let(:acct) { user.account }
  48. it 'does not update the moved account', :aggregate_failures do
  49. subject
  50. expect(user.account.reload.moved_to_account_id).to be_nil
  51. expect(response).to render_template :show
  52. end
  53. end
  54. context 'when target account does not reference the account being moved from' do
  55. let(:acct) { Fabricate(:account, also_known_as: []) }
  56. it 'does not update the moved account', :aggregate_failures do
  57. subject
  58. expect(user.account.reload.moved_to_account_id).to be_nil
  59. expect(response).to render_template :show
  60. end
  61. end
  62. context 'when a recent migration already exists' do
  63. let(:acct) { Fabricate(:account, also_known_as: [ActivityPub::TagManager.instance.uri_for(user.account)]) }
  64. before do
  65. moved_to = Fabricate(:account, also_known_as: [ActivityPub::TagManager.instance.uri_for(user.account)])
  66. user.account.migrations.create!(acct: moved_to.acct)
  67. end
  68. it 'does not update the moved account', :aggregate_failures do
  69. subject
  70. expect(user.account.reload.moved_to_account_id).to be_nil
  71. expect(response).to render_template :show
  72. end
  73. end
  74. end
  75. end
  76. end