shutl_resource 0.10.5 → 0.10.6
Sign up to get free protection for your applications and to get access to all the features.
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'logger'
|
2
2
|
|
3
3
|
module Shutl::Resource
|
4
|
-
|
5
4
|
class << self
|
6
|
-
attr_writer :raise_exceptions_on_validation
|
5
|
+
attr_writer :raise_exceptions_on_validation,
|
6
|
+
:raise_exceptions_on_no_quotes_generated
|
7
7
|
|
8
8
|
def raise_exceptions_on_validation
|
9
9
|
if @raise_exceptions_on_validation.nil?
|
@@ -12,6 +12,14 @@ module Shutl::Resource
|
|
12
12
|
|
13
13
|
@raise_exceptions_on_validation
|
14
14
|
end
|
15
|
+
|
16
|
+
def raise_exceptions_on_no_quotes_generated
|
17
|
+
if @raise_exceptions_on_no_quotes_generated.nil?
|
18
|
+
@raise_exceptions_on_no_quotes_generated = true
|
19
|
+
end
|
20
|
+
|
21
|
+
@raise_exceptions_on_no_quotes_generated
|
22
|
+
end
|
15
23
|
end
|
16
24
|
|
17
25
|
def configure(*args, &block)
|
@@ -234,7 +234,13 @@ module Shutl::Resource
|
|
234
234
|
def check_fail response, message
|
235
235
|
c = response.code
|
236
236
|
failure_klass = case c
|
237
|
-
when 299
|
237
|
+
when 299
|
238
|
+
if Shutl::Resource.raise_exceptions_on_no_quotes_generated
|
239
|
+
Shutl::NoQuotesGenerated
|
240
|
+
else
|
241
|
+
nil
|
242
|
+
end
|
243
|
+
|
238
244
|
when 400 then Shutl::BadRequest
|
239
245
|
when 401 then Shutl::UnauthorizedAccess
|
240
246
|
when 403 then Shutl::ForbiddenAccess
|
data/spec/rest_resource_spec.rb
CHANGED
@@ -81,15 +81,44 @@ describe Shutl::Resource::Rest do
|
|
81
81
|
resource.instance_variable_get('@b').should == 2
|
82
82
|
end
|
83
83
|
|
84
|
-
|
84
|
+
context "299" do
|
85
|
+
specify do
|
86
|
+
@default = Shutl::Resource.raise_exceptions_on_no_quotes_generated
|
87
|
+
Shutl::Resource.raise_exceptions_on_no_quotes_generated = false
|
88
|
+
|
89
|
+
stub_request(:get, 'http://host/test_rests/b').
|
90
|
+
to_return(status: 299, :body => '{"errors": {"base":["No quotes for you today"]}}')
|
91
|
+
|
92
|
+
expect(-> { TestRest.find('b') }).not_to raise_error Shutl::NoQuotesGenerated
|
93
|
+
Shutl::Resource.raise_exceptions_on_no_quotes_generated = @default
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
context "422" do
|
98
|
+
before do
|
99
|
+
@default = Shutl::Resource.raise_exceptions_on_validation
|
100
|
+
Shutl::Resource.raise_exceptions_on_validation = true
|
101
|
+
end
|
102
|
+
|
103
|
+
after do
|
104
|
+
Shutl::Resource.raise_exceptions_on_validation = @default
|
105
|
+
end
|
106
|
+
specify do
|
107
|
+
stub_request(:get, 'http://host/test_rests/b').
|
108
|
+
to_return(status: 422)
|
109
|
+
|
110
|
+
expect(-> { TestRest.find('b') }).to raise_error(Shutl::ResourceInvalid)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
85
114
|
{
|
115
|
+
299 => Shutl::NoQuotesGenerated,
|
86
116
|
400 => Shutl::BadRequest,
|
87
117
|
401 => Shutl::UnauthorizedAccess,
|
88
118
|
403 => Shutl::ForbiddenAccess,
|
89
119
|
404 => Shutl::ResourceNotFound,
|
90
120
|
409 => Shutl::ResourceConflict,
|
91
121
|
410 => Shutl::ResourceGone,
|
92
|
-
422 => Shutl::ResourceInvalid,
|
93
122
|
503 => Shutl::ServiceUnavailable,
|
94
123
|
501..502 => Shutl::ServerError,
|
95
124
|
504..599 => Shutl::ServerError
|
@@ -112,6 +141,7 @@ describe Shutl::Resource::Rest do
|
|
112
141
|
end
|
113
142
|
end
|
114
143
|
|
144
|
+
|
115
145
|
it 'should add a id based on the resource id' do
|
116
146
|
resource = TestRest.find('a')
|
117
147
|
|
@@ -124,9 +154,9 @@ describe Shutl::Resource::Rest do
|
|
124
154
|
to_return(:status => 200, :body => '{"test_rest": {}}',
|
125
155
|
:headers => headers)
|
126
156
|
|
127
|
-
|
157
|
+
TestRest.find('new resource')
|
128
158
|
|
129
|
-
|
159
|
+
request.should have_been_requested
|
130
160
|
end
|
131
161
|
|
132
162
|
context 'with url arguments' do
|
@@ -299,9 +329,9 @@ describe Shutl::Resource::Rest do
|
|
299
329
|
with(body: '{"test_rest":{"a":"a","b":"b"}}',
|
300
330
|
headers: headers)
|
301
331
|
|
302
|
-
|
332
|
+
TestRest.create(a: 'a', b: 'b')
|
303
333
|
|
304
|
-
|
334
|
+
request.should have_been_requested
|
305
335
|
end
|
306
336
|
|
307
337
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shutl_resource
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.10.
|
4
|
+
version: 0.10.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -15,7 +15,7 @@ date: 2013-07-19 00:00:00.000000000 Z
|
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: httparty
|
18
|
-
requirement: &
|
18
|
+
requirement: &70172591200440 !ruby/object:Gem::Requirement
|
19
19
|
none: false
|
20
20
|
requirements:
|
21
21
|
- - ~>
|
@@ -23,10 +23,10 @@ dependencies:
|
|
23
23
|
version: 0.10.0
|
24
24
|
type: :runtime
|
25
25
|
prerelease: false
|
26
|
-
version_requirements: *
|
26
|
+
version_requirements: *70172591200440
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: shutl_auth
|
29
|
-
requirement: &
|
29
|
+
requirement: &70172591199320 !ruby/object:Gem::Requirement
|
30
30
|
none: false
|
31
31
|
requirements:
|
32
32
|
- - =
|
@@ -34,10 +34,10 @@ dependencies:
|
|
34
34
|
version: 0.8.0
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
|
-
version_requirements: *
|
37
|
+
version_requirements: *70172591199320
|
38
38
|
- !ruby/object:Gem::Dependency
|
39
39
|
name: activemodel
|
40
|
-
requirement: &
|
40
|
+
requirement: &70172591198300 !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
42
|
requirements:
|
43
43
|
- - ! '>='
|
@@ -45,10 +45,10 @@ dependencies:
|
|
45
45
|
version: '0'
|
46
46
|
type: :runtime
|
47
47
|
prerelease: false
|
48
|
-
version_requirements: *
|
48
|
+
version_requirements: *70172591198300
|
49
49
|
- !ruby/object:Gem::Dependency
|
50
50
|
name: rake
|
51
|
-
requirement: &
|
51
|
+
requirement: &70172591220740 !ruby/object:Gem::Requirement
|
52
52
|
none: false
|
53
53
|
requirements:
|
54
54
|
- - ! '>='
|
@@ -56,10 +56,10 @@ dependencies:
|
|
56
56
|
version: '0'
|
57
57
|
type: :development
|
58
58
|
prerelease: false
|
59
|
-
version_requirements: *
|
59
|
+
version_requirements: *70172591220740
|
60
60
|
- !ruby/object:Gem::Dependency
|
61
61
|
name: rspec
|
62
|
-
requirement: &
|
62
|
+
requirement: &70172591214620 !ruby/object:Gem::Requirement
|
63
63
|
none: false
|
64
64
|
requirements:
|
65
65
|
- - ~>
|
@@ -67,10 +67,10 @@ dependencies:
|
|
67
67
|
version: 2.11.0
|
68
68
|
type: :development
|
69
69
|
prerelease: false
|
70
|
-
version_requirements: *
|
70
|
+
version_requirements: *70172591214620
|
71
71
|
- !ruby/object:Gem::Dependency
|
72
72
|
name: debugger
|
73
|
-
requirement: &
|
73
|
+
requirement: &70172591232420 !ruby/object:Gem::Requirement
|
74
74
|
none: false
|
75
75
|
requirements:
|
76
76
|
- - ! '>='
|
@@ -78,10 +78,10 @@ dependencies:
|
|
78
78
|
version: '0'
|
79
79
|
type: :development
|
80
80
|
prerelease: false
|
81
|
-
version_requirements: *
|
81
|
+
version_requirements: *70172591232420
|
82
82
|
- !ruby/object:Gem::Dependency
|
83
83
|
name: webmock
|
84
|
-
requirement: &
|
84
|
+
requirement: &70172591231420 !ruby/object:Gem::Requirement
|
85
85
|
none: false
|
86
86
|
requirements:
|
87
87
|
- - ~>
|
@@ -89,7 +89,7 @@ dependencies:
|
|
89
89
|
version: 1.8.7
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
|
-
version_requirements: *
|
92
|
+
version_requirements: *70172591231420
|
93
93
|
description: Shutl Rest resource
|
94
94
|
email:
|
95
95
|
- davidr@shutl.co.uk
|
@@ -140,7 +140,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
140
140
|
version: '0'
|
141
141
|
segments:
|
142
142
|
- 0
|
143
|
-
hash: -
|
143
|
+
hash: -655986128022496311
|
144
144
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
145
|
none: false
|
146
146
|
requirements:
|
@@ -149,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
149
|
version: '0'
|
150
150
|
segments:
|
151
151
|
- 0
|
152
|
-
hash: -
|
152
|
+
hash: -655986128022496311
|
153
153
|
requirements: []
|
154
154
|
rubyforge_project:
|
155
155
|
rubygems_version: 1.8.11
|