logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

tag_spec.rb (1972B)


  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 '#to_param' do
  30. it 'returns name' do
  31. tag = Fabricate(:tag, name: 'foo')
  32. expect(tag.to_param).to eq 'foo'
  33. end
  34. end
  35. describe '.search_for' do
  36. it 'finds tag records with matching names' 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 tag records in case insensitive' do
  43. tag = Fabricate(:tag, name: "MATCH")
  44. _miss_tag = Fabricate(:tag, name: "miss")
  45. results = Tag.search_for("match")
  46. expect(results).to eq [tag]
  47. end
  48. it 'finds the exact matching tag as the first item' do
  49. similar_tag = Fabricate(:tag, name: "matchlater")
  50. tag = Fabricate(:tag, name: "match")
  51. results = Tag.search_for("match")
  52. expect(results).to eq [tag, similar_tag]
  53. end
  54. end
  55. end