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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZWE2MGVlODNmMDkxMWIxYzA1NDA0MWZjMGQ4YTJiODljMDZiZTJjYw==
4
+ ODY0YTZhN2FmZGI4MjMwNGQwOWEzOWU3MmM0ZWRiN2IzYzNmNmQyMg==
5
5
  data.tar.gz: !binary |-
6
- ODk4N2ZmZWE3MGE0NWFhN2Y4ZmMzZThmMjVjOGYwNjI3YjI2OTg3OA==
6
+ YTdiZDY1YTI3NGIyMzc4NTVjNTAyNGU5MjFlNGMwMDE2YWNjNjhkOQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- OWJjOWMwMGYwZmE0MzRkZjU5OGE5ODBiMDhjYWQyYTIwYjFhMDFiZDAzOWYy
10
- YmU1ZDQ3Y2QwZjhiYzU3OGExYWZmMmEwODBiYTVmYjhkZTQwMmJkZTkzYzY4
11
- YjBmMjhjZjU3ZmFjNTg3MWNmMTA0YTFmYWI4ZDIzYTMwNThkZTk=
9
+ MTFmOGIxYWU4ZDQ4NmM4NDZiNGI4MzFjMmUwYzc4ZDI0YzFmZjM3M2YyZGQw
10
+ MTM4Mzg2MmUzMTAzOGViOGMyZmMzZGVmMjRmYzBmNDYwYWY2ZWI5YzhlODZj
11
+ YTlkNzE1YTM1ZTU4MjRlYmE5YTA0NmQ2NDk5ZTFiMTM3MDliYjg=
12
12
  data.tar.gz: !binary |-
13
- MTViN2VhMzI0Y2MyZjg4NTZiZmFjM2VmMGI3MzkyMzY2MjI3M2Q5Mjk2M2Jm
14
- NWM4MmY0N2NiNjFiNGVhODQwMjIzOGVhNmQxNzAyZTgzMGI4ZjU0MWMwZGRj
15
- MjM1ZDVmNzQ3MjcyNmVmOGZiNjAwMjUyYzE2MDBkNmU2NzNmYzY=
13
+ Njk4NjE3OTRjZmRlNGRjYThiZWYxY2Y2NTRhODQzZDcyZTNiMjFkODNlMzY5
14
+ MzdkZWIyYjExNDMzYjllZTgyMGRiNmU3YjExMTkxMDhmYzFkZDUwMDhmZDE2
15
+ NzNiOGNjNzZjNzNjOGNmMTI4YmM0YzdjMzI3YzVmYWM5MzhhYTY=
@@ -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
@@ -1,3 +1,3 @@
1
1
  module StarkParameters
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  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 be_true }
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
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: 2014-07-24 00:00:00.000000000 Z
11
+ date: 2015-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack