active_rest_client 1.0.9 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +22 -0
- data/active_rest_client.gemspec +1 -0
- data/lib/active_rest_client/base.rb +5 -1
- data/lib/active_rest_client/caching.rb +6 -5
- data/lib/active_rest_client/configuration.rb +6 -0
- data/lib/active_rest_client/connection_manager.rb +15 -0
- data/lib/active_rest_client/proxy_base.rb +36 -2
- data/lib/active_rest_client/request.rb +54 -45
- data/lib/active_rest_client/request_delegator.rb +44 -0
- data/lib/active_rest_client/result_iterator.rb +4 -3
- data/lib/active_rest_client/validation.rb +1 -1
- data/lib/active_rest_client/version.rb +1 -1
- data/lib/active_rest_client.rb +1 -0
- data/spec/lib/base_spec.rb +34 -18
- data/spec/lib/caching_spec.rb +5 -5
- data/spec/lib/configuration_spec.rb +24 -0
- data/spec/lib/connection_manager_spec.rb +7 -0
- data/spec/lib/instrumentation_spec.rb +1 -1
- data/spec/lib/proxy_spec.rb +7 -7
- data/spec/lib/request_spec.rb +117 -60
- data/spec/lib/result_iterator_spec.rb +8 -1
- data/spec/lib/validation_spec.rb +14 -14
- data/spec/spec_helper.rb +31 -0
- metadata +17 -2
data/spec/lib/validation_spec.rb
CHANGED
@@ -17,86 +17,86 @@ describe "ActiveRestClient::Validation" do
|
|
17
17
|
a = SimpleValidationExample.new
|
18
18
|
a.first_name = nil
|
19
19
|
a.valid?
|
20
|
-
expect(a.
|
20
|
+
expect(a._errors[:first_name].size).to eq(1)
|
21
21
|
end
|
22
22
|
|
23
23
|
it "should be valid if a required value is present" do
|
24
24
|
a = SimpleValidationExample.new
|
25
25
|
a.first_name = "John"
|
26
26
|
a.valid?
|
27
|
-
expect(a.
|
27
|
+
expect(a._errors[:first_name]).to be_empty
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should be invalid if a length within value is outside the range" do
|
31
31
|
a = SimpleValidationExample.new(password:"12345")
|
32
32
|
a.valid?
|
33
|
-
expect(a.
|
33
|
+
expect(a._errors[:password].size).to eq(1)
|
34
34
|
end
|
35
35
|
|
36
36
|
it "should be valid if a length within value is inside the range" do
|
37
37
|
a = SimpleValidationExample.new(password:"123456")
|
38
38
|
a.valid?
|
39
|
-
expect(a.
|
39
|
+
expect(a._errors[:password].size).to eq(0)
|
40
40
|
end
|
41
41
|
|
42
42
|
it "should be invalid if a length is below the minimum" do
|
43
43
|
a = SimpleValidationExample.new(post_code:"12345")
|
44
44
|
a.valid?
|
45
|
-
expect(a.
|
45
|
+
expect(a._errors[:post_code].size).to eq(1)
|
46
46
|
end
|
47
47
|
|
48
48
|
it "should be valid if a length is above or equal to the minimum and below the maximum" do
|
49
49
|
a = SimpleValidationExample.new(post_code:"123456")
|
50
50
|
a.valid?
|
51
|
-
expect(a.
|
51
|
+
expect(a._errors[:post_code].size).to eq(0)
|
52
52
|
end
|
53
53
|
|
54
54
|
it "should be invalid if a length is above the maximum" do
|
55
55
|
a = SimpleValidationExample.new(post_code:"123456789")
|
56
56
|
a.valid?
|
57
|
-
expect(a.
|
57
|
+
expect(a._errors[:post_code].size).to eq(1)
|
58
58
|
end
|
59
59
|
|
60
60
|
it "should be able to validate that a field is numeric" do
|
61
61
|
a = SimpleValidationExample.new(salary:"Bob")
|
62
62
|
a.valid?
|
63
|
-
expect(a.
|
63
|
+
expect(a._errors[:salary].size).to be > 0
|
64
64
|
end
|
65
65
|
|
66
66
|
it "should be able to validate that a numeric field is above or equal to a minimum" do
|
67
67
|
a = SimpleValidationExample.new(salary:10_000)
|
68
68
|
a.valid?
|
69
|
-
expect(a.
|
69
|
+
expect(a._errors[:salary].size).to be > 0
|
70
70
|
end
|
71
71
|
|
72
72
|
it "should be able to validate that a numeric field is above or equal to a minimum" do
|
73
73
|
a = SimpleValidationExample.new(salary:100_000)
|
74
74
|
a.valid?
|
75
|
-
expect(a.
|
75
|
+
expect(a._errors[:salary].size).to be > 0
|
76
76
|
end
|
77
77
|
|
78
78
|
it "should be invalid when a block adds an error" do
|
79
79
|
class ValidationExample1 < OpenStruct
|
80
80
|
include ActiveRestClient::Validation
|
81
81
|
validates :first_name do |object, name, value|
|
82
|
-
object.
|
82
|
+
object._errors[name] << "must be over 4 chars long" if value.length <= 4
|
83
83
|
end
|
84
84
|
end
|
85
85
|
a = ValidationExample1.new(first_name:"John")
|
86
86
|
a.valid?
|
87
|
-
expect(a.
|
87
|
+
expect(a._errors[:first_name].size).to eq(1)
|
88
88
|
end
|
89
89
|
|
90
90
|
it "should be valid when a block doesn't add an error" do
|
91
91
|
class ValidationExample2 < OpenStruct
|
92
92
|
include ActiveRestClient::Validation
|
93
93
|
validates :first_name do |object, name, value|
|
94
|
-
object.
|
94
|
+
object._errors[name] << "must be over 4 chars long" if value.length <= 4
|
95
95
|
end
|
96
96
|
end
|
97
97
|
a = ValidationExample2.new(first_name:"Johnny")
|
98
98
|
a.valid?
|
99
|
-
expect(a.
|
99
|
+
expect(a._errors[:first_name]).to be_empty
|
100
100
|
end
|
101
101
|
|
102
102
|
it "should call valid? before making a request" do
|
data/spec/spec_helper.rb
CHANGED
@@ -55,3 +55,34 @@ class TestCacheStore
|
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
58
|
+
|
59
|
+
class FaradayResponseMock < ::ActiveRestClient::FaradayResponseProxy
|
60
|
+
# The FaradayResponseMock is setup to automatically resolve all calls by default.
|
61
|
+
# By setting auto_resolve to false it allows the spec to control when the response
|
62
|
+
# is resolved, which simulates what it is like when inside a Faraday in_parallel block.
|
63
|
+
def initialize(response, auto_resolve=true)
|
64
|
+
super(response)
|
65
|
+
@auto_resolve = auto_resolve
|
66
|
+
@finished = false
|
67
|
+
end
|
68
|
+
|
69
|
+
def on_complete
|
70
|
+
if @auto_resolve
|
71
|
+
@finished = true
|
72
|
+
yield(@response)
|
73
|
+
else
|
74
|
+
@callback = Proc.new
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# This is exactly what is called on responses after a Faraday in_parallel block ends.
|
79
|
+
# This method simulates the end of in_parallel block.
|
80
|
+
def finish
|
81
|
+
@finished = true
|
82
|
+
@callback.call(@response)
|
83
|
+
end
|
84
|
+
|
85
|
+
def finished?
|
86
|
+
@finished
|
87
|
+
end
|
88
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_rest_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Which Ltd
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-06-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -165,6 +165,20 @@ dependencies:
|
|
165
165
|
- - ">="
|
166
166
|
- !ruby/object:Gem::Version
|
167
167
|
version: 1.3.1
|
168
|
+
- !ruby/object:Gem::Dependency
|
169
|
+
name: typhoeus
|
170
|
+
requirement: !ruby/object:Gem::Requirement
|
171
|
+
requirements:
|
172
|
+
- - ">="
|
173
|
+
- !ruby/object:Gem::Version
|
174
|
+
version: '0'
|
175
|
+
type: :development
|
176
|
+
prerelease: false
|
177
|
+
version_requirements: !ruby/object:Gem::Requirement
|
178
|
+
requirements:
|
179
|
+
- - ">="
|
180
|
+
- !ruby/object:Gem::Version
|
181
|
+
version: '0'
|
168
182
|
- !ruby/object:Gem::Dependency
|
169
183
|
name: multi_json
|
170
184
|
requirement: !ruby/object:Gem::Requirement
|
@@ -257,6 +271,7 @@ files:
|
|
257
271
|
- lib/active_rest_client/proxy_base.rb
|
258
272
|
- lib/active_rest_client/recording.rb
|
259
273
|
- lib/active_rest_client/request.rb
|
274
|
+
- lib/active_rest_client/request_delegator.rb
|
260
275
|
- lib/active_rest_client/request_filtering.rb
|
261
276
|
- lib/active_rest_client/result_iterator.rb
|
262
277
|
- lib/active_rest_client/validation.rb
|