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
5187e6a6
Commit
5187e6a6
authored
Oct 28, 2014
by
cole bradley
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change tabs back to 2 spaces to resemble original style
parent
e17d84f4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
55 additions
and
55 deletions
+55
-55
lib/rails_param/param.rb
+0
-0
spec/fixtures/controllers.rb
+11
-11
spec/rails_integration_spec.rb
+44
-44
spec/rails_param/param_spec.rb
+0
-0
No files found.
lib/rails_param/param.rb
View file @
5187e6a6
This diff is collapsed.
Click to expand it.
spec/fixtures/controllers.rb
View file @
5187e6a6
...
@@ -18,17 +18,17 @@ class FakeController < ActionController::Base
...
@@ -18,17 +18,17 @@ class FakeController < ActionController::Base
render
text:
"new"
render
text:
"new"
end
end
def
edit
def
edit
param!
:book
,
Hash
,
required:
true
do
|
b
|
param!
:book
,
Hash
,
required:
true
do
|
b
|
b
.
param!
:title
,
String
,
required:
true
b
.
param!
:title
,
String
,
required:
true
b
.
param!
:author
,
Hash
do
|
a
|
b
.
param!
:author
,
Hash
do
|
a
|
a
.
param!
:first_name
,
String
,
required:
true
a
.
param!
:first_name
,
String
,
required:
true
a
.
param!
:last_name
,
String
,
required:
true
a
.
param!
:last_name
,
String
,
required:
true
a
.
param!
:age
,
Integer
,
required:
true
a
.
param!
:age
,
Integer
,
required:
true
end
end
b
.
param!
:price
,
BigDecimal
,
required:
true
b
.
param!
:price
,
BigDecimal
,
required:
true
end
render
text: :book
end
end
render
text: :book
end
end
end
spec/rails_integration_spec.rb
View file @
5187e6a6
...
@@ -11,51 +11,51 @@ describe FakeController, type: :controller do
...
@@ -11,51 +11,51 @@ describe FakeController, type: :controller do
end
end
describe
"nested_hash"
do
describe
"nested_hash"
do
it
"validates nested properties"
do
it
"validates nested properties"
do
params
=
{
params
=
{
'book'
=>
{
'book'
=>
{
'title'
=>
'One Hundred Years of Solitude'
,
'title'
=>
'One Hundred Years of Solitude'
,
'author'
=>
{
'author'
=>
{
'first_name'
=>
'Garbriel Garcia'
,
'first_name'
=>
'Garbriel Garcia'
,
'last_name'
=>
'Marquez'
,
'last_name'
=>
'Marquez'
,
'age'
=>
'70'
'age'
=>
'70'
},
},
'price'
=>
'$1,000.00'
'price'
=>
'$1,000.00'
}}
}}
get
:edit
,
params
get
:edit
,
params
expect
(
controller
.
params
[
:book
][
:author
][
:age
]).
to
eql
70
expect
(
controller
.
params
[
:book
][
:author
][
:age
]).
to
eql
70
expect
(
controller
.
params
[
:book
][
:author
][
:age
]).
to
be_kind_of
Integer
expect
(
controller
.
params
[
:book
][
:author
][
:age
]).
to
be_kind_of
Integer
expect
(
controller
.
params
[
:book
][
:price
]).
to
eql
1000.0
expect
(
controller
.
params
[
:book
][
:price
]).
to
eql
1000.0
expect
(
controller
.
params
[
:book
][
:price
]).
to
be_instance_of
BigDecimal
expect
(
controller
.
params
[
:book
][
:price
]).
to
be_instance_of
BigDecimal
end
end
it
"raises error when required nested attribute missing"
do
it
"raises error when required nested attribute missing"
do
params
=
{
params
=
{
'book'
=>
{
'book'
=>
{
'title'
=>
'One Hundred Years of Solitude'
,
'title'
=>
'One Hundred Years of Solitude'
,
'author'
=>
{
'author'
=>
{
'last_name'
=>
'Marquez'
,
'last_name'
=>
'Marquez'
,
'age'
=>
'70'
'age'
=>
'70'
},
},
'price'
=>
'$1,000.00'
'price'
=>
'$1,000.00'
}}
}}
expect
{
get
:edit
,
params
}.
to
raise_error
{
|
error
|
expect
{
get
:edit
,
params
}.
to
raise_error
{
|
error
|
expect
(
error
).
to
be_a
(
RailsParam
::
Param
::
InvalidParameterError
)
expect
(
error
).
to
be_a
(
RailsParam
::
Param
::
InvalidParameterError
)
expect
(
error
.
param
).
to
eql
(
"first_name"
)
expect
(
error
.
param
).
to
eql
(
"first_name"
)
expect
(
error
.
options
).
to
eql
({
:required
=>
true
})
expect
(
error
.
options
).
to
eql
({
:required
=>
true
})
}
}
end
end
it
"passes when hash that's not required but has required attributes is missing"
do
it
"passes when hash that's not required but has required attributes is missing"
do
params
=
{
params
=
{
'book'
=>
{
'book'
=>
{
'title'
=>
'One Hundred Years of Solitude'
,
'title'
=>
'One Hundred Years of Solitude'
,
'price'
=>
'$1,000.00'
'price'
=>
'$1,000.00'
}}
}}
get
:edit
,
params
get
:edit
,
params
expect
(
controller
.
params
[
:book
][
:price
]).
to
eql
1000.0
expect
(
controller
.
params
[
:book
][
:price
]).
to
eql
1000.0
expect
(
controller
.
params
[
:book
][
:price
]).
to
be_instance_of
BigDecimal
expect
(
controller
.
params
[
:book
][
:price
]).
to
be_instance_of
BigDecimal
end
end
end
end
describe
"InvalidParameterError"
do
describe
"InvalidParameterError"
do
...
@@ -63,7 +63,7 @@ describe FakeController, type: :controller do
...
@@ -63,7 +63,7 @@ describe FakeController, type: :controller do
expect
{
get
:index
,
sort:
"foo"
}.
to
raise_error
{
|
error
|
expect
{
get
:index
,
sort:
"foo"
}.
to
raise_error
{
|
error
|
expect
(
error
).
to
be_a
(
RailsParam
::
Param
::
InvalidParameterError
)
expect
(
error
).
to
be_a
(
RailsParam
::
Param
::
InvalidParameterError
)
expect
(
error
.
param
).
to
eql
(
"sort"
)
expect
(
error
.
param
).
to
eql
(
"sort"
)
expect
(
error
.
options
).
to
eql
({
:in
=>
[
"asc"
,
"desc"
],
:default
=>
"asc"
,
:transform
=>
:downcase
})
expect
(
error
.
options
).
to
eql
({
:in
=>
[
"asc"
,
"desc"
],
:default
=>
"asc"
,
:transform
=>
:downcase
})
}
}
end
end
end
end
...
...
spec/rails_param/param_spec.rb
View file @
5187e6a6
This diff is collapsed.
Click to expand it.
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