solidus_core 2.1.1 → 2.2.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.
Files changed (145) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +0 -1
  3. data/app/assets/config/solidus_core_manifest.js +1 -0
  4. data/app/assets/javascripts/spree.js.erb +72 -0
  5. data/app/helpers/spree/store_helper.rb +5 -0
  6. data/app/jobs/spree/promotion_code_batch_job.rb +24 -0
  7. data/app/mailers/spree/promotion_code_batch_mailer.rb +13 -0
  8. data/app/models/concerns/spree/calculated_adjustments.rb +1 -1
  9. data/app/models/concerns/spree/ordered_property_value_list.rb +2 -2
  10. data/app/models/concerns/spree/user_address_book.rb +4 -4
  11. data/app/models/concerns/spree/user_methods.rb +7 -0
  12. data/app/models/concerns/spree/user_payment_source.rb +12 -5
  13. data/app/models/spree/address.rb +14 -3
  14. data/app/models/spree/adjustment.rb +13 -1
  15. data/app/models/spree/app_configuration.rb +0 -19
  16. data/app/models/spree/base.rb +2 -0
  17. data/app/models/spree/credit_card.rb +34 -43
  18. data/app/models/spree/gateway/bogus.rb +1 -1
  19. data/app/models/spree/gateway.rb +6 -4
  20. data/app/models/spree/inventory_unit.rb +3 -2
  21. data/app/models/spree/order/checkout.rb +187 -273
  22. data/app/models/spree/order.rb +137 -71
  23. data/app/models/spree/order_contents.rb +1 -1
  24. data/app/models/spree/order_inventory.rb +11 -11
  25. data/app/models/spree/order_promotion.rb +2 -0
  26. data/app/models/spree/order_update_attributes.rb +1 -8
  27. data/app/models/spree/order_updater.rb +67 -63
  28. data/app/models/spree/payment.rb +0 -1
  29. data/app/models/spree/payment_create.rb +27 -7
  30. data/app/models/spree/payment_method/store_credit.rb +3 -3
  31. data/app/models/spree/payment_method.rb +4 -1
  32. data/app/models/spree/payment_source.rb +45 -0
  33. data/app/models/spree/product/scopes.rb +24 -24
  34. data/app/models/spree/product.rb +4 -4
  35. data/app/models/spree/promotion.rb +2 -0
  36. data/app/models/spree/promotion_code/batch_builder.rb +63 -0
  37. data/app/models/spree/promotion_code.rb +1 -0
  38. data/app/models/spree/promotion_code_batch.rb +25 -0
  39. data/app/models/spree/promotion_handler/cart.rb +2 -2
  40. data/app/models/spree/promotion_handler/coupon.rb +1 -2
  41. data/app/models/spree/promotion_handler/free_shipping.rb +32 -21
  42. data/app/models/spree/promotion_handler/page.rb +1 -1
  43. data/app/models/spree/reimbursement.rb +1 -1
  44. data/app/models/spree/return_authorization.rb +0 -28
  45. data/app/models/spree/return_item.rb +1 -1
  46. data/app/models/spree/shipment.rb +4 -4
  47. data/app/models/spree/shipping_method.rb +2 -2
  48. data/app/models/spree/shipping_rate.rb +1 -1
  49. data/app/models/spree/stock/availability_validator.rb +16 -17
  50. data/app/models/spree/stock/coordinator.rb +3 -3
  51. data/app/models/spree/stock/package.rb +1 -1
  52. data/app/models/spree/stock/quantifier.rb +5 -4
  53. data/app/models/spree/stock_location.rb +2 -2
  54. data/app/models/spree/store.rb +2 -2
  55. data/app/models/spree/store_credit.rb +1 -1
  56. data/app/models/spree/tax/tax_helpers.rb +3 -3
  57. data/app/models/spree/tax_rate.rb +7 -1
  58. data/app/models/spree/taxonomy.rb +1 -1
  59. data/app/models/spree/variant/scopes.rb +5 -5
  60. data/app/models/spree/variant/vat_price_generator.rb +8 -5
  61. data/app/models/spree/variant.rb +1 -0
  62. data/app/models/spree/wallet/add_payment_sources_to_wallet.rb +19 -10
  63. data/app/models/spree/wallet/default_payment_builder.rb +6 -6
  64. data/app/models/spree/wallet.rb +71 -0
  65. data/app/models/spree/wallet_payment_source.rb +17 -0
  66. data/app/models/spree/zone.rb +1 -1
  67. data/app/views/spree/carton_mailer/shipped_email.text.erb +1 -1
  68. data/app/views/spree/promotion_code_batch_mailer/promotion_code_batch_errored.text.erb +2 -0
  69. data/app/views/spree/promotion_code_batch_mailer/promotion_code_batch_finished.text.erb +2 -0
  70. data/app/views/spree/reimbursement_mailer/reimbursement_email.html.erb +0 -7
  71. data/app/views/spree/reimbursement_mailer/reimbursement_email.text.erb +0 -5
  72. data/app/views/spree/shared/_error_messages.html.erb +1 -1
  73. data/app/views/spree/shipment_mailer/shipped_email.html.erb +1 -1
  74. data/config/initializers/assets.rb +1 -1
  75. data/config/initializers/friendly_id.rb +1 -1
  76. data/config/locales/en.yml +50 -12
  77. data/db/default/spree/store_credit.rb +2 -1
  78. data/db/migrate/20130826062534_add_depth_to_spree_taxons.rb +4 -6
  79. data/db/migrate/20160420044191_create_spree_wallet_payment_sources.rb +23 -0
  80. data/db/migrate/20160420181916_migrate_credit_cards_to_wallet_payment_sources.rb +26 -0
  81. data/db/migrate/20161017102621_create_spree_promotion_code_batch.rb +36 -0
  82. data/db/migrate/20161129035810_add_index_to_spree_payments_number.rb +5 -0
  83. data/db/migrate/20170223235001_remove_spree_store_credits_column.rb +5 -0
  84. data/lib/generators/spree/dummy/templates/rails/application.rb +1 -1
  85. data/lib/generators/spree/dummy/templates/rails/test.rb +1 -1
  86. data/lib/generators/spree/install/install_generator.rb +6 -5
  87. data/lib/spree/core/controller_helpers/payment_parameters.rb +54 -0
  88. data/lib/spree/core/engine.rb +6 -9
  89. data/lib/spree/core/version.rb +1 -1
  90. data/lib/spree/core.rb +0 -1
  91. data/lib/spree/money.rb +18 -0
  92. data/lib/spree/permission_sets/default_customer.rb +1 -1
  93. data/lib/spree/permitted_attributes.rb +1 -1
  94. data/lib/spree/testing_support/authorization_helpers.rb +1 -0
  95. data/lib/spree/testing_support/capybara_ext.rb +13 -0
  96. data/lib/spree/testing_support/factories/order_factory.rb +5 -1
  97. data/lib/spree/testing_support/factories/payment_factory.rb +1 -1
  98. data/lib/spree/testing_support/factories/shipment_factory.rb +0 -1
  99. data/solidus_core.gemspec +3 -3
  100. data/spec/jobs/promotion_code_batch_job_spec.rb +65 -0
  101. data/spec/lib/calculated_adjustments_spec.rb +105 -1
  102. data/spec/lib/spree/core/testing_support/factories/order_factory_spec.rb +4 -1
  103. data/spec/lib/spree/core/testing_support/factories/payment_factory_spec.rb +8 -0
  104. data/spec/lib/spree/money_spec.rb +32 -0
  105. data/spec/lib/spree/permission_sets/default_customer_spec.rb +20 -0
  106. data/spec/mailers/promotion_code_batch_mailer_spec.rb +45 -0
  107. data/spec/models/spree/credit_card_spec.rb +86 -86
  108. data/spec/models/spree/gateway_spec.rb +3 -1
  109. data/spec/models/spree/inventory_unit_spec.rb +12 -4
  110. data/spec/models/spree/order/checkout_spec.rb +11 -32
  111. data/spec/models/spree/order/tax_spec.rb +2 -2
  112. data/spec/models/spree/order_contents_spec.rb +24 -1
  113. data/spec/models/spree/order_inventory_spec.rb +130 -83
  114. data/spec/models/spree/order_spec.rb +15 -117
  115. data/spec/models/spree/order_update_attributes_spec.rb +1 -44
  116. data/spec/models/spree/order_updater_spec.rb +10 -13
  117. data/spec/models/spree/payment_create_spec.rb +5 -1
  118. data/spec/models/spree/payment_method_spec.rb +16 -0
  119. data/spec/models/spree/payment_spec.rb +14 -8
  120. data/spec/models/spree/promotion_code/batch_builder_spec.rb +61 -0
  121. data/spec/models/spree/promotion_code_batch_spec.rb +58 -0
  122. data/spec/models/spree/promotion_code_spec.rb +4 -0
  123. data/spec/models/spree/promotion_spec.rb +3 -6
  124. data/spec/models/spree/return_authorization_spec.rb +0 -59
  125. data/spec/models/spree/shipment_spec.rb +4 -4
  126. data/spec/models/spree/stock/availability_validator_spec.rb +64 -9
  127. data/spec/models/spree/tax/item_adjuster_spec.rb +1 -2
  128. data/spec/models/spree/unit_cancel_spec.rb +0 -85
  129. data/spec/models/spree/user_spec.rb +3 -1
  130. data/spec/models/spree/variant/vat_price_generator_spec.rb +8 -2
  131. data/spec/models/spree/variant_spec.rb +16 -4
  132. data/spec/models/spree/wallet_payment_source_spec.rb +46 -0
  133. data/spec/models/spree/wallet_spec.rb +128 -0
  134. data/spec/support/concerns/payment_source.rb +64 -0
  135. metadata +51 -25
  136. data/app/assets/javascripts/spree.js.coffee.erb +0 -64
  137. data/app/models/spree/promotion_builder.rb +0 -55
  138. data/app/models/spree/promotion_code/code_builder.rb +0 -62
  139. data/config/initializers/premailer_assets.rb +0 -1
  140. data/lib/spree/core/unreturned_item_charger.rb +0 -106
  141. data/lib/tasks/exchanges.rake +0 -47
  142. data/spec/lib/spree/core/unreturned_item_charger_spec.rb +0 -126
  143. data/spec/lib/tasks/exchanges_spec.rb +0 -220
  144. data/spec/models/spree/promotion_builder_spec.rb +0 -120
  145. data/spec/models/spree/promotion_code/code_builder_spec.rb +0 -77
