haveapi 0.20.0 → 0.21.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -1
  3. data/Rakefile +6 -6
  4. data/haveapi.gemspec +13 -13
  5. data/lib/haveapi/action.rb +153 -167
  6. data/lib/haveapi/action_state.rb +2 -6
  7. data/lib/haveapi/actions/default.rb +8 -10
  8. data/lib/haveapi/api.rb +2 -1
  9. data/lib/haveapi/authentication/base.rb +5 -8
  10. data/lib/haveapi/authentication/basic/provider.rb +4 -5
  11. data/lib/haveapi/authentication/chain.rb +19 -17
  12. data/lib/haveapi/authentication/oauth2/config.rb +12 -32
  13. data/lib/haveapi/authentication/oauth2/provider.rb +20 -30
  14. data/lib/haveapi/authentication/oauth2/revoke_endpoint.rb +1 -2
  15. data/lib/haveapi/authentication/token/action_config.rb +5 -3
  16. data/lib/haveapi/authentication/token/config.rb +5 -5
  17. data/lib/haveapi/authentication/token/provider.rb +33 -37
  18. data/lib/haveapi/authorization.rb +10 -4
  19. data/lib/haveapi/client_example.rb +11 -14
  20. data/lib/haveapi/client_examples/curl.rb +37 -37
  21. data/lib/haveapi/client_examples/fs_client.rb +29 -31
  22. data/lib/haveapi/client_examples/http.rb +35 -36
  23. data/lib/haveapi/client_examples/js_client.rb +62 -63
  24. data/lib/haveapi/client_examples/php_client.rb +77 -76
  25. data/lib/haveapi/client_examples/ruby_cli.rb +30 -30
  26. data/lib/haveapi/client_examples/ruby_client.rb +26 -26
  27. data/lib/haveapi/common.rb +3 -4
  28. data/lib/haveapi/context.rb +11 -10
  29. data/lib/haveapi/example.rb +9 -4
  30. data/lib/haveapi/example_list.rb +2 -2
  31. data/lib/haveapi/exceptions.rb +1 -1
  32. data/lib/haveapi/extensions/action_exceptions.rb +2 -2
  33. data/lib/haveapi/extensions/base.rb +1 -3
  34. data/lib/haveapi/extensions/exception_mailer.rb +260 -257
  35. data/lib/haveapi/hooks.rb +40 -39
  36. data/lib/haveapi/metadata.rb +1 -1
  37. data/lib/haveapi/model_adapter.rb +16 -27
  38. data/lib/haveapi/model_adapters/active_record.rb +59 -69
  39. data/lib/haveapi/output_formatter.rb +7 -7
  40. data/lib/haveapi/output_formatters/base.rb +2 -4
  41. data/lib/haveapi/parameters/resource.rb +7 -7
  42. data/lib/haveapi/parameters/typed.rb +6 -9
  43. data/lib/haveapi/params.rb +38 -45
  44. data/lib/haveapi/resource.rb +8 -8
  45. data/lib/haveapi/resources/action_state.rb +11 -19
  46. data/lib/haveapi/server.rb +102 -107
  47. data/lib/haveapi/spec/api_response.rb +1 -1
  48. data/lib/haveapi/spec/helpers.rb +1 -1
  49. data/lib/haveapi/spec/mock_action.rb +11 -10
  50. data/lib/haveapi/spec/spec_methods.rb +9 -8
  51. data/lib/haveapi/tasks/yard.rb +2 -2
  52. data/lib/haveapi/types.rb +0 -3
  53. data/lib/haveapi/validator.rb +6 -3
  54. data/lib/haveapi/validator_chain.rb +9 -8
  55. data/lib/haveapi/validators/acceptance.rb +6 -6
  56. data/lib/haveapi/validators/confirmation.rb +2 -3
  57. data/lib/haveapi/validators/exclusion.rb +1 -1
  58. data/lib/haveapi/validators/format.rb +1 -1
  59. data/lib/haveapi/validators/inclusion.rb +1 -1
  60. data/lib/haveapi/validators/length.rb +12 -11
  61. data/lib/haveapi/validators/numericality.rb +14 -13
  62. data/lib/haveapi/validators/presence.rb +4 -3
  63. data/lib/haveapi/version.rb +2 -2
  64. data/lib/haveapi.rb +2 -3
  65. data/spec/.rubocop.yml +4 -0
  66. data/spec/action/dsl_spec.rb +18 -18
  67. data/spec/authorization_spec.rb +8 -8
  68. data/spec/common_spec.rb +2 -1
  69. data/spec/documentation_spec.rb +2 -9
  70. data/spec/envelope_spec.rb +2 -2
  71. data/spec/hooks_spec.rb +12 -12
  72. data/spec/parameters/typed_spec.rb +6 -6
  73. data/spec/params_spec.rb +22 -24
  74. data/spec/resource_spec.rb +5 -7
  75. data/spec/spec_helper.rb +0 -1
  76. data/spec/validators/acceptance_spec.rb +1 -1
  77. data/spec/validators/confirmation_spec.rb +5 -5
  78. data/spec/validators/exclusion_spec.rb +3 -3
  79. data/spec/validators/format_spec.rb +2 -2
  80. data/spec/validators/inclusion_spec.rb +4 -4
  81. data/spec/validators/length_spec.rb +23 -23
  82. data/spec/validators/numericality_spec.rb +13 -13
  83. data/spec/validators/presence_spec.rb +3 -3
  84. metadata +49 -48
data/spec/params_spec.rb CHANGED
@@ -6,7 +6,6 @@ describe HaveAPI::Params do
6
6
  end
7
7
 
8
8
  class Index < HaveAPI::Actions::Default::Index
9
-
10
9
  end
11
10
 
12
11
  class Show < HaveAPI::Actions::Default::Show
@@ -16,17 +15,16 @@ describe HaveAPI::Params do
16
15
  end
17
16
 
18
17
  class Create < HaveAPI::Actions::Default::Create
19
-
20
18
  end
21
19
  end
22
20
 
23
21
  it 'executes all blocks' do
24
22
  p = HaveAPI::Params.new(:input, MyResource::Index)
25
- p.add_block Proc.new { string :param1 }
26
- p.add_block Proc.new { string :param2 }
27
- p.add_block Proc.new { string :param3 }
23
+ p.add_block proc { string :param1 }
24
+ p.add_block proc { string :param2 }
25
+ p.add_block proc { string :param3 }
28
26
  p.exec
29
- expect(p.params.map { |p| p.name }).to contain_exactly(*%i(param1 param2 param3))
27
+ expect(p.params.map(&:name)).to contain_exactly(*%i[param1 param2 param3])
30
28
  end
31
29
 
32
30
  it 'returns deduced singular namespace' do
@@ -48,43 +46,43 @@ describe HaveAPI::Params do
48
46
 
49
47
  it 'uses params from parent resource' do
50
48
  p = HaveAPI::Params.new(:input, MyResource::Index)
51
- p.add_block Proc.new { use :all }
49
+ p.add_block proc { use :all }
52
50
  p.exec
53
- expect(p.params.map { |p| p.name }).to contain_exactly(*%i(res_param1 res_param2))
51
+ expect(p.params.map(&:name)).to contain_exactly(*%i[res_param1 res_param2])
54
52
  end
55
53
 
56
54
  it 'has param requires' do
57
55
  p = HaveAPI::Params.new(:input, MyResource::Index)
58
- p.add_block Proc.new { requires :p_required }
56
+ p.add_block proc { requires :p_required }
59
57
  p.exec
60
58
  expect(p.params.first.required?).to be true
61
59
  end
62
60
 
63
61
  it 'has param optional' do
64
62
  p = HaveAPI::Params.new(:input, MyResource::Index)
65
- p.add_block Proc.new { optional :p_optional }
63
+ p.add_block proc { optional :p_optional }
66
64
  p.exec
67
65
  expect(p.params.first.required?).to be false
68
66
  end
69
67
 
70
68
  it 'has param string' do
71
69
  p = HaveAPI::Params.new(:input, MyResource::Index)
72
- p.add_block Proc.new { string :p_string }
70
+ p.add_block proc { string :p_string }
73
71
  p.exec
