You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.4 KiB

  1. require 'rails_helper'
  2. describe TagFeed, type: :service do
  3. describe '#get' do
  4. let(:account) { Fabricate(:account) }
  5. let(:tag1) { Fabricate(:tag) }
  6. let(:tag2) { Fabricate(:tag) }
  7. let!(:status1) { Fabricate(:status, tags: [tag1]) }
  8. let!(:status2) { Fabricate(:status, tags: [tag2]) }
  9. let!(:both) { Fabricate(:status, tags: [tag1, tag2]) }
  10. it 'can add tags in "any" mode' do
  11. results = described_class.new(tag1, nil, any: [tag2.name]).get(20)
  12. expect(results).to include status1
  13. expect(results).to include status2
  14. expect(results).to include both
  15. end
  16. it 'can remove tags in "all" mode' do
  17. results = described_class.new(tag1, nil, all: [tag2.name]).get(20)
  18. expect(results).to_not include status1
  19. expect(results).to_not include status2
  20. expect(results).to include both
  21. end
  22. it 'can remove tags in "none" mode' do
  23. results = described_class.new(tag1, nil, none: [tag2.name]).get(20)
  24. expect(results).to include status1
  25. expect(results).to_not include status2
  26. expect(results).to_not include both
  27. end
  28. it 'ignores an invalid mode' do
  29. results = described_class.new(tag1, nil, wark: [tag2.name]).get(20)
  30. expect(results).to include status1
  31. expect(results).to_not include status2
  32. expect(results).to include both
  33. end
  34. it 'handles being passed non existant tag names' do
  35. results = described_class.new(tag1, nil, any: ['wark']).get(20)
  36. expect(results).to include status1
  37. expect(results).to_not include status2
  38. expect(results).to include both
  39. end
  40. it 'can restrict to an account' do
  41. BlockService.new.call(account, status1.account)
  42. results = described_class.new(tag1, account, none: [tag2.name]).get(20)
  43. expect(results).to_not include status1
  44. end
  45. it 'can restrict to local' do
  46. status1.account.update(domain: 'example.com')
  47. status1.update(local: false, uri: 'example.com/toot')
  48. results = described_class.new(tag1, nil, any: [tag2.name], local: true).get(20)
  49. expect(results).to_not include status1
  50. end
  51. it 'allows replies to be included' do
  52. original = Fabricate(:status)
  53. status = Fabricate(:status, tags: [tag1], in_reply_to_id: original.id)
  54. results = described_class.new(tag1, nil).get(20)
  55. expect(results).to include(status)
  56. end
  57. end
  58. end