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.

39 lines
1.1 KiB

  1. require 'rails_helper'
  2. RSpec.describe Tag, type: :model do
  3. describe 'HASHTAG_RE' do
  4. subject { Tag::HASHTAG_RE }
  5. it 'does not match URLs with anchors with non-hashtag characters' do
  6. expect(subject.match('Check this out https://medium.com/@alice/some-article#.abcdef123')).to be_nil
  7. end
  8. it 'does not match URLs with hashtag-like anchors' do
  9. expect(subject.match('https://en.wikipedia.org/wiki/Ghostbusters_(song)#Lawsuit')).to be_nil
  10. end
  11. it 'matches #aesthetic' do
  12. expect(subject.match('this is #aesthetic')).to_not be_nil
  13. end
  14. end
  15. describe '.search_for' do
  16. it 'finds tag records with matching names' do
  17. tag = Fabricate(:tag, name: "match")
  18. _miss_tag = Fabricate(:tag, name: "miss")
  19. results = Tag.search_for("match")
  20. expect(results).to eq [tag]
  21. end
  22. it 'finds the exact matching tag as the first item' do
  23. similar_tag = Fabricate(:tag, name: "matchlater")
  24. tag = Fabricate(:tag, name: "match")
  25. results = Tag.search_for("match")
  26. expect(results).to eq [tag, similar_tag]
  27. end
  28. end
  29. end