disco_app 0.10.4 → 0.10.5
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/app/models/disco_app/concerns/shop.rb +6 -0
- data/app/models/disco_app/concerns/synchronises.rb +5 -1
- data/app/views/disco_app/install/installing.html.erb +18 -3
- data/lib/disco_app/version.rb +1 -1
- data/test/dummy/app/jobs/carts_update_job.rb +7 -0
- data/test/dummy/app/models/cart.rb +24 -0
- data/test/dummy/config/initializers/disco_app.rb +1 -1
- data/test/dummy/db/migrate/20161105054746_create_carts.rb +13 -0
- data/test/dummy/db/schema.rb +12 -1
- data/test/fixtures/carts.yml +5 -0
- data/test/fixtures/disco_app/shops.yml +1 -1
- data/test/fixtures/webhooks/cart_updated.json +28 -0
- data/test/integration/synchronises_test.rb +8 -1
- data/test/models/disco_app/shop_test.rb +8 -0
- metadata +11 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d2699aebc167db360768aa4fa911174c22af550d15d9d3193d7748ce6a4dddf3
|
4
|
+
data.tar.gz: d11b08a1f24ffb3a64d306f03dd84132297c20ea9c51ba86c73f5f5450b4fa33
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79865fb4cb2da60159930b27830937634e40f10749866fafc27a5fd47af56fcb4343a199d93416df7edd398441b860e0531831a14d167078b8468729ad10e382
|
7
|
+
data.tar.gz: 9edcce2afda59c4a59d850d9018b84ac645941dc1d330bc1ff1075b22c7c0324d9fdd249ae4b7ea9452b959d3f8c1cfb36d3b311c5f63e6b196e7395c395d24c
|
@@ -10,13 +10,17 @@ module DiscoApp::Concerns::Synchronises
|
|
10
10
|
true
|
11
11
|
end
|
12
12
|
|
13
|
+
def synchronise_by(shop, data)
|
14
|
+
{ id: data[:id] }
|
15
|
+
end
|
16
|
+
|
13
17
|
def synchronise(shop, data)
|
14
18
|
data = data.with_indifferent_access
|
15
19
|
|
16
20
|
return unless should_synchronise?(shop, data)
|
17
21
|
|
18
22
|
begin
|
19
|
-
instance = self.find_or_create_by!(
|
23
|
+
instance = self.find_or_create_by!(self.synchronise_by(shop, data)) do |instance|
|
20
24
|
instance.shop = shop
|
21
25
|
instance.data = data
|
22
26
|
end
|
@@ -2,6 +2,21 @@
|
|
2
2
|
<meta http-equiv="refresh" content="5">
|
3
3
|
<% end %>
|
4
4
|
|
5
|
-
<
|
6
|
-
|
7
|
-
|
5
|
+
<div class="ui-empty-state">
|
6
|
+
<section class="ui-empty-state__section">
|
7
|
+
<div class="ui-empty-state__subsection">
|
8
|
+
<h1 class="ui-empty-state__title">Installing <%= DiscoApp.configuration.app_name %></h1>
|
9
|
+
<h2 class="ui-empty-state__subtitle">Please wait...</h2>
|
10
|
+
</div>
|
11
|
+
</section>
|
12
|
+
</div>
|
13
|
+
|
14
|
+
<div class="ui-footer-help">
|
15
|
+
<div class="ui-footer-help__content">
|
16
|
+
<div>
|
17
|
+
<p>
|
18
|
+
Stuck on this page? <a href="mailto:help@discolabs.com?subject=<%= DiscoApp.configuration.app_name %> not installing for <%= @shop.shopify_domain %>!">Email us</a>.
|
19
|
+
</p>
|
20
|
+
</div>
|
21
|
+
</div>
|
22
|
+
</div>
|
data/lib/disco_app/version.rb
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
class Cart < ActiveRecord::Base
|
2
|
+
include DiscoApp::Concerns::Synchronises
|
3
|
+
|
4
|
+
belongs_to :shop, class_name: 'DiscoApp::Shop'
|
5
|
+
|
6
|
+
SHOPIFY_API_CLASS = ShopifyAPI::Cart
|
7
|
+
|
8
|
+
before_save :set_token
|
9
|
+
|
10
|
+
def self.synchronise_by(shop, data)
|
11
|
+
{ token: data['token'] }
|
12
|
+
end
|
13
|
+
|
14
|
+
def total_price
|
15
|
+
data['line_items'].map { |line_item| line_item['line_price'].to_f }.sum
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def set_token
|
21
|
+
self.token = data['token']
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -6,7 +6,7 @@ DiscoApp.configure do |config|
|
|
6
6
|
|
7
7
|
# Set a list of webhook topics to listen for.
|
8
8
|
# See https://help.shopify.com/api/reference/webhook.
|
9
|
-
config.webhook_topics = [:'orders/create', :'orders/paid']
|
9
|
+
config.webhook_topics = [:'orders/create', :'orders/paid', :'carts/create', :'carts/update']
|
10
10
|
|
11
11
|
# Set the below if using an application proxy.
|
12
12
|
config.app_proxy_prefix = ENV['SHOPIFY_APP_PROXY_PREFIX']
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class CreateCarts < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :carts do |t|
|
4
|
+
t.integer :shop_id, limit: 8
|
5
|
+
t.string :token
|
6
|
+
t.jsonb :data
|
7
|
+
|
8
|
+
t.timestamps null: false
|
9
|
+
end
|
10
|
+
add_foreign_key :carts, :disco_app_shops, column: :shop_id
|
11
|
+
add_index :carts, :token, unique: true
|
12
|
+
end
|
13
|
+
end
|
data/test/dummy/db/schema.rb
CHANGED
@@ -11,11 +11,21 @@
|
|
11
11
|
#
|
12
12
|
# It's strongly recommended that you check this file into your version control system.
|
13
13
|
|
14
|
-
ActiveRecord::Schema.define(version:
|
14
|
+
ActiveRecord::Schema.define(version: 20161105054746) do
|
15
15
|
|
16
16
|
# These are extensions that must be enabled in order to support this database
|
17
17
|
enable_extension "plpgsql"
|
18
18
|
|
19
|
+
create_table "carts", force: :cascade do |t|
|
20
|
+
t.integer "shop_id", limit: 8
|
21
|
+
t.string "token"
|
22
|
+
t.jsonb "data"
|
23
|
+
t.datetime "created_at", null: false
|
24
|
+
t.datetime "updated_at", null: false
|
25
|
+
end
|
26
|
+
|
27
|
+
add_index "carts", ["token"], name: "index_carts_on_token", unique: true, using: :btree
|
28
|
+
|
19
29
|
create_table "disco_app_app_settings", force: :cascade do |t|
|
20
30
|
t.datetime "created_at", null: false
|
21
31
|
t.datetime "updated_at", null: false
|
@@ -128,6 +138,7 @@ ActiveRecord::Schema.define(version: 20160530160739) do
|
|
128
138
|
t.string "background_color", default: "#FFFFFF"
|
129
139
|
end
|
130
140
|
|
141
|
+
add_foreign_key "carts", "disco_app_shops", column: "shop_id"
|
131
142
|
add_foreign_key "disco_app_application_charges", "disco_app_shops", column: "shop_id"
|
132
143
|
add_foreign_key "disco_app_application_charges", "disco_app_subscriptions", column: "subscription_id"
|
133
144
|
add_foreign_key "disco_app_plan_codes", "disco_app_plans", column: "plan_id"
|
@@ -0,0 +1,28 @@
|
|
1
|
+
{
|
2
|
+
"created_at": "2016-11-05T04:34:40.353Z",
|
3
|
+
"updated_at": "2016-11-05T05:36:58.908Z",
|
4
|
+
"id": "efa1e7d02cfc60cf3ddadbed770ef1b6",
|
5
|
+
"token": "efa1e7d02cfc60cf3ddadbed770ef1b6",
|
6
|
+
"line_items": [
|
7
|
+
{
|
8
|
+
"id": 27132991496,
|
9
|
+
"properties": null,
|
10
|
+
"quantity": 2,
|
11
|
+
"variant_id": 27132991496,
|
12
|
+
"key": "27132991496:bf1f8c0342f4b55df844abfcc8536c49",
|
13
|
+
"title": "Douglas - Black/White - XS",
|
14
|
+
"price": "1600.00",
|
15
|
+
"original_price": "1600.00",
|
16
|
+
"discounted_price": "1600.00",
|
17
|
+
"line_price": "3200.00",
|
18
|
+
"original_line_price": "3200.00",
|
19
|
+
"total_discount": "0.00",
|
20
|
+
"discounts": [],
|
21
|
+
"sku": "300 60 041-XS",
|
22
|
+
"grams": 0,
|
23
|
+
"vendor": "Uniforms for the Dedicated",
|
24
|
+
"product_id": 8194697800,
|
25
|
+
"gift_card": false
|
26
|
+
}
|
27
|
+
]
|
28
|
+
}
|
@@ -32,11 +32,18 @@ class SynchronisesTest < ActionDispatch::IntegrationTest
|
|
32
32
|
assert_equal 'IPod Nano - 8GB', @product.data['title']
|
33
33
|
end
|
34
34
|
|
35
|
-
test 'existing product is deleted when product deleted webhook is
|
35
|
+
test 'existing product is deleted when product deleted webhook is received' do
|
36
36
|
post_webhook('product_deleted', :'products/delete')
|
37
37
|
assert_equal 0, Product.count
|
38
38
|
end
|
39
39
|
|
40
|
+
test 'cart with token for id is updated when cart updated webhook is received' do
|
41
|
+
post_webhook('cart_updated', :'carts/update')
|
42
|
+
|
43
|
+
# Assert the cart data was correctly updated
|
44
|
+
assert_equal 3200.0, carts(:cart).total_price
|
45
|
+
end
|
46
|
+
|
40
47
|
private
|
41
48
|
|
42
49
|
def webhooks_url
|
@@ -32,4 +32,12 @@ class DiscoApp::ShopTest < ActiveSupport::TestCase
|
|
32
32
|
assert_equal 'UTC', disco_app_shops(:widget_store_dev).time_zone.name
|
33
33
|
end
|
34
34
|
|
35
|
+
test 'locale helper returns correct locale when defined on shop model' do
|
36
|
+
assert_equal :sv, disco_app_shops(:widget_store_dev).locale
|
37
|
+
end
|
38
|
+
|
39
|
+
test 'locale helper returns correct en locale when no known locale defined' do
|
40
|
+
assert_equal :en, disco_app_shops(:widget_store).locale
|
41
|
+
end
|
42
|
+
|
35
43
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: disco_app
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.10.
|
4
|
+
version: 0.10.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gavin Ballard
|
@@ -582,11 +582,13 @@ files:
|
|
582
582
|
- test/dummy/app/controllers/home_controller.rb
|
583
583
|
- test/dummy/app/controllers/proxy_controller.rb
|
584
584
|
- test/dummy/app/helpers/application_helper.rb
|
585
|
+
- test/dummy/app/jobs/carts_update_job.rb
|
585
586
|
- test/dummy/app/jobs/disco_app/app_installed_job.rb
|
586
587
|
- test/dummy/app/jobs/disco_app/app_uninstalled_job.rb
|
587
588
|
- test/dummy/app/jobs/products_create_job.rb
|
588
589
|
- test/dummy/app/jobs/products_delete_job.rb
|
589
590
|
- test/dummy/app/jobs/products_update_job.rb
|
591
|
+
- test/dummy/app/models/cart.rb
|
590
592
|
- test/dummy/app/models/disco_app/shop.rb
|
591
593
|
- test/dummy/app/models/js_configuration.rb
|
592
594
|
- test/dummy/app/models/product.rb
|
@@ -628,6 +630,7 @@ files:
|
|
628
630
|
- test/dummy/config/secrets.yml
|
629
631
|
- test/dummy/db/migrate/20160307182229_create_products.rb
|
630
632
|
- test/dummy/db/migrate/20160530160739_create_asset_models.rb
|
633
|
+
- test/dummy/db/migrate/20161105054746_create_carts.rb
|
631
634
|
- test/dummy/db/schema.rb
|
632
635
|
- test/dummy/public/404.html
|
633
636
|
- test/dummy/public/422.html
|
@@ -677,6 +680,7 @@ files:
|
|
677
680
|
- test/fixtures/api/widget_store/webhooks.json
|
678
681
|
- test/fixtures/assets/test.js
|
679
682
|
- test/fixtures/assets/test.min.js
|
683
|
+
- test/fixtures/carts.yml
|
680
684
|
- test/fixtures/disco_app/application_charges.yml
|
681
685
|
- test/fixtures/disco_app/plan_codes.yml
|
682
686
|
- test/fixtures/disco_app/plans.yml
|
@@ -687,6 +691,7 @@ files:
|
|
687
691
|
- test/fixtures/liquid/model.liquid
|
688
692
|
- test/fixtures/products.yml
|
689
693
|
- test/fixtures/webhooks/app_uninstalled.json
|
694
|
+
- test/fixtures/webhooks/cart_updated.json
|
690
695
|
- test/fixtures/webhooks/product_created.json
|
691
696
|
- test/fixtures/webhooks/product_deleted.json
|
692
697
|
- test/fixtures/webhooks/product_updated.json
|
@@ -750,6 +755,7 @@ test_files:
|
|
750
755
|
- test/dummy/app/jobs/disco_app/app_installed_job.rb
|
751
756
|
- test/dummy/app/jobs/disco_app/app_uninstalled_job.rb
|
752
757
|
- test/dummy/app/jobs/products_delete_job.rb
|
758
|
+
- test/dummy/app/jobs/carts_update_job.rb
|
753
759
|
- test/dummy/app/controllers/home_controller.rb
|
754
760
|
- test/dummy/app/controllers/disco_app/admin/shops_controller.rb
|
755
761
|
- test/dummy/app/controllers/carrier_request_controller.rb
|
@@ -760,12 +766,14 @@ test_files:
|
|
760
766
|
- test/dummy/app/models/product.rb
|
761
767
|
- test/dummy/app/models/widget_configuration.rb
|
762
768
|
- test/dummy/app/models/js_configuration.rb
|
769
|
+
- test/dummy/app/models/cart.rb
|
763
770
|
- test/dummy/app/views/assets/script_tag.js.erb
|
764
771
|
- test/dummy/app/views/assets/widget.scss.erb
|
765
772
|
- test/dummy/app/views/assets/test.js.erb
|
766
773
|
- test/dummy/app/views/assets/widget.js.erb
|
767
774
|
- test/dummy/app/views/snippets/widget.liquid.erb
|
768
775
|
- test/dummy/app/views/home/index.html.erb
|
776
|
+
- test/dummy/db/migrate/20161105054746_create_carts.rb
|
769
777
|
- test/dummy/db/migrate/20160530160739_create_asset_models.rb
|
770
778
|
- test/dummy/db/migrate/20160307182229_create_products.rb
|
771
779
|
- test/dummy/db/schema.rb
|
@@ -846,6 +854,8 @@ test_files:
|
|
846
854
|
- test/fixtures/disco_app/subscriptions.yml
|
847
855
|
- test/fixtures/disco_app/plans.yml
|
848
856
|
- test/fixtures/disco_app/recurring_application_charges.yml
|
857
|
+
- test/fixtures/carts.yml
|
858
|
+
- test/fixtures/webhooks/cart_updated.json
|
849
859
|
- test/fixtures/webhooks/app_uninstalled.json
|
850
860
|
- test/fixtures/webhooks/product_updated.json
|
851
861
|
- test/fixtures/webhooks/product_created.json
|