simple_params 1.6.9 → 2.0.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 CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- YmVlM2RmYWE5ZmY1MDExOTg3NTEwZTQxNDhkMWY1MzhlY2RiNDA0ZA==
5
- data.tar.gz: !binary |-
6
- ZmU1ZGFhNTYwNjg4YWZkZjE4M2M4ODY3MjJkZGE4ZDBhYTE2ZDg0Ng==
2
+ SHA1:
3
+ metadata.gz: ded5b73a35aef4fa98f1334911b8adc78ddf0a98
4
+ data.tar.gz: ff44c10ec9eb4c5d6766c2fcb4b045d8fe6d1d7e
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- MzZmZjI0Y2M1Y2RjYzdiNmZjMDNhZjk1OTJkMzdmN2NhNWZiYzcwNTE2ODc3
10
- ZmI3OGQ5ZWNiNTliNmMxNDYxODJlYjM5ODFkZDA2N2M5ZGRlNjZlZjNkNjQ2
11
- NDUzNzFmM2NlMGVlMTA1NDdiMmNiMGQwMmU2ZjM5ZjMyYzg5ODE=
12
- data.tar.gz: !binary |-
13
- MjAyMDYxMWY4OWE1ZDBkM2IwOGM3YTM4MTRjYjI5MjljNTA0MDI2ZWY2M2Fh
14
- NGJlMjhkZjZiNGZjMGNiZDljMTQ3N2ZjZjhiZGE2ZjExMjdhMWE5MzU1YTVk
15
- ZDYxNmFjNTRjNDZjYmVmMjRkNmRmNWZiZWFmY2M1N2Q1ZDViYjY=
6
+ metadata.gz: '0438842202760d651dedc3cd2289cf590ce51f7c311bda9cb348100bf018dd12a7dd3f8cc8812def1d13da0159ae4b30ab5bc1e20cd3fc010aff2bb247586870'
7
+ data.tar.gz: 4a5a7ab8467342d8a0f158de6ccf78cf2560009e41c5073c0ed107ed89b145f379e5103f700ab5d2f59d7e28b2e4d3d09ba3b390313ae56949f0d44e4ef4c80e
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- ruby-1.9.3-p545
1
+ 2.4.1
data/Appraisals ADDED
@@ -0,0 +1,11 @@
1
+ appraise 'activemodel-3' do
2
+ gem 'activemodel', '>= 3.0'
3
+ end
4
+
5
+ appraise 'activemodel-4' do
6
+ gem 'activemodel', '>= 4.0'
7
+ end
8
+
9
+ appraise 'activemodel-5' do
10
+ gem 'activemodel', '>= 5.0'
11
+ end
data/Gemfile.lock CHANGED
@@ -1,40 +1,42 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- simple_params (1.6.8)
5
- activemodel (>= 3.0, < 5.0)
4
+ simple_params (1.7.0)
5
+ activemodel (>= 3.0, <= 6.0)
6
6
  shoulda-matchers (~> 2.8)
7
7
  virtus (>= 1.0.0)
8
8
 
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- activemodel (4.2.6)
13
- activesupport (= 4.2.6)
14
- builder (~> 3.1)
15
- activesupport (4.2.6)
12
+ activemodel (5.1.4)
13
+ activesupport (= 5.1.4)
14
+ activesupport (5.1.4)
15
+ concurrent-ruby (~> 1.0, >= 1.0.2)
16
16
  i18n (~> 0.7)
17
- json (~> 1.7, >= 1.7.7)
18
17
  minitest (~> 5.1)
19
- thread_safe (~> 0.3, >= 0.3.4)
20
18
  tzinfo (~> 1.1)
19
+ appraisal (2.2.0)
20
+ bundler
21
+ rake
22
+ thor (>= 0.14.0)
21
23
  axiom-types (0.1.1)
22
24
  descendants_tracker (~> 0.0.4)
23
25
  ice_nine (~> 0.11.0)
24
26
  thread_safe (~> 0.3, >= 0.3.1)
25
- builder (3.2.2)
26
27
  coderay (1.1.0)
27
28
  coercible (1.0.0)
28
29
  descendants_tracker (~> 0.0.1)
30
+ concurrent-ruby (1.0.5)
29
31
  descendants_tracker (0.0.4)
30
32
  thread_safe (~> 0.3, >= 0.3.1)
31
33
  diff-lcs (1.2.5)
32
34
  equalizer (0.0.11)
33
- i18n (0.7.0)
35
+ i18n (0.9.0)
36
+ concurrent-ruby (~> 1.0)
34
37
  ice_nine (0.11.2)
35
- json (1.8.3)
36
38
  method_source (0.8.2)
37
- minitest (5.9.0)
39
+ minitest (5.10.3)
38
40
  pry (0.10.1)
39
41
  coderay (~> 1.1.0)
40
42
  method_source (~> 0.8.1)
@@ -51,8 +53,9 @@ GEM
51
53
  shoulda-matchers (2.8.0)
52
54
  activesupport (>= 3.0.0)
53
55
  slop (3.6.0)
54
- thread_safe (0.3.5)
55
- tzinfo (1.2.2)
56
+ thor (0.20.0)
57
+ thread_safe (0.3.6)
58
+ tzinfo (1.2.4)
56
59
  thread_safe (~> 0.1)
57
60
  virtus (1.0.5)
58
61
  axiom-types (~> 0.1)
@@ -64,6 +67,7 @@ PLATFORMS
64
67
  ruby
65
68
 
66
69
  DEPENDENCIES
70
+ appraisal
67
71
  bundler (~> 1.5)
68
72
  pry
69
73
  rake (~> 10.1)
@@ -71,4 +75,4 @@ DEPENDENCIES
71
75
  simple_params!
72
76
 
73
77
  BUNDLED WITH
