about summary refs log tree commit diff
path: root/spec
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2016-03-22 21:05:23 +0100
committerEugen Rochko <eugen@zeonfederated.com>2016-03-22 21:05:23 +0100
commit02e4fb2e06f424c16ab25ea294a4af6490a5f7e3 (patch)
treea63f863ed677eb789646ab468681001628e29490 /spec
parent921f40c1873883e8ce476e04de1f3f1bd5ccbf91 (diff)
Only re-download avatar if URL changed (fix #19)
Diffstat (limited to 'spec')
-rw-r--r--spec/services/update_remote_profile_service_spec.rb54
1 files changed, 54 insertions, 0 deletions
diff --git a/spec/services/update_remote_profile_service_spec.rb b/spec/services/update_remote_profile_service_spec.rb
index f09f60ada..1ffcfbfac 100644
--- a/spec/services/update_remote_profile_service_spec.rb
+++ b/spec/services/update_remote_profile_service_spec.rb
@@ -1,5 +1,59 @@
 require 'rails_helper'
 
 RSpec.describe UpdateRemoteProfileService do
+  let(:xml) { Nokogiri::XML(File.read(File.join(Rails.root, 'spec', 'fixtures', 'push', 'feed.atom'))).at_xpath('//xmlns:author') }
+
   subject { UpdateRemoteProfileService.new }
+
+  before do
+    stub_request(:get, 'https://quitter.no/avatar/7477-300-20160211190340.png').to_return(request_fixture('avatar.txt'))
+  end
+
+  context 'with updated details' do
+    let(:remote_account) { Fabricate(:account, username: 'bob', domain: 'example.com') }
+
+    before do
+      subject.(xml, remote_account)
+    end
+
+    it 'downloads new avatar' do
+      expect(a_request(:get, 'https://quitter.no/avatar/7477-300-20160211190340.png')).to have_been_made
+    end
+
+    it 'sets the avatar remote url' do
+      expect(remote_account.reload.avatar_remote_url).to eq 'https://quitter.no/avatar/7477-300-20160211190340.png'
+    end
+
+    it 'sets display name' do
+      expect(remote_account.reload.display_name).to eq 'DIGITAL CAT'
+    end
+
+    it 'sets note' do
+      expect(remote_account.reload.note).to eq 'Software engineer, free time musician and DIGITAL SPORTS enthusiast. Likes cats. Warning: May contain memes'
+    end
+  end
+
+  context 'with unchanged details' do
+    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') }
+
+    before do
+      subject.(xml, remote_account)
+    end
+
+    it 'does not re-download avatar' do
+      expect(a_request(:get, 'https://quitter.no/avatar/7477-300-20160211190340.png')).to have_been_made.once
+    end
+
+    it 'sets the avatar remote url' do
+      expect(remote_account.reload.avatar_remote_url).to eq 'https://quitter.no/avatar/7477-300-20160211190340.png'
+    end
+
+    it 'sets display name' do
+      expect(remote_account.reload.display_name).to eq 'DIGITAL CAT'
+    end
+
+    it 'sets note' do
+      expect(remote_account.reload.note).to eq 'Software engineer, free time musician and DIGITAL SPORTS enthusiast. Likes cats. Warning: May contain memes'
+    end
+  end
 end