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.

67 lines
2.0 KiB

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