2016-02-27 01:28:08 +11:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2017-04-10 01:11:37 +10:00
|
|
|
describe ApplicationHelper do
|
|
|
|
describe 'active_nav_class' do
|
|
|
|
it 'returns active when on the current page' do
|
|
|
|
allow(helper).to receive(:current_page?).and_return(true)
|
2016-02-27 01:28:08 +11:00
|
|
|
|
2017-04-10 01:11:37 +10:00
|
|
|
result = helper.active_nav_class("/test")
|
|
|
|
expect(result).to eq "active"
|
2018-09-24 04:42:13 +10:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns active when on a current page' do
|
|
|
|
allow(helper).to receive(:current_page?).with('/foo').and_return(false)
|
|
|
|
allow(helper).to receive(:current_page?).with('/test').and_return(true)
|
|
|
|
|
|
|
|
result = helper.active_nav_class('/foo', '/test')
|
|
|
|
expect(result).to eq "active"
|
2017-04-10 01:11:37 +10:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns empty string when not on current page' do
|
|
|
|
allow(helper).to receive(:current_page?).and_return(false)
|
|
|
|
|
|
|
|
result = helper.active_nav_class("/test")
|
|
|
|
expect(result).to eq ""
|
|
|
|
end
|
|
|
|
end
|
2017-04-16 11:40:33 +10:00
|
|
|
|
2018-08-26 06:55:25 +10:00
|
|
|
describe 'locale_direction' do
|
2017-06-01 01:09:28 +10:00
|
|
|
around do |example|
|
|
|
|
current_locale = I18n.locale
|
|
|
|
example.run
|
|
|
|
I18n.locale = current_locale
|
|
|
|
end
|
|
|
|
|
2017-05-30 02:03:37 +10:00
|
|
|
it 'adds rtl body class if locale is Arabic' do
|
|
|
|
I18n.locale = :ar
|
2018-08-26 06:55:25 +10:00
|
|
|
expect(helper.locale_direction).to eq 'rtl'
|
2017-05-30 02:03:37 +10:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'adds rtl body class if locale is Farsi' do
|
|
|
|
I18n.locale = :fa
|
2018-08-26 06:55:25 +10:00
|
|
|
expect(helper.locale_direction).to eq 'rtl'
|
2017-05-30 02:03:37 +10:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'adds rtl if locale is Hebrew' do
|
|
|
|
I18n.locale = :he
|
2018-08-26 06:55:25 +10:00
|
|
|
expect(helper.locale_direction).to eq 'rtl'
|
2017-05-30 02:03:37 +10:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not add rtl if locale is Thai' do
|
|
|
|
I18n.locale = :th
|
2018-08-26 06:55:25 +10:00
|
|
|
expect(helper.locale_direction).to_not eq 'rtl'
|
2017-05-30 02:03:37 +10:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'fa_icon' do
|
|
|
|
it 'returns a tag of fixed-width cog' do
|
2018-09-28 10:11:14 +10:00
|
|
|
expect(helper.fa_icon('cog fw')).to eq '<i class="fa fa-cog fa-fw"></i>'
|
2017-05-30 02:03:37 +10:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'favicon_path' do
|
2022-03-07 08:51:40 +11:00
|
|
|
it 'returns /favicon.ico on production environment' do
|
2017-05-30 02:03:37 +10:00
|
|
|
expect(Rails.env).to receive(:production?).and_return(true)
|
|
|
|
expect(helper.favicon_path).to eq '/favicon.ico'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'open_registrations?' do
|
|
|
|
it 'returns true when open for registrations' do
|
|
|
|
without_partial_double_verification do
|
2019-03-14 15:28:30 +11:00
|
|
|
expect(Setting).to receive(:registrations_mode).and_return('open')
|
2017-05-30 02:03:37 +10:00
|
|
|
end
|
|
|
|
|
|
|
|
expect(helper.open_registrations?).to eq true
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false when closed for registrations' do
|
|
|
|
without_partial_double_verification do
|
2019-03-14 15:28:30 +11:00
|
|
|
expect(Setting).to receive(:registrations_mode).and_return('none')
|
2017-05-30 02:03:37 +10:00
|
|
|
end
|
|
|
|
|
|
|
|
expect(helper.open_registrations?).to eq false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-04-16 11:40:33 +10:00
|
|
|
describe 'show_landing_strip?', without_verify_partial_doubles: true do
|
|
|
|
describe 'when signed in' do
|
|
|
|
before do
|
|
|
|
allow(helper).to receive(:user_signed_in?).and_return(true)
|
|
|
|
end
|
|
|
|
it 'does not show landing strip' do
|
|
|
|
expect(helper.show_landing_strip?).to eq false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'when signed out' do
|
|
|
|
before do
|
|
|
|
allow(helper).to receive(:user_signed_in?).and_return(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not show landing strip on single user instance' do
|
|
|
|
allow(helper).to receive(:single_user_mode?).and_return(true)
|
|
|
|
|
|
|
|
expect(helper.show_landing_strip?).to eq false
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows landing strip on multi user instance' do
|
|
|
|
allow(helper).to receive(:single_user_mode?).and_return(false)
|
|
|
|
|
|
|
|
expect(helper.show_landing_strip?).to eq true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-05-30 02:03:37 +10:00
|
|
|
|
|
|
|
describe 'title' do
|
2017-05-30 20:29:48 +10:00
|
|
|
around do |example|
|
|
|
|
site_title = Setting.site_title
|
|
|
|
example.run
|
|
|
|
Setting.site_title = site_title
|
|
|
|
end
|
|
|
|
|
2017-05-30 02:03:37 +10:00
|
|
|
it 'returns site title on production enviroment' do
|
|
|
|
Setting.site_title = 'site title'
|
|
|
|
expect(Rails.env).to receive(:production?).and_return(true)
|
|
|
|
expect(helper.title).to eq 'site title'
|
|
|
|
end
|
|
|
|
end
|
2016-02-27 01:28:08 +11:00
|
|
|
end
|