bootstrap_timeline_service_spec.rb 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe BootstrapTimelineService do
  4. subject { described_class.new }
  5. context 'when the new user has registered from an invite' do
  6. let(:service) { instance_double(FollowService) }
  7. let(:autofollow) { false }
  8. let(:inviter) { Fabricate(:user, confirmed_at: 2.days.ago) }
  9. let(:invite) { Fabricate(:invite, user: inviter, max_uses: nil, expires_at: 1.hour.from_now, autofollow: autofollow) }
  10. let(:new_user) { Fabricate(:user, invite_code: invite.code) }
  11. before do
  12. allow(FollowService).to receive(:new).and_return(service)
  13. allow(service).to receive(:call)
  14. end
  15. context 'when the invite has auto-follow enabled' do
  16. let(:autofollow) { true }
  17. it 'calls FollowService to follow the inviter' do
  18. subject.call(new_user.account)
  19. expect(service).to have_received(:call).with(new_user.account, inviter.account)
  20. end
  21. end
  22. context 'when the invite does not have auto-follow enable' do
  23. let(:autofollow) { false }
  24. it 'calls FollowService to follow the inviter' do
  25. subject.call(new_user.account)
  26. expect(service).to_not have_received(:call)
  27. end
  28. end
  29. end
  30. end