solidus_core 2.2.2 → 2.3.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 +4 -7
- data/app/assets/javascripts/spree.js.erb +2 -2
- data/app/helpers/spree/base_helper.rb +3 -4
- data/app/models/spree/address.rb +1 -1
- data/app/models/spree/adjustment.rb +3 -1
- data/app/models/spree/app_configuration.rb +43 -0
- data/app/models/spree/billing_integration.rb +2 -2
- data/app/models/spree/calculator/default_tax.rb +3 -1
- data/app/models/spree/calculator/distributed_amount.rb +24 -0
- data/app/models/spree/calculator/free_shipping.rb +0 -1
- data/app/models/spree/calculator/tiered_flat_rate.rb +17 -3
- data/app/models/spree/calculator/tiered_percent.rb +18 -3
- data/app/models/spree/distributed_amounts_handler.rb +43 -0
- data/app/models/spree/gateway/bogus.rb +7 -83
- data/app/models/spree/gateway/bogus_simple.rb +7 -20
- data/app/models/spree/gateway.rb +8 -58
- data/app/models/spree/image.rb +1 -1
- data/app/models/spree/line_item.rb +1 -1
- data/app/models/spree/option_value.rb +1 -1
- data/app/models/spree/order/checkout.rb +1 -4
- data/app/models/spree/order/number_generator.rb +43 -0
- data/app/models/spree/order.rb +33 -38
- data/app/models/spree/order_contents.rb +1 -1
- data/app/models/spree/order_taxation.rb +79 -0
- data/app/models/spree/order_update_attributes.rb +0 -2
- data/app/models/spree/order_updater.rb +55 -33
- data/app/models/spree/payment.rb +0 -1
- data/app/models/spree/payment_method/bogus_credit_card.rb +87 -0
- data/app/models/spree/payment_method/check.rb +14 -6
- data/app/models/spree/payment_method/credit_card.rb +41 -0
- data/app/models/spree/payment_method/simple_bogus_credit_card.rb +24 -0
- data/app/models/spree/payment_method/store_credit.rb +5 -13
- data/app/models/spree/payment_method.rb +126 -40
- data/app/models/spree/preferences/preferable.rb +5 -1
- data/app/models/spree/preferences/store.rb +2 -2
- data/app/models/spree/product/scopes.rb +14 -1
- data/app/models/spree/product.rb +10 -4
- data/app/models/spree/promotion_action.rb +4 -0
- data/app/models/spree/promotion_code/batch_builder.rb +3 -2
- data/app/models/spree/promotion_rule.rb +4 -0
- data/app/models/spree/role.rb +2 -0
- data/app/models/spree/role_user.rb +2 -0
- data/app/models/spree/shipment.rb +4 -2
- data/app/models/spree/shipping_method.rb +3 -1
- data/app/models/spree/shipping_rate.rb +1 -1
- data/app/models/spree/state.rb +10 -2
- data/app/models/spree/stock_item.rb +3 -3
- data/app/models/spree/store.rb +5 -0
- data/app/models/spree/store_credit.rb +2 -2
- data/app/models/spree/store_credit_event.rb +1 -1
- data/app/models/spree/store_selector/by_server_name.rb +30 -0
- data/app/models/spree/store_selector/legacy.rb +48 -0
- data/app/models/spree/tax/item_tax.rb +20 -0
- data/app/models/spree/tax/order_adjuster.rb +2 -14
- data/app/models/spree/tax/order_tax.rb +18 -0
- data/app/models/spree/tax/shipping_rate_taxer.rb +4 -13
- data/app/models/spree/tax/tax_helpers.rb +5 -3
- data/app/models/spree/tax_calculator/default.rb +83 -0
- data/app/models/spree/tax_calculator/shipping_rate.rb +46 -0
- data/app/models/spree/tax_category.rb +9 -1
- data/app/models/spree/tax_rate.rb +31 -7
- data/app/models/spree/tax_rate_tax_category.rb +6 -0
- data/app/models/spree/taxon.rb +1 -1
- data/app/models/spree/variant.rb +1 -1
- data/app/views/spree/{shipment_mailer → carton_mailer}/shipped_email.html.erb +3 -3
- data/app/views/spree/order_mailer/cancel_email.html.erb +3 -3
- data/app/views/spree/order_mailer/confirm_email.html.erb +2 -2
- data/app/views/spree/order_mailer/inventory_cancellation_email.html.erb +26 -0
- data/app/views/spree/reimbursement_mailer/reimbursement_email.html.erb +2 -2
- data/app/views/spree/test_mailer/test_email.html.erb +2 -2
- data/config/locales/en.yml +66 -57
- data/db/default/spree/refund_reasons.rb +1 -0
- data/db/default/spree/shipping_categories.rb +1 -0
- data/db/default/spree/stock_locations.rb +2 -0
- data/db/default/spree/stores.rb +3 -4
- data/db/migrate/20170412103617_transform_tax_rate_category_relation.rb +48 -0
- data/db/migrate/20170422134804_add_roles_unique_constraints.rb +6 -0
- data/db/migrate/20170522143442_add_time_range_to_tax_rate.rb +6 -0
- data/db/migrate/20170608074534_rename_bogus_gateways.rb +13 -0
- data/lib/generators/spree/custom_user/custom_user_generator.rb +1 -1
- data/lib/generators/spree/dummy/dummy_generator.rb +10 -4
- data/lib/generators/spree/dummy/templates/rails/database.yml +12 -12
- data/lib/generators/spree/install/install_generator.rb +5 -5
- data/lib/generators/spree/install/templates/config/initializers/{spree.rb → solidus.rb} +0 -0
- data/lib/solidus/migrations/rename_gateways.rb +39 -0
- data/lib/spree/core/controller_helpers/auth.rb +1 -1
- data/lib/spree/core/controller_helpers/order.rb +10 -5
- data/lib/spree/core/controller_helpers/store.rb +1 -9
- data/lib/spree/core/current_store.rb +6 -14
- data/lib/spree/core/engine.rb +4 -3
- data/lib/spree/core/importer/order.rb +4 -4
- data/lib/spree/core/version.rb +1 -1
- data/lib/spree/core.rb +0 -1
- data/lib/spree/localized_number.rb +2 -1
- data/lib/spree/permitted_attributes.rb +12 -6
- data/lib/spree/testing_support/capybara_ext.rb +0 -1
- data/lib/spree/testing_support/factories/adjustment_factory.rb +5 -1
- data/lib/spree/testing_support/factories/order_factory.rb +26 -24
- data/lib/spree/testing_support/factories/payment_factory.rb +4 -0
- data/lib/spree/testing_support/factories/payment_method_factory.rb +3 -3
- data/lib/spree/testing_support/factories/shipment_factory.rb +7 -3
- data/lib/spree/testing_support/factories/tax_rate_factory.rb +1 -1
- data/lib/spree/testing_support/factories/variant_factory.rb +3 -1
- data/lib/tasks/migrations/copy_order_bill_address_to_credit_card.rake +0 -4
- data/lib/tasks/migrations/migrate_user_addresses.rake +2 -2
- data/lib/tasks/migrations/rename_gateways.rake +19 -0
- data/solidus_core.gemspec +2 -3
- data/spec/lib/spree/core/controller_helpers/order_spec.rb +32 -6
- data/spec/lib/spree/core/controller_helpers/payment_parameters_spec.rb +0 -1
- data/spec/lib/spree/core/current_store_spec.rb +6 -11
- data/spec/lib/spree/core/price_migrator_spec.rb +4 -4
- data/spec/lib/spree/core/testing_support/factories/order_factory_spec.rb +199 -91
- data/spec/lib/spree/core/testing_support/factories/variant_factory_spec.rb +18 -0
- data/spec/lib/spree/localized_number_spec.rb +6 -0
- data/spec/mailers/carton_mailer_spec.rb +3 -3
- data/spec/models/spree/address_spec.rb +3 -3
- data/spec/models/spree/adjustment_spec.rb +71 -27
- data/spec/models/spree/calculator/default_tax_spec.rb +72 -1
- data/spec/models/spree/calculator/distributed_amount_spec.rb +32 -0
- data/spec/models/spree/calculator/tiered_flat_rate_spec.rb +20 -1
- data/spec/models/spree/calculator/tiered_percent_spec.rb +20 -1
- data/spec/models/spree/distributed_amounts_handler_spec.rb +79 -0
- data/spec/models/spree/gateway/bogus_simple.rb +7 -13
- data/spec/models/spree/gateway/bogus_spec.rb +8 -4
- data/spec/models/spree/gateway_spec.rb +6 -105
- data/spec/models/spree/image_spec.rb +23 -0
- data/spec/models/spree/order/checkout_spec.rb +3 -18
- data/spec/models/spree/order/number_generator_spec.rb +45 -0
- data/spec/models/spree/order/outstanding_balance_integration_spec.rb +135 -0
- data/spec/models/spree/order/payment_spec.rb +7 -2
- data/spec/models/spree/order/state_machine_spec.rb +4 -2
- data/spec/models/spree/order_capturing_spec.rb +8 -8
- data/spec/models/spree/order_contents_spec.rb +8 -1
- data/spec/models/spree/order_shipping_spec.rb +5 -1
- data/spec/models/spree/order_spec.rb +156 -83
- data/spec/models/spree/order_taxation_spec.rb +126 -0
- data/spec/models/spree/order_update_attributes_spec.rb +1 -5
- data/spec/models/spree/order_updater_spec.rb +20 -21
- data/spec/models/spree/payment_create_spec.rb +14 -6
- data/spec/models/spree/payment_method/bogus_credit_card_spec.rb +8 -0
- data/spec/models/spree/payment_method/check_spec.rb +78 -0
- data/spec/models/spree/payment_method/credit_card_spec.rb +66 -0
- data/spec/models/spree/payment_method/simple_bogus_credit_card_spec.rb +18 -0
- data/spec/models/spree/payment_method_spec.rb +47 -2
- data/spec/models/spree/payment_spec.rb +6 -8
- data/spec/models/spree/preference_spec.rb +1 -1
- data/spec/models/spree/price_spec.rb +1 -1
- data/spec/models/spree/product/scopes_spec.rb +46 -0
- data/spec/models/spree/promotion_action_spec.rb +4 -0
- data/spec/models/spree/promotion_code/batch_builder_spec.rb +25 -3
- data/spec/models/spree/promotion_code_batch_spec.rb +0 -6
- data/spec/models/spree/promotion_handler/coupon_spec.rb +1 -1
- data/spec/models/spree/promotion_rule_spec.rb +5 -0
- data/spec/models/spree/reimbursement_type/original_payment_spec.rb +1 -1
- data/spec/models/spree/shipment_spec.rb +24 -3
- data/spec/models/spree/shipping_rate_spec.rb +5 -5
- data/spec/models/spree/state_spec.rb +31 -4
- data/spec/models/spree/stock/coordinator_spec.rb +24 -0
- data/spec/models/spree/stock/estimator_spec.rb +1 -1
- data/spec/models/spree/store_selector/by_server_name_spec.rb +26 -0
- data/spec/models/spree/store_selector/legacy_spec.rb +44 -0
- data/spec/models/spree/store_spec.rb +10 -2
- data/spec/models/spree/tax/order_adjuster_spec.rb +11 -21
- data/spec/models/spree/tax/shipping_rate_taxer_spec.rb +10 -3
- data/spec/models/spree/tax/taxation_integration_spec.rb +43 -8
- data/spec/models/spree/tax_calculator/default_spec.rb +54 -0
- data/spec/models/spree/tax_rate_spec.rb +92 -0
- data/spec/models/spree/variant/vat_price_generator_spec.rb +4 -4
- data/spec/models/spree/variant_spec.rb +8 -2
- data/spec/spec_helper.rb +2 -1
- data/spec/support/test_gateway.rb +1 -1
- metadata +45 -24
- data/app/models/spree/tax/item_adjuster.rb +0 -51
- data/spec/models/spree/tax/item_adjuster_spec.rb +0 -82
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
FactoryGirl.define do
|
|
2
|
-
factory :payment_method, aliases: [:credit_card_payment_method], class: Spree::
|
|
2
|
+
factory :payment_method, aliases: [:credit_card_payment_method], class: Spree::PaymentMethod::BogusCreditCard do
|
|
3
3
|
name 'Credit Card'
|
|
4
4
|
available_to_admin true
|
|
5
5
|
available_to_users true
|
|
@@ -13,7 +13,7 @@ FactoryGirl.define do
|
|
|
13
13
|
|
|
14
14
|
# authorize.net was moved to spree_gateway.
|
|
15
15
|
# Leaving this factory in place with bogus in case anyone is using it.
|
|
16
|
-
factory :simple_credit_card_payment_method, class: Spree::
|
|
16
|
+
factory :simple_credit_card_payment_method, class: Spree::PaymentMethod::SimpleBogusCreditCard do
|
|
17
17
|
name 'Credit Card'
|
|
18
18
|
available_to_admin true
|
|
19
19
|
available_to_users true
|
|
@@ -25,6 +25,6 @@ FactoryGirl.define do
|
|
|
25
25
|
active true
|
|
26
26
|
available_to_admin false
|
|
27
27
|
available_to_users false
|
|
28
|
-
auto_capture
|
|
28
|
+
auto_capture true
|
|
29
29
|
end
|
|
30
30
|
end
|
|
@@ -14,9 +14,13 @@ FactoryGirl.define do
|
|
|
14
14
|
shipping_method nil
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
after(:create) do |shipment,
|
|
18
|
-
shipping_method =
|
|
19
|
-
shipment.
|
|
17
|
+
after(:create) do |shipment, evaluator|
|
|
18
|
+
shipping_method = evaluator.shipping_method || create(:shipping_method, cost: evaluator.cost)
|
|
19
|
+
shipment.shipping_rates.create!(
|
|
20
|
+
shipping_method: shipping_method,
|
|
21
|
+
cost: evaluator.cost,
|
|
22
|
+
selected: true
|
|
23
|
+
)
|
|
20
24
|
|
|
21
25
|
shipment.order.line_items.each do |line_item|
|
|
22
26
|
line_item.quantity.times do
|
|
@@ -14,7 +14,6 @@ FactoryGirl.define do
|
|
|
14
14
|
track_inventory true
|
|
15
15
|
|
|
16
16
|
product { |p| p.association(:base_product) }
|
|
17
|
-
option_values { [create(:option_value)] }
|
|
18
17
|
|
|
19
18
|
# ensure stock item will be created for this variant
|
|
20
19
|
before(:create) { create(:stock_location) if Spree::StockLocation.count == 0 }
|
|
@@ -22,10 +21,13 @@ FactoryGirl.define do
|
|
|
22
21
|
factory :variant do
|
|
23
22
|
# on_hand 5
|
|
24
23
|
product { |p| p.association(:product) }
|
|
24
|
+
option_values { [create(:option_value)] }
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
factory :master_variant do
|
|
28
28
|
is_master 1
|
|
29
|
+
before(:create){ |variant| variant.product.master = variant }
|
|
30
|
+
product { build(:base_product) }
|
|
29
31
|
end
|
|
30
32
|
|
|
31
33
|
factory :on_demand_variant do
|
|
@@ -11,8 +11,6 @@ namespace 'spree:migrations:copy_order_bill_address_to_credit_card' do
|
|
|
11
11
|
# This task should be safe to run multiple times.
|
|
12
12
|
|
|
13
13
|
task up: :environment do
|
|
14
|
-
puts "Copying order bill addresses to credit cards"
|
|
15
|
-
|
|
16
14
|
if Spree::CreditCard.connection.adapter_name =~ /postgres/i
|
|
17
15
|
postgres_copy
|
|
18
16
|
else
|
|
@@ -52,8 +50,6 @@ namespace 'spree:migrations:copy_order_bill_address_to_credit_card' do
|
|
|
52
50
|
def postgres_copy
|
|
53
51
|
batch_size = 10_000
|
|
54
52
|
|
|
55
|
-
puts "last id: #{last_credit_card_id}"
|
|
56
|
-
|
|
57
53
|
current_start_id = 1
|
|
58
54
|
|
|
59
55
|
while current_start_id <= last_credit_card_id
|
|
@@ -9,8 +9,8 @@ namespace 'spree:migrations:migrate_user_addresses' do
|
|
|
9
9
|
|
|
10
10
|
task up: :environment do
|
|
11
11
|
Spree.user_class.find_each(batch_size: 500) do |user|
|
|
12
|
-
ship_address = Spree::Address.
|
|
13
|
-
bill_address = Spree::Address.
|
|
12
|
+
ship_address = Spree::Address.find_by(id: user.ship_address_id)
|
|
13
|
+
bill_address = Spree::Address.find_by(id: user.bill_address_id)
|
|
14
14
|
|
|
15
15
|
current_addresses = [bill_address, ship_address].compact.uniq
|
|
16
16
|
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require 'solidus/migrations/rename_gateways'
|
|
2
|
+
|
|
3
|
+
namespace 'solidus:migrations:rename_gateways' do
|
|
4
|
+
task up: :environment do
|
|
5
|
+
count = Solidus::Migrations::RenameGateways.new.up
|
|
6
|
+
|
|
7
|
+
unless ENV['VERBOSE'] == 'false' || !verbose
|
|
8
|
+
puts "Renamed #{count} gateways into payment methods."
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
task down: :environment do
|
|
13
|
+
count = Solidus::Migrations::RenameGateways.new.down
|
|
14
|
+
|
|
15
|
+
unless ENV['VERBOSE'] == 'false' || !verbose
|
|
16
|
+
puts "Renamed #{count} payment methods into gateways."
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
data/solidus_core.gemspec
CHANGED
|
@@ -31,9 +31,8 @@ Gem::Specification.new do |s|
|
|
|
31
31
|
s.add_dependency 'kaminari', '>= 0.17', '< 2.0'
|
|
32
32
|
s.add_dependency 'monetize', '~> 1.1'
|
|
33
33
|
s.add_dependency 'paperclip', ['>= 4.2', '< 6']
|
|
34
|
-
s.add_dependency 'paranoia', '~> 2.
|
|
35
|
-
s.add_dependency '
|
|
36
|
-
s.add_dependency 'rails', '~> 5.0.0'
|
|
34
|
+
s.add_dependency 'paranoia', '~> 2.3'
|
|
35
|
+
s.add_dependency 'rails', '~> 5.1.0'
|
|
37
36
|
s.add_dependency 'ransack', '~> 1.8'
|
|
38
37
|
s.add_dependency 'responders'
|
|
39
38
|
s.add_dependency 'state_machines-activerecord', '~> 0.4'
|
|
@@ -19,11 +19,26 @@ describe Spree::Core::ControllerHelpers::Order, type: :controller do
|
|
|
19
19
|
|
|
20
20
|
describe '#simple_current_order' do
|
|
21
21
|
it "returns an empty order" do
|
|
22
|
-
|
|
22
|
+
Spree::Deprecation.silence do
|
|
23
|
+
expect(controller.simple_current_order.item_count).to eq 0
|
|
24
|
+
end
|
|
23
25
|
end
|
|
24
26
|
it 'returns Spree::Order instance' do
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
Spree::Deprecation.silence do
|
|
28
|
+
allow(controller).to receive_messages(cookies: double(signed: { guest_token: order.guest_token }))
|
|
29
|
+
expect(controller.simple_current_order).to eq order
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
it 'assigns the current_store id' do
|
|
33
|
+
Spree::Deprecation.silence do
|
|
34
|
+
expect(controller.simple_current_order.store_id).to eq store.id
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
it 'is deprecated' do
|
|
38
|
+
Spree::Deprecation.silence do
|
|
39
|
+
expect(Spree::Deprecation).to(receive(:warn))
|
|
40
|
+
controller.simple_current_order
|
|
41
|
+
end
|
|
27
42
|
end
|
|
28
43
|
end
|
|
29
44
|
|
|
@@ -34,17 +49,28 @@ describe Spree::Core::ControllerHelpers::Order, type: :controller do
|
|
|
34
49
|
expect(controller.current_order).to eq order
|
|
35
50
|
end
|
|
36
51
|
end
|
|
52
|
+
|
|
37
53
|
context 'create_order_if_necessary option is true' do
|
|
54
|
+
subject { controller.current_order(create_order_if_necessary: true) }
|
|
55
|
+
|
|
38
56
|
it 'creates new order' do
|
|
39
57
|
expect {
|
|
40
|
-
|
|
41
|
-
}.to change(Spree::Order, :count).to(1)
|
|
58
|
+
subject
|
|
59
|
+
}.to change(Spree::Order, :count).from(0).to(1)
|
|
42
60
|
end
|
|
43
61
|
|
|
44
62
|
it 'assigns the current_store id' do
|
|
45
|
-
|
|
63
|
+
subject
|
|
46
64
|
expect(Spree::Order.last.store_id).to eq store.id
|
|
47
65
|
end
|
|
66
|
+
|
|
67
|
+
it 'records last_ip_address' do
|
|
68
|
+
expect {
|
|
69
|
+
subject
|
|
70
|
+
}.to change {
|
|
71
|
+
Spree::Order.last.try!(:last_ip_address)
|
|
72
|
+
}.from(nil).to("0.0.0.0")
|
|
73
|
+
end
|
|
48
74
|
end
|
|
49
75
|
end
|
|
50
76
|
|
|
@@ -11,7 +11,6 @@ describe Spree::Core::ControllerHelpers::PaymentParameters, type: :controller do
|
|
|
11
11
|
it "is unpermitted ActionController::Parameters" do
|
|
12
12
|
expect(subject).to be_a(ActionController::Parameters)
|
|
13
13
|
expect(subject).not_to be_permitted
|
|
14
|
-
expect(subject.to_h).to eq({})
|
|
15
14
|
end
|
|
16
15
|
end
|
|
17
16
|
|
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
|
2
2
|
|
|
3
3
|
describe Spree::Core::CurrentStore do
|
|
4
4
|
describe "#store" do
|
|
5
|
-
subject { Spree::Core::CurrentStore.new(request).store }
|
|
5
|
+
subject { Spree::Deprecation.silence { Spree::Core::CurrentStore.new(request).store } }
|
|
6
6
|
|
|
7
7
|
context "with a default" do
|
|
8
8
|
let(:request) { double(headers: {}, env: {}) }
|
|
@@ -20,17 +20,12 @@ describe Spree::Core::CurrentStore do
|
|
|
20
20
|
it "returns the store with the matching domain" do
|
|
21
21
|
expect(subject).to eq(store_2)
|
|
22
22
|
end
|
|
23
|
-
|
|
24
|
-
context "with headers" do
|
|
25
|
-
let(:request) { double(headers: { "HTTP_SPREE_STORE" => headers_code }, env: {}) }
|
|
26
|
-
let(:headers_code) { "HEADERS" }
|
|
27
|
-
let!(:store_3) { create :store, code: headers_code, default: false }
|
|
28
|
-
|
|
29
|
-
it "returns the store with the matching code" do
|
|
30
|
-
expect(subject).to eq(store_3)
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
23
|
end
|
|
34
24
|
end
|
|
25
|
+
|
|
26
|
+
it 'is deprecated' do
|
|
27
|
+
expect(Spree::Deprecation).to(receive(:warn))
|
|
28
|
+
Spree::Core::CurrentStore.new(double)
|
|
29
|
+
end
|
|
35
30
|
end
|
|
36
31
|
end
|
|
@@ -55,7 +55,7 @@ describe Spree::PriceMigrator do
|
|
|
55
55
|
name: "German reduced VAT",
|
|
56
56
|
included_in_price: true,
|
|
57
57
|
amount: 0.07,
|
|
58
|
-
|
|
58
|
+
tax_categories: [books_category],
|
|
59
59
|
zone: eu_zone
|
|
60
60
|
)
|
|
61
61
|
end
|
|
@@ -65,7 +65,7 @@ describe Spree::PriceMigrator do
|
|
|
65
65
|
name: "German VAT",
|
|
66
66
|
included_in_price: true,
|
|
67
67
|
amount: 0.19,
|
|
68
|
-
|
|
68
|
+
tax_categories: [normal_category],
|
|
69
69
|
zone: eu_zone
|
|
70
70
|
)
|
|
71
71
|
end
|
|
@@ -75,7 +75,7 @@ describe Spree::PriceMigrator do
|
|
|
75
75
|
name: "German VAT",
|
|
76
76
|
included_in_price: true,
|
|
77
77
|
amount: 0.19,
|
|
78
|
-
|
|
78
|
+
tax_categories: [digital_category],
|
|
79
79
|
zone: germany_zone
|
|
80
80
|
)
|
|
81
81
|
end
|
|
@@ -85,7 +85,7 @@ describe Spree::PriceMigrator do
|
|
|
85
85
|
name: "Romanian VAT",
|
|
86
86
|
included_in_price: true,
|
|
87
87
|
amount: 0.24,
|
|
88
|
-
|
|
88
|
+
tax_categories: [digital_category],
|
|
89
89
|
zone: romania_zone
|
|
90
90
|
)
|
|
91
91
|
end
|
|
@@ -1,6 +1,126 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
require 'spree/testing_support/factories/order_factory'
|
|
3
3
|
|
|
4
|
+
shared_examples "shipping methods are assigned" do
|
|
5
|
+
context "given a shipping method" do
|
|
6
|
+
let(:shipping_method) { create(:shipping_method) }
|
|
7
|
+
|
|
8
|
+
it "assigns the shipping method when created" do
|
|
9
|
+
expect(
|
|
10
|
+
create(
|
|
11
|
+
factory,
|
|
12
|
+
shipping_method: shipping_method
|
|
13
|
+
).shipments.map(&:shipping_method)
|
|
14
|
+
).to all(eq(shipping_method))
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "assigns the shipping method when built" do
|
|
18
|
+
expect(
|
|
19
|
+
build(
|
|
20
|
+
factory,
|
|
21
|
+
shipping_method: shipping_method
|
|
22
|
+
).shipments.map(&:shipping_method)
|
|
23
|
+
).to all(eq(shipping_method))
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
RSpec.shared_examples "an order with line items factory" do |expected_order_state, expected_inventory_unit_state|
|
|
29
|
+
# This factory cannot be built correctly because Shipment#set_up_inventory
|
|
30
|
+
# requires records to be saved.
|
|
31
|
+
context "when created" do
|
|
32
|
+
let(:stock_location) { create(:stock_location) }
|
|
33
|
+
let(:first_variant) { create(:variant) }
|
|
34
|
+
let(:second_variant) { create(:variant) }
|
|
35
|
+
let(:shipping_method) { create(:shipping_method) }
|
|
36
|
+
let(:order) do
|
|
37
|
+
create(
|
|
38
|
+
factory,
|
|
39
|
+
stock_location: stock_location,
|
|
40
|
+
line_items_attributes: [
|
|
41
|
+
{ variant: first_variant, quantity: 1, price: 1 },
|
|
42
|
+
{ variant: second_variant, quantity: 2, price: 2 }
|
|
43
|
+
],
|
|
44
|
+
shipment_cost: 3,
|
|
45
|
+
shipping_method: shipping_method
|
|
46
|
+
)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it "has the expected attributes" do
|
|
50
|
+
aggregate_failures "for line items" do
|
|
51
|
+
expect(order.line_items.count).to eq 2
|
|
52
|
+
expect(order.line_items[0]).to have_attributes(
|
|
53
|
+
quantity: 1,
|
|
54
|
+
price: 1.0
|
|
55
|
+
)
|
|
56
|
+
expect(order.line_items[1]).to have_attributes(
|
|
57
|
+
price: 2.0,
|
|
58
|
+
quantity: 2
|
|
59
|
+
)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
aggregate_failures "for shipments" do
|
|
63
|
+
expect(order.shipments.count).to eq 1
|
|
64
|
+
expect(order.shipments[0]).to have_attributes(
|
|
65
|
+
amount: 3.0,
|
|
66
|
+
stock_location: stock_location
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
expect(order.shipments[0].shipping_method).to eq(shipping_method)
|
|
70
|
+
|
|
71
|
+
# Explicitly order by line item id, because otherwise these can be in
|
|
72
|
+
# an arbitrary order.
|
|
73
|
+
inventory_units = order.shipments[0].inventory_units.sort_by(&:line_item_id)
|
|
74
|
+
|
|
75
|
+
expect(inventory_units.count).to eq(3)
|
|
76
|
+
expect(inventory_units[0]).to have_attributes(
|
|
77
|
+
order: order,
|
|
78
|
+
shipment: order.shipments[0],
|
|
79
|
+
line_item: order.line_items[0],
|
|
80
|
+
variant: order.line_items[0].variant,
|
|
81
|
+
state: expected_inventory_unit_state
|
|
82
|
+
)
|
|
83
|
+
expect(inventory_units[1]).to have_attributes(
|
|
84
|
+
order: order,
|
|
85
|
+
shipment: order.shipments[0],
|
|
86
|
+
line_item: order.line_items[1],
|
|
87
|
+
variant: order.line_items[1].variant,
|
|
88
|
+
state: expected_inventory_unit_state
|
|
89
|
+
)
|
|
90
|
+
expect(inventory_units[2]).to have_attributes(
|
|
91
|
+
order: order,
|
|
92
|
+
shipment: order.shipments[0],
|
|
93
|
+
line_item: order.line_items[1],
|
|
94
|
+
variant: order.line_items[1].variant,
|
|
95
|
+
state: expected_inventory_unit_state
|
|
96
|
+
)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
expect(order).to have_attributes(
|
|
100
|
+
item_total: 5.0,
|
|
101
|
+
ship_total: 3.0,
|
|
102
|
+
total: 8.0,
|
|
103
|
+
state: expected_order_state
|
|
104
|
+
)
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
context 'when shipments should be taxed' do
|
|
109
|
+
let!(:ship_address) { create(:address) }
|
|
110
|
+
let!(:tax_zone) { create(:global_zone) } # will include the above address
|
|
111
|
+
let!(:tax_rate) { create(:tax_rate, amount: 0.10, zone: tax_zone, tax_categories: [tax_category]) }
|
|
112
|
+
|
|
113
|
+
let(:tax_category) { create(:tax_category) }
|
|
114
|
+
let(:shipping_method) { create(:shipping_method, tax_category: tax_category, zones: [tax_zone]) }
|
|
115
|
+
|
|
116
|
+
it 'shipments get a tax adjustment' do
|
|
117
|
+
order = create(factory, ship_address: ship_address, shipping_method: shipping_method)
|
|
118
|
+
shipment = order.shipments[0]
|
|
119
|
+
|
|
120
|
+
expect(shipment.additional_tax_total).to be > 0
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
end
|
|
4
124
|
RSpec.describe 'order factory' do
|
|
5
125
|
let(:factory_class) { Spree::Order }
|
|
6
126
|
|
|
@@ -9,19 +129,30 @@ RSpec.describe 'order factory' do
|
|
|
9
129
|
|
|
10
130
|
it_behaves_like 'a working factory'
|
|
11
131
|
|
|
12
|
-
it
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
132
|
+
shared_examples "it has the expected attributes" do
|
|
133
|
+
it do
|
|
134
|
+
aggregate_failures do
|
|
135
|
+
expect(order.bill_address).to be_present
|
|
136
|
+
expect(order.ship_address).to be_present
|
|
137
|
+
expect(order.user).to be_present
|
|
138
|
+
expect(order.email).to be_present
|
|
139
|
+
expect(order.email).to eq(order.user.email)
|
|
140
|
+
expect(order.state).to eq "cart"
|
|
141
|
+
expect(order.store).to be_present
|
|
142
|
+
expect(order).not_to be_completed
|
|
143
|
+
end
|
|
23
144
|
end
|
|
24
145
|
end
|
|
146
|
+
|
|
147
|
+
context "when built" do
|
|
148
|
+
let(:order) { build(factory) }
|
|
149
|
+
it_behaves_like "it has the expected attributes"
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
context "when created" do
|
|
153
|
+
let(:order) { create(factory) }
|
|
154
|
+
it_behaves_like "it has the expected attributes"
|
|
155
|
+
end
|
|
25
156
|
end
|
|
26
157
|
|
|
27
158
|
describe 'order with totals' do
|
|
@@ -29,66 +160,70 @@ RSpec.describe 'order factory' do
|
|
|
29
160
|
|
|
30
161
|
it_behaves_like 'a working factory'
|
|
31
162
|
|
|
32
|
-
it
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
163
|
+
shared_examples "it has the expected attributes" do
|
|
164
|
+
it do
|
|
165
|
+
aggregate_failures do
|
|
166
|
+
expect(order.total).to eq 0
|
|
167
|
+
expect(order.line_items.length).to eq 1
|
|
168
|
+
expect(order.line_items.first.price).to eq 77
|
|
169
|
+
end
|
|
38
170
|
end
|
|
39
171
|
end
|
|
172
|
+
|
|
173
|
+
context "when built" do
|
|
174
|
+
let(:order) { build(factory, line_items_price: 77) }
|
|
175
|
+
it_behaves_like "it has the expected attributes"
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
context "when created" do
|
|
179
|
+
let(:order) { create(factory, line_items_price: 77) }
|
|
180
|
+
it_behaves_like "it has the expected attributes"
|
|
181
|
+
end
|
|
40
182
|
end
|
|
41
183
|
|
|
42
184
|
describe 'order with line items' do
|
|
43
185
|
let(:factory) { :order_with_line_items }
|
|
44
186
|
|
|
45
187
|
it_behaves_like 'a working factory'
|
|
188
|
+
it_behaves_like 'an order with line items factory', "cart", "on_hand"
|
|
189
|
+
it_behaves_like 'shipping methods are assigned'
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
describe 'completed order with promotion' do
|
|
193
|
+
let(:factory) { :completed_order_with_promotion }
|
|
194
|
+
|
|
195
|
+
it_behaves_like 'a working factory'
|
|
196
|
+
it_behaves_like 'an order with line items factory', "complete", "on_hand"
|
|
197
|
+
it_behaves_like 'shipping methods are assigned'
|
|
46
198
|
|
|
47
199
|
it "has the expected attributes" do
|
|
48
200
|
order = create(factory)
|
|
49
201
|
aggregate_failures do
|
|
50
|
-
expect(order
|
|
51
|
-
expect(order
|
|
52
|
-
quantity: 1,
|
|
53
|
-
price: 10
|
|
54
|
-
)
|
|
55
|
-
|
|
56
|
-
expect(order.shipments.count).to eq 1
|
|
57
|
-
expect(order.shipments[0]).to have_attributes(
|
|
58
|
-
amount: 100
|
|
59
|
-
)
|
|
60
|
-
|
|
61
|
-
expect(order.shipments[0].inventory_units.count).to eq(1)
|
|
62
|
-
expect(order.shipments[0].inventory_units[0]).to have_attributes(
|
|
63
|
-
order: order,
|
|
64
|
-
shipment: order.shipments[0],
|
|
65
|
-
line_item: order.line_items[0],
|
|
66
|
-
variant: order.line_items[0].variant,
|
|
67
|
-
state: 'on_hand'
|
|
68
|
-
)
|
|
202
|
+
expect(order).to be_completed
|
|
203
|
+
expect(order).to be_complete
|
|
69
204
|
|
|
70
|
-
expect(order).to
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
total: 110,
|
|
74
|
-
state: 'cart' # this isn't realistic
|
|
75
|
-
)
|
|
205
|
+
expect(order.order_promotions.count).to eq(1)
|
|
206
|
+
order_promotion = order.order_promotions[0]
|
|
207
|
+
expect(order_promotion.promotion_code.promotion).to eq order_promotion.promotion
|
|
76
208
|
end
|
|
77
209
|
end
|
|
78
210
|
|
|
79
|
-
context '
|
|
80
|
-
let
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
it 'shipments get a tax adjustment' do
|
|
88
|
-
order = create(factory, ship_address: ship_address, shipping_method: shipping_method)
|
|
89
|
-
shipment = order.shipments[0]
|
|
211
|
+
context 'with a promotion with an action' do
|
|
212
|
+
let(:promotion) { create(:promotion, :with_line_item_adjustment) }
|
|
213
|
+
it "has the expected attributes" do
|
|
214
|
+
order = create(factory, promotion: promotion)
|
|
215
|
+
aggregate_failures do
|
|
216
|
+
expect(order).to be_completed
|
|
217
|
+
expect(order).to be_complete
|
|
90
218
|
|
|
91
|
-
|
|
219
|
+
expect(order.line_items[0].adjustments.count).to eq 1
|
|
220
|
+
adjustment = order.line_items[0].adjustments[0]
|
|
221
|
+
expect(adjustment).to have_attributes(
|
|
222
|
+
amount: -10,
|
|
223
|
+
eligible: true,
|
|
224
|
+
order_id: order.id
|
|
225
|
+
)
|
|
226
|
+
end
|
|
92
227
|
end
|
|
93
228
|
end
|
|
94
229
|
end
|
|
@@ -97,6 +232,8 @@ RSpec.describe 'order factory' do
|
|
|
97
232
|
let(:factory) { :order_ready_to_complete }
|
|
98
233
|
|
|
99
234
|
it_behaves_like 'a working factory'
|
|
235
|
+
it_behaves_like 'an order with line items factory', "confirm", "on_hand"
|
|
236
|
+
it_behaves_like 'shipping methods are assigned'
|
|
100
237
|
|
|
101
238
|
it "is completable" do
|
|
102
239
|
order = create(factory)
|
|
@@ -111,6 +248,8 @@ RSpec.describe 'order factory' do
|
|
|
111
248
|
let(:factory) { :completed_order_with_totals }
|
|
112
249
|
|
|
113
250
|
it_behaves_like 'a working factory'
|
|
251
|
+
it_behaves_like 'an order with line items factory', "complete", "on_hand"
|
|
252
|
+
it_behaves_like 'shipping methods are assigned'
|
|
114
253
|
|
|
115
254
|
it "has the expected attributes" do
|
|
116
255
|
order = create(factory)
|
|
@@ -132,6 +271,8 @@ RSpec.describe 'order factory' do
|
|
|
132
271
|
let(:factory) { :completed_order_with_pending_payment }
|
|
133
272
|
|
|
134
273
|
it_behaves_like 'a working factory'
|
|
274
|
+
it_behaves_like 'an order with line items factory', "complete", "on_hand"
|
|
275
|
+
it_behaves_like 'shipping methods are assigned'
|
|
135
276
|
|
|
136
277
|
it "has the expected attributes" do
|
|
137
278
|
order = create(factory)
|
|
@@ -156,6 +297,8 @@ RSpec.describe 'order factory' do
|
|
|
156
297
|
let(:factory) { :order_ready_to_ship }
|
|
157
298
|
|
|
158
299
|
it_behaves_like 'a working factory'
|
|
300
|
+
it_behaves_like 'an order with line items factory', "complete", "on_hand"
|
|
301
|
+
it_behaves_like 'shipping methods are assigned'
|
|
159
302
|
|
|
160
303
|
it "has the expected attributes" do
|
|
161
304
|
order = create(factory)
|
|
@@ -195,6 +338,8 @@ RSpec.describe 'order factory' do
|
|
|
195
338
|
let(:factory) { :shipped_order }
|
|
196
339
|
|
|
197
340
|
it_behaves_like 'a working factory'
|
|
341
|
+
it_behaves_like 'an order with line items factory', "complete", "shipped"
|
|
342
|
+
it_behaves_like 'shipping methods are assigned'
|
|
198
343
|
|
|
199
344
|
it "has the expected attributes" do
|
|
200
345
|
order = create(factory)
|
|
@@ -222,41 +367,4 @@ RSpec.describe 'order factory' do
|
|
|
222
367
|
end
|
|
223
368
|
end
|
|
224
369
|
end
|
|
225
|
-
|
|
226
|
-
describe 'completed order with promotion' do
|
|
227
|
-
let(:factory) { :completed_order_with_promotion }
|
|
228
|
-
|
|
229
|
-
it_behaves_like 'a working factory'
|
|
230
|
-
|
|
231
|
-
it "has the expected attributes" do
|
|
232
|
-
order = create(factory)
|
|
233
|
-
aggregate_failures do
|
|
234
|
-
expect(order).to be_completed
|
|
235
|
-
expect(order).to be_complete
|
|
236
|
-
|
|
237
|
-
expect(order.order_promotions.count).to eq(1)
|
|
238
|
-
order_promotion = order.order_promotions[0]
|
|
239
|
-
expect(order_promotion.promotion_code.promotion).to eq order_promotion.promotion
|
|
240
|
-
end
|
|
241
|
-
end
|
|
242
|
-
|
|
243
|
-
context 'with a promotion with an action' do
|
|
244
|
-
let(:promotion) { create(:promotion, :with_line_item_adjustment) }
|
|
245
|
-
it "has the expected attributes" do
|
|
246
|
-
order = create(factory, promotion: promotion)
|
|
247
|
-
aggregate_failures do
|
|
248
|
-
expect(order).to be_completed
|
|
249
|
-
expect(order).to be_complete
|
|
250
|
-
|
|
251
|
-
expect(order.line_items[0].adjustments.count).to eq 1
|
|
252
|
-
adjustment = order.line_items[0].adjustments[0]
|
|
253
|
-
expect(adjustment).to have_attributes(
|
|
254
|
-
amount: -10,
|
|
255
|
-
eligible: true,
|
|
256
|
-
order_id: order.id
|
|
257
|
-
)
|
|
258
|
-
end
|
|
259
|
-
end
|
|
260
|
-
end
|
|
261
|
-
end
|
|
262
370
|
end
|
|
@@ -20,6 +20,24 @@ RSpec.describe 'variant factory' do
|
|
|
20
20
|
let(:factory) { :master_variant }
|
|
21
21
|
|
|
22
22
|
it_behaves_like 'a working factory'
|
|
23
|
+
|
|
24
|
+
it "builds a master variant properly" do
|
|
25
|
+
variant = create(factory)
|
|
26
|
+
expect(variant).to be_is_master
|
|
27
|
+
expect(variant.option_values).to be_empty
|
|
28
|
+
|
|
29
|
+
product = variant.product
|
|
30
|
+
expect(product.master).to be(variant)
|
|
31
|
+
expect(product.variants).to be_empty
|
|
32
|
+
expect(product.variants_including_master).to eq [variant]
|
|
33
|
+
expect(product.option_types).to be_empty
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "creates only one variant" do
|
|
37
|
+
expect {
|
|
38
|
+
create(factory)
|
|
39
|
+
}.to change { Spree::Variant.count }.from(0).to(1)
|
|
40
|
+
end
|
|
23
41
|
end
|
|
24
42
|
|
|
25
43
|
describe 'on demand variant' do
|
|
@@ -13,6 +13,12 @@ describe Spree::LocalizedNumber do
|
|
|
13
13
|
I18n.enforce_available_locales = true
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
+
context "with an empty string" do
|
|
17
|
+
it "parses to 0" do
|
|
18
|
+
expect(subject.class.parse("")).to eq 0.0
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
16
22
|
context "with decimal point" do
|
|
17
23
|
it "captures the proper amount for a formatted price" do
|
|
18
24
|
expect(subject.class.parse('1,599.99')).to eql 1599.99
|