@@ -19,12 +19,35 @@ describe Spree::OrderContents, type: :model do
19
19
  end
20
20
 
21
21
  context 'given a shipment' do
22
+ let!(:shipment) { create(:shipment) }
23
+
22
24
  it "ensure shipment calls update_amounts instead of order calling ensure_updated_shipments" do
23
- shipment = create(:shipment)
24
25
  expect(subject.order).to_not receive(:ensure_updated_shipments)
25
26
  expect(shipment).to receive(:update_amounts)
26
27
  subject.add(variant, 1, shipment: shipment)
27
28
  end
29
+
30
+ context "with quantity=1" do
31
+ it "creates correct inventory" do
32
+ subject.add(variant, 1, shipment: shipment)
33
+ expect(order.inventory_units.count).to eq(1)
34
+ end
35
+ end
36
+
37
+ context "with quantity=2" do
38
+ it "creates correct inventory" do
39
+ subject.add(variant, 2, shipment: shipment)
40
+ expect(order.inventory_units.count).to eq(2)
41
+ end
42
+ end
43
+
44
+ context "called multiple times" do
45
+ it "creates correct inventory" do
46
+ subject.add(variant, 1, shipment: shipment)
47
+ subject.add(variant, 1, shipment: shipment)
48
+ expect(order.inventory_units.count).to eq(2)
49
+ end
50
+ end
28
51
  end
