From 15c0f6ae56e31ced750fa0ae06bf39d72355a477 Mon Sep 17 00:00:00 2001 From: ysksn Date: Sun, 5 Nov 2017 17:20:05 +0900 Subject: Implement tests for Account#possibly_stale? (#5591) --- spec/models/account_spec.rb | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'spec/models/account_spec.rb') diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb index aef0c3082..2144bffee 100644 --- a/spec/models/account_spec.rb +++ b/spec/models/account_spec.rb @@ -123,6 +123,34 @@ RSpec.describe Account, type: :model do end end + describe '#possibly_stale?' do + let(:account) { Fabricate(:account, last_webfingered_at: last_webfingered_at) } + + context 'last_webfingered_at is nil' do + let(:last_webfingered_at) { nil } + + it 'returns true' do + expect(account.possibly_stale?).to be true + end + end + + context 'last_webfingered_at is more than 24 hours before' do + let(:last_webfingered_at) { 25.hours.ago } + + it 'returns true' do + expect(account.possibly_stale?).to be true + end + end + + context 'last_webfingered_at is less than 24 hours before' do + let(:last_webfingered_at) { 23.hours.ago } + + it 'returns false' do + expect(account.possibly_stale?).to be false + end + end + end + describe '#to_param' do it 'returns username' do account = Fabricate(:account, username: 'alice') -- cgit From cf01326cc130bc6255aab5ce1e961ff8810758ae Mon Sep 17 00:00:00 2001 From: ysksn Date: Mon, 6 Nov 2017 13:54:12 +0900 Subject: Add test for Account#save_with_optional_media! (#5603) There was a test when some of the properties are invalid, but none when all of them are valid. --- spec/models/account_spec.rb | 49 +++++++++++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 13 deletions(-) (limited to 'spec/models/account_spec.rb') diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb index 2144bffee..5165082d1 100644 --- a/spec/models/account_spec.rb +++ b/spec/models/account_spec.rb @@ -93,21 +93,44 @@ RSpec.describe Account, type: :model do end describe '#save_with_optional_media!' do - it 'sets default avatar, header, avatar_remote_url, and header_remote_url if some of them are invalid' do + before do stub_request(:get, 'https://remote/valid_avatar').to_return(request_fixture('avatar.txt')) stub_request(:get, 'https://remote/invalid_avatar').to_return(request_fixture('feed.txt')) - account = Fabricate(:account, - avatar_remote_url: 'https://remote/valid_avatar', - header_remote_url: 'https://remote/valid_avatar') - - account.avatar_remote_url = 'https://remote/invalid_avatar' - account.save_with_optional_media! - - account.reload - expect(account.avatar_remote_url).to eq '' - expect(account.header_remote_url).to eq '' - expect(account.avatar_file_name).to eq nil - expect(account.header_file_name).to eq nil + end + + let(:account) do + Fabricate(:account, + avatar_remote_url: 'https://remote/valid_avatar', + header_remote_url: 'https://remote/valid_avatar') + end + + let!(:expectation) { account.dup } + + context 'with valid properties' do + before do + account.save_with_optional_media! + end + + it 'unchanges avatar, header, avatar_remote_url, and header_remote_url' do + expect(account.avatar_remote_url).to eq expectation.avatar_remote_url + expect(account.header_remote_url).to eq expectation.header_remote_url + expect(account.avatar_file_name).to eq expectation.avatar_file_name + expect(account.header_file_name).to eq expectation.header_file_name + end + end + + context 'with invalid properties' do + before do + account.avatar_remote_url = 'https://remote/invalid_avatar' + account.save_with_optional_media! + end + + it 'sets default avatar, header, avatar_remote_url, and header_remote_url' do + expect(account.avatar_remote_url).to eq '' + expect(account.header_remote_url).to eq '' + expect(account.avatar_file_name).to eq nil + expect(account.header_file_name).to eq nil + end end end -- cgit From d307ee79e9b2f783fbdc6fd2e174ec91c47e8e5e Mon Sep 17 00:00:00 2001 From: ysksn Date: Mon, 6 Nov 2017 13:54:41 +0900 Subject: Implement tests for Account#refresh! (#5601) --- spec/models/account_spec.rb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'spec/models/account_spec.rb') diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb index 5165082d1..9c1492c90 100644 --- a/spec/models/account_spec.rb +++ b/spec/models/account_spec.rb @@ -174,6 +174,33 @@ RSpec.describe Account, type: :model do end end + describe '#refresh!' do + let(:account) { Fabricate(:account, domain: domain) } + let(:acct) { account.acct } + + context 'domain is nil' do + let(:domain) { nil } + + it 'returns nil' do + expect(account.refresh!).to be_nil + end + + it 'calls not ResolveRemoteAccountService#call' do + expect_any_instance_of(ResolveRemoteAccountService).not_to receive(:call).with(acct) + account.refresh! + end + end + + context 'domain is present' do + let(:domain) { 'example.com' } + + it 'calls ResolveRemoteAccountService#call' do + expect_any_instance_of(ResolveRemoteAccountService).to receive(:call).with(acct).once + account.refresh! + end + end + end + describe '#to_param' do it 'returns username' do account = Fabricate(:account, username: 'alice') -- cgit