Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mastodon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pierre Boudes
mastodon
Commits
b4f38edf
Unverified
Commit
b4f38edf
authored
1 year ago
by
Christian Schmidt
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Wrong type for user setting when default is defined by lambda (#24321)
parent
68a192e7
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/models/user_settings/setting.rb
+2
-1
2 additions, 1 deletion
app/models/user_settings/setting.rb
spec/models/user_settings/setting_spec.rb
+32
-0
32 additions, 0 deletions
spec/models/user_settings/setting_spec.rb
with
34 additions
and
1 deletion
app/models/user_settings/setting.rb
+
2
−
1
View file @
b4f38edf
...
...
@@ -19,7 +19,8 @@ class UserSettings::Setting
end
def
type
if
@default_value
.
is_a?
(
TrueClass
)
||
@default_value
.
is_a?
(
FalseClass
)
case
default_value
when
TrueClass
,
FalseClass
ActiveModel
::
Type
::
Boolean
.
new
else
ActiveModel
::
Type
::
String
.
new
...
...
This diff is collapsed.
Click to expand it.
spec/models/user_settings/setting_spec.rb
+
32
−
0
View file @
b4f38edf
...
...
@@ -30,6 +30,38 @@ RSpec.describe UserSettings::Setting do
it
'returns a type'
do
expect
(
subject
.
type
).
to
be_a
ActiveModel
::
Type
::
Value
end
context
'when default value is a boolean'
do
let
(
:default
)
{
false
}
it
'returns boolean'
do
expect
(
subject
.
type
).
to
be_a
ActiveModel
::
Type
::
Boolean
end
end
context
'when default value is a string'
do
let
(
:default
)
{
''
}
it
'returns string'
do
expect
(
subject
.
type
).
to
be_a
ActiveModel
::
Type
::
String
end
end
context
'when default value is a lambda returning a boolean'
do
let
(
:default
)
{
->
{
false
}
}
it
'returns boolean'
do
expect
(
subject
.
type
).
to
be_a
ActiveModel
::
Type
::
Boolean
end
end
context
'when default value is a lambda returning a string'
do
let
(
:default
)
{
->
{
''
}
}
it
'returns boolean'
do
expect
(
subject
.
type
).
to
be_a
ActiveModel
::
Type
::
String
end
end
end
describe
'#type_cast'
do
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment