stark_parameters 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/stark_parameters.rb +2 -2
- data/lib/stark_parameters/version.rb +1 -1
- data/spec/lib/stark_parameters_spec.rb +20 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ODY0YTZhN2FmZGI4MjMwNGQwOWEzOWU3MmM0ZWRiN2IzYzNmNmQyMg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YTdiZDY1YTI3NGIyMzc4NTVjNTAyNGU5MjFlNGMwMDE2YWNjNjhkOQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MTFmOGIxYWU4ZDQ4NmM4NDZiNGI4MzFjMmUwYzc4ZDI0YzFmZjM3M2YyZGQw
|
10
|
+
MTM4Mzg2MmUzMTAzOGViOGMyZmMzZGVmMjRmYzBmNDYwYWY2ZWI5YzhlODZj
|
11
|
+
YTlkNzE1YTM1ZTU4MjRlYmE5YTA0NmQ2NDk5ZTFiMTM3MDliYjg=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
Njk4NjE3OTRjZmRlNGRjYThiZWYxY2Y2NTRhODQzZDcyZTNiMjFkODNlMzY5
|
14
|
+
MzdkZWIyYjExNDMzYjllZTgyMGRiNmU3YjExMTkxMDhmYzFkZDUwMDhmZDE2
|
15
|
+
NzNiOGNjNzZjNzNjOGNmMTI4YmM0YzdjMzI3YzVmYWM5MzhhYTY=
|
data/lib/stark_parameters.rb
CHANGED
@@ -32,7 +32,7 @@ module StarkParameters
|
|
32
32
|
permitted_key = permitted_param.is_a?(Hash) ? permitted_param.keys.first : permitted_param
|
33
33
|
name = self.class.aliases[permitted_key] || permitted_key
|
34
34
|
permitted_value = respond_to?(name) ? send(name) : @params.permit(permitted_param)[name]
|
35
|
-
hash[name] = permitted_value if @params.has_key?(permitted_key)
|
35
|
+
hash[name] = permitted_value if (@params.has_key?(permitted_key) || respond_to?(name))
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
@@ -96,4 +96,4 @@ module StarkParameters
|
|
96
96
|
@permitted_params.push permitted_param
|
97
97
|
end
|
98
98
|
end
|
99
|
-
end
|
99
|
+
end
|
@@ -34,7 +34,7 @@ describe StarkParameters do
|
|
34
34
|
it { expect(validator.params.to_hash).to include("login" => "ryan@6wunderkinder.com") }
|
35
35
|
it { expect(validator.params.to_hash.keys).to_not include("email") }
|
36
36
|
|
37
|
-
it { expect(validator.params.permitted?).to
|
37
|
+
it { expect(validator.params.permitted?).to eq(true) }
|
38
38
|
end
|
39
39
|
|
40
40
|
context "when required param is missing" do
|
@@ -111,7 +111,7 @@ describe StarkParameters do
|
|
111
111
|
it { expect(validator.params.to_hash).to include("name" => "Steve") }
|
112
112
|
end
|
113
113
|
|
114
|
-
context "with default values provided by methods" do
|
114
|
+
context "with default values provided by methods for required keys" do
|
115
115
|
let(:test_klass) do
|
116
116
|
Class.new do
|
117
117
|
include StarkParameters
|
@@ -128,6 +128,23 @@ describe StarkParameters do
|
|
128
128
|
it { expect(validator.params.to_hash).to include("foo" => "bar") }
|
129
129
|
end
|
130
130
|
|
131
|
+
context "with default values provided by methods for permitted keys" do
|
132
|
+
let(:test_klass) do
|
133
|
+
Class.new do
|
134
|
+
include StarkParameters
|
135
|
+
|
136
|
+
permit :foo
|
137
|
+
|
138
|
+
def foo
|
139
|
+
"bar"
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
let(:validator) { test_klass.new({}) }
|
145
|
+
it { expect(validator.params.to_hash).to include("foo" => "bar") }
|
146
|
+
end
|
147
|
+
|
131
148
|
context "with empty permitted value" do
|
132
149
|
let(:test_klass) do
|
133
150
|
Class.new do
|
@@ -140,4 +157,4 @@ describe StarkParameters do
|
|
140
157
|
let(:validator) { test_klass.new({foo: nil}) }
|
141
158
|
it { expect(validator.params.to_hash).to include("foo" => nil) }
|
142
159
|
end
|
143
|
-
end
|
160
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stark_parameters
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- rylev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-02-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|