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 +4 -4
- data/app/models/spree/credit_card.rb +4 -1
- data/app/models/spree/payment.rb +9 -10
- data/app/models/spree/product.rb +1 -1
- data/app/models/spree/product_property.rb +1 -0
- data/app/models/spree/promotion/actions/create_adjustment.rb +1 -1
- data/app/models/spree/variant.rb +1 -1
- data/db/migrate/20150314013438_add_missing_indexes_on_spree_tables.rb +9 -9
- data/db/migrate/20161014145148_add_created_at_to_variant.rb +2 -2
- data/lib/spree/core/version.rb +1 -1
- data/spec/models/spree/product_property_spec.rb +4 -0
- data/spec/models/spree/product_spec.rb +10 -0
- data/spec/models/spree/promotion/actions/create_adjustment_spec.rb +63 -0
- data/spec/models/spree/variant_spec.rb +9 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b61c878ac693ae6026b96d3c9fcd0274d64fd06
|
4
|
+
data.tar.gz: 88fe797219b35ec4ef662b070992078e1451fe4f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 }
|
data/app/models/spree/payment.rb
CHANGED
@@ -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
|
-
|
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!
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
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
|
data/app/models/spree/product.rb
CHANGED
@@ -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
|
data/app/models/spree/variant.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
class AddMissingIndexesOnSpreeTables < ActiveRecord::Migration[4.2]
|
2
2
|
def change
|
3
|
-
if
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
data/lib/spree/core/version.rb
CHANGED
@@ -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.
|
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:
|
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.
|
1180
|
+
rubygems_version: 2.6.10
|
1181
1181
|
signing_key:
|
1182
1182
|
specification_version: 4
|
1183
1183
|
summary: The bare bones necessary for Spree.
|