account_migration_spec.rb 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe AccountMigration do
  4. describe 'validations' do
  5. subject { described_class.new(account: source_account, acct: target_acct) }
  6. let(:source_account) { Fabricate(:account) }
  7. let(:target_acct) { target_account.acct }
  8. context 'with valid properties' do
  9. let(:target_account) { Fabricate(:account, username: 'target', domain: 'remote.org') }
  10. before do
  11. target_account.aliases.create!(acct: source_account.acct)
  12. service_double = instance_double(ResolveAccountService)
  13. allow(ResolveAccountService).to receive(:new).and_return(service_double)
  14. allow(service_double).to receive(:call).with(target_acct, anything).and_return(target_account)
  15. end
  16. it 'passes validations' do
  17. expect(subject).to be_valid
  18. end
  19. end
  20. context 'with unresolvable account' do
  21. let(:target_acct) { 'target@remote' }
  22. before do
  23. service_double = instance_double(ResolveAccountService)
  24. allow(ResolveAccountService).to receive(:new).and_return(service_double)
  25. allow(service_double).to receive(:call).with(target_acct, anything).and_return(nil)
  26. end
  27. it 'has errors on acct field' do
  28. expect(subject).to model_have_error_on_field(:acct)
  29. end
  30. end
  31. context 'with a space in the domain part' do
  32. let(:target_acct) { 'target@remote. org' }
  33. it 'has errors on acct field' do
  34. expect(subject).to model_have_error_on_field(:acct)
  35. end
  36. end
  37. end
  38. end