sinatra-my-params 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/permit_params.rb +3 -0
- data/spec/permit_params_spec.rb +13 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 004ffa9a419a6ca94f76672d37e9cd242aca9f69ca1c92ada97ac135a1329abc
|
4
|
+
data.tar.gz: a0dcc3771df668d6356a4443e98cd1bcb4d1ad6e877076bbc3cc5f99e904a078
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04d4e285426806ac16f36f7b757eed7682d1502c272dedf7f0fd3291234e9cf3eb611c52c25a73cca3f3b29d6190ed83523cde335125599cfb92f81e2eee8c17
|
7
|
+
data.tar.gz: 861c6fc9858865ac856e66ed030f5bd8ac7005b268c3a3a2cb66deec648feec52b1c596808e6736b4495bf20e1fe7e4e818ccbfa8ebb24fe2727d77511bb13cf
|
data/lib/permit_params.rb
CHANGED
@@ -20,8 +20,11 @@ module PermitParams
|
|
20
20
|
private
|
21
21
|
|
22
22
|
Boolean = :boolean
|
23
|
+
Any = :any
|
23
24
|
|
24
25
|
def coerce(param, type, strong_validation = false, options = {})
|
26
|
+
return param if type == Any
|
27
|
+
|
25
28
|
begin
|
26
29
|
return nil if param.nil?
|
27
30
|
return param if (param.is_a?(type) rescue false)
|
data/spec/permit_params_spec.rb
CHANGED
@@ -6,6 +6,10 @@ require "rack/test"
|
|
6
6
|
include PermitParams
|
7
7
|
|
8
8
|
describe "exceptions" do
|
9
|
+
before do
|
10
|
+
class TestClass; end
|
11
|
+
end
|
12
|
+
|
9
13
|
it "should raise error when at least one param is invalid" do
|
10
14
|
input = { param_1: "a" }
|
11
15
|
expect{
|
@@ -91,6 +95,15 @@ describe "exceptions" do
|
|
91
95
|
)
|
92
96
|
end
|
93
97
|
|
98
|
+
it "returns the paramter without casting if Any" do
|
99
|
+
input = { param_1: "1" }
|
100
|
+
output = { param_1: "1" }
|
101
|
+
expect(output).to eq permitted_params(input, { param_1: Any })
|
102
|
+
|
103
|
+
input = { param_1: TestClass.new }
|
104
|
+
expect(input).to eq permitted_params(input, { param_1: Any })
|
105
|
+
end
|
106
|
+
|
94
107
|
it "should remove a string when a pemitted is integer" do
|
95
108
|
input = { param_1: "a string" }
|
96
109
|
output = {}
|