solidus_core 2.0.3 → 2.1.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of solidus_core might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/README.md +62 -3
- data/app/assets/javascripts/spree.js.coffee.erb +4 -1
- data/app/helpers/spree/base_helper.rb +7 -48
- data/app/models/spree/address.rb +5 -1
- data/app/models/spree/adjustment.rb +3 -3
- data/app/models/spree/app_configuration.rb +13 -0
- data/app/models/spree/calculator.rb +3 -2
- data/app/models/spree/calculator/default_tax.rb +6 -10
- data/app/models/spree/calculator/flat_percent_item_total.rb +0 -4
- data/app/models/spree/calculator/flat_rate.rb +0 -4
- data/app/models/spree/calculator/flexi_rate.rb +0 -4
- data/app/models/spree/calculator/free_shipping.rb +0 -3
- data/app/models/spree/calculator/percent_on_line_item.rb +0 -4
- data/app/models/spree/calculator/percent_per_item.rb +0 -4
- data/app/models/spree/calculator/price_sack.rb +0 -4
- data/app/models/spree/calculator/returns/default_refund_amount.rb +0 -3
- data/app/models/spree/calculator/shipping/flat_percent_item_total.rb +0 -4
- data/app/models/spree/calculator/shipping/flat_rate.rb +0 -4
- data/app/models/spree/calculator/shipping/flexi_rate.rb +0 -4
- data/app/models/spree/calculator/shipping/per_item.rb +0 -4
- data/app/models/spree/calculator/shipping/price_sack.rb +0 -4
- data/app/models/spree/calculator/tiered_flat_rate.rb +0 -4
- data/app/models/spree/calculator/tiered_percent.rb +0 -4
- data/app/models/spree/credit_card.rb +27 -14
- data/app/models/spree/gateway.rb +4 -0
- data/app/models/spree/inventory_unit.rb +2 -0
- data/app/models/spree/line_item.rb +31 -26
- data/app/models/spree/option_type.rb +0 -3
- data/app/models/spree/order.rb +28 -31
- data/app/models/spree/order/checkout.rb +0 -2
- data/app/models/spree/order_contents.rb +0 -45
- data/app/models/spree/order_merger.rb +6 -6
- data/app/models/spree/order_update_attributes.rb +0 -2
- data/app/models/spree/order_updater.rb +91 -13
- data/app/models/spree/payment.rb +9 -2
- data/app/models/spree/payment/processing.rb +15 -9
- data/app/models/spree/payment_method.rb +48 -5
- data/app/models/spree/price.rb +7 -9
- data/app/models/spree/product.rb +1 -25
- data/app/models/spree/promotion.rb +22 -14
- data/app/models/spree/promotion/actions/create_adjustment.rb +12 -1
- data/app/models/spree/promotion/actions/create_item_adjustments.rb +15 -1
- data/app/models/spree/promotion/actions/create_quantity_adjustments.rb +5 -3
- data/app/models/spree/promotion/actions/free_shipping.rb +14 -0
- data/app/models/spree/promotion/rules/taxon.rb +7 -2
- data/app/models/spree/promotion/rules/user_role.rb +43 -0
- data/app/models/spree/promotion_action.rb +19 -2
- data/app/models/spree/promotion_handler/coupon.rb +1 -4
- data/app/models/spree/promotion_handler/free_shipping.rb +22 -17
- data/app/models/spree/promotion_rule_role.rb +6 -0
- data/app/models/spree/property.rb +0 -3
- data/app/models/spree/return_authorization.rb +2 -0
- data/app/models/spree/shipment.rb +5 -21
- data/app/models/spree/shipping_method.rb +23 -2
- data/app/models/spree/shipping_rate.rb +3 -0
- data/app/models/spree/stock/estimator.rb +1 -1
- data/app/models/spree/stock_location.rb +3 -0
- data/app/models/spree/store.rb +7 -0
- data/app/models/spree/tax/item_adjuster.rb +27 -12
- data/app/models/spree/tax/order_adjuster.rb +2 -5
- data/app/models/spree/tax/tax_helpers.rb +4 -8
- data/app/models/spree/tax_rate.rb +1 -15
- data/app/models/spree/taxon.rb +0 -3
- data/app/models/spree/transfer_item.rb +1 -1
- data/app/models/spree/user_class_handle.rb +14 -9
- data/app/models/spree/variant/pricing_options.rb +1 -1
- data/app/models/spree/wallet/add_payment_sources_to_wallet.rb +1 -1
- data/app/models/spree/zone.rb +20 -13
- data/config/locales/en.yml +144 -62
- data/db/migrate/20120831092320_spree_one_two.rb +0 -7
- data/db/migrate/20150723224133_remove_unnecessary_indexes.rb +0 -2
- data/db/migrate/20160924135758_remove_is_default_from_prices.rb +5 -0
- data/db/migrate/20161009141333_remove_currency_from_line_items.rb +5 -0
- data/db/migrate/20161014221052_add_available_to_columns_and_remove_display_on_from_payment_methods.rb +28 -0
- data/db/migrate/20161123154034_add_available_to_users_and_remove_display_on_from_shipping_methods.rb +20 -0
- data/lib/generators/spree/custom_user/templates/authentication_helpers.rb.tt +4 -0
- data/lib/generators/spree/dummy/dummy_generator.rb +0 -2
- data/lib/spree/core.rb +0 -5
- data/lib/spree/core/controller_helpers/pricing.rb +2 -1
- data/lib/spree/core/engine.rb +14 -0
- data/lib/spree/core/version.rb +1 -1
- data/lib/spree/deprecation.rb +1 -1
- data/lib/spree/localized_number.rb +3 -2
- data/lib/spree/permission_sets/configuration_display.rb +0 -1
- data/lib/spree/permission_sets/configuration_management.rb +0 -1
- data/lib/spree/permission_sets/product_display.rb +0 -1
- data/lib/spree/permission_sets/product_management.rb +0 -1
- data/lib/spree/permission_sets/user_management.rb +2 -4
- data/lib/spree/permitted_attributes.rb +3 -2
- data/lib/spree/testing_support/capybara_ext.rb +0 -12
- data/lib/spree/testing_support/factories/address_factory.rb +1 -1
- data/lib/spree/testing_support/factories/line_item_factory.rb +0 -1
- data/lib/spree/testing_support/factories/payment_factory.rb +4 -0
- data/lib/spree/testing_support/factories/payment_method_factory.rb +8 -1
- data/lib/spree/testing_support/factories/user_factory.rb +2 -2
- data/solidus_core.gemspec +4 -3
- data/spec/helpers/base_helper_spec.rb +0 -40
- data/spec/lib/spree/core/controller_helpers/pricing_spec.rb +16 -0
- data/spec/lib/spree/core/importer/order_spec.rb +27 -18
- data/spec/lib/spree/core/price_migrator_spec.rb +3 -1
- data/spec/lib/spree/core/testing_support/factories/order_factory_spec.rb +16 -0
- data/spec/lib/spree/core/unreturned_item_charger_spec.rb +0 -2
- data/spec/lib/tasks/exchanges_spec.rb +4 -2
- data/spec/lib/tasks/migrations/create_vat_prices_spec.rb +5 -3
- data/spec/models/spree/adjustment_spec.rb +136 -0
- data/spec/models/spree/calculator/default_tax_spec.rb +13 -7
- data/spec/models/spree/calculator/flat_percent_item_total_spec.rb +3 -0
- data/spec/models/spree/calculator/flat_rate_spec.rb +3 -0
- data/spec/models/spree/calculator/flexi_rate_spec.rb +3 -0
- data/spec/models/spree/calculator/free_shipping_spec.rb +6 -0
- data/spec/models/spree/calculator/percent_on_line_item_spec.rb +9 -4
- data/spec/models/spree/calculator/percent_per_item_spec.rb +10 -0
- data/spec/models/spree/calculator/price_sack_spec.rb +3 -0
- data/spec/models/spree/calculator/refunds/default_refund_amount_spec.rb +3 -0
- data/spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb +3 -0
- data/spec/models/spree/calculator/shipping/flat_rate_spec.rb +3 -0
- data/spec/models/spree/calculator/shipping/flexi_rate_spec.rb +3 -0
- data/spec/models/spree/calculator/shipping/per_item_spec.rb +3 -0
- data/spec/models/spree/calculator/shipping/price_sack_spec.rb +4 -1
- data/spec/models/spree/calculator/tiered_flat_rate_spec.rb +3 -0
- data/spec/models/spree/calculator/tiered_percent_spec.rb +3 -0
- data/spec/models/spree/credit_card_spec.rb +27 -1
- data/spec/models/spree/line_item_spec.rb +58 -65
- data/spec/models/spree/order/checkout_spec.rb +2 -1
- data/spec/models/spree/order/payment_spec.rb +9 -10
- data/spec/models/spree/order/tax_spec.rb +22 -7
- data/spec/models/spree/order/updating_spec.rb +1 -3
- data/spec/models/spree/order_cancellations_spec.rb +6 -4
- data/spec/models/spree/order_contents_spec.rb +34 -50
- data/spec/models/spree/order_inventory_spec.rb +3 -5
- data/spec/models/spree/order_merger_spec.rb +20 -0
- data/spec/models/spree/order_spec.rb +28 -64
- data/spec/models/spree/order_update_attributes_spec.rb +1 -5
- data/spec/models/spree/order_updater_spec.rb +251 -0
- data/spec/models/spree/payment_method_spec.rb +178 -28
- data/spec/models/spree/payment_spec.rb +35 -19
- data/spec/models/spree/permission_sets/configuration_display.rb +0 -4
- data/spec/models/spree/permission_sets/configuration_management_spec.rb +0 -2
- data/spec/models/spree/permission_sets/product_display_spec.rb +0 -4
- data/spec/models/spree/permission_sets/product_management_spec.rb +0 -2
- data/spec/models/spree/permission_sets/user_management_spec.rb +9 -2
- data/spec/models/spree/price_spec.rb +16 -1
- data/spec/models/spree/product_spec.rb +0 -75
- data/spec/models/spree/promotion/actions/create_adjustment_spec.rb +20 -0
- data/spec/models/spree/promotion/actions/create_item_adjustments_spec.rb +39 -15
- data/spec/models/spree/promotion/actions/create_quantity_adjustments_spec.rb +203 -22
- data/spec/models/spree/promotion/actions/free_shipping_spec.rb +22 -3
- data/spec/models/spree/promotion/rules/taxon_spec.rb +26 -0
- data/spec/models/spree/promotion/rules/user_role_spec.rb +86 -0
- data/spec/models/spree/promotion_action_spec.rb +38 -0
- data/spec/models/spree/promotion_handler/coupon_spec.rb +36 -33
- data/spec/models/spree/promotion_handler/free_shipping_spec.rb +21 -22
- data/spec/models/spree/promotion_spec.rb +46 -6
- data/spec/models/spree/reimbursement_spec.rb +1 -1
- data/spec/models/spree/reimbursement_tax_calculator_spec.rb +2 -2
- data/spec/models/spree/shipment_spec.rb +68 -50
- data/spec/models/spree/shipping_method_spec.rb +41 -0
- data/spec/models/spree/shipping_rate_spec.rb +9 -3
- data/spec/models/spree/stock/estimator_spec.rb +4 -2
- data/spec/models/spree/store_credit_spec.rb +3 -3
- data/spec/models/spree/tax/item_adjuster_spec.rb +31 -21
- data/spec/models/spree/tax/order_adjuster_spec.rb +6 -10
- data/spec/models/spree/tax/taxation_integration_spec.rb +19 -0
- data/spec/models/spree/tax_rate_spec.rb +5 -26
- data/spec/models/spree/transfer_item_spec.rb +11 -0
- data/spec/models/spree/variant/pricing_options_spec.rb +7 -17
- data/spec/models/spree/variant_spec.rb +2 -4
- data/spec/models/spree/zone_spec.rb +60 -20
- data/spec/shared_examples/calculator_shared_examples.rb +8 -0
- metadata +19 -24
- data/app/models/spree/item_adjustments.rb +0 -89
- data/app/models/spree/option_type_prototype.rb +0 -6
- data/app/models/spree/property_prototype.rb +0 -6
- data/app/models/spree/prototype.rb +0 -14
- data/app/models/spree/prototype_taxon.rb +0 -6
- data/app/models/spree/tracker.rb +0 -8
- data/db/migrate/20150128032538_remove_environment_from_tracker.rb +0 -6
- data/lib/generators/spree/dummy/templates/initializers/custom_user.rb +0 -1
- data/lib/spree/core/delegate_belongs_to.rb +0 -94
- data/lib/spree/testing_support/factories/prototype_factory.rb +0 -8
- data/lib/spree/testing_support/factories/tracker_factory.rb +0 -6
- data/spec/lib/spree/core/delegate_belongs_to_spec.rb +0 -24
- data/spec/lib/spree/core/testing_support/factories/prototype_factory_spec.rb +0 -12
- data/spec/lib/spree/core/testing_support/factories/tracker_factory_spec.rb +0 -12
- data/spec/models/spree/item_adjustments_spec.rb +0 -306
- data/spec/models/spree/tracker_spec.rb +0 -21
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'shared_examples/calculator_shared_examples'
|
2
3
|
|
3
4
|
describe Spree::Calculator::PriceSack, type: :model do
|
4
5
|
let(:calculator) do
|
@@ -9,6 +10,8 @@ describe Spree::Calculator::PriceSack, type: :model do
|
|
9
10
|
calculator
|
10
11
|
end
|
11
12
|
|
13
|
+
it_behaves_like 'a calculator with a description'
|
14
|
+
|
12
15
|
let(:order) { stub_model(Spree::Order) }
|
13
16
|
let(:shipment) { stub_model(Spree::Shipment, amount: 10) }
|
14
17
|
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'shared_examples/calculator_shared_examples'
|
2
3
|
|
3
4
|
describe Spree::Calculator::Returns::DefaultRefundAmount, type: :model do
|
4
5
|
let(:line_item_quantity) { 2 }
|
@@ -9,6 +10,8 @@ describe Spree::Calculator::Returns::DefaultRefundAmount, type: :model do
|
|
9
10
|
let(:calculator) { Spree::Calculator::Returns::DefaultRefundAmount.new }
|
10
11
|
let(:order) { line_item.order }
|
11
12
|
|
13
|
+
it_behaves_like 'a calculator with a description'
|
14
|
+
|
12
15
|
subject { calculator.compute(return_item) }
|
13
16
|
|
14
17
|
context "not an exchange" do
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'shared_examples/calculator_shared_examples'
|
2
3
|
|
3
4
|
module Spree
|
4
5
|
module Calculator::Shipping
|
@@ -6,6 +7,8 @@ module Spree
|
|
6
7
|
let(:variant1) { build(:variant, price: 10.11) }
|
7
8
|
let(:variant2) { build(:variant, price: 20.2222) }
|
8
9
|
|
10
|
+
it_behaves_like 'a calculator with a description'
|
11
|
+
|
9
12
|
let(:line_item1) { build(:line_item, variant: variant1) }
|
10
13
|
let(:line_item2) { build(:line_item, variant: variant2) }
|
11
14
|
|
@@ -1,10 +1,13 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'shared_examples/calculator_shared_examples'
|
2
3
|
|
3
4
|
module Spree
|
4
5
|
module Calculator::Shipping
|
5
6
|
describe FlatRate, type: :model do
|
6
7
|
subject { Calculator::Shipping::FlatRate.new(preferred_amount: 4.00) }
|
7
8
|
|
9
|
+
it_behaves_like 'a calculator with a description'
|
10
|
+
|
8
11
|
it 'always returns the same rate' do
|
9
12
|
expect(subject.compute(build(:stock_package_fulfilled))).to eql 4.00
|
10
13
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'shared_examples/calculator_shared_examples'
|
2
3
|
|
3
4
|
module Spree
|
4
5
|
module Calculator::Shipping
|
@@ -6,6 +7,8 @@ module Spree
|
|
6
7
|
let(:variant1) { build(:variant, price: 10) }
|
7
8
|
let(:variant2) { build(:variant, price: 20) }
|
8
9
|
|
10
|
+
it_behaves_like 'a calculator with a description'
|
11
|
+
|
9
12
|
let(:package) do
|
10
13
|
build(:stock_package, variants_contents: { variant1 => 4, variant2 => 6 })
|
11
14
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'shared_examples/calculator_shared_examples'
|
2
3
|
|
3
4
|
module Spree
|
4
5
|
module Calculator::Shipping
|
@@ -6,6 +7,8 @@ module Spree
|
|
6
7
|
let(:variant1) { build(:variant) }
|
7
8
|
let(:variant2) { build(:variant) }
|
8
9
|
|
10
|
+
it_behaves_like 'a calculator with a description'
|
11
|
+
|
9
12
|
let(:package) do
|
10
13
|
build(:stock_package, variants_contents: { variant1 => 5, variant2 => 3 })
|
11
14
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'shared_examples/calculator_shared_examples'
|
2
3
|
|
3
|
-
describe Spree::Calculator::PriceSack, type: :model do
|
4
|
+
describe Spree::Calculator::Shipping::PriceSack, type: :model do
|
4
5
|
let(:calculator) do
|
5
6
|
calculator = Spree::Calculator::PriceSack.new
|
6
7
|
calculator.preferred_minimal_amount = 5
|
@@ -9,6 +10,8 @@ describe Spree::Calculator::PriceSack, type: :model do
|
|
9
10
|
calculator
|
10
11
|
end
|
11
12
|
|
13
|
+
it_behaves_like 'a calculator with a description'
|
14
|
+
|
12
15
|
let(:order) { stub_model(Spree::Order) }
|
13
16
|
let(:shipment) { stub_model(Spree::Shipment, amount: 10) }
|
14
17
|
|
@@ -1,8 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'shared_examples/calculator_shared_examples'
|
2
3
|
|
3
4
|
describe Spree::Calculator::TieredFlatRate, type: :model do
|
4
5
|
let(:calculator) { Spree::Calculator::TieredFlatRate.new }
|
5
6
|
|
7
|
+
it_behaves_like 'a calculator with a description'
|
8
|
+
|
6
9
|
describe "#valid?" do
|
7
10
|
subject { calculator.valid? }
|
8
11
|
context "when tiers is a hash" do
|
@@ -1,8 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'shared_examples/calculator_shared_examples'
|
2
3
|
|
3
4
|
describe Spree::Calculator::TieredPercent, type: :model do
|
4
5
|
let(:calculator) { Spree::Calculator::TieredPercent.new }
|
5
6
|
|
7
|
+
it_behaves_like 'a calculator with a description'
|
8
|
+
|
6
9
|
describe "#valid?" do
|
7
10
|
subject { calculator.valid? }
|
8
11
|
context "when base percent is less than zero" do
|
@@ -160,6 +160,28 @@ describe Spree::CreditCard, type: :model do
|
|
160
160
|
end
|
161
161
|
end
|
162
162
|
|
163
|
+
describe "#verification_value=" do
|
164
|
+
it "accepts a valid 3-digit value" do
|
165
|
+
credit_card.verification_value = "123"
|
166
|
+
expect(credit_card.verification_value).to eq("123")
|
167
|
+
end
|
168
|
+
|
169
|
+
it "accepts a valid 4-digit value" do
|
170
|
+
credit_card.verification_value = "1234"
|
171
|
+
expect(credit_card.verification_value).to eq("1234")
|
172
|
+
end
|
173
|
+
|
174
|
+
it "stringifies an integer" do
|
175
|
+
credit_card.verification_value = 123
|
176
|
+
expect(credit_card.verification_value).to eq("123")
|
177
|
+
end
|
178
|
+
|
179
|
+
it "strips any whitespace" do
|
180
|
+
credit_card.verification_value = ' 1 2 3 '
|
181
|
+
expect(credit_card.verification_value).to eq('123')
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
163
185
|
# Regression test for https://github.com/spree/spree/issues/3847 and https://github.com/spree/spree/issues/3896
|
164
186
|
describe "#expiry=" do
|
165
187
|
it "can set with a 2-digit month and year" do
|
@@ -235,6 +257,10 @@ describe Spree::CreditCard, type: :model do
|
|
235
257
|
credit_card.cc_type = ''
|
236
258
|
expect(credit_card.cc_type).to eq('master')
|
237
259
|
|
260
|
+
credit_card.number = '2221000000000000'
|
261
|
+
credit_card.cc_type = ''
|
262
|
+
expect(credit_card.cc_type).to eq('master')
|
263
|
+
|
238
264
|
credit_card.number = '378282246310005'
|
239
265
|
credit_card.cc_type = ''
|
240
266
|
expect(credit_card.cc_type).to eq('american_express')
|
@@ -299,7 +325,7 @@ describe Spree::CreditCard, type: :model do
|
|
299
325
|
expect(am_card.month).to eq(Time.current.month)
|
300
326
|
expect(am_card.first_name).to eq("Ludwig")
|
301
327
|
expect(am_card.last_name).to eq("van Beethoven")
|
302
|
-
expect(am_card.verification_value).to eq(123)
|
328
|
+
expect(am_card.verification_value).to eq("123")
|
303
329
|
end
|
304
330
|
end
|
305
331
|
|
@@ -35,41 +35,6 @@ describe Spree::LineItem, type: :model do
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
context "#create" do
|
39
|
-
let(:variant) { create(:variant) }
|
40
|
-
|
41
|
-
before do
|
42
|
-
create(:tax_rate, zone: order.tax_zone, tax_category: variant.tax_category)
|
43
|
-
end
|
44
|
-
|
45
|
-
context "when order has a tax zone" do
|
46
|
-
before do
|
47
|
-
expect(order.tax_zone).to be_present
|
48
|
-
end
|
49
|
-
|
50
|
-
it "creates a tax adjustment" do
|
51
|
-
order.contents.add(variant)
|
52
|
-
line_item = order.find_line_item_by_variant(variant)
|
53
|
-
expect(line_item.adjustments.tax.count).to eq(1)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
context "when order does not have a tax zone" do
|
58
|
-
before do
|
59
|
-
order.bill_address = nil
|
60
|
-
order.ship_address = nil
|
61
|
-
order.save
|
62
|
-
expect(order.reload.tax_zone).to be_nil
|
63
|
-
end
|
64
|
-
|
65
|
-
it "does not create a tax adjustment" do
|
66
|
-
order.contents.add(variant)
|
67
|
-
line_item = order.find_line_item_by_variant(variant)
|
68
|
-
expect(line_item.adjustments.tax.count).to eq(0)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
38
|
describe 'line item creation' do
|
74
39
|
let(:variant) { create :variant }
|
75
40
|
|
@@ -102,7 +67,6 @@ describe Spree::LineItem, type: :model do
|
|
102
67
|
before(:context) do
|
103
68
|
Spree::LineItem.class_eval do
|
104
69
|
def copy_price
|
105
|
-
self.currency = "USD"
|
106
70
|
self.cost_price = 10
|
107
71
|
self.price = 20
|
108
72
|
end
|
@@ -163,66 +127,95 @@ describe Spree::LineItem, type: :model do
|
|
163
127
|
end
|
164
128
|
end
|
165
129
|
|
166
|
-
context 'setting
|
167
|
-
let(:
|
130
|
+
context 'setting a line item price' do
|
131
|
+
let(:store) { create(:store, default: true) }
|
132
|
+
let(:order) { Spree::Order.new(currency: "RUB", store: store) }
|
133
|
+
let(:variant) { Spree::Variant.new(product: Spree::Product.new) }
|
134
|
+
let(:line_item) { Spree::LineItem.new(order: order, variant: variant) }
|
168
135
|
|
169
|
-
|
170
|
-
it "is a valid line item" do
|
171
|
-
line_item.currency = order.currency
|
172
|
-
line_item.valid?
|
136
|
+
before { expect(variant).to receive(:price_for).at_least(:once).and_return(price) }
|
173
137
|
|
174
|
-
|
138
|
+
context "when a price exists in order currency" do
|
139
|
+
let(:price) { Spree::Money.new(99.00, currency: "RUB") }
|
140
|
+
|
141
|
+
it "is a valid line item" do
|
142
|
+
expect(line_item.valid?).to be_truthy
|
143
|
+
expect(line_item.error_on(:price).size).to eq(0)
|
175
144
|
end
|
176
145
|
end
|
177
146
|
|
178
|
-
context "
|
179
|
-
|
180
|
-
expect(Spree::Deprecation).to receive(:warn).at_least(:once)
|
181
|
-
line_item.currency = "RUB"
|
182
|
-
line_item.valid?
|
147
|
+
context "when a price does not exist in order currency" do
|
148
|
+
let(:price) { nil }
|
183
149
|
|
184
|
-
|
150
|
+
it "is not a valid line item" do
|
151
|
+
expect(line_item.valid?).to be_falsey
|
152
|
+
expect(line_item.error_on(:price).size).to eq(1)
|
185
153
|
end
|
186
154
|
end
|
187
155
|
end
|
188
156
|
|
189
157
|
describe "#options=" do
|
190
|
-
|
191
|
-
line_item.options = { price: 123 }
|
192
|
-
end
|
158
|
+
let(:options) { { price: 123, quantity: 5 } }
|
193
159
|
|
194
160
|
it "updates the data provided in the options" do
|
195
|
-
line_item.options =
|
161
|
+
line_item.options = options
|
162
|
+
|
196
163
|
expect(line_item.price).to eq 123
|
164
|
+
expect(line_item.quantity).to eq 5
|
197
165
|
end
|
198
166
|
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
167
|
+
context "when price is not provided" do
|
168
|
+
let(:options) { { quantity: 5 } }
|
169
|
+
|
170
|
+
it "sets price anyway, retrieving it from line item options" do
|
171
|
+
expect(line_item.variant)
|
172
|
+
.to receive(:price_for)
|
173
|
+
.and_return(Spree::Money.new(123, currency: "USD"))
|
174
|
+
|
175
|
+
line_item.options = options
|
176
|
+
|
177
|
+
expect(line_item.price).to eq 123
|
178
|
+
expect(line_item.quantity).to eq 5
|
179
|
+
end
|
203
180
|
end
|
204
181
|
end
|
205
182
|
|
206
183
|
describe 'money_price=' do
|
207
|
-
let(:
|
208
|
-
let(:new_price) { Spree::Money.new(99.00, currency:
|
184
|
+
let(:currency) { "USD" }
|
185
|
+
let(:new_price) { Spree::Money.new(99.00, currency: currency) }
|
209
186
|
|
210
|
-
it 'assigns a new price
|
187
|
+
it 'assigns a new price' do
|
211
188
|
line_item.money_price = new_price
|
212
189
|
expect(line_item.price).to eq(new_price.cents / 100.0)
|
213
|
-
|
190
|
+
end
|
191
|
+
|
192
|
+
context 'when the new price is nil' do
|
193
|
+
let(:new_price) { nil }
|
194
|
+
|
195
|
+
it 'makes the line item price empty' do
|
196
|
+
line_item.money_price = new_price
|
197
|
+
expect(line_item.price).to be_nil
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
context 'when the price has a currency different from the order currency' do
|
202
|
+
let(:currency) { "RUB" }
|
203
|
+
|
204
|
+
it 'raises an exception' do
|
205
|
+
expect {
|
206
|
+
line_item.money_price = new_price
|
207
|
+
}.to raise_exception Spree::LineItem::CurrencyMismatch
|
208
|
+
end
|
214
209
|
end
|
215
210
|
end
|
216
211
|
|
217
212
|
describe "#pricing_options" do
|
218
|
-
let(:line_item) { Spree::LineItem.new(currency: "RUB") }
|
219
|
-
|
220
213
|
subject { line_item.pricing_options }
|
221
214
|
|
222
215
|
it { is_expected.to be_a(Spree::Config.pricing_options_class) }
|
223
216
|
|
224
|
-
it "holds the
|
225
|
-
expect(subject.currency).to eq("
|
217
|
+
it "holds the order currency" do
|
218
|
+
expect(subject.currency).to eq("USD")
|
226
219
|
end
|
227
220
|
end
|
228
221
|
end
|
@@ -183,7 +183,8 @@ describe Spree::Order, type: :model do
|
|
183
183
|
end
|
184
184
|
|
185
185
|
it "recalculates tax and updates totals" do
|
186
|
-
create(:
|
186
|
+
zone = create(:zone, countries: [order.tax_address.country])
|
187
|
+
create(:tax_rate, tax_category: line_item.tax_category, amount: 0.05, zone: zone)
|
187
188
|
order.next!
|
188
189
|
expect(order).to have_attributes(
|
189
190
|
adjustment_total: 0.5,
|
@@ -22,8 +22,8 @@ module Spree
|
|
22
22
|
expect(order.payment_state).to eq('paid')
|
23
23
|
expect(order.payment_total).to eq(100)
|
24
24
|
|
25
|
-
expect(payment_1
|
26
|
-
expect(payment_2
|
25
|
+
expect(payment_1).to be_completed
|
26
|
+
expect(payment_2).to be_completed
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'does not go over total for order' do
|
@@ -37,18 +37,17 @@ module Spree
|
|
37
37
|
expect(order.payment_state).to eq('paid')
|
38
38
|
expect(order.payment_total).to eq(100)
|
39
39
|
|
40
|
-
expect(payment_1
|
41
|
-
expect(payment_2
|
42
|
-
expect(payment_3
|
40
|
+
expect(payment_1).to be_completed
|
41
|
+
expect(payment_2).to be_completed
|
42
|
+
expect(payment_3).to be_checkout
|
43
43
|
end
|
44
44
|
|
45
45
|
it "does not use failed payments" do
|
46
|
-
create(:payment, order: order, amount: 50)
|
47
|
-
create(:payment, order: order, amount: 50, state: 'failed')
|
48
|
-
order.payments.reload
|
46
|
+
payment1 = create(:payment, order: order, amount: 50)
|
47
|
+
payment2 = create(:payment, order: order, amount: 50, state: 'failed')
|
49
48
|
|
50
|
-
expect(
|
51
|
-
expect(
|
49
|
+
expect(payment1).to receive(:process!).and_call_original
|
50
|
+
expect(payment2).not_to receive(:process!)
|
52
51
|
|
53
52
|
order.process_payments!
|
54
53
|
|
@@ -12,7 +12,9 @@ module Spree
|
|
12
12
|
|
13
13
|
context "when no zones exist" do
|
14
14
|
it "should return nil" do
|
15
|
-
|
15
|
+
Spree::Deprecation.silence do
|
16
|
+
expect(order.tax_zone).to be_nil
|
17
|
+
end
|
16
18
|
end
|
17
19
|
end
|
18
20
|
|
@@ -22,7 +24,9 @@ module Spree
|
|
22
24
|
it "should calculate using ship_address" do
|
23
25
|
expect(Spree::Zone).to receive(:match).at_least(:once).with(ship_address)
|
24
26
|
expect(Spree::Zone).not_to receive(:match).with(bill_address)
|
25
|
-
|
27
|
+
Spree::Deprecation.silence do
|
28
|
+
order.tax_zone
|
29
|
+
end
|
26
30
|
end
|
27
31
|
end
|
28
32
|
|
@@ -32,7 +36,9 @@ module Spree
|
|
32
36
|
it "should calculate using bill_address" do
|
33
37
|
expect(Spree::Zone).to receive(:match).at_least(:once).with(bill_address)
|
34
38
|
expect(Spree::Zone).not_to receive(:match).with(ship_address)
|
35
|
-
|
39
|
+
Spree::Deprecation.silence do
|
40
|
+
order.tax_zone
|
41
|
+
end
|
36
42
|
end
|
37
43
|
end
|
38
44
|
|
@@ -46,7 +52,9 @@ module Spree
|
|
46
52
|
before { allow(Spree::Zone).to receive_messages(match: zone) }
|
47
53
|
|
48
54
|
it "should return the matching zone" do
|
49
|
-
|
55
|
+
Spree::Deprecation.silence do
|
56
|
+
expect(order.tax_zone).to eq(zone)
|
57
|
+
end
|
50
58
|
end
|
51
59
|
end
|
52
60
|
|
@@ -54,7 +62,9 @@ module Spree
|
|
54
62
|
before { allow(Spree::Zone).to receive_messages(match: nil) }
|
55
63
|
|
56
64
|
it "should return the default tax zone" do
|
57
|
-
|
65
|
+
Spree::Deprecation.silence do
|
66
|
+
expect(order.tax_zone).to eq(@default_zone)
|
67
|
+
end
|
58
68
|
end
|
59
69
|
end
|
60
70
|
end
|
@@ -66,7 +76,9 @@ module Spree
|
|
66
76
|
before { allow(Spree::Zone).to receive_messages(match: zone) }
|
67
77
|
|
68
78
|
it "should return the matching zone" do
|
69
|
-
|
79
|
+
Spree::Deprecation.silence do
|
80
|
+
expect(order.tax_zone).to eq(zone)
|
81
|
+
end
|
70
82
|
end
|
71
83
|
end
|
72
84
|
|
@@ -74,10 +86,13 @@ module Spree
|
|
74
86
|
before { allow(Spree::Zone).to receive_messages(match: nil) }
|
75
87
|
|
76
88
|
it "should return nil" do
|
77
|
-
|
89
|
+
Spree::Deprecation.silence do
|
90
|
+
expect(order.tax_zone).to be_nil
|
91
|
+
end
|
78
92
|
end
|
79
93
|
end
|
80
94
|
end
|
95
|
+
|
81
96
|
end
|
82
97
|
end
|
83
98
|
end
|