disco_app 0.13.4 → 0.13.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 333b0540e47c1d1c0f35b1e10ad0b8039fae81c91a9e96648ca4e5d2abbbb526
4
- data.tar.gz: 1749255c14c73a9c3835d4c9a1e140c9c695a97535445b16121eb9eb38e711ff
3
+ metadata.gz: 5cbe53474f9532175efcd1c15e0cea3a5673bead56896a9686e89dfc0678523c
4
+ data.tar.gz: fd20dc03f5c76e649505c2daf34005492a3a46929cd73f411139c004e178bfb3
5
5
  SHA512:
6
- metadata.gz: 0367c1f61d48894dcc70a8f08d8bfe2f00fe4c7ba589a0969ff28e2043f538c8f413f9417b02268940b9b9ba9281fc12d0278402406128dee20a7ea14fa45308
7
- data.tar.gz: 2da5c048070836eebd7fd577f01240cc70c8f4671d57d5f5be70143e23ab55029d5cecc514eb2b021129f626ef9703806c621dbd4c7610a3b05d7adeeb3a5553
6
+ metadata.gz: 5d2f69daede5c2304456a14d92cffaec906474b70095dd47e516f405cf58d206b4e04a36d5a336946a062c7d191f29b6667331429a955dfe9eeeeefbcaff44a7
7
+ data.tar.gz: 48ee3ac8fc12dfe21528562ff86fe2094037a3ca582a505927033b52e90a634057cf869621e535a92bb2667d4d6fb99e255cdb1e3be07e6cfc5ff63faafbfc05
@@ -2,6 +2,9 @@
2
2
  # particular Shop's API session. The first argument to any job inheriting from
3
3
  # this class must be the domain of the relevant store, so that the appropriate
4
4
  # Shop model can be fetched and the temporary API session created.
5
+
6
+ require 'rollbar'
7
+
5
8
  class DiscoApp::ShopJob < ActiveJob::Base
6
9
 
7
10
  queue_as :default
@@ -19,9 +22,13 @@ class DiscoApp::ShopJob < ActiveJob::Base
19
22
  end
20
23
 
21
24
  def shop_context(job, block)
22
- @shop.with_api_context {
23
- block.call(job.arguments)
24
- }
25
+ Rollbar.scoped(rollbar_scope) do
26
+ @shop.with_api_context { block.call(job.arguments) }
27
+ end
28
+ end
29
+
30
+ def rollbar_scope
31
+ { person: { id: @shop.id, username: @shop.shopify_domain } }
25
32
  end
26
33
 
27
34
  end
@@ -66,7 +66,7 @@ module DiscoApp::Concerns::Shop
66
66
 
67
67
  # Convenience method to get the email of the shop's admin, to display in Rollbar.
68
68
  def email
69
- self.data['email']
69
+ data[:email]
70
70
  end
71
71
 
72
72
  def installed_duration
@@ -77,7 +77,7 @@ module DiscoApp::Concerns::Shop
77
77
  # shop's "data" hash, return the default Rails zone (which should be UTC).
78
78
  def time_zone
79
79
  @time_zone ||= begin
80
- Time.find_zone!(data['timezone'].to_s.gsub(/^\(.+\)\s/, ''))
80
+ Time.find_zone!(data[:timezone].to_s.gsub(/^\(.+\)\s/, ''))
81
81
  rescue ArgumentError
82
82
  Time.zone
83
83
  end
@@ -86,7 +86,7 @@ module DiscoApp::Concerns::Shop
86
86
  # Return the shop's configured locale as a symbol. If none exists for some
87
87
  # reason, 'en' is returned.
88
88
  def locale
89
- (data['primary_locale'] || 'en').to_sym
89
+ (data[:primary_locale] || 'en').to_sym
90
90
  end
91
91
 
92
92
  # Return an instance of the Disco API client.
@@ -94,6 +94,11 @@ module DiscoApp::Concerns::Shop
94
94
  @api_client ||= DiscoApp::ApiClient.new(self, ENV['DISCO_API_URL'])
95
95
  end
96
96
 
97
+ # Override the "read" data attribute to allow indifferent access.
98
+ def data
99
+ read_attribute(:data).with_indifferent_access
100
+ end
101
+
97
102
  end
98
103
 
99
104
  end
@@ -58,4 +58,13 @@ module DiscoApp::Concerns::Synchronises
58
58
 
59
59
  end
60
60
 
61
+ included do
62
+
63
+ # Override the "read" data attribute to allow indifferent access.
64
+ def data
65
+ read_attribute(:data).with_indifferent_access
66
+ end
67
+
68
+ end
69
+
61
70
  end
@@ -2,15 +2,19 @@ module DiscoApp::Concerns::Taggable
2
2
  extend ActiveSupport::Concern
3
3
 
