bootstrap_timeline_service_spec.rb 1.2 KB

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