29
52
 
30
53
  context 'not given a shipment' do
@@ -3,37 +3,57 @@ require 'spec_helper'
3
3
  describe Spree::OrderInventory, type: :model do
4
4
  let(:order) { create :completed_order_with_totals }
5
5
  let(:line_item) { order.line_items.first }
6
+ let(:shipment) { order.shipments.first }
7
+ let(:variant) { subject.variant }
8
+ let(:stock_item) { shipment.stock_location.stock_item(variant) }
9
+
6
10
 
7
11
  subject { described_class.new(order, line_item) }
8
12
 
9
- context "when order is missing inventory units" do
10
- before { line_item.update_column(:quantity, 2) }
13
+ context "insufficient inventory units" do
14
+ let(:old_quantity) { 1 }
15
+ let(:new_quantity) { 3 }
16
+
17
+ before do
18
+ line_item.update_attributes!(quantity: old_quantity)
19
+
20
+ line_item.update_column(:quantity, new_quantity)
21
+ subject.line_item.reload
22
+ end
11
23
 
12
24
  it 'creates the proper number of inventory units' do
13
- subject.verify
14
- expect(subject.inventory_units.count).to eq 2
25
+ expect(line_item.inventory_units.count).to eq(old_quantity)
26
+ subject.verify(shipment)
27
+ expect(line_item.inventory_units.count).to eq(new_quantity)
15
28
  end
16
- end
17
29
 
18
- context "#add_to_shipment" do
19
- let(:shipment) { order.shipments.first }
30
+ it "unstocks items" do
31
+ expect {
32
+ subject.verify(shipment)
33
+ }.to change { stock_item.reload.count_on_hand }.by(-2)
34
+ end
20
35
 
21
36
  context "order is not completed" do
22
- before { allow(order).to receive_messages completed?: false }
37
+ before { order.update_columns completed_at: nil }
23
38
 
24
39
  it "doesn't unstock items" do
25
- expect(shipment.stock_location).not_to receive(:unstock)
26
- expect(subject.send(:add_to_shipment, shipment, 5)).to eq(5)
40
+ expect {
41
+ subject.verify(shipment)
42
+ }.not_to change { stock_item.reload.count_on_hand }
27
43
  end
28
44
  end
29
45
 
30
46
  context "inventory units state" do
31
47
  before { shipment.inventory_units.destroy_all }
48
+ let(:new_quantity) { 5 }
32
49
 
33
50
  it 'sets inventory_units state as per stock location availability' do
34
- expect(shipment.stock_location).to receive(:fill_status).with(subject.variant, 5).and_return([3, 2])
51
+ stock_item.update_columns(
52
+ backorderable: true,
53
+ count_on_hand: 3
54
+ )
35
55
 
36
- expect(subject.send(:add_to_shipment, shipment, 5)).to eq(5)
56
+ subject.verify
37
57
 
38
58
  units = shipment.inventory_units_for(subject.variant).group_by(&:state)
39
59
  expect(units['backordered'].size).to eq(2)
@@ -42,33 +62,31 @@ describe Spree::OrderInventory, type: :model do
42
62
  end
43
63
 
44
64
  context "store doesnt track inventory" do
45
- let(:variant) { create(:variant) }
65
+ let(:new_quantity) { 1 }
46
66
 
47
67
  before { Spree::Config.track_inventory_levels = false }
48
68
 
49
- it "creates only on hand inventory units" do
69
+ it "creates on hand inventory units" do
50
70
  variant.stock_items.destroy_all
51
71
 
52
- # The before_save callback in LineItem would verify inventory
53
- line_item = order.contents.add variant, 1, shipment: shipment
72
+ subject.verify(shipment)
54
73
 
55
- units = shipment.inventory_units_for(line_item.variant)
74
+ units = shipment.inventory_units_for(variant)
56
75
  expect(units.count).to eq 1
57
76
  expect(units.first).to be_on_hand
58
77
  end
59
78
  end
60
79
 
61
80
  context "variant doesnt track inventory" do
62
- let(:variant) { create(:variant) }
63
- before { variant.track_inventory = false }
81
+ before { variant.update_attributes!(track_inventory: false) }
82
+ let(:new_quantity) { 1 }
64
83
 
65
- it "creates only on hand inventory units" do
84
+ it "creates on hand inventory units" do
66
85
  variant.stock_items.destroy_all
67
86
 
68
- line_item = order.contents.add variant, 1
69
87
  subject.verify(shipment)
70
88
 
71
- units = shipment.inventory_units_for(line_item.variant)
89
+ units = shipment.inventory_units_for(variant)
72
90
  expect(units.count).to eq 1
73
91
  expect(units.first).to be_on_hand
74
92
  end
@@ -79,9 +97,21 @@ describe Spree::OrderInventory, type: :model do
79
97
 
80
98
  stock_item = shipment.stock_location.stock_item(subject.variant)
81
99
  movement = stock_item.stock_movements.last
82
- # movement.originator.should == shipment
100
+ expect(movement.originator).to eq(shipment)
83
101
  expect(movement.quantity).to eq(-5)
84
102
  end
103
+
104
+ context "calling multiple times" do
105
+ it "creates the correct number of inventory units" do
106
+ line_item.update_columns(quantity: 2)
107
+ subject.verify(shipment)
108
+ expect(line_item.inventory_units.count).to eq(2)
109
+
110
+ line_item.update_columns(quantity: 3)
111
+ subject.verify(shipment)
112
+ expect(line_item.inventory_units.count).to eq(3)
113
+ end
114
+ end
85
115
  end
86
116
 
87
117
  context "#determine_target_shipment" do
@@ -122,11 +152,13 @@ describe Spree::OrderInventory, type: :model do
122
152
  end
123
153
 
124
154
  context 'when order has too many inventory units' do
155
+ let(:old_quantity) { 3 }
156
+ let(:new_quantity) { 2 }
157
+
125
158
  before do
126
- line_item.quantity = 3
127
- line_item.save!
159
+ line_item.update_attributes!(quantity: old_quantity)
128
160
 
129
- line_item.update_column(:quantity, 2)
161
+ line_item.update_column(:quantity, new_quantity)
130
162
  subject.line_item.reload
131
163
  end
132
164
 
@@ -137,93 +169,108 @@ describe Spree::OrderInventory, type: :model do
137
169
 
138
170
  it 'should decrease the number of inventory units' do
139
171
  subject.verify
