account_migration_spec.rb 1.4 KB

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