application_helper_spec.rb 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. require 'rails_helper'
  2. describe ApplicationHelper do
  3. describe 'active_nav_class' do
  4. it 'returns active when on the current page' do
  5. allow(helper).to receive(:current_page?).and_return(true)
  6. result = helper.active_nav_class("/test")
  7. expect(result).to eq "active"
  8. end
  9. it 'returns active when on a current page' do
  10. allow(helper).to receive(:current_page?).with('/foo').and_return(false)
  11. allow(helper).to receive(:current_page?).with('/test').and_return(true)
  12. result = helper.active_nav_class('/foo', '/test')
  13. expect(result).to eq "active"
  14. end
  15. it 'returns empty string when not on current page' do
  16. allow(helper).to receive(:current_page?).and_return(false)
  17. result = helper.active_nav_class("/test")
  18. expect(result).to eq ""
  19. end
  20. end
  21. describe 'locale_direction' do
  22. around do |example|
  23. current_locale = I18n.locale
  24. example.run
  25. I18n.locale = current_locale
  26. end
  27. it 'adds rtl body class if locale is Arabic' do
  28. I18n.locale = :ar
  29. expect(helper.locale_direction).to eq 'rtl'
  30. end
  31. it 'adds rtl body class if locale is Farsi' do
  32. I18n.locale = :fa
  33. expect(helper.locale_direction).to eq 'rtl'
  34. end
  35. it 'adds rtl if locale is Hebrew' do
  36. I18n.locale = :he
  37. expect(helper.locale_direction).to eq 'rtl'
  38. end
  39. it 'does not add rtl if locale is Thai' do
  40. I18n.locale = :th
  41. expect(helper.locale_direction).to_not eq 'rtl'
  42. end
  43. end
  44. describe 'fa_icon' do
  45. it 'returns a tag of fixed-width cog' do
  46. expect(helper.fa_icon('cog fw')).to eq '<i class="fa fa-cog fa-fw"></i>'
  47. end
  48. end
  49. describe 'open_registrations?' do
  50. it 'returns true when open for registrations' do
  51. without_partial_double_verification do
  52. expect(Setting).to receive(:registrations_mode).and_return('open')
  53. end
  54. expect(helper.open_registrations?).to eq true
  55. end
  56. it 'returns false when closed for registrations' do
  57. without_partial_double_verification do
  58. expect(Setting).to receive(:registrations_mode).and_return('none')
  59. end
  60. expect(helper.open_registrations?).to eq false
  61. end
  62. end
  63. describe 'show_landing_strip?', without_verify_partial_doubles: true do
  64. describe 'when signed in' do
  65. before do
  66. allow(helper).to receive(:user_signed_in?).and_return(true)
  67. end
  68. it 'does not show landing strip' do
  69. expect(helper.show_landing_strip?).to eq false
  70. end
  71. end
  72. describe 'when signed out' do
  73. before do
  74. allow(helper).to receive(:user_signed_in?).and_return(false)
  75. end
  76. it 'does not show landing strip on single user instance' do
  77. allow(helper).to receive(:single_user_mode?).and_return(true)
  78. expect(helper.show_landing_strip?).to eq false
  79. end
  80. it 'shows landing strip on multi user instance' do
  81. allow(helper).to receive(:single_user_mode?).and_return(false)
  82. expect(helper.show_landing_strip?).to eq true
  83. end
  84. end
  85. end
  86. describe 'title' do
  87. around do |example|
  88. site_title = Setting.site_title
  89. example.run
  90. Setting.site_title = site_title
  91. end
  92. it 'returns site title on production environment' do
  93. Setting.site_title = 'site title'
  94. expect(Rails.env).to receive(:production?).and_return(true)
  95. expect(helper.title).to eq 'site title'
  96. end
  97. end
  98. end