mute_service_spec.rb 1.9 KB

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