140
- expect(subject.inventory_units.count).to eq 2
172
+ expect(line_item.inventory_units.count).to eq 2
173
+ expect(order.inventory_units.count).to eq 2
141
174
  end
142
175
 
143
- context '#remove_from_shipment' do
144
- let(:shipment) { order.shipments.first }
145
- let(:variant) { subject.variant }
176
+ context "order is not completed" do
177
+ before { order.update_columns(completed_at: nil) }
146
178
 
147
- context "order is not completed" do
148
- before { allow(order).to receive_messages completed?: false }
179
+ it "doesn't restock items" do
180
+ expect(shipment.stock_location).not_to receive(:restock)
149
181
 
150
- it "doesn't restock items" do
151
- expect(shipment.stock_location).not_to receive(:restock)
152
- expect(subject.send(:remove_from_shipment, shipment, 1)).to eq(1)
153
- end
182
+ expect {
183
+ subject.verify(shipment)
184
+ }.not_to change { stock_item.reload.count_on_hand }
185
+
186
+ expect(line_item.inventory_units.count).to eq(new_quantity)
154
187
  end
188
+ end
189
+
190
+ it 'should change count_on_hand' do
191
+ expect {
192
+ subject.verify(shipment)
193
+ }.to change { stock_item.reload.count_on_hand }.by(1)
194
+ end
155
195
 
156
- it 'should create stock_movement' do
157
- expect(subject.send(:remove_from_shipment, shipment, 1)).to eq(1)
196
+ it 'should create stock_movement' do
197
+ stock_item = shipment.stock_location.stock_item(variant)
158
198
 
159
- stock_item = shipment.stock_location.stock_item(variant)
160
- movement = stock_item.stock_movements.last
161
- # movement.originator.should == shipment
162
- expect(movement.quantity).to eq(1)
199
+ expect {
200
+ subject.verify(shipment)
201
+ }.to change { stock_item.stock_movements.count }.by(1)
202
+
203
+ movement = stock_item.stock_movements.last
204
+ expect(movement.originator).to eq shipment
205
+ expect(movement.quantity).to eq(1)
206
+ end
207
+
208
+ context 'with some backordered' do
209
+ let(:new_quantity) { 1 }
210
+
211
+ before do
212
+ line_item.inventory_units[0].update_columns(state: 'backordered')
213
+ line_item.inventory_units[1].update_columns(state: 'on_hand')
214
+ line_item.inventory_units[2].update_columns(state: 'backordered')
163
215
  end
164
216
 
165
217
  it 'should destroy backordered units first' do
166
- allow(shipment).to receive_messages(inventory_units_for_item: [
167
- mock_model(Spree::InventoryUnit, variant_id: variant.id, state: 'backordered'),
168
- mock_model(Spree::InventoryUnit, variant_id: variant.id, state: 'on_hand'),
169
- mock_model(Spree::InventoryUnit, variant_id: variant.id, state: 'backordered')
170
- ])
218
+ on_hand_unit = line_item.inventory_units.find_by state: 'on_hand'
171
219
 
172
- expect(shipment.inventory_units_for_item[0]).to receive(:destroy)
173
- expect(shipment.inventory_units_for_item[1]).not_to receive(:destroy)
174
- expect(shipment.inventory_units_for_item[2]).to receive(:destroy)
220
+ subject.verify(shipment)
175
221
 
176
- expect(subject.send(:remove_from_shipment, shipment, 2)).to eq(2)
222
+ expect(line_item.inventory_units.reload).to eq([on_hand_unit])
177
223
  end
224
+ end
178
225
 
179
- it 'should destroy unshipped units first' do
180
- allow(shipment).to receive_messages(inventory_units_for_item: [
181
- mock_model(Spree::InventoryUnit, variant_id: variant.id, state: 'shipped'),
182
- mock_model(Spree::InventoryUnit, variant_id: variant.id, state: 'on_hand')
183
- ])
226
+ context 'with some shipped items' do
227
+ let(:old_quantity) { 2 }
228
+ let(:new_quantity) { 1 }
184
229
 
185
- expect(shipment.inventory_units_for_item[0]).not_to receive(:destroy)
186
- expect(shipment.inventory_units_for_item[1]).to receive(:destroy)
230
+ let(:shipped_unit) { line_item.inventory_units[0] }
231
+ before do
232
+ shipped_unit.update_columns(state: 'shipped')
233
+ end
234
+
235
+ it 'should destroy unshipped units first' do
236
+ subject.verify(shipment)
187
237
 
188
- expect(subject.send(:remove_from_shipment, shipment, 1)).to eq(1)
238
+ expect(line_item.inventory_units.reload).to eq([shipped_unit])
189
239
  end
