spree_core 3.1.0.rc4 → 3.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4cb7bbd6bde30953cc5391ee02b054f23ca0b9b9
4
- data.tar.gz: b9824021ae30dabf0f658a412bdcb8b37a76ebbd
3
+ metadata.gz: f35feac4376cd13546d618115a69843e88fc1cd5
4
+ data.tar.gz: 4c8e8813de79c6000a63d75fba52a2e3c446474b
5
5
  SHA512:
6
- metadata.gz: e993ddd8cd1329cf5a7925c4cea0ac14a33c7a8cabc75b2ee6c0793502e4d8d759e2f94a92d4c100c34ef6408ff073f9df5205df23356afdbb2249a9e548edf6
7
- data.tar.gz: c7f741a6505e5d5c15ff12f08afdc137aa8b3f8cfde04541b834e6bcb782a750257ac2463c2da5d74994fc8abf194d9683867fbb7bd8dba9875a9555ee1ec614
6
+ metadata.gz: 2681d8f8676b8d42aabdca0ee04058a36375a3407d2321173b5aa72faee19ae644b0e32b2a4df917adb26c40986c1125fa50801222d7ca14a1ff09c0143d1fc5
7
+ data.tar.gz: 1223897e7344f28e241967b864994bc4958056d0faa40b1ac430cfc8b18a31be28ef3ee1cad0314a4446e5ca0ccdc80b687c05066a92edbfc4922d9ddb36970f
@@ -25,6 +25,10 @@ module Spree
25
25
 
26
26
  acts_as_paranoid
27
27
 
28
+ # we need to have this callback before any dependent: :destroy associations
29
+ # https://github.com/rails/rails/issues/3458
30
+ before_destroy :ensure_no_line_items
31
+
28
32
  has_many :product_option_types, dependent: :destroy, inverse_of: :product
29
33
  has_many :option_types, through: :product_option_types
30
34
  has_many :product_properties, dependent: :destroy, inverse_of: :product
@@ -355,6 +359,13 @@ module Spree
355
359
  Spree::Taxonomy.where(id: taxonomy_ids).update_all(updated_at: Time.current)
356
360
  end
357
361
 
362
+ def ensure_no_line_items
363
+ if line_items.any?
364
+ errors.add(:base, Spree.t(:cannot_destroy_if_attached_to_line_items))
365
+ return false
366
+ end
367
+ end
368
+
358
369
  def remove_taxon(taxon)
359
370
  removed_classifications = classifications.where(taxon: taxon)
360
371
  removed_classifications.each &:remove_from_list
@@ -12,13 +12,16 @@ module Spree
12
12
  :shipping_category_id, :meta_description, :meta_keywords,
13
13
  :shipping_category
14
14
 
15
+ # we need to have this callback before any dependent: :destroy associations
16
+ # https://github.com/rails/rails/issues/3458
17
+ before_destroy :ensure_no_line_items
18
+
15
19
  with_options inverse_of: :variant do
16
20
  has_many :inventory_units
21
+ has_many :line_items
17
22
  has_many :stock_items, dependent: :destroy
18
23
  end
19
24
 
20
- has_many :line_items, dependent: :restrict_with_error
21
-
22
25
  has_many :orders, through: :line_items
23
26
  with_options through: :stock_items do
24
27
  has_many :stock_locations
@@ -258,6 +261,13 @@ module Spree
258
261
 
259
262
  private
260
263
 
264
+ def ensure_no_line_items
265
+ if line_items.any?
266
+ errors.add(:base, Spree.t(:cannot_destroy_if_attached_to_line_items))
267
+ return false
268
+ end
269
+ end
270
+
261
271
  def quantifier
262
272
  Spree::Stock::Quantifier.new(self)
263
273
  end
@@ -309,6 +309,14 @@ en:
309
309
  attributes:
310
310
  currency:
311
311
  must_match_order_currency: "Must match order currency"
312
+ spree/promotion:
313
+ attributes:
314
+ expires_at:
315
+ invalid_date_range: must be later than start date
316
+ spree/product:
317
+ attributes:
318
+ base:
319
+ cannot_destroy_if_attached_to_line_items: Cannot delete products once they are attached to line items.
312
320
  spree/refund:
313
321
  attributes:
314
322
  amount:
@@ -342,6 +350,10 @@ en:
342
350
  attributes:
343
351
  base:
344
352
  cannot_destroy_if_attached_to_line_items: Cannot delete variants once they are attached to line items.
353
+ spree/shipping_method:
354
+ attributes:
355
+ base:
356
+ cannot_destroy_if_attached_to_line_items: Cannot delete variants once they are attached to line items.
345
357
 
346
358
  devise:
347
359
  confirmations:
@@ -1,5 +1,5 @@
1
1
  module Spree
2
2
  def self.version
3
- "3.1.0.rc4"
3
+ "3.1.0"
4
4
  end
5
5
  end
@@ -124,7 +124,9 @@ module Spree
124
124
  end
125
125
 
126
126
  it "should create errors with invalid line items" do
127
- variant_2.destroy
127
+ # we cannot use .destroy here as it will be halted by
128
+ # :ensure_no_line_items callback
129
+ variant_2.really_destroy!
128
130
  subject.merge!(order_2)
129
131
  expect(order_1.errors.full_messages).not_to be_empty
130
132
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0.rc4
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Schofield
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-13 00:00:00.000000000 Z
11
+ date: 2016-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemerchant