gecko-ruby 0.9.0 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/config/rubocop_linter_action.yml +7 -0
- data/.github/workflows/testing.yml +26 -0
- data/.rubocop.yml +23 -16
- data/CHANGELOG.md +18 -0
- data/Gemfile +2 -0
- data/README.md +1 -1
- data/Rakefile +3 -1
- data/gecko-ruby.gemspec +11 -10
- data/generate.thor +4 -1
- data/lib/gecko-ruby.rb +2 -0
- data/lib/gecko.rb +2 -0
- data/lib/gecko/client.rb +16 -14
- data/lib/gecko/ext/liquid_compat.rb +11 -9
- data/lib/gecko/ext/log_subscriber.rb +6 -6
- data/lib/gecko/helpers/association_helper.rb +14 -12
- data/lib/gecko/helpers/inspection_helper.rb +4 -2
- data/lib/gecko/helpers/record_helper.rb +2 -0
- data/lib/gecko/helpers/serialization_helper.rb +5 -1
- data/lib/gecko/helpers/validation_helper.rb +3 -1
- data/lib/gecko/record/account.rb +3 -1
- data/lib/gecko/record/address.rb +2 -0
- data/lib/gecko/record/base.rb +5 -3
- data/lib/gecko/record/base_adapter.rb +33 -22
- data/lib/gecko/record/company.rb +2 -0
- data/lib/gecko/record/contact.rb +2 -0
- data/lib/gecko/record/currency.rb +2 -0
- data/lib/gecko/record/exceptions.rb +2 -0
- data/lib/gecko/record/fulfillment.rb +2 -0
- data/lib/gecko/record/fulfillment_line_item.rb +2 -1
- data/lib/gecko/record/image.rb +13 -8
- data/lib/gecko/record/invoice.rb +7 -3
- data/lib/gecko/record/invoice_line_item.rb +2 -1
- data/lib/gecko/record/location.rb +2 -0
- data/lib/gecko/record/note.rb +2 -0
- data/lib/gecko/record/order.rb +2 -0
- data/lib/gecko/record/order_line_item.rb +3 -0
- data/lib/gecko/record/payment_term.rb +2 -1
- data/lib/gecko/record/product.rb +4 -0
- data/lib/gecko/record/purchase_order.rb +2 -1
- data/lib/gecko/record/purchase_order_line_item.rb +2 -1
- data/lib/gecko/record/tax_type.rb +2 -1
- data/lib/gecko/record/user.rb +3 -1
- data/lib/gecko/record/variant.rb +9 -7
- data/lib/gecko/record/webhook.rb +3 -1
- data/lib/gecko/version.rb +3 -1
- data/test/client_test.rb +4 -2
- data/test/fixtures/vcr_cassettes/images.yml +1 -1
- data/test/gecko_test.rb +2 -0
- data/test/helpers/association_helper_test.rb +7 -5
- data/test/helpers/inspection_helper_test.rb +6 -4
- data/test/helpers/serialization_helper_test.rb +16 -14
- data/test/helpers/validation_helper_test.rb +3 -1
- data/test/record/account_adapter_test.rb +2 -0
- data/test/record/address_adapter_test.rb +2 -0
- data/test/record/address_test.rb +2 -0
- data/test/record/company_adapter_test.rb +2 -0
- data/test/record/company_test.rb +2 -0
- data/test/record/contact_adapter_test.rb +2 -0
- data/test/record/contact_test.rb +3 -1
- data/test/record/currency_adapter_test.rb +2 -0
- data/test/record/currency_test.rb +2 -0
- data/test/record/fulfillment_adapter_test.rb +2 -0
- data/test/record/fulfillment_line_item_adapter_test.rb +2 -0
- data/test/record/fulfillment_line_item_test.rb +2 -0
- data/test/record/fulfillment_test.rb +4 -2
- data/test/record/image_adapter_test.rb +2 -0
- data/test/record/image_test.rb +18 -0
- data/test/record/invoice_adapter_test.rb +2 -0
- data/test/record/invoice_line_item_adapter_test.rb +2 -0
- data/test/record/invoice_line_item_test.rb +2 -0
- data/test/record/invoice_test.rb +2 -0
- data/test/record/location_adapter_test.rb +2 -0
- data/test/record/location_test.rb +2 -0
- data/test/record/note_test.rb +2 -0
- data/test/record/order_adapter_test.rb +2 -0
- data/test/record/order_line_item_adapter_test.rb +2 -0
- data/test/record/order_line_item_test.rb +2 -0
- data/test/record/order_test.rb +2 -0
- data/test/record/payment_term_adapter_test.rb +2 -0
- data/test/record/payment_term_test.rb +2 -0
- data/test/record/product_adapter_test.rb +2 -0
- data/test/record/product_test.rb +2 -0
- data/test/record/purchase_order_adapter_test.rb +2 -0
- data/test/record/purchase_order_line_item_adapter_test.rb +2 -0
- data/test/record/purchase_order_line_item_test.rb +2 -0
- data/test/record/purchase_order_test.rb +2 -0
- data/test/record/tax_type_adapter_test.rb +2 -0
- data/test/record/tax_type_test.rb +2 -0
- data/test/record/user_adapter_test.rb +2 -0
- data/test/record/user_test.rb +2 -0
- data/test/record/variant_adapter_test.rb +2 -0
- data/test/record/variant_test.rb +6 -4
- data/test/record/webhook_test.rb +2 -0
- data/test/support/let.rb +2 -0
- data/test/support/shared_adapter_examples.rb +35 -31
- data/test/support/shared_record_examples.rb +3 -1
- data/test/support/shared_sideloaded_data_parsing_examples.rb +2 -1
- data/test/support/testing_adapter.rb +2 -0
- data/test/support/vcr_support.rb +2 -0
- data/test/test_helper.rb +2 -0
- metadata +24 -23
- data/.travis.yml +0 -8
data/test/record/invoice_test.rb
CHANGED
data/test/record/note_test.rb
CHANGED
data/test/record/order_test.rb
CHANGED
data/test/record/product_test.rb
CHANGED
data/test/record/user_test.rb
CHANGED
data/test/record/variant_test.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
|
3
5
|
class Gecko::VariantTest < Minitest::Test
|
@@ -22,7 +24,7 @@ class Gecko::VariantTest < Minitest::Test
|
|
22
24
|
end
|
23
25
|
|
24
26
|
def test_variant_prices
|
25
|
-
json = {variant_prices: [{price_list_id: "buy", value: "12.50"}, {price_list_id: 123, value: "14.00"}]}
|
27
|
+
json = { variant_prices: [{ price_list_id: "buy", value: "12.50" }, { price_list_id: 123, value: "14.00" }] }
|
26
28
|
variant_prices = record_class.new(client, json).variant_prices
|
27
29
|
assert_instance_of(Gecko::Record::Variant::VariantPrice, variant_prices.first)
|
28
30
|
assert_equal(variant_prices[0].price_list_id, "buy")
|
@@ -31,10 +33,10 @@ class Gecko::VariantTest < Minitest::Test
|
|
31
33
|
end
|
32
34
|
|
33
35
|
def test_variant_locations
|
34
|
-
json = {locations: [
|
36
|
+
json = { locations: [
|
35
37
|
{ location_id: 1, stock_on_hand: "12.50",
|
36
|
-
committed: "0", bin_location: "AB-123" }
|
37
|
-
]}
|
38
|
+
committed: "0", bin_location: "AB-123" }
|
39
|
+
] }
|
38
40
|
|
39
41
|
locations = record_class.new(client, json).locations
|
40
42
|
assert_instance_of(Gecko::Record::Variant::VariantLocation, locations.first)
|
data/test/record/webhook_test.rb
CHANGED
data/test/support/let.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Shared tests for Gecko::Record Adapters
|
2
4
|
# requires definition of several variables
|
3
5
|
# - adapter
|
@@ -5,7 +7,8 @@
|
|
5
7
|
# - record_class
|
6
8
|
|
7
9
|
require 'json'
|
8
|
-
|
10
|
+
|
11
|
+
module SharedAdapterExamples # rubocop:disable Metrics/ModuleLength
|
9
12
|
def test_adapter_all
|
10
13
|
VCR.use_cassette(plural_name) do
|
11
14
|
collection = adapter.where(limit: 5)
|
@@ -49,29 +52,29 @@ module SharedAdapterExamples
|
|
49
52
|
|
50
53
|
def test_has_record_for_id
|
51
54
|
mock_record = Object.new
|
52
|
-
adapter.instance_variable_set(:@identity_map, {12 => mock_record})
|
55
|
+
adapter.instance_variable_set(:@identity_map, { 12 => mock_record })
|
53
56
|
assert adapter.has_record_for_id?(12)
|
54
57
|
assert !adapter.has_record_for_id?(12345)
|
55
58
|
end
|
56
59
|
|
57
60
|
def test_fetch
|
58
|
-
request_stub = stub_request(:get,
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
61
|
+
request_stub = stub_request(:get, %r{#{plural_name}/\d+})
|
62
|
+
.to_return({
|
63
|
+
headers: { "Content-Type" => "application/json" },
|
64
|
+
body: JSON.dump({ plural_name.singularize => { id: 12345 } })
|
65
|
+
})
|
63
66
|
record = adapter.fetch(12345)
|
64
67
|
assert_equal(12345, record.id)
|
65
68
|
assert_requested(request_stub)
|
66
69
|
end
|
67
70
|
|
68
|
-
def test_fetch_miss
|
69
|
-
stub_request(:get,
|
71
|
+
def test_fetch_miss # rubocop:disable Metrics/MethodLength
|
72
|
+
stub_request(:get, %r{#{plural_name}/\d+})
|
70
73
|
.to_return({
|
71
74
|
status: 404,
|
72
|
-
headers: {"Content-Type" => "application/json"},
|
73
|
-
body:
|
74
|
-
type:
|
75
|
+
headers: { "Content-Type" => "application/json" },
|
76
|
+
body: JSON.dump({
|
77
|
+
type: "Not Found",
|
75
78
|
message: "Couldn't find #{plural_name.singularize} with id 12345"
|
76
79
|
})
|
77
80
|
})
|
@@ -105,9 +108,8 @@ module SharedAdapterExamples
|
|
105
108
|
def test_saving_new_record
|
106
109
|
record = adapter.build
|
107
110
|
mock_api_request(record,
|
108
|
-
|
109
|
-
|
110
|
-
)
|
111
|
+
[:post, plural_name],
|
112
|
+
[200, { plural_name.singularize => { id: 123 } }])
|
111
113
|
adapter.save(record)
|
112
114
|
assert_equal(record.id, 123)
|
113
115
|
assert(record.valid?)
|
@@ -116,9 +118,8 @@ module SharedAdapterExamples
|
|
116
118
|
def test_saving_new_invalid_record
|
117
119
|
record = adapter.build
|
118
120
|
mock_api_request(record,
|
119
|
-
|
120
|
-
|
121
|
-
)
|
121
|
+
[:post, plural_name],
|
122
|
+
[422, { "errors" => { title: ["can not be bounced"] } }])
|
122
123
|
adapter.save(record)
|
123
124
|
assert_nil(record.id)
|
124
125
|
assert(!record.valid?)
|
@@ -127,9 +128,8 @@ module SharedAdapterExamples
|
|
127
128
|
def test_saving_existing_record
|
128
129
|
record = existing_record
|
129
130
|
mock_api_request(record,
|
130
|
-
|
131
|
-
|
132
|
-
)
|
131
|
+
[:put, "#{plural_name}/#{record.id}"],
|
132
|
+
[204, ''])
|
133
133
|
adapter.save(record)
|
134
134
|
assert(record.valid?)
|
135
135
|
end
|
@@ -137,23 +137,22 @@ module SharedAdapterExamples
|
|
137
137
|
def test_saving_existing_invalid_record
|
138
138
|
record = existing_record
|
139
139
|
mock_api_request(record,
|
140
|
-
|
141
|
-
|
142
|
-
)
|
140
|
+
[:put, "#{plural_name}/#{record.id}"],
|
141
|
+
[422, { "errors" => { title: ["can not be bounced"] } }])
|
143
142
|
adapter.save(record)
|
144
143
|
assert(!record.valid?)
|
145
144
|
assert(record.errors[:title].any?)
|
146
145
|
end
|
147
146
|
|
148
|
-
def test_saving_record_with_idempotency_key
|
147
|
+
def test_saving_record_with_idempotency_key # rubocop:disable Metrics/MethodLength
|
149
148
|
record = adapter.build
|
150
149
|
mock_token = mock
|
151
|
-
mock_response = mock(status: 200, parsed: {plural_name.singularize => {id: 123}})
|
150
|
+
mock_response = mock(status: 200, parsed: { plural_name.singularize => { id: 123 } }, error: nil)
|
152
151
|
mock_token.expects(:request)
|
153
152
|
.with(:post, plural_name, {
|
154
|
-
body:
|
153
|
+
body: record.as_json.to_json,
|
155
154
|
raise_errors: false,
|
156
|
-
headers:
|
155
|
+
headers: {
|
157
156
|
'Content-Type' => 'application/json',
|
158
157
|
'Idempotency-Key' => 'abcdefghijkl'
|
159
158
|
}
|
@@ -163,11 +162,16 @@ module SharedAdapterExamples
|
|
163
162
|
end
|
164
163
|
|
165
164
|
private
|
165
|
+
|
166
166
|
def mock_api_request(record, request, response)
|
167
167
|
mock_token = mock
|
168
|
-
mock_response = mock(status: response[0], parsed: response[1])
|
168
|
+
mock_response = mock(status: response[0], parsed: response[1], error: nil)
|
169
169
|
mock_token.expects(:request)
|
170
|
-
.with(request[0], request[1],
|
170
|
+
.with(request[0], request[1], {
|
171
|
+
body: record.as_json.to_json,
|
172
|
+
raise_errors: false,
|
173
|
+
headers: { 'Content-Type' => 'application/json' }
|
174
|
+
})
|
171
175
|
.returns(mock_response)
|
172
176
|
adapter.client.access_token = mock_token
|
173
177
|
end
|
@@ -177,6 +181,6 @@ private
|
|
177
181
|
end
|
178
182
|
|
179
183
|
def random_attribute
|
180
|
-
@
|
184
|
+
@random_attribute ||= record_class.attribute_set.find { |att| att.type == Axiom::Types::String }.name
|
181
185
|
end
|
182
186
|
end
|
@@ -1,7 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module SharedSideloadedDataParsingExamples
|
2
4
|
def test_adapter_sideloaded_data_parsing
|
3
5
|
VCR.use_cassette(plural_name + '_sideloaded') do
|
4
|
-
|
5
6
|
collection = adapter.where(limit: 5, _include: children.join(","))
|
6
7
|
|
7
8
|
children.each do |child|
|
data/test/support/vcr_support.rb
CHANGED
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gecko-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bradley Priest
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-07-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -25,7 +25,7 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: dotenv
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
@@ -53,7 +53,7 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: mocha
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
@@ -67,7 +67,7 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: pry
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
@@ -81,7 +81,7 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: rake
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - ">="
|
@@ -95,7 +95,7 @@ dependencies:
|
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: thor
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - ">="
|
@@ -109,7 +109,7 @@ dependencies:
|
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
112
|
+
name: timecop
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
115
|
- - ">="
|
@@ -123,7 +123,7 @@ dependencies:
|
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
|
-
name:
|
126
|
+
name: vcr
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
129
|
- - ">="
|
@@ -137,7 +137,7 @@ dependencies:
|
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
|
-
name:
|
140
|
+
name: webmock
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
143
|
- - ">="
|
@@ -151,35 +151,35 @@ dependencies:
|
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '0'
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
|
-
name:
|
154
|
+
name: activesupport
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
156
156
|
requirements:
|
157
|
-
- - "
|
157
|
+
- - ">="
|
158
158
|
- !ruby/object:Gem::Version
|
159
|
-
version:
|
159
|
+
version: '0'
|
160
160
|
type: :runtime
|
161
161
|
prerelease: false
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
|
-
- - "
|
164
|
+
- - ">="
|
165
165
|
- !ruby/object:Gem::Version
|
166
|
-
version:
|
166
|
+
version: '0'
|
167
167
|
- !ruby/object:Gem::Dependency
|
168
|
-
name:
|
168
|
+
name: oauth2
|
169
169
|
requirement: !ruby/object:Gem::Requirement
|
170
170
|
requirements:
|
171
|
-
- - "
|
171
|
+
- - ">"
|
172
172
|
- !ruby/object:Gem::Version
|
173
|
-
version:
|
173
|
+
version: 1.1.0
|
174
174
|
type: :runtime
|
175
175
|
prerelease: false
|
176
176
|
version_requirements: !ruby/object:Gem::Requirement
|
177
177
|
requirements:
|
178
|
-
- - "
|
178
|
+
- - ">"
|
179
179
|
- !ruby/object:Gem::Version
|
180
|
-
version:
|
180
|
+
version: 1.1.0
|
181
181
|
- !ruby/object:Gem::Dependency
|
182
|
-
name:
|
182
|
+
name: virtus
|
183
183
|
requirement: !ruby/object:Gem::Requirement
|
184
184
|
requirements:
|
185
185
|
- - ">="
|
@@ -199,10 +199,11 @@ executables: []
|
|
199
199
|
extensions: []
|
200
200
|
extra_rdoc_files: []
|
201
201
|
files:
|
202
|
+
- ".github/config/rubocop_linter_action.yml"
|
203
|
+
- ".github/workflows/testing.yml"
|
202
204
|
- ".gitignore"
|
203
205
|
- ".hound.yml"
|
204
206
|
- ".rubocop.yml"
|
205
|
-
- ".travis.yml"
|
206
207
|
- CHANGELOG.md
|
207
208
|
- CONTRIBUTING.md
|
208
209
|
- Gemfile
|
@@ -365,7 +366,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
365
366
|
- !ruby/object:Gem::Version
|
366
367
|
version: '0'
|
367
368
|
requirements: []
|
368
|
-
rubygems_version: 3.
|
369
|
+
rubygems_version: 3.1.2
|
369
370
|
signing_key:
|
370
371
|
specification_version: 4
|
371
372
|
summary: A Ruby interface to the TradeGecko API.
|