4
4
  def tags
5
- data['tags'].split(',').map(&:strip)
5
+ data[:tags].split(',').map(&:strip)
6
6
  end
7
7
 
8
8
  def add_tag(tag)
9
- data['tags'] = (tags + [tag]).uniq.join(',')
9
+ data[:tags] = (tags + [tag]).uniq.join(',')
10
10
  end
11
11
 
12
12
  def remove_tag(tag)
13
- data['tags'] = (tags - [tag]).uniq.join(',')
13
+ data[:tags] = (tags - [tag]).uniq.join(',')
14
+ end
15
+
16
+ def has_tag?(tag_to_check)
17
+ tags.any? { |tag| tag.casecmp(tag_to_check) }
14
18
  end
15
19
 
16
20
  end
@@ -5,13 +5,15 @@ module DiscoApp::Concerns::User
5
5
  belongs_to :shop
6
6
 
7
7
  def self.create_from_auth(shopify_user, shop)
8
- user = self.find_or_create_by(id: shopify_user.id, shop: shop)
8
+ user = self.find_or_create_by!(id: shopify_user.id, shop: shop)
9
9
  user.update(
10
10
  first_name: shopify_user.first_name || '',
11
11
  last_name: shopify_user.last_name || '',
12
12
  email: shopify_user.email
13
13
  )
14
14
  user
15
+ rescue ActiveRecord::RecordNotUnique, PG::UniqueViolation
16
+ retry
15
17
  end
16
18
 
17
19
  end
@@ -46,19 +46,19 @@ module DiscoApp::Admin::Resources::Concerns::ShopResource
46
46
  end
47
47
 
48
48
  def email
49
- @model.data['email']
49
+ @model.data[:email]
50
50
  end
51
51
 
52
52
  def country_name
53
- @model.data['country_name']
53
+ @model.data[:country_name]
54
54
  end
55
55
 
56
56
  def currency
57
- @model.data['currency']
57
+ @model.data[:currency]
58
58
  end
59
59
 
60
60
  def plan_display_name
61
- @model.data['plan_display_name']
61
+ @model.data[:plan_display_name]
62
62
  end
63
63
 
64
64
  def current_subscription_id
@@ -0,0 +1,6 @@
1
+ class FixDiscoAppUsersIndex < ActiveRecord::Migration
2
+ def change
3
+ remove_index :disco_app_users, :shop_id
4
+ add_index :disco_app_users, [:id, :shop_id], unique: true
5
+ end
6
+ end
@@ -1,3 +1,3 @@
1
1
  module DiscoApp
2
- VERSION = '0.13.4'
2
+ VERSION = '0.13.5'
3
3
  end
@@ -3,6 +3,7 @@ default: &default
3
3
  encoding: unicode
4
4
  pool: 5
5
5
  timeout: 5000
6
+ prepared_statements: false
6
7
 
7
8
  development:
8
9
  <<: *default
@@ -8,17 +8,17 @@ class Cart < ActiveRecord::Base
8
8
  before_save :set_token
9
9
 
10
10
  def self.synchronise_by(shop, data)
11
- { token: data['token'] }
11
+ { token: data[:token] }
12
12
  end
13
13
 
14
14
  def total_price
15
- data['line_items'].map { |line_item| line_item['line_price'].to_f }.sum
15
+ data[:line_items].map { |line_item| line_item[:line_price].to_f }.sum
16
16
  end
17
17
 
18
18
  private
19
19
 
20
20
  def set_token
21
- self.token = data['token']
21
+ self.token = data[:token]
22
22
  end
23
23
 
24
24
  end
@@ -11,7 +11,7 @@ class DiscoApp::Shop < ActiveRecord::Base
11
11
  # Extend the Shop model to return the Shop's country as an ActiveUtils country.
12
12
  def country
13
13
  begin
14
- ActiveUtils::Country.find(data['country_name'])
14
+ ActiveUtils::Country.find(data[:country_name])
15
15
  rescue ActiveUtils::InvalidCountryCodeError
16
16
  nil
17
17
  end
@@ -3,6 +3,7 @@ default: &default
3
3
  encoding: unicode
4
4
  pool: 5
5
5
  timeout: 5000
6
+ prepared_statements: false
6
7
 
7
8
  development:
8
9
  <<: *default
@@ -11,7 +11,7 @@
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: 20170327214540) do
14
+ ActiveRecord::Schema.define(version: 20170606160751) do
15
15
 
16
16
  # These are extensions that must be enabled in order to support this database
17
17
  enable_extension "plpgsql"
@@ -136,7 +136,7 @@ ActiveRecord::Schema.define(version: 20170327214540) do
136
136
  t.datetime "updated_at", null: false
137
137
  end
138
138
 