190
240
 
191
- it 'only attempts to destroy as many units as are eligible, and return amount destroyed' do
192
- allow(shipment).to receive_messages(inventory_units_for_item: [
193
- mock_model(Spree::InventoryUnit, variant_id: variant.id, state: 'shipped'),
194
- mock_model(Spree::InventoryUnit, variant_id: variant.id, state: 'on_hand')
195
- ])
241
+ context 'trying to remove shipped units' do
242
+ let(:new_quantity) { 0 }
196
243
 
197
- expect(shipment.inventory_units_for_item[0]).not_to receive(:destroy)
198
- expect(shipment.inventory_units_for_item[1]).to receive(:destroy)
244
+ it 'only attempts to destroy as many units as are eligible, and return amount destroyed' do
245
+ subject.verify(shipment)
199
246
 
200
- expect(subject.send(:remove_from_shipment, shipment, 1)).to eq(1)
247
+ expect(line_item.inventory_units.reload).to eq([shipped_unit])
248
+ end
201
249
  end
250
+ end
202
251
 
203
- it 'should destroy self if not inventory units remain' do
204
- shipment.inventory_units[1...999].each(&:destroy)
205
- shipment.inventory_units.reload
252
+ context 'destroying all units' do
253
+ let(:new_quantity) { 0 }
206
254
 
255
+ it 'should destroy shipment' do
207
256
  expect {
208
- expect(subject.send(:remove_from_shipment, shipment, 1)).to eq(1)
257
+ subject.verify(shipment)
209
258
  }.to change{ order.shipments.count }.from(1).to(0)
210
259
  end
260
+ end
211
261
 
212
- context "inventory unit line item and variant points to different products" do
213
- let(:different_line_item) { create(:line_item) }
262
+ context "inventory unit line item and variant points to different products" do
263
+ let(:new_quantity) { 0 }
264
+ let(:different_line_item) { create(:line_item, order: order) }
214
265
 
215
- let!(:different_inventory) do
216
- shipment.set_up_inventory("on_hand", variant, order, different_line_item)
217
- end
266
+ let!(:different_inventory) do
267
+ shipment.set_up_inventory("on_hand", variant, order, different_line_item)
268
+ end
218
269
 
219
- context "completed order" do
220
- before { order.touch :completed_at }
270
+ it "removes only units that match both line item and variant" do
271
+ subject.verify(shipment)
221
272
 
222
- it "removes only units that match both line item and variant" do
223
- subject.send(:remove_from_shipment, shipment, shipment.inventory_units.count)
224
- expect(different_inventory.reload).to be_persisted
225
- end
226
- end
273
+ expect(different_inventory.reload).to be_persisted
227
274
  end
228
275
  end
229
276
  end
@@ -107,10 +107,11 @@ describe Spree::Order, type: :model do
107
107
 
108
108
  it "update and persist totals" do
109
109
  expect(shipment).to receive :update_amounts
110
- expect(order.updater).to receive :update_shipment_total
111
- expect(order.updater).to receive :persist_totals
110
+ expect(order.updater).to receive :update
112
111
 
113
- order.set_shipments_cost
112
+ Spree::Deprecation.silence do
113
+ order.set_shipments_cost
114
+ end
114
115
  end
115
116
  end
116
117
 
@@ -537,6 +538,16 @@ describe Spree::Order, type: :model do
537
538
  expect(order.available_payment_methods).to include(payment_method)
538
539
  end
539
540
 
541
+ it "does not include inactive payment methods" do
542
+ Spree::PaymentMethod.create!({
543
+ name: "Fake",
544
+ active: false,
545
+ available_to_users: true,
546
+ available_to_admin: true
547
+ })
548
+ expect(order.available_payment_methods.count).to eq(0)
549
+ end
550
+
540
551
  context "with more than one payment method" do
541
552
  subject { order.available_payment_methods }
542
553
 
@@ -550,7 +561,7 @@ describe Spree::Order, type: :model do
550
561
  end
551
562
 
552
563
  it "respects the order of methods based on position" do
553
- expect(subject).to eql([second_method, first_method])
564
+ expect(subject).to eq([second_method, first_method])
554
565
  end
555
566
  end
556
567
 
@@ -956,25 +967,6 @@ describe Spree::Order, type: :model do
956
967
 
957
968
  expect { shipment.reload }.not_to raise_error
958
969
  end
