my_john_deere_api 0.5.1 → 0.5.2
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/model/asset.rb +4 -0
- data/lib/my_john_deere_api/model/asset_location.rb +4 -0
- data/lib/my_john_deere_api/model/base.rb +11 -0
- data/lib/my_john_deere_api/model/field.rb +4 -0
- data/lib/my_john_deere_api/model/flag.rb +4 -0
- data/lib/my_john_deere_api/model/organization.rb +4 -0
- data/lib/my_john_deere_api/version.rb +1 -1
- data/test/lib/my_john_deere_api/model/base_test.rb +10 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4517a78430360d8ba494a5e64a206eb6924cd9ee1d9c1bcdfff6a823f17496e8
|
4
|
+
data.tar.gz: a0788ce8e4ead19974e675dbca2bf515ab530aaa0cfc561c914ab23651767d93
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8baaae2f1eb4d639b31b85d0a5450fd46442d31e88f2f3495465774fd445370c0433d43ef4d0a76abb61d6495ff9bc573e4185a19fda71e3b018000ddb18eaf7
|
7
|
+
data.tar.gz: 2a8e2e13cdd2ed7687fba31a10f61c7153198925120132743db6c15f857a323a822256159b1987682fab5e237ad475cd79882bc390e48552d6fdc070da21cfd0
|
@@ -15,6 +15,8 @@ module MyJohnDeereApi
|
|
15
15
|
# to be made, as is the case with *flags*.
|
16
16
|
|
17
17
|
def initialize(record, accessor = nil)
|
18
|
+
verify_record_type(record['@type'])
|
19
|
+
|
18
20
|
@id = record['id']
|
19
21
|
@record_type = record['@type']
|
20
22
|
@accessor = accessor
|
@@ -45,5 +47,14 @@ module MyJohnDeereApi
|
|
45
47
|
def expected_record_type
|
46
48
|
'Base'
|
47
49
|
end
|
50
|
+
|
51
|
+
##
|
52
|
+
# Raise an error if this is not the type of record we expect to receive
|
53
|
+
|
54
|
+
def verify_record_type(type)
|
55
|
+
unless type == expected_record_type
|
56
|
+
raise TypeMismatchError, "Expected record of type '#{expected_record_type}', but received type '#{type}'"
|
57
|
+
end
|
58
|
+
end
|
48
59
|
end
|
49
60
|
end
|
@@ -35,6 +35,16 @@ describe 'MyJohnDeereApi::Model::Base' do
|
|
35
35
|
record['links'].detect{|link| link['rel'] == label}['uri'].gsub('https://sandboxapi.deere.com/platform', '')
|
36
36
|
end
|
37
37
|
|
38
|
+
it 'raises an error if there is a record type mismatch' do
|
39
|
+
record = {
|
40
|
+
'@type'=>'WrongType',
|
41
|
+
'links'=>[]
|
42
|
+
}
|
43
|
+
|
44
|
+
exception = assert_raises(JD::TypeMismatchError) { JD::Model::Base.new(record) }
|
45
|
+
assert_equal "Expected record of type 'Base', but received type 'WrongType'", exception.message
|
46
|
+
end
|
47
|
+
|
38
48
|
it 'sets the base attributes' do
|
39
49
|
assert_equal record['id'], object.id
|
40
50
|
assert_equal record['@type'], object.record_type
|