File tree 2 files changed +14
-19
lines changed
2 files changed +14
-19
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ class LineItem < Spree::Base
20
20
has_many :inventory_units , inverse_of : :line_item
21
21
22
22
before_validation :normalize_quantity
23
- before_validation :set_required_attributes
23
+ after_initialize :set_required_attributes
24
24
25
25
validates :variant , presence : true
26
26
validates :quantity , numericality : {
@@ -157,6 +157,7 @@ def normalize_quantity
157
157
# Sets tax category, price-related attributes from
158
158
# its variant if they are nil and a variant is present.
159
159
def set_required_attributes
160
+ return if persisted?
160
161
return unless variant
161
162
self . tax_category ||= variant . tax_category
162
163
set_pricing_attributes
Original file line number Diff line number Diff line change 39
39
end
40
40
end
41
41
42
- describe 'line item creation ' do
42
+ describe '.new ' do
43
43
let ( :variant ) { create :variant }
44
44
45
45
subject ( :line_item ) { Spree ::LineItem . new ( variant :, order :) }
46
46
47
- # Tests for https://github.com/spree/spree/issues/3391
48
- context 'before validation' do
49
- before { line_item . valid? }
50
-
51
- it 'copies the variants price' do
52
- expect ( line_item . price ) . to eq ( variant . price )
53
- end
47
+ it 'copies the variants price' do
48
+ expect ( line_item . price ) . to eq ( variant . price )
49
+ end
54
50
55
- it 'copies the variants cost_price' do
56
- expect ( line_item . cost_price ) . to eq ( variant . cost_price )
57
- end
51
+ it 'copies the variants cost_price' do
52
+ expect ( line_item . cost_price ) . to eq ( variant . cost_price )
53
+ end
58
54
59
- it "copies the order's currency" do
60
- expect ( line_item . currency ) . to eq ( order . currency )
61
- end
55
+ it "copies the order's currency" do
56
+ expect ( line_item . currency ) . to eq ( order . currency )
57
+ end
62
58
63
- # Test for https://github.com/spree/spree/issues/3481
64
- it 'copies the variants tax category' do
65
- expect ( line_item . tax_category ) . to eq ( line_item . variant . tax_category )
66
- end
59
+ it 'copies the variants tax category' do
60
+ expect ( line_item . tax_category ) . to eq ( line_item . variant . tax_category )
67
61
end
68
62
end
69
63
You can’t perform that action at this time.
0 commit comments