my_john_deere_api 2.5.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/my_john_deere_api.rb +1 -1
- data/lib/my_john_deere_api/authorize.rb +36 -27
- data/lib/my_john_deere_api/client.rb +38 -29
- data/lib/my_john_deere_api/consumer.rb +46 -35
- data/lib/my_john_deere_api/helpers/case_conversion.rb +5 -2
- data/lib/my_john_deere_api/helpers/uri_helpers.rb +1 -1
- data/lib/my_john_deere_api/model/contribution_definition.rb +1 -1
- data/lib/my_john_deere_api/net_http_retry/decorator.rb +10 -11
- data/lib/my_john_deere_api/net_http_retry/invalid_response_error.rb +2 -2
- data/lib/my_john_deere_api/request/collection/asset_locations.rb +1 -1
- data/lib/my_john_deere_api/request/collection/assets.rb +1 -1
- data/lib/my_john_deere_api/request/collection/base.rb +2 -14
- data/lib/my_john_deere_api/request/collection/contribution_definitions.rb +1 -1
- data/lib/my_john_deere_api/request/collection/contribution_products.rb +1 -1
- data/lib/my_john_deere_api/request/collection/fields.rb +1 -1
- data/lib/my_john_deere_api/request/collection/flags.rb +1 -1
- data/lib/my_john_deere_api/request/collection/organizations.rb +1 -1
- data/lib/my_john_deere_api/request/create/asset.rb +8 -11
- data/lib/my_john_deere_api/request/create/asset_location.rb +24 -25
- data/lib/my_john_deere_api/request/create/base.rb +2 -20
- data/lib/my_john_deere_api/request/individual/asset.rb +2 -2
- data/lib/my_john_deere_api/request/individual/base.rb +6 -24
- data/lib/my_john_deere_api/request/individual/contribution_definition.rb +1 -1
- data/lib/my_john_deere_api/request/individual/contribution_product.rb +1 -1
- data/lib/my_john_deere_api/request/individual/field.rb +1 -1
- data/lib/my_john_deere_api/request/individual/organization.rb +1 -1
- data/lib/my_john_deere_api/request/update/asset.rb +2 -2
- data/lib/my_john_deere_api/request/update/base.rb +1 -19
- data/lib/my_john_deere_api/version.rb +1 -1
- data/test/lib/my_john_deere_api/authorize_test.rb +37 -25
- data/test/lib/my_john_deere_api/client_test.rb +22 -56
- data/test/lib/my_john_deere_api/consumer_test.rb +16 -28
- data/test/lib/my_john_deere_api/helpers/uri_helpers_test.rb +0 -10
- data/test/lib/my_john_deere_api/model/asset_location_test.rb +0 -4
- data/test/lib/my_john_deere_api/model/asset_test.rb +9 -8
- data/test/lib/my_john_deere_api/model/base_test.rb +4 -8
- data/test/lib/my_john_deere_api/model/contribution_definition_test.rb +3 -7
- data/test/lib/my_john_deere_api/model/contribution_product_test.rb +4 -7
- data/test/lib/my_john_deere_api/model/field_test.rb +4 -6
- data/test/lib/my_john_deere_api/model/flag_test.rb +6 -7
- data/test/lib/my_john_deere_api/model/organization_test.rb +3 -5
- data/test/lib/my_john_deere_api/net_http_retry/decorator_test.rb +14 -14
- data/test/lib/my_john_deere_api/net_http_retry/invalid_response_error_test.rb +22 -2
- data/test/lib/my_john_deere_api/request/collection/asset_locations_test.rb +2 -2
- data/test/lib/my_john_deere_api/request/collection/assets_test.rb +2 -2
- data/test/lib/my_john_deere_api/request/collection/contribution_definitions_test.rb +2 -2
- data/test/lib/my_john_deere_api/request/collection/contribution_products_test.rb +2 -2
- data/test/lib/my_john_deere_api/request/collection/fields_test.rb +2 -2
- data/test/lib/my_john_deere_api/request/collection/flags_test.rb +2 -2
- data/test/lib/my_john_deere_api/request/collection/organizations_test.rb +2 -2
- data/test/lib/my_john_deere_api/request/create/asset_location_test.rb +3 -2
- data/test/lib/my_john_deere_api/request/create/asset_test.rb +5 -4
- data/test/lib/my_john_deere_api/request/create/base_test.rb +0 -14
- data/test/lib/my_john_deere_api/request/individual/asset_test.rb +2 -3
- data/test/lib/my_john_deere_api/request/individual/base_test.rb +0 -1
- data/test/lib/my_john_deere_api/request/individual/contribution_definition_test.rb +2 -3
- data/test/lib/my_john_deere_api/request/individual/contribution_product_test.rb +2 -3
- data/test/lib/my_john_deere_api/request/individual/field_test.rb +2 -3
- data/test/lib/my_john_deere_api/request/individual/organization_test.rb +2 -3
- data/test/lib/my_john_deere_api/request/update/asset_test.rb +5 -17
- data/test/lib/my_john_deere_api/request/update/base_test.rb +0 -14
- data/test/support/helper.rb +14 -5
- data/test/support/link_helpers.rb +14 -0
- data/test/support/response_helpers.rb +18 -0
- data/test/support/vcr/catalog.yml +44 -37
- data/test/support/vcr/get_access_token.yml +90 -17
- data/test/support/vcr/get_refresh_token.yml +159 -0
- data/test/support/vcr/get_request_url.yml +51 -0
- data/test/support/vcr_setup.rb +80 -19
- metadata +11 -8
- data/test/support/vcr/get_request_token.yml +0 -83
@@ -31,13 +31,12 @@ describe 'MyJohnDeereApi::Authorize' do
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
describe '#
|
35
|
-
it "returns a non-user-specific
|
34
|
+
describe '#oauth_client' do
|
35
|
+
it "returns a non-user-specific client" do
|
36
36
|
authorize = create_authorize
|
37
|
-
consumer = VCR.use_cassette('catalog') { authorize.
|
37
|
+
consumer = VCR.use_cassette('catalog') { authorize.oauth_client }
|
38
38
|
|
39
|
-
assert_kind_of
|
40
|
-
assert_equal :get, consumer.http_method
|
39
|
+
assert_kind_of OAuth2::Client, consumer
|
41
40
|
end
|
42
41
|
end
|
43
42
|
|
@@ -45,37 +44,50 @@ describe 'MyJohnDeereApi::Authorize' do
|
|
45
44
|
it 'retrieves a request url' do
|
46
45
|
authorize = create_authorize
|
47
46
|
|
48
|
-
url = VCR.use_cassette('
|
49
|
-
links = VCR.use_cassette('catalog') { JD::Consumer.new(api_key, api_secret, environment: :sandbox).send(:
|
47
|
+
url = VCR.use_cassette('get_request_url') { authorize.authorize_url }
|
48
|
+
links = VCR.use_cassette('catalog') { JD::Consumer.new(api_key, api_secret, environment: :sandbox).send(:authorization_links) }
|
50
49
|
|
51
|
-
assert_includes url, links[:
|
52
|
-
|
53
|
-
query = URI.parse(url).query
|
54
|
-
params = CGI::parse(query)
|
55
|
-
|
56
|
-
assert_match(TOKEN_PATTERN, params['oauth_token'].first)
|
50
|
+
assert_includes url, links[:authorization]
|
57
51
|
end
|
52
|
+
end
|
58
53
|
|
59
|
-
|
54
|
+
describe '#verify(code)' do
|
55
|
+
it 'sets the access/refresh token hash' do
|
60
56
|
authorize = create_authorize
|
57
|
+
code = 'VERIFY'
|
58
|
+
|
59
|
+
VCR.use_cassette('get_request_url') { authorize.authorize_url }
|
60
|
+
VCR.use_cassette('get_access_token') { authorize.verify(code) }
|
61
61
|
|
62
|
-
|
62
|
+
hash = authorize.token_hash
|
63
63
|
|
64
|
-
assert_match TOKEN_PATTERN,
|
65
|
-
assert_match
|
64
|
+
assert_match TOKEN_PATTERN, hash['access_token']
|
65
|
+
assert_match TOKEN_PATTERN, hash['refresh_token']
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
|
-
describe '#
|
70
|
-
|
71
|
-
|
72
|
-
|
69
|
+
describe '#refresh_from_hash(old_token_hash)' do
|
70
|
+
let(:authorize) { create_authorize }
|
71
|
+
|
72
|
+
let(:old_hash) do
|
73
|
+
{
|
74
|
+
"token_type": "Bearer",
|
75
|
+
"scope": "ag2 ag1 offline_access ag3",
|
76
|
+
"access_token": access_token,
|
77
|
+
"refresh_token": refresh_token,
|
78
|
+
"expires_at": 1616484631
|
79
|
+
}
|
80
|
+
end
|
73
81
|
|
74
|
-
|
75
|
-
|
82
|
+
subject { authorize.refresh_from_hash(old_hash) }
|
83
|
+
|
84
|
+
it "fetches a new token hash using OAuth2's refresh! method" do
|
85
|
+
new_hash = VCR.use_cassette('get_refresh_token') { subject }
|
86
|
+
|
87
|
+
# normalize response hash
|
88
|
+
new_hash = JSON.parse(new_hash.to_json)
|
76
89
|
|
77
|
-
|
78
|
-
assert_match SECRET_PATTERN, authorize.access_secret
|
90
|
+
assert_equal new_access_token, new_hash['access_token']
|
79
91
|
end
|
80
92
|
end
|
81
93
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'support/helper'
|
2
2
|
|
3
3
|
describe 'MyJohnDeereApi::Client' do
|
4
|
+
include JD::ResponseHelpers
|
5
|
+
|
4
6
|
it 'includes the CaseConversion helper' do
|
5
7
|
client = JD::Client.new(api_key, api_secret)
|
6
8
|
assert_equal 'thisIsATest', client.send(:camelize, :this_is_a_test)
|
@@ -14,14 +16,10 @@ describe 'MyJohnDeereApi::Client' do
|
|
14
16
|
assert_equal api_secret, client.api_secret
|
15
17
|
end
|
16
18
|
|
17
|
-
it 'accepts
|
18
|
-
|
19
|
-
access_secret = 'secret'
|
20
|
-
|
21
|
-
client = JD::Client.new(api_key, api_secret, access: [access_token, access_secret])
|
19
|
+
it 'accepts token_hash' do
|
20
|
+
client = JD::Client.new(api_key, api_secret, token_hash: token_hash)
|
22
21
|
|
23
|
-
assert_equal
|
24
|
-
assert_equal access_secret, client.access_secret
|
22
|
+
assert_equal token_hash, client.token_hash
|
25
23
|
end
|
26
24
|
|
27
25
|
it 'accepts the environment' do
|
@@ -45,7 +43,7 @@ describe 'MyJohnDeereApi::Client' do
|
|
45
43
|
api_secret,
|
46
44
|
contribution_definition_id: contribution_definition_id,
|
47
45
|
environment: :sandbox,
|
48
|
-
|
46
|
+
token_hash: token_hash,
|
49
47
|
http_retry: {max_retries: custom_retries}
|
50
48
|
)
|
51
49
|
|
@@ -66,7 +64,7 @@ describe 'MyJohnDeereApi::Client' do
|
|
66
64
|
|
67
65
|
describe '#get' do
|
68
66
|
it 'returns the response as a Hash' do
|
69
|
-
response = VCR.use_cassette('get_organizations') { client.get('/organizations') }
|
67
|
+
response = VCR.use_cassette('get_organizations') { client.get('/platform/organizations') }
|
70
68
|
|
71
69
|
assert_kind_of Hash, response
|
72
70
|
assert_kind_of Integer, response['total']
|
@@ -75,16 +73,7 @@ describe 'MyJohnDeereApi::Client' do
|
|
75
73
|
end
|
76
74
|
|
77
75
|
it 'prepends the leading slash if needed' do
|
78
|
-
response = VCR.use_cassette('get_organizations') { client.get('organizations') }
|
79
|
-
|
80
|
-
assert_kind_of Hash, response
|
81
|
-
assert_kind_of Integer, response['total']
|
82
|
-
assert response['values'].all?{|value| value['@type'] == 'Organization'}
|
83
|
-
assert response['values'].all?{|value| value.has_key?('links')}
|
84
|
-
end
|
85
|
-
|
86
|
-
it 'allows symbols for simple resources' do
|
87
|
-
response = VCR.use_cassette('get_organizations') { client.get(:organizations) }
|
76
|
+
response = VCR.use_cassette('get_organizations') { client.get('platform/organizations') }
|
88
77
|
|
89
78
|
assert_kind_of Hash, response
|
90
79
|
assert_kind_of Integer, response['total']
|
@@ -108,22 +97,20 @@ describe 'MyJohnDeereApi::Client' do
|
|
108
97
|
|
109
98
|
it 'returns the response as a Hash' do
|
110
99
|
response = VCR.use_cassette('post_assets') do
|
111
|
-
client.post("/organizations/#{organization_id}/assets", attributes)
|
100
|
+
client.post("/platform/organizations/#{organization_id}/assets", attributes)
|
112
101
|
end
|
113
102
|
|
114
|
-
|
115
|
-
assert_equal
|
116
|
-
assert_equal "#{base_url}/assets/#{asset_id}", response['Location']
|
103
|
+
assert_created response
|
104
|
+
assert_equal "#{base_url}/platform/assets/#{asset_id}", response.response.headers['Location']
|
117
105
|
end
|
118
106
|
|
119
107
|
it 'prepends the leading slash if needed' do
|
120
108
|
response = VCR.use_cassette('post_assets') do
|
121
|
-
client.post("organizations/#{organization_id}/assets", attributes)
|
109
|
+
client.post("platform/organizations/#{organization_id}/assets", attributes)
|
122
110
|
end
|
123
111
|
|
124
|
-
|
125
|
-
assert_equal
|
126
|
-
assert_equal "#{base_url}/assets/#{asset_id}", response['Location']
|
112
|
+
assert_created response
|
113
|
+
assert_equal "#{base_url}/platform/assets/#{asset_id}", response.response.headers['Location']
|
127
114
|
end
|
128
115
|
end
|
129
116
|
|
@@ -146,33 +133,29 @@ describe 'MyJohnDeereApi::Client' do
|
|
146
133
|
end
|
147
134
|
|
148
135
|
it 'sends the request' do
|
149
|
-
response = VCR.use_cassette('put_asset') { client.put("/assets/#{asset_id}", attributes) }
|
136
|
+
response = VCR.use_cassette('put_asset') { client.put("/platform/assets/#{asset_id}", attributes) }
|
150
137
|
|
151
|
-
|
152
|
-
assert_equal 'No Content', response.message
|
138
|
+
assert_no_content response
|
153
139
|
end
|
154
140
|
|
155
141
|
it 'prepends the leading slash if needed' do
|
156
|
-
response = VCR.use_cassette('put_asset') { client.put("assets/#{asset_id}", attributes) }
|
142
|
+
response = VCR.use_cassette('put_asset') { client.put("platform/assets/#{asset_id}", attributes) }
|
157
143
|
|
158
|
-
|
159
|
-
assert_equal 'No Content', response.message
|
144
|
+
assert_no_content response
|
160
145
|
end
|
161
146
|
end
|
162
147
|
|
163
148
|
describe '#delete' do
|
164
149
|
it 'sends the request' do
|
165
|
-
response = VCR.use_cassette('delete_asset') { client.delete("/assets/#{asset_id}") }
|
150
|
+
response = VCR.use_cassette('delete_asset') { client.delete("/platform/assets/#{asset_id}") }
|
166
151
|
|
167
|
-
|
168
|
-
assert_equal 'No Content', response.message
|
152
|
+
assert_no_content response
|
169
153
|
end
|
170
154
|
|
171
155
|
it 'prepends the leading slash if needed' do
|
172
|
-
response = VCR.use_cassette('delete_asset') { client.delete("assets/#{asset_id}") }
|
156
|
+
response = VCR.use_cassette('delete_asset') { client.delete("platform/assets/#{asset_id}") }
|
173
157
|
|
174
|
-
|
175
|
-
assert_equal 'No Content', response.message
|
158
|
+
assert_no_content response
|
176
159
|
end
|
177
160
|
end
|
178
161
|
|
@@ -200,26 +183,9 @@ describe 'MyJohnDeereApi::Client' do
|
|
200
183
|
end
|
201
184
|
end
|
202
185
|
|
203
|
-
describe '#consumer' do
|
204
|
-
it 'receives the api key/secret and environment of the client' do
|
205
|
-
environment = :sandbox
|
206
|
-
|
207
|
-
client = JD::Client.new(api_key, api_secret, environment: environment)
|
208
|
-
consumer = client.send :consumer
|
209
|
-
|
210
|
-
assert_kind_of JD::Consumer, consumer
|
211
|
-
assert_equal api_key, consumer.api_key
|
212
|
-
assert_equal api_secret, consumer.api_secret
|
213
|
-
assert_equal environment, consumer.environment
|
214
|
-
end
|
215
|
-
end
|
216
|
-
|
217
186
|
describe '#accessor' do
|
218
187
|
it 'returns an object that can make user-specific requests' do
|
219
188
|
assert_kind_of JD::NetHttpRetry::Decorator, accessor
|
220
|
-
assert_kind_of OAuth::Consumer, accessor.consumer
|
221
|
-
assert_equal access_token, accessor.token
|
222
|
-
assert_equal access_secret, accessor.secret
|
223
189
|
end
|
224
190
|
end
|
225
191
|
end
|
@@ -14,45 +14,33 @@ describe 'JD::Consumer' do
|
|
14
14
|
consumer = JD::Consumer.new(api_key, api_secret, environment: environment)
|
15
15
|
|
16
16
|
assert_equal environment, consumer.environment
|
17
|
-
assert_equal JD::Consumer::URLS[environment], consumer.
|
17
|
+
assert_equal JD::Consumer::URLS[environment], consumer.site
|
18
18
|
end
|
19
19
|
|
20
|
-
it 'accepts an arbitrary
|
21
|
-
|
22
|
-
consumer = JD::Consumer.new(api_key, api_secret,
|
20
|
+
it 'accepts an arbitrary site' do
|
21
|
+
site = 'https://example.com'
|
22
|
+
consumer = JD::Consumer.new(api_key, api_secret, site: site)
|
23
23
|
|
24
|
-
assert_equal
|
24
|
+
assert_equal site, consumer.site
|
25
25
|
end
|
26
26
|
|
27
|
-
it 'uses specified
|
28
|
-
|
29
|
-
consumer = JD::Consumer.new(api_key, api_secret,
|
27
|
+
it 'uses specified site regardless of specified environment' do
|
28
|
+
site = 'https://example.com'
|
29
|
+
consumer = JD::Consumer.new(api_key, api_secret, site: site, environment: :sandbox)
|
30
30
|
|
31
|
-
assert_equal
|
31
|
+
assert_equal site, consumer.site
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
describe '#
|
36
|
-
it 'creates a working oAuth
|
35
|
+
describe '#platform_client' do
|
36
|
+
it 'creates a working oAuth client' do
|
37
37
|
consumer = JD::Consumer.new(api_key, api_secret, environment: :sandbox)
|
38
|
-
|
38
|
+
platform_client = VCR.use_cassette('catalog') { consumer.platform_client }
|
39
39
|
|
40
|
-
assert_kind_of
|
41
|
-
assert_equal api_key,
|
42
|
-
assert_equal api_secret,
|
43
|
-
assert_equal JD::Consumer::URLS[:sandbox],
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
describe '#user_get' do
|
48
|
-
it 'creates a working oAuth consumer for user-specific GET requests' do
|
49
|
-
consumer = JD::Consumer.new(api_key, api_secret, environment: :sandbox)
|
50
|
-
user_get = VCR.use_cassette('catalog') { consumer.user_get }
|
51
|
-
|
52
|
-
assert_kind_of OAuth::Consumer, user_get
|
53
|
-
assert_equal api_key, user_get.key
|
54
|
-
assert_equal api_secret, user_get.secret
|
55
|
-
assert_equal "#{JD::Consumer::URLS[:sandbox]}/platform", user_get.site
|
40
|
+
assert_kind_of OAuth2::Client, platform_client
|
41
|
+
assert_equal api_key, platform_client.id
|
42
|
+
assert_equal api_secret, platform_client.secret
|
43
|
+
assert_equal JD::Consumer::URLS[:sandbox], platform_client.site
|
56
44
|
end
|
57
45
|
end
|
58
46
|
end
|
@@ -17,16 +17,6 @@ describe 'UriHelpers' do
|
|
17
17
|
assert_equal '/turtles', path
|
18
18
|
end
|
19
19
|
|
20
|
-
it 'removes leading /platform from the path' do
|
21
|
-
path = object.send(:uri_path, 'https://example.com/platform/turtles')
|
22
|
-
assert_equal '/turtles', path
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'preserves /platform in any other part of the path' do
|
26
|
-
path = object.send(:uri_path, 'https://example.com/platform/turtles/platform')
|
27
|
-
assert_equal '/turtles/platform', path
|
28
|
-
end
|
29
|
-
|
30
20
|
it 'is a private method' do
|
31
21
|
exception = assert_raises(NoMethodError) { object.uri_path('https://example.com/turtles')}
|
32
22
|
assert_includes exception.message, 'private method'
|
@@ -15,10 +15,6 @@ describe 'MyJohnDeereApi::Model::AssetLocation' do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
describe '#initialize' do
|
18
|
-
def link_for label
|
19
|
-
record['links'].detect{|link| link['rel'] == label}['uri'].gsub('https://sandboxapi.deere.com/platform', '')
|
20
|
-
end
|
21
|
-
|
22
18
|
it 'sets the attributes from the given record' do
|
23
19
|
location = klass.new(client, record)
|
24
20
|
|
@@ -1,6 +1,9 @@
|
|
1
1
|
require 'support/helper'
|
2
2
|
|
3
3
|
describe 'MyJohnDeereApi::Model::Asset' do
|
4
|
+
include JD::ResponseHelpers
|
5
|
+
include JD::LinkHelpers
|
6
|
+
|
4
7
|
let(:klass) { JD::Model::Asset }
|
5
8
|
|
6
9
|
let(:record) do
|
@@ -21,10 +24,6 @@ describe 'MyJohnDeereApi::Model::Asset' do
|
|
21
24
|
end
|
22
25
|
|
23
26
|
describe '#initialize' do
|
24
|
-
def link_for label
|
25
|
-
record['links'].detect{|link| link['rel'] == label}['uri'].gsub('https://sandboxapi.deere.com/platform', '')
|
26
|
-
end
|
27
|
-
|
28
27
|
it 'sets the attributes from the given record' do
|
29
28
|
asset = klass.new(client, record)
|
30
29
|
|
@@ -43,7 +42,7 @@ describe 'MyJohnDeereApi::Model::Asset' do
|
|
43
42
|
assert_kind_of Hash, asset.links
|
44
43
|
|
45
44
|
['self', 'organization', 'locations'].each do |association|
|
46
|
-
|
45
|
+
assert_link_for(asset, association)
|
47
46
|
end
|
48
47
|
end
|
49
48
|
end
|
@@ -70,7 +69,7 @@ describe 'MyJohnDeereApi::Model::Asset' do
|
|
70
69
|
assert_equal new_title, asset.title
|
71
70
|
|
72
71
|
response = VCR.use_cassette('put_asset') { asset.save }
|
73
|
-
|
72
|
+
assert_no_content response
|
74
73
|
end
|
75
74
|
|
76
75
|
it 'does not make a JD request if nothing has changed' do
|
@@ -85,7 +84,9 @@ describe 'MyJohnDeereApi::Model::Asset' do
|
|
85
84
|
asset.title = 'i REALLY like turtles!'
|
86
85
|
|
87
86
|
response = VCR.use_cassette('put_asset') { asset.save }
|
88
|
-
|
87
|
+
|
88
|
+
assert_equal 204, response.response.status
|
89
|
+
assert_equal 'No Content', response.response.reason_phrase
|
89
90
|
|
90
91
|
response = asset.save
|
91
92
|
assert_nil response
|
@@ -109,7 +110,7 @@ describe 'MyJohnDeereApi::Model::Asset' do
|
|
109
110
|
new_title = 'i REALLY like turtles!'
|
110
111
|
response = VCR.use_cassette('put_asset') { asset.update(title: new_title) }
|
111
112
|
|
112
|
-
|
113
|
+
assert_no_content response
|
113
114
|
end
|
114
115
|
end
|
115
116
|
|
@@ -9,6 +9,8 @@ class SampleModel < JD::Model::Base
|
|
9
9
|
end
|
10
10
|
|
11
11
|
describe 'MyJohnDeereApi::Model::Base' do
|
12
|
+
include JD::LinkHelpers
|
13
|
+
|
12
14
|
let(:klass) { JD::Model::Base }
|
13
15
|
let(:object) { klass.new(client, record) }
|
14
16
|
|
@@ -31,10 +33,6 @@ describe 'MyJohnDeereApi::Model::Base' do
|
|
31
33
|
end
|
32
34
|
|
33
35
|
describe '#initialize(client, record)' do
|
34
|
-
def link_for label
|
35
|
-
record['links'].detect{|link| link['rel'] == label}['uri'].gsub('https://sandboxapi.deere.com/platform', '')
|
36
|
-
end
|
37
|
-
|
38
36
|
describe 'when the wrong record type is passed' do
|
39
37
|
let(:record) do
|
40
38
|
{
|
@@ -59,12 +57,10 @@ describe 'MyJohnDeereApi::Model::Base' do
|
|
59
57
|
end
|
60
58
|
|
61
59
|
it 'sets the links' do
|
62
|
-
|
63
|
-
|
64
|
-
assert_kind_of Hash, links
|
60
|
+
assert_kind_of Hash, object.links
|
65
61
|
|
66
62
|
['self', 'organization', 'locations'].each do |link|
|
67
|
-
|
63
|
+
assert_link_for(object, link)
|
68
64
|
end
|
69
65
|
end
|
70
66
|
|
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'support/helper'
|
2
2
|
|
3
3
|
describe 'MyJohnDeereApi::Model::ContributionDefinition' do
|
4
|
+
include JD::LinkHelpers
|
5
|
+
|
4
6
|
let(:klass) { JD::Model::ContributionDefinition }
|
5
7
|
|
6
8
|
let(:record) do
|
@@ -25,16 +27,10 @@ describe 'MyJohnDeereApi::Model::ContributionDefinition' do
|
|
25
27
|
end
|
26
28
|
|
27
29
|
describe '#initialize' do
|
28
|
-
def link_for label
|
29
|
-
camel_label = label.gsub(/_(.)/){|m| m[1].upcase}
|
30
|
-
record['links'].detect{|link| link['rel'] == camel_label}['uri'].gsub('https://sandboxapi.deere.com/platform', '')
|
31
|
-
end
|
32
|
-
|
33
30
|
it 'sets the attributes from the given record' do
|
34
31
|
definition = klass.new(client, record)
|
35
32
|
|
36
33
|
assert_equal client, definition.client
|
37
|
-
assert_equal accessor, definition.accessor
|
38
34
|
|
39
35
|
# basic attributes
|
40
36
|
assert_equal record['id'], definition.id
|
@@ -45,7 +41,7 @@ describe 'MyJohnDeereApi::Model::ContributionDefinition' do
|
|
45
41
|
product = klass.new(client, record)
|
46
42
|
|
47
43
|
['self', 'contribution_product'].each do |association|
|
48
|
-
|
44
|
+
assert_link_for product, association
|
49
45
|
end
|
50
46
|
end
|
51
47
|
end
|