74
- 1.12.5
78
+ 1.15.4
data/README.md CHANGED
@@ -8,6 +8,12 @@ This class provides the following benefits for handling params:
8
8
  * ActiveModel-like errors, including nested error objects for nested params
9
9
  * Parameter type-coercion (e.g. transform "1" into the Integer 1)
10
10
 
11
+ ## Versions
12
+
13
+ Major Version 1 is compatible with Rails/ActiveModel 3 & 4.
14
+
15
+ Major Version 2 is compatible with Rails/ActiveModel 5, and is built to be backwards compatible with Rails/ActiveModel 3 & 4.
16
+
11
17
  ## Installation
12
18
 
13
19
  Add this line to your application's Gemfile:
@@ -399,6 +405,17 @@ describe YourClass do
399
405
  end
400
406
  ```
401
407
 
408
+ ## Testing this Gem
409
+
410
+ We use Appraisals (https://github.com/thoughtbot/appraisal) as a way to make sure that the gem is compatible across different versions of our dependencies (ActiveModel being the biggest one).
411
+
412
+ Any contributions should pass across all of our Appraisals, i.e.
413
+
414
+ ```ruby
415
+ appraisal activemodel-3 rspec spec #=> Should all be green
416
+ appraisal activemodel-4 rspec spec #=> Should all be green
417
+ ```
418
+
402
419
  ## Contributing
403
420
 
404
421
  1. Fork it
@@ -0,0 +1,2 @@
1
+ ---
2
+ BUNDLE_RETRY: "1"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activemodel", ">= 3.0"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,81 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ simple_params (1.7.0)
5
+ activemodel (>= 3.0, <= 6.0)
6
+ shoulda-matchers (~> 2.8)
7
+ virtus (>= 1.0.0)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ activemodel (4.2.10)
13
+ activesupport (= 4.2.10)
14
+ builder (~> 3.1)
15
+ activesupport (4.2.10)
16
+ i18n (~> 0.7)
17
+ minitest (~> 5.1)
18
+ thread_safe (~> 0.3, >= 0.3.4)
19
+ tzinfo (~> 1.1)
20
+ appraisal (2.2.0)
21
+ bundler
22
+ rake
23
+ thor (>= 0.14.0)
24
+ axiom-types (0.1.1)
25
+ descendants_tracker (~> 0.0.4)
26
+ ice_nine (~> 0.11.0)
27
+ thread_safe (~> 0.3, >= 0.3.1)
28
+ builder (3.2.3)
29
+ coderay (1.1.0)
30
+ coercible (1.0.0)
31
+ descendants_tracker (~> 0.0.1)
32
+ concurrent-ruby (1.0.5)
33
+ descendants_tracker (0.0.4)
34
+ thread_safe (~> 0.3, >= 0.3.1)
35
+ diff-lcs (1.2.5)
36
+ equalizer (0.0.11)
37
+ i18n (0.9.0)
38
+ concurrent-ruby (~> 1.0)
39
+ ice_nine (0.11.2)
40
+ method_source (0.8.2)
41
+ minitest (5.10.3)
42
+ pry (0.10.1)
43
+ coderay (~> 1.1.0)
44
+ method_source (~> 0.8.1)
45
+ slop (~> 3.4)
46
+ rake (10.4.2)
47
+ rspec (2.99.0)
48
+ rspec-core (~> 2.99.0)
49
+ rspec-expectations (~> 2.99.0)
50
+ rspec-mocks (~> 2.99.0)
51
+ rspec-core (2.99.2)
52
+ rspec-expectations (2.99.2)
53
+ diff-lcs (>= 1.1.3, < 2.0)
54
+ rspec-mocks (2.99.3)
55
+ shoulda-matchers (2.8.0)
56
+ activesupport (>= 3.0.0)
57
+ slop (3.6.0)
58
+ thor (0.20.0)
59
+ thread_safe (0.3.6)
60
+ tzinfo (1.2.4)
61
+ thread_safe (~> 0.1)
62
+ virtus (1.0.5)
63
+ axiom-types (~> 0.1)
64
+ coercible (~> 1.0)
65
+ descendants_tracker (~> 0.0, >= 0.0.3)
66
+ equalizer (~> 0.0, >= 0.0.9)
67
+
68
+ PLATFORMS
69
+ ruby
70
+
71
+ DEPENDENCIES
72
+ activemodel (>= 3.0)
73
+ appraisal
74
+ bundler (~> 1.5)
75
+ pry
76
+ rake (~> 10.1)
77
+ rspec (~> 2.6)
78
+ simple_params!
79
+
80
+ BUNDLED WITH
81
+ 1.15.4
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activemodel", ">= 4.0"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,81 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ simple_params (1.7.0)
5
+ activemodel (>= 3.0, <= 6.0)
6
+ shoulda-matchers (~> 2.8)
7
+ virtus (>= 1.0.0)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ activemodel (4.2.10)
13
+ activesupport (= 4.2.10)
14
+ builder (~> 3.1)
15
+ activesupport (4.2.10)
16
+ i18n (~> 0.7)
17
+ minitest (~> 5.1)
18
+ thread_safe (~> 0.3, >= 0.3.4)
19
+ tzinfo (~> 1.1)
20
+ appraisal (2.2.0)
21
+ bundler
22
+ rake
23
+ thor (>= 0.14.0)
24
+ axiom-types (0.1.1)
25
+ descendants_tracker (~> 0.0.4)
26
+ ice_nine (~> 0.11.0)
27
+ thread_safe (~> 0.3, >= 0.3.1)
28
+ builder (3.2.3)
29
+ coderay (1.1.0)
30
+ coercible (1.0.0)
31
+ descendants_tracker (~> 0.0.1)
32
+ concurrent-ruby (1.0.5)
33
+ descendants_tracker (0.0.4)
34
+ thread_safe (~> 0.3, >= 0.3.1)
35
+ diff-lcs (1.2.5)
36
+ equalizer (0.0.11)
37
+ i18n (0.9.0)
38
+ concurrent-ruby (~> 1.0)
39
+ ice_nine (0.11.2)
40
+ method_source (0.8.2)
41
+ minitest (5.10.3)
42
+ pry (0.10.1)
43
+ coderay (~> 1.1.0)
44
+ method_source (~> 0.8.1)
45
+ slop (~> 3.4)
46
+ rake (10.4.2)
47
+ rspec (2.99.0)
48
+ rspec-core (~> 2.99.0)
49
+ rspec-expectations (~> 2.99.0)
50
+ rspec-mocks (~> 2.99.0)
51
+ rspec-core (2.99.2)
52
+ rspec-expectations (2.99.2)
53
+ diff-lcs (>= 1.1.3, < 2.0)
54
+ rspec-mocks (2.99.3)
55
+ shoulda-matchers (2.8.0)
56
+ activesupport (>= 3.0.0)
57
+ slop (3.6.0)
58
+ thor (0.20.0)
59
+ thread_safe (0.3.6)
60
+ tzinfo (1.2.4)
61
+ thread_safe (~> 0.1)
62
+ virtus (1.0.5)
63
+ axiom-types (~> 0.1)
64
+ coercible (~> 1.0)
65
+ descendants_tracker (~> 0.0, >= 0.0.3)
66
+ equalizer (~> 0.0, >= 0.0.9)
67
+
68
+ PLATFORMS
69
+ ruby
70
+
71
+ DEPENDENCIES
72
+ activemodel (>= 4.0)
73
+ appraisal
74
+ bundler (~> 1.5)
75
+ pry
76
+ rake (~> 10.1)
77
+ rspec (~> 2.6)
78
+ simple_params!
79
+
80
+ BUNDLED WITH
81
+ 1.15.4
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activemodel", ">= 5.0"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,79 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ simple_params (1.7.0)
5
+ activemodel (>= 3.0, <= 6.0)
6
+ shoulda-matchers (~> 2.8)
7
+ virtus (>= 1.0.0)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ activemodel (5.1.4)
13
+ activesupport (= 5.1.4)
14
+ activesupport (5.1.4)
15
+ concurrent-ruby (~> 1.0, >= 1.0.2)
16
+ i18n (~> 0.7)
17
+ minitest (~> 5.1)
18
+ tzinfo (~> 1.1)
19
+ appraisal (2.2.0)
20
+ bundler
21
+ rake
22
+ thor (>= 0.14.0)
23
+ axiom-types (0.1.1)
24
+ descendants_tracker (~> 0.0.4)
25
+ ice_nine (~> 0.11.0)
26
+ thread_safe (~> 0.3, >= 0.3.1)
27
+ coderay (1.1.0)
28
+ coercible (1.0.0)
29
+ descendants_tracker (~> 0.0.1)
30
+ concurrent-ruby (1.0.5)
31
+ descendants_tracker (0.0.4)
32
+ thread_safe (~> 0.3, >= 0.3.1)
33
+ diff-lcs (1.2.5)
34
+ equalizer (0.0.11)
35
+ i18n (0.9.0)
36
+ concurrent-ruby (~> 1.0)
37
+ ice_nine (0.11.2)
38
+ method_source (0.8.2)
39
+ minitest (5.10.3)
40
+ pry (0.10.1)
41
+ coderay (~> 1.1.0)
42
+ method_source (~> 0.8.1)
43
+ slop (~> 3.4)
44
+ rake (10.4.2)
45
+ rspec (2.99.0)
46
+ rspec-core (~> 2.99.0)
47
+ rspec-expectations (~> 2.99.0)
48
+ rspec-mocks (~> 2.99.0)
49
+ rspec-core (2.99.2)
50
+ rspec-expectations (2.99.2)
51
+ diff-lcs (>= 1.1.3, < 2.0)
52
+ rspec-mocks (2.99.3)
53
+ shoulda-matchers (2.8.0)
54
+ activesupport (>= 3.0.0)
55
+ slop (3.6.0)
56
+ thor (0.20.0)
57
+ thread_safe (0.3.6)
58
+ tzinfo (1.2.4)
59
+ thread_safe (~> 0.1)
60
+ virtus (1.0.5)
61
+ axiom-types (~> 0.1)
62
+ coercible (~> 1.0)
63
+ descendants_tracker (~> 0.0, >= 0.0.3)
64
+ equalizer (~> 0.0, >= 0.0.9)
65
+
66
+ PLATFORMS
67
+ ruby
68
+
69
+ DEPENDENCIES
70
+ activemodel (>= 5.0)
71
+ appraisal
72
+ bundler (~> 1.5)
73
+ pry
74
+ rake (~> 10.1)
75
+ rspec (~> 2.6)
76
+ simple_params!
77
+
78
+ BUNDLED WITH
79
+ 1.15.4
@@ -15,7 +15,7 @@ module SimpleParams
15
15
  if nested_attribute?(attribute)
16
16
  set_nested(attribute)
17
17
  else
18
- get(attribute.to_sym) || set(attribute.to_sym, [])
18
+ super(attribute)
19
19
  end
20
20
  end
21
21
 
@@ -24,6 +24,7 @@ module SimpleParams
24
24
  end
25
25
 
26
26
  def add(attribute, message = :invalid, options = {})
27
+ message = message.call if message.respond_to?(:call)
27
28
  message = normalize_message(attribute, message, options)
28
29
  if exception = options[:strict]
29
30
  exception = ActiveModel::StrictValidationFailed if exception == true
@@ -68,6 +69,10 @@ module SimpleParams
68
69
  (parent_messages + nested_messages).flatten
69
70
  end
70
71
 
72
+ def to_a
73
+ full_messages
74
+ end
75
+
71
76
  def to_hash(full_messages = false)
72
77
  msgs = get_messages(self, full_messages)
73
78
 
@@ -99,12 +104,11 @@ module SimpleParams
99
104
  @nested_classes.keys.include?(attribute.to_sym)
100
105
  end
101
106
 
102
-
103
- def add_error_to_attribute(attribute, error)
107
+ def add_error_to_attribute(attribute, message)
104
108
  if nested_attribute?(attribute)
105
- @nested_classes[attribute].errors.add(:base, error)
109
+ @nested_classes[attribute].errors.add(:base, message)
106
110
  else
107
- self[attribute] << error
111
+ self[attribute] << message
108
112
  end
109
113
  end
110
114
 
@@ -137,7 +141,11 @@ module SimpleParams
137
141
  def set_nested(attribute)
138
142
  klass = nested_class(attribute)
139
143
  errors = run_or_mapped_run(klass) { |k| k.errors if k.present? }
140
- set(attribute.to_sym, errors)
144
+ if respond_to?(:normalize_detail)
145
+ detail = normalize_detail(errors, {})
146
+ details[attribute.to_sym] = detail
147
+ end
148
+ messages[attribute.to_sym] = errors
141
149
  end
142
150
 
143
151
  def nested_instances
@@ -18,7 +18,7 @@ module SimpleParams
18
18
  end
19
19
 
20
20
  def [](attribute)
21
- get(attribute.to_sym) || set(attribute.to_sym, [])
21
+ super(attribute)
22
22
  end
23
23
 
24
24
  def []=(attribute, error)
@@ -58,6 +58,10 @@ module SimpleParams
58
58
  map { |attribute, message| full_message(attribute, message) }
59
59
  end
60
60
 
61
+ def to_a
62
+ full_messages
63
+ end
64
+
61
65
  def to_hash(full_messages = false)
62
66
  get_messages(self, full_messages)
63
67
  end
@@ -1,3 +1,3 @@
1
1
  module SimpleParams
2
- VERSION = "1.6.9"
2
+ VERSION = "2.0.0"
3
3
  end
@@ -4,25 +4,26 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'simple_params/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "simple_params"
7
+ spec.name = 'simple_params'
8
8
  spec.version = SimpleParams::VERSION
9
- spec.authors = ["brycesenz"]
10
- spec.email = ["bryce.senz@gmail.com"]
9
+ spec.authors = ['brycesenz']
10
+ spec.email = ['bryce.senz@gmail.com']
11
11
  spec.description = %q{Simple way to specify API params}
12
12
  spec.summary = %q{A DSL for specifying params, including type coercion and validation}
13
- spec.homepage = "https://github.com/brycesenz/simple_params"
14
- spec.license = "MIT"
13
+ spec.homepage = 'https://github.com/brycesenz/simple_params'
14
+ spec.license = 'MIT'
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
19
+ spec.require_paths = ['lib']
20
20
 
21
- spec.add_dependency "activemodel", ">= 3.0", "< 5.0"
22
- spec.add_dependency "virtus", ">= 1.0.0"
23
- spec.add_dependency "shoulda-matchers", "~> 2.8"
24
- spec.add_development_dependency "bundler", "~> 1.5"
25
- spec.add_development_dependency "rake", "~> 10.1"
26
- spec.add_development_dependency "rspec", "~> 2.6"
27
- spec.add_development_dependency "pry"
21
+ spec.add_dependency 'activemodel', '>= 3.0', '<= 6.0'
22
+ spec.add_dependency 'virtus', '>= 1.0.0'
23
+ spec.add_dependency 'shoulda-matchers', '~> 2.8'
24
+ spec.add_development_dependency 'appraisal'
25
+ spec.add_development_dependency 'bundler', '~> 1.5'
26
+ spec.add_development_dependency 'rake', '~> 10.1'
27
+ spec.add_development_dependency 'rspec', '~> 2.6'
28
+ spec.add_development_dependency 'pry'
28
29
  end
data/spec/errors_spec.rb CHANGED
@@ -92,154 +92,56 @@ describe SimpleParams::Errors do
92
92
  end
93
93
  end
94
94
 
95
- describe "setting and getting errors", setters_getters: true do
96
- it "get returns the errors for the provided key" do
95
+ describe '[]', getter: true do
96
+ it "gets the errors for the provided key" do
97
97
  errors = SimpleParams::Errors.new(self)
98
- errors[:foo] = "omg"
99
- errors.get(:foo).should eq(["omg"])
100
- end
101
-
102
- it "sets the error with the provided key" do
103
- errors = SimpleParams::Errors.new(self)
104
- errors.set(:foo, "omg")
105
- errors.messages.should eq({ foo: "omg" })
106
- end
107
-
108
- it "values returns an array of messages" do
109
- errors = SimpleParams::Errors.new(self)
110
- errors.set(:foo, "omg")
111
- errors.set(:baz, "zomg")
112
- errors.values.should eq(["omg", "zomg"])
113
- end
114
-
115
- it "keys returns the error keys" do
116
- errors = SimpleParams::Errors.new(self)
117
- errors.set(:foo, "omg")
118
- errors.set(:baz, "zomg")
119
- errors.keys.should eq([:foo, :baz])
120
- end
121
-
122
- describe "setting on model" do
123
- it "assign error" do
124
- person = Person.new
125
- person.errors[:name] = 'should not be nil'
126
- person.errors[:name].should eq(["should not be nil"])
127
- end
128
-
129
- it "add an error message on a specific attribute" do
130
- person = Person.new
131
- person.errors.add(:name, "can not be blank")
132
- person.errors[:name].should eq(["can not be blank"])
133
- end
134
-
135
- it "add an error with a symbol" do
136
- person = Person.new
137
- person.errors.add(:name, :blank)
138
- message = person.errors.generate_message(:name, :blank)
139
- person.errors[:name].should eq([message])
140
- end
141
-
142
- it "add an error with a proc" do
143
- person = Person.new
144
- message = Proc.new { "can not be blank" }
145
- person.errors.add(:name, message)
146
- person.errors[:name].should eq(["can not be blank"])
147
- end
148
- end
149
- end
150
-
151
- describe "setting and getting nested error model", nested_model: true do
152
- it "can access error model" do
153
- person = Person.new
154
- dog = person.dog
155
- dog_errors = dog.errors
156
- person.errors[:dog].should eq(dog_errors)
157
- end
158
-
159
- it "can add to nested errors through []" do
160
- person = Person.new
161
- person.errors[:dog] = 'should not be nil'
162
- person.dog.errors[:base].should eq(['should not be nil'])
163
- end
164
-
165
- it "can add to nested errors through add" do
166
- person = Person.new
167
- person.errors.add(:dog, 'should not be nil')
168
- person.dog.errors[:base].should eq(['should not be nil'])
169
- end
170
-
171
- it "can add multiple errors to nested errors through []" do
172
- person = Person.new
173
- person.errors[:dog] = 'should not be nil'
174
- person.errors[:dog] = 'must be cute'
175
- person.dog.errors[:base].should eq(['should not be nil', 'must be cute'])
98
+ errors.add(:foo, "omg")
99
+ errors[:foo].should eq(["omg"])
176
100
  end
177
101
 
178
- it "can add multiple errors to nested errors through add" do
102
+ it "gets model with nested attributes" do
179
103
  person = Person.new
180
- person.errors.add(:dog, 'should not be nil')
181
- person.errors.add(:dog, 'must be cute')
182
- person.dog.errors[:base].should eq(['should not be nil', 'must be cute'])
104
+ person.errors.add(:name, "can not be blank")
105
+ person.errors.add(:name, "can not be nil")
106
+ person.errors[:name].should eq(["can not be blank", "can not be nil"])
183
107
  end
184
108
 
185
- it "can add individual errors to nested attributes through []" do
109
+ it "gets nested model errors" do
186
110
  person = Person.new
187
- person.errors[:dog][:breed] = 'should not be nil'
188
- person.dog.errors[:breed].should eq(['should not be nil'])
111
+ person.dog.errors.add(:breed, "can not be blank")
112
+ person.errors[:dog][:breed].should eq(["can not be blank"])
189
113
  end
190
114
 
191
- it "can add individual errors to nested attributes through add" do
115
+ it "gets nested model errors" do
192
116
  person = Person.new
193
- person.errors[:dog].add(:breed, 'should not be nil')
194
- person.dog.errors[:breed].should eq(['should not be nil'])
117
+ person.cats.first.errors.add(:name, "can not be blank")
118
+ person.errors[:cats][0][:name].should eq(["can not be blank"])
195
119
  end
196
120
  end
197
121
 
198
- describe "setting and getting nested array error model", nested_array: true do
199
- it "can access error model" do
200
- person = Person.new
201
- cats = person.cats
202
- cat_errors = cats.first.errors
203
- person.errors[:cats][0].should eq(cat_errors)
204
- end
205
-
206
- it "can add to nested errors through []" do
207
- person = Person.new
208
- person.errors[:cats].first[:base] = 'should not be nil'
209
- person.errors[:cats].first[:base].should eq(['should not be nil'])
210
- person.cats.first.errors[:base].should eq(['should not be nil'])
211
- end
212
-
213
- it "can add to nested errors through add" do
214
- person = Person.new
215
- person.errors[:cats].first.add(:age, 'should not be nil')
216
- person.cats.first.errors[:age].should eq(['should not be nil'])
217
- end
218
-
219
- it "can add multiple errors to nested errors through []" do
220
- person = Person.new
221
- person.errors[:cats].first[:name] = 'should not be nil'
222
- person.errors[:cats].first[:name] = 'must be cute'
223
- person.cats.first.errors[:name].should eq(['should not be nil', 'must be cute'])
122
+ describe '[]=', setter: true do
123
+ it "sets the errors for the provided key" do
124
+ errors = SimpleParams::Errors.new(self)
125
+ errors[:foo] = "omg"
126
+ errors[:foo].should eq(["omg"])
224
127
  end
225
128
 
226
- it "can add multiple errors to nested errors through add" do
129
+ it "sets model with nested attributes" do
227
130
  person = Person.new
228
- person.errors[:cats].first.add(:name, 'should not be nil')
229
- person.errors[:cats].first.add(:name, 'must be cute')
230
- person.cats.first.errors[:name].should eq(['should not be nil', 'must be cute'])
131
+ person.errors[:name] = "can not be blank"
132
+ person.errors[:name].should eq(["can not be blank"])
231
133
  end
232
134
 
233
- it "can add individual errors to nested attributes through []" do
135
+ it "sets nested model errors" do
234
136
  person = Person.new
235
- person.errors[:cats][0][:age] = 'should not be nil'
236
- person.cats.first.errors[:age].should eq(['should not be nil'])
137
+ person.dog.errors[:breed] = "can not be blank"
138
+ person.errors[:dog][:breed].should eq(["can not be blank"])
237
139
  end
238
140
 
239
- it "can add individual errors to nested attributes through add" do
141
+ it "sets nested model errors" do
240
142
  person = Person.new
241
- person.errors[:cats].first.add(:age, 'should not be nil')
242
- person.cats.first.errors[:age].should eq(['should not be nil'])
143
+ person.cats.first.errors[:name] = "can not be blank"
144
+ person.errors[:cats][0][:name].should eq(["can not be blank"])
243
145
  end
244
146
  end
245
147
 
@@ -292,51 +194,6 @@ describe SimpleParams::Errors do
292
194
  end
293
195
  end
294
196
 
295
- describe "#added?", added: true do
296
- it "added? detects if a specific error was added to the object" do
297
- person = Person.new
298
- person.errors.add(:name, "can not be blank")
299
- person.errors.added?(:name, "can not be blank").should be_truthy
300
- end
301
-
302
- it "added? handles symbol message" do
303
- person = Person.new
304
- person.errors.add(:name, :blank)
305
- person.errors.added?(:name, :blank).should be_truthy
306
- end
307
-
308
- it "added? handles proc messages" do
309
- person = Person.new
310
- message = Proc.new { "can not be blank" }
311
- person.errors.add(:name, message)
312
- person.errors.added?(:name, message).should be_truthy
313
- end
314
-
315
- it "added? defaults message to :invalid" do
316
- person = Person.new
317
- person.errors.add(:name)
318
- person.errors.added?(:name).should be_truthy
319
- end
320
-
321
- it "added? matches the given message when several errors are present for the same attribute" do
322
- person = Person.new
323
- person.errors.add(:name, "can not be blank")
324
- person.errors.add(:name, "is invalid")
325
- person.errors.added?(:name, "can not be blank").should be_truthy
326
- end
327
-
328
- it "added? returns false when no errors are present" do
329
- person = Person.new
330
- person.errors.added?(:name).should_not be_truthy
331
- end
332
-
333
- it "added? returns false when checking a nonexisting error and other errors are present for the given attribute" do
334
- person = Person.new
335
- person.errors.add(:name, "is invalid")
336
- person.errors.added?(:name, "can not be blank").should_not be_truthy
337
- end
338
- end
339
-
340
197
  describe "#size", size: true do
341
198
  it "size calculates the number of error messages" do
342
199
  person = Person.new
@@ -520,63 +377,4 @@ describe SimpleParams::Errors do
520
377
  person.errors.full_message(:name_test, "can not be blank").should eq("name_test can not be blank")
521
378
  end
522
379
  end
523
-
524
- describe "#generate_message", generate_message: true do
525
- it "generate_message works without i18n_scope" do
526
- person = Person.new
527
- Person.should_not respond_to(:i18n_scope)
528
- expect {
529
- person.errors.generate_message(:name, :blank)
530
- }.to_not raise_error
531
- end
532
- end
533
-
534
- describe "#adds_on_empty", add_on_empty: true do
535
- it "add_on_empty generates message" do
536
- person = Person.new
537
- person.errors.should_receive(:generate_message).with(:name, :empty, {})
538
- person.errors.add_on_empty :name
539
- end
540
-
541
- it "add_on_empty generates message for multiple attributes" do
542
- person = Person.new
543
- person.errors.should_receive(:generate_message).with(:name, :empty, {})
544
- person.errors.should_receive(:generate_message).with(:age, :empty, {})
545
- person.errors.add_on_empty [:name, :age]
546
- end
547
-
548
- it "add_on_empty generates message with custom default message" do
549
- person = Person.new
550
- person.errors.should_receive(:generate_message).with(:name, :empty, { message: 'custom' })
551
- person.errors.add_on_empty :name, message: 'custom'
552
- end
553
-
554
- it "add_on_empty generates message with empty string value" do
555
- person = Person.new
556
- person.name = ''
557
- person.errors.should_receive(:generate_message).with(:name, :empty, {})
558
- person.errors.add_on_empty :name
559
- end
560
- end
561
-
562
- describe "#adds_on_blank", add_on_blank: true do
563
- it "add_on_blank generates message" do
564
- person = Person.new
565
- person.errors.should_receive(:generate_message).with(:name, :blank, {})
566
- person.errors.add_on_blank :name
567
- end
568
-
569
- it "add_on_blank generates message for multiple attributes" do
570
- person = Person.new
571
- person.errors.should_receive(:generate_message).with(:name, :blank, {})
572
- person.errors.should_receive(:generate_message).with(:age, :blank, {})
573
- person.errors.add_on_blank [:name, :age]
574
- end
575
-
576
- it "add_on_blank generates message with custom default message" do
577
- person = Person.new
578
- person.errors.should_receive(:generate_message).with(:name, :blank, { message: 'custom' })
579
- person.errors.add_on_blank :name, message: 'custom'
580
- end
581
- end
582
380
  end
@@ -53,59 +53,32 @@ describe SimpleParams::NestedErrors do
53
53
  end
54
54
  end
55
55
 
56
- describe "setting and getting errors", setters_getters: true do
57
- it "get returns the errors for the provided key" do
58
- errors = SimpleParams::Errors.new(self)
59
- errors[:foo] = "omg"
60
- errors.get(:foo).should eq(["omg"])
56
+ describe '[]', getter: true do
57
+ it "gets the errors for the provided key" do
58
+ errors = SimpleParams::NestedErrors.new(self)
59
+ errors.add(:foo, "omg")
60
+ errors[:foo].should eq(["omg"])
61
61
  end
62
62
 
63
- it "sets the error with the provided key" do
64
- errors = SimpleParams::Errors.new(self)
65
- errors.set(:foo, "omg")
66
- errors.messages.should eq({ foo: "omg" })
63
+ it "gets model errors" do
64
+ car = Car.new
65
+ car.errors.add(:make, "can not be blank")
66
+ car.errors.add(:make, "can not be nil")
67
+ car.errors[:make].should eq(["can not be blank", "can not be nil"])
67
68
  end
69
+ end
68
70
 
69
- it "values returns an array of messages" do
71
+ describe '[]=', setter: true do
72
+ it "sets the errors for the provided key" do
70
73
  errors = SimpleParams::Errors.new(self)
71
- errors.set(:foo, "omg")
72
- errors.set(:baz, "zomg")
73
- errors.values.should eq(["omg", "zomg"])
74
+ errors[:foo] = "omg"
75
+ errors[:foo].should eq(["omg"])
74
76
  end
75
77
 
76
- it "keys returns the error keys" do
77
- errors = SimpleParams::Errors.new(self)
78
- errors.set(:foo, "omg")
79
- errors.set(:baz, "zomg")
80
- errors.keys.should eq([:foo, :baz])
81
- end
82
-
83
- describe "setting on model" do
84
- it "assign error" do
85
- car = Car.new
86
- car.errors[:make] = 'should not be nil'
87
- car.errors[:make].should eq(["should not be nil"])
88
- end
89
-
90
- it "add an error message on a specific attribute" do
91
- car = Car.new
92
- car.errors.add(:make, "can not be blank")
93
- car.errors[:make].should eq(["can not be blank"])
94
- end
95
-
96
- it "add an error with a symbol" do
97
- car = Car.new
98
- car.errors.add(:make, :blank)
99
- message = car.errors.generate_message(:make, :blank)
100
- car.errors[:make].should eq([message])
101
- end
102
-
103
- it "add an error with a proc" do
104
- car = Car.new
105
- message = Proc.new { "can not be blank" }
106
- car.errors.add(:make, message)
107
- car.errors[:make].should eq(["can not be blank"])
108
- end
78
+ it "sets model errors" do
79
+ car = Car.new
80
+ car.errors[:make] = "can not be blank"
81
+ car.errors[:make].should eq(["can not be blank"])
109
82
  end
110
83
  end
111
84
 
@@ -136,51 +109,6 @@ describe SimpleParams::NestedErrors do
136
109
  end
137
110
  end
138
111
 
139
- describe "#added?", added: true do
140
- it "added? detects if a specific error was added to the object" do
141
- car = Car.new
142
- car.errors.add(:make, "can not be blank")
143
- car.errors.added?(:make, "can not be blank").should be_truthy
144
- end
145
-
146
- it "added? handles symbol message" do
147
- car = Car.new
148
- car.errors.add(:make, :blank)
149
- car.errors.added?(:make, :blank).should be_truthy
150
- end
151
-
152
- it "added? handles proc messages" do
153
- car = Car.new
154
- message = Proc.new { "can not be blank" }
155
- car.errors.add(:make, message)
156
- car.errors.added?(:make, message).should be_truthy
157
- end
158
-
159
- it "added? defaults message to :invalid" do
160
- car = Car.new
161
- car.errors.add(:make)
162
- car.errors.added?(:make).should be_truthy
163
- end
164
-
165
- it "added? matches the given message when several errors are present for the same attribute" do
166
- car = Car.new
167
- car.errors.add(:make, "can not be blank")
168
- car.errors.add(:make, "is invalid")
169
- car.errors.added?(:make, "can not be blank").should be_truthy
170
- end
171
-
172
- it "added? returns false when no errors are present" do
173
- car = Car.new
174
- car.errors.added?(:make).should_not be_truthy
175
- end
176
-
177
- it "added? returns false when checking a nonexisting error and other errors are present for the given attribute" do
178
- car = Car.new
179
- car.errors.add(:make, "is invalid")
180
- car.errors.added?(:make, "can not be blank").should_not be_truthy
181
- end
182
- end
183
-
184
112
  describe "#size", size: true do
185
113
  it "size calculates the number of error messages" do
186
114
  car = Car.new
@@ -205,7 +133,6 @@ describe SimpleParams::NestedErrors do
205
133
  car.errors.add(:make, "can not be nil")
206
134
  car.errors.to_s.should eq("make can not be blank, make can not be nil")
207
135
  end
208
-
209
136
  end
210
137
 
211
138
  describe "#to_hash", to_hash: true do
@@ -281,53 +208,4 @@ describe SimpleParams::NestedErrors do
281
208
  }.to_not raise_error
282
209
  end
283
210
  end
284
-
285
- describe "#adds_on_empty", add_on_empty: true do
286
- it "add_on_empty generates message" do
287
- car = Car.new
288
- car.errors.should_receive(:generate_message).with(:make, :empty, {})
289
- car.errors.add_on_empty :make
290
- end
291
-
292
- it "add_on_empty generates message for multiple attributes" do
293
- car = Car.new
294
- car.errors.should_receive(:generate_message).with(:make, :empty, {})
295
- car.errors.should_receive(:generate_message).with(:model, :empty, {})
296
- car.errors.add_on_empty [:make, :model]
297
- end
298
-
299
- it "add_on_empty generates message with custom default message" do
300
- car = Car.new
301
- car.errors.should_receive(:generate_message).with(:make, :empty, { message: 'custom' })
302
- car.errors.add_on_empty :make, message: 'custom'
303
- end
304
-
305
- it "add_on_empty generates message with empty string value" do
306
- car = Car.new
307
- car.make = ''
308
- car.errors.should_receive(:generate_message).with(:make, :empty, {})
309
- car.errors.add_on_empty :make
310
- end
311
- end
312
-
313
- describe "#adds_on_blank", add_on_blank: true do
314
- it "add_on_blank generates message" do
315
- car = Car.new
316
- car.errors.should_receive(:generate_message).with(:make, :blank, {})
317
- car.errors.add_on_blank :make
318
- end
319
-
320
- it "add_on_blank generates message for multiple attributes" do
321
- car = Car.new
322
- car.errors.should_receive(:generate_message).with(:make, :blank, {})
323
- car.errors.should_receive(:generate_message).with(:model, :blank, {})
324
- car.errors.add_on_blank [:make, :model]
325
- end
326
-
327
- it "add_on_blank generates message with custom default message" do
328
- car = Car.new
329
- car.errors.should_receive(:generate_message).with(:make, :blank, { message: 'custom' })
330
- car.errors.add_on_blank :make, message: 'custom'
331
- end
332
- end
333
211
  end
metadata CHANGED
@@ -1,117 +1,131 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_params
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.9
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - brycesenz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-13 00:00:00.000000000 Z
11
+ date: 2017-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.0'
20
- - - <
20
+ - - "<="
21
21
  - !ruby/object:Gem::Version
22
- version: '5.0'
22
+ version: '6.0'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - ! '>='
27
+ - - ">="
28
28
  - !ruby/object:Gem::Version
29
29
  version: '3.0'
30
- - - <
30
+ - - "<="
31
31
  - !ruby/object:Gem::Version
32
- version: '5.0'
32
+ version: '6.0'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: virtus
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - ! '>='
37
+ - - ">="
38
38
  - !ruby/object:Gem::Version
39
39
  version: 1.0.0
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
- - - ! '>='
44
+ - - ">="
45
45
  - !ruby/object:Gem::Version
46
46
  version: 1.0.0
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: shoulda-matchers
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
- - - ~>
51
+ - - "~>"
52
52
  - !ruby/object:Gem::Version
53
53
  version: '2.8'
54
54
  type: :runtime
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
- - - ~>
58
+ - - "~>"
59
59
  - !ruby/object:Gem::Version
60
60
  version: '2.8'
61
+ - !ruby/object:Gem::Dependency
62
+ name: appraisal
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
61
75
  - !ruby/object:Gem::Dependency
62
76
  name: bundler
63
77
  requirement: !ruby/object:Gem::Requirement
64
78
  requirements:
65
- - - ~>
79
+ - - "~>"
66
80
  - !ruby/object:Gem::Version
67
81
  version: '1.5'
68
82
  type: :development
69
83
  prerelease: false
70
84
  version_requirements: !ruby/object:Gem::Requirement
71
85
  requirements:
72
- - - ~>
86
+ - - "~>"
73
87
  - !ruby/object:Gem::Version
74
88
  version: '1.5'
75
89
  - !ruby/object:Gem::Dependency
76
90
  name: rake
77
91
  requirement: !ruby/object:Gem::Requirement
78
92
  requirements:
79
- - - ~>
93
+ - - "~>"
80
94
  - !ruby/object:Gem::Version
81
95
  version: '10.1'
82
96
  type: :development
83
97
  prerelease: false
84
98
  version_requirements: !ruby/object:Gem::Requirement
85
99
  requirements:
86
- - - ~>
100
+ - - "~>"
87
101
  - !ruby/object:Gem::Version
88
102
  version: '10.1'
89
103
  - !ruby/object:Gem::Dependency
90
104
  name: rspec
91
105
  requirement: !ruby/object:Gem::Requirement
92
106
  requirements:
93
- - - ~>
107
+ - - "~>"
94
108
  - !ruby/object:Gem::Version
95
109
  version: '2.6'
96
110
  type: :development
97
111
  prerelease: false
98
112
  version_requirements: !ruby/object:Gem::Requirement
99
113
  requirements:
100
- - - ~>
114
+ - - "~>"
101
115
  - !ruby/object:Gem::Version
102
116
  version: '2.6'
103
117
  - !ruby/object:Gem::Dependency
104
118
  name: pry
105
119
  requirement: !ruby/object:Gem::Requirement
106
120
  requirements:
107
- - - ! '>='
121
+ - - ">="
108
122
  - !ruby/object:Gem::Version
109
123
  version: '0'
110
124
  type: :development
111
125
  prerelease: false
112
126
  version_requirements: !ruby/object:Gem::Requirement
113
127
  requirements:
114
- - - ! '>='
128
+ - - ">="
115
129
  - !ruby/object:Gem::Version
116
130
  version: '0'
117
131
  description: Simple way to specify API params
@@ -121,12 +135,20 @@ executables: []
121
135
  extensions: []
122
136
  extra_rdoc_files: []
123
137
  files:
124
- - .rspec
125
- - .ruby-gemset
126
- - .ruby-version
138
+ - ".rspec"
139
+ - ".ruby-gemset"
140
+ - ".ruby-version"
141
+ - Appraisals
127
142
  - Gemfile
128
143
  - Gemfile.lock
129
144
  - README.md
145
+ - gemfiles/.bundle/config
146
+ - gemfiles/activemodel_3.gemfile
147
+ - gemfiles/activemodel_3.gemfile.lock
148
+ - gemfiles/activemodel_4.gemfile
149
+ - gemfiles/activemodel_4.gemfile.lock
150
+ - gemfiles/activemodel_5.gemfile
151
+ - gemfiles/activemodel_5.gemfile.lock
130
152
  - lib/simple_params.rb
131
153
  - lib/simple_params/api_pie_doc.rb
132
154
  - lib/simple_params/api_pie_doc/attribute.rb
@@ -194,17 +216,17 @@ require_paths:
194
216
  - lib
195
217
  required_ruby_version: !ruby/object:Gem::Requirement
196
218
  requirements:
197
- - - ! '>='
219
+ - - ">="
198
220
  - !ruby/object:Gem::Version
199
221
  version: '0'
200
222
  required_rubygems_version: !ruby/object:Gem::Requirement
201
223
  requirements:
202
- - - ! '>='
224
+ - - ">="
203
225
  - !ruby/object:Gem::Version
204
226
  version: '0'
205
227
  requirements: []
206
228
  rubyforge_project:
207
- rubygems_version: 2.4.8
229
+ rubygems_version: 2.6.11
208
230
  signing_key:
209
231
  specification_version: 4
210
232
  summary: A DSL for specifying params, including type coercion and validation