solidus_core 2.1.0.beta1 → 2.1.0.rc1

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.

Potentially problematic release.


This version of solidus_core might be problematic. Click here for more details.

Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/app/mailers/spree/base_mailer.rb +2 -7
  3. data/app/mailers/spree/carton_mailer.rb +3 -11
  4. data/app/mailers/spree/order_mailer.rb +3 -12
  5. data/app/models/concerns/spree/default_price.rb +2 -3
  6. data/app/models/concerns/spree/user_methods.rb +1 -1
  7. data/app/models/concerns/spree/user_payment_source.rb +0 -6
  8. data/app/models/spree/address.rb +0 -9
  9. data/app/models/spree/adjustment.rb +2 -63
  10. data/app/models/spree/app_configuration.rb +0 -22
  11. data/app/models/spree/calculator/flexi_rate.rb +7 -12
  12. data/app/models/spree/calculator/shipping/flat_percent_item_total.rb +1 -1
  13. data/app/models/spree/calculator/tiered_flat_rate.rb +3 -1
  14. data/app/models/spree/calculator/tiered_percent.rb +3 -1
  15. data/app/models/spree/country.rb +0 -7
  16. data/app/models/spree/gateway.rb +0 -9
  17. data/app/models/spree/order.rb +1 -15
  18. data/app/models/spree/order/checkout.rb +0 -41
  19. data/app/models/spree/payment.rb +0 -22
  20. data/app/models/spree/payment/processing.rb +1 -1
  21. data/app/models/spree/product/scopes.rb +1 -8
  22. data/app/models/spree/promotion/actions/create_adjustment.rb +6 -1
  23. data/app/models/spree/promotion/actions/create_item_adjustments.rb +6 -1
  24. data/app/models/spree/promotion/actions/create_quantity_adjustments.rb +6 -1
  25. data/app/models/spree/refund.rb +1 -1
  26. data/app/models/spree/store.rb +1 -2
  27. data/app/models/spree/zone.rb +12 -10
  28. data/lib/spree/core.rb +0 -10
  29. data/lib/spree/core/engine.rb +0 -2
  30. data/lib/spree/core/version.rb +1 -6
  31. data/spec/mailers/carton_mailer_spec.rb +0 -9
  32. data/spec/mailers/order_mailer_spec.rb +0 -14
  33. data/spec/models/spree/calculator/flexi_rate_spec.rb +132 -20
  34. data/spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb +4 -0
  35. data/spec/models/spree/calculator/tiered_flat_rate_spec.rb +41 -1
  36. data/spec/models/spree/calculator/tiered_percent_spec.rb +45 -1
  37. data/spec/models/spree/gateway/bogus_spec.rb +0 -7
  38. data/spec/models/spree/order/checkout_spec.rb +0 -119
  39. data/spec/models/spree/order/payment_spec.rb +19 -10
  40. data/spec/models/spree/order_spec.rb +0 -45
  41. data/spec/models/spree/payment_spec.rb +56 -63
  42. data/spec/models/spree/promotion/actions/create_item_adjustments_spec.rb +2 -2
  43. data/spec/models/spree/store_spec.rb +0 -8
  44. data/spec/models/spree/user_spec.rb +0 -7
  45. data/spec/models/spree/variant_spec.rb +0 -8
  46. metadata +2 -4
  47. data/config/initializers/spree_user.rb +0 -10
  48. data/lib/spree/core/routes.rb +0 -20
@@ -8,23 +8,67 @@ describe Spree::Calculator::TieredPercent, type: :model do
8
8
 
9
9
  describe "#valid?" do
10
10
  subject { calculator.valid? }
11
+
11
12
  context "when base percent is less than zero" do
12
13
  before { calculator.preferred_base_percent = -1 }
13
14
  it { is_expected.to be false }
14
15
  end
16
+
15
17
  context "when base percent is greater than 100" do
16
18
  before { calculator.preferred_base_percent = 110 }
17
19
  it { is_expected.to be false }
18
20
  end
21
+
19
22
  context "when tiers is a hash" do
20
- context "and one of the keys is not a positive number" do
23
+ context "and the key is not a positive number" do
21
24
  before { calculator.preferred_tiers = { "nope" => 20 } }
22
25
  it { is_expected.to be false }
23
26
  end
27
+
24
28
  context "and one of the values is not a percent" do
25
29
  before { calculator.preferred_tiers = { 10 => 110 } }
26
30
  it { is_expected.to be false }
27
31
  end
32
+
33
+ context "and the key is an integer" do
34
+ before { calculator.preferred_tiers = { 20 => 20 } }
35
+ it "converts successfully" do
36
+ is_expected.to be true
37
+ expect(calculator.preferred_tiers).to eq({ BigDecimal.new('20') => BigDecimal.new('20') })
38
+ end
39
+ end
40
+
41
+ context "and the key is a float" do
42
+ before { calculator.preferred_tiers = { 20.5 => 20.5 } }
43
+ it "converts successfully" do
44
+ is_expected.to be true
45
+ expect(calculator.preferred_tiers).to eq({ BigDecimal.new('20.5') => BigDecimal.new('20.5') })
46
+ end
47
+ end
48
+
49
+ context "and the key is a string number" do
50
+ before { calculator.preferred_tiers = { "20" => 20 } }
51
+ it "converts successfully" do
52
+ is_expected.to be true
53
+ expect(calculator.preferred_tiers).to eq({ BigDecimal.new('20') => BigDecimal.new('20') })
54
+ end
55
+ end
56
+
57
+ context "and the key is a numeric string with spaces" do
58
+ before { calculator.preferred_tiers = { " 20 " => 20 } }
59
+ it "converts successfully" do
60
+ is_expected.to be true
61
+ expect(calculator.preferred_tiers).to eq({ BigDecimal.new('20') => BigDecimal.new('20') })
62
+ end
63
+ end
64
+
65
+ context "and the key is a string number with decimals" do
66
+ before { calculator.preferred_tiers = { "20.5" => "20.5" } }
67
+ it "converts successfully" do
68
+ is_expected.to be true
69
+ expect(calculator.preferred_tiers).to eq({ BigDecimal.new('20.5') => BigDecimal.new('20.5') })
70
+ end
71
+ end
28
72
  end
29
73
  end
30
74
 
@@ -4,12 +4,5 @@ module Spree
4
4
  describe Gateway::Bogus, type: :model do
5
5
  let(:bogus) { create(:credit_card_payment_method) }
6
6
  let!(:cc) { create(:credit_card, payment_method: bogus, gateway_customer_profile_id: "BGS-RERTERT") }
7
-
8
- it "disable recurring contract by destroying payment source" do
9
- Spree::Deprecation.silence do
10
- bogus.disable_customer_profile(cc)
11
- end
12
- expect(cc.gateway_customer_profile_id).to be_nil
13
- end
14
7
  end
15
8
  end
@@ -775,123 +775,4 @@ describe Spree::Order, type: :model do
775
775
  expect(order.checkout_steps).to eq(%w(delivery confirm complete))
776
776
  end
777
777
  end
778
-
779
- describe 'update_from_params' do
780
- let(:order) { create(:order) }
781
- let(:permitted_params) { {} }
782
- let(:params) { {} }
783
-
784
- around do |example|
785
- Spree::Deprecation.silence { example.run }
786
- end
787
-
788
- it 'calls update_atributes without order params' do
789
- expect {
790
- order.update_from_params( params, permitted_params)
791
- }.not_to change{ order.attributes }
792
- end
793
-
794
- it 'runs the callbacks' do
795
- expect(order).to receive(:run_callbacks).with(:updating_from_params)
796
- order.update_from_params( params, permitted_params)
797
- end
798
-
799
- context "passing a credit card" do
800
- let(:permitted_params) do
801
- Spree::PermittedAttributes.checkout_attributes +
802
- [payments_attributes: Spree::PermittedAttributes.payment_attributes]
803
- end
804
-
805
- let(:credit_card) { create(:credit_card, user_id: order.user_id) }
806
-
807
- let(:params) do
808
- ActionController::Parameters.new(
809
- order: {
810
- payments_attributes: [
811
- {
812
- payment_method_id: 1,
813
- source_attributes: attributes_for(:credit_card)
814
- }
815
- ],
816
- existing_card: credit_card.id
817
- },
818
- cvc_confirm: "737"
819
- )
820
- end
821
-
822
- before { order.user_id = 3 }
823
-
824
- it "sets confirmation value when its available via :cvc_confirm" do
825
- allow(Spree::CreditCard).to receive_messages find: credit_card
826
- expect(credit_card).to receive(:verification_value=)
827
- order.update_from_params(params, permitted_params)
828
- end
829
-
830
- it "sets existing card as source for new payment" do
831
- expect {
832
- order.update_from_params(params, permitted_params)
833
- }.to change { Spree::Payment.count }.by(1)
834
-
835
- expect(Spree::Payment.last.source).to eq credit_card
836
- end
837
-
838
- it "sets request_env on payment" do
839
- request_env = { "USER_AGENT" => "Firefox" }
840
-
841
- order.update_from_params(params, permitted_params, request_env)
842
- expect(order.payments[0].request_env).to eq request_env
843
- end
844
-
845
- it "dont let users mess with others users cards" do
846
- credit_card.update_column :user_id, 5
847
-
848
- expect {
849
- order.update_from_params(params, permitted_params)
850
- }.to raise_error Spree::Core::GatewayError
851
- end
852
- end
853
-
854
- context 'has params' do
855
- let(:permitted_params) { [:good_param] }
856
- let(:params) { ActionController::Parameters.new(order: { bad_param: 'okay' } ) }
857
-
858
- it 'does not let through unpermitted attributes' do
859
- expect(order).to receive(:assign_attributes).with(ActionController::Parameters.new.permit!)
860
- order.update_from_params(params, permitted_params)
861
- end
862
-
863
- context 'has allowed params' do
864
- let(:params) { ActionController::Parameters.new(order: { good_param: 'okay' } ) }
865
-
866
- it 'accepts permitted attributes' do
867
- expect(order).to receive(:assign_attributes).with(ActionController::Parameters.new("good_param" => 'okay').permit!)
868
- order.update_from_params(params, permitted_params)
869
- end
870
- end
871
-
872
- context 'callback returns false' do
873
- before do
874
- expect(order).to receive(:update_params_payment_source).and_return false
875
- end
876
- it 'does not let through unpermitted attributes' do
877
- expect(order).not_to receive(:assign_attributes)
878
- expect(order).not_to receive(:save)
879
- ActiveSupport::Deprecation.silence do
880
- order.update_from_params(params, permitted_params)
881
- end
882
- end
883
- end
884
-
885
- context 'callback throws abort' do
886
- before do
887
- expect(order).to receive(:update_params_payment_source).and_throw :abort
888
- end
889
- it 'does not let through unpermitted attributes' do
890
- expect(order).not_to receive(:assign_attributes)
891
- expect(order).not_to receive(:save)
892
- order.update_from_params(params, permitted_params)
893
- end
894
- end
895
- end
896
- end
897
778
  end
@@ -77,11 +77,8 @@ module Spree
77
77
  }
78
78
  end
79
79
 
80
- # For the reason of this test, please see spree/spree_gateway#132
81
80
  it "keeps source attributes on assignment" do
82
- Spree::Deprecation.silence do
83
- order.update_attributes(payments_attributes: [payment_attributes])
84
- end
81
+ OrderUpdateAttributes.new(order, payments_attributes: [payment_attributes]).apply
85
82
  expect(order.unprocessed_payments.last.source.number).to be_present
86
83
  end
87
84
 
@@ -218,15 +215,27 @@ module Spree
218
215
  end
219
216
  end
220
217
 
221
- context "payment required?" do
218
+ context "payment_required?" do
219
+ before { order.total = total }
220
+
222
221
  context "total is zero" do
223
- before { allow(order).to receive_messages(total: 0) }
224
- it { expect(order.payment_required?).to be false }
222
+ let(:total) { 0 }
223
+ it { expect(order).not_to be_payment_required }
224
+ end
225
+
226
+ context "total is once cent" do
227
+ let(:total) { 1 }
228
+ it { expect(order).to be_payment_required }
229
+ end
230
+
231
+ context "total is once dollar" do
232
+ let(:total) { 1 }
233
+ it { expect(order).to be_payment_required }
225
234
  end
226
235
 
227
- context "total > zero" do
228
- before { allow(order).to receive_messages(total: 1) }
229
- it { expect(order.payment_required?).to be true }
236
+ context "total is huge" do
237
+ let(:total) { 2**32 }
238
+ it { expect(order).to be_payment_required }
230
239
  end
231
240
  end
232
241
  end
@@ -1049,51 +1049,6 @@ describe Spree::Order, type: :model do
1049
1049
  end
1050
1050
  end
1051
1051
 
1052
- describe "#fully_discounted?" do
1053
- let(:line_item) { Spree::LineItem.new(price: 10, quantity: 1) }
1054
- let(:shipment) { Spree::Shipment.new(cost: 10) }
1055
- let(:payment) { Spree::Payment.new(amount: 10) }
1056
-
1057
- around do |example|
1058
- Spree::Deprecation.silence do
1059
- example.run
1060
- end
1061
- end
1062
-
1063
- before do
1064
- allow(order).to receive(:line_items) { [line_item] }
1065
- allow(order).to receive(:shipments) { [shipment] }
1066
- allow(order).to receive(:payments) { [payment] }
1067
- end
1068
-
1069
- context "the order had no inventory-related cost" do
1070
- before do
1071
- # discount the cost of the line items
1072
- allow(order).to receive(:adjustment_total) { -5 }
1073
- allow(line_item).to receive(:adjustment_total) { -5 }
1074
-
1075
- # but leave some shipment payment amount
1076
- allow(shipment).to receive(:adjustment_total) { 0 }
1077
- end
1078
-
1079
- it { expect(order.fully_discounted?).to eq true }
1080
- end
1081
-
1082
- context "the order had inventory-related cost" do
1083
- before do
1084
- # partially discount the cost of the line item
1085
- allow(order).to receive(:adjustment_total) { 0 }
1086
- allow(line_item).to receive(:adjustment_total) { -5 }
1087
-
1088
- # and partially discount the cost of the shipment so the total
1089
- # discount matches the item total for test completeness
1090
- allow(shipment).to receive(:adjustment_total) { -5 }
1091
- end
1092
-
1093
- it { expect(order.fully_discounted?).to eq false }
1094
- end
1095
- end
1096
-
1097
1052
  context "store credit" do
1098
1053
  shared_examples "check total store credit from payments" do
1099
1054
  context "with valid payments" do
@@ -686,25 +686,22 @@ describe Spree::Payment, type: :model do
686
686
 
687
687
  context "with multiple payment attempts" do
688
688
  let(:attributes) { attributes_for(:credit_card) }
689
- around do |example|
690
- Spree::Deprecation.silence{ example.run }
691
- end
692
689
 
693
690
  it "should not try to create profiles on old failed payment attempts" do
694
691
  allow_any_instance_of(Spree::Payment).to receive(:payment_method) { gateway }
695
692
 
696
- order.payments.create!(
693
+ Spree::PaymentCreate.new(order, {
697
694
  source_attributes: attributes,
698
695
  payment_method: gateway,
699
696
  amount: 100
700
- )
697
+ }).build.save!
701
698
  expect(gateway).to receive(:create_profile).exactly :once
702
699
  expect(order.payments.count).to eq(1)
703
- order.payments.create!(
700
+ Spree::PaymentCreate.new(order, {
704
701
  source_attributes: attributes,
705
702
  payment_method: gateway,
706
703
  amount: 100
707
- )
704
+ }).build.save!
708
705
  end
709
706
  end
710
707
 
@@ -762,14 +759,8 @@ describe Spree::Payment, type: :model do
762
759
  end
763
760
  end
764
761
 
762
+ # This used to describe #apply_source_attributes, whose behaviour is now part of PaymentCreate
765
763
  describe "#apply_source_attributes" do
766
- # This method is deprecated
767
- around do |example|
768
- Spree::Deprecation.silence do
769
- example.run
770
- end
771
- end
772
-
773
764
  context 'with a new source' do
774
765
  let(:params) do
775
766
  {
@@ -785,14 +776,15 @@ describe Spree::Payment, type: :model do
785
776
  end
786
777
 
787
778
  it "should build the payment's source" do
788
- payment = Spree::Payment.new(params)
779
+ payment = Spree::PaymentCreate.new(order, params).build
789
780
  expect(payment).to be_valid
790
781
  expect(payment.source).not_to be_nil
791
782
  end
792
783
 
793
784
  it "assigns user and gateway to payment source" do
794
785
  order = create(:order)
795
- source = order.payments.new(params).source
786
+ payment = Spree::PaymentCreate.new(order, params).build
787
+ source = payment.source
796
788
 
797
789
  expect(source.user_id).to eq order.user_id
798
790
  expect(source.payment_method_id).to eq gateway.id
@@ -802,18 +794,12 @@ describe Spree::Payment, type: :model do
802
794
  params = { amount: 100, payment_method: gateway,
803
795
  source_attributes: { expiry: "1 / 12" } }
804
796
 
805
- payment = Spree::Payment.new(params)
797
+ payment = Spree::PaymentCreate.new(order, params).build
806
798
  expect(payment).not_to be_valid
807
799
  expect(payment.source).not_to be_nil
808
800
  expect(payment.source.error_on(:number).size).to eq(1)
809
801
  expect(payment.source.error_on(:verification_value).size).to eq(1)
810
802
  end
811
-
812
- it "does not build a new source when duplicating the model with source_attributes set" do
813
- payment = create(:payment)
814
- payment.source_attributes = params[:source_attributes]
815
- expect { payment.dup }.to_not change { payment.source }
816
- end
817
803
  end
818
804
 
819
805
  context 'with an existing credit card' do
@@ -830,58 +816,65 @@ describe Spree::Payment, type: :model do
830
816
  }
831
817
  end
832
818
 
833
- it 'sets the existing card as the source for the new payment' do
834
- expect {
835
- order.payments.create!(params)
836
- }.to change { Spree::Payment.count }.by(1)
819
+ describe "building a payment" do
820
+ subject do
821
+ Spree::PaymentCreate.new(order, params).build.save!
822
+ end
837
823
 
838
- expect(order.payments.last.source).to eq(credit_card)
839
- end
824
+ it 'sets the existing card as the source for the new payment' do
825
+ expect {
826
+ subject
827
+ }.to change { Spree::Payment.count }.by(1)
840
828
 
841
- it 'sets the payment payment_method to that of the credit card' do
842
- order.payments.create!(params)
843
- expect(order.payments.last.payment_method_id).to eq(credit_card.payment_method_id)
844
- end
829
+ expect(order.payments.last.source).to eq(credit_card)
830
+ end
845
831
 
846
- it 'sets the verification_value on the credit card' do
847
- payment = order.payments.create!(params)
848
- expect(payment.source.verification_value).to eq('321')
849
- end
832
+ it 'sets the payment payment_method to that of the credit card' do
833
+ subject
834
+ expect(order.payments.last.payment_method_id).to eq(credit_card.payment_method_id)
835
+ end
850
836
 
851
- it 'sets the request_env on the payment' do
852
- payment = order.payments.create!(params.merge(request_env: { 'USER_AGENT' => 'Firefox' }))
853
- expect(payment.request_env).to eq({ 'USER_AGENT' => 'Firefox' })
854
- end
837
+ it 'sets the verification_value on the credit card' do
838
+ subject
839
+ expect(order.payments.last.source.verification_value).to eq('321')
840
+ end
855
841
 
856
- context 'the credit card belongs to a different user' do
857
- let(:other_user) { create(:user) }
858
- before { credit_card.update!(user_id: other_user.id) }
859
- it 'errors' do
860
- expect { order.payments.create!(params) }.to raise_error(ActiveRecord::RecordNotFound)
842
+ it 'sets the request_env on the payment' do
843
+ payment = Spree::PaymentCreate.new(order, params.merge(request_env: { 'USER_AGENT' => 'Firefox' })).build
844
+ payment.save!
845
+ expect(payment.request_env).to eq({ 'USER_AGENT' => 'Firefox' })
861
846
  end
862
- end
863
847
 
864
- context 'the credit card has no user' do
865
- before { credit_card.update!(user_id: nil) }
866
- it 'errors' do
867
- expect { order.payments.create!(params) }.to raise_error(ActiveRecord::RecordNotFound)
848
+ context 'the credit card belongs to a different user' do
849
+ let(:other_user) { create(:user) }
850
+ before { credit_card.update!(user_id: other_user.id) }
851
+ it 'errors' do
852
+ expect { subject }.to raise_error(ActiveRecord::RecordNotFound)
853
+ end
868
854
  end
869
- end
870
855
 
871
- context 'the order has no user' do
872
- before { order.update_attributes!(user_id: nil) }
873
- it 'errors' do
874
- expect { order.payments.create!(params) }.to raise_error(ActiveRecord::RecordNotFound)
856
+ context 'the credit card has no user' do
857
+ before { credit_card.update!(user_id: nil) }
858
+ it 'errors' do
859
+ expect { subject }.to raise_error(ActiveRecord::RecordNotFound)
860
+ end
875
861
  end
876
- end
877
862
 
878
- context 'the order and the credit card have no user' do
879
- before do
880
- order.update_attributes!(user_id: nil)
881
- credit_card.update!(user_id: nil)
863
+ context 'the order has no user' do
864
+ before { order.update_attributes!(user_id: nil) }
865
+ it 'errors' do
866
+ expect { subject }.to raise_error(ActiveRecord::RecordNotFound)
867
+ end
882
868
  end
883
- it 'errors' do
884
- expect { order.payments.create!(params) }.to raise_error(ActiveRecord::RecordNotFound)
869
+
870
+ context 'the order and the credit card have no user' do
871
+ before do
872
+ order.update_attributes!(user_id: nil)
873
+ credit_card.update!(user_id: nil)
874
+ end
875
+ it 'errors' do
876
+ expect { subject }.to raise_error(ActiveRecord::RecordNotFound)
877
+ end
885
878
  end
886
879
  end
887
880
  end