1
0

accounts_helper_spec.rb 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe AccountsHelper do
  4. def set_not_embedded_view
  5. params[:controller] = "not_#{StatusesHelper::EMBEDDED_CONTROLLER}"
  6. params[:action] = "not_#{StatusesHelper::EMBEDDED_ACTION}"
  7. end
  8. def set_embedded_view
  9. params[:controller] = StatusesHelper::EMBEDDED_CONTROLLER
  10. params[:action] = StatusesHelper::EMBEDDED_ACTION
  11. end
  12. describe '#display_name' do
  13. it 'uses the display name when it exists' do
  14. account = Account.new(display_name: 'Display', username: 'Username')
  15. expect(helper.display_name(account)).to eq 'Display'
  16. end
  17. it 'uses the username when display name is nil' do
  18. account = Account.new(display_name: nil, username: 'Username')
  19. expect(helper.display_name(account)).to eq 'Username'
  20. end
  21. end
  22. describe '#acct' do
  23. it 'is fully qualified for embedded local accounts' do
  24. allow(Rails.configuration.x).to receive(:local_domain).and_return('local_domain')
  25. set_embedded_view
  26. account = Account.new(domain: nil, username: 'user')
  27. acct = helper.acct(account)
  28. expect(acct).to eq '@user@local_domain'
  29. end
  30. it 'is fully qualified for embedded foreign accounts' do
  31. set_embedded_view
  32. account = Account.new(domain: 'foreign_server.com', username: 'user')
  33. acct = helper.acct(account)
  34. expect(acct).to eq '@user@foreign_server.com'
  35. end
  36. it 'is fully qualified for non embedded foreign accounts' do
  37. set_not_embedded_view
  38. account = Account.new(domain: 'foreign_server.com', username: 'user')
  39. acct = helper.acct(account)
  40. expect(acct).to eq '@user@foreign_server.com'
  41. end
  42. it 'is fully qualified for non embedded local accounts' do
  43. allow(Rails.configuration.x).to receive(:local_domain).and_return('local_domain')
  44. set_not_embedded_view
  45. account = Account.new(domain: nil, username: 'user')
  46. acct = helper.acct(account)
  47. expect(acct).to eq '@user@local_domain'
  48. end
  49. end
  50. end