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.

58 lines
2.0 KiB

  1. require 'rails_helper'
  2. RSpec.describe ApplicationHelper, type: :helper do
  3. let(:local_domain) { 'local.tld' }
  4. before do
  5. Rails.configuration.x.local_domain = local_domain
  6. end
  7. describe '#unique_tag' do
  8. it 'returns a string' do
  9. expect(helper.unique_tag(Time.now, 12, 'Status')).to be_a String
  10. end
  11. end
  12. describe '#unique_tag_to_local_id' do
  13. it 'returns the ID part' do
  14. expect(helper.unique_tag_to_local_id("tag:#{local_domain};objectId=12:objectType=Status", 'Status')).to eql '12'
  15. end
  16. end
  17. describe '#local_id?' do
  18. it 'returns true for a local ID' do
  19. expect(helper.local_id?("tag:#{local_domain};objectId=12:objectType=Status")).to be true
  20. end
  21. it 'returns false for a foreign ID' do
  22. expect(helper.local_id?('tag:foreign.tld;objectId=12:objectType=Status')).to be false
  23. end
  24. end
  25. describe '#linkify' do
  26. let(:alice) { Fabricate(:account, username: 'alice') }
  27. let(:bob) { Fabricate(:account, username: 'bob', domain: 'example.com', url: 'http://example.com/bob') }
  28. it 'turns mention of remote user into link' do
  29. status = Fabricate(:status, text: 'Hello @bob@example.com', account: bob)
  30. status.mentions.create(account: bob)
  31. expect(helper.linkify(status)).to match('<a href="http://example.com/bob" class="mention">@<span>bob@example.com</span></a>')
  32. end
  33. it 'turns mention of local user into link' do
  34. status = Fabricate(:status, text: 'Hello @alice', account: bob)
  35. status.mentions.create(account: alice)
  36. expect(helper.linkify(status)).to match('<a href="http://test.host/users/alice" class="mention">@<span>alice</span></a>')
  37. end
  38. end
  39. describe '#account_from_mentions' do
  40. let(:bob) { Fabricate(:account, username: 'bob', domain: 'example.com') }
  41. let(:status) { Fabricate(:status, text: 'Hello @bob@example.com', account: bob) }
  42. let(:mentions) { [Mention.create(status: status, account: bob)] }
  43. it 'returns account' do
  44. expect(helper.account_from_mentions('bob@example.com', mentions)).to eq bob
  45. end
  46. end
  47. end