959
-
960
- context "unreturned exchange" do
961
- let!(:first_shipment) do
962
- create(:shipment, order: subject, state: first_shipment_state, created_at: 5.days.ago)
963
- end
964
- let!(:second_shipment) do
965
- create(:shipment, order: subject, state: second_shipment_state, created_at: 5.days.ago)
966
- end
967
-
968
- context "all shipments are shipped" do
969
- let(:first_shipment_state) { "shipped" }
970
- let(:second_shipment_state) { "shipped" }
971
-
972
- it "returns the shipments" do
973
- subject.create_proposed_shipments
974
- expect(subject.shipments).to match_array [first_shipment, second_shipment]
975
- end
976
- end
977
- end
978
970
  end
979
971
 
980
972
  describe "#all_inventory_units_returned?" do
@@ -1007,48 +999,6 @@ describe Spree::Order, type: :model do
1007
999
  end
1008
1000
  end
1009
1001
 
1010
- describe "#unreturned_exchange?" do
1011
- let(:order) { create(:order_with_line_items) }
1012
- subject { order.reload.unreturned_exchange? }
1013
-
1014
- context "the order does not have a shipment" do
1015
- before { order.shipments.destroy_all }
1016
-
1017
- it { is_expected.to be false }
1018
- end
1019
-
1020
- context "shipment created after order" do
1021
- it { is_expected.to be false }
1022
- end
1023
-
1024
- context "shipment created before order" do
1025
- before do
1026
- order.shipments.first.update_attributes!(created_at: order.created_at - 1.day)
1027
- end
1028
-
1029
- it { is_expected.to be true }
1030
- end
1031
- end
1032
-
1033
- describe '.unreturned_exchange' do
1034
- let(:order) { create(:order_with_line_items) }
1035
- subject { described_class.unreturned_exchange }
1036
-
1037
- it 'includes orders that have a shipment created prior to the order' do
1038
- order.shipments.first.update_attributes!(created_at: order.created_at - 1.day)
1039
- expect(subject).to include order
1040
- end
1041
-
1042
- it 'excludes orders that were created prior to their shipment' do
1043
- expect(subject).not_to include order
1044
- end
1045
-
1046
- it 'excludes orders with no shipment' do
1047
- order.shipments.destroy_all
1048
- expect(subject).not_to include order
1049
- end
1050
- end
1051
-
1052
1002
  context "store credit" do
1053
1003
  shared_examples "check total store credit from payments" do
1054
1004
  context "with valid payments" do
@@ -1459,56 +1409,4 @@ describe Spree::Order, type: :model do
1459
1409
  end
1460
1410
  end
1461
1411
  end
1462
-
1463
- describe "#validate_payments_attributes" do
1464
- let(:attributes) { [ActionController::Parameters.new(payment_method_id: payment_method.id)] }
1465
- subject do
1466
- order.validate_payments_attributes(attributes)
1467
- end
1468
-
1469
- context "with empty array" do
1470
- let(:attributes) { [] }
1471
- it "doesn't error" do
1472
- subject
1473
- end
1474
- end
1475
-
1476
- context "with no payment method specified" do
1477
- let(:attributes) { [ActionController::Parameters.new({})] }
1478
- it "doesn't error" do
1479
- subject
1480
- end
1481
- end
1482
-
1483
- context "with valid payment method" do
1484
- let(:payment_method) { create(:check_payment_method) }
1485
- it "doesn't error" do
1486
- subject
1487
- end
1488
- end
1489
-
1490
- context "with inactive payment method" do
1491
- let(:payment_method) { create(:check_payment_method, active: false) }
1492
-
1493
- it "raises RecordNotFound" do
1494
- expect { subject }.to raise_error(ActiveRecord::RecordNotFound)
1495
- end
1496
- end
1497
-
1498
- context "with unavailable payment method" do
1499
- let(:payment_method) { create(:check_payment_method, available_to_users: false) }
1500
-
1501
- it "raises RecordNotFound" do
1502
- expect { subject }.to raise_error(ActiveRecord::RecordNotFound)
1503
- end
1504
- end
1505
-
1506
- context "with soft-deleted payment method" do
1507
- let(:payment_method) { create(:check_payment_method, deleted_at: Time.current) }
1508
-
1509
- it "raises RecordNotFound" do
1510
- expect { subject }.to raise_error(ActiveRecord::RecordNotFound)
1511
- end
1512
- end
1513
- end
1514
1412
  end
@@ -3,7 +3,6 @@ require 'spec_helper'
3
3
  module Spree
4
4
  RSpec.describe OrderUpdateAttributes do
5
5
  let(:order) { create(:order) }
6
- let(:payment_method) { create(:payment_method) }
7
6
  let(:request_env) { nil }
8
7
  let(:update) { described_class.new(order, attributes, request_env: request_env) }
9
8
 
@@ -26,10 +25,7 @@ module Spree
26
25
  let(:attributes) do
