has_tags_examples.rb 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. RSpec.shared_examples 'HasTags' do
  2. subject { create(described_class.name.underscore) }
  3. describe '#tag_add' do
  4. let(:item_name) { 'foo' }
  5. it 'delegates to Tag.tag_add' do
  6. expect(Tag)
  7. .to receive(:tag_add)
  8. .with(object: described_class.name,
  9. o_id: subject.id,
  10. item: item_name,
  11. created_by_id: nil)
  12. subject.tag_add(item_name)
  13. end
  14. it 'optionally accepts a current_user_id argument' do
  15. expect(Tag)
  16. .to receive(:tag_add)
  17. .with(object: described_class.name,
  18. o_id: subject.id,
  19. item: item_name,
  20. created_by_id: 1)
  21. subject.tag_add(item_name, 1)
  22. end
  23. end
  24. describe '#tag_remove' do
  25. let(:item_name) { 'foo' }
  26. it 'delegates to Tag.tag_remove' do
  27. expect(Tag)
  28. .to receive(:tag_remove)
  29. .with(object: described_class.name,
  30. o_id: subject.id,
  31. item: item_name,
  32. created_by_id: nil)
  33. subject.tag_remove(item_name)
  34. end
  35. it 'optionally accepts a current_user_id argument' do
  36. expect(Tag)
  37. .to receive(:tag_remove)
  38. .with(object: described_class.name,
  39. o_id: subject.id,
  40. item: item_name,
  41. created_by_id: 1)
  42. subject.tag_remove(item_name, 1)
  43. end
  44. end
  45. describe '#tag_list' do
  46. it 'delegates to Tag.tag_list' do
  47. expect(Tag)
  48. .to receive(:tag_list)
  49. .with(object: described_class.name,
  50. o_id: subject.id)
  51. subject.tag_list
  52. end
  53. end
  54. end