139
- add_index "disco_app_users", ["shop_id"], name: "index_disco_app_users_on_shop_id", unique: true, using: :btree
139
+ add_index "disco_app_users", ["id", "shop_id"], name: "index_disco_app_users_on_id_and_shop_id", unique: true, using: :btree
140
140
 
141
141
  create_table "js_configurations", force: :cascade do |t|
142
142
  t.integer "shop_id", limit: 8
@@ -18,7 +18,7 @@ class SynchronisesTest < ActionDispatch::IntegrationTest
18
18
 
19
19
  # Assert the product was created locally, with the correct attributes.
20
20
  product = Product.find(632910392)
21
- assert_equal 'IPod Nano - 8GB', product.data['title']
21
+ assert_equal 'IPod Nano - 8GB', product.data[:title]
22
22
  end
23
23
 
24
24
  test 'existing product is updated when product updated webhook is received' do
@@ -29,7 +29,7 @@ class SynchronisesTest < ActionDispatch::IntegrationTest
29
29
  # Assert the product was updated locally, with the correct attributes.
30
30
  @product.reload
31
31
  assert_equal 632910393, @product.id
32
- assert_equal 'IPod Nano - 8GB', @product.data['title']
32
+ assert_equal 'IPod Nano - 8GB', @product.data[:title]
33
33
  end
34
34
 
35
35
  test 'existing product is deleted when product deleted webhook is received' do
@@ -53,7 +53,7 @@ class SynchronisesTest < ActionDispatch::IntegrationTest
53
53
  # Assert the product was updated locally, with the correct attributes.
54
54
  @product.reload
55
55
  assert_equal 632910393, @product.id
56
- assert_equal 'IPod Nano - 8GB', @product.data['title']
56
+ assert_equal 'IPod Nano - 8GB', @product.data[:title]
57
57
  end
58
58
 
59
59
  private
@@ -27,7 +27,7 @@ class DiscoApp::AppInstalledJobTest < ActionController::TestCase
27
27
 
28
28
  # Assert the update shop job was performed.
29
29
  @shop.reload
30
- assert_equal 'United States', @shop.data['country_name']
30
+ assert_equal 'United States', @shop.data[:country_name]
31
31
  end
32
32
 
33
33
  test 'app installed job automatically subscribes stores to the correct default plan' do
@@ -25,6 +25,6 @@ class DiscoApp::AppUninstalledJobTest < ActionController::TestCase
25
25
  test 'app uninstalled job can be extended using concerns' do
26
26
  assert_performed_jobs 2
27
27
  @shop.reload
28
- assert_equal 'Nowhere', @shop.data['country_name'] # Assert extended method called.
28
+ assert_equal 'Nowhere', @shop.data[:country_name] # Assert extended method called.
29
29
  end
30
30
  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.13.4
4
+ version: 0.13.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gavin Ballard
@@ -642,6 +642,7 @@ files:
642
642
  - db/migrate/20170315062548_create_disco_app_sources.rb
643
643
  - db/migrate/20170315062629_add_sources_to_shop_subscriptions.rb
644
644
  - db/migrate/20170327214540_create_disco_app_users.rb
645
+ - db/migrate/20170606160751_fix_disco_app_users_index.rb
645
646
  - lib/disco_app.rb
646
647
  - lib/disco_app/configuration.rb
647
648
  - lib/disco_app/constants.rb
@@ -717,7 +718,6 @@ files:
717
718
  - test/dummy/config/application.rb
718
719
  - test/dummy/config/boot.rb
719
720
  - test/dummy/config/database.codeship.yml
720
- - test/dummy/config/database.gitlab-ci.yml
721
721
  - test/dummy/config/database.yml
722
722
  - test/dummy/config/environment.rb
723
723
  - test/dummy/config/environments/development.rb
@@ -912,7 +912,6 @@ test_files:
912
912
  - test/dummy/config/environment.rb
913
913
  - test/dummy/config/boot.rb
914
914
  - test/dummy/config/database.yml
915
- - test/dummy/config/database.gitlab-ci.yml
916
915
  - test/dummy/config/application.rb
917
916
  - test/fixtures/liquid/model.liquid
918
917
  - test/fixtures/api/subscriptions/valid_request.json
@@ -1,24 +0,0 @@
1
- development:
2
- adapter: postgresql
3
- host: postgres
4
- encoding: unicode
5
- pool: 10
6
- username: disco_pguser
7
- template: template1
8
- password: disco_pgpassword
9
- database: disco_app
10
- port: 5432
11
- sslmode: disable
12
-
13
- test:
14
- adapter: postgresql
15
- host: postgres
16
- encoding: unicode
17
- pool: 10
18
- username: disco_pguser
19
- template: template1
20
- password: disco_pgpassword
21
- database: disco_app
22
- port: 5432
23
- sslmode: disable
24
-