Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
7a81dc65
Commit
7a81dc65
authored
Aug 26, 2015
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Re-add user_color_scheme helper
Update PreferencesHelper specs
parent
2d72efcd
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
24 deletions
+59
-24
app/helpers/preferences_helper.rb
app/helpers/preferences_helper.rb
+5
-1
spec/helpers/preferences_helper_spec.rb
spec/helpers/preferences_helper_spec.rb
+54
-23
No files found.
app/helpers/preferences_helper.rb
View file @
7a81dc65
...
@@ -30,7 +30,11 @@ module PreferencesHelper
...
@@ -30,7 +30,11 @@ module PreferencesHelper
end
end
def
user_application_theme
def
user_application_theme
Gitlab
::
Themes
.
by_id
(
current_user
.
try
(
:theme_id
)).
css_class
Gitlab
::
Themes
.
for_user
(
current_user
).
css_class
end
def
user_color_scheme
Gitlab
::
ColorSchemes
.
for_user
(
current_user
).
css_class
end
end
def
prefer_readme?
def
prefer_readme?
...
...
spec/helpers/preferences_helper_spec.rb
View file @
7a81dc65
require
'spec_helper'
require
'spec_helper'
describe
PreferencesHelper
do
describe
PreferencesHelper
do
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
describe
'user_application_theme'
do
describe
'user_application_theme'
do
context
'with a user'
do
context
'with a user'
do
it
"returns user's theme's css_class"
do
it
"returns user's theme's css_class"
do
user
=
double
(
'user'
,
theme_id:
3
)
stub_user
(
theme_id:
3
)
allow
(
self
).
to
receive
(
:current_user
).
and_return
(
user
)
expect
(
user_application_theme
).
to
eq
'ui_green'
expect
(
helper
.
user_application_theme
).
to
eq
'ui_green'
end
end
it
'returns the default when id is invalid'
do
it
'returns the default when id is invalid'
do
user
=
double
(
'user'
,
theme_id:
Gitlab
::
Themes
::
THEMES
.
size
+
5
)
stub_user
(
theme_id:
Gitlab
::
Themes
.
count
+
5
)
allow
(
Gitlab
.
config
.
gitlab
).
to
receive
(
:default_theme
).
and_return
(
2
)
allow
(
Gitlab
.
config
.
gitlab
).
to
receive
(
:default_theme
).
and_return
(
2
)
allow
(
self
).
to
receive
(
:current_user
).
and_return
(
user
)
expect
(
user_application_theme
).
to
eq
'ui_charcoal'
expect
(
helper
.
user_application_theme
).
to
eq
'ui_charcoal'
end
end
end
end
context
'without a user'
do
context
'without a user'
do
before
do
allow
(
self
).
to
receive
(
:current_user
).
and_return
(
nil
)
end
it
'returns the default theme'
do
it
'returns the default theme'
do
expect
(
user_application_theme
).
to
eq
Gitlab
::
Themes
.
default
.
css_class
stub_user
expect
(
helper
.
user_application_theme
).
to
eq
Gitlab
::
Themes
.
default
.
css_class
end
end
end
end
end
end
describe
'dashboard_choices'
do
describe
'user_color_scheme'
do
it
'raises an exception when defined choices may be missing'
do
context
'with a user'
do
expect
(
User
).
to
receive
(
:dashboards
).
and_return
(
foo:
'foo'
)
it
"returns user's scheme's css_class"
do
expect
{
dashboard_choices
}.
to
raise_error
(
RuntimeError
)
allow
(
helper
).
to
receive
(
:current_user
).
and_return
(
double
(
color_scheme_id:
3
))
expect
(
helper
.
user_color_scheme
).
to
eq
'solarized-light'
end
end
it
'raises an exception when defined choices may be using the wrong key'
do
it
'returns the default when id is invalid'
do
expect
(
User
).
to
receive
(
:dashboards
).
and_return
(
foo:
'foo'
,
bar:
'bar'
)
allow
(
helper
).
to
receive
(
:current_user
).
expect
{
dashboard_choices
}.
to
raise_error
(
KeyError
)
and_return
(
double
(
color_scheme_id:
Gitlab
::
ColorSchemes
.
count
+
5
))
end
end
end
it
'provides better option descriptions'
do
context
'without a user'
do
expect
(
dashboard_choices
).
to
match_array
[
it
'returns the default theme'
do
[
'Your Projects (default)'
,
'projects'
],
stub_user
[
'Starred Projects'
,
'stars'
]
]
expect
(
helper
.
user_color_scheme
).
to
eq
Gitlab
::
ColorSchemes
.
default
.
css_class
end
end
end
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
))
end
end
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment