simple_params 1.3.6 → 1.4.0
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 +8 -8
- data/Gemfile.lock +1 -1
- data/lib/simple_params/nested_params.rb +7 -4
- data/lib/simple_params/params.rb +9 -1
- data/lib/simple_params/version.rb +1 -1
- data/spec/acceptance_spec.rb +77 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
N2FhZWYzZTAzNmJhMmE3YjYxOThlNDhkMzM5NzlhYmQxNTMxOTQ5OQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OWQ3NmQwYzA2OGZlNTNkNTM4MTY3ZjQ5M2FjNDU3YWU0ODRkZTE5ZQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZDQwMDY2MzZjMTAxNmI1OTAzM2Q5M2VjY2M3YjgzY2E5NzI4ODM1Njk3YTYw
|
10
|
+
MzQxZWI0N2VjNDg3YTA3Y2MxOGVlMGMxYWM1OWJlNGQ2MzJhYjM1MzExMjU2
|
11
|
+
YWEwMTk5M2Q4NmE1ZTY0YWJkZWFmZjIyY2JkNWE4MWViYWQ1Y2I=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NzQ1N2U2MWMxNTg4OGQwMWViYmZlOTFlOGQ2ZjMyNjQyY2JjMDJlZDYwZDBm
|
14
|
+
NjJiNWQzZDdkMzYxMThlYTViNDMyNTM3NGNlZjc1ZmQ2Yjg3YWI4MzBiMmVi
|
15
|
+
MTU5N2QyMTM1ZWFmMDQwZGQ3OGZmMDRiMzJhODc2NzE5ODJlNWE=
|
data/Gemfile.lock
CHANGED
@@ -38,14 +38,17 @@ module SimpleParams
|
|
38
38
|
#{parent}
|
39
39
|
end
|
40
40
|
DEF
|
41
|
+
extend ActiveModel::Naming
|
42
|
+
klass.class_eval(&block)
|
43
|
+
klass.class_eval("self.options = #{options}")
|
41
44
|
if klass.parent_class.using_rails_helpers?
|
42
45
|
klass.instance_eval("with_rails_helpers")
|
43
|
-
|
46
|
+
end
|
47
|
+
|
48
|
+
# define a _destroy param (Boolean, default: false)
|
49
|
+
if klass.using_rails_helpers?
|
44
50
|
klass.send(:define_attribute, :_destroy, {type: :boolean, default: false})
|
45
51
|
end
|
46
|
-
extend ActiveModel::Naming
|
47
|
-
klass.class_eval(&block)
|
48
|
-
klass.class_eval("self.options = #{options}")
|
49
52
|
end
|
50
53
|
end
|
51
54
|
end
|
data/lib/simple_params/params.rb
CHANGED
@@ -86,7 +86,15 @@ module SimpleParams
|
|
86
86
|
init_value = if initializer.is_a?(Array)
|
87
87
|
if klass.with_ids?
|
88
88
|
initializer.first.each_pair.inject([]) do |array, (key, val)|
|
89
|
-
|
89
|
+
destroyed = if val.has_key?(:_destroy)
|
90
|
+
val[:_destroy]
|
91
|
+
elsif val.has_key?("_destroy")
|
92
|
+
val["_destroy"]
|
93
|
+
end
|
94
|
+
unless [true, "1"].include?(destroyed)
|
95
|
+
array << klass.new({key => val}, self)
|
96
|
+
end
|
97
|
+
array
|
90
98
|
end
|
91
99
|
else
|
92
100
|
initializer.map { |val| klass.new(val, self) }
|
data/spec/acceptance_spec.rb
CHANGED
@@ -28,6 +28,11 @@ class AcceptanceParams < SimpleParams::Params
|
|
28
28
|
param :age, type: :integer, validations: { inclusion: { in: 1..20 } }
|
29
29
|
end
|
30
30
|
|
31
|
+
nested_array :cats, with_ids: true do
|
32
|
+
with_rails_helpers
|
33
|
+
param :name
|
34
|
+
end
|
35
|
+
|
31
36
|
def name_has_letters
|
32
37
|
if name.present? && !(name =~ /^[a-zA-Z]*$/)
|
33
38
|
errors.add(:name, "must only contain letters")
|
@@ -111,6 +116,12 @@ describe SimpleParams::Params do
|
|
111
116
|
name: "Spot",
|
112
117
|
age: 8
|
113
118
|
}
|
119
|
+
],
|
120
|
+
cats: [
|
121
|
+
{
|
122
|
+
name: nil,
|
123
|
+
_destroy: false
|
124
|
+
}
|
114
125
|
]
|
115
126
|
})
|
116
127
|
end
|
@@ -204,7 +215,7 @@ describe SimpleParams::Params do
|
|
204
215
|
describe "attributes", attributes: true do
|
205
216
|
it "returns array of attribute symbols" do
|
206
217
|
params = AcceptanceParams.new
|
207
|
-
params.attributes.should eq([:reference, :name, :date_of_birth, :current_time, :age, :color, :sibling_names, :address, :phone, :dogs])
|
218
|
+
params.attributes.should eq([:reference, :name, :date_of_birth, :current_time, :age, :color, :sibling_names, :address, :phone, :dogs, :cats])
|
208
219
|
end
|
209
220
|
|
210
221
|
it "returns array of attribute symbols for nested class" do
|
@@ -320,12 +331,12 @@ describe SimpleParams::Params do
|
|
320
331
|
end
|
321
332
|
end
|
322
333
|
|
323
|
-
describe "#validate!"
|
334
|
+
describe "#validate!" do
|
324
335
|
let(:params) { AcceptanceParams.new }
|
325
336
|
|
326
337
|
it "raises error with validation descriptions" do
|
327
338
|
expect { params.validate! }.to raise_error(SimpleParamsError,
|
328
|
-
"{:name=>[\"can't be blank\"], :address=>{:street=>[\"can't be blank\"], :city=>[\"is too short (minimum is 4 characters)\", \"can't be blank\"]}, :dogs=>[{:name=>[\"can't be blank\"], :age=>[\"is not included in the list\", \"can't be blank\"]}]}"
|
339
|
+
"{:name=>[\"can't be blank\"], :address=>{:street=>[\"can't be blank\"], :city=>[\"is too short (minimum is 4 characters)\", \"can't be blank\"]}, :dogs=>[{:name=>[\"can't be blank\"], :age=>[\"is not included in the list\", \"can't be blank\"]}], :cats=>[{:name=>[\"can't be blank\"]}]}"
|
329
340
|
)
|
330
341
|
end
|
331
342
|
end
|
@@ -345,6 +356,11 @@ describe SimpleParams::Params do
|
|
345
356
|
dogs: [
|
346
357
|
name: "Spot",
|
347
358
|
age: 6
|
359
|
+
],
|
360
|
+
cats: [
|
361
|
+
"0" => {
|
362
|
+
name: "Fuzzball"
|
363
|
+
}
|
348
364
|
]
|
349
365
|
}
|
350
366
|
end
|
@@ -379,8 +395,15 @@ describe SimpleParams::Params do
|
|
379
395
|
phone_number: "234"
|
380
396
|
},
|
381
397
|
dogs: [
|
382
|
-
|
383
|
-
|
398
|
+
{
|
399
|
+
name: "Spot",
|
400
|
+
age: 6
|
401
|
+
}
|
402
|
+
],
|
403
|
+
cats: [
|
404
|
+
"0" => {
|
405
|
+
name: "Fuzzball"
|
406
|
+
}
|
384
407
|
]
|
385
408
|
}
|
386
409
|
end
|
@@ -399,6 +422,51 @@ describe SimpleParams::Params do
|
|
399
422
|
acceptance_params.should_not be_valid
|
400
423
|
end
|
401
424
|
end
|
425
|
+
|
426
|
+
context "with destroyed cat" do
|
427
|
+
let(:params) do
|
428
|
+
{
|
429
|
+
name: "Tom",
|
430
|
+
age: 41,
|
431
|
+
address: {
|
432
|
+
street: "1 Main St.",
|
433
|
+
city: "Chicago",
|
434
|
+
state: "IL",
|
435
|
+
zip_code: 33440
|
436
|
+
},
|
437
|
+
phone: {
|
438
|
+
phone_number: "234"
|
439
|
+
},
|
440
|
+
dogs: [
|
441
|
+
{
|
442
|
+
name: "Spot",
|
443
|
+
age: 6
|
444
|
+
}
|
445
|
+
],
|
446
|
+
cats: [
|
447
|
+
"0" => {
|
448
|
+
name: "Fuzzball"
|
449
|
+
},
|
450
|
+
"1" => {
|
451
|
+
name: "Fuzzball 2",
|
452
|
+
_destroy: "1"
|
453
|
+
}
|
454
|
+
]
|
455
|
+
}
|
456
|
+
end
|
457
|
+
|
458
|
+
it "is valid after multiple times" do
|
459
|
+
acceptance_params = AcceptanceParams.new(params)
|
460
|
+
acceptance_params.valid?
|
461
|
+
acceptance_params.should be_valid
|
462
|
+
acceptance_params.should be_valid
|
463
|
+
end
|
464
|
+
|
465
|
+
it "only assigns 1 cat", failing: true do
|
466
|
+
acceptance_params = AcceptanceParams.new(params)
|
467
|
+
acceptance_params.cats.count.should eq(1)
|
468
|
+
end
|
469
|
+
end
|
402
470
|
end
|
403
471
|
end
|
404
472
|
|
@@ -447,6 +515,10 @@ describe SimpleParams::Params do
|
|
447
515
|
param :name, String, desc: '', required: true
|
448
516
|
param :age, Integer, desc: '', required: true
|
449
517
|
end
|
518
|
+
param :cats, Array, desc:'', required: true do
|
519
|
+
param :name, String, desc:'', required: true
|
520
|
+
param :_destroy, Boolean, desc:'', required: false
|
521
|
+
end
|
450
522
|
API_PIE_DOCS
|
451
523
|
|
452
524
|
expect(documentation).to be_a String
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_params
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- brycesenz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|