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.

66 lines
1.8 KiB

  1. require 'rails_helper'
  2. RSpec.describe Tag, type: :model do
  3. describe 'validations' do
  4. it 'invalid with #' do
  5. expect(Tag.new(name: '#hello_world')).to_not be_valid
  6. end
  7. it 'invalid with .' do
  8. expect(Tag.new(name: '.abcdef123')).to_not be_valid
  9. end
  10. it 'invalid with spaces' do
  11. expect(Tag.new(name: 'hello world')).to_not be_valid
  12. end
  13. it 'valid with aesthetic' do
  14. expect(Tag.new(name: 'aesthetic')).to be_valid
  15. end
  16. end
  17. describe 'HASHTAG_RE' do
  18. subject { Tag::HASHTAG_RE }
  19. it 'does not match URLs with anchors with non-hashtag characters' do
  20. expect(subject.match('Check this out https://medium.com/@alice/some-article#.abcdef123')).to be_nil
  21. end
  22. it 'does not match URLs with hashtag-like anchors' do
  23. expect(subject.match('https://en.wikipedia.org/wiki/Ghostbusters_(song)#Lawsuit')).to be_nil
  24. end
  25. it 'matches #aesthetic' do
  26. expect(subject.match('this is #aesthetic')).to_not be_nil
  27. end
  28. end
  29. describe '.search_for' do
  30. it 'finds tag records with matching names' do
  31. tag = Fabricate(:tag, name: "match")
  32. _miss_tag = Fabricate(:tag, name: "miss")
  33. results = Tag.search_for("match")
  34. expect(results).to eq [tag]
  35. end
  36. it 'finds tag records in case insensitive' do
  37. tag = Fabricate(:tag, name: "MATCH")
  38. _miss_tag = Fabricate(:tag, name: "miss")
  39. results = Tag.search_for("match")
  40. expect(results).to eq [tag]
  41. end
  42. it 'finds the exact matching tag as the first item' do
  43. similar_tag = Fabricate(:tag, name: "matchlater")
  44. tag = Fabricate(:tag, name: "match")
  45. results = Tag.search_for("match")
  46. expect(results).to eq [tag, similar_tag]
  47. end
  48. end
  49. end