debian-mirror-gitlab/spec/helpers/preferences_helper_spec.rb

83 lines
2.3 KiB
Ruby
Raw Normal View History

2015-09-11 14:41:01 +05:30
require 'spec_helper'
describe PreferencesHelper do
2015-09-25 12:07:36 +05:30
describe 'dashboard_choices' do
it 'raises an exception when defined choices may be missing' do
expect(User).to receive(:dashboards).and_return(foo: 'foo')
expect { helper.dashboard_choices }.to raise_error(RuntimeError)
end
it 'raises an exception when defined choices may be using the wrong key' do
expect(User).to receive(:dashboards).and_return(foo: 'foo', bar: 'bar')
expect { helper.dashboard_choices }.to raise_error(KeyError)
end
it 'provides better option descriptions' do
expect(helper.dashboard_choices).to match_array [
['Your Projects (default)', 'projects'],
['Starred Projects', 'stars']
]
end
end
2015-09-11 14:41:01 +05:30
describe 'user_application_theme' do
context 'with a user' do
it "returns user's theme's css_class" do
2015-09-25 12:07:36 +05:30
stub_user(theme_id: 3)
expect(helper.user_application_theme).to eq 'ui_green'
2015-09-11 14:41:01 +05:30
end
it 'returns the default when id is invalid' do
2015-09-25 12:07:36 +05:30
stub_user(theme_id: Gitlab::Themes.count + 5)
2015-09-11 14:41:01 +05:30
allow(Gitlab.config.gitlab).to receive(:default_theme).and_return(2)
2015-09-25 12:07:36 +05:30
expect(helper.user_application_theme).to eq 'ui_charcoal'
2015-09-11 14:41:01 +05:30
end
end
context 'without a user' do
it 'returns the default theme' do
2015-09-25 12:07:36 +05:30
stub_user
expect(helper.user_application_theme).to eq Gitlab::Themes.default.css_class
2015-09-11 14:41:01 +05:30
end
end
end
2015-09-25 12:07:36 +05:30
describe 'user_color_scheme' do
context 'with a user' do
it "returns user's scheme's css_class" do
allow(helper).to receive(:current_user).
and_return(double(color_scheme_id: 3))
2015-09-11 14:41:01 +05:30
2015-09-25 12:07:36 +05:30
expect(helper.user_color_scheme).to eq 'solarized-light'
end
2015-09-11 14:41:01 +05:30
2015-09-25 12:07:36 +05:30
it 'returns the default when id is invalid' do
allow(helper).to receive(:current_user).
and_return(double(color_scheme_id: Gitlab::ColorSchemes.count + 5))
end
2015-09-11 14:41:01 +05:30
end
2015-09-25 12:07:36 +05:30
context 'without a user' do
it 'returns the default theme' do
stub_user
expect(helper.user_color_scheme).
to eq Gitlab::ColorSchemes.default.css_class
2015-09-11 14:41:01 +05:30
end
end
2015-09-25 12:07:36 +05:30
end
2015-09-11 14:41:01 +05:30
2015-09-25 12:07:36 +05:30
def stub_user(messages = {})
if messages.empty?
allow(helper).to receive(:current_user).and_return(nil)
else
allow(helper).to receive(:current_user).
and_return(double('user', messages))
2015-09-11 14:41:01 +05:30
end
end
end