27
26
  {
28
27
  payments_attributes: [
29
- {
30
- payment_method_id: payment_method.id,
31
- source_attributes: attributes_for(:credit_card)
32
- }
28
+ { source_attributes: attributes_for(:credit_card) }
33
29
  ]
34
30
  }
35
31
  end
@@ -43,44 +39,5 @@ module Spree
43
39
  end
44
40
  end
45
41
  end
46
-
47
- context 'when changing shipping method' do
48
- let!(:order) { create(:order_with_line_items, shipping_method: shipping_method1) }
49
- let(:shipment){ order.shipments.first }
50
- let!(:zone) { create(:zone) }
51
- let!(:shipping_method1){ create(:shipping_method, cost: 10, zones: [zone]) }
52
- let!(:shipping_method2){ create(:shipping_method, cost: 20, zones: [zone]) }
53
-
54
- let(:attributes) do
55
- {
56
- shipments_attributes: {
57
- 0 => { selected_shipping_rate_id: shipping_method2, id: shipment.id }
58
- }
59
- }
60
- end
61
-
62
- it "updates shipment costs" do
63
- zone.zone_members.create!(zoneable: order.ship_address.country)
64
- order.create_proposed_shipments
65
- order.set_shipments_cost
66
-
67
- shipping_rate2 = shipment.shipping_rates.find_by(shipping_method_id: shipping_method2.id)
68
-
69
- expect(order.shipment_total).to eq(10)
70
-
71
- # We need an order which doesn't have shipping_rates loaded
72
- order.reload
73
-
74
- described_class.new(
75
- order,
76
- shipments_attributes: {
77
- 0 => { selected_shipping_rate_id: shipping_rate2.id, id: shipment.id }
78
- }
79
- ).apply
80
-
81
- expect(order.shipment_total).to eq(20)
82
- expect(order.shipments.first.cost).to eq(20)
83
- end
84
- end
85
42
  end
86
43
  end
@@ -16,20 +16,22 @@ module Spree
16
16
  context 'with refund' do
17
17
  it "updates payment totals" do
18
18
  create(:payment_with_refund, order: order, amount: 33.25, refund_amount: 3)
19
- Spree::OrderUpdater.new(order).update_payment_total
19
+ updater.update
20
20
  expect(order.payment_total).to eq(30.25)
21
21
  end
22
22
  end
23
23
 
24
24
  it "update item total" do
25
- updater.update_item_total
26
- expect(order.item_total).to eq(20)
25
+ expect {
26
+ updater.update
27
+ }.to change { order.item_total }.to 20
27
28
  end
28
29
 
29
30
  it "update shipment total" do
30
31
  create(:shipment, order: order, cost: 10)
31
- updater.update_shipment_total
32
- expect(order.shipment_total).to eq(10)
32
+ expect {
33
+ updater.update
34
+ }.to change { order.shipment_total }.to 10
33
35
  end
34
36
 
35
37
  context 'with order promotion followed by line item addition' do
@@ -60,7 +62,7 @@ module Spree
60
62
  create(:adjustment, adjustable: order, order: order, source: nil, amount: 10)
61
63
 
62
64
  expect {
63
- updater.update_adjustment_total
65
+ updater.update
64
66
  }.to change {
65
67
  order.adjustment_total
66
68
  }.from(0).to(10)
@@ -483,17 +485,12 @@ module Spree
483
485
 
484
486
  it "updates each shipment" do
485
487
  expect(shipment).to receive(:update!)
486
- updater.update_shipments
487
- end
488
-
489
- it "refreshes shipment rates" do
490
- expect(shipment).to receive(:refresh_rates)
491
- updater.update_shipments
488
+ updater.update
492
489
  end
493
490
 
494
491
  it "updates the shipment amount" do
495
492
  expect(shipment).to receive(:update_amounts)
496
- updater.update_shipments
493
+ updater.update
497
494
  end
498
495
  end
499
496
  end
@@ -68,7 +68,7 @@ module Spree
68
68
  end
69
69
  end
70
70
 
71
- context 'with an existing credit card' do
71
+ context 'with the deprecated existing_card_id attribute' do
72
72
  let(:user) { create(:user) }
73
73
  let!(:credit_card) { create(:credit_card, user: order.user) }
74
74
 
@@ -81,6 +81,10 @@ module Spree
81
81
  }
82
82
  end
83
83
 
84
+ around do |example|
85
+ Spree::Deprecation.silence { example.run }
86
+ end
87
+
84
88
  it 'sets the existing card as the source for the new payment' do
85
89
  expect(new_payment.source).to eq(credit_card)
86
90
  end