spree_core 3.0.5 → 3.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile +3 -0
- data/Rakefile +30 -0
- data/app/assets/javascripts/spree.js.coffee.erb +1 -1
- data/app/models/spree/ability.rb +1 -1
- data/app/models/spree/base.rb +3 -1
- data/app/models/spree/order_updater.rb +2 -1
- data/app/models/spree/price.rb +7 -12
- data/app/models/spree/product.rb +3 -2
- data/app/models/spree/reimbursement.rb +1 -1
- data/app/models/spree/state.rb +2 -0
- data/app/models/spree/zone.rb +1 -1
- data/lib/spree/core/version.rb +1 -1
- data/lib/spree/testing_support/shoulda_matcher_configuration.rb +6 -0
- data/script/rails +9 -0
- data/spec/fixtures/thinking-cat.jpg +0 -0
- data/spec/helpers/base_helper_spec.rb +137 -0
- data/spec/helpers/products_helper_spec.rb +224 -0
- data/spec/lib/calculated_adjustments_spec.rb +7 -0
- data/spec/lib/i18n_spec.rb +123 -0
- data/spec/lib/search/base_spec.rb +86 -0
- data/spec/lib/spree/core/controller_helpers/auth_spec.rb +101 -0
- data/spec/lib/spree/core/controller_helpers/order_spec.rb +95 -0
- data/spec/lib/spree/core/controller_helpers/search_spec.rb +17 -0
- data/spec/lib/spree/core/controller_helpers/store_spec.rb +16 -0
- data/spec/lib/spree/core/controller_helpers/strong_parameters_spec.rb +39 -0
- data/spec/lib/spree/core/delegate_belongs_to_spec.rb +22 -0
- data/spec/lib/spree/core/importer/order_spec.rb +502 -0
- data/spec/lib/spree/core/validators/email_spec.rb +53 -0
- data/spec/lib/spree/localized_number_spec.rb +38 -0
- data/spec/lib/spree/migrations_spec.rb +34 -0
- data/spec/lib/spree/money_spec.rb +122 -0
- data/spec/lib/tasks/exchanges_spec.rb +136 -0
- data/spec/mailers/order_mailer_spec.rb +124 -0
- data/spec/mailers/reimbursement_mailer_spec.rb +47 -0
- data/spec/mailers/shipment_mailer_spec.rb +63 -0
- data/spec/mailers/test_mailer_spec.rb +24 -0
- data/spec/models/spree/ability_spec.rb +246 -0
- data/spec/models/spree/address_spec.rb +291 -0
- data/spec/models/spree/adjustable/adjustments_updater_spec.rb +286 -0
- data/spec/models/spree/adjustment_spec.rb +163 -0
- data/spec/models/spree/app_configuration_spec.rb +23 -0
- data/spec/models/spree/asset_spec.rb +25 -0
- data/spec/models/spree/calculator/default_tax_spec.rb +127 -0
- data/spec/models/spree/calculator/flat_percent_item_total_spec.rb +25 -0
- data/spec/models/spree/calculator/flat_rate_spec.rb +47 -0
- data/spec/models/spree/calculator/flexi_rate_spec.rb +41 -0
- data/spec/models/spree/calculator/percent_on_line_item_spec.rb +15 -0
- data/spec/models/spree/calculator/price_sack_spec.rb +30 -0
- data/spec/models/spree/calculator/refunds/default_refund_amount_spec.rb +51 -0
- data/spec/models/spree/calculator/shipping.rb +8 -0
- data/spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb +23 -0
- data/spec/models/spree/calculator/shipping/flat_rate_spec.rb +13 -0
- data/spec/models/spree/calculator/shipping/flexi_rate_spec.rb +52 -0
- data/spec/models/spree/calculator/shipping/per_item_spec.rb +20 -0
- data/spec/models/spree/calculator/shipping/price_sack_spec.rb +29 -0
- data/spec/models/spree/calculator/tiered_flat_rate_spec.rb +40 -0
- data/spec/models/spree/calculator/tiered_percent_spec.rb +51 -0
- data/spec/models/spree/calculator_spec.rb +69 -0
- data/spec/models/spree/classification_spec.rb +93 -0
- data/spec/models/spree/concerns/display_money_spec.rb +43 -0
- data/spec/models/spree/country_spec.rb +18 -0
- data/spec/models/spree/credit_card_spec.rb +324 -0
- data/spec/models/spree/customer_return_spec.rb +262 -0
- data/spec/models/spree/exchange_spec.rb +75 -0
- data/spec/models/spree/gateway/bogus_simple.rb +20 -0
- data/spec/models/spree/gateway/bogus_spec.rb +13 -0
- data/spec/models/spree/gateway_spec.rb +54 -0
- data/spec/models/spree/image_spec.rb +5 -0
- data/spec/models/spree/inventory_unit_spec.rb +242 -0
- data/spec/models/spree/line_item_spec.rb +267 -0
- data/spec/models/spree/option_type_spec.rb +14 -0
- data/spec/models/spree/option_value_spec.rb +13 -0
- data/spec/models/spree/order/address_spec.rb +50 -0
- data/spec/models/spree/order/adjustments_spec.rb +29 -0
- data/spec/models/spree/order/callbacks_spec.rb +42 -0
- data/spec/models/spree/order/checkout_spec.rb +764 -0
- data/spec/models/spree/order/currency_updater_spec.rb +32 -0
- data/spec/models/spree/order/finalizing_spec.rb +117 -0
- data/spec/models/spree/order/helpers_spec.rb +5 -0
- data/spec/models/spree/order/payment_spec.rb +214 -0
- data/spec/models/spree/order/risk_assessment_spec.rb +84 -0
- data/spec/models/spree/order/shipments_spec.rb +43 -0
- data/spec/models/spree/order/state_machine_spec.rb +216 -0
- data/spec/models/spree/order/tax_spec.rb +84 -0
- data/spec/models/spree/order/totals_spec.rb +24 -0
- data/spec/models/spree/order/updating_spec.rb +18 -0
- data/spec/models/spree/order/validations_spec.rb +15 -0
- data/spec/models/spree/order_contents_spec.rb +256 -0
- data/spec/models/spree/order_inventory_spec.rb +228 -0
- data/spec/models/spree/order_merger_spec.rb +133 -0
- data/spec/models/spree/order_spec.rb +954 -0
- data/spec/models/spree/order_updater_spec.rb +283 -0
- data/spec/models/spree/payment/gateway_options_spec.rb +119 -0
- data/spec/models/spree/payment_method_spec.rb +95 -0
- data/spec/models/spree/payment_spec.rb +926 -0
- data/spec/models/spree/preference_spec.rb +80 -0
- data/spec/models/spree/preferences/configuration_spec.rb +30 -0
- data/spec/models/spree/preferences/preferable_spec.rb +348 -0
- data/spec/models/spree/preferences/scoped_store_spec.rb +58 -0
- data/spec/models/spree/preferences/store_spec.rb +46 -0
- data/spec/models/spree/price_spec.rb +42 -0
- data/spec/models/spree/product/scopes_spec.rb +148 -0
- data/spec/models/spree/product_duplicator_spec.rb +103 -0
- data/spec/models/spree/product_filter_spec.rb +26 -0
- data/spec/models/spree/product_option_type_spec.rb +5 -0
- data/spec/models/spree/product_property_spec.rb +11 -0
- data/spec/models/spree/product_spec.rb +474 -0
- data/spec/models/spree/promotion/actions/create_adjustment_spec.rb +50 -0
- data/spec/models/spree/promotion/actions/create_item_adjustments_spec.rb +148 -0
- data/spec/models/spree/promotion/actions/create_line_items_spec.rb +86 -0
- data/spec/models/spree/promotion/actions/free_shipping_spec.rb +36 -0
- data/spec/models/spree/promotion/rules/first_order_spec.rb +75 -0
- data/spec/models/spree/promotion/rules/item_total_spec.rb +282 -0
- data/spec/models/spree/promotion/rules/one_use_per_user_spec.rb +42 -0
- data/spec/models/spree/promotion/rules/option_value_spec.rb +90 -0
- data/spec/models/spree/promotion/rules/product_spec.rb +143 -0
- data/spec/models/spree/promotion/rules/taxon_spec.rb +102 -0
- data/spec/models/spree/promotion/rules/user_logged_in_spec.rb +27 -0
- data/spec/models/spree/promotion/rules/user_spec.rb +37 -0
- data/spec/models/spree/promotion_action_spec.rb +10 -0
- data/spec/models/spree/promotion_category_spec.rb +17 -0
- data/spec/models/spree/promotion_handler/cart_spec.rb +102 -0
- data/spec/models/spree/promotion_handler/coupon_spec.rb +323 -0
- data/spec/models/spree/promotion_handler/free_shipping_spec.rb +48 -0
- data/spec/models/spree/promotion_handler/page_spec.rb +44 -0
- data/spec/models/spree/promotion_rule_spec.rb +29 -0
- data/spec/models/spree/promotion_spec.rb +603 -0
- data/spec/models/spree/property_spec.rb +5 -0
- data/spec/models/spree/prototype_spec.rb +5 -0
- data/spec/models/spree/refund_spec.rb +195 -0
- data/spec/models/spree/reimbursement/credit_spec.rb +36 -0
- data/spec/models/spree/reimbursement/reimbursement_type_engine_spec.rb +140 -0
- data/spec/models/spree/reimbursement/reimbursement_type_validator_spec.rb +83 -0
- data/spec/models/spree/reimbursement_performer_spec.rb +30 -0
- data/spec/models/spree/reimbursement_spec.rb +215 -0
- data/spec/models/spree/reimbursement_tax_calculator_spec.rb +51 -0
- data/spec/models/spree/reimbursement_type/credit_spec.rb +53 -0
- data/spec/models/spree/reimbursement_type/exchange_spec.rb +46 -0
- data/spec/models/spree/reimbursement_type/original_payment_spec.rb +55 -0
- data/spec/models/spree/return_authorization_spec.rb +250 -0
- data/spec/models/spree/return_item/eligibility_validator/default_spec.rb +77 -0
- data/spec/models/spree/return_item/eligibility_validator/inventory_shipped_spec.rb +58 -0
- data/spec/models/spree/return_item/eligibility_validator/no_reimbursements_spec.rb +61 -0
- data/spec/models/spree/return_item/eligibility_validator/order_completed_spec.rb +32 -0
- data/spec/models/spree/return_item/eligibility_validator/rma_required_spec.rb +29 -0
- data/spec/models/spree/return_item/eligibility_validator/time_since_purchase_spec.rb +35 -0
- data/spec/models/spree/return_item/exchange_variant_eligibility/same_option_value_spec.rb +65 -0
- data/spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb +43 -0
- data/spec/models/spree/return_item_spec.rb +682 -0
- data/spec/models/spree/returns_calculator_spec.rb +14 -0
- data/spec/models/spree/shipment_spec.rb +740 -0
- data/spec/models/spree/shipping_calculator_spec.rb +45 -0
- data/spec/models/spree/shipping_category_spec.rb +5 -0
- data/spec/models/spree/shipping_method_spec.rb +88 -0
- data/spec/models/spree/shipping_rate_spec.rb +141 -0
- data/spec/models/spree/state_spec.rb +18 -0
- data/spec/models/spree/stock/availability_validator_spec.rb +36 -0
- data/spec/models/spree/stock/content_item_spec.rb +22 -0
- data/spec/models/spree/stock/coordinator_spec.rb +51 -0
- data/spec/models/spree/stock/differentiator_spec.rb +39 -0
- data/spec/models/spree/stock/estimator_spec.rb +154 -0
- data/spec/models/spree/stock/inventory_unit_builder_spec.rb +38 -0
- data/spec/models/spree/stock/package_spec.rb +194 -0
- data/spec/models/spree/stock/packer_spec.rb +70 -0
- data/spec/models/spree/stock/prioritizer_spec.rb +125 -0
- data/spec/models/spree/stock/quantifier_spec.rb +97 -0
- data/spec/models/spree/stock/splitter/backordered_spec.rb +29 -0
- data/spec/models/spree/stock/splitter/base_spec.rb +21 -0
- data/spec/models/spree/stock/splitter/shipping_category_spec.rb +47 -0
- data/spec/models/spree/stock/splitter/weight_spec.rb +32 -0
- data/spec/models/spree/stock_item_spec.rb +410 -0
- data/spec/models/spree/stock_location_spec.rb +243 -0
- data/spec/models/spree/stock_movement_spec.rb +56 -0
- data/spec/models/spree/stock_transfer_spec.rb +50 -0
- data/spec/models/spree/store_spec.rb +50 -0
- data/spec/models/spree/tax_category_spec.rb +27 -0
- data/spec/models/spree/tax_rate_spec.rb +382 -0
- data/spec/models/spree/taxon_spec.rb +74 -0
- data/spec/models/spree/taxonomy_spec.rb +18 -0
- data/spec/models/spree/tracker_spec.rb +21 -0
- data/spec/models/spree/user_spec.rb +130 -0
- data/spec/models/spree/validations/db_maximum_length_validator_spec.rb +24 -0
- data/spec/models/spree/variant_spec.rb +523 -0
- data/spec/models/spree/zone_spec.rb +444 -0
- data/spec/spec_helper.rb +74 -0
- data/spec/support/big_decimal.rb +5 -0
- data/spec/support/concerns/adjustment_source_spec.rb +23 -0
- data/spec/support/concerns/default_price_spec.rb +28 -0
- data/spec/support/rake.rb +13 -0
- data/spec/support/test_gateway.rb +2 -0
- data/spree_core.gemspec +48 -0
- metadata +185 -4
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Spree
|
4
|
+
describe ShippingCalculator, :type => :model do
|
5
|
+
let(:variant1) { build(:variant, :price => 10) }
|
6
|
+
let(:variant2) { build(:variant, :price => 20) }
|
7
|
+
|
8
|
+
let(:package) do
|
9
|
+
build(:stock_package, variants_contents: { variant1 => 2, variant2 => 1 })
|
10
|
+
end
|
11
|
+
|
12
|
+
subject { ShippingCalculator.new }
|
13
|
+
|
14
|
+
it 'computes with a shipment' do
|
15
|
+
shipment = mock_model(Spree::Shipment)
|
16
|
+
expect(subject).to receive(:compute_shipment).with(shipment)
|
17
|
+
subject.compute(shipment)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'computes with a package' do
|
21
|
+
expect(subject).to receive(:compute_package).with(package)
|
22
|
+
subject.compute(package)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'compute_shipment must be overridden' do
|
26
|
+
expect {
|
27
|
+
subject.compute_shipment(shipment)
|
28
|
+
}.to raise_error
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'compute_package must be overridden' do
|
32
|
+
expect {
|
33
|
+
subject.compute_package(package)
|
34
|
+
}.to raise_error
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'checks availability for a package' do
|
38
|
+
expect(subject.available?(package)).to be true
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'calculates totals for content_items' do
|
42
|
+
expect(subject.send(:total, package.contents)).to eq 40.00
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class DummyShippingCalculator < Spree::ShippingCalculator
|
4
|
+
end
|
5
|
+
|
6
|
+
describe Spree::ShippingMethod, :type => :model do
|
7
|
+
let(:shipping_method){ create(:shipping_method) }
|
8
|
+
|
9
|
+
context 'calculators' do
|
10
|
+
it "Should reject calculators that don't inherit from Spree::ShippingCalculator" do
|
11
|
+
allow(Spree::ShippingMethod).to receive_message_chain(:spree_calculators, :shipping_methods).and_return([
|
12
|
+
Spree::Calculator::Shipping::FlatPercentItemTotal,
|
13
|
+
Spree::Calculator::Shipping::PriceSack,
|
14
|
+
Spree::Calculator::DefaultTax,
|
15
|
+
DummyShippingCalculator # included as regression test for https://github.com/spree/spree/issues/3109
|
16
|
+
])
|
17
|
+
|
18
|
+
expect(Spree::ShippingMethod.calculators).to eq([Spree::Calculator::Shipping::FlatPercentItemTotal, Spree::Calculator::Shipping::PriceSack, DummyShippingCalculator ])
|
19
|
+
expect(Spree::ShippingMethod.calculators).not_to eq([Spree::Calculator::DefaultTax])
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Regression test for #4492
|
24
|
+
context "#shipments" do
|
25
|
+
let!(:shipping_method) { create(:shipping_method) }
|
26
|
+
let!(:shipment) do
|
27
|
+
shipment = create(:shipment)
|
28
|
+
shipment.shipping_rates.create!(:shipping_method => shipping_method)
|
29
|
+
shipment
|
30
|
+
end
|
31
|
+
|
32
|
+
it "can gather all the related shipments" do
|
33
|
+
expect(shipping_method.shipments).to include(shipment)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "validations" do
|
38
|
+
before { subject.valid? }
|
39
|
+
|
40
|
+
it "validates presence of name" do
|
41
|
+
expect(subject.error_on(:name).size).to eq(1)
|
42
|
+
end
|
43
|
+
|
44
|
+
context "shipping category" do
|
45
|
+
it "validates presence of at least one" do
|
46
|
+
expect(subject.error_on(:base).size).to eq(1)
|
47
|
+
end
|
48
|
+
|
49
|
+
context "one associated" do
|
50
|
+
before { subject.shipping_categories.push create(:shipping_category) }
|
51
|
+
it { expect(subject.error_on(:base).size).to eq(0) }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'factory' do
|
57
|
+
it "should set calculable correctly" do
|
58
|
+
expect(shipping_method.calculator.calculable).to eq(shipping_method)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context "generating tracking URLs" do
|
63
|
+
context "shipping method has a tracking URL mask on file" do
|
64
|
+
let(:tracking_url) { "https://track-o-matic.com/:tracking" }
|
65
|
+
before { allow(subject).to receive(:tracking_url) { tracking_url } }
|
66
|
+
|
67
|
+
context 'tracking number has spaces' do
|
68
|
+
let(:tracking_numbers) { ["1234 5678 9012 3456", "a bcdef"] }
|
69
|
+
let(:expectations) { %w[https://track-o-matic.com/1234%205678%209012%203456 https://track-o-matic.com/a%20bcdef] }
|
70
|
+
|
71
|
+
it "should return a single URL with '%20' in lieu of spaces" do
|
72
|
+
tracking_numbers.each_with_index do |num, i|
|
73
|
+
expect(subject.build_tracking_url(num)).to eq(expectations[i])
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# Regression test for #4320
|
81
|
+
context "soft deletion" do
|
82
|
+
let(:shipping_method) { create(:shipping_method) }
|
83
|
+
it "soft-deletes when destroy is called" do
|
84
|
+
shipping_method.destroy
|
85
|
+
expect(shipping_method.deleted_at).not_to be_blank
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,141 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Spree::ShippingRate, :type => :model do
|
6
|
+
let(:shipment) { create(:shipment) }
|
7
|
+
let(:shipping_method) { create(:shipping_method) }
|
8
|
+
let(:shipping_rate) { Spree::ShippingRate.new(:shipment => shipment,
|
9
|
+
:shipping_method => shipping_method,
|
10
|
+
:cost => 10) }
|
11
|
+
|
12
|
+
context "#display_price" do
|
13
|
+
context "when tax included in price" do
|
14
|
+
context "when the tax rate is from the default zone" do
|
15
|
+
let!(:zone) { create(:zone, :default_tax => true) }
|
16
|
+
let(:tax_rate) do
|
17
|
+
create(:tax_rate,
|
18
|
+
:name => "VAT",
|
19
|
+
:amount => 0.1,
|
20
|
+
:included_in_price => true,
|
21
|
+
:zone => zone)
|
22
|
+
end
|
23
|
+
|
24
|
+
before { shipping_rate.tax_rate = tax_rate }
|
25
|
+
|
26
|
+
it "shows correct tax amount" do
|
27
|
+
expect(shipping_rate.display_price.to_s).to eq("$10.00 (incl. $0.91 #{tax_rate.name})")
|
28
|
+
end
|
29
|
+
|
30
|
+
context "when cost is zero" do
|
31
|
+
before do
|
32
|
+
shipping_rate.cost = 0
|
33
|
+
end
|
34
|
+
|
35
|
+
it "shows no tax amount" do
|
36
|
+
expect(shipping_rate.display_price.to_s).to eq("$0.00")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "when the tax rate is from a non-default zone" do
|
42
|
+
let!(:default_zone) { create(:zone, :default_tax => true) }
|
43
|
+
let!(:non_default_zone) { create(:zone, :default_tax => false) }
|
44
|
+
let(:tax_rate) do
|
45
|
+
create(:tax_rate,
|
46
|
+
:name => "VAT",
|
47
|
+
:amount => 0.1,
|
48
|
+
:included_in_price => true,
|
49
|
+
:zone => non_default_zone)
|
50
|
+
end
|
51
|
+
before { shipping_rate.tax_rate = tax_rate }
|
52
|
+
|
53
|
+
it "shows correct tax amount" do
|
54
|
+
expect(shipping_rate.display_price.to_s).to eq("$10.00 (excl. $0.91 #{tax_rate.name})")
|
55
|
+
end
|
56
|
+
|
57
|
+
context "when cost is zero" do
|
58
|
+
before do
|
59
|
+
shipping_rate.cost = 0
|
60
|
+
end
|
61
|
+
|
62
|
+
it "shows no tax amount" do
|
63
|
+
expect(shipping_rate.display_price.to_s).to eq("$0.00")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context "when tax is additional to price" do
|
70
|
+
let(:tax_rate) { create(:tax_rate, :name => "Sales Tax", :amount => 0.1) }
|
71
|
+
before { shipping_rate.tax_rate = tax_rate }
|
72
|
+
|
73
|
+
it "shows correct tax amount" do
|
74
|
+
expect(shipping_rate.display_price.to_s).to eq("$10.00 (+ $1.00 #{tax_rate.name})")
|
75
|
+
end
|
76
|
+
|
77
|
+
context "when cost is zero" do
|
78
|
+
before do
|
79
|
+
shipping_rate.cost = 0
|
80
|
+
end
|
81
|
+
|
82
|
+
it "shows no tax amount" do
|
83
|
+
expect(shipping_rate.display_price.to_s).to eq("$0.00")
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context "when the currency is JPY" do
|
89
|
+
let(:shipping_rate) { shipping_rate = Spree::ShippingRate.new(:cost => 205)
|
90
|
+
allow(shipping_rate).to receive_messages(:currency => "JPY")
|
91
|
+
shipping_rate }
|
92
|
+
|
93
|
+
it "displays the price in yen" do
|
94
|
+
expect(shipping_rate.display_price.to_s).to eq("¥205")
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
# Regression test for #3829
|
100
|
+
context "#shipping_method" do
|
101
|
+
it "can be retrieved" do
|
102
|
+
expect(shipping_rate.shipping_method.reload).to eq(shipping_method)
|
103
|
+
end
|
104
|
+
|
105
|
+
it "can be retrieved even when deleted" do
|
106
|
+
shipping_method.update_column(:deleted_at, Time.now)
|
107
|
+
shipping_rate.save
|
108
|
+
shipping_rate.reload
|
109
|
+
expect(shipping_rate.shipping_method).to eq(shipping_method)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
context "#tax_rate" do
|
114
|
+
let!(:tax_rate) { create(:tax_rate) }
|
115
|
+
|
116
|
+
before do
|
117
|
+
shipping_rate.tax_rate = tax_rate
|
118
|
+
end
|
119
|
+
|
120
|
+
it "can be retrieved" do
|
121
|
+
expect(shipping_rate.tax_rate.reload).to eq(tax_rate)
|
122
|
+
end
|
123
|
+
|
124
|
+
it "can be retrieved even when deleted" do
|
125
|
+
tax_rate.update_column(:deleted_at, Time.now)
|
126
|
+
shipping_rate.save
|
127
|
+
shipping_rate.reload
|
128
|
+
expect(shipping_rate.tax_rate).to eq(tax_rate)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
context "#shipping_method_code" do
|
133
|
+
before do
|
134
|
+
shipping_method.code = "THE_CODE"
|
135
|
+
end
|
136
|
+
|
137
|
+
it 'should be shipping_method.code' do
|
138
|
+
expect(shipping_rate.shipping_method_code).to eq("THE_CODE")
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::State, :type => :model do
|
4
|
+
it "can find a state by name or abbr" do
|
5
|
+
state = create(:state, :name => "California", :abbr => "CA")
|
6
|
+
expect(Spree::State.find_all_by_name_or_abbr("California")).to include(state)
|
7
|
+
expect(Spree::State.find_all_by_name_or_abbr("CA")).to include(state)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "can find all states group by country id" do
|
11
|
+
state = create(:state)
|
12
|
+
expect(Spree::State.states_group_by_country_id).to eq({ state.country_id.to_s => [[state.id, state.name]] })
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'whitelisted_ransackable_attributes' do
|
16
|
+
it { expect(Spree::State.whitelisted_ransackable_attributes).to eq(%w(abbr)) }
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Spree
|
4
|
+
module Stock
|
5
|
+
describe AvailabilityValidator, :type => :model do
|
6
|
+
let!(:line_item) { double(quantity: 5, variant_id: 1, variant: double.as_null_object, errors: double('errors'), inventory_units: []) }
|
7
|
+
|
8
|
+
subject { described_class.new }
|
9
|
+
|
10
|
+
it 'should be valid when supply is sufficient' do
|
11
|
+
allow_any_instance_of(Stock::Quantifier).to receive_messages(can_supply?: true)
|
12
|
+
expect(line_item).not_to receive(:errors)
|
13
|
+
subject.validate(line_item)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should be invalid when supply is insufficent' do
|
17
|
+
allow_any_instance_of(Stock::Quantifier).to receive_messages(can_supply?: false)
|
18
|
+
expect(line_item.errors).to receive(:[]).with(:quantity).and_return []
|
19
|
+
subject.validate(line_item)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should consider existing inventory_units sufficient' do
|
23
|
+
allow_any_instance_of(Stock::Quantifier).to receive_messages(can_supply?: false)
|
24
|
+
expect(line_item).not_to receive(:errors)
|
25
|
+
allow(line_item).to receive_messages(inventory_units: [double] * 5)
|
26
|
+
subject.validate(line_item)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should be valid when the quantity is zero' do
|
30
|
+
expect(line_item).to receive(:quantity).and_return(0)
|
31
|
+
expect(line_item.errors).to_not receive(:[]).with(:quantity)
|
32
|
+
subject.validate(line_item)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Spree
|
4
|
+
module Stock
|
5
|
+
describe ContentItem, type: :model do
|
6
|
+
let(:variant) { build(:variant, weight: 25.0) }
|
7
|
+
subject { ContentItem.new(build(:inventory_unit, variant: variant)) }
|
8
|
+
|
9
|
+
context "#volume" do
|
10
|
+
it "calculate the total volume of the variant" do
|
11
|
+
expect(subject.volume).to eq variant.volume * subject.quantity
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context "#dimension" do
|
16
|
+
it "calculate the total dimension of the variant" do
|
17
|
+
expect(subject.dimension).to eq variant.dimension * subject.quantity
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Spree
|
4
|
+
module Stock
|
5
|
+
describe Coordinator, :type => :model do
|
6
|
+
let!(:order) { create(:order_with_line_items) }
|
7
|
+
|
8
|
+
subject { Coordinator.new(order) }
|
9
|
+
|
10
|
+
context "packages" do
|
11
|
+
it "builds, prioritizes and estimates" do
|
12
|
+
expect(subject).to receive(:build_packages).ordered
|
13
|
+
expect(subject).to receive(:prioritize_packages).ordered
|
14
|
+
expect(subject).to receive(:estimate_packages).ordered
|
15
|
+
subject.packages
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#shipments" do
|
20
|
+
let(:packages) { [build(:stock_package_fulfilled), build(:stock_package_fulfilled)] }
|
21
|
+
|
22
|
+
before { allow(subject).to receive(:packages).and_return(packages) }
|
23
|
+
|
24
|
+
it "turns packages into shipments" do
|
25
|
+
shipments = subject.shipments
|
26
|
+
expect(shipments.count).to eq packages.count
|
27
|
+
shipments.each { |shipment| expect(shipment).to be_a Shipment }
|
28
|
+
end
|
29
|
+
|
30
|
+
it "puts the order's ship address on the shipments" do
|
31
|
+
shipments = subject.shipments
|
32
|
+
shipments.each { |shipment| expect(shipment.address).to eq order.ship_address }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "build packages" do
|
37
|
+
it "builds a package for every stock location" do
|
38
|
+
subject.packages.count == StockLocation.count
|
39
|
+
end
|
40
|
+
|
41
|
+
context "missing stock items in stock location" do
|
42
|
+
let!(:another_location) { create(:stock_location, propagate_all_variants: false) }
|
43
|
+
|
44
|
+
it "builds packages only for valid stock locations" do
|
45
|
+
expect(subject.build_packages.count).to eq(StockLocation.count - 1)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Spree
|
4
|
+
module Stock
|
5
|
+
describe Differentiator, :type => :model do
|
6
|
+
let(:variant1) { mock_model(Variant) }
|
7
|
+
let(:variant2) { mock_model(Variant) }
|
8
|
+
|
9
|
+
let(:line_item1) { build(:line_item, variant: variant1, quantity: 2) }
|
10
|
+
let(:line_item2) { build(:line_item, variant: variant2, quantity: 2) }
|
11
|
+
|
12
|
+
let(:stock_location) { mock_model(StockLocation) }
|
13
|
+
|
14
|
+
let(:inventory_unit1) { build(:inventory_unit, variant: variant1, line_item: line_item1) }
|
15
|
+
let(:inventory_unit2) { build(:inventory_unit, variant: variant2, line_item: line_item2) }
|
16
|
+
|
17
|
+
let(:order) { mock_model(Order, line_items: [line_item1, line_item2]) }
|
18
|
+
|
19
|
+
let(:package1) do
|
20
|
+
Package.new(stock_location).tap { |p| p.add(inventory_unit1) }
|
21
|
+
end
|
22
|
+
|
23
|
+
let(:package2) do
|
24
|
+
Package.new(stock_location).tap { |p| p.add(inventory_unit2) }
|
25
|
+
end
|
26
|
+
|
27
|
+
let(:packages) { [package1, package2] }
|
28
|
+
|
29
|
+
subject { Differentiator.new(order, packages) }
|
30
|
+
|
31
|
+
it { is_expected.to be_missing }
|
32
|
+
|
33
|
+
it 'calculates the missing items' do
|
34
|
+
expect(subject.missing[variant1]).to eq 1
|
35
|
+
expect(subject.missing[variant2]).to eq 1
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|