2015-06-05 19:53:57 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe PreferencesHelper do
|
2017-09-11 15:44:42 +00:00
|
|
|
describe '#dashboard_choices' do
|
2015-08-26 18:33:44 +00:00
|
|
|
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
|
2015-09-26 00:04:20 +00:00
|
|
|
dashboards = User.dashboards.dup
|
|
|
|
dashboards[:projects_changed] = dashboards.delete :projects
|
|
|
|
expect(User).to receive(:dashboards).and_return(dashboards)
|
2015-08-26 18:33:44 +00:00
|
|
|
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'],
|
2015-09-26 00:04:20 +00:00
|
|
|
['Starred Projects', 'stars'],
|
|
|
|
["Your Projects' Activity", 'project_activity'],
|
2016-03-24 10:12:45 +00:00
|
|
|
["Starred Projects' Activity", 'starred_project_activity'],
|
|
|
|
["Your Groups", 'groups'],
|
|
|
|
["Your Todos", 'todos']
|
2015-08-26 18:33:44 +00:00
|
|
|
]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-09-11 15:44:42 +00:00
|
|
|
describe '#user_application_theme' do
|
|
|
|
context 'with a user' do
|
|
|
|
it "returns user's theme's css_class" do
|
|
|
|
stub_user(theme_id: 3)
|
|
|
|
|
|
|
|
expect(helper.user_application_theme).to eq 'ui_light'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the default when id is invalid' do
|
|
|
|
stub_user(theme_id: Gitlab::Themes.count + 5)
|
|
|
|
|
|
|
|
allow(Gitlab.config.gitlab).to receive(:default_theme).and_return(1)
|
|
|
|
|
|
|
|
expect(helper.user_application_theme).to eq 'ui_indigo'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'without a user' do
|
|
|
|
it 'returns the default theme' do
|
|
|
|
stub_user
|
|
|
|
|
|
|
|
expect(helper.user_application_theme).to eq Gitlab::Themes.default.css_class
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#user_color_scheme' do
|
2015-08-26 18:33:44 +00:00
|
|
|
context 'with a user' do
|
|
|
|
it "returns user's scheme's css_class" do
|
2017-06-21 13:48:12 +00:00
|
|
|
allow(helper).to receive(:current_user)
|
|
|
|
.and_return(double(color_scheme_id: 3))
|
2015-08-26 18:33:44 +00:00
|
|
|
|
|
|
|
expect(helper.user_color_scheme).to eq 'solarized-light'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the default when id is invalid' do
|
2017-06-21 13:48:12 +00:00
|
|
|
allow(helper).to receive(:current_user)
|
|
|
|
.and_return(double(color_scheme_id: Gitlab::ColorSchemes.count + 5))
|
2015-08-26 18:33:44 +00:00
|
|
|
end
|
2015-06-13 00:39:48 +00:00
|
|
|
end
|
2015-06-10 08:42:02 +00:00
|
|
|
|
2015-08-26 18:33:44 +00:00
|
|
|
context 'without a user' do
|
|
|
|
it 'returns the default theme' do
|
|
|
|
stub_user
|
|
|
|
|
2017-06-21 13:48:12 +00:00
|
|
|
expect(helper.user_color_scheme)
|
|
|
|
.to eq Gitlab::ColorSchemes.default.css_class
|
2015-08-26 18:33:44 +00:00
|
|
|
end
|
2015-06-10 08:42:02 +00:00
|
|
|
end
|
2015-08-26 18:33:44 +00:00
|
|
|
end
|
2015-06-10 08:42:02 +00:00
|
|
|
|
2015-08-26 18:33:44 +00:00
|
|
|
def stub_user(messages = {})
|
|
|
|
if messages.empty?
|
|
|
|
allow(helper).to receive(:current_user).and_return(nil)
|
|
|
|
else
|
2017-06-21 13:48:12 +00:00
|
|
|
allow(helper).to receive(:current_user)
|
|
|
|
.and_return(double('user', messages))
|
2015-06-10 08:42:02 +00:00
|
|
|
end
|
|
|
|
end
|
2016-11-08 17:43:19 +00:00
|
|
|
|
2016-11-16 18:20:05 +00:00
|
|
|
describe '#default_project_view' do
|
2016-11-08 17:43:19 +00:00
|
|
|
context 'user not signed in' do
|
2016-11-15 14:21:05 +00:00
|
|
|
before do
|
2016-11-16 18:20:05 +00:00
|
|
|
helper.instance_variable_set(:@project, project)
|
2016-11-15 14:21:05 +00:00
|
|
|
stub_user
|
|
|
|
end
|
2016-11-08 17:43:19 +00:00
|
|
|
|
2016-11-16 18:20:05 +00:00
|
|
|
context 'when repository is empty' do
|
|
|
|
let(:project) { create(:project_empty_repo, :public) }
|
|
|
|
|
|
|
|
it 'returns activity if user has repository access' do
|
|
|
|
allow(helper).to receive(:can?).with(nil, :download_code, project).and_return(true)
|
|
|
|
|
|
|
|
expect(helper.default_project_view).to eq('activity')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns activity if user does not have repository access' do
|
|
|
|
allow(helper).to receive(:can?).with(nil, :download_code, project).and_return(false)
|
|
|
|
|
|
|
|
expect(helper.default_project_view).to eq('activity')
|
|
|
|
end
|
2016-11-08 17:43:19 +00:00
|
|
|
end
|
|
|
|
|
2016-11-16 18:20:05 +00:00
|
|
|
context 'when repository is not empty' do
|
2017-01-25 22:10:32 +00:00
|
|
|
let(:project) { create(:project, :public, :repository) }
|
2016-11-16 18:20:05 +00:00
|
|
|
|
2017-04-06 14:52:15 +00:00
|
|
|
it 'returns files and readme if user has repository access' do
|
2016-11-16 18:20:05 +00:00
|
|
|
allow(helper).to receive(:can?).with(nil, :download_code, project).and_return(true)
|
|
|
|
|
2017-04-06 14:52:15 +00:00
|
|
|
expect(helper.default_project_view).to eq('files')
|
2016-11-16 18:20:05 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns activity if user does not have repository access' do
|
|
|
|
allow(helper).to receive(:can?).with(nil, :download_code, project).and_return(false)
|
2016-11-08 17:43:19 +00:00
|
|
|
|
2016-11-16 18:20:05 +00:00
|
|
|
expect(helper.default_project_view).to eq('activity')
|
|
|
|
end
|
2016-11-08 17:43:19 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-06-05 19:53:57 +00:00
|
|
|
end
|