mute_service_spec.rb 1.9 KB

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