solidus_core 1.3.2 → 1.4.0.beta1
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/README.md +15 -0
- data/app/helpers/spree/base_helper.rb +6 -2
- data/app/mailers/spree/base_mailer.rb +1 -1
- data/app/mailers/spree/carton_mailer.rb +1 -1
- data/app/mailers/spree/order_mailer.rb +2 -2
- data/app/mailers/spree/reimbursement_mailer.rb +7 -7
- data/app/mailers/spree/test_mailer.rb +3 -2
- data/app/models/concerns/spree/user_payment_source.rb +1 -1
- data/app/models/spree/address.rb +14 -4
- data/app/models/spree/adjustment.rb +11 -19
- data/app/models/spree/app_configuration.rb +23 -1
- data/app/models/spree/base.rb +9 -0
- data/app/models/spree/country.rb +2 -2
- data/app/models/spree/exchange.rb +1 -1
- data/app/models/spree/gateway.rb +1 -1
- data/app/models/spree/item_adjustments.rb +7 -0
- data/app/models/spree/line_item.rb +1 -13
- data/app/models/spree/order/checkout.rb +19 -16
- data/app/models/spree/order/payments.rb +0 -2
- data/app/models/spree/order.rb +7 -21
- data/app/models/spree/order_contents.rb +60 -4
- data/app/models/spree/order_merger.rb +2 -4
- data/app/models/spree/order_shipping.rb +1 -1
- data/app/models/spree/order_update_attributes.rb +0 -2
- data/app/models/spree/order_updater.rb +14 -11
- data/app/models/spree/payment.rb +2 -3
- data/app/models/spree/payment_create.rb +5 -2
- data/app/models/spree/payment_method/store_credit.rb +6 -5
- data/app/models/spree/product/scopes.rb +2 -1
- data/app/models/spree/product.rb +2 -5
- data/app/models/spree/promotion/actions/create_item_adjustments.rb +5 -3
- data/app/models/spree/promotion/actions/free_shipping.rb +1 -1
- data/app/models/spree/promotion/rules/option_value.rb +2 -3
- data/app/models/spree/promotion/rules/product.rb +9 -3
- data/app/models/spree/promotion/rules/taxon.rb +33 -7
- data/app/models/spree/promotion/rules/user.rb +2 -3
- data/app/models/spree/promotion.rb +16 -6
- data/app/models/spree/promotion_handler/coupon.rb +1 -1
- data/app/models/spree/shipment.rb +12 -16
- data/app/models/spree/stock/estimator.rb +1 -1
- data/app/models/spree/stock/package.rb +0 -1
- data/app/models/spree/stock_item.rb +2 -6
- data/app/models/spree/store.rb +2 -1
- data/app/models/spree/tax_rate.rb +1 -1
- data/app/models/spree/wallet/add_payment_sources_to_wallet.rb +29 -0
- data/app/models/spree/wallet/default_payment_builder.rb +26 -0
- data/app/views/spree/reimbursement_mailer/reimbursement_email.html.erb +46 -0
- data/app/views/spree/reimbursement_mailer/reimbursement_email.text.erb +1 -1
- data/app/views/spree/shared/_base_mailer_footer.html.erb +1 -20
- data/app/views/spree/shared/_base_mailer_header.html.erb +1 -31
- data/config/initializers/spree_user.rb +1 -1
- data/config/locales/en.yml +58 -34
- data/db/migrate/20130414000512_update_name_fields_on_spree_credit_cards.rb +1 -1
- data/db/migrate/20140601011216_set_shipment_total_for_users_upgrading.rb +15 -3
- data/db/migrate/20160527070401_rename_shipment_address_field.rb +7 -0
- data/db/migrate/20160616232103_remove_user_id_from_promotion_rules.rb +11 -0
- data/db/migrate/20160718205341_add_payment_id_index_to_spree_refunds.rb +5 -0
- data/db/migrate/20160718205859_add_reimbursement_id_index_to_spree_refunds.rb +5 -0
- data/lib/generators/spree/dummy/dummy_generator.rb +1 -1
- data/lib/generators/spree/dummy/templates/rails/database.yml +3 -1
- data/lib/generators/spree/dummy/templates/rails/test.rb +4 -2
- data/lib/generators/spree/install/install_generator.rb +6 -16
- data/lib/spree/core/controller_helpers/auth.rb +1 -1
- data/lib/spree/core/controller_helpers/common.rb +1 -1
- data/lib/spree/core/controller_helpers/order.rb +2 -2
- data/lib/spree/core/current_store.rb +5 -1
- data/lib/spree/core/delegate_belongs_to.rb +1 -1
- data/lib/spree/core/routes.rb +6 -32
- data/lib/spree/core/search/base.rb +2 -2
- data/lib/spree/core/stock_configuration.rb +6 -0
- data/lib/spree/core/version.rb +2 -2
- data/lib/spree/core.rb +2 -1
- data/lib/spree/i18n.rb +7 -0
- data/lib/spree/mailer_previews/carton_preview.rb +2 -1
- data/lib/spree/mailer_previews/order_preview.rb +8 -3
- data/lib/spree/mailer_previews/reimbursement_preview.rb +11 -0
- data/lib/spree/migrations.rb +13 -7
- data/lib/spree/permitted_attributes.rb +1 -1
- data/lib/spree/testing_support/capybara_ext.rb +6 -1
- data/lib/spree/testing_support/common_rake.rb +3 -7
- data/lib/spree/testing_support/controller_requests.rb +8 -0
- data/lib/spree/testing_support/factories/order_factory.rb +30 -8
- data/lib/spree/testing_support/factories/payment_factory.rb +1 -1
- data/lib/spree/testing_support/factories/product_factory.rb +6 -0
- data/lib/spree/testing_support/factories/reimbursement_factory.rb +1 -0
- data/lib/tasks/migrations/copy_shipped_shipments_to_cartons.rake +3 -1
- data/solidus_core.gemspec +3 -3
- data/spec/helpers/base_helper_spec.rb +18 -2
- data/spec/lib/i18n_spec.rb +4 -0
- data/spec/lib/spree/core/controller_helpers/order_spec.rb +16 -4
- data/spec/lib/spree/core/controller_helpers/payment_parameters_spec.rb +75 -59
- data/spec/lib/spree/core/delegate_belongs_to_spec.rb +1 -1
- data/spec/lib/spree/core/importer/order_spec.rb +4 -2
- data/spec/lib/spree/core/stock_configuration_spec.rb +17 -0
- data/spec/lib/spree/core/testing_support/factories/order_factory_spec.rb +195 -0
- data/spec/lib/spree/core/testing_support/factories/payment_factory_spec.rb +6 -0
- data/spec/lib/spree/core/testing_support/factories/reimbursement_factory_spec.rb +6 -0
- data/spec/lib/spree/migrations_spec.rb +3 -9
- data/spec/lib/tasks/migrations/copy_shipped_shipments_to_cartons_spec.rb +1 -1
- data/spec/mailers/carton_mailer_spec.rb +1 -1
- data/spec/mailers/order_mailer_spec.rb +2 -2
- data/spec/mailers/reimbursement_mailer_spec.rb +1 -1
- data/spec/models/spree/address_spec.rb +22 -0
- data/spec/models/spree/adjustment_spec.rb +0 -10
- data/spec/models/spree/carton_spec.rb +1 -1
- data/spec/models/spree/country_spec.rb +9 -1
- data/spec/models/spree/gateway/bogus_spec.rb +1 -1
- data/spec/models/spree/item_adjustments_spec.rb +33 -0
- data/spec/models/spree/line_item_spec.rb +2 -21
- data/spec/models/spree/order/checkout_spec.rb +32 -45
- data/spec/models/spree/order/payment_spec.rb +1 -16
- data/spec/models/spree/order_cancellations_spec.rb +8 -3
- data/spec/models/spree/order_contents_spec.rb +48 -0
- data/spec/models/spree/order_merger_spec.rb +8 -5
- data/spec/models/spree/order_shipping_spec.rb +3 -4
- data/spec/models/spree/order_spec.rb +23 -59
- data/spec/models/spree/order_update_attributes_spec.rb +1 -5
- data/spec/models/spree/order_updater_spec.rb +39 -11
- data/spec/models/spree/payment_create_spec.rb +61 -0
- data/spec/models/spree/payment_method/store_credit_spec.rb +23 -10
- data/spec/models/spree/payment_spec.rb +17 -4
- data/spec/models/spree/product_spec.rb +1 -1
- data/spec/models/spree/promotion/actions/create_item_adjustments_spec.rb +8 -13
- data/spec/models/spree/promotion/rules/product_spec.rb +33 -0
- data/spec/models/spree/promotion/rules/taxon_spec.rb +52 -8
- data/spec/models/spree/promotion_spec.rb +18 -12
- data/spec/models/spree/return_authorization_spec.rb +0 -16
- data/spec/models/spree/shipment_spec.rb +57 -36
- data/spec/models/spree/stock/coordinator_spec.rb +0 -5
- data/spec/models/spree/stock/package_spec.rb +0 -1
- data/spec/models/spree/stock_item_spec.rb +35 -145
- data/spec/models/spree/store_spec.rb +24 -10
- data/spec/models/spree/tax_rate_spec.rb +2 -2
- data/spec/models/spree/user_spec.rb +1 -1
- data/spec/models/spree/validations/db_maximum_length_validator_spec.rb +20 -12
- data/spec/support/concerns/working_factories.rb +4 -0
- metadata +30 -10
- data/config/routes.rb +0 -1
|
@@ -200,6 +200,7 @@ module Spree
|
|
|
200
200
|
order_promos[promo_sequence[0]].activate order: order
|
|
201
201
|
order_promos[promo_sequence[1]].activate order: order
|
|
202
202
|
|
|
203
|
+
order.update!
|
|
203
204
|
order.reload
|
|
204
205
|
expect(order.all_adjustments.count).to eq(2), "Expected two adjustments (using sequence #{promo_sequence})"
|
|
205
206
|
expect(order.all_adjustments.eligible.count).to eq(1), "Expected one elegible adjustment (using sequence #{promo_sequence})"
|
|
@@ -267,5 +268,37 @@ module Spree
|
|
|
267
268
|
expect(line_item.adjustments.promotion.eligible.first.amount.to_i).to eq(-200)
|
|
268
269
|
end
|
|
269
270
|
end
|
|
271
|
+
|
|
272
|
+
context "multiple updates" do
|
|
273
|
+
let(:adjustment) { create(:tax_adjustment, amount: -10) }
|
|
274
|
+
let(:item) { adjustment.adjustable }
|
|
275
|
+
|
|
276
|
+
def update
|
|
277
|
+
described_class.new(item).update
|
|
278
|
+
end
|
|
279
|
+
|
|
280
|
+
# "fresh" record from the DB
|
|
281
|
+
def db_record
|
|
282
|
+
Spree::LineItem.find(item.id)
|
|
283
|
+
end
|
|
284
|
+
|
|
285
|
+
it "persists each change" do
|
|
286
|
+
adjustment.source.update_attributes!(amount: 0.1)
|
|
287
|
+
update
|
|
288
|
+
expect(item).not_to be_changed
|
|
289
|
+
expect(db_record).to have_attributes(adjustment_total: 1)
|
|
290
|
+
|
|
291
|
+
adjustment.source.update_attributes!(amount: 0.20)
|
|
292
|
+
item.reload
|
|
293
|
+
update
|
|
294
|
+
expect(item).not_to be_changed
|
|
295
|
+
expect(db_record).to have_attributes(adjustment_total: 2)
|
|
296
|
+
|
|
297
|
+
adjustment.source.update_attributes!(amount: 0.10)
|
|
298
|
+
update
|
|
299
|
+
expect(item).not_to be_changed
|
|
300
|
+
expect(db_record).to have_attributes(adjustment_total: 1)
|
|
301
|
+
end
|
|
302
|
+
end
|
|
270
303
|
end
|
|
271
304
|
end
|
|
@@ -26,25 +26,6 @@ describe Spree::LineItem, type: :model do
|
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
context "#save" do
|
|
29
|
-
context "line item changes" do
|
|
30
|
-
before do
|
|
31
|
-
line_item.quantity = line_item.quantity + 1
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
it "triggers adjustment total recalculation" do
|
|
35
|
-
expect(line_item).to receive(:update_tax_charge) # Regression test for https://github.com/spree/spree/issues/4671
|
|
36
|
-
expect(line_item).to receive(:recalculate_adjustments)
|
|
37
|
-
line_item.save
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
context "line item does not change" do
|
|
42
|
-
it "does not trigger adjustment total recalculation" do
|
|
43
|
-
expect(line_item).not_to receive(:recalculate_adjustments)
|
|
44
|
-
line_item.save
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
|
|
48
29
|
context "target_shipment is provided" do
|
|
49
30
|
it "verifies inventory" do
|
|
50
31
|
line_item.target_shipment = Spree::Shipment.new
|
|
@@ -135,13 +116,13 @@ describe Spree::LineItem, type: :model do
|
|
|
135
116
|
end
|
|
136
117
|
|
|
137
118
|
it 'should display a deprecation warning' do
|
|
138
|
-
expect(
|
|
119
|
+
expect(Spree::Deprecation).to receive(:warn)
|
|
139
120
|
Spree::LineItem.new(variant: variant, order: order)
|
|
140
121
|
end
|
|
141
122
|
|
|
142
123
|
it 'should run the user-defined copy_price method' do
|
|
143
124
|
expect_any_instance_of(Spree::LineItem).to receive(:copy_price).and_call_original
|
|
144
|
-
|
|
125
|
+
Spree::Deprecation.silence do
|
|
145
126
|
Spree::LineItem.new(variant: variant, order: order)
|
|
146
127
|
end
|
|
147
128
|
end
|
|
@@ -162,12 +162,14 @@ describe Spree::Order, type: :model do
|
|
|
162
162
|
end
|
|
163
163
|
|
|
164
164
|
context "from address" do
|
|
165
|
-
let(:ship_address) {
|
|
165
|
+
let(:ship_address) { create(:ship_address) }
|
|
166
|
+
let!(:line_item) { create(:line_item, order: order, price: 10) }
|
|
167
|
+
let!(:shipping_method) { create(:shipping_method) }
|
|
166
168
|
|
|
167
169
|
before do
|
|
170
|
+
order.line_items.reload
|
|
168
171
|
order.state = 'address'
|
|
169
172
|
order.ship_address = ship_address
|
|
170
|
-
FactoryGirl.create(:shipment, order: order, cost: 10)
|
|
171
173
|
order.email = "user@example.com"
|
|
172
174
|
order.save!
|
|
173
175
|
end
|
|
@@ -180,31 +182,24 @@ describe Spree::Order, type: :model do
|
|
|
180
182
|
end
|
|
181
183
|
end
|
|
182
184
|
|
|
183
|
-
it "updates totals" do
|
|
184
|
-
|
|
185
|
-
order.line_items << line_item
|
|
186
|
-
tax_rate = create(:tax_rate, tax_category: line_item.tax_category, amount: 0.05)
|
|
187
|
-
allow(Spree::TaxRate).to receive_messages match: [tax_rate]
|
|
188
|
-
FactoryGirl.create(:tax_adjustment, adjustable: line_item, source: tax_rate, order: order)
|
|
189
|
-
order.email = "user@example.com"
|
|
185
|
+
it "recalculates tax and updates totals" do
|
|
186
|
+
create(:tax_rate, tax_category: line_item.tax_category, amount: 0.05, zone: order.tax_zone)
|
|
190
187
|
order.next!
|
|
191
|
-
expect(order
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
188
|
+
expect(order).to have_attributes(
|
|
189
|
+
adjustment_total: 0.5,
|
|
190
|
+
additional_tax_total: 0.5,
|
|
191
|
+
included_tax_total: 0,
|
|
192
|
+
total: 20.5
|
|
193
|
+
)
|
|
195
194
|
end
|
|
196
195
|
|
|
197
196
|
it "transitions to delivery" do
|
|
198
|
-
allow(order).to receive_messages(ensure_available_shipping_rates: true)
|
|
199
197
|
order.next!
|
|
200
198
|
assert_state_changed(order, 'address', 'delivery')
|
|
201
199
|
expect(order.state).to eq("delivery")
|
|
202
200
|
end
|
|
203
201
|
|
|
204
202
|
it "does not call persist_order_address if there is no address on the order" do
|
|
205
|
-
# otherwise, it will crash
|
|
206
|
-
allow(order).to receive_messages(ensure_available_shipping_rates: true)
|
|
207
|
-
|
|
208
203
|
order.user = FactoryGirl.create(:user)
|
|
209
204
|
order.save!
|
|
210
205
|
|
|
@@ -213,8 +208,6 @@ describe Spree::Order, type: :model do
|
|
|
213
208
|
end
|
|
214
209
|
|
|
215
210
|
it "calls persist_order_address on the order's user" do
|
|
216
|
-
allow(order).to receive_messages(ensure_available_shipping_rates: true)
|
|
217
|
-
|
|
218
211
|
order.user = FactoryGirl.create(:user)
|
|
219
212
|
order.ship_address = FactoryGirl.create(:address)
|
|
220
213
|
order.bill_address = FactoryGirl.create(:address)
|
|
@@ -225,8 +218,6 @@ describe Spree::Order, type: :model do
|
|
|
225
218
|
end
|
|
226
219
|
|
|
227
220
|
it "does not call persist_order_address on the order's user for a temporary address" do
|
|
228
|
-
allow(order).to receive_messages(ensure_available_shipping_rates: true)
|
|
229
|
-
|
|
230
221
|
order.user = FactoryGirl.create(:user)
|
|
231
222
|
order.temporary_address = true
|
|
232
223
|
order.save!
|
|
@@ -506,6 +497,23 @@ describe Spree::Order, type: :model do
|
|
|
506
497
|
end
|
|
507
498
|
end
|
|
508
499
|
|
|
500
|
+
context "with a payment in the pending state" do
|
|
501
|
+
let(:order) { create :order_ready_to_complete }
|
|
502
|
+
let(:payment) { create :payment, state: "pending", amount: order.total }
|
|
503
|
+
|
|
504
|
+
before do
|
|
505
|
+
order.payments = [payment]
|
|
506
|
+
order.save!
|
|
507
|
+
end
|
|
508
|
+
|
|
509
|
+
it "allows the order to complete" do
|
|
510
|
+
expect { order.complete! }.
|
|
511
|
+
to change { order.state }.
|
|
512
|
+
from("confirm").
|
|
513
|
+
to("complete")
|
|
514
|
+
end
|
|
515
|
+
end
|
|
516
|
+
|
|
509
517
|
context "exchange order completion" do
|
|
510
518
|
before do
|
|
511
519
|
order.email = 'spree@example.org'
|
|
@@ -628,27 +636,6 @@ describe Spree::Order, type: :model do
|
|
|
628
636
|
end
|
|
629
637
|
end
|
|
630
638
|
|
|
631
|
-
context "subclassed order" do
|
|
632
|
-
# This causes another test above to fail, but fixing this test should make
|
|
633
|
-
# the other test pass
|
|
634
|
-
class SubclassedOrder < Spree::Order
|
|
635
|
-
checkout_flow do
|
|
636
|
-
go_to_state :payment
|
|
637
|
-
go_to_state :complete
|
|
638
|
-
end
|
|
639
|
-
end
|
|
640
|
-
|
|
641
|
-
skip "should only call default transitions once when checkout_flow is redefined" do
|
|
642
|
-
order = SubclassedOrder.new
|
|
643
|
-
allow(order).to receive_messages payment_required?: true
|
|
644
|
-
expect(order).to receive(:process_payments!).once
|
|
645
|
-
order.state = "payment"
|
|
646
|
-
order.next!
|
|
647
|
-
assert_state_changed(order, 'payment', 'complete')
|
|
648
|
-
expect(order.state).to eq("complete")
|
|
649
|
-
end
|
|
650
|
-
end
|
|
651
|
-
|
|
652
639
|
context "re-define checkout flow" do
|
|
653
640
|
before do
|
|
654
641
|
@old_checkout_flow = Spree::Order.checkout_flow
|
|
@@ -794,7 +781,7 @@ describe Spree::Order, type: :model do
|
|
|
794
781
|
let(:params) { {} }
|
|
795
782
|
|
|
796
783
|
around do |example|
|
|
797
|
-
|
|
784
|
+
Spree::Deprecation.silence { example.run }
|
|
798
785
|
end
|
|
799
786
|
|
|
800
787
|
it 'calls update_atributes without order params' do
|
|
@@ -868,7 +855,7 @@ describe Spree::Order, type: :model do
|
|
|
868
855
|
let(:params) { ActionController::Parameters.new(order: { bad_param: 'okay' } ) }
|
|
869
856
|
|
|
870
857
|
it 'does not let through unpermitted attributes' do
|
|
871
|
-
expect(order).to receive(:assign_attributes).with(
|
|
858
|
+
expect(order).to receive(:assign_attributes).with(ActionController::Parameters.new.permit!)
|
|
872
859
|
order.update_from_params(params, permitted_params)
|
|
873
860
|
end
|
|
874
861
|
|
|
@@ -876,7 +863,7 @@ describe Spree::Order, type: :model do
|
|
|
876
863
|
let(:params) { ActionController::Parameters.new(order: { good_param: 'okay' } ) }
|
|
877
864
|
|
|
878
865
|
it 'accepts permitted attributes' do
|
|
879
|
-
expect(order).to receive(:assign_attributes).with(
|
|
866
|
+
expect(order).to receive(:assign_attributes).with(ActionController::Parameters.new("good_param" => 'okay').permit!)
|
|
880
867
|
order.update_from_params(params, permitted_params)
|
|
881
868
|
end
|
|
882
869
|
end
|
|
@@ -45,7 +45,6 @@ module Spree
|
|
|
45
45
|
it "does not use failed payments" do
|
|
46
46
|
payment_1 = create(:payment, amount: 50)
|
|
47
47
|
payment_2 = create(:payment, amount: 50, state: 'failed')
|
|
48
|
-
allow(order).to receive(:pending_payments).and_return([payment_1])
|
|
49
48
|
|
|
50
49
|
expect(payment_2).not_to receive(:process!)
|
|
51
50
|
|
|
@@ -53,13 +52,6 @@ module Spree
|
|
|
53
52
|
end
|
|
54
53
|
end
|
|
55
54
|
|
|
56
|
-
context "with no payments" do
|
|
57
|
-
it "should return falsy" do
|
|
58
|
-
expect(order).to receive_messages total: 100
|
|
59
|
-
expect(order.process_payments!).to be_falsy
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
|
|
63
55
|
context "with payments completed" do
|
|
64
56
|
it "should not fail transitioning to complete when paid" do
|
|
65
57
|
expect(order).to receive_messages total: 100, payment_total: 100
|
|
@@ -84,7 +76,7 @@ module Spree
|
|
|
84
76
|
|
|
85
77
|
# For the reason of this test, please see spree/spree_gateway#132
|
|
86
78
|
it "keeps source attributes on assignment" do
|
|
87
|
-
|
|
79
|
+
Spree::Deprecation.silence do
|
|
88
80
|
order.update_attributes(payments_attributes: [payment_attributes])
|
|
89
81
|
end
|
|
90
82
|
expect(order.unprocessed_payments.last.source.number).to be_present
|
|
@@ -118,13 +110,6 @@ module Spree
|
|
|
118
110
|
expect(order.process_payments!).to be_truthy
|
|
119
111
|
end
|
|
120
112
|
|
|
121
|
-
# Regression spec for https://github.com/spree/spree/issues/5436
|
|
122
|
-
it 'should raise an error if there are no payments to process' do
|
|
123
|
-
allow(order).to receive_messages unprocessed_payments: []
|
|
124
|
-
expect(payment).to_not receive(:process!)
|
|
125
|
-
expect(order.process_payments!).to be_falsey
|
|
126
|
-
end
|
|
127
|
-
|
|
128
113
|
context "when a payment raises a GatewayError" do
|
|
129
114
|
before { expect(payment).to receive(:process!).and_raise(Spree::Core::GatewayError) }
|
|
130
115
|
|
|
@@ -131,13 +131,12 @@ describe Spree::OrderCancellations do
|
|
|
131
131
|
|
|
132
132
|
context "when rounding is required" do
|
|
133
133
|
let(:order) { create(:order_ready_to_ship, line_items_count: 1, line_items_price: 0.83) }
|
|
134
|
-
let(:line_item) { order.line_items.first }
|
|
134
|
+
let(:line_item) { order.line_items.to_a.first }
|
|
135
135
|
let(:inventory_unit_1) { line_item.inventory_units[0] }
|
|
136
136
|
let(:inventory_unit_2) { line_item.inventory_units[1] }
|
|
137
137
|
|
|
138
138
|
before do
|
|
139
139
|
order.contents.add(line_item.variant)
|
|
140
|
-
line_item.reload
|
|
141
140
|
|
|
142
141
|
# make the total $1.67 so it divides unevenly
|
|
143
142
|
Spree::Adjustment.tax.create!(
|
|
@@ -153,7 +152,13 @@ describe Spree::OrderCancellations do
|
|
|
153
152
|
it "generates the correct total amount" do
|
|
154
153
|
order.cancellations.short_ship([inventory_unit_1])
|
|
155
154
|
order.cancellations.short_ship([inventory_unit_2])
|
|
156
|
-
expect(line_item.adjustments.
|
|
155
|
+
expect(line_item.adjustments.map(&:amount)).to match_array(
|
|
156
|
+
[
|
|
157
|
+
0.01, # tax adjustment
|
|
158
|
+
-0.84, # short ship 1
|
|
159
|
+
-0.83, # short ship 2
|
|
160
|
+
]
|
|
161
|
+
)
|
|
157
162
|
expect(line_item.total).to eq 0
|
|
158
163
|
end
|
|
159
164
|
end
|
|
@@ -224,6 +224,54 @@ describe Spree::OrderContents, type: :model do
|
|
|
224
224
|
}.to change { subject.order.total }
|
|
225
225
|
end
|
|
226
226
|
|
|
227
|
+
context "given an order with existing addresses" do
|
|
228
|
+
let(:default_address) { create :address, state_code: "NY", zipcode: "17402" }
|
|
229
|
+
let(:order_with_address ) { create :order, ship_address: default_address, bill_address: default_address }
|
|
230
|
+
|
|
231
|
+
subject { described_class.new(order_with_address) }
|
|
232
|
+
|
|
233
|
+
context "when an address in a potentially different tax zone is supplied " do
|
|
234
|
+
let(:updated_address) { build :address, state_code: "AL", zipcode: "64092" }
|
|
235
|
+
|
|
236
|
+
let(:params) do
|
|
237
|
+
{ ship_address_attributes: updated_address.value_attributes, bill_address_attributes: updated_address.value_attributes }
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
it "updates tax adjustments" do
|
|
241
|
+
expect(subject.order).to receive(:create_tax_charge!)
|
|
242
|
+
subject.update_cart params
|
|
243
|
+
end
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
context "when an address in potentially the same tax zone is supplied" do
|
|
247
|
+
let(:updated_address) { build :address, state_code: "NY", zipcode: "17402", firstname: 'Robert' }
|
|
248
|
+
|
|
249
|
+
let(:params) do
|
|
250
|
+
{ ship_address_attributes: updated_address.value_attributes, bill_address_attributes: updated_address.value_attributes }
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
it "does not updates tax adjustments" do
|
|
254
|
+
expect(subject.order).not_to receive(:create_tax_charge!)
|
|
255
|
+
subject.update_cart params
|
|
256
|
+
end
|
|
257
|
+
end
|
|
258
|
+
end
|
|
259
|
+
|
|
260
|
+
context "given an order with no existing addresses" do
|
|
261
|
+
context "when an address is supplied" do
|
|
262
|
+
let(:updated_address) { build :address, state_code: "CA", zipcode: "14902" }
|
|
263
|
+
|
|
264
|
+
let(:params) do
|
|
265
|
+
{ ship_address_attributes: updated_address.attributes, bill_address_attributes: updated_address.value_attributes }
|
|
266
|
+
end
|
|
267
|
+
|
|
268
|
+
it "does not updates tax adjustments" do
|
|
269
|
+
expect(subject.order).not_to receive(:create_tax_charge!)
|
|
270
|
+
subject.update_cart params
|
|
271
|
+
end
|
|
272
|
+
end
|
|
273
|
+
end
|
|
274
|
+
|
|
227
275
|
context "submits item quantity 0" do
|
|
228
276
|
let(:params) do
|
|
229
277
|
{ line_items_attributes: {
|
|
@@ -104,15 +104,17 @@ module Spree
|
|
|
104
104
|
|
|
105
105
|
specify do
|
|
106
106
|
subject.merge!(order_2)
|
|
107
|
-
|
|
108
|
-
|
|
107
|
+
|
|
108
|
+
# Both in memory and in DB line items
|
|
109
|
+
expect(order_1.line_items.length).to eq(2)
|
|
110
|
+
expect(order_1.line_items.count).to eq(2)
|
|
109
111
|
|
|
110
112
|
expect(order_1.item_count).to eq 2
|
|
111
|
-
expect(order_1.item_total).to eq line_items.map(&:amount).sum
|
|
113
|
+
expect(order_1.item_total).to eq order_1.line_items.map(&:amount).sum
|
|
112
114
|
|
|
113
115
|
# No guarantee on ordering of line items, so we do this:
|
|
114
|
-
expect(line_items.pluck(:quantity)).to match_array([1, 1])
|
|
115
|
-
expect(line_items.pluck(:variant_id)).to match_array([variant.id, variant_2.id])
|
|
116
|
+
expect(order_1.line_items.pluck(:quantity)).to match_array([1, 1])
|
|
117
|
+
expect(order_1.line_items.pluck(:variant_id)).to match_array([variant.id, variant_2.id])
|
|
116
118
|
end
|
|
117
119
|
end
|
|
118
120
|
|
|
@@ -126,6 +128,7 @@ module Spree
|
|
|
126
128
|
|
|
127
129
|
it "should create errors with invalid line items" do
|
|
128
130
|
variant_2.really_destroy!
|
|
131
|
+
order_2.line_items.to_a.first.reload # so that it registers as invalid
|
|
129
132
|
subject.merge!(order_2)
|
|
130
133
|
expect(order_1.errors.full_messages).not_to be_empty
|
|
131
134
|
end
|
|
@@ -57,7 +57,7 @@ describe Spree::OrderShipping do
|
|
|
57
57
|
let(:shipment) { order.shipments.to_a.first }
|
|
58
58
|
let(:inventory_units) { shipment.inventory_units }
|
|
59
59
|
let(:stock_location) { shipment.stock_location }
|
|
60
|
-
let(:address) {
|
|
60
|
+
let(:address) { order.ship_address }
|
|
61
61
|
let(:shipping_method) { shipment.shipping_method }
|
|
62
62
|
|
|
63
63
|
it_behaves_like 'shipment shipping'
|
|
@@ -190,7 +190,7 @@ describe Spree::OrderShipping do
|
|
|
190
190
|
order.shipping.ship(
|
|
191
191
|
inventory_units: shipped_inventory,
|
|
192
192
|
stock_location: shipment.stock_location,
|
|
193
|
-
address:
|
|
193
|
+
address: order.ship_address,
|
|
194
194
|
shipping_method: shipment.shipping_method
|
|
195
195
|
)
|
|
196
196
|
end
|
|
@@ -223,8 +223,7 @@ describe Spree::OrderShipping do
|
|
|
223
223
|
let(:shipment) do
|
|
224
224
|
FactoryGirl.create(
|
|
225
225
|
:shipment,
|
|
226
|
-
order: order
|
|
227
|
-
address: FactoryGirl.create(:address)
|
|
226
|
+
order: order
|
|
228
227
|
)
|
|
229
228
|
end
|
|
230
229
|
|
|
@@ -40,6 +40,28 @@ describe Spree::Order, type: :model do
|
|
|
40
40
|
end
|
|
41
41
|
end
|
|
42
42
|
|
|
43
|
+
describe "#cancel!" do
|
|
44
|
+
context "with captured store credit" do
|
|
45
|
+
let!(:store_credit_payment_method) { create(:store_credit_payment_method) }
|
|
46
|
+
let(:order_total) { 500.00 }
|
|
47
|
+
let(:store_credit) { create(:store_credit, amount: order_total) }
|
|
48
|
+
let(:order) { create(:order_with_line_items, user: store_credit.user, line_items_price: order_total) }
|
|
49
|
+
|
|
50
|
+
before do
|
|
51
|
+
order.add_store_credit_payments
|
|
52
|
+
order.finalize!
|
|
53
|
+
order.capture_payments!
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
subject { order.cancel! }
|
|
57
|
+
|
|
58
|
+
it "cancels the order" do
|
|
59
|
+
expect{ subject }.to change{ order.can_cancel? }.from(true).to(false)
|
|
60
|
+
expect(order).to be_canceled
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
43
65
|
context "#canceled_by" do
|
|
44
66
|
let(:admin_user) { create :admin_user }
|
|
45
67
|
let(:order) { create :order }
|
|
@@ -1021,7 +1043,7 @@ describe Spree::Order, type: :model do
|
|
|
1021
1043
|
let(:payment) { Spree::Payment.new(amount: 10) }
|
|
1022
1044
|
|
|
1023
1045
|
around do |example|
|
|
1024
|
-
|
|
1046
|
+
Spree::Deprecation.silence do
|
|
1025
1047
|
example.run
|
|
1026
1048
|
end
|
|
1027
1049
|
end
|
|
@@ -1114,12 +1136,6 @@ describe Spree::Order, type: :model do
|
|
|
1114
1136
|
end
|
|
1115
1137
|
end
|
|
1116
1138
|
|
|
1117
|
-
context "there are no other payments" do
|
|
1118
|
-
it "adds an error to the model" do
|
|
1119
|
-
expect(subject).to be false
|
|
1120
|
-
expect(order.errors.full_messages).to include(Spree.t("store_credit.errors.unable_to_fund"))
|
|
1121
|
-
end
|
|
1122
|
-
end
|
|
1123
1139
|
end
|
|
1124
1140
|
|
|
1125
1141
|
context "there is enough store credit to pay for the entire order" do
|
|
@@ -1476,56 +1492,4 @@ describe Spree::Order, type: :model do
|
|
|
1476
1492
|
end
|
|
1477
1493
|
end
|
|
1478
1494
|
end
|
|
1479
|
-
|
|
1480
|
-
describe "#validate_payments_attributes" do
|
|
1481
|
-
let(:attributes) { [ActionController::Parameters.new(payment_method_id: payment_method.id)] }
|
|
1482
|
-
subject do
|
|
1483
|
-
order.validate_payments_attributes(attributes)
|
|
1484
|
-
end
|
|
1485
|
-
|
|
1486
|
-
context "with empty array" do
|
|
1487
|
-
let(:attributes) { [] }
|
|
1488
|
-
it "doesn't error" do
|
|
1489
|
-
subject
|
|
1490
|
-
end
|
|
1491
|
-
end
|
|
1492
|
-
|
|
1493
|
-
context "with no payment method specified" do
|
|
1494
|
-
let(:attributes) { [ActionController::Parameters.new({})] }
|
|
1495
|
-
it "doesn't error" do
|
|
1496
|
-
subject
|
|
1497
|
-
end
|
|
1498
|
-
end
|
|
1499
|
-
|
|
1500
|
-
context "with valid payment method" do
|
|
1501
|
-
let(:payment_method) { create(:check_payment_method) }
|
|
1502
|
-
it "doesn't error" do
|
|
1503
|
-
subject
|
|
1504
|
-
end
|
|
1505
|
-
end
|
|
1506
|
-
|
|
1507
|
-
context "with inactive payment method" do
|
|
1508
|
-
let(:payment_method) { create(:check_payment_method, active: false) }
|
|
1509
|
-
|
|
1510
|
-
it "raises RecordNotFound" do
|
|
1511
|
-
expect { subject }.to raise_error(ActiveRecord::RecordNotFound)
|
|
1512
|
-
end
|
|
1513
|
-
end
|
|
1514
|
-
|
|
1515
|
-
context "with unavailable payment method" do
|
|
1516
|
-
let(:payment_method) { create(:check_payment_method, display_on: "back_end") }
|
|
1517
|
-
|
|
1518
|
-
it "raises RecordNotFound" do
|
|
1519
|
-
expect { subject }.to raise_error(ActiveRecord::RecordNotFound)
|
|
1520
|
-
end
|
|
1521
|
-
end
|
|
1522
|
-
|
|
1523
|
-
context "with soft-deleted payment method" do
|
|
1524
|
-
let(:payment_method) { create(:check_payment_method, deleted_at: Time.current) }
|
|
1525
|
-
|
|
1526
|
-
it "raises RecordNotFound" do
|
|
1527
|
-
expect { subject }.to raise_error(ActiveRecord::RecordNotFound)
|
|
1528
|
-
end
|
|
1529
|
-
end
|
|
1530
|
-
end
|
|
1531
1495
|
end
|
|
@@ -3,7 +3,6 @@ require 'spec_helper'
|
|
|
3
3
|
module Spree
|
|
4
4
|
RSpec.describe OrderUpdateAttributes do
|
|
5
5
|
let(:order) { create(:order) }
|
|
6
|
-
let(:payment_method) { create(:payment_method) }
|
|
7
6
|
let(:request_env) { nil }
|
|
8
7
|
let(:update) { described_class.new(order, attributes, request_env: request_env) }
|
|
9
8
|
|
|
@@ -26,10 +25,7 @@ module Spree
|
|
|
26
25
|
let(:attributes) do
|
|
27
26
|
{
|
|
28
27
|
payments_attributes: [
|
|
29
|
-
{
|
|
30
|
-
payment_method_id: payment_method.id,
|
|
31
|
-
source_attributes: attributes_for(:credit_card)
|
|
32
|
-
}
|
|
28
|
+
{ source_attributes: attributes_for(:credit_card) }
|
|
33
29
|
]
|
|
34
30
|
}
|
|
35
31
|
end
|
|
@@ -47,6 +47,7 @@ module Spree
|
|
|
47
47
|
updater.update
|
|
48
48
|
create(:adjustment, source: promotion_action, adjustable: order, order: order)
|
|
49
49
|
create(:line_item, order: order, price: 10) # in addition to the two already created
|
|
50
|
+
order.line_items.reload # need to pick up the extra line item
|
|
50
51
|
updater.update
|
|
51
52
|
end
|
|
52
53
|
|
|
@@ -56,17 +57,13 @@ module Spree
|
|
|
56
57
|
end
|
|
57
58
|
|
|
58
59
|
it "update order adjustments" do
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
})
|
|
66
|
-
updater.update_adjustment_total
|
|
67
|
-
expect(order.adjustment_total).to eq(10.05)
|
|
68
|
-
expect(order.additional_tax_total).to eq(0.05)
|
|
69
|
-
expect(order.included_tax_total).to eq(0.05)
|
|
60
|
+
create(:adjustment, adjustable: order, order: order, source: nil, amount: 10)
|
|
61
|
+
|
|
62
|
+
expect {
|
|
63
|
+
updater.update_adjustment_total
|
|
64
|
+
}.to change {
|
|
65
|
+
order.adjustment_total
|
|
66
|
+
}.from(0).to(10)
|
|
70
67
|
end
|
|
71
68
|
end
|
|
72
69
|
|
|
@@ -277,5 +274,36 @@ module Spree
|
|
|
277
274
|
updater.update
|
|
278
275
|
end
|
|
279
276
|
end
|
|
277
|
+
|
|
278
|
+
describe 'updating in-memory items' do
|
|
279
|
+
let(:order) do
|
|
280
|
+
create(:order_with_line_items, line_items_count: 1, line_items_price: 10)
|
|
281
|
+
end
|
|
282
|
+
let(:line_item) { order.line_items.first }
|
|
283
|
+
let(:promotion) { create(:promotion, :with_line_item_adjustment, adjustment_rate: 1) }
|
|
284
|
+
|
|
285
|
+
it 'updates in-memory items' do
|
|
286
|
+
promotion.activate(order: order)
|
|
287
|
+
|
|
288
|
+
expect(line_item.promo_total).to eq(0)
|
|
289
|
+
expect(order.promo_total).to eq(0)
|
|
290
|
+
|
|
291
|
+
order.update!
|
|
292
|
+
|
|
293
|
+
expect(line_item.promo_total).to eq(-1)
|
|
294
|
+
expect(order.promo_total).to eq(-1)
|
|
295
|
+
end
|
|
296
|
+
end
|
|
297
|
+
|
|
298
|
+
context "with item with no adjustment and incorrect totals" do
|
|
299
|
+
let!(:line_item) { create(:line_item, order: order, price: 10) }
|
|
300
|
+
|
|
301
|
+
it "updates the totals" do
|
|
302
|
+
line_item.update!(adjustment_total: 100)
|
|
303
|
+
expect {
|
|
304
|
+
order.update!
|
|
305
|
+
}.to change { line_item.reload.adjustment_total }.from(100).to(0)
|
|
306
|
+
end
|
|
307
|
+
end
|
|
280
308
|
end
|
|
281
309
|
end
|