74
72
  expect(p.params.first.type).to eq(String)
75
73
  end
76
74
 
77
75
  it 'has param text' do
78
76
  p = HaveAPI::Params.new(:input, MyResource::Index)
79
- p.add_block Proc.new { text :p_text }
77
+ p.add_block proc { text :p_text }
80
78
  p.exec
81
79
  expect(p.params.first.type).to eq(Text)
82
80
  end
83
81
 
84
- %i(id integer foreign_key).each do |type|
82
+ %i[id integer foreign_key].each do |type|
85
83
  it "has param #{type}" do
86
84
  p = HaveAPI::Params.new(:input, MyResource::Index)
87
- p.add_block Proc.new { send(type, :"p_#{type}") }
85
+ p.add_block proc { send(type, :"p_#{type}") }
88
86
  p.exec
89
87
  expect(p.params.first.type).to eq(Integer)
90
88
  end
@@ -92,42 +90,42 @@ describe HaveAPI::Params do
92
90
 
93
91
  it 'has param float' do
94
92
  p = HaveAPI::Params.new(:input, MyResource::Index)
95
- p.add_block Proc.new { float :p_float }
93
+ p.add_block proc { float :p_float }
96
94
  p.exec
97
95
  expect(p.params.first.type).to eq(Float)
98
96
  end
99
97
 
100
98
  it 'has param bool' do
101
99
  p = HaveAPI::Params.new(:input, MyResource::Index)
102
- p.add_block Proc.new { bool :p_bool }
100
+ p.add_block proc { bool :p_bool }
103
101
  p.exec
104
102
  expect(p.params.first.type).to eq(Boolean)
105
103
  end
106
104
 
107
105
  it 'has param datetime' do
108
106
  p = HaveAPI::Params.new(:input, MyResource::Index)
109
- p.add_block Proc.new { datetime :p_datetime }
107
+ p.add_block proc { datetime :p_datetime }
110
108
  p.exec
111
109
  expect(p.params.first.type).to eq(Datetime)
112
110
  end
113
111
 
114
112
  it 'has param param' do
115
113
  p = HaveAPI::Params.new(:input, MyResource::Index)
116
- p.add_block Proc.new { param :p_param, type: Integer }
114
+ p.add_block proc { param :p_param, type: Integer }
117
115
  p.exec
118
116
  expect(p.params.first.type).to eq(Integer)
119
117
  end
120
118
 
121
119
  it 'has param resource' do
122
120
  p = HaveAPI::Params.new(:input, MyResource::Index)
123
- p.add_block Proc.new { resource MyResource }
121
+ p.add_block proc { resource MyResource }
124
122
  p.exec
125
123
  expect(p.params.first).to be_an_instance_of(HaveAPI::Parameters::Resource)
126
124
  end
127
125
 
128
126
  it 'patches params' do
129
127
  p = HaveAPI::Params.new(:input, MyResource::Index)
