Refactor remote_follow_spec.rb (#5690)
parent
20150659e6
commit
1f1838420f
|
@ -3,83 +3,65 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe RemoteFollow do
|
RSpec.describe RemoteFollow do
|
||||||
|
before do
|
||||||
|
stub_request(:get, 'https://quitter.no/.well-known/webfinger?resource=acct:gargron@quitter.no').to_return(request_fixture('webfinger.txt'))
|
||||||
|
end
|
||||||
|
|
||||||
|
let(:attrs) { nil }
|
||||||
|
let(:remote_follow) { described_class.new(attrs) }
|
||||||
|
|
||||||
describe '.initialize' do
|
describe '.initialize' do
|
||||||
let(:remote_follow) { RemoteFollow.new(option) }
|
subject { remote_follow.acct }
|
||||||
|
|
||||||
context 'option with acct' do
|
context 'attrs with acct' do
|
||||||
let(:option) { { acct: 'hoge@example.com' } }
|
let(:attrs) { { acct: 'gargron@quitter.no' } }
|
||||||
|
|
||||||
it 'sets acct' do
|
it 'returns acct' do
|
||||||
expect(remote_follow.acct).to eq 'hoge@example.com'
|
is_expected.to eq 'gargron@quitter.no'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'option without acct' do
|
context 'attrs without acct' do
|
||||||
let(:option) { {} }
|
let(:attrs) { {} }
|
||||||
|
|
||||||
it 'does not set acct' do
|
it do
|
||||||
expect(remote_follow.acct).to be_nil
|
is_expected.to be_nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#valid?' do
|
describe '#valid?' do
|
||||||
let(:remote_follow) { RemoteFollow.new }
|
subject { remote_follow.valid? }
|
||||||
|
|
||||||
context 'super is falsy' do
|
context 'attrs with acct' do
|
||||||
module InvalidSuper
|
let(:attrs) { { acct: 'gargron@quitter.no' }}
|
||||||
def valid?
|
|
||||||
nil
|
it do
|
||||||
|
is_expected.to be true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
before do
|
context 'attrs without acct' do
|
||||||
class RemoteFollow
|
let(:attrs) { { } }
|
||||||
include InvalidSuper
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns false without calling #populate_template and #errors' do
|
it do
|
||||||
expect(remote_follow).not_to receive(:populate_template)
|
is_expected.to be false
|
||||||
expect(remote_follow).not_to receive(:errors)
|
|
||||||
expect(remote_follow.valid?).to be false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'super is truthy' do
|
|
||||||
module ValidSuper
|
|
||||||
def valid?
|
|
||||||
true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
before do
|
|
||||||
class RemoteFollow
|
|
||||||
include ValidSuper
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'calls #populate_template and #errors.empty?' do
|
|
||||||
expect(remote_follow).to receive(:populate_template)
|
|
||||||
expect(remote_follow).to receive_message_chain(:errors, :empty?)
|
|
||||||
remote_follow.valid?
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#subscribe_address_for' do
|
describe '#subscribe_address_for' do
|
||||||
before do
|
before do
|
||||||
allow(remote_follow).to receive(:addressable_template).and_return(addressable_template)
|
remote_follow.valid?
|
||||||
end
|
end
|
||||||
|
|
||||||
let(:account) { instance_double('Account', local_username_and_domain: local_username_and_domain) }
|
let(:attrs) { { acct: 'gargron@quitter.no' } }
|
||||||
let(:addressable_template) { instance_double('Addressable::Template') }
|
let(:account) { Fabricate(:account, username: 'alice') }
|
||||||
let(:local_username_and_domain) { 'hoge@example.com' }
|
|
||||||
let(:remote_follow) { RemoteFollow.new }
|
|
||||||
|
|
||||||
it 'calls Addressable::Template#expand.to_s' do
|
subject { remote_follow.subscribe_address_for(account) }
|
||||||
expect(addressable_template).to receive_message_chain(:expand, :to_s).with(uri: local_username_and_domain).with(no_args)
|
|
||||||
remote_follow.subscribe_address_for(account)
|
it 'returns subscribe address' do
|
||||||
|
is_expected.to eq 'https://quitter.no/main/ostatussub?profile=alice%40cb6e6126.ngrok.io'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue