solidus_product_assembly 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.circleci/config.yml +35 -0
- data/.gem_release.yml +5 -0
- data/.github/dependabot.yml +7 -0
- data/.github/stale.yml +17 -0
- data/.gitignore +14 -2
- data/.rspec +2 -2
- data/.rubocop.yml +4 -0
- data/.rubocop_todo.yml +192 -0
- data/CHANGELOG.md +19 -0
- data/Gemfile +21 -9
- data/LICENSE +26 -0
- data/README.md +52 -18
- data/Rakefile +4 -19
- data/app/controllers/spree/admin/parts_controller.rb +13 -11
- data/app/decorators/controllers/solidus_product_assembly/spree/checkout_controller_decorator.rb +13 -0
- data/app/decorators/helpers/solidus_product_assembly/spree/admin/orders_helper_decorator.rb +19 -0
- data/app/decorators/models/solidus_product_assembly/spree/inventory_unit_decorator.rb +19 -0
- data/app/decorators/models/solidus_product_assembly/spree/line_item_decorator.rb +52 -0
- data/app/decorators/models/solidus_product_assembly/spree/product_decorator.rb +70 -0
- data/app/decorators/models/solidus_product_assembly/spree/return_item_decorator.rb +15 -0
- data/app/decorators/models/solidus_product_assembly/spree/shipment_decorator.rb +55 -0
- data/app/decorators/models/solidus_product_assembly/spree/stock/availability_validator_decorator.rb +37 -0
- data/app/decorators/models/solidus_product_assembly/spree/stock/inventory_unit_builder_decorator.rb +39 -0
- data/app/decorators/models/solidus_product_assembly/spree/stock/inventory_units_finalizer_decorator.rb +33 -0
- data/app/decorators/models/solidus_product_assembly/spree/stock/inventory_validator_decorator.rb +22 -0
- data/app/decorators/models/solidus_product_assembly/spree/variant_decorator.rb +26 -0
- data/app/models/spree/assemblies_part.rb +6 -4
- data/app/models/spree/calculator/returns/assemblies_default_refund_amount.rb +17 -0
- data/app/models/spree/order_inventory_assembly.rb +11 -2
- data/app/overrides/add_admin_product_form_fields.rb +7 -5
- data/app/overrides/add_admin_tabs.rb +7 -5
- data/app/overrides/add_line_item_description.rb +7 -5
- data/app/overrides/spree/admin/orders/_carton_manifest/_assembly_parts_price.html.erb.deface +9 -0
- data/app/overrides/spree/admin/orders/_carton_manifest/_assembly_parts_total_price.html.erb.deface +9 -0
- data/app/overrides/spree/admin/orders/_shipment/stock_contents.html.erb.deface +7 -1
- data/app/overrides/spree/products/show/add_links_to_parts.html.erb.deface +2 -2
- data/app/views/spree/admin/orders/_assemblies.html.erb +8 -17
- data/app/views/spree/admin/orders/_stock_contents.html.erb +2 -62
- data/app/views/spree/admin/orders/_stock_contents_2_3.html.erb +69 -0
- data/app/views/spree/admin/orders/_stock_contents_2_4.html.erb +70 -0
- data/app/views/spree/admin/orders/_stock_item.html.erb +13 -10
- data/app/views/spree/admin/parts/_parts_table.html.erb +17 -11
- data/app/views/spree/admin/parts/available.html.erb +10 -8
- data/app/views/spree/admin/parts/available.js.erb +9 -7
- data/app/views/spree/admin/parts/index.html.erb +1 -1
- data/app/views/spree/admin/products/_product_assembly_fields.html.erb +2 -2
- data/app/views/spree/admin/shared/_product_assembly_product_tabs.html.erb +1 -1
- data/app/views/spree/api/line_items/show.v1.rabl +27 -0
- data/app/views/spree/checkout/_line_item_manifest.html.erb +3 -1
- data/bin/console +17 -0
- data/bin/rails +12 -4
- data/bin/setup +8 -0
- data/config/routes.rb +2 -2
- data/db/migrate/20091028152124_add_many_to_many_relation_to_products.rb +7 -5
- data/db/migrate/20091029165620_add_parts_fields_to_products.rb +18 -16
- data/db/migrate/20120316141830_namespace_product_assembly_for_spree_one.rb +3 -1
- data/db/migrate/20140620223938_add_id_to_spree_assemblies_parts.rb +4 -2
- data/lib/generators/solidus_product_assembly/install/install_generator.rb +13 -8
- data/lib/solidus_product_assembly/engine.rb +11 -8
- data/lib/solidus_product_assembly/testing_support/factories.rb +4 -0
- data/lib/solidus_product_assembly/version.rb +3 -1
- data/lib/solidus_product_assembly.rb +5 -1
- data/lib/tasks/spree2_upgrade.rake +12 -12
- data/solidus_product_assembly.gemspec +25 -20
- data/spec/features/admin/orders_spec.rb +114 -16
- data/spec/features/admin/parts_spec.rb +5 -3
- data/spec/features/admin/return_items_spec.rb +151 -0
- data/spec/features/checkout_spec.rb +103 -21
- data/spec/models/spree/assemblies_part_spec.rb +3 -1
- data/spec/models/spree/inventory_unit_spec.rb +15 -6
- data/spec/models/spree/line_item_spec.rb +6 -4
- data/spec/models/spree/order_contents_spec.rb +6 -5
- data/spec/models/spree/order_inventory_assembly_spec.rb +8 -6
- data/spec/models/spree/order_inventory_spec.rb +7 -3
- data/spec/models/spree/product_spec.rb +15 -14
- data/spec/models/spree/shipment_spec.rb +20 -13
- data/spec/models/spree/stock/availability_validator_spec.rb +22 -33
- data/spec/models/spree/stock/coordinator_spec.rb +11 -3
- data/spec/models/spree/stock/inventory_unit_builder_spec.rb +5 -7
- data/spec/models/spree/variant_spec.rb +3 -1
- data/spec/spec_helper.rb +18 -47
- data/spec/support/shared_contexts/order_with_bundle.rb +2 -0
- metadata +80 -102
- data/.travis.yml +0 -21
- data/LICENSE.md +0 -13
- data/app/controllers/spree/checkout_controller_decorator.rb +0 -9
- data/app/helpers/spree/admin/orders_helper_decorator.rb +0 -9
- data/app/models/spree/inventory_unit_decorator.rb +0 -13
- data/app/models/spree/line_item_decorator.rb +0 -44
- data/app/models/spree/product_decorator.rb +0 -56
- data/app/models/spree/shipment_decorator.rb +0 -50
- data/app/models/spree/stock/availability_validator.rb +0 -28
- data/app/models/spree/stock/inventory_unit_builder_decorator.rb +0 -30
- data/app/models/spree/stock/inventory_validator_decorator.rb +0 -12
- data/app/models/spree/variant_decorator.rb +0 -13
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
module Spree
|
@@ -53,8 +55,8 @@ module Spree
|
|
53
55
|
end
|
54
56
|
|
55
57
|
it "verifies inventory units via OrderInventoryAssembly" do
|
56
|
-
OrderInventoryAssembly.
|
57
|
-
inventory.
|
58
|
+
expect(OrderInventoryAssembly).to receive(:new).with(line_item).and_return(inventory)
|
59
|
+
expect(inventory).to receive(:verify).with(line_item.target_shipment)
|
58
60
|
line_item.quantity = 2
|
59
61
|
line_item.save
|
60
62
|
end
|
@@ -62,8 +64,8 @@ module Spree
|
|
62
64
|
|
63
65
|
context "updates regular line item" do
|
64
66
|
it "verifies inventory units via OrderInventory" do
|
65
|
-
OrderInventory.
|
66
|
-
inventory.
|
67
|
+
expect(OrderInventory).to receive(:new).with(line_item.order, line_item).and_return(inventory)
|
68
|
+
expect(inventory).to receive(:verify).with(line_item.target_shipment)
|
67
69
|
line_item.quantity = 2
|
68
70
|
line_item.save
|
69
71
|
end
|
@@ -1,7 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
module Spree
|
4
6
|
describe OrderContents do
|
7
|
+
subject { described_class.new(order) }
|
8
|
+
|
5
9
|
let!(:store) { create :store }
|
6
10
|
let(:order) { Order.create }
|
7
11
|
|
@@ -10,8 +14,6 @@ module Spree
|
|
10
14
|
|
11
15
|
let(:bundle) { create(:product) }
|
12
16
|
|
13
|
-
subject { OrderContents.new(order) }
|
14
|
-
|
15
17
|
before { bundle.parts.push [guitar, bass] }
|
16
18
|
|
17
19
|
context "same variant within bundle and as regular product" do
|
@@ -30,9 +32,8 @@ module Spree
|
|
30
32
|
end
|
31
33
|
|
32
34
|
it "destroys accurate number of inventory units" do
|
33
|
-
expect {
|
34
|
-
|
35
|
-
}.to change { InventoryUnit.count }.by(-3)
|
35
|
+
expect { subject.remove(guitar, 3) }.
|
36
|
+
to change(InventoryUnit, :count).by(-3)
|
36
37
|
end
|
37
38
|
end
|
38
39
|
end
|
@@ -1,7 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
module Spree
|
4
6
|
describe OrderInventoryAssembly do
|
7
|
+
subject { described_class.new(line_item) }
|
8
|
+
|
5
9
|
let(:order) { create(:order_with_line_items) }
|
6
10
|
let(:line_item) { order.line_items.first }
|
7
11
|
let(:bundle) { line_item.product }
|
@@ -11,13 +15,11 @@ module Spree
|
|
11
15
|
bundle.parts << [parts]
|
12
16
|
bundle.set_part_count(parts.first, 3)
|
13
17
|
|
14
|
-
line_item.
|
18
|
+
line_item.update!(quantity: 3)
|
15
19
|
order.reload.create_proposed_shipments
|
16
|
-
order.finalize!
|
20
|
+
order.finalize!
|
17
21
|
end
|
18
22
|
|
19
|
-
subject { OrderInventoryAssembly.new(line_item) }
|
20
|
-
|
21
23
|
context "inventory units count" do
|
22
24
|
it "calculates the proper value for the bundle" do
|
23
25
|
expected_units_count = line_item.quantity * bundle.assemblies_parts.to_a.sum(&:count)
|
@@ -34,7 +36,7 @@ module Spree
|
|
34
36
|
it "inserts new inventory units for every bundle part" do
|
35
37
|
expected_units_count = original_units_count + bundle.assemblies_parts.to_a.sum(&:count)
|
36
38
|
subject.verify
|
37
|
-
expect(
|
39
|
+
expect(described_class.new(line_item.reload).inventory_units.count).to eql(expected_units_count)
|
38
40
|
end
|
39
41
|
end
|
40
42
|
|
@@ -46,7 +48,7 @@ module Spree
|
|
46
48
|
subject.verify
|
47
49
|
|
48
50
|
# needs to reload so that inventory units are fetched from updates order.shipments
|
49
|
-
updated_units_count =
|
51
|
+
updated_units_count = described_class.new(line_item.reload).inventory_units.count
|
50
52
|
expect(updated_units_count).to eql(expected_units_count)
|
51
53
|
end
|
52
54
|
end
|
@@ -1,12 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
module Spree
|
4
6
|
describe OrderInventory do
|
7
|
+
subject { described_class.new(order, order.line_items.first) }
|
8
|
+
|
5
9
|
let!(:store) { create :store }
|
6
10
|
let(:order) { Order.create }
|
7
11
|
|
8
|
-
subject { OrderInventory.new(order, order.line_items.first) }
|
9
|
-
|
10
12
|
context "same variant within bundle and as regular product" do
|
11
13
|
let(:contents) { OrderContents.new(order) }
|
12
14
|
let(:guitar) { create(:variant) }
|
@@ -22,7 +24,9 @@ module Spree
|
|
22
24
|
let!(:shipment) { order.create_proposed_shipments.first }
|
23
25
|
|
24
26
|
context "completed order" do
|
25
|
-
before
|
27
|
+
before do
|
28
|
+
order.touch :completed_at
|
29
|
+
end
|
26
30
|
|
27
31
|
it "removes only units associated with provided line item" do
|
28
32
|
expect {
|
@@ -1,35 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Spree::Product do
|
4
|
-
before
|
5
|
-
@product =
|
6
|
-
@master_variant = Spree::Variant.where(is_master: true).
|
6
|
+
before do
|
7
|
+
@product = FactoryBot.create(:product, name: "Foo Bar")
|
8
|
+
@master_variant = Spree::Variant.where(is_master: true).find_by(product_id: @product.id)
|
7
9
|
end
|
8
|
-
|
10
|
+
|
9
11
|
describe "Spree::Product Assembly" do
|
10
|
-
before
|
12
|
+
before do
|
11
13
|
@product = create(:product)
|
12
|
-
@part1 = create(:product, :
|
13
|
-
@part2 = create(:product, :
|
14
|
+
@part1 = create(:product, can_be_part: true)
|
15
|
+
@part2 = create(:product, can_be_part: true)
|
14
16
|
@product.add_part @part1.master, 1
|
15
17
|
@product.add_part @part2.master, 4
|
16
18
|
end
|
17
|
-
|
19
|
+
|
18
20
|
it "is an assembly" do
|
19
|
-
@product.
|
21
|
+
expect(@product).to be_assembly
|
20
22
|
end
|
21
|
-
|
22
23
|
|
23
24
|
it "cannot be part" do
|
24
|
-
@product.
|
25
|
+
expect(@product).to be_assembly
|
25
26
|
@product.can_be_part = true
|
26
|
-
@product.
|
27
|
-
@product.errors[:can_be_part].
|
27
|
+
expect(@product).not_to be_valid
|
28
|
+
expect(@product.errors[:can_be_part]).to eq ["assembly can't be part"]
|
28
29
|
end
|
29
30
|
|
30
31
|
it 'changing part qty changes count on_hand' do
|
31
32
|
@product.set_part_count(@part2.master, 2)
|
32
|
-
@product.count_of(@part2.master).
|
33
|
+
expect(@product.count_of(@part2.master)).to eq 2
|
33
34
|
end
|
34
35
|
end
|
35
36
|
end
|
@@ -1,8 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
module Spree
|
4
6
|
describe Shipment do
|
5
7
|
context "order has one product assembly" do
|
8
|
+
let!(:store) { create(:store) }
|
6
9
|
let(:order) { Order.create }
|
7
10
|
let(:bundle) { create(:variant) }
|
8
11
|
let!(:parts) { (1..2).map { create(:variant) } }
|
@@ -11,7 +14,9 @@ module Spree
|
|
11
14
|
let!(:line_item) { order.contents.add(bundle, 1) }
|
12
15
|
let!(:shipment) { order.create_proposed_shipments.first }
|
13
16
|
|
14
|
-
before
|
17
|
+
before do
|
18
|
+
order.update_column :state, 'complete'
|
19
|
+
end
|
15
20
|
|
16
21
|
it "shipment item cost equals line item amount" do
|
17
22
|
expect(shipment.item_cost).to eq line_item.amount
|
@@ -25,19 +30,21 @@ module Spree
|
|
25
30
|
|
26
31
|
context "default" do
|
27
32
|
let(:expected_variants) { order.variants - [bundle_variant] + bundle.parts }
|
33
|
+
before {shipments.first.save }
|
28
34
|
|
29
35
|
it "separates variant purchased individually from the bundle one" do
|
30
|
-
expect(shipments.count).to
|
31
|
-
shipments.first.manifest.map(&:variant).
|
36
|
+
expect(shipments.count).to be 1
|
37
|
+
expect(shipments.first.manifest.map(&:variant)).to match_array expected_variants
|
32
38
|
end
|
33
39
|
end
|
34
40
|
|
35
41
|
context "line items manifest" do
|
36
42
|
let(:expected_variants) { order.variants }
|
43
|
+
before { shipments.first.save }
|
37
44
|
|
38
45
|
it "groups units by line_item only" do
|
39
|
-
expect(shipments.count).to
|
40
|
-
shipments.first.line_item_manifest.map(&:variant).
|
46
|
+
expect(shipments.count).to be 1
|
47
|
+
expect(shipments.first.line_item_manifest.map(&:variant)).to match_array expected_variants
|
41
48
|
end
|
42
49
|
end
|
43
50
|
|
@@ -46,7 +53,7 @@ module Spree
|
|
46
53
|
let(:shipment) { order.shipments.first }
|
47
54
|
|
48
55
|
it "searches for line item if inventory unit doesn't have one" do
|
49
|
-
shipment.manifest.last.line_item.
|
56
|
+
expect(shipment.manifest.last.line_item).not_to be_blank
|
50
57
|
end
|
51
58
|
end
|
52
59
|
end
|
@@ -55,7 +62,7 @@ module Spree
|
|
55
62
|
let(:line_item) { create(:line_item) }
|
56
63
|
let(:variant) { line_item.variant }
|
57
64
|
let(:order) { line_item.order }
|
58
|
-
let(:shipment) { create(:shipment) }
|
65
|
+
let(:shipment) { create(:shipment, order: order) }
|
59
66
|
|
60
67
|
it "assigns variant, order and line_item" do
|
61
68
|
unit = shipment.set_up_inventory('on_hand', variant, order, line_item)
|
@@ -74,9 +81,9 @@ module Spree
|
|
74
81
|
let(:assembly_shirts) do
|
75
82
|
5.times.map {
|
76
83
|
create(:inventory_unit,
|
77
|
-
|
78
|
-
|
79
|
-
|
84
|
+
variant: shirt,
|
85
|
+
line_item: assembly_line_item,
|
86
|
+
state: :on_hand)
|
80
87
|
}
|
81
88
|
end
|
82
89
|
|
@@ -85,9 +92,9 @@ module Spree
|
|
85
92
|
let(:standalone_shirts) do
|
86
93
|
2.times.map {
|
87
94
|
create(:inventory_unit,
|
88
|
-
|
89
|
-
|
90
|
-
|
95
|
+
variant: shirt,
|
96
|
+
line_item: standalone_line_item,
|
97
|
+
state: :on_hand)
|
91
98
|
}
|
92
99
|
end
|
93
100
|
|
@@ -1,67 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
module Spree
|
4
6
|
module Stock
|
5
|
-
describe AvailabilityValidator, :
|
7
|
+
describe AvailabilityValidator, type: :model do
|
6
8
|
context "line item has no parts" do
|
7
|
-
let!(:line_item) { create(:line_item, quantity: 5) }
|
8
|
-
let!(:product) { line_item.product }
|
9
|
-
|
10
9
|
subject { described_class.new }
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
expect(line_item).not_to receive(:errors)
|
15
|
-
subject.validate(line_item)
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'should be invalid when supply is insufficent' do
|
19
|
-
Stock::Quantifier.any_instance.stub(can_supply?: false)
|
20
|
-
expect(line_item.errors).to receive(:[]).exactly(1).times.with(:quantity).and_return([])
|
21
|
-
subject.validate(line_item)
|
22
|
-
end
|
11
|
+
let!(:line_item) { create(:line_item, quantity: 5) }
|
12
|
+
let!(:product) { line_item.product }
|
23
13
|
|
24
|
-
it '
|
25
|
-
|
26
|
-
line_item.inventory_units.stub(where: [double] * 5)
|
27
|
-
expect(line_item).not_to receive(:errors)
|
14
|
+
it 'delegates to the original Solidus implementation' do
|
15
|
+
expect(subject).to receive(:is_valid?).with(line_item)
|
28
16
|
subject.validate(line_item)
|
29
17
|
end
|
30
18
|
end
|
31
19
|
|
32
20
|
context "line item has parts" do
|
21
|
+
subject { described_class.new }
|
22
|
+
|
33
23
|
let!(:order) { create(:order_with_line_items) }
|
34
24
|
let(:line_item) { order.line_items.first }
|
35
25
|
let(:product) { line_item.product }
|
36
26
|
let(:variant) { line_item.variant }
|
37
27
|
let(:parts) { (1..2).map { create(:variant) } }
|
38
|
-
before { product.parts << parts }
|
39
28
|
|
40
|
-
|
29
|
+
before { product.parts << parts }
|
41
30
|
|
42
|
-
it '
|
43
|
-
Stock::Quantifier.
|
31
|
+
it 'is valid when supply of all parts is sufficient' do
|
32
|
+
allow_any_instance_of(Stock::Quantifier).to receive(:can_supply?).and_return(true)
|
44
33
|
expect(line_item).not_to receive(:errors)
|
45
34
|
subject.validate(line_item)
|
46
35
|
end
|
47
36
|
|
48
|
-
it '
|
49
|
-
Stock::Quantifier.
|
37
|
+
it 'is invalid when supplies of all parts are insufficent' do
|
38
|
+
allow_any_instance_of(Stock::Quantifier).to receive(:can_supply?).and_return(false)
|
50
39
|
expect(line_item.errors).to receive(:[]).exactly(line_item.parts.size).times.with(:quantity).and_return([])
|
51
40
|
subject.validate(line_item)
|
52
41
|
end
|
53
42
|
|
54
|
-
it '
|
55
|
-
Stock::Quantifier.
|
56
|
-
|
57
|
-
line_item.
|
58
|
-
expect(line_item.inventory_units).to receive(:where).and_return(inventory_units, [])
|
59
|
-
expect(line_item.errors).to receive(:[]).exactly(1).times.with(:quantity).and_return([])
|
43
|
+
it 'is invalid when supply of 1 part is insufficient' do
|
44
|
+
allow_any_instance_of(Stock::Quantifier).to receive(:can_supply?).and_return(false)
|
45
|
+
create_list(:inventory_unit, 5, line_item: line_item, variant: line_item.parts.first, order: order, shipment: order.shipments.first)
|
46
|
+
expect(line_item.errors).to receive(:[]).once.with(:quantity).and_return([])
|
60
47
|
subject.validate(line_item)
|
61
48
|
end
|
62
49
|
|
63
|
-
it '
|
64
|
-
line_item.parts.each
|
50
|
+
it 'is valid when supply of each part is sufficient' do
|
51
|
+
line_item.parts.each do |part|
|
52
|
+
allow(part).to receive(:inventory_units).and_return([double(variant: part)] * 5)
|
53
|
+
end
|
65
54
|
expect(line_item).not_to receive(:errors)
|
66
55
|
subject.validate(line_item)
|
67
56
|
end
|
@@ -1,15 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
# Spree::Stock::Coordinator was refactored in Solidus to hide keep private
|
4
6
|
# information about packages, we have to be sneaky to reach inside
|
5
7
|
def inventory_units(coordinator)
|
6
|
-
coordinator.shipments.flat_map
|
8
|
+
coordinator.shipments.flat_map(&:inventory_units)
|
7
9
|
end
|
8
10
|
|
9
11
|
module Spree
|
10
12
|
module Stock
|
11
|
-
|
12
|
-
|
13
|
+
coordinator_class =
|
14
|
+
if Spree.solidus_gem_version < Gem::Version.new('2.4.x')
|
15
|
+
Coordinator
|
16
|
+
else
|
17
|
+
SimpleCoordinator
|
18
|
+
end
|
19
|
+
describe coordinator_class do
|
20
|
+
subject { described_class.new(order) }
|
13
21
|
|
14
22
|
context "order shares variant as individual and within bundle" do
|
15
23
|
include_context "product is ordered as individual and within a bundle"
|
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
module Spree
|
4
6
|
module Stock
|
5
|
-
describe InventoryUnitBuilder, :
|
6
|
-
subject {
|
7
|
-
|
7
|
+
describe InventoryUnitBuilder, type: :model do
|
8
|
+
subject { described_class.new(order) }
|
9
|
+
|
8
10
|
context "order shares variant as individual and within bundle" do
|
9
11
|
include_context "product is ordered as individual and within a bundle" do
|
10
12
|
let(:bundle_item_quantity) { order.find_line_item_by_variant(bundle_variant).quantity }
|
@@ -24,10 +26,6 @@ module Spree
|
|
24
26
|
it "builds the inventory units as pending" do
|
25
27
|
expect(subject.units.map(&:pending).uniq).to eq [true]
|
26
28
|
end
|
27
|
-
|
28
|
-
it "associates the inventory units to the order" do
|
29
|
-
expect(subject.units.map(&:order).uniq).to eq [order]
|
30
|
-
end
|
31
29
|
end
|
32
30
|
end
|
33
31
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
module Spree
|
@@ -20,7 +22,7 @@ module Spree
|
|
20
22
|
|
21
23
|
context "variant no assembly" do
|
22
24
|
it "returns both products" do
|
23
|
-
variant.assemblies_for([mug, tshirt]).
|
25
|
+
expect(variant.assemblies_for([mug, tshirt])).to be_empty
|
24
26
|
end
|
25
27
|
end
|
26
28
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,57 +1,28 @@
|
|
1
|
-
|
2
|
-
SimpleCov.start 'rails'
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
|
3
|
+
# Configure Rails Environment
|
4
|
+
ENV['RAILS_ENV'] ||= 'test'
|
5
5
|
|
6
|
-
|
6
|
+
# Run Coverage report
|
7
|
+
require 'solidus_dev_support/rspec/coverage'
|
7
8
|
|
8
|
-
require '
|
9
|
-
require 'ffaker'
|
10
|
-
require 'database_cleaner'
|
9
|
+
require File.expand_path('dummy/config/environment.rb', __dir__)
|
11
10
|
|
12
|
-
|
13
|
-
require '
|
14
|
-
require 'capybara/poltergeist'
|
15
|
-
Capybara.javascript_driver = :poltergeist
|
11
|
+
# Requires factories and other useful helpers defined in spree_core.
|
12
|
+
require 'solidus_dev_support/rspec/feature_helper'
|
16
13
|
|
17
|
-
|
14
|
+
# This will load Solidus Core factories right before the ones defined in
|
15
|
+
# lib/extension_name/testing_support/factories/*_factory.rb or
|
16
|
+
# lib/extension_name/testing_support/factories.rb
|
17
|
+
SolidusDevSupport::TestingSupport::Factories.load_for(SolidusProductAssembly::Engine)
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
require 'spree/testing_support/capybara_ext'
|
23
|
-
|
24
|
-
# ActiveRecord::Base.logger = Logger.new(STDOUT)
|
19
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
20
|
+
# in spec/support/ and its subdirectories.
|
21
|
+
Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |f| require f }
|
25
22
|
|
26
23
|
RSpec.configure do |config|
|
27
|
-
config.
|
24
|
+
config.infer_spec_type_from_file_location!
|
28
25
|
config.use_transactional_fixtures = false
|
29
|
-
|
30
|
-
config.before :suite do
|
31
|
-
Capybara.match = :prefer_exact
|
32
|
-
DatabaseCleaner.clean_with :truncation
|
33
|
-
end
|
34
|
-
|
35
|
-
config.before(:each) do
|
36
|
-
Rails.cache.clear
|
37
|
-
|
38
|
-
if RSpec.current_example.metadata[:js]
|
39
|
-
DatabaseCleaner.strategy = :truncation
|
40
|
-
else
|
41
|
-
DatabaseCleaner.strategy = :transaction
|
42
|
-
end
|
43
|
-
|
44
|
-
DatabaseCleaner.start
|
45
|
-
end
|
46
|
-
|
47
|
-
config.after(:each) do
|
48
|
-
# Ensure js requests finish processing before advancing to the next test
|
49
|
-
wait_for_ajax if RSpec.current_example.metadata[:js]
|
50
|
-
|
51
|
-
DatabaseCleaner.clean
|
52
|
-
end
|
53
|
-
|
54
|
-
config.include FactoryGirl::Syntax::Methods
|
55
|
-
config.include Spree::TestingSupport::UrlHelpers
|
56
|
-
config.example_status_persistence_file_path = "./spec/examples.txt"
|
57
26
|
end
|
27
|
+
|
28
|
+
Capybara.javascript_driver = (ENV['CAPYBARA_DRIVER'] || :selenium_headless).to_sym
|