my_john_deere_api 1.3.6 → 1.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/my_john_deere_api/client.rb +11 -11
- data/lib/my_john_deere_api/model/asset.rb +1 -1
- data/lib/my_john_deere_api/model/base.rb +15 -6
- data/lib/my_john_deere_api/model/contribution_product.rb +1 -1
- data/lib/my_john_deere_api/model/field.rb +1 -1
- data/lib/my_john_deere_api/model/organization.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 +2 -2
- data/lib/my_john_deere_api/request/collection/base.rb +16 -8
- 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/organizations.rb +1 -1
- data/lib/my_john_deere_api/request/create/base.rb +12 -4
- data/lib/my_john_deere_api/request/individual/base.rb +13 -5
- data/lib/my_john_deere_api/request/update/base.rb +11 -3
- data/lib/my_john_deere_api/version.rb +1 -1
- data/test/lib/my_john_deere_api/client_test.rb +0 -3
- data/test/lib/my_john_deere_api/model/asset_location_test.rb +6 -6
- data/test/lib/my_john_deere_api/model/asset_test.rb +8 -9
- data/test/lib/my_john_deere_api/model/base_test.rb +8 -7
- data/test/lib/my_john_deere_api/model/contribution_definition_test.rb +3 -5
- data/test/lib/my_john_deere_api/model/contribution_product_test.rb +8 -8
- data/test/lib/my_john_deere_api/model/field_test.rb +8 -9
- data/test/lib/my_john_deere_api/model/flag_test.rb +6 -6
- data/test/lib/my_john_deere_api/model/organization_test.rb +9 -11
- data/test/lib/my_john_deere_api/request/collection/asset_locations_test.rb +6 -5
- data/test/lib/my_john_deere_api/request/collection/assets_test.rb +6 -5
- data/test/lib/my_john_deere_api/request/collection/base_test.rb +8 -6
- data/test/lib/my_john_deere_api/request/collection/contribution_definitions_test.rb +5 -5
- data/test/lib/my_john_deere_api/request/collection/contribution_products_test.rb +5 -5
- data/test/lib/my_john_deere_api/request/collection/fields_test.rb +6 -5
- data/test/lib/my_john_deere_api/request/collection/flags_test.rb +6 -5
- data/test/lib/my_john_deere_api/request/collection/organizations_test.rb +7 -6
- data/test/lib/my_john_deere_api/request/create/asset_location_test.rb +15 -13
- data/test/lib/my_john_deere_api/request/create/asset_test.rb +16 -14
- data/test/lib/my_john_deere_api/request/create/base_test.rb +6 -4
- data/test/lib/my_john_deere_api/request/individual/asset_test.rb +4 -3
- data/test/lib/my_john_deere_api/request/individual/base_test.rb +4 -3
- data/test/lib/my_john_deere_api/request/individual/contribution_definition_test.rb +4 -3
- data/test/lib/my_john_deere_api/request/individual/contribution_product_test.rb +4 -3
- data/test/lib/my_john_deere_api/request/individual/field_test.rb +4 -3
- data/test/lib/my_john_deere_api/request/individual/organization_test.rb +4 -3
- data/test/lib/my_john_deere_api/request/update/asset_test.rb +6 -5
- data/test/lib/my_john_deere_api/request/update/base_test.rb +6 -4
- data/test/support/helper.rb +7 -2
- metadata +1 -1
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'support/helper'
|
2
2
|
|
3
3
|
describe 'MyJohnDeereApi::Model::Field' do
|
4
|
+
let(:klass) { JD::Model::Field }
|
5
|
+
|
4
6
|
let(:record) do
|
5
7
|
{
|
6
8
|
"@type"=>"Field",
|
@@ -21,9 +23,9 @@ describe 'MyJohnDeereApi::Model::Field' do
|
|
21
23
|
end
|
22
24
|
|
23
25
|
it 'sets the attributes from the given record' do
|
24
|
-
field =
|
26
|
+
field = klass.new(record)
|
25
27
|
|
26
|
-
assert_nil field.
|
28
|
+
assert_nil field.client
|
27
29
|
|
28
30
|
# basic attributes
|
29
31
|
assert_equal record['name'], field.name
|
@@ -39,16 +41,13 @@ describe 'MyJohnDeereApi::Model::Field' do
|
|
39
41
|
end
|
40
42
|
|
41
43
|
it 'accepts an optional accessor' do
|
42
|
-
|
43
|
-
|
44
|
-
field = JD::Model::Field.new(record, mock_accessor)
|
45
|
-
assert_equal mock_accessor, field.accessor
|
44
|
+
field = klass.new(record, client)
|
45
|
+
assert_equal client, field.client
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
49
|
describe '#flags' do
|
50
50
|
it 'returns a collection of flags for this organization' do
|
51
|
-
accessor
|
52
51
|
organization = VCR.use_cassette('get_organizations') { client.organizations.first }
|
53
52
|
field = VCR.use_cassette('get_fields') { organization.fields.first }
|
54
53
|
flags = VCR.use_cassette('get_flags') { field.flags.all }
|
@@ -61,7 +60,7 @@ describe 'MyJohnDeereApi::Model::Field' do
|
|
61
60
|
end
|
62
61
|
|
63
62
|
it 'raises an exception if an accessor is not available' do
|
64
|
-
field =
|
63
|
+
field = klass.new(record)
|
65
64
|
|
66
65
|
exception = assert_raises(JD::AccessTokenError) { field.flags }
|
67
66
|
|
@@ -71,7 +70,7 @@ describe 'MyJohnDeereApi::Model::Field' do
|
|
71
70
|
|
72
71
|
describe 'private #organization_id' do
|
73
72
|
it "infers the organization_id from links" do
|
74
|
-
field =
|
73
|
+
field = klass.new(record)
|
75
74
|
assert_equal organization_id, field.send(:organization_id)
|
76
75
|
end
|
77
76
|
end
|
@@ -2,6 +2,8 @@ require 'support/helper'
|
|
2
2
|
require 'json'
|
3
3
|
|
4
4
|
describe 'MyJohnDeereApi::Model::Flag' do
|
5
|
+
let(:klass) { JD::Model::Flag }
|
6
|
+
|
5
7
|
let(:record) do
|
6
8
|
{
|
7
9
|
"@type"=>"Flag",
|
@@ -24,7 +26,7 @@ describe 'MyJohnDeereApi::Model::Flag' do
|
|
24
26
|
end
|
25
27
|
|
26
28
|
it 'sets the attributes from the given record' do
|
27
|
-
field =
|
29
|
+
field = klass.new(record)
|
28
30
|
|
29
31
|
assert_nil field.accessor
|
30
32
|
|
@@ -42,11 +44,9 @@ describe 'MyJohnDeereApi::Model::Flag' do
|
|
42
44
|
assert_equal link_for('lastModifiedBy'), field.links['last_modified_by']
|
43
45
|
end
|
44
46
|
|
45
|
-
it 'accepts an optional
|
46
|
-
|
47
|
-
|
48
|
-
field = JD::Model::Flag.new(record, accessor)
|
49
|
-
assert_equal accessor, field.accessor
|
47
|
+
it 'accepts an optional client' do
|
48
|
+
field = klass.new(record, client)
|
49
|
+
assert_equal client, field.client
|
50
50
|
end
|
51
51
|
end
|
52
52
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'support/helper'
|
2
2
|
|
3
3
|
describe 'MyJohnDeereApi::Model::Organization' do
|
4
|
+
let(:klass) { JD::Model::Organization }
|
5
|
+
|
4
6
|
let(:record) do
|
5
7
|
{
|
6
8
|
"@type"=>"Organization",
|
@@ -28,13 +30,13 @@ describe 'MyJohnDeereApi::Model::Organization' do
|
|
28
30
|
}
|
29
31
|
end
|
30
32
|
|
31
|
-
describe '#initialize(record,
|
33
|
+
describe '#initialize(record, client = nil)' do
|
32
34
|
def link_for label
|
33
35
|
record['links'].detect{|link| link['rel'] == label}['uri'].gsub('https://sandboxapi.deere.com/platform', '')
|
34
36
|
end
|
35
37
|
|
36
38
|
it 'sets the attributes from the given record' do
|
37
|
-
organization =
|
39
|
+
organization = klass.new(record)
|
38
40
|
|
39
41
|
# basic attributes
|
40
42
|
assert_equal record['name'], organization.name
|
@@ -51,17 +53,14 @@ describe 'MyJohnDeereApi::Model::Organization' do
|
|
51
53
|
end
|
52
54
|
end
|
53
55
|
|
54
|
-
it 'accepts an optional
|
55
|
-
|
56
|
-
|
57
|
-
organization = JD::Model::Organization.new(record, mock_accessor)
|
58
|
-
assert_equal mock_accessor, organization.accessor
|
56
|
+
it 'accepts an optional client' do
|
57
|
+
organization = klass.new(record, client)
|
58
|
+
assert_equal client, organization.client
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
62
|
describe '#fields' do
|
63
63
|
it 'returns a collection of fields for this organization' do
|
64
|
-
accessor
|
65
64
|
organization = VCR.use_cassette('get_organizations') { client.organizations.first }
|
66
65
|
fields = VCR.use_cassette('get_fields') { organization.fields.all }
|
67
66
|
|
@@ -73,7 +72,7 @@ describe 'MyJohnDeereApi::Model::Organization' do
|
|
73
72
|
end
|
74
73
|
|
75
74
|
it 'raises an exception if an accessor is not available' do
|
76
|
-
organization =
|
75
|
+
organization = klass.new(record)
|
77
76
|
|
78
77
|
exception = assert_raises(JD::AccessTokenError) { organization.fields }
|
79
78
|
|
@@ -83,7 +82,6 @@ describe 'MyJohnDeereApi::Model::Organization' do
|
|
83
82
|
|
84
83
|
describe '#assets' do
|
85
84
|
it 'returns a collection of assets for this organization' do
|
86
|
-
accessor
|
87
85
|
organization = VCR.use_cassette('get_organizations') { client.organizations.first }
|
88
86
|
assets = VCR.use_cassette('get_assets') { organization.assets.all; organization.assets }
|
89
87
|
|
@@ -95,7 +93,7 @@ describe 'MyJohnDeereApi::Model::Organization' do
|
|
95
93
|
end
|
96
94
|
|
97
95
|
it 'raises an exception if an accessor is not available' do
|
98
|
-
organization =
|
96
|
+
organization = klass.new(record)
|
99
97
|
|
100
98
|
exception = assert_raises(JD::AccessTokenError) { organization.assets }
|
101
99
|
assert_includes exception.message, 'Access Token must be supplied'
|
@@ -3,18 +3,19 @@ require 'yaml'
|
|
3
3
|
require 'json'
|
4
4
|
|
5
5
|
describe 'MyJohnDeereApi::Request::Collection::AssetLocations' do
|
6
|
-
let(:
|
6
|
+
let(:klass) { JD::Request::Collection::AssetLocations }
|
7
|
+
let(:collection) { klass.new(client, asset: asset_id) }
|
7
8
|
let(:object) { collection }
|
8
9
|
|
9
10
|
inherits_from JD::Request::Collection::Base
|
10
11
|
|
11
|
-
describe '#initialize(
|
12
|
-
it 'accepts
|
13
|
-
|
12
|
+
describe '#initialize(client)' do
|
13
|
+
it 'accepts a client' do
|
14
|
+
assert_equal client, collection.client
|
14
15
|
end
|
15
16
|
|
16
17
|
it 'accepts associations' do
|
17
|
-
collection =
|
18
|
+
collection = klass.new(client, asset: asset_id)
|
18
19
|
|
19
20
|
assert_kind_of Hash, collection.associations
|
20
21
|
assert_equal asset_id, collection.associations[:asset]
|
@@ -3,18 +3,19 @@ require 'yaml'
|
|
3
3
|
require 'json'
|
4
4
|
|
5
5
|
describe 'MyJohnDeereApi::Request::Collection::Assets' do
|
6
|
-
let(:
|
6
|
+
let(:klass) { JD::Request::Collection::Assets }
|
7
|
+
let(:collection) { klass.new(client, organization: organization_id) }
|
7
8
|
let(:object) { collection }
|
8
9
|
|
9
10
|
inherits_from JD::Request::Collection::Base
|
10
11
|
|
11
|
-
describe '#initialize(
|
12
|
-
it 'accepts
|
13
|
-
|
12
|
+
describe '#initialize(client)' do
|
13
|
+
it 'accepts a client' do
|
14
|
+
assert_equal client, collection.client
|
14
15
|
end
|
15
16
|
|
16
17
|
it 'accepts associations' do
|
17
|
-
collection =
|
18
|
+
collection = klass.new(client, organization: organization_id)
|
18
19
|
|
19
20
|
assert_kind_of Hash, collection.associations
|
20
21
|
assert_equal organization_id, collection.associations[:organization]
|
@@ -1,14 +1,16 @@
|
|
1
1
|
require 'support/helper'
|
2
2
|
|
3
3
|
describe 'MyJohnDeereApi::Request::Collection::Base' do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
let(:klass) { JD::Request::Collection::Base }
|
5
|
+
|
6
|
+
describe '#initialize(client)' do
|
7
|
+
it 'accepts a client' do
|
8
|
+
collection = klass.new(client)
|
9
|
+
assert_equal client, collection.client
|
8
10
|
end
|
9
11
|
|
10
12
|
it 'accepts associations' do
|
11
|
-
collection =
|
13
|
+
collection = klass.new(client, organization: organization_id)
|
12
14
|
|
13
15
|
assert_kind_of Hash, collection.associations
|
14
16
|
assert_equal organization_id, collection.associations[:organization]
|
@@ -16,7 +18,7 @@ describe 'MyJohnDeereApi::Request::Collection::Base' do
|
|
16
18
|
end
|
17
19
|
|
18
20
|
it 'uses the Enumerable module' do
|
19
|
-
collection =
|
21
|
+
collection = klass.new(client)
|
20
22
|
|
21
23
|
[:each, :first, :map, :detect, :select].each do |method_name|
|
22
24
|
assert collection.respond_to?(method_name)
|
@@ -5,18 +5,18 @@ require 'json'
|
|
5
5
|
describe 'MyJohnDeereApi::Request::Collection::ContributionDefinitions' do
|
6
6
|
let(:klass) { MyJohnDeereApi::Request::Collection::ContributionDefinitions }
|
7
7
|
|
8
|
-
let(:collection) { klass.new(
|
8
|
+
let(:collection) { klass.new(client, contribution_product: contribution_product_id) }
|
9
9
|
let(:object) { collection }
|
10
10
|
|
11
11
|
inherits_from JD::Request::Collection::Base
|
12
12
|
|
13
|
-
describe '#initialize(
|
14
|
-
it 'accepts
|
15
|
-
|
13
|
+
describe '#initialize(client)' do
|
14
|
+
it 'accepts a client' do
|
15
|
+
assert_equal client, collection.client
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'accepts associations' do
|
19
|
-
collection = klass.new(
|
19
|
+
collection = klass.new(client, something: 123)
|
20
20
|
|
21
21
|
assert_kind_of Hash, collection.associations
|
22
22
|
assert_equal 123, collection.associations[:something]
|
@@ -5,18 +5,18 @@ require 'json'
|
|
5
5
|
describe 'MyJohnDeereApi::Request::Collection::ContributionProducts' do
|
6
6
|
let(:klass) { MyJohnDeereApi::Request::Collection::ContributionProducts }
|
7
7
|
|
8
|
-
let(:collection) { klass.new(
|
8
|
+
let(:collection) { klass.new(client) }
|
9
9
|
let(:object) { collection }
|
10
10
|
|
11
11
|
inherits_from JD::Request::Collection::Base
|
12
12
|
|
13
|
-
describe '#initialize(
|
14
|
-
it 'accepts
|
15
|
-
|
13
|
+
describe '#initialize(client)' do
|
14
|
+
it 'accepts a client' do
|
15
|
+
assert_equal client, collection.client
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'accepts associations' do
|
19
|
-
collection = klass.new(
|
19
|
+
collection = klass.new(client, something: 123)
|
20
20
|
|
21
21
|
assert_kind_of Hash, collection.associations
|
22
22
|
assert_equal 123, collection.associations[:something]
|
@@ -3,18 +3,19 @@ require 'yaml'
|
|
3
3
|
require 'json'
|
4
4
|
|
5
5
|
describe 'MyJohnDeereApi::Request::Collection::Fields' do
|
6
|
-
let(:
|
6
|
+
let(:klass) { JD::Request::Collection::Fields }
|
7
|
+
let(:collection) { klass.new(client, organization: organization_id) }
|
7
8
|
let(:object) { collection }
|
8
9
|
|
9
10
|
inherits_from JD::Request::Collection::Base
|
10
11
|
|
11
|
-
describe '#initialize(
|
12
|
-
it 'accepts
|
13
|
-
|
12
|
+
describe '#initialize(client)' do
|
13
|
+
it 'accepts a client' do
|
14
|
+
assert_equal client, collection.client
|
14
15
|
end
|
15
16
|
|
16
17
|
it 'accepts associations' do
|
17
|
-
collection =
|
18
|
+
collection = klass.new(client, organization: organization_id)
|
18
19
|
|
19
20
|
assert_kind_of Hash, collection.associations
|
20
21
|
assert_equal organization_id, collection.associations[:organization]
|
@@ -3,18 +3,19 @@ require 'yaml'
|
|
3
3
|
require 'json'
|
4
4
|
|
5
5
|
describe 'MyJohnDeereApi::Request::Collection::Flags' do
|
6
|
-
let(:
|
6
|
+
let(:klass) { JD::Request::Collection::Flags }
|
7
|
+
let(:collection) { klass.new(client, organization: organization_id, field: field_id) }
|
7
8
|
let(:object) { collection }
|
8
9
|
|
9
10
|
inherits_from JD::Request::Collection::Base
|
10
11
|
|
11
|
-
describe '#initialize(
|
12
|
-
it 'accepts
|
13
|
-
|
12
|
+
describe '#initialize(client)' do
|
13
|
+
it 'accepts a client' do
|
14
|
+
assert_equal client, collection.client
|
14
15
|
end
|
15
16
|
|
16
17
|
it 'accepts associations' do
|
17
|
-
collection =
|
18
|
+
collection = klass.new(client, organization: organization_id, field: field_id)
|
18
19
|
|
19
20
|
assert_kind_of Hash, collection.associations
|
20
21
|
assert_equal organization_id, collection.associations[:organization]
|
@@ -3,14 +3,15 @@ require 'yaml'
|
|
3
3
|
require 'json'
|
4
4
|
|
5
5
|
describe 'MyJohnDeereApi::Request::Collection::Organizations' do
|
6
|
-
let(:
|
6
|
+
let(:klass) { JD::Request::Collection::Organizations }
|
7
|
+
let(:collection) { klass.new(client) }
|
7
8
|
let(:object) { collection }
|
8
9
|
|
9
10
|
inherits_from JD::Request::Collection::Base
|
10
11
|
|
11
|
-
describe '#initialize(
|
12
|
-
it 'accepts
|
13
|
-
|
12
|
+
describe '#initialize(client)' do
|
13
|
+
it 'accepts a client' do
|
14
|
+
assert_equal client, collection.client
|
14
15
|
end
|
15
16
|
end
|
16
17
|
|
@@ -75,11 +76,11 @@ describe 'MyJohnDeereApi::Request::Collection::Organizations' do
|
|
75
76
|
end
|
76
77
|
end
|
77
78
|
|
78
|
-
it 'passes the
|
79
|
+
it 'passes the client to all organizations' do
|
79
80
|
organizations = VCR.use_cassette('get_organizations') { collection.all }
|
80
81
|
|
81
82
|
organizations.each do |organization|
|
82
|
-
assert_equal
|
83
|
+
assert_equal client, organization.client
|
83
84
|
end
|
84
85
|
end
|
85
86
|
end
|
@@ -15,12 +15,14 @@ describe 'MyJohnDeereApi::Request::Create::AssetLocation' do
|
|
15
15
|
|
16
16
|
let(:attributes) { valid_attributes }
|
17
17
|
|
18
|
-
let(:
|
18
|
+
let(:klass) { JD::Request::Create::AssetLocation }
|
19
|
+
let(:object) { klass.new(client, attributes) }
|
19
20
|
|
20
21
|
inherits_from MyJohnDeereApi::Request::Create::Base
|
21
22
|
|
22
|
-
describe '#initialize(
|
23
|
-
it 'accepts
|
23
|
+
describe '#initialize(client, attributes)' do
|
24
|
+
it 'accepts a client and attributes' do
|
25
|
+
assert_equal client, object.client
|
24
26
|
assert_equal accessor, object.accessor
|
25
27
|
assert_equal attributes, object.attributes
|
26
28
|
end
|
@@ -33,13 +35,13 @@ describe 'MyJohnDeereApi::Request::Create::AssetLocation' do
|
|
33
35
|
measurement_data: valid_attributes[:measurement_data]
|
34
36
|
}
|
35
37
|
|
36
|
-
object =
|
38
|
+
object = klass.new(client, attributes)
|
37
39
|
assert_equal valid_attributes[:geometry].to_json, object.attributes[:geometry]
|
38
40
|
end
|
39
41
|
|
40
42
|
it 'defaults timestamp to current time' do
|
41
43
|
attributes = valid_attributes.slice(:asset_id, :geometry, :measurement_data)
|
42
|
-
object =
|
44
|
+
object = klass.new(client, attributes)
|
43
45
|
|
44
46
|
expected_stamp = Time.now.utc.to_i
|
45
47
|
actual_stamp = DateTime.parse(object.attributes[:timestamp]).to_time.to_i
|
@@ -55,21 +57,21 @@ describe 'MyJohnDeereApi::Request::Create::AssetLocation' do
|
|
55
57
|
end
|
56
58
|
|
57
59
|
it 'requires asset_id' do
|
58
|
-
object =
|
60
|
+
object = klass.new(client, attributes_without(:asset_id))
|
59
61
|
|
60
62
|
refute object.valid?
|
61
63
|
assert_equal 'is required', object.errors[:asset_id]
|
62
64
|
end
|
63
65
|
|
64
66
|
it 'requires geometry' do
|
65
|
-
object =
|
67
|
+
object = klass.new(client, attributes_without(:geometry))
|
66
68
|
|
67
69
|
refute object.valid?
|
68
70
|
assert_equal 'is required', object.errors[:geometry]
|
69
71
|
end
|
70
72
|
|
71
73
|
it 'requires measurement_data' do
|
72
|
-
object =
|
74
|
+
object = klass.new(client, attributes_without(:measurement_data))
|
73
75
|
|
74
76
|
refute object.valid?
|
75
77
|
assert_equal 'is required', object.errors[:measurement_data]
|
@@ -77,7 +79,7 @@ describe 'MyJohnDeereApi::Request::Create::AssetLocation' do
|
|
77
79
|
|
78
80
|
describe 'validating measurement_data' do
|
79
81
|
it 'must be an array' do
|
80
|
-
object =
|
82
|
+
object = klass.new(client, attributes.merge(measurement_data: 'something'))
|
81
83
|
|
82
84
|
refute object.valid?
|
83
85
|
assert_equal 'must be an array', object.errors[:measurement_data]
|
@@ -85,7 +87,7 @@ describe 'MyJohnDeereApi::Request::Create::AssetLocation' do
|
|
85
87
|
|
86
88
|
it 'must include a name' do
|
87
89
|
without_attr = [attributes[:measurement_data].first.reject{|k,v| k == :name}]
|
88
|
-
object =
|
90
|
+
object = klass.new(client, attributes.merge(measurement_data: without_attr))
|
89
91
|
|
90
92
|
refute object.valid?
|
91
93
|
assert_equal 'must include name', object.errors[:measurement_data]
|
@@ -93,7 +95,7 @@ describe 'MyJohnDeereApi::Request::Create::AssetLocation' do
|
|
93
95
|
|
94
96
|
it 'must include a value' do
|
95
97
|
without_attr = [attributes[:measurement_data].first.reject{|k,v| k == :value}]
|
96
|
-
object =
|
98
|
+
object = klass.new(client, attributes.merge(measurement_data: without_attr))
|
97
99
|
|
98
100
|
refute object.valid?
|
99
101
|
assert_equal 'must include value', object.errors[:measurement_data]
|
@@ -101,7 +103,7 @@ describe 'MyJohnDeereApi::Request::Create::AssetLocation' do
|
|
101
103
|
|
102
104
|
it 'must include a unit' do
|
103
105
|
without_attr = [attributes[:measurement_data].first.reject{|k,v| k == :unit}]
|
104
|
-
object =
|
106
|
+
object = klass.new(client, attributes.merge(measurement_data: without_attr))
|
105
107
|
|
106
108
|
refute object.valid?
|
107
109
|
assert_equal 'must include unit', object.errors[:measurement_data]
|
@@ -111,7 +113,7 @@ describe 'MyJohnDeereApi::Request::Create::AssetLocation' do
|
|
111
113
|
|
112
114
|
describe '#validate!' do
|
113
115
|
it 'raises an error when invalid' do
|
114
|
-
object =
|
116
|
+
object = klass.new(client, attributes_without(:asset_id))
|
115
117
|
|
116
118
|
exception = assert_raises(JD::InvalidRecordError) { object.validate! }
|
117
119
|
assert_includes exception.message, 'Record is invalid'
|
@@ -13,14 +13,16 @@ describe 'MyJohnDeereApi::Request::Create::Asset' do
|
|
13
13
|
)
|
14
14
|
end
|
15
15
|
|
16
|
-
let(:
|
16
|
+
let(:klass) { JD::Request::Create::Asset }
|
17
|
+
let(:object) { klass.new(client, attributes) }
|
17
18
|
|
18
19
|
let(:attributes) { valid_attributes }
|
19
20
|
|
20
21
|
inherits_from MyJohnDeereApi::Request::Create::Base
|
21
22
|
|
22
|
-
describe '#initialize(
|
23
|
-
it 'accepts
|
23
|
+
describe '#initialize(client, attributes)' do
|
24
|
+
it 'accepts a client and attributes' do
|
25
|
+
assert_equal client, object.client
|
24
26
|
assert_equal accessor, object.accessor
|
25
27
|
assert_equal attributes, object.attributes
|
26
28
|
end
|
@@ -33,42 +35,42 @@ describe 'MyJohnDeereApi::Request::Create::Asset' do
|
|
33
35
|
end
|
34
36
|
|
35
37
|
it 'requires organization_id' do
|
36
|
-
object =
|
38
|
+
object = klass.new(client, attributes_without(:organization_id))
|
37
39
|
|
38
40
|
refute object.valid?
|
39
41
|
assert_equal 'is required', object.errors[:organization_id]
|
40
42
|
end
|
41
43
|
|
42
44
|
it 'requires contribution_definition_id' do
|
43
|
-
object =
|
45
|
+
object = klass.new(client, attributes_without(:contribution_definition_id))
|
44
46
|
|
45
47
|
refute object.valid?
|
46
48
|
assert_equal 'is required', object.errors[:contribution_definition_id]
|
47
49
|
end
|
48
50
|
|
49
51
|
it 'requires title' do
|
50
|
-
object =
|
52
|
+
object = klass.new(client, attributes_without(:title))
|
51
53
|
|
52
54
|
refute object.valid?
|
53
55
|
assert_equal 'is required', object.errors[:title]
|
54
56
|
end
|
55
57
|
|
56
58
|
it 'requires a valid category' do
|
57
|
-
object =
|
59
|
+
object = klass.new(client, attributes.merge(asset_category: 'TURTLES'))
|
58
60
|
|
59
61
|
refute object.valid?
|
60
62
|
assert_equal 'requires valid combination of category/type/subtype', object.errors[:asset_category]
|
61
63
|
end
|
62
64
|
|
63
65
|
it 'requires a valid type' do
|
64
|
-
object =
|
66
|
+
object = klass.new(client, attributes.merge(asset_type: 'TURTLES'))
|
65
67
|
|
66
68
|
refute object.valid?
|
67
69
|
assert_equal 'requires valid combination of category/type/subtype', object.errors[:asset_category]
|
68
70
|
end
|
69
71
|
|
70
72
|
it 'requires a valid subtype' do
|
71
|
-
object =
|
73
|
+
object = klass.new(client, attributes.merge(asset_sub_type: 'TURTLES'))
|
72
74
|
|
73
75
|
refute object.valid?
|
74
76
|
assert_equal 'requires valid combination of category/type/subtype', object.errors[:asset_category]
|
@@ -77,7 +79,7 @@ describe 'MyJohnDeereApi::Request::Create::Asset' do
|
|
77
79
|
|
78
80
|
describe '#validate!' do
|
79
81
|
it 'raises an error when invalid' do
|
80
|
-
object =
|
82
|
+
object = klass.new(client, attributes_without(:organization_id))
|
81
83
|
|
82
84
|
exception = assert_raises(JD::InvalidRecordError) { object.validate! }
|
83
85
|
assert_includes exception.message, 'Record is invalid'
|
@@ -87,7 +89,7 @@ describe 'MyJohnDeereApi::Request::Create::Asset' do
|
|
87
89
|
|
88
90
|
describe '#valid_categories?(category, type, subtype)' do
|
89
91
|
it 'only allows pre-defined combinations' do
|
90
|
-
object =
|
92
|
+
object = klass.new(client, {})
|
91
93
|
|
92
94
|
valid_combos = [
|
93
95
|
['DEVICE', 'SENSOR', 'ENVIRONMENTAL'],
|
@@ -126,14 +128,14 @@ describe 'MyJohnDeereApi::Request::Create::Asset' do
|
|
126
128
|
|
127
129
|
describe '#resource' do
|
128
130
|
it 'is built from the organization id' do
|
129
|
-
object =
|
131
|
+
object = klass.new(client, attributes)
|
130
132
|
assert_equal "/organizations/#{organization_id}/assets", object.send(:resource)
|
131
133
|
end
|
132
134
|
end
|
133
135
|
|
134
136
|
describe '#request_body' do
|
135
137
|
it 'properly forms the request body' do
|
136
|
-
object =
|
138
|
+
object = klass.new(client, attributes)
|
137
139
|
body = object.send(:request_body)
|
138
140
|
|
139
141
|
assert_equal attributes[:title], body[:title]
|
@@ -162,7 +164,7 @@ describe 'MyJohnDeereApi::Request::Create::Asset' do
|
|
162
164
|
|
163
165
|
describe '#object' do
|
164
166
|
it 'returns the asset model instance' do
|
165
|
-
object =
|
167
|
+
object = klass.new(client, attributes)
|
166
168
|
result = VCR.use_cassette('post_assets') { object.object }
|
167
169
|
|
168
170
|
assert_kind_of JD::Model::Asset, result
|
@@ -1,12 +1,14 @@
|
|
1
1
|
require 'support/helper'
|
2
2
|
|
3
3
|
describe 'MyJohnDeereApi::Request::Create::Base' do
|
4
|
+
let(:klass) { JD::Request::Create::Base }
|
4
5
|
let(:attributes) { {} }
|
5
6
|
|
6
|
-
describe '#initialize(
|
7
|
-
it 'accepts
|
8
|
-
object =
|
7
|
+
describe '#initialize(client, attributes)' do
|
8
|
+
it 'accepts a client and attributes' do
|
9
|
+
object = klass.new(client, attributes)
|
9
10
|
|
11
|
+
assert_equal client, object.client
|
10
12
|
assert_equal accessor, object.accessor
|
11
13
|
assert_equal attributes, object.attributes
|
12
14
|
end
|
@@ -14,7 +16,7 @@ describe 'MyJohnDeereApi::Request::Create::Base' do
|
|
14
16
|
|
15
17
|
describe '#headers' do
|
16
18
|
it 'sets the accept and content-type headers' do
|
17
|
-
object =
|
19
|
+
object = klass.new(client, attributes)
|
18
20
|
headers = object.send(:headers)
|
19
21
|
|
20
22
|
expected = 'application/vnd.deere.axiom.v3+json'
|
@@ -3,12 +3,13 @@ require 'yaml'
|
|
3
3
|
require 'json'
|
4
4
|
|
5
5
|
describe 'MyJohnDeereApi::Request::Individual::Asset' do
|
6
|
-
let(:object) { JD::Request::Individual::Asset.new(
|
6
|
+
let(:object) { JD::Request::Individual::Asset.new(client, asset_id) }
|
7
7
|
|
8
8
|
inherits_from JD::Request::Individual::Base
|
9
9
|
|
10
|
-
describe '#initialize(
|
11
|
-
it 'accepts
|
10
|
+
describe '#initialize(client, asset_id)' do
|
11
|
+
it 'accepts a client' do
|
12
|
+
assert_equal client, object.client
|
12
13
|
assert_equal accessor, object.accessor
|
13
14
|
end
|
14
15
|
|
@@ -3,10 +3,11 @@ require 'yaml'
|
|
3
3
|
require 'json'
|
4
4
|
|
5
5
|
describe 'MyJohnDeereApi::Request::Individual::Base' do
|
6
|
-
let(:object) { JD::Request::Individual::Base.new(
|
6
|
+
let(:object) { JD::Request::Individual::Base.new(client, asset_id) }
|
7
7
|
|
8
|
-
describe '#initialize(
|
9
|
-
it 'accepts
|
8
|
+
describe '#initialize(client, asset_id)' do
|
9
|
+
it 'accepts a client' do
|
10
|
+
assert_equal client, object.client
|
10
11
|
assert_equal accessor, object.accessor
|
11
12
|
end
|
12
13
|
|