Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
rails_param
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
ikcrm_common
rails_param
Commits
afd75dcd
Commit
afd75dcd
authored
Mar 10, 2016
by
Vlad Vanca
Committed by
ifool
Mar 27, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix issue with boolean params using a default with block that returns false
parent
e31bc384
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
4 deletions
+16
-4
lib/rails_param/param.rb
+14
-2
spec/rails_param/param_spec.rb
+2
-2
No files found.
lib/rails_param/param.rb
View file @
afd75dcd
...
@@ -19,8 +19,20 @@ module RailsParam
...
@@ -19,8 +19,20 @@ module RailsParam
begin
begin
params
[
name
]
=
coerce
(
params
[
name
],
type
,
options
)
params
[
name
]
=
coerce
(
params
[
name
],
type
,
options
)
params
[
name
]
=
(
options
[
:default
].
call
if
options
[
:default
].
respond_to?
(
:call
))
||
options
[
:default
]
if
params
[
name
].
nil?
and
check_param_presence?
(
options
[
:default
])
params
[
name
]
=
options
[
:transform
].
to_proc
.
call
(
params
[
name
])
if
params
[
name
]
and
options
[
:transform
]
# set default
if
options
[
:default
].
respond_to?
(
:call
)
params
[
name
]
=
options
[
:default
].
call
elsif
params
[
name
].
nil?
&&
check_param_presence?
(
options
[
:default
])
params
[
name
]
=
options
[
:default
]
end
# apply tranformation
if
params
[
name
]
&&
options
[
:transform
]
params
[
name
]
=
options
[
:transform
].
to_proc
.
call
(
params
[
name
])
end
# validate
validate!
(
params
[
name
],
options
)
validate!
(
params
[
name
],
options
)
if
block_given?
if
block_given?
...
...
spec/rails_param/param_spec.rb
View file @
afd75dcd
...
@@ -46,8 +46,8 @@ describe RailsParam::Param do
...
@@ -46,8 +46,8 @@ describe RailsParam::Param do
context
"with a block"
do
context
"with a block"
do
it
"defaults to the block value"
do
it
"defaults to the block value"
do
allow
(
controller
).
to
receive
(
:params
).
and_return
({})
allow
(
controller
).
to
receive
(
:params
).
and_return
({})
controller
.
param!
:
word
,
String
,
default:
lambda
{
"foo"
}
controller
.
param!
:
foo
,
:boolean
,
default:
lambda
{
false
}
expect
(
controller
.
params
[
"
word"
]).
to
eql
(
"foo"
)
expect
(
controller
.
params
[
"
foo"
]).
to
eql
(
false
)
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