mute_service_spec.rb 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe MuteService, type: :service do
  4. subject { described_class.new.call(account, target_account) }
  5. let(:account) { Fabricate(:account) }
  6. let(:target_account) { Fabricate(:account) }
  7. describe 'home timeline' do
  8. let(:status) { Fabricate(:status, account: target_account) }
  9. let(:other_account_status) { Fabricate(:status) }
  10. let(:home_timeline_key) { FeedManager.instance.key(:home, account.id) }
  11. before do
  12. redis.del(home_timeline_key)
  13. end
  14. it "clears account's statuses" do
  15. FeedManager.instance.push_to_home(account, status)
  16. FeedManager.instance.push_to_home(account, other_account_status)
  17. expect { subject }.to change {
  18. redis.zrange(home_timeline_key, 0, -1)
  19. }.from([status.id.to_s, other_account_status.id.to_s]).to([other_account_status.id.to_s])
  20. end
  21. end
  22. it 'mutes account' do
  23. expect { subject }.to change {
  24. account.muting?(target_account)
  25. }.from(false).to(true)
  26. end
  27. context 'without specifying a notifications parameter' do
  28. it 'mutes notifications from the account' do
  29. expect { subject }.to change {
  30. account.muting_notifications?(target_account)
  31. }.from(false).to(true)
  32. end
  33. end
  34. context 'with a true notifications parameter' do
  35. subject { described_class.new.call(account, target_account, notifications: true) }
  36. it 'mutes notifications from the account' do
  37. expect { subject }.to change {
  38. account.muting_notifications?(target_account)
  39. }.from(false).to(true)
  40. end
  41. end
  42. context 'with a false notifications parameter' do
  43. subject { described_class.new.call(account, target_account, notifications: false) }
  44. it 'does not mute notifications from the account' do
  45. expect { subject }.to_not change {
  46. account.muting_notifications?(target_account)
  47. }.from(false)
  48. end
  49. end
  50. end