gecko-ruby 0.9.1 → 0.10.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 +4 -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 +10 -10
- data/lib/gecko/ext/log_subscriber.rb +6 -6
- data/lib/gecko/helpers/association_helper.rb +11 -9
- 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 +23 -18
- 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 +5 -1
- 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 +34 -30
- 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/lib/gecko/record/variant.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'gecko/record/base'
|
2
4
|
|
3
5
|
module Gecko
|
@@ -13,7 +15,7 @@ module Gecko
|
|
13
15
|
attribute :committed, BigDecimal
|
14
16
|
attribute :stock_on_hand, BigDecimal
|
15
17
|
|
16
|
-
|
18
|
+
alias committed_stock committed
|
17
19
|
end
|
18
20
|
|
19
21
|
class VariantPrice
|
@@ -84,12 +86,12 @@ module Gecko
|
|
84
86
|
#
|
85
87
|
# @api public
|
86
88
|
def display_name
|
87
|
-
if name.nil? || !name.include?(product_name)
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
parts.select { |part| part
|
89
|
+
parts = if name.nil? || !name.include?(product_name)
|
90
|
+
[sku, product_name, name]
|
91
|
+
else
|
92
|
+
[sku, name]
|
93
|
+
end
|
94
|
+
parts.select { |part| part&.length }.join(' - ')
|
93
95
|
end
|
94
96
|
|
95
97
|
# attribute :is_online
|
data/lib/gecko/record/webhook.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'gecko/record/base'
|
2
4
|
|
3
5
|
module Gecko
|
@@ -27,7 +29,7 @@ module Gecko
|
|
27
29
|
stock_adjustment.create
|
28
30
|
stock_transfer.create
|
29
31
|
variant.create
|
30
|
-
]
|
32
|
+
].freeze
|
31
33
|
|
32
34
|
attribute :address, String
|
33
35
|
attribute :event, String
|
data/lib/gecko/version.rb
CHANGED
data/test/client_test.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
|
3
5
|
class ClientTest < Minitest::Test
|
@@ -13,10 +15,10 @@ class ClientTest < Minitest::Test
|
|
13
15
|
def test_custom_user_agent
|
14
16
|
client = Gecko::Client.new("ABC", "DEF")
|
15
17
|
agent = client.oauth_client.connection.headers["User-Agent"]
|
16
|
-
assert_match(%r
|
18
|
+
assert_match(%r{Gecko/#{Gecko::VERSION} OAuth2/\d\.\d\.\d Faraday/\d\.\d+\.\d Ruby/\d\.\d\.\d}, agent)
|
17
19
|
end
|
18
20
|
|
19
|
-
def
|
21
|
+
def test_allows_test_urls
|
20
22
|
client = Gecko::Client.new("ABC", "DEF", site: "localhost:3000")
|
21
23
|
assert_equal "localhost:3000", client.oauth_client.site
|
22
24
|
end
|
@@ -53,7 +53,7 @@ http_interactions:
|
|
53
53
|
- chunked
|
54
54
|
body:
|
55
55
|
encoding: UTF-8
|
56
|
-
string: '{"images":[{"
|
56
|
+
string: '{"images":[{"base_path":"https://tradegecko-development-images.s3.amazonaws.com/uploads/variant_image/image/204","created_at":"2013-12-19T03:55:45.973Z","file_name":"Dead_Cool.jpeg","id":204,"image_processing":false,"name":"p17e54uam11hmn11g019qg16gj1lvh4.jpeg","position":1,"product_id":27,"updated_at":"2013-12-19T03:55:45.973Z","uploader_id":26,"variant_ids":[1035],"versions":["thumbnail"]},{"base_path":"https://tradegecko-development-images.s3.amazonaws.com/uploads/variant_image/image/5140","created_at":"2013-12-19T03:55:45.973Z","file_name":"Broken_heart_copy.jpeg","id":5140,"image_processing":false,"name":"p17hgbcgn413jf2pi9h415jjjc74.jpeg","position":1,"product_id":27,"updated_at":"2013-12-19T03:55:45.973Z","uploader_id":26,"variant_id":1995,"variant_ids":[1995],"versions":["thumbnail"]},{"base_path":"https://tradegecko-development-images.s3.amazonaws.com/uploads/variant_image/image/59274","created_at":"2013-12-19T03:55:45.973Z","file_name":"dellMON.jpg","id":59274,"image_processing":false,"name":null,"position":1,"product_id":28,"updated_at":"2013-12-19T03:55:45.973Z","uploader_id":"Shopify","variant_id":92694,"variant_ids":[92694],"versions":["thumbnail"]},{"base_path":"https://tradegecko-development-images.s3.amazonaws.com/uploads/variant_image/image/206","created_at":"2013-12-19T03:55:45.973Z","file_name":"Dead_Cool.jpeg","id":206,"image_processing":false,"name":"p17e54urld1ffth831j3ct6a1gl1e.jpeg","position":1,"product_id":1034,"updated_at":"2013-12-19T03:55:45.973Z","uploader_id":26,"variant_id":1034,"variant_ids":[1034],"versions":["thumbnail"]},{"base_path":"https://tradegecko-development-images.s3.amazonaws.com/uploads/variant_image/image/251","created_at":"2013-12-19T03:55:45.973Z","file_name":"Chance_PerfectBoatneck_WhiteW.Navy.jpg","id":251,"image_processing":false,"name":"p17eh9kpij1u771kg1rdc103vn5i.jpg","position":1,"product_id":5252,"updated_at":"2013-12-19T03:55:45.973Z","uploader_id":213,"variant_id":5252,"variant_ids":[5252],"versions":["thumbnail"]}]}'
|
57
57
|
http_version:
|
58
58
|
recorded_at: Wed, 12 Mar 2014 11:39:39 GMT
|
59
59
|
recorded_with: VCR 2.8.0
|
data/test/gecko_test.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'gecko'
|
2
4
|
|
3
5
|
class Gecko::Helpers::AssociationHelperTest < Minitest::Test
|
@@ -25,31 +27,31 @@ class Gecko::Helpers::AssociationHelperTest < Minitest::Test
|
|
25
27
|
end
|
26
28
|
|
27
29
|
def test_has_many
|
28
|
-
record = @klass.new(@client, {order_ids: [123]})
|
30
|
+
record = @klass.new(@client, { order_ids: [123] })
|
29
31
|
@client.Order.expects(:find_many).with([123])
|
30
32
|
record.orders
|
31
33
|
end
|
32
34
|
|
33
35
|
def test_has_many_without_ids
|
34
|
-
record = @klass.new(@client, {order_ids: []})
|
36
|
+
record = @klass.new(@client, { order_ids: [] })
|
35
37
|
@client.Order.expects(:find_many).never
|
36
38
|
assert_empty(record.orders)
|
37
39
|
end
|
38
40
|
|
39
41
|
def test_belongs_to
|
40
|
-
record = @klass.new(@client, {order_id: 4})
|
42
|
+
record = @klass.new(@client, { order_id: 4 })
|
41
43
|
@client.Order.expects(:find).with(4)
|
42
44
|
record.order
|
43
45
|
end
|
44
46
|
|
45
47
|
def test_belongs_to_without_id
|
46
|
-
record = @klass.new(@client, {order_id: nil})
|
48
|
+
record = @klass.new(@client, { order_id: nil })
|
47
49
|
@client.Order.expects(:find).never
|
48
50
|
assert_nil record.order
|
49
51
|
end
|
50
52
|
|
51
53
|
def test_belongs_to_with_class
|
52
|
-
record = @klass.new(@client, {small_order_id: 56})
|
54
|
+
record = @klass.new(@client, { small_order_id: 56 })
|
53
55
|
@client.Order.expects(:find).with(56)
|
54
56
|
record.small_order
|
55
57
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'gecko'
|
2
4
|
|
3
5
|
class Gecko::Helpers::InspectionHelperTest < Minitest::Test
|
@@ -12,9 +14,9 @@ class Gecko::Helpers::InspectionHelperTest < Minitest::Test
|
|
12
14
|
|
13
15
|
def test_inspect_times
|
14
16
|
record = @klass.new(@client, {
|
15
|
-
published_date:
|
16
|
-
published_time:
|
17
|
-
published_datetime: DateTime.new(2014)
|
17
|
+
published_date: Date.new(2014),
|
18
|
+
published_time: Time.new(2014),
|
19
|
+
published_datetime: DateTime.new(2014)
|
18
20
|
})
|
19
21
|
assert_equal("2014-01-01 00:00:00", get_timestamp(record.inspect, :published_time))
|
20
22
|
assert_equal("2014-01-01 00:00:00", get_timestamp(record.inspect, :published_datetime))
|
@@ -22,6 +24,6 @@ class Gecko::Helpers::InspectionHelperTest < Minitest::Test
|
|
22
24
|
end
|
23
25
|
|
24
26
|
def get_timestamp(inspect_string, attribute)
|
25
|
-
inspect_string.match(
|
27
|
+
inspect_string.match(/#{attribute}: \"(?<timestamp>[\d:\s-]+)\"/)[:timestamp]
|
26
28
|
end
|
27
29
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'gecko'
|
2
4
|
require 'test_helper'
|
3
5
|
|
@@ -27,14 +29,14 @@ class Gecko::Helpers::SerializationHelperTest < Minitest::Test
|
|
27
29
|
|
28
30
|
let(:record) do
|
29
31
|
Widget.new(@client, {
|
30
|
-
name:
|
31
|
-
secret:
|
32
|
+
name: "Gecko",
|
33
|
+
secret: "Iguana",
|
32
34
|
initial_stock: 10.0,
|
33
|
-
update_stock:
|
34
|
-
score:
|
35
|
-
started_at:
|
36
|
-
started_on:
|
37
|
-
wodgets:
|
35
|
+
update_stock: 10.0,
|
36
|
+
score: 1.234,
|
37
|
+
started_at: DateTime.now,
|
38
|
+
started_on: Date.today,
|
39
|
+
wodgets: [Wodget.new(@client, name: "Hi")]
|
38
40
|
})
|
39
41
|
end
|
40
42
|
|
@@ -48,7 +50,7 @@ class Gecko::Helpers::SerializationHelperTest < Minitest::Test
|
|
48
50
|
end
|
49
51
|
|
50
52
|
def test_as_json
|
51
|
-
assert_equal({widget: record.serializable_hash}, record.as_json)
|
53
|
+
assert_equal({ widget: record.serializable_hash }, record.as_json)
|
52
54
|
end
|
53
55
|
|
54
56
|
def test_writeable_on_create
|
@@ -72,7 +74,7 @@ class Gecko::Helpers::SerializationHelperTest < Minitest::Test
|
|
72
74
|
end
|
73
75
|
|
74
76
|
def test_serializes_arrays
|
75
|
-
assert_equal([{name: "Hi"}], record.serializable_hash[:wodgets])
|
77
|
+
assert_equal([{ name: "Hi" }], record.serializable_hash[:wodgets])
|
76
78
|
end
|
77
79
|
|
78
80
|
def test_root_key
|
@@ -100,12 +102,12 @@ private
|
|
100
102
|
|
101
103
|
def serialized_record
|
102
104
|
{
|
103
|
-
name:
|
105
|
+
name: "Gecko",
|
104
106
|
initial_stock: "10.0",
|
105
|
-
score:
|
106
|
-
started_on:
|
107
|
-
started_at:
|
108
|
-
wodgets:
|
107
|
+
score: "1.234",
|
108
|
+
started_on: Date.today,
|
109
|
+
started_at: DateTime.now,
|
110
|
+
wodgets: [{ name: "Hi" }]
|
109
111
|
}
|
110
112
|
end
|
111
113
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'gecko'
|
2
4
|
|
3
5
|
class Gecko::Helpers::ValidationHelperTest < Minitest::Test
|
@@ -17,7 +19,7 @@ class Gecko::Helpers::ValidationHelperTest < Minitest::Test
|
|
17
19
|
|
18
20
|
def test_from_response
|
19
21
|
record = @klass.new(@client, name: "Gecko")
|
20
|
-
record.errors.from_response({name: ["is not shiny"]})
|
22
|
+
record.errors.from_response({ name: ["is not shiny"] })
|
21
23
|
assert(!record.valid?)
|
22
24
|
assert_equal(record.errors[:name], ["is not shiny"])
|
23
25
|
end
|
data/test/record/address_test.rb
CHANGED
data/test/record/company_test.rb
CHANGED
data/test/record/contact_test.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
|
3
5
|
class Gecko::ContactTest < Minitest::Test
|
@@ -15,4 +17,4 @@ class Gecko::ContactTest < Minitest::Test
|
|
15
17
|
def test_initializes_record
|
16
18
|
assert_instance_of(Gecko::Record::Contact, @record)
|
17
19
|
end
|
18
|
-
end
|
20
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
|
3
5
|
class Gecko::FulfillmentTest < Minitest::Test
|
@@ -17,11 +19,11 @@ class Gecko::FulfillmentTest < Minitest::Test
|
|
17
19
|
end
|
18
20
|
|
19
21
|
def test_serialization
|
20
|
-
json_keys = %w
|
22
|
+
json_keys = %w[
|
21
23
|
order_id shipping_address_id billing_address_id status stock_location_id exchange_rate
|
22
24
|
delivery_type tracking_number notes tracking_url tracking_company packed_at
|
23
25
|
service shipped_at received_at receipt
|
24
|
-
|
26
|
+
].map(&:to_sym)
|
25
27
|
assert_equal json_keys.sort, @record.as_json[:fulfillment].keys.sort
|
26
28
|
end
|
27
29
|
end
|
data/test/record/image_test.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
|
3
5
|
class Gecko::ImageTest < Minitest::Test
|
@@ -22,4 +24,20 @@ class Gecko::ImageTest < Minitest::Test
|
|
22
24
|
assert_equal("https://example.com/Gecko.jpg", @record.url(:full))
|
23
25
|
assert_equal("https://example.com/thumbnail_Gecko.jpg", @record.url(:thumbnail))
|
24
26
|
end
|
27
|
+
|
28
|
+
def test_building_record # rubocop:disable Metrics/MethodLength
|
29
|
+
record = @client.adapter_for(record_class.demodulized_name).build({
|
30
|
+
variant_ids: 1,
|
31
|
+
product_id: 1,
|
32
|
+
url: "https://example.com/Gecko.jpg"
|
33
|
+
})
|
34
|
+
assert_equal(record.product_id, 1)
|
35
|
+
assert_equal(record.variant_ids, [1])
|
36
|
+
assert_equal(record.serializable_hash, {
|
37
|
+
product_id: 1,
|
38
|
+
variant_ids: [1],
|
39
|
+
name: nil,
|
40
|
+
url: "https://example.com/Gecko.jpg"
|
41
|
+
})
|
42
|
+
end
|
25
43
|
end
|
data/test/record/invoice_test.rb
CHANGED
data/test/record/note_test.rb
CHANGED