tag_feed_spec.rb 2.8 KB

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