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
f028ba3f
Commit
f028ba3f
authored
Jan 20, 2015
by
stantoncbradley
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add tests for when required array elements are missing
parent
a2093577
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
2 deletions
+50
-2
spec/rails_param/param_spec.rb
+50
-2
No files found.
spec/rails_param/param_spec.rb
View file @
f028ba3f
...
...
@@ -192,8 +192,8 @@ describe RailsParam::Param do
end
end
describe
'validating array
element
s'
do
it
'typecasts array elements'
do
describe
'validating arrays'
do
it
'typecasts array
of primitive
elements'
do
allow
(
controller
).
to
receive
(
:params
).
and_return
({
'array'
=>
[
'1'
,
'2'
]})
controller
.
param!
:array
,
Array
do
|
a
,
i
|
a
.
param!
i
,
Integer
,
required:
true
...
...
@@ -216,6 +216,54 @@ describe RailsParam::Param do
expect
(
controller
.
params
[
'array'
][
1
][
'object'
][
'num'
]).
to
be_a
Integer
expect
(
controller
.
params
[
'array'
][
1
][
'object'
][
'float'
]).
to
be_instance_of
Float
end
it
'validates an array of arrays'
do
params
=
{
'array'
=>
[[
'1'
,
'2'
],[
'3'
,
'4'
]]
}
allow
(
controller
).
to
receive
(
:params
).
and_return
(
params
)
controller
.
param!
:array
,
Array
do
|
a
,
i
|
a
.
param!
i
,
Array
do
|
b
,
e
|
b
.
param!
e
,
Integer
,
required:
true
end
end
expect
(
controller
.
params
[
'array'
][
0
][
0
]).
to
be_a
Integer
expect
(
controller
.
params
[
'array'
][
0
][
1
]).
to
be_a
Integer
expect
(
controller
.
params
[
'array'
][
1
][
0
]).
to
be_a
Integer
expect
(
controller
.
params
[
'array'
][
1
][
1
]).
to
be_a
Integer
end
it
'raises exception when primitive element missing'
do
allow
(
controller
).
to
receive
(
:params
).
and_return
({
'array'
=>
[
'1'
,
nil
]})
expect
{
controller
.
param!
:array
,
Array
do
|
a
,
i
|
a
.
param!
i
,
Integer
,
required:
true
end
}.
to
raise_exception
end
it
'raises exception when nested hash element missing'
do
params
=
{
'array'
=>
[{
'object'
=>
{
'num'
=>
'1'
,
'float'
=>
nil
}},{
'object'
=>
{
'num'
=>
'2'
,
'float'
=>
'2.3'
}}]
}
allow
(
controller
).
to
receive
(
:params
).
and_return
(
params
)
expect
{
controller
.
param!
:array
,
Array
do
|
a
|
a
.
param!
:object
,
Hash
do
|
h
|
h
.
param!
:num
,
Integer
,
required:
true
h
.
param!
:float
,
Float
,
required:
true
end
end
}.
to
raise_exception
end
it
'raises exception when nested array element missing'
do
params
=
{
'array'
=>
[[
'1'
,
'2'
],[
'3'
,
nil
]]
}
allow
(
controller
).
to
receive
(
:params
).
and_return
(
params
)
expect
{
controller
.
param!
:array
,
Array
do
|
a
,
i
|
a
.
param!
i
,
Array
do
|
b
,
e
|
b
.
param!
e
,
Integer
,
required:
true
end
end
}.
to
raise_exception
end
end
describe
"validation"
do
...
...
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