130
- p.add_block(Proc.new do
128
+ p.add_block(proc do
131
129
  string :param1, label: 'Param 1'
132
130
  string :param2, label: 'Param 2', desc: 'Implicit description'
133
131
  end)
@@ -140,7 +138,7 @@ describe HaveAPI::Params do
140
138
 
141
139
  it 'validates upon build' do
142
140
  p = HaveAPI::Params.new(:output, MyResource::Index)
143
- p.add_block Proc.new { resource MyResource }
141
+ p.add_block proc { resource MyResource }
144
142
  p.exec
145
143
  expect(p.params.first).to be_an_instance_of(HaveAPI::Parameters::Resource)
146
144
  expect { p.validate_build }.to raise_error(RuntimeError)
@@ -148,7 +146,7 @@ describe HaveAPI::Params do
148
146
 
149
147
  it 'accepts valid input layout' do
150
148
  p = HaveAPI::Params.new(:input, MyResource::Index)
151
- p.add_block(Proc.new do
149
+ p.add_block(proc do
152
150
  string :param1, required: true
153
151
  string :param2
154
152
  end)
@@ -163,7 +161,7 @@ describe HaveAPI::Params do
163
161
 
164
162
  it 'rejects invalid input layout' do
165
163
  p = HaveAPI::Params.new(:input, MyResource::Index)
166
- p.add_block(Proc.new do
164
+ p.add_block(proc do
167
165
  string :param1, required: true
168
166
  string :param2
169
167
  end)
@@ -178,7 +176,7 @@ describe HaveAPI::Params do
178
176
 
179
177
  it 'indexes parameters by name' do
180
178
  p = HaveAPI::Params.new(:input, MyResource::Index)
181
- p.add_block(Proc.new do
179
+ p.add_block(proc do
182
180
  string :param1
183
181
  string :param2
184
182
  end)
@@ -1,6 +1,5 @@
1
1
  describe HaveAPI::Resource do
2
2
  class PluralTest < HaveAPI::Resource
3
-
4
3
  end
5
4
 
6
5
  class SingularTest < HaveAPI::Resource
@@ -21,14 +20,13 @@ describe HaveAPI::Resource do
21
20
  end
22
21
 
23
22
  class ComplexTest < HaveAPI::Resource
24
- class Index < HaveAPI::Actions::Default::Index ; end
25
- class Show < HaveAPI::Actions::Default::Show ; end
26
- class Create < HaveAPI::Actions::Default::Create ; end
27
- class Dummy ; end
23
+ class Index < HaveAPI::Actions::Default::Index; end
24
+ class Show < HaveAPI::Actions::Default::Show; end
25
+ class Create < HaveAPI::Actions::Default::Create; end
28
26
 
29
27
  class SubResource < HaveAPI::Resource
30
- class Index < HaveAPI::Actions::Default::Index ; end
31
- class Show < HaveAPI::Actions::Default::Show ; end
28
+ class Index < HaveAPI::Actions::Default::Index; end
29
+ class Show < HaveAPI::Actions::Default::Show; end
32
30
  end
33
31
  end
34
32
 
data/spec/spec_helper.rb CHANGED
@@ -5,7 +5,6 @@ require_rel '../lib/haveapi/spec/*.rb'
5
5
  module HaveAPI
6
6
  module Spec
7
7
  module API
8
-
9
8
  end
10
9
  end
11
10
  end
@@ -4,7 +4,7 @@ describe HaveAPI::Validators::Acceptance do
4
4
  expect(@v.valid?('foo')).to be true
5
5
  end
6
6
 
7
- it "rejects incorrect value" do
7
+ it 'rejects incorrect value' do
8
8
  expect(@v.valid?('bar')).to be false
9
9
  end
10
10
  end
@@ -1,11 +1,11 @@
1
1
  describe HaveAPI::Validators::Confirmation do
2
2
  shared_examples(:all) do
3
3
  it 'accepts the same value' do
4
- expect(@v.validate('foo', {other_param: 'foo'})).to be true
4
+ expect(@v.validate('foo', { other_param: 'foo' })).to be true
5
5
  end
6
6
 
7
- it "rejects a different value" do
8
- expect(@v.validate('bar', {other_param: 'foo'})).to be false
7
+ it 'rejects a different value' do
8
+ expect(@v.validate('bar', { other_param: 'foo' })).to be false
9
9
  end
10
10
  end
11
11
 
@@ -36,11 +36,11 @@ describe HaveAPI::Validators::Confirmation do
36
36
  end
37
37
 
38
38
  it 'rejects the same value' do
39
- expect(@v.validate('foo', {other_param: 'foo'})).to be false
39
+ expect(@v.validate('foo', { other_param: 'foo' })).to be false
40
40
  end
41
41
 
42
42
  it 'accepts a different value' do
43
- expect(@v.validate('bar', {other_param: 'foo'})).to be true
43
+ expect(@v.validate('bar', { other_param: 'foo' })).to be true
44
44
  end
45
45
  end
46
46
  end
@@ -6,7 +6,7 @@ describe HaveAPI::Validators::Exclusion do
6
6
  expect(@v.valid?('three')).to be false
7
7
  end
8
8
 
9
- it "accepts an unlisted value" do
9
+ it 'accepts an unlisted value' do
10
10
  expect(@v.valid?('zero')).to be true
11
11
  expect(@v.valid?('four')).to be true
12
12
  end
@@ -14,7 +14,7 @@ describe HaveAPI::Validators::Exclusion do
14
14
 
15
15
  context 'short form' do
16
16
  before(:each) do
17
- @v = HaveAPI::Validators::Exclusion.new(:exclude, %w(one two three))
17
+ @v = HaveAPI::Validators::Exclusion.new(:exclude, %w[one two three])
18
18
  end
19
19
 
20
20
  include_examples :all
@@ -23,7 +23,7 @@ describe HaveAPI::Validators::Exclusion do
23
23
  context 'full form' do
24
24
  before(:each) do
25
25
  @v = HaveAPI::Validators::Exclusion.new(:exclude, {
26
- values: %w(one two three)
26
+ values: %w[one two three]
27
27
  })
28
28
  end
29
29
 
@@ -5,7 +5,7 @@ describe HaveAPI::Validators::Format do
5
5
  expect(@v.valid?('aacacb')).to be true
6
6
  end
7
7
 
8
- it "rejects a value that does not match the regexp" do
8
+ it 'rejects a value that does not match the regexp' do
9
9
  expect(@v.valid?('aacac')).to be false
10
10
  expect(@v.valid?('bacacb')).to be false
11
11
  expect(@v.valid?('b')).to be false
@@ -45,7 +45,7 @@ describe HaveAPI::Validators::Format do
45
45
  expect(@v.valid?('aacacb')).to be false
46
46
  end
47
47
 
48
- it "accepts a value if it does not match the regexp" do
48
+ it 'accepts a value if it does not match the regexp' do
49
49
  expect(@v.valid?('aacac')).to be true
50
50
  expect(@v.valid?('bacacb')).to be true
51
51
  expect(@v.valid?('b')).to be true
@@ -6,14 +6,14 @@ describe HaveAPI::Validators::Inclusion do
6
6
  expect(@v.valid?('three')).to be true
7
7
  end
8
8
 
9
- it "rejects an unlisted value" do
9
+ it 'rejects an unlisted value' do
10
10
  expect(@v.valid?('zero')).to be false
11
11
  expect(@v.valid?('four')).to be false
12
12
  end
13
13
  end
14
14
 
15
15
  [
16
- %w(one two three),
16
+ %w[one two three],
17
17
  {
18
18
  one: 'Fancy one',
19
19
  two: 'Fancy two',
@@ -23,7 +23,7 @@ describe HaveAPI::Validators::Inclusion do
23
23
  context "with include as a '#{include.class}'" do
24
24
  context 'short form' do
25
25
  before(:each) do
26
- @v = HaveAPI::Validators::Inclusion.new(:include, %w(one two three))
26
+ @v = HaveAPI::Validators::Inclusion.new(:include, %w[one two three])
27
27
  end
28
28
 
29
29
  include_examples :all
@@ -32,7 +32,7 @@ describe HaveAPI::Validators::Inclusion do
32
32
  context 'full form' do
33
33
  before(:each) do
34
34
  @v = HaveAPI::Validators::Inclusion.new(:include, {
35
- values: %w(one two three)
35
+ values: %w[one two three]
36
36
  })
37
37
  end
38
38
 
@@ -1,10 +1,10 @@
1
1
  describe HaveAPI::Validators::Length do
2
2
  it 'does not allow to mix min/max with equals' do
3
3
  expect do
4
- HaveAPI::Validators::Length.new(:length, {min: 33, equals: 42})
4
+ HaveAPI::Validators::Length.new(:length, { min: 33, equals: 42 })
5
5
  end.to raise_error(RuntimeError)
6
6
  end
7
-
7
+
8
8
  it 'requires one of min, max or equals' do
9
9
  expect do
10
10
  HaveAPI::Validators::Length.new(:length, {})
@@ -12,34 +12,34 @@ describe HaveAPI::Validators::Length do
12
12
  end
13
13
 
14
14
  it 'checks minimum' do
15
- v = HaveAPI::Validators::Length.new(:length, {min: 2})
16
- expect(v.valid?('a'*1)).to be false
17
- expect(v.valid?('a'*2)).to be true
18
- expect(v.valid?('a'*33)).to be true
15
+ v = HaveAPI::Validators::Length.new(:length, { min: 2 })
16
+ expect(v.valid?('a' * 1)).to be false
17
+ expect(v.valid?('a' * 2)).to be true
18
+ expect(v.valid?('a' * 33)).to be true
19
19
  end
20
-
20
+
21
21
  it 'checks maximum' do
22
- v = HaveAPI::Validators::Length.new(:length, {max: 5})
23
- expect(v.valid?('a'*4)).to be true
24
- expect(v.valid?('a'*5)).to be true
25
- expect(v.valid?('a'*6)).to be false
26
- expect(v.valid?('a'*11)).to be false
22
+ v = HaveAPI::Validators::Length.new(:length, { max: 5 })
23
+ expect(v.valid?('a' * 4)).to be true
24
+ expect(v.valid?('a' * 5)).to be true
25
+ expect(v.valid?('a' * 6)).to be false
26
+ expect(v.valid?('a' * 11)).to be false
27
27
  end
28
28
 
29
29
  it 'checks range' do
30
- v = HaveAPI::Validators::Length.new(:length, {min: 3, max: 6})
31
- expect(v.valid?('a'*2)).to be false
32
- expect(v.valid?('a'*3)).to be true
33
- expect(v.valid?('a'*4)).to be true
34
- expect(v.valid?('a'*5)).to be true
35
- expect(v.valid?('a'*6)).to be true
36
- expect(v.valid?('a'*7)).to be false
30
+ v = HaveAPI::Validators::Length.new(:length, { min: 3, max: 6 })
31
+ expect(v.valid?('a' * 2)).to be false
32
+ expect(v.valid?('a' * 3)).to be true
33
+ expect(v.valid?('a' * 4)).to be true
34
+ expect(v.valid?('a' * 5)).to be true
35
+ expect(v.valid?('a' * 6)).to be true
36
+ expect(v.valid?('a' * 7)).to be false
37
37
  end
38
38
 
39
39
  it 'check a specific length' do
40
- v = HaveAPI::Validators::Length.new(:length, {equals: 4})
41
- expect(v.valid?('a'*2)).to be false
42
- expect(v.valid?('a'*4)).to be true
43
- expect(v.valid?('a'*5)).to be false
40
+ v = HaveAPI::Validators::Length.new(:length, { equals: 4 })
41
+ expect(v.valid?('a' * 2)).to be false
42
+ expect(v.valid?('a' * 4)).to be true
43
+ expect(v.valid?('a' * 5)).to be false
44
44
  end
45
45
  end
@@ -1,19 +1,19 @@
1
1
  describe HaveAPI::Validators::Numericality do
2
2
  it 'cannot be both even and odd at the same time' do
3
3
  expect do
4
- HaveAPI::Validators::Numericality.new(:number, {odd: true, even: true})
4
+ HaveAPI::Validators::Numericality.new(:number, { odd: true, even: true })
5
5
  end.to raise_error(RuntimeError)
6
6
  end
7
7
 
8
8
  it 'checks minimum' do
9
- v = HaveAPI::Validators::Numericality.new(:number, {min: 5})
9
+ v = HaveAPI::Validators::Numericality.new(:number, { min: 5 })
10
10
  expect(v.valid?(4)).to be false
11
11
  expect(v.valid?(5)).to be true
12
12
  expect(v.valid?(6)).to be true
13
13
  end
14
-
14
+
15
15
  it 'checks maximum' do
16
- v = HaveAPI::Validators::Numericality.new(:number, {max: 50})
16
+ v = HaveAPI::Validators::Numericality.new(:number, { max: 50 })
17
17
  expect(v.valid?(100)).to be false
18
18
  expect(v.valid?(51)).to be false
19
19
  expect(v.valid?(50)).to be true
@@ -21,16 +21,16 @@ describe HaveAPI::Validators::Numericality do
21
21
  end
22
22
 
23
23
  it 'checks that x % y = 0' do
24
- v = HaveAPI::Validators::Numericality.new(:number, {mod: 2})
24
+ v = HaveAPI::Validators::Numericality.new(:number, { mod: 2 })
25
25
  expect(v.valid?(3)).to be false
26
26
  expect(v.valid?(15)).to be false
27
27
  expect(v.valid?(0)).to be true
28
28
  expect(v.valid?(2)).to be true
29
29
  expect(v.valid?(48)).to be true
30
30
  end
31
-
31
+
32
32
  it 'checks that the number is in a step' do
33
- v = HaveAPI::Validators::Numericality.new(:number, {step: 3})
33
+ v = HaveAPI::Validators::Numericality.new(:number, { step: 3 })
34
34
  expect(v.valid?(4)).to be false
35
35
  expect(v.valid?(14)).to be false
36
36
  expect(v.valid?(0)).to be true
@@ -40,7 +40,7 @@ describe HaveAPI::Validators::Numericality do
40
40
  end
41
41
 
42
42
  it 'checks that the number is in a step with a minimum' do
43
- v = HaveAPI::Validators::Numericality.new(:number, {min: 5, step: 3})
43
+ v = HaveAPI::Validators::Numericality.new(:number, { min: 5, step: 3 })
44
44
  expect(v.valid?(0)).to be false
45
45
  expect(v.valid?(3)).to be false
46
46
  expect(v.valid?(4)).to be false
@@ -53,15 +53,15 @@ describe HaveAPI::Validators::Numericality do
53
53
  end
54
54
 
55
55
  it 'checks that the number is even' do
56
- v = HaveAPI::Validators::Numericality.new(:number, {even: true})
56
+ v = HaveAPI::Validators::Numericality.new(:number, { even: true })
57
57
  expect(v.valid?(1)).to be false
58
58
  expect(v.valid?(3)).to be false
59
59
  expect(v.valid?(0)).to be true
60
60
  expect(v.valid?(2)).to be true
61
61
  end
62
-
62
+
63
63
  it 'checks that the number is odd' do
64
- v = HaveAPI::Validators::Numericality.new(:number, {odd: true})
64
+ v = HaveAPI::Validators::Numericality.new(:number, { odd: true })
65
65
  expect(v.valid?(1)).to be true
66
66
  expect(v.valid?(3)).to be true
67
67
  expect(v.valid?(0)).to be false
@@ -69,12 +69,12 @@ describe HaveAPI::Validators::Numericality do
69
69
  end
70
70
 
71
71
  it 'checks number as string' do
72
- v = HaveAPI::Validators::Numericality.new(:number, {min: 5})
72
+ v = HaveAPI::Validators::Numericality.new(:number, { min: 5 })
73
73
  expect(v.valid?('5')).to be true
74
74
  end
75
75
 
76
76
  it 'rejects a string that is not a number' do
77
- v = HaveAPI::Validators::Numericality.new(:number, {min: 5})
77
+ v = HaveAPI::Validators::Numericality.new(:number, { min: 5 })
78
78
  expect(v.valid?('abc')).to be false
79
79
  end
80
80
  end
@@ -7,7 +7,7 @@ describe HaveAPI::Validators::Presence do
7
7
  it 'rejects a missing or empty value' do
8
8
  expect(@v.valid?(nil)).to be false
9
9
  expect(@v.valid?('')).to be false
10
- expect(@v.valid?(" \t"*4)).to be false
10
+ expect(@v.valid?(" \t" * 4)).to be false
11
11
  end
12
12
  end
13
13
 
@@ -31,7 +31,7 @@ describe HaveAPI::Validators::Presence do
31
31
 
32
32
  context 'with empty = false' do
33
33
  before(:each) do
34
- @v = HaveAPI::Validators::Presence.new(:required, {empty: true})
34
+ @v = HaveAPI::Validators::Presence.new(:required, { empty: true })
35
35
  end
36
36
 
37
37
  it 'accepts a present value' do
@@ -41,7 +41,7 @@ describe HaveAPI::Validators::Presence do
41
41
  it 'rejects a missing or an empty value' do
42
42
  expect(@v.valid?(nil)).to be false
43
43
  expect(@v.valid?('')).to be true
44
- expect(@v.valid?(" \t"*4)).to be true
44
+ expect(@v.valid?(" \t" * 4)).to be true
45
45
  end
46
46
  end
47
47
  end