my_john_deere_api 2.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +813 -0
- data/Rakefile +9 -0
- data/lib/my_john_deere_api.rb +17 -0
- data/lib/my_john_deere_api/authorize.rb +69 -0
- data/lib/my_john_deere_api/client.rb +151 -0
- data/lib/my_john_deere_api/consumer.rb +90 -0
- data/lib/my_john_deere_api/errors.rb +7 -0
- data/lib/my_john_deere_api/errors/invalid_record_error.rb +29 -0
- data/lib/my_john_deere_api/errors/missing_contribution_definition_id_error.rb +12 -0
- data/lib/my_john_deere_api/errors/not_yet_implemented_error.rb +12 -0
- data/lib/my_john_deere_api/errors/type_mismatch_error.rb +12 -0
- data/lib/my_john_deere_api/errors/unsupported_environment_error.rb +18 -0
- data/lib/my_john_deere_api/helpers.rb +6 -0
- data/lib/my_john_deere_api/helpers/case_conversion.rb +37 -0
- data/lib/my_john_deere_api/helpers/environment_helper.rb +25 -0
- data/lib/my_john_deere_api/helpers/uri_helpers.rb +19 -0
- data/lib/my_john_deere_api/helpers/validate_contribution_definition.rb +18 -0
- data/lib/my_john_deere_api/model.rb +10 -0
- data/lib/my_john_deere_api/model/asset.rb +69 -0
- data/lib/my_john_deere_api/model/asset_location.rb +19 -0
- data/lib/my_john_deere_api/model/base.rb +97 -0
- data/lib/my_john_deere_api/model/contribution_definition.rb +15 -0
- data/lib/my_john_deere_api/model/contribution_product.rb +33 -0
- data/lib/my_john_deere_api/model/field.rb +40 -0
- data/lib/my_john_deere_api/model/flag.rb +36 -0
- data/lib/my_john_deere_api/model/organization.rb +43 -0
- data/lib/my_john_deere_api/net_http_retry.rb +2 -0
- data/lib/my_john_deere_api/net_http_retry/decorator.rb +53 -0
- data/lib/my_john_deere_api/net_http_retry/max_retries_exceeded_error.rb +20 -0
- data/lib/my_john_deere_api/request.rb +6 -0
- data/lib/my_john_deere_api/request/collection.rb +10 -0
- data/lib/my_john_deere_api/request/collection/asset_locations.rb +27 -0
- data/lib/my_john_deere_api/request/collection/assets.rb +34 -0
- data/lib/my_john_deere_api/request/collection/base.rb +91 -0
- data/lib/my_john_deere_api/request/collection/contribution_definitions.rb +26 -0
- data/lib/my_john_deere_api/request/collection/contribution_products.rb +26 -0
- data/lib/my_john_deere_api/request/collection/fields.rb +26 -0
- data/lib/my_john_deere_api/request/collection/flags.rb +33 -0
- data/lib/my_john_deere_api/request/collection/organizations.rb +26 -0
- data/lib/my_john_deere_api/request/create.rb +5 -0
- data/lib/my_john_deere_api/request/create/asset.rb +57 -0
- data/lib/my_john_deere_api/request/create/asset_location.rb +110 -0
- data/lib/my_john_deere_api/request/create/base.rb +67 -0
- data/lib/my_john_deere_api/request/individual.rb +8 -0
- data/lib/my_john_deere_api/request/individual/asset.rb +19 -0
- data/lib/my_john_deere_api/request/individual/base.rb +52 -0
- data/lib/my_john_deere_api/request/individual/contribution_definition.rb +19 -0
- data/lib/my_john_deere_api/request/individual/contribution_product.rb +19 -0
- data/lib/my_john_deere_api/request/individual/field.rb +19 -0
- data/lib/my_john_deere_api/request/individual/organization.rb +19 -0
- data/lib/my_john_deere_api/request/update.rb +4 -0
- data/lib/my_john_deere_api/request/update/asset.rb +40 -0
- data/lib/my_john_deere_api/request/update/base.rb +67 -0
- data/lib/my_john_deere_api/validators.rb +5 -0
- data/lib/my_john_deere_api/validators/asset.rb +35 -0
- data/lib/my_john_deere_api/validators/asset_location.rb +34 -0
- data/lib/my_john_deere_api/validators/base.rb +67 -0
- data/lib/my_john_deere_api/version.rb +3 -0
- data/test/lib/my_john_deere_api/authorize_test.rb +81 -0
- data/test/lib/my_john_deere_api/client_test.rb +225 -0
- data/test/lib/my_john_deere_api/consumer_test.rb +58 -0
- data/test/lib/my_john_deere_api/errors/invalid_record_error_test.rb +26 -0
- data/test/lib/my_john_deere_api/errors/max_retries_exceeded_error_test.rb +13 -0
- data/test/lib/my_john_deere_api/errors/missing_contribution_definition_id_error_test.rb +14 -0
- data/test/lib/my_john_deere_api/errors/not_yet_implemented_error_test.rb +13 -0
- data/test/lib/my_john_deere_api/errors/type_mismatch_error_test.rb +13 -0
- data/test/lib/my_john_deere_api/errors/unsupported_environment_error_test.rb +18 -0
- data/test/lib/my_john_deere_api/errors_test.rb +25 -0
- data/test/lib/my_john_deere_api/helpers/case_conversion_test.rb +100 -0
- data/test/lib/my_john_deere_api/helpers/environment_helper_test.rb +67 -0
- data/test/lib/my_john_deere_api/helpers/uri_helpers_test.rb +58 -0
- data/test/lib/my_john_deere_api/helpers/validate_contribution_definition_test.rb +74 -0
- data/test/lib/my_john_deere_api/helpers_test.rb +21 -0
- data/test/lib/my_john_deere_api/model/asset_location_test.rb +38 -0
- data/test/lib/my_john_deere_api/model/asset_test.rb +133 -0
- data/test/lib/my_john_deere_api/model/base_test.rb +76 -0
- data/test/lib/my_john_deere_api/model/contribution_definition_test.rb +52 -0
- data/test/lib/my_john_deere_api/model/contribution_product_test.rb +82 -0
- data/test/lib/my_john_deere_api/model/field_test.rb +65 -0
- data/test/lib/my_john_deere_api/model/flag_test.rb +48 -0
- data/test/lib/my_john_deere_api/model/organization_test.rb +84 -0
- data/test/lib/my_john_deere_api/model_test.rb +37 -0
- data/test/lib/my_john_deere_api/net_http_retry/decorator_test.rb +163 -0
- data/test/lib/my_john_deere_api/request/collection/asset_locations_test.rb +102 -0
- data/test/lib/my_john_deere_api/request/collection/assets_test.rb +99 -0
- data/test/lib/my_john_deere_api/request/collection/base_test.rb +27 -0
- data/test/lib/my_john_deere_api/request/collection/contribution_definitions_test.rb +88 -0
- data/test/lib/my_john_deere_api/request/collection/contribution_products_test.rb +88 -0
- data/test/lib/my_john_deere_api/request/collection/fields_test.rb +86 -0
- data/test/lib/my_john_deere_api/request/collection/flags_test.rb +92 -0
- data/test/lib/my_john_deere_api/request/collection/organizations_test.rb +87 -0
- data/test/lib/my_john_deere_api/request/collection_test.rb +37 -0
- data/test/lib/my_john_deere_api/request/create/asset_location_test.rb +163 -0
- data/test/lib/my_john_deere_api/request/create/asset_test.rb +182 -0
- data/test/lib/my_john_deere_api/request/create/base_test.rb +29 -0
- data/test/lib/my_john_deere_api/request/create_test.rb +17 -0
- data/test/lib/my_john_deere_api/request/individual/asset_test.rb +33 -0
- data/test/lib/my_john_deere_api/request/individual/base_test.rb +18 -0
- data/test/lib/my_john_deere_api/request/individual/contribution_definition_test.rb +33 -0
- data/test/lib/my_john_deere_api/request/individual/contribution_product_test.rb +33 -0
- data/test/lib/my_john_deere_api/request/individual/field_test.rb +37 -0
- data/test/lib/my_john_deere_api/request/individual/organization_test.rb +33 -0
- data/test/lib/my_john_deere_api/request/individual_test.rb +29 -0
- data/test/lib/my_john_deere_api/request/update/asset_test.rb +99 -0
- data/test/lib/my_john_deere_api/request/update/base_test.rb +60 -0
- data/test/lib/my_john_deere_api/request/update_test.rb +13 -0
- data/test/lib/my_john_deere_api/request_test.rb +21 -0
- data/test/lib/my_john_deere_api/validators/asset_location_test.rb +61 -0
- data/test/lib/my_john_deere_api/validators/asset_test.rb +93 -0
- data/test/lib/my_john_deere_api/validators/base_test.rb +92 -0
- data/test/lib/my_john_deere_api/validators_test.rb +17 -0
- data/test/lib/my_john_deere_api/version_test.rb +9 -0
- data/test/my_john_deere_api_test.rb +37 -0
- data/test/support/helper.rb +97 -0
- data/test/support/vcr/accessor/delete_failed.yml +327 -0
- data/test/support/vcr/accessor/delete_max_failed.yml +615 -0
- data/test/support/vcr/accessor/delete_retry.yml +191 -0
- data/test/support/vcr/accessor/delete_retry_too_soon.yml +191 -0
- data/test/support/vcr/accessor/get_failed.yml +390 -0
- data/test/support/vcr/accessor/get_max_failed.yml +734 -0
- data/test/support/vcr/accessor/get_retry.yml +226 -0
- data/test/support/vcr/accessor/get_retry_too_soon.yml +226 -0
- data/test/support/vcr/accessor/post_failed.yml +417 -0
- data/test/support/vcr/accessor/post_max_failed.yml +785 -0
- data/test/support/vcr/accessor/post_retry.yml +241 -0
- data/test/support/vcr/accessor/post_retry_too_soon.yml +241 -0
- data/test/support/vcr/accessor/put_failed.yml +372 -0
- data/test/support/vcr/accessor/put_max_failed.yml +700 -0
- data/test/support/vcr/accessor/put_retry.yml +216 -0
- data/test/support/vcr/accessor/put_retry_too_soon.yml +216 -0
- data/test/support/vcr/catalog.yml +89 -0
- data/test/support/vcr/delete_asset.yml +82 -0
- data/test/support/vcr/get_access_token.yml +41 -0
- data/test/support/vcr/get_asset.yml +144 -0
- data/test/support/vcr/get_asset_locations.yml +196 -0
- data/test/support/vcr/get_assets.yml +152 -0
- data/test/support/vcr/get_contribution_definition.yml +90 -0
- data/test/support/vcr/get_contribution_definitions.yml +91 -0
- data/test/support/vcr/get_contribution_product.yml +91 -0
- data/test/support/vcr/get_contribution_products.yml +91 -0
- data/test/support/vcr/get_field.yml +144 -0
- data/test/support/vcr/get_fields.yml +146 -0
- data/test/support/vcr/get_flags.yml +47 -0
- data/test/support/vcr/get_organization.yml +90 -0
- data/test/support/vcr/get_organizations.yml +149 -0
- data/test/support/vcr/get_request_token.yml +83 -0
- data/test/support/vcr/post_asset_locations.yml +244 -0
- data/test/support/vcr/post_assets.yml +192 -0
- data/test/support/vcr/put_asset.yml +87 -0
- data/test/support/vcr/warning.txt +28 -0
- data/test/support/vcr_setup.rb +488 -0
- metadata +277 -0
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'support/helper'
|
2
|
+
|
3
|
+
describe 'JD::Consumer' do
|
4
|
+
describe '#initialize' do
|
5
|
+
it 'requires an api key and secret' do
|
6
|
+
consumer = JD::Consumer.new(api_key, api_secret)
|
7
|
+
|
8
|
+
assert_equal api_key, consumer.api_key
|
9
|
+
assert_equal api_secret, consumer.api_secret
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'accepts the environment' do
|
13
|
+
environment = :sandbox
|
14
|
+
consumer = JD::Consumer.new(api_key, api_secret, environment: environment)
|
15
|
+
|
16
|
+
assert_equal environment, consumer.environment
|
17
|
+
assert_equal JD::Consumer::URLS[environment], consumer.base_url
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'accepts an arbitrary base_url' do
|
21
|
+
base_url = 'https://example.com'
|
22
|
+
consumer = JD::Consumer.new(api_key, api_secret, base_url: base_url)
|
23
|
+
|
24
|
+
assert_equal base_url, consumer.base_url
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'uses specified base_url regardless of specified environment' do
|
28
|
+
base_url = 'https://example.com'
|
29
|
+
consumer = JD::Consumer.new(api_key, api_secret, base_url: base_url, environment: :sandbox)
|
30
|
+
|
31
|
+
assert_equal base_url, consumer.base_url
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe '#app_get' do
|
36
|
+
it 'creates a working oAuth consumer for non-user-specific GET requests' do
|
37
|
+
consumer = JD::Consumer.new(api_key, api_secret, environment: :sandbox)
|
38
|
+
app_get = VCR.use_cassette('catalog') { consumer.app_get }
|
39
|
+
|
40
|
+
assert_kind_of OAuth::Consumer, app_get
|
41
|
+
assert_equal api_key, app_get.key
|
42
|
+
assert_equal api_secret, app_get.secret
|
43
|
+
assert_equal JD::Consumer::URLS[:sandbox], app_get.site
|
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
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'support/helper'
|
2
|
+
|
3
|
+
describe 'MyJohnDeereApi::InvalidRecordError' do
|
4
|
+
it 'inherits from StandardError' do
|
5
|
+
error = MyJohnDeereApi::InvalidRecordError.new
|
6
|
+
assert_kind_of StandardError, error
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'has a default message' do
|
10
|
+
error = MyJohnDeereApi::InvalidRecordError.new
|
11
|
+
assert_includes error.message, 'Record is invalid'
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'accepts a hash of errors, and includes them in message' do
|
15
|
+
errors = {
|
16
|
+
name: 'must be specified',
|
17
|
+
age: 'must be greater than 21'
|
18
|
+
}
|
19
|
+
|
20
|
+
message = MyJohnDeereApi::InvalidRecordError.new(errors).message
|
21
|
+
|
22
|
+
assert_includes message, 'Record is invalid'
|
23
|
+
assert_includes message, 'name must be specified'
|
24
|
+
assert_includes message, 'age must be greater than 21'
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'support/helper'
|
2
|
+
|
3
|
+
describe 'JD::NetHttpRetry::MaxRetriesExceededError' do
|
4
|
+
it 'inherits from StandardError' do
|
5
|
+
error = JD::NetHttpRetry::MaxRetriesExceededError.new(:get, '503')
|
6
|
+
assert_kind_of StandardError, error
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'accepts a request description, and includes in message' do
|
10
|
+
message = JD::NetHttpRetry::MaxRetriesExceededError.new(:get, '503 Service Unavailable').message
|
11
|
+
assert_equal message, "Max retries exceeded for GET request: 503 Service Unavailable"
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'support/helper'
|
2
|
+
|
3
|
+
describe 'MyJohnDeereApi::MissingContributionDefinitionIdError' do
|
4
|
+
let(:klass) { MyJohnDeereApi::MissingContributionDefinitionIdError }
|
5
|
+
let(:error) { klass.new }
|
6
|
+
|
7
|
+
it 'inherits from StandardError' do
|
8
|
+
assert_kind_of StandardError, error
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'has a default message' do
|
12
|
+
assert_includes error.message, 'Contribution Definition ID must be set in the client to use this feature.'
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'support/helper'
|
2
|
+
|
3
|
+
describe 'MyJohnDeereApi::NotYetImplementedError' do
|
4
|
+
it 'inherits from StandardError' do
|
5
|
+
error = MyJohnDeereApi::NotYetImplementedError.new
|
6
|
+
assert_kind_of StandardError, error
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'has a default message' do
|
10
|
+
error = MyJohnDeereApi::NotYetImplementedError.new
|
11
|
+
assert_includes error.message, 'This is not yet implemented. View README to help make this gem better!'
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'support/helper'
|
2
|
+
|
3
|
+
describe 'MyJohnDeereApi::TypeMismatchError' do
|
4
|
+
it 'inherits from StandardError' do
|
5
|
+
error = MyJohnDeereApi::TypeMismatchError.new
|
6
|
+
assert_kind_of StandardError, error
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'has a default message' do
|
10
|
+
error = MyJohnDeereApi::TypeMismatchError.new
|
11
|
+
assert_includes error.message, 'Record type does not match'
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'support/helper'
|
2
|
+
|
3
|
+
describe 'MyJohnDeereApi::UnsupportedEnvironmentError' do
|
4
|
+
it 'inherits from StandardError' do
|
5
|
+
error = MyJohnDeereApi::UnsupportedEnvironmentError.new
|
6
|
+
assert_kind_of StandardError, error
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'has a default message' do
|
10
|
+
error = MyJohnDeereApi::UnsupportedEnvironmentError.new
|
11
|
+
assert_includes error.message, 'This environment is not supported.'
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'specifies the failing environment if supplied' do
|
15
|
+
error = MyJohnDeereApi::UnsupportedEnvironmentError.new(:turtles)
|
16
|
+
assert_includes error.message, "The :turtles environment is not supported."
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'support/helper'
|
2
|
+
|
3
|
+
describe 'MyJohnDeereApi Errors' do
|
4
|
+
describe 'loading dependencies' do
|
5
|
+
it 'loads InvalidRecordError' do
|
6
|
+
assert JD::InvalidRecordError
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'loads MissingContributionDefinitionIdError' do
|
10
|
+
assert JD::MissingContributionDefinitionIdError
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'loads NotYetImplementedError' do
|
14
|
+
assert JD::NotYetImplementedError
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'loads TypeMismatchError' do
|
18
|
+
assert JD::TypeMismatchError
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'loads UnsupportedEnvironmentError' do
|
22
|
+
assert JD::UnsupportedEnvironmentError
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'support/helper'
|
2
|
+
|
3
|
+
class CaseConversionHelperSample
|
4
|
+
include JD::Helpers::CaseConversion
|
5
|
+
|
6
|
+
def test
|
7
|
+
'test'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'Helpers::CaseConversion' do
|
12
|
+
let(:object) { CaseConversionHelperSample.new }
|
13
|
+
|
14
|
+
describe '#underscore' do
|
15
|
+
it 'converts from camelcase' do
|
16
|
+
string = object.send(:underscore, 'camelCaseExample')
|
17
|
+
assert_equal 'camel_case_example', string
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'converts from a symbol' do
|
21
|
+
string = object.send(:underscore, :camelCaseExample)
|
22
|
+
assert_equal 'camel_case_example', string
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'converts the keys of a hash' do
|
26
|
+
hash = {
|
27
|
+
assetCategory: 'Asset Category',
|
28
|
+
assetType: 'Asset Type'
|
29
|
+
}
|
30
|
+
|
31
|
+
new_hash = object.send(:underscore, hash)
|
32
|
+
|
33
|
+
assert_equal new_hash['asset_category'], hash[:assetCategory]
|
34
|
+
assert_equal new_hash['asset_type'], hash[:assetType]
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'handles leading uppercase' do
|
38
|
+
string = object.send(:underscore, 'CamelCaseExample')
|
39
|
+
assert_equal 'camel_case_example', string
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'converts spaces to underscores' do
|
43
|
+
string = object.send(:underscore, 'camel case Example')
|
44
|
+
assert_equal 'camel_case_example', string
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'removes duplicate underscores after processing' do
|
48
|
+
string = object.send(:underscore, 'camel Case Example')
|
49
|
+
assert_equal 'camel_case_example', string
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'is a private method' do
|
53
|
+
exception = assert_raises(NoMethodError) { object.underscore('test') }
|
54
|
+
assert_includes exception.message, 'private method'
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe '#camelize' do
|
59
|
+
it 'converts from underscored' do
|
60
|
+
string = object.send(:camelize, 'this_is_a_test')
|
61
|
+
assert_equal 'thisIsATest', string
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'converts from spaced' do
|
65
|
+
string = object.send(:camelize, 'this is a test')
|
66
|
+
assert_equal 'thisIsATest', string
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'honors original capitalization' do
|
70
|
+
string = object.send(:camelize, 'This is a test')
|
71
|
+
assert_equal 'ThisIsATest', string
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'converts from a symbol' do
|
75
|
+
string = object.send(:camelize, :this_is_a_test)
|
76
|
+
assert_equal 'thisIsATest', string
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'converts the keys of a hash' do
|
80
|
+
hash = {
|
81
|
+
asset_category: 'Asset Category',
|
82
|
+
asset_type: 'Asset Type'
|
83
|
+
}
|
84
|
+
|
85
|
+
new_hash = object.send(:camelize, hash)
|
86
|
+
|
87
|
+
assert_equal new_hash['assetCategory'], hash[:asset_category]
|
88
|
+
assert_equal new_hash['assetType'], hash[:asset_type]
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'is a private method' do
|
92
|
+
exception = assert_raises(NoMethodError) { object.camelize('test') }
|
93
|
+
assert_includes exception.message, 'private method'
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
it "preserves the public nature of the including class's other methods" do
|
98
|
+
assert_equal 'test', object.test
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'support/helper'
|
2
|
+
|
3
|
+
class EnvironmentHelperSample
|
4
|
+
include JD::Helpers::EnvironmentHelper
|
5
|
+
|
6
|
+
def initialize(environment = nil)
|
7
|
+
self.environment = environment
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'EnvironmentHelper' do
|
12
|
+
let(:object) { EnvironmentHelperSample.new(environment) }
|
13
|
+
let(:environment) { :sandbox }
|
14
|
+
|
15
|
+
it 'provides an attr_reader for :environment' do
|
16
|
+
assert object.environment
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'when no specific environment requested' do
|
20
|
+
let(:environment) { nil }
|
21
|
+
|
22
|
+
it 'sets the environment to :live' do
|
23
|
+
assert_equal :live, object.environment
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe 'when :sandbox environment requested' do
|
28
|
+
let(:environment) { :sandbox }
|
29
|
+
|
30
|
+
it 'sets the environment to :sandbox' do
|
31
|
+
assert_equal environment, object.environment
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe 'when :live environment requested' do
|
36
|
+
let(:environment) { :live }
|
37
|
+
|
38
|
+
it 'sets the environment to :live' do
|
39
|
+
assert_equal environment, object.environment
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe 'when :production synonym requested' do
|
44
|
+
let(:environment) { :production }
|
45
|
+
|
46
|
+
it 'sets the environment to :live' do
|
47
|
+
assert_equal :live, object.environment
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe 'when environment is passed as a string' do
|
52
|
+
let(:environment) { 'sandbox' }
|
53
|
+
|
54
|
+
it 'converts the environment to a symbol' do
|
55
|
+
assert_equal :sandbox, object.environment
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe 'when an unrecognized environment is requested' do
|
60
|
+
let(:environment) { :turtles }
|
61
|
+
|
62
|
+
it 'raises an error' do
|
63
|
+
exception = assert_raises(JD::UnsupportedEnvironmentError) { object }
|
64
|
+
assert_equal "The :turtles environment is not supported.", exception.message
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'support/helper'
|
2
|
+
|
3
|
+
class UriHelpersHelperSample
|
4
|
+
include JD::Helpers::UriHelpers
|
5
|
+
|
6
|
+
def test
|
7
|
+
'test'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'UriHelpers' do
|
12
|
+
let(:object) { UriHelpersHelperSample.new }
|
13
|
+
|
14
|
+
describe '#uri_path' do
|
15
|
+
it 'extracts the path from the uri' do
|
16
|
+
path = object.send(:uri_path, 'https://example.com/turtles')
|
17
|
+
assert_equal '/turtles', path
|
18
|
+
end
|
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
|
+
it 'is a private method' do
|
31
|
+
exception = assert_raises(NoMethodError) { object.uri_path('https://example.com/turtles')}
|
32
|
+
assert_includes exception.message, 'private method'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#id_from_uri(uri, label)' do
|
37
|
+
it 'extracts the id immediately following a given label' do
|
38
|
+
uri = 'https://example.com/cows/123/pigs/456/turtles/789/birds/012'
|
39
|
+
assert_equal '789', object.send(:id_from_uri, uri, 'turtles')
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'accepts a symbol for the label' do
|
43
|
+
uri = 'https://example.com/cows/123/pigs/456/turtles/789/birds/012'
|
44
|
+
assert_equal '789', object.send(:id_from_uri, uri, :turtles)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'is a private method' do
|
48
|
+
uri = 'https://example.com/cows/123/pigs/456/turtles/789/birds/012'
|
49
|
+
|
50
|
+
exception = assert_raises(NoMethodError) { object.id_from_uri(uri, 'turtles') }
|
51
|
+
assert_includes exception.message, 'private method'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
it "preserves the public nature of the including class's other methods" do
|
56
|
+
assert_equal 'test', object.test
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'support/helper'
|
2
|
+
|
3
|
+
class ValidateContributionDefinitionHelperSample
|
4
|
+
include JD::Helpers::ValidateContributionDefinition
|
5
|
+
|
6
|
+
attr_reader :client
|
7
|
+
|
8
|
+
def initialize(client)
|
9
|
+
@client = client
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe 'Helpers::ValidateContributionDefinition' do
|
14
|
+
let(:object) { ValidateContributionDefinitionHelperSample.new(client) }
|
15
|
+
|
16
|
+
describe '#validate_contribution_definition' do
|
17
|
+
it 'returns true when contribution_definition_id is present' do
|
18
|
+
assert object.send(:validate_contribution_definition)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'raises an error when contribution_definition_id is missing' do
|
22
|
+
client.contribution_definition_id = nil
|
23
|
+
|
24
|
+
assert_raises(JD::MissingContributionDefinitionIdError) do
|
25
|
+
object.send(:validate_contribution_definition)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# describe '#uri_path' do
|
31
|
+
# it 'extracts the path from the uri' do
|
32
|
+
# path = object.send(:uri_path, 'https://example.com/turtles')
|
33
|
+
# assert_equal '/turtles', path
|
34
|
+
# end
|
35
|
+
#
|
36
|
+
# it 'removes leading /platform from the path' do
|
37
|
+
# path = object.send(:uri_path, 'https://example.com/platform/turtles')
|
38
|
+
# assert_equal '/turtles', path
|
39
|
+
# end
|
40
|
+
#
|
41
|
+
# it 'preserves /platform in any other part of the path' do
|
42
|
+
# path = object.send(:uri_path, 'https://example.com/platform/turtles/platform')
|
43
|
+
# assert_equal '/turtles/platform', path
|
44
|
+
# end
|
45
|
+
#
|
46
|
+
# it 'is a private method' do
|
47
|
+
# exception = assert_raises(NoMethodError) { object.uri_path('https://example.com/turtles')}
|
48
|
+
# assert_includes exception.message, 'private method'
|
49
|
+
# end
|
50
|
+
# end
|
51
|
+
#
|
52
|
+
# describe '#id_from_uri(uri, label)' do
|
53
|
+
# it 'extracts the id immediately following a given label' do
|
54
|
+
# uri = 'https://example.com/cows/123/pigs/456/turtles/789/birds/012'
|
55
|
+
# assert_equal '789', object.send(:id_from_uri, uri, 'turtles')
|
56
|
+
# end
|
57
|
+
#
|
58
|
+
# it 'accepts a symbol for the label' do
|
59
|
+
# uri = 'https://example.com/cows/123/pigs/456/turtles/789/birds/012'
|
60
|
+
# assert_equal '789', object.send(:id_from_uri, uri, :turtles)
|
61
|
+
# end
|
62
|
+
#
|
63
|
+
# it 'is a private method' do
|
64
|
+
# uri = 'https://example.com/cows/123/pigs/456/turtles/789/birds/012'
|
65
|
+
#
|
66
|
+
# exception = assert_raises(NoMethodError) { object.id_from_uri(uri, 'turtles') }
|
67
|
+
# assert_includes exception.message, 'private method'
|
68
|
+
# end
|
69
|
+
# end
|
70
|
+
#
|
71
|
+
# it "preserves the public nature of the including class's other methods" do
|
72
|
+
# assert_equal 'test', object.test
|
73
|
+
# end
|
74
|
+
end
|