You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
2.3 KiB

  1. require 'rails_helper'
  2. RSpec.describe UpdateRemoteProfileService do
  3. let(:xml) { Nokogiri::XML(File.read(File.join(Rails.root, 'spec', 'fixtures', 'push', 'feed.atom'))).at_xpath('//xmlns:author') }
  4. subject { UpdateRemoteProfileService.new }
  5. before do
  6. stub_request(:get, 'https://quitter.no/avatar/7477-300-20160211190340.png').to_return(request_fixture('avatar.txt'))
  7. end
  8. context 'with updated details' do
  9. let(:remote_account) { Fabricate(:account, username: 'bob', domain: 'example.com') }
  10. before do
  11. subject.(xml, remote_account)
  12. end
  13. it 'downloads new avatar' do
  14. expect(a_request(:get, 'https://quitter.no/avatar/7477-300-20160211190340.png')).to have_been_made
  15. end
  16. it 'sets the avatar remote url' do
  17. expect(remote_account.reload.avatar_remote_url).to eq 'https://quitter.no/avatar/7477-300-20160211190340.png'
  18. end
  19. it 'sets display name' do
  20. expect(remote_account.reload.display_name).to eq 'DIGITAL CAT'
  21. end
  22. it 'sets note' do
  23. expect(remote_account.reload.note).to eq 'Software engineer, free time musician and DIGITAL SPORTS enthusiast. Likes cats. Warning: May contain memes'
  24. end
  25. end
  26. context 'with unchanged details' do
  27. let(:remote_account) { Fabricate(:account, username: 'bob', domain: 'example.com',display_name: 'DIGITAL CAT', note: 'Software engineer, free time musician and DIGITAL SPORTS enthusiast. Likes cats. Warning: May contain memes', avatar_remote_url: 'https://quitter.no/avatar/7477-300-20160211190340.png') }
  28. before do
  29. subject.(xml, remote_account)
  30. end
  31. it 'does not re-download avatar' do
  32. expect(a_request(:get, 'https://quitter.no/avatar/7477-300-20160211190340.png')).to have_been_made.once
  33. end
  34. it 'sets the avatar remote url' do
  35. expect(remote_account.reload.avatar_remote_url).to eq 'https://quitter.no/avatar/7477-300-20160211190340.png'
  36. end
  37. it 'sets display name' do
  38. expect(remote_account.reload.display_name).to eq 'DIGITAL CAT'
  39. end
  40. it 'sets note' do
  41. expect(remote_account.reload.note).to eq 'Software engineer, free time musician and DIGITAL SPORTS enthusiast. Likes cats. Warning: May contain memes'
  42. end
  43. end
  44. end