spree_core 3.2.0.rc2 → 3.2.0.rc3

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: 9df21e1febf6c28c6c7fbe5f29457f33e1662bf7
4
- data.tar.gz: 2b855fcc790eb5ed35eaf4c2ae34f023c1f38586
3
+ metadata.gz: 3b61c878ac693ae6026b96d3c9fcd0274d64fd06
4
+ data.tar.gz: 88fe797219b35ec4ef662b070992078e1451fe4f
5
5
  SHA512:
6
- metadata.gz: 9872b3128e4d27049be36b7a83dcea10c77b04cca603c8d2b052683c4989cd863f904c5b195c574e52d5ad7cc2c5b5d9f253e61cc3c31ffb6221f2c085888111
7
- data.tar.gz: efaa4550232d0d9bc5c7a4ccfd16e6b346e07fb2c276636e27d1e52875e9593369481f06eb1932dca4faa9fdaf52db49b9342d7357d1cd813eb73e1d454e8653
6
+ metadata.gz: 9953b341797318e180c7f33547c063a36f6c322c52f1faced2f833d3438ca25f11f098193a3bcabf825ccb80d4edbf4d1eb5efac350f712bfc60457a483e2aee
7
+ data.tar.gz: 10fbf84a91906b6554bec7ad3dfdc119ad1b0a666f0c97bb5a7008574d3ea60e2730b37543d6ab6916387fffde33ba462dbb2fdb988029ea28a2d5c6b079b7d5
@@ -1,5 +1,7 @@
1
1
  module Spree
2
2
  class CreditCard < Spree::Base
3
+ include ActiveMerchant::Billing::CreditCardMethods
4
+
3
5
  belongs_to :payment_method
4
6
  belongs_to :user, class_name: Spree.user_class, foreign_key: 'user_id'
5
7
  has_many :payments, as: :source
@@ -15,7 +17,8 @@ module Spree
15
17
  attr_reader :number
16
18
  attr_accessor :encrypted_data,
17
19
  :imported,
18
- :verification_value
20
+ :verification_value,
21
+ :manual_entry
19
22
 
20
23
  with_options if: :require_card_numbers?, on: :create do
21
24
  validates :month, :year, numericality: { only_integer: true }
@@ -29,13 +29,13 @@ module Spree
29
29
  after_save :create_payment_profile, if: :profiles_supported?
30
30
 
31
31
  # update the order totals, etc.
32
- after_save :update_order
32
+ set_callback :save, :after, :update_order, unless: -> { capture_on_dispatch }
33
33
 
34
34
  # invalidate previously entered payments
35
35
  after_create :invalidate_old_payments
36
36
  after_create :create_eligible_credit_event
37
37
 
38
- attr_accessor :source_attributes, :request_env
38
+ attr_accessor :source_attributes, :request_env, :capture_on_dispatch
39
39
 
40
40
  after_initialize :build_source
41
41
 
@@ -221,14 +221,13 @@ module Spree
221
221
 
222
222
  def split_uncaptured_amount
223
223
  if uncaptured_amount > 0
224
- order.payments.create! amount: uncaptured_amount,
225
- avs_response: avs_response,
226
- cvv_response_code: cvv_response_code,
227
- cvv_response_message: cvv_response_message,
228
- payment_method: payment_method,
229
- response_code: response_code,
230
- source: source,
231
- state: 'pending'
224
+ order.payments.create!(
225
+ amount: uncaptured_amount,
226
+ payment_method: payment_method,
227
+ source: source,
228
+ state: 'pending',
229
+ capture_on_dispatch: true
230
+ ).authorize!
232
231
  update_attributes(amount: captured_amount)
233
232
  end
234
233
  end
@@ -373,7 +373,7 @@ module Spree
373
373
  def ensure_no_line_items
374
374
  if line_items.any?
375
375
  errors.add(:base, Spree.t(:cannot_destroy_if_attached_to_line_items))
376
- return false
376
+ throw(:abort)
377
377
  end
378
378
  end
379
379
 
@@ -14,6 +14,7 @@ module Spree
14
14
  default_scope { order(:position) }
15
15
 
16
16
  self.whitelisted_ransackable_attributes = ['value']
17
+ self.whitelisted_ransackable_associations = ['property']
17
18
 
18
19
  # virtual attributes for use with AJAX completion stuff
19
20
  delegate :name, to: :property, prefix: true, allow_nil: true
@@ -13,7 +13,7 @@ module Spree
13
13
  end
14
14
 
15
15
  def compute_amount(order)
16
- [(order.item_total + order.ship_total), compute(order)].min * -1
16
+ [(order.item_total + order.ship_total - order.shipping_discount), compute(order)].min * -1
17
17
  end
18
18
  end
19
19
  end
@@ -267,7 +267,7 @@ module Spree
267
267
  def ensure_no_line_items
268
268
  if line_items.any?
269
269
  errors.add(:base, Spree.t(:cannot_destroy_if_attached_to_line_items))
270
- return false
270
+ throw(:abort)
271
271
  end
272
272
  end
273
273
 
@@ -1,6 +1,6 @@
1
1
  class AddMissingIndexesOnSpreeTables < ActiveRecord::Migration[4.2]
2
2
  def change
3
- if table_exists?(:spree_promotion_rules_users) && !index_exists?(:spree_promotion_rules_users,
3
+ if data_source_exists?(:spree_promotion_rules_users) && !index_exists?(:spree_promotion_rules_users,
4
4
  [:user_id, :promotion_rule_id],
5
5
  name: 'index_promotion_rules_users_on_user_id_and_promotion_rule_id')
6
6
  add_index :spree_promotion_rules_users,
@@ -8,7 +8,7 @@ class AddMissingIndexesOnSpreeTables < ActiveRecord::Migration[4.2]
8
8
  name: 'index_promotion_rules_users_on_user_id_and_promotion_rule_id'
9
9
  end
10
10
 
11
- if table_exists?(:spree_products_promotion_rules) && !index_exists?(:spree_products_promotion_rules,
11
+ if data_source_exists?(:spree_products_promotion_rules) && !index_exists?(:spree_products_promotion_rules,
12
12
  [:promotion_rule_id, :product_id],
13
13
  name: 'index_products_promotion_rules_on_promotion_rule_and_product')
14
14
  add_index :spree_products_promotion_rules,
@@ -24,15 +24,15 @@ class AddMissingIndexesOnSpreeTables < ActiveRecord::Migration[4.2]
24
24
  add_index :spree_orders, :store_id
25
25
  end
26
26
 
27
- if table_exists?(:spree_orders_promotions) && !index_exists?(:spree_orders_promotions, [:promotion_id, :order_id])
27
+ if data_source_exists?(:spree_orders_promotions) && !index_exists?(:spree_orders_promotions, [:promotion_id, :order_id])
28
28
  add_index :spree_orders_promotions, [:promotion_id, :order_id]
29
29
  end
30
30
 
31
- if table_exists?(:spree_properties_prototypes) && !index_exists?(:spree_properties_prototypes, :prototype_id)
31
+ if data_source_exists?(:spree_properties_prototypes) && !index_exists?(:spree_properties_prototypes, :prototype_id)
32
32
  add_index :spree_properties_prototypes, :prototype_id
33
33
  end
34
34
 
35
- if table_exists?(:spree_properties_prototypes) && !index_exists?(:spree_properties_prototypes,
35
+ if data_source_exists?(:spree_properties_prototypes) && !index_exists?(:spree_properties_prototypes,
36
36
  [:prototype_id, :property_id],
37
37
  name: 'index_properties_prototypes_on_prototype_and_property')
38
38
  add_index :spree_properties_prototypes,
@@ -40,15 +40,15 @@ class AddMissingIndexesOnSpreeTables < ActiveRecord::Migration[4.2]
40
40
  name: 'index_properties_prototypes_on_prototype_and_property'
41
41
  end
42
42
 
43
- if table_exists?(:spree_taxons_prototypes) && !index_exists?(:spree_taxons_prototypes, [:prototype_id, :taxon_id])
43
+ if data_source_exists?(:spree_taxons_prototypes) && !index_exists?(:spree_taxons_prototypes, [:prototype_id, :taxon_id])
44
44
  add_index :spree_taxons_prototypes, [:prototype_id, :taxon_id]
45
45
  end
46
46
 
47
- if table_exists?(:spree_option_types_prototypes) && !index_exists?(:spree_option_types_prototypes, :prototype_id)
47
+ if data_source_exists?(:spree_option_types_prototypes) && !index_exists?(:spree_option_types_prototypes, :prototype_id)
48
48
  add_index :spree_option_types_prototypes, :prototype_id
49
49
  end
50
50
 
51
- if table_exists?(:spree_option_types_prototypes) && !index_exists?(:spree_option_types_prototypes,
51
+ if data_source_exists?(:spree_option_types_prototypes) && !index_exists?(:spree_option_types_prototypes,
52
52
  [:prototype_id, :option_type_id],
53
53
  name: 'index_option_types_prototypes_on_prototype_and_option_type')
54
54
  add_index :spree_option_types_prototypes,
@@ -56,7 +56,7 @@ class AddMissingIndexesOnSpreeTables < ActiveRecord::Migration[4.2]
56
56
  name: 'index_option_types_prototypes_on_prototype_and_option_type'
57
57
  end
58
58
 
59
- if table_exists?(:spree_option_values_variants) && !index_exists?(:spree_option_values_variants,
59
+ if data_source_exists?(:spree_option_values_variants) && !index_exists?(:spree_option_values_variants,
60
60
  [:option_value_id, :variant_id],
61
61
  name: 'index_option_values_variants_on_option_value_and_variant')
62
62
  add_index :spree_option_values_variants,
@@ -2,7 +2,7 @@ class AddCreatedAtToVariant < ActiveRecord::Migration[5.0]
2
2
  def change
3
3
  add_column :spree_variants, :created_at, :datetime
4
4
  Spree::Variant.reset_column_information
5
- Spree::Variant.where.not(updated_at: nil).update_all('created_at = updated_at')
6
- Spree::Variant.where(updated_at: nil).update_all(created_at: Time.current, updated_at: Time.current)
5
+ Spree::Variant.unscoped.where.not(updated_at: nil).update_all('created_at = updated_at')
6
+ Spree::Variant.unscoped.where(updated_at: nil).update_all(created_at: Time.current, updated_at: Time.current)
7
7
  end
8
8
  end
@@ -1,5 +1,5 @@
1
1
  module Spree
2
2
  def self.version
3
- "3.2.0.rc2"
3
+ "3.2.0.rc3"
4
4
  end
5
5
  end
@@ -19,4 +19,8 @@ describe Spree::ProductProperty, type: :model do
19
19
  expect(@pp.property.name).to eq('Size')
20
20
  end
21
21
  end
22
+
23
+ context 'ransackable_associations' do
24
+ it { expect(Spree::ProductProperty.whitelisted_ransackable_associations).to include('property') }
25
+ end
22
26
  end
@@ -616,4 +616,14 @@ describe Spree::Product, type: :model do
616
616
  expect(product.category).to eql(taxonomy.taxons.first)
617
617
  end
618
618
  end
619
+
620
+ describe '#ensure_no_line_items' do
621
+ let(:product) { create(:product) }
622
+ let!(:line_item) { create(:line_item, variant: product.master) }
623
+
624
+ it 'should add error on product destroy' do
625
+ expect(product.destroy).to eq false
626
+ expect(product.errors[:base]).to include Spree.t(:cannot_destroy_if_attached_to_line_items)
627
+ end
628
+ end
619
629
  end
@@ -8,6 +8,69 @@ describe Spree::Promotion::Actions::CreateAdjustment, type: :model do
8
8
 
9
9
  it_behaves_like 'an adjustment source'
10
10
 
11
+ describe '#compute_amount' do
12
+ subject { described_class.new }
13
+
14
+ let(:shipping_discount) { 10 }
15
+ let(:order) do
16
+ double(:order, item_total: 30, ship_total: 10, shipping_discount: shipping_discount)
17
+ end
18
+
19
+ context 'when shipping_discount is applied' do
20
+ context 'and total is less than discount' do
21
+ it 'returns discount amount eq to total' do
22
+ allow(subject).to receive(:compute).with(order).and_return(100)
23
+
24
+ expect(subject.compute_amount(order)).to eq -30
25
+ end
26
+ end
27
+
28
+ context 'and total is equal to discount' do
29
+ it 'returns discount amount' do
30
+ allow(subject).to receive(:compute).with(order).and_return(30)
31
+
32
+ expect(subject.compute_amount(order)).to eq -30
33
+ end
34
+ end
35
+
36
+ context 'and total is greater than discount' do
37
+ it 'returns discount amount' do
38
+ allow(subject).to receive(:compute).with(order).and_return(10)
39
+
40
+ expect(subject.compute_amount(order)).to eq -10
41
+ end
42
+ end
43
+ end
44
+
45
+ context 'when shipping_discount is not applied' do
46
+ let(:shipping_discount) { 0 }
47
+
48
+ context 'and total is less than discount' do
49
+ it 'returns discount amount eq to total' do
50
+ allow(subject).to receive(:compute).with(order).and_return(100)
51
+
52
+ expect(subject.compute_amount(order)).to eq -40
53
+ end
54
+ end
55
+
56
+ context 'and total is equal to discount' do
57
+ it 'returns discount amount' do
58
+ allow(subject).to receive(:compute).with(order).and_return(40)
59
+
60
+ expect(subject.compute_amount(order)).to eq -40
61
+ end
62
+ end
63
+
64
+ context 'and total is greater than discount' do
65
+ it 'returns discount amount' do
66
+ allow(subject).to receive(:compute).with(order).and_return(10)
67
+
68
+ expect(subject.compute_amount(order)).to eq -10
69
+ end
70
+ end
71
+ end
72
+ end
73
+
11
74
  # From promotion spec:
12
75
  context "#perform" do
13
76
  before do
@@ -806,4 +806,13 @@ describe Spree::Variant, type: :model do
806
806
  expect(variant.updated_at).to_not be_nil
807
807
  end
808
808
  end
809
+
810
+ describe '#ensure_no_line_items' do
811
+ let!(:line_item) { create(:line_item, variant: variant) }
812
+
813
+ it 'should add error on product destroy' do
814
+ expect(variant.destroy).to eq false
815
+ expect(variant.errors[:base]).to include Spree.t(:cannot_destroy_if_attached_to_line_items)
816
+ end
817
+ end
809
818
  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.2.0.rc2
4
+ version: 3.2.0.rc3
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-12-20 00:00:00.000000000 Z
11
+ date: 2017-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemerchant
@@ -1177,7 +1177,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1177
1177
  version: 1.8.23
1178
1178
  requirements: []
1179
1179
  rubyforge_project:
1180
- rubygems_version: 2.5.1
1180
+ rubygems_version: 2.6.10
1181
1181
  signing_key:
1182
1182
  specification_version: 4
1183
1183
  summary: The bare bones necessary for Spree.