solidus_frontend 1.1.0 → 1.1.1

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.

Potentially problematic release.


This version of solidus_frontend might be problematic. Click here for more details.

Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +6 -0
  3. data/Rakefile +15 -0
  4. data/script/rails +9 -0
  5. data/solidus_frontend.gemspec +28 -0
  6. data/spec/controllers/controller_extension_spec.rb +126 -0
  7. data/spec/controllers/controller_helpers_spec.rb +26 -0
  8. data/spec/controllers/spree/checkout_controller_spec.rb +400 -0
  9. data/spec/controllers/spree/checkout_controller_with_views_spec.rb +36 -0
  10. data/spec/controllers/spree/content_controller_spec.rb +7 -0
  11. data/spec/controllers/spree/current_order_tracking_spec.rb +44 -0
  12. data/spec/controllers/spree/home_controller_spec.rb +27 -0
  13. data/spec/controllers/spree/orders_controller_ability_spec.rb +104 -0
  14. data/spec/controllers/spree/orders_controller_spec.rb +134 -0
  15. data/spec/controllers/spree/orders_controller_transitions_spec.rb +31 -0
  16. data/spec/controllers/spree/products_controller_spec.rb +36 -0
  17. data/spec/controllers/spree/taxons_controller_spec.rb +12 -0
  18. data/spec/features/address_spec.rb +76 -0
  19. data/spec/features/automatic_promotion_adjustments_spec.rb +47 -0
  20. data/spec/features/caching/products_spec.rb +55 -0
  21. data/spec/features/caching/taxons_spec.rb +22 -0
  22. data/spec/features/cart_spec.rb +81 -0
  23. data/spec/features/checkout_spec.rb +477 -0
  24. data/spec/features/checkout_unshippable_spec.rb +36 -0
  25. data/spec/features/coupon_code_spec.rb +227 -0
  26. data/spec/features/currency_spec.rb +18 -0
  27. data/spec/features/free_shipping_promotions_spec.rb +59 -0
  28. data/spec/features/locale_spec.rb +60 -0
  29. data/spec/features/order_spec.rb +73 -0
  30. data/spec/features/products_spec.rb +260 -0
  31. data/spec/features/promotion_code_invalidation_spec.rb +51 -0
  32. data/spec/features/quantity_promotions_spec.rb +128 -0
  33. data/spec/features/taxons_spec.rb +135 -0
  34. data/spec/features/template_rendering_spec.rb +19 -0
  35. data/spec/fixtures/thinking-cat.jpg +0 -0
  36. data/spec/helpers/base_helper_spec.rb +11 -0
  37. data/spec/spec_helper.rb +129 -0
  38. data/spec/support/shared_contexts/checkout_setup.rb +9 -0
  39. data/spec/support/shared_contexts/custom_products.rb +25 -0
  40. data/spec/support/shared_contexts/product_prototypes.rb +30 -0
  41. data/spec/views/spree/checkout/_summary_spec.rb +11 -0
  42. metadata +46 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8ad1542e9b72fbbb94234f29a5152046547bde16
4
- data.tar.gz: ea41c5e70d3b926c821a5c7f8ea8205be50fbf30
3
+ metadata.gz: 91e44cc077f8c0722c34d2e140538dfc7b93666f
4
+ data.tar.gz: 526ec8a133539279d5e019f4f5d615ca280df47f
5
5
  SHA512:
6
- metadata.gz: cfaf5acb4bf0053d1c29b1cf059cae7c49a4c01b809b03ab7d2838ab82ded99de39ebd2847c297b98b25c594050cb4675724101e4c01d54f7e28cd2bdb27f551
7
- data.tar.gz: 5b2859edac2ca908c938174d06251f442f9fd52338c78a67a42f0c67afef1243fb15f3eb5b9e333bc83fbf33d555c55820a0864ef696371ad3007a8245d36875
6
+ metadata.gz: 518839b6bcd447a9a06bd8d248021250d9c28d2f2a345d40dbe4e1f44a6cb166ad18acbd62e59c8fc6dccc7987ec19a50be17cff062a6fdbabe3dab05c93eccb
7
+ data.tar.gz: a6a22da41038fadfd08b04cf21537b730027623a2997ef49ba7394b52305c6de43d8cf0bdd09f99b6290182be72eb57567f6bb930995e33e7eef80665d4ca4a4
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ eval(File.read(File.dirname(__FILE__) + '/../common_spree_dependencies.rb'))
2
+
3
+ gem 'solidus_core', :path => '../core'
4
+ gem 'solidus_api', :path => '../api'
5
+
6
+ gemspec
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+ require 'rspec/core/rake_task'
5
+ require 'spree/testing_support/common_rake'
6
+
7
+ RSpec::Core::RakeTask.new
8
+
9
+ task :default => :spec
10
+
11
+ desc "Generates a dummy app for testing"
12
+ task :test_app do
13
+ ENV['LIB_NAME'] = 'spree/frontend'
14
+ Rake::Task['common:test_app'].invoke
15
+ end
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ ENGINE_ROOT = File.expand_path('../..', __FILE__)
5
+ ENGINE_PATH = File.expand_path('../../lib/spree/frontend/engine', __FILE__)
6
+
7
+ require 'rails/all'
8
+ require 'rails/engine/commands'
9
+
@@ -0,0 +1,28 @@
1
+ # encoding: UTF-8
2
+ version = File.read(File.expand_path("../../SOLIDUS_VERSION", __FILE__)).strip
3
+
4
+ Gem::Specification.new do |s|
5
+ s.platform = Gem::Platform::RUBY
6
+ s.name = 'solidus_frontend'
7
+ s.version = version
8
+ s.summary = 'Cart and storefront for the Solidus e-commerce project.'
9
+ s.description = s.summary
10
+
11
+ s.required_ruby_version = '>= 2.1.0'
12
+ s.author = 'Solidus Team'
13
+ s.email = 'contact@solidus.io'
14
+ s.homepage = 'http://solidus.io/'
15
+ s.rubyforge_project = 'solidus_frontend'
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.require_path = 'lib'
19
+ s.requirements << 'none'
20
+
21
+ s.add_dependency 'solidus_api', version
22
+ s.add_dependency 'solidus_core', version
23
+
24
+ s.add_dependency 'canonical-rails', '~> 0.0.4'
25
+ s.add_dependency 'jquery-rails'
26
+
27
+ s.add_development_dependency 'capybara-accessible'
28
+ end
@@ -0,0 +1,126 @@
1
+ require 'spec_helper'
2
+
3
+ # This test tests the functionality within
4
+ # spree/core/controller_helpers/respond_with.rb
5
+ # Rather than duck-punching the existing controllers, let's define a custom one:
6
+ class Spree::CustomController < Spree::BaseController
7
+ def index
8
+ respond_with(Spree::Address.new) do |format|
9
+ format.html { render :text => "neutral" }
10
+ end
11
+ end
12
+
13
+ def create
14
+ # Just need a model with validations
15
+ # Address is good enough, so let's go with that
16
+ address = Spree::Address.new(params[:address])
17
+ respond_with(address)
18
+ end
19
+ end
20
+
21
+ describe Spree::CustomController, :type => :controller do
22
+ after do
23
+ Spree::CustomController.clear_overrides!
24
+ end
25
+
26
+ before do
27
+ @routes = ActionDispatch::Routing::RouteSet.new.tap do |r|
28
+ r.draw {
29
+ get 'index', to: 'spree/custom#index'
30
+ post 'create', to: 'spree/custom#create'
31
+ }
32
+ end
33
+ end
34
+
35
+ context "extension testing" do
36
+ context "index" do
37
+ context "specify symbol for handler instead of Proc" do
38
+ before do
39
+ Spree::CustomController.class_eval do
40
+ respond_override({:index => {:html => {:success => :success_method}}})
41
+
42
+ private
43
+
44
+ def success_method
45
+ render :text => 'success!!!'
46
+ end
47
+ end
48
+ end
49
+
50
+ describe "GET" do
51
+ it "has value success" do
52
+ spree_get :index
53
+ expect(response).to be_success
54
+ assert (response.body =~ /success!!!/)
55
+ end
56
+ end
57
+ end
58
+
59
+ context "render" do
60
+ before do
61
+ Spree::CustomController.instance_eval do
62
+ respond_override({:index => {:html => {:success => lambda { render(:text => 'success!!!') }}}})
63
+ respond_override({:index => {:html => {:failure => lambda { render(:text => 'failure!!!') }}}})
64
+ end
65
+ end
66
+
67
+ describe "GET" do
68
+ it "has value success" do
69
+ spree_get :index
70
+ expect(response).to be_success
71
+ assert (response.body =~ /success!!!/)
72
+ end
73
+ end
74
+ end
75
+
76
+ context "redirect" do
77
+ before do
78
+ Spree::CustomController.instance_eval do
79
+ respond_override({:index => {:html => {:success => lambda { redirect_to('/cart') }}}})
80
+ respond_override({:index => {:html => {:failure => lambda { render(:text => 'failure!!!') }}}})
81
+ end
82
+ end
83
+
84
+ describe "GET" do
85
+ it "has value success" do
86
+ spree_get :index
87
+ expect(response).to be_redirect
88
+ end
89
+ end
90
+ end
91
+
92
+ context "validation error" do
93
+ before do
94
+ Spree::CustomController.instance_eval do
95
+ respond_to :html
96
+ respond_override({:create => {:html => {:success => lambda { render(:text => 'success!!!') }}}})
97
+ respond_override({:create => {:html => {:failure => lambda { render(:text => 'failure!!!') }}}})
98
+ end
99
+ end
100
+
101
+ describe "POST" do
102
+ it "has value success" do
103
+ spree_post :create
104
+ expect(response).to be_success
105
+ assert (response.body =~ /success!/)
106
+ end
107
+ end
108
+ end
109
+
110
+ context 'A different controllers respond_override. Regression test for #1301' do
111
+ before do
112
+ Spree::CheckoutController.instance_eval do
113
+ respond_override({:index => {:html => {:success => lambda { render(:text => 'success!!!') }}}})
114
+ end
115
+ end
116
+
117
+ describe "POST" do
118
+ it "should not effect the wrong controller" do
119
+ spree_get :index
120
+ assert (response.body =~ /neutral/)
121
+ end
122
+ end
123
+ end
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ # In this file, we want to test that the controller helpers function correctly
4
+ # So we need to use one of the controllers inside Spree.
5
+ # ProductsController is good.
6
+ describe Spree::ProductsController, :type => :controller do
7
+
8
+ before do
9
+ I18n.enforce_available_locales = false
10
+ expect(I18n).to receive(:available_locales).and_return([:en, :de])
11
+ Spree::Frontend::Config[:locale] = :de
12
+ end
13
+
14
+ after do
15
+ Spree::Frontend::Config[:locale] = :en
16
+ I18n.locale = :en
17
+ I18n.enforce_available_locales = true
18
+ end
19
+
20
+ # Regression test for #1184
21
+ it "sets the default locale based off Spree::Frontend::Config[:locale]" do
22
+ expect(I18n.locale).to eq(:en)
23
+ spree_get :index
24
+ expect(I18n.locale).to eq(:de)
25
+ end
26
+ end
@@ -0,0 +1,400 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::CheckoutController, :type => :controller do
4
+ let(:token) { 'some_token' }
5
+ let(:user) { stub_model(Spree::LegacyUser) }
6
+ let(:order) { FactoryGirl.create(:order_with_totals) }
7
+
8
+ let(:address_params) do
9
+ address = FactoryGirl.build(:address)
10
+ address.attributes.except("created_at", "updated_at")
11
+ end
12
+
13
+ before do
14
+ allow(controller).to receive_messages try_spree_current_user: user
15
+ allow(controller).to receive_messages spree_current_user: user
16
+ allow(controller).to receive_messages current_order: order
17
+ end
18
+
19
+ context "#edit" do
20
+ it 'should check if the user is authorized for :edit' do
21
+ expect(controller).to receive(:authorize!).with(:edit, order, token)
22
+ request.cookie_jar.signed[:guest_token] = token
23
+ spree_get :edit, { state: 'address' }
24
+ end
25
+
26
+ it "should redirect to the cart path unless checkout_allowed?" do
27
+ allow(order).to receive_messages :checkout_allowed? => false
28
+ spree_get :edit, { :state => "delivery" }
29
+ expect(response).to redirect_to(spree.cart_path)
30
+ end
31
+
32
+ it "should redirect to the cart path if current_order is nil" do
33
+ allow(controller).to receive(:current_order).and_return(nil)
34
+ spree_get :edit, { :state => "delivery" }
35
+ expect(response).to redirect_to(spree.cart_path)
36
+ end
37
+
38
+ it "should redirect to cart if order is completed" do
39
+ allow(order).to receive_messages(:completed? => true)
40
+ spree_get :edit, { :state => "address" }
41
+ expect(response).to redirect_to(spree.cart_path)
42
+ end
43
+
44
+ # Regression test for #2280
45
+ it "should redirect to current step trying to access a future step" do
46
+ order.update_column(:state, "address")
47
+ spree_get :edit, { :state => "delivery" }
48
+ expect(response).to redirect_to spree.checkout_state_path("address")
49
+ end
50
+
51
+ context "when entering the checkout" do
52
+ before do
53
+ # The first step for checkout controller is address
54
+ # Transitioning into this state first is required
55
+ order.update_column(:state, "address")
56
+ end
57
+
58
+ it "should associate the order with a user" do
59
+ order.update_column :user_id, nil
60
+ expect(order).to receive(:associate_user!).with(user)
61
+ spree_get :edit, {}, order_id: 1
62
+ end
63
+ end
64
+ end
65
+
66
+ context "#update" do
67
+ it 'should check if the user is authorized for :edit' do
68
+ expect(controller).to receive(:authorize!).with(:edit, order, token)
69
+ request.cookie_jar.signed[:guest_token] = token
70
+ spree_post :update, { state: 'address' }
71
+ end
72
+
73
+ context "save successful" do
74
+ def spree_post_address
75
+ spree_post :update, {
76
+ :state => "address",
77
+ :order => {
78
+ :bill_address_attributes => address_params,
79
+ :use_billing => true
80
+ }
81
+ }
82
+ end
83
+
84
+ before do
85
+ # Must have *a* shipping method and a payment method so updating from address works
86
+ allow(order).to receive_messages :available_shipping_methods => [stub_model(Spree::ShippingMethod)]
87
+ allow(order).to receive_messages :available_payment_methods => [stub_model(Spree::PaymentMethod)]
88
+ allow(order).to receive_messages :ensure_available_shipping_rates => true
89
+ order.line_items << FactoryGirl.create(:line_item)
90
+ end
91
+
92
+ context "with the order in the cart state" do
93
+ before do
94
+ order.update_column(:state, "cart")
95
+ allow(order).to receive_messages :user => user
96
+ end
97
+
98
+ it "should assign order" do
99
+ spree_post :update, {:state => "address"}
100
+ expect(assigns[:order]).not_to be_nil
101
+ end
102
+
103
+ it "should advance the state" do
104
+ spree_post_address
105
+ expect(order.reload.state).to eq("delivery")
106
+ end
107
+
108
+ it "should redirect the next state" do
109
+ spree_post_address
110
+ expect(response).to redirect_to spree.checkout_state_path("delivery")
111
+ end
112
+
113
+ context "current_user respond to save address method" do
114
+ it "calls persist order address on user" do
115
+ expect(user).to receive(:persist_order_address)
116
+ spree_post :update, {
117
+ :state => "address",
118
+ :order => {
119
+ :bill_address_attributes => address_params,
120
+ :use_billing => true
121
+ },
122
+ :save_user_address => "1"
123
+ }
124
+ end
125
+ end
126
+
127
+ context "current_user doesnt respond to persist_order_address" do
128
+ it "doesnt raise any error" do
129
+ expect {
130
+ spree_post :update, {
131
+ :state => "address",
132
+ :order => {
133
+ :bill_address_attributes => address_params,
134
+ :use_billing => true
135
+ },
136
+ :save_user_address => "1"
137
+ }
138
+ }.to_not raise_error
139
+ end
140
+ end
141
+ end
142
+
143
+ context "with the order in the address state" do
144
+ before do
145
+ order.update_columns(ship_address_id: create(:address).id, state: "address")
146
+ allow(order).to receive_messages user: user
147
+ end
148
+
149
+ context "with a billing and shipping address" do
150
+ before do
151
+ @expected_bill_address_id = order.bill_address.id
152
+ @expected_ship_address_id = order.ship_address.id
153
+
154
+ spree_post :update, {
155
+ :state => "address",
156
+ :order => {
157
+ :bill_address_attributes => order.bill_address.attributes.except("created_at", "updated_at"),
158
+ :ship_address_attributes => order.ship_address.attributes.except("created_at", "updated_at"),
159
+ :use_billing => false
160
+ }
161
+ }
162
+
163
+ order.reload
164
+ end
165
+
166
+ it "unchanged address data does not change Address instances" do
167
+ expect(order.bill_address.id).to eq(@expected_bill_address_id)
168
+ expect(order.ship_address.id).to eq(@expected_ship_address_id)
169
+ end
170
+ end
171
+ end
172
+
173
+ context "when in the confirm state" do
174
+ before do
175
+ order.update_column(:state, "confirm")
176
+ allow(order).to receive_messages :user => user
177
+ # An order requires a payment to reach the complete state
178
+ # This is because payment_required? is true on the order
179
+ create(:payment, :amount => order.total, :order => order)
180
+ order.create_proposed_shipments
181
+ order.payments.reload
182
+ end
183
+
184
+ # This inadvertently is a regression test for #2694
185
+ it "should redirect to the order view" do
186
+ spree_post :update, {:state => "confirm"}
187
+ expect(response).to redirect_to spree.order_path(order)
188
+ end
189
+
190
+ it "should populate the flash message" do
191
+ spree_post :update, {:state => "confirm"}
192
+ expect(flash.notice).to eq(Spree.t(:order_processed_successfully))
193
+ end
194
+
195
+ it "should remove completed order from current_order" do
196
+ spree_post :update, {:state => "confirm"}, {:order_id => "foofah"}
197
+ expect(assigns(:current_order)).to be_nil
198
+ expect(assigns(:order)).to eql controller.current_order
199
+ end
200
+ end
201
+ end
202
+
203
+ context "save unsuccessful" do
204
+ before do
205
+ allow(order).to receive_messages :user => user
206
+ allow(order).to receive_messages :update_attributes => false
207
+ end
208
+
209
+ it "should not assign order" do
210
+ spree_post :update, {:state => "address"}
211
+ expect(assigns[:order]).not_to be_nil
212
+ end
213
+
214
+ it "should not change the order state" do
215
+ spree_post :update, { :state => 'address' }
216
+ end
217
+
218
+ it "should render the edit template" do
219
+ spree_post :update, { :state => 'address' }
220
+ expect(response).to render_template :edit
221
+ end
222
+ end
223
+
224
+ context "when current_order is nil" do
225
+ before { allow(controller).to receive_messages :current_order => nil }
226
+
227
+ it "should not change the state if order is completed" do
228
+ expect(order).not_to receive(:update_attribute)
229
+ spree_post :update, {:state => "confirm"}
230
+ end
231
+
232
+ it "should redirect to the cart_path" do
233
+ spree_post :update, {:state => "confirm"}
234
+ expect(response).to redirect_to spree.cart_path
235
+ end
236
+ end
237
+
238
+ context "Spree::Core::GatewayError" do
239
+ before do
240
+ allow(order).to receive_messages :user => user
241
+ allow(order).to receive(:update_attributes).and_raise(Spree::Core::GatewayError.new("Invalid something or other."))
242
+ spree_post :update, {:state => "address"}
243
+ end
244
+
245
+ it "should render the edit template and display exception message" do
246
+ expect(response).to render_template :edit
247
+ expect(flash.now[:error]).to eq(Spree.t(:spree_gateway_error_flash_for_checkout))
248
+ expect(assigns(:order).errors[:base]).to include("Invalid something or other.")
249
+ end
250
+ end
251
+
252
+ context "fails to transition from address" do
253
+ let(:order) do
254
+ FactoryGirl.create(:order_with_line_items).tap do |order|
255
+ order.next!
256
+ expect(order.state).to eq('address')
257
+ end
258
+ end
259
+
260
+ before do
261
+ allow(controller).to receive_messages :current_order => order
262
+ allow(controller).to receive_messages :check_authorization => true
263
+ end
264
+
265
+ context "when the order is invalid" do
266
+ before do
267
+ allow(order).to receive_messages :update_attributes => true, :next => nil
268
+ order.errors.add :base, 'Base error'
269
+ order.errors.add :adjustments, 'error'
270
+ end
271
+
272
+ it "due to the order having errors" do
273
+ spree_put :update, :state => order.state, :order => {}
274
+ expect(flash[:error]).to eq("Base error\nAdjustments error")
275
+ expect(response).to redirect_to(spree.checkout_state_path('address'))
276
+ end
277
+ end
278
+ end
279
+
280
+ context "fails to transition to complete from confirm" do
281
+ let(:order) do
282
+ FactoryGirl.create(:order_with_line_items).tap do |order|
283
+ order.next!
284
+ end
285
+ end
286
+
287
+ before do
288
+ allow(controller).to receive_messages :current_order => order
289
+ allow(controller).to receive_messages :check_authorization => true
290
+ end
291
+
292
+ context "when the country is not a shippable country" do
293
+ before do
294
+ order.ship_address.tap do |address|
295
+ # A different country which is not included in the list of shippable countries
296
+ australia = create(:country, name: "Australia")
297
+ # update_columns to get around readonly restriction when testing
298
+ address.update_columns(country_id: australia.id, state_name: 'Victoria')
299
+ end
300
+
301
+ payment_method = FactoryGirl.create(:simple_credit_card_payment_method)
302
+ payment = FactoryGirl.create(:payment, :payment_method => payment_method)
303
+ order.payments << payment
304
+ end
305
+
306
+ it "due to no available shipping rates for any of the shipments" do
307
+ expect(order.shipments.count).to eq(1)
308
+ order.shipments.first.shipping_rates.delete_all
309
+ order.update_attributes(state: 'confirm')
310
+ spree_put :update, state: order.state, :order => {}
311
+ expect(flash[:error]).to eq(Spree.t(:items_cannot_be_shipped))
312
+ expect(response).to redirect_to(spree.checkout_state_path('confirm'))
313
+ end
314
+ end
315
+ end
316
+
317
+ context "when GatewayError is raised" do
318
+ let(:order) do
319
+ FactoryGirl.create(:order_with_line_items).tap do |order|
320
+ until order.state == 'payment'
321
+ order.next!
322
+ end
323
+ # So that the confirmation step is skipped and we get straight to the action.
324
+ payment_method = FactoryGirl.create(:simple_credit_card_payment_method)
325
+ payment = FactoryGirl.create(:payment, payment_method: payment_method, amount: order.total)
326
+ order.payments << payment
327
+ order.next!
328
+ end
329
+ end
330
+
331
+ before do
332
+ allow(controller).to receive_messages :current_order => order
333
+ allow(controller).to receive_messages :check_authorization => true
334
+ end
335
+
336
+ it "fails to transition from payment to complete" do
337
+ allow_any_instance_of(Spree::Payment).to receive(:process!).and_raise(Spree::Core::GatewayError.new(Spree.t(:payment_processing_failed)))
338
+ spree_put :update, state: order.state, :order => {}
339
+ expect(flash[:error]).to eq(Spree.t(:payment_processing_failed))
340
+ end
341
+ end
342
+ end
343
+
344
+ context "When last inventory item has been purchased" do
345
+ let(:product) { mock_model(Spree::Product, :name => "Amazing Object") }
346
+ let(:variant) { mock_model(Spree::Variant) }
347
+ let(:line_item) { mock_model Spree::LineItem, :insufficient_stock? => true, :amount => 0 }
348
+ let(:order) { create(:order) }
349
+
350
+ before do
351
+ allow(order).to receive_messages(:line_items => [line_item], :state => "payment")
352
+
353
+ configure_spree_preferences do |config|
354
+ config.track_inventory_levels = true
355
+ end
356
+ end
357
+
358
+ context "and back orders are not allowed" do
359
+ before do
360
+ spree_post :update, { :state => "payment" }
361
+ end
362
+
363
+ it "should redirect to cart" do
364
+ expect(response).to redirect_to spree.cart_path
365
+ end
366
+
367
+ it "should set flash message for no inventory" do
368
+ expect(flash[:error]).to eq(Spree.t(:inventory_error_flash_for_insufficient_quantity , :names => "'#{product.name}'" ))
369
+ end
370
+ end
371
+ end
372
+
373
+ context "order doesn't have a delivery step" do
374
+ before do
375
+ allow(order).to receive_messages(:checkout_steps => ["cart", "address", "payment"])
376
+ allow(order).to receive_messages state: "address"
377
+ allow(controller).to receive_messages :check_authorization => true
378
+ end
379
+
380
+ it "doesn't set shipping address on the order" do
381
+ expect(order).to_not receive(:ship_address=)
382
+ spree_post :update, state: order.state
383
+ end
384
+
385
+ it "doesn't remove unshippable items before payment" do
386
+ expect {
387
+ spree_post :update, { :state => "payment" }
388
+ }.to_not change { order.line_items }
389
+ end
390
+ end
391
+
392
+ it "does remove unshippable items before payment" do
393
+ allow(order).to receive_messages :payment_required? => true
394
+ allow(controller).to receive_messages :check_authorization => true
395
+
396
+ expect {
397
+ spree_post :update, { :state => "payment" }
398
+ }.to change { order.line_items }
399
+ end
400
+ end