my_john_deere_api 1.3.3 → 1.3.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4919eaf224090046a44f2ec4712dfddaebcbb7b5279dc9499cb09ab5b13f1445
4
- data.tar.gz: 5b9d66230b2a3fc29f7111ddad1fc82ea3796935d1d87465238e4f8a70c66f18
3
+ metadata.gz: 2295d8403dd887dfd1dad300885aebef06aa41b07f209a72d2de68b784535ea0
4
+ data.tar.gz: ceb47dd947221150f3d6826e19e343888830f85c88924b189948874aa7825888
5
5
  SHA512:
6
- metadata.gz: 6d908341e42d6a225810c7463157dc453490c7dc5a5c93fea52c5445a91e3ec73d2860c3565918a0a70d9858fe61f7170dd5acdc1b9bb6b5cc0eb57f7d4597cc
7
- data.tar.gz: 6f23310c0403f482d092026780c2280778f7e55ccf309dec23e993522a4d9c80aaf62a94cf045272e16b8563571cd8b00b2e092b775c304a5eed52ae4d27b4c3
6
+ metadata.gz: 1183f5923dcb7932c71f9f10e6968ea332e35e332d980030637426261d0240dd4ab4c464d58cb2a511ce7f2060bdb320926dfca682808afe72cc704afafb061c
7
+ data.tar.gz: c16eb6aa03f079b1968d7eab2bde1f754e147305e66378ce7719648f930f76891f2ac51bed88391e6dd0676e4e7b4a403255851f9efb3b297239d5d46eeec1cf
@@ -2,6 +2,8 @@ require 'date'
2
2
 
3
3
  module MyJohnDeereApi
4
4
  class Request::Create::AssetLocation < Request::Create::Base
5
+ include Validators::AssetLocation
6
+
5
7
  private
6
8
 
7
9
  ##
@@ -73,13 +75,6 @@ module MyJohnDeereApi
73
75
  @resource ||= "/assets/#{attributes[:asset_id]}/locations"
74
76
  end
75
77
 
76
- ##
77
- # Required attributes for this class
78
-
79
- def required_attributes
80
- [:asset_id, :timestamp, :geometry, :measurement_data]
81
- end
82
-
83
78
  ##
84
79
  # Retrieve newly created record
85
80
 
@@ -111,28 +106,5 @@ module MyJohnDeereApi
111
106
  def model
112
107
  Model::AssetLocation
113
108
  end
114
-
115
- ##
116
- # Custom validations for this class
117
-
118
- def validate_attributes
119
- validate_measurement_data
120
- end
121
-
122
- def validate_measurement_data
123
- unless attributes[:measurement_data].is_a?(Array)
124
- errors[:measurement_data] ||= 'must be an array'
125
- return
126
- end
127
-
128
- attributes[:measurement_data].each do |measurement|
129
- [:name, :value, :unit].each do |attr|
130
- unless measurement.has_key?(attr)
131
- errors[:measurement_data] ||= "must include #{attr}"
132
- return
133
- end
134
- end
135
- end
136
- end
137
109
  end
138
110
  end
@@ -0,0 +1,34 @@
1
+ module MyJohnDeereApi::Validators
2
+ module AssetLocation
3
+ include Base
4
+
5
+ private
6
+
7
+ def required_attributes
8
+ [:asset_id, :timestamp, :geometry, :measurement_data]
9
+ end
10
+
11
+ ##
12
+ # Custom validations for this class
13
+
14
+ def validate_attributes
15
+ validate_measurement_data
16
+ end
17
+
18
+ def validate_measurement_data
19
+ unless attributes[:measurement_data].is_a?(Array)
20
+ errors[:measurement_data] ||= 'must be an array'
21
+ return
22
+ end
23
+
24
+ attributes[:measurement_data].each do |measurement|
25
+ [:name, :value, :unit].each do |attr|
26
+ unless measurement.has_key?(attr)
27
+ errors[:measurement_data] ||= "must include #{attr}"
28
+ return
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -1,4 +1,5 @@
1
1
  module MyJohnDeereApi::Validators
2
2
  autoload :Base, 'my_john_deere_api/validators/base'
3
3
  autoload :Asset, 'my_john_deere_api/validators/asset'
4
+ autoload :AssetLocation, 'my_john_deere_api/validators/asset_location'
4
5
  end
@@ -1,3 +1,3 @@
1
1
  module MyJohnDeereApi
2
- VERSION='1.3.3'
2
+ VERSION='1.3.4'
3
3
  end
@@ -0,0 +1,61 @@
1
+ require 'support/helper'
2
+
3
+ class AssetLocationValidatorTest
4
+ include JD::Validators::AssetLocation
5
+
6
+ attr_reader :attributes
7
+
8
+ def initialize(attributes)
9
+ @attributes = attributes
10
+ end
11
+ end
12
+
13
+ describe 'MyJohnDeereApi::Validators::AssetLocation' do
14
+ let(:klass) { AssetLocationValidatorTest }
15
+ let(:object) { klass.new(attributes) }
16
+ let(:attributes) { valid_attributes }
17
+
18
+ let(:valid_attributes) do
19
+ {
20
+ asset_id: asset_id,
21
+ timestamp: CONFIG.timestamp,
22
+ coordinates: CONFIG.coordinates,
23
+ measurement_data: CONFIG.measurement_data
24
+ }
25
+ end
26
+
27
+ it 'exists' do
28
+ assert JD::Validators::AssetLocation
29
+ end
30
+
31
+ it 'inherits from MyJohnDeereApi::Validators::Base' do
32
+ [:validate!, :valid?].each{ |method_name| assert object.respond_to?(method_name) }
33
+ end
34
+
35
+ it 'requires several attributes' do
36
+ [:asset_id, :timestamp, :geometry, :measurement_data].each do |attr|
37
+ object = klass.new(valid_attributes.merge(attr => nil))
38
+
39
+ refute object.valid?
40
+ exception = assert_raises(JD::InvalidRecordError) { object.validate! }
41
+
42
+ assert_includes exception.message, "#{attr} is required"
43
+ assert_includes object.errors[attr], 'is required'
44
+ end
45
+ end
46
+
47
+ it 'requires measurement_data to have the right keys' do
48
+ [:name, :value, :unit].each do |key|
49
+ attributes = Marshal.load(Marshal.dump(valid_attributes))
50
+ attributes[:measurement_data].first.delete(key)
51
+
52
+ object = klass.new(attributes)
53
+
54
+ refute object.valid?
55
+ exception = assert_raises(JD::InvalidRecordError) { object.validate! }
56
+
57
+ assert_includes exception.message, "measurement_data must include #{key}"
58
+ assert_includes object.errors[:measurement_data], "must include #{key}"
59
+ end
60
+ end
61
+ end
@@ -1,22 +1,17 @@
1
1
  require 'support/helper'
2
2
 
3
- module AssetValidatorTest
4
- class Base
5
- include JD::Validators::Asset
3
+ class AssetValidatorTest
4
+ include JD::Validators::Asset
6
5
 
7
- attr_reader :attributes
6
+ attr_reader :attributes
8
7
 
9
- def initialize(attributes)
10
- @attributes = attributes
11
- end
12
- end
13
-
14
- class Vanilla < Base
8
+ def initialize(attributes)
9
+ @attributes = attributes
15
10
  end
16
11
  end
17
12
 
18
13
  describe 'MyJohnDeereApi::Validators::Asset' do
19
- let(:klass) { AssetValidatorTest::Base }
14
+ let(:klass) { AssetValidatorTest }
20
15
  let(:object) { klass.new(attributes) }
21
16
  let(:attributes) { valid_attributes }
22
17
 
@@ -9,5 +9,9 @@ describe 'MyJohnDeereApi::Validators' do
9
9
  it 'loads Validators::Asset' do
10
10
  assert JD::Validators::Asset
11
11
  end
12
+
13
+ it 'loads Validators::AssetLocation' do
14
+ assert JD::Validators::AssetLocation
15
+ end
12
16
  end
13
17
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: my_john_deere_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.3
4
+ version: 1.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jaime Bellmyer
@@ -151,6 +151,7 @@ files:
151
151
  - lib/my_john_deere_api/request/update/base.rb
152
152
  - lib/my_john_deere_api/validators.rb
153
153
  - lib/my_john_deere_api/validators/asset.rb
154
+ - lib/my_john_deere_api/validators/asset_location.rb
154
155
  - lib/my_john_deere_api/validators/base.rb
155
156
  - lib/my_john_deere_api/version.rb
156
157
  - test/lib/my_john_deere_api/authorize_test.rb
@@ -199,6 +200,7 @@ files:
199
200
  - test/lib/my_john_deere_api/request/update/base_test.rb
200
201
  - test/lib/my_john_deere_api/request/update_test.rb
201
202
  - test/lib/my_john_deere_api/request_test.rb
203
+ - test/lib/my_john_deere_api/validators/asset_location_test.rb
202
204
  - test/lib/my_john_deere_api/validators/asset_test.rb
203
205
  - test/lib/my_john_deere_api/validators/base_test.rb
204
206
  - test/lib/my_john_deere_api/validators_test.rb