spree_frontend 3.1.5 → 3.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/spree/products_controller.rb +1 -1
  3. data/app/views/spree/shared/_taxonomies.html.erb +4 -2
  4. data/spree_frontend.gemspec +1 -2
  5. metadata +8 -84
  6. data/spec/controllers/controller_extension_spec.rb +0 -126
  7. data/spec/controllers/controller_helpers_spec.rb +0 -122
  8. data/spec/controllers/spree/checkout_controller_spec.rb +0 -462
  9. data/spec/controllers/spree/checkout_controller_with_views_spec.rb +0 -36
  10. data/spec/controllers/spree/content_controller_spec.rb +0 -12
  11. data/spec/controllers/spree/current_order_tracking_spec.rb +0 -44
  12. data/spec/controllers/spree/home_controller_spec.rb +0 -47
  13. data/spec/controllers/spree/orders_controller_ability_spec.rb +0 -96
  14. data/spec/controllers/spree/orders_controller_spec.rb +0 -134
  15. data/spec/controllers/spree/orders_controller_transitions_spec.rb +0 -31
  16. data/spec/controllers/spree/products_controller_spec.rb +0 -87
  17. data/spec/controllers/spree/taxons_controller_spec.rb +0 -12
  18. data/spec/features/address_spec.rb +0 -93
  19. data/spec/features/automatic_promotion_adjustments_spec.rb +0 -47
  20. data/spec/features/caching/products_spec.rb +0 -59
  21. data/spec/features/caching/taxons_spec.rb +0 -22
  22. data/spec/features/cart_spec.rb +0 -90
  23. data/spec/features/checkout_spec.rb +0 -572
  24. data/spec/features/checkout_unshippable_spec.rb +0 -34
  25. data/spec/features/coupon_code_spec.rb +0 -88
  26. data/spec/features/currency_spec.rb +0 -18
  27. data/spec/features/free_shipping_promotions_spec.rb +0 -59
  28. data/spec/features/locale_spec.rb +0 -60
  29. data/spec/features/microdata_spec.rb +0 -0
  30. data/spec/features/order_spec.rb +0 -74
  31. data/spec/features/page_promotions_spec.rb +0 -36
  32. data/spec/features/products_spec.rb +0 -334
  33. data/spec/features/taxons_spec.rb +0 -147
  34. data/spec/features/template_rendering_spec.rb +0 -19
  35. data/spec/fixtures/thinking-cat.jpg +0 -0
  36. data/spec/helpers/frontend_helper_spec.rb +0 -57
  37. data/spec/helpers/order_helper_spec.rb +0 -12
  38. data/spec/helpers/taxons_helper_spec.rb +0 -17
  39. data/spec/spec_helper.rb +0 -126
  40. data/spec/support/shared_contexts/checkout_setup.rb +0 -10
  41. data/spec/support/shared_contexts/custom_products.rb +0 -25
  42. data/spec/support/shared_contexts/product_prototypes.rb +0 -30
  43. data/spec/views/spree/checkout/_summary_spec.rb +0 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2a1c4fe0ac3def093009ff735f08243d103d5130
4
- data.tar.gz: ad595ec587238ae70a496bca8a2af8a3ae567f2c
3
+ metadata.gz: a531bf11aae89fc8b3bd960b3eef3d3481298b95
4
+ data.tar.gz: 4639ab270e9a2d25e55ba1e862e1539a8eb0fa84
5
5
  SHA512:
6
- metadata.gz: 1077db0afa86a29823870aa2e54c98a58ae43fdf8894052fc2eb67aef2200fb0b26c72374401998010c03810f199b4b04c9cf9f9bc7531412f9bb3033f068aeb
7
- data.tar.gz: 46279944e9e5ade75562ea4e5422bdaca9746adf40c4ef190e1ee3e7a9f0a291ee8e6b39b13de899b3aceb9fc7d1dd1969c9bbc949872d803a6152414b1dfb21
6
+ metadata.gz: eb72a87f0b00e84a3c857d15511cd951aa32ae050c096f57b69f4a7ce0c83f5e8e929ff44c46cc5513702987ffd4bc9b5b37ec7ac7a61ea86e90849ee17a4f99
7
+ data.tar.gz: 6946c7092038de4f5f32972663cc5ab1fbdc98220b2b2c447070ea0d7cf69df0a8a56418b1e67ec99bdf59cd1d7bb66ad0cca11e63cf959676c293faa3b82267
@@ -41,7 +41,7 @@ module Spree
41
41
  else
42
42
  @products = Product.active(current_currency)
43
43
  end
44
- @product = @products.includes(:variants_including_master).friendly.find(params[:id])
44
+ @product = @products.includes(:variants_including_master, variant_images: :viewable).friendly.find(params[:id])
45
45
  end
46
46
 
47
47
  def load_taxon
@@ -3,8 +3,10 @@
3
3
  <nav id="taxonomies" class="sidebar-item" data-hook>
4
4
  <% @taxonomies.each do |taxonomy| %>
5
5
  <% cache [I18n.locale, taxonomy, max_level, @taxon] do %>
6
- <h4 class='taxonomy-root'><%= Spree.t(:shop_by_taxonomy, :taxonomy => taxonomy.name) %></h4>
7
- <%= taxons_tree(taxonomy.root, @taxon, max_level) %>
6
+ <% if taxonomy.root.children.any? %>
7
+ <h4 class='taxonomy-root'><%= Spree.t(:shop_by_taxonomy, taxonomy: taxonomy.name) %></h4>
8
+ <%= taxons_tree(taxonomy.root, @taxon, max_level) %>
9
+ <% end %>
8
10
  <% end %>
9
11
  <% end %>
10
12
  </nav>
@@ -13,8 +13,7 @@ Gem::Specification.new do |s|
13
13
  s.homepage = 'https://spreecommerce.com'
14
14
  s.license = 'BSD-3'
15
15
 
16
- s.files = `git ls-files`.split("\n")
17
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.files = `git ls-files`.split("\n").reject { |f| f.match(/^spec/) }
18
17
  s.require_path = 'lib'
19
18
  s.requirements << 'none'
20
19
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_frontend
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.5
4
+ version: 3.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Schofield
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-04 00:00:00.000000000 Z
11
+ date: 2017-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: spree_api
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 3.1.5
19
+ version: 3.1.6
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 3.1.5
26
+ version: 3.1.6
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: spree_core
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 3.1.5
33
+ version: 3.1.6
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 3.1.5
40
+ version: 3.1.6
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bootstrap-sass
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -476,44 +476,6 @@ files:
476
476
  - lib/tasks/rake_util.rb
477
477
  - lib/tasks/taxon.rake
478
478
  - script/rails
479
- - spec/controllers/controller_extension_spec.rb
480
- - spec/controllers/controller_helpers_spec.rb
481
- - spec/controllers/spree/checkout_controller_spec.rb
482
- - spec/controllers/spree/checkout_controller_with_views_spec.rb
483
- - spec/controllers/spree/content_controller_spec.rb
484
- - spec/controllers/spree/current_order_tracking_spec.rb
485
- - spec/controllers/spree/home_controller_spec.rb
486
- - spec/controllers/spree/orders_controller_ability_spec.rb
487
- - spec/controllers/spree/orders_controller_spec.rb
488
- - spec/controllers/spree/orders_controller_transitions_spec.rb
489
- - spec/controllers/spree/products_controller_spec.rb
490
- - spec/controllers/spree/taxons_controller_spec.rb
491
- - spec/features/address_spec.rb
492
- - spec/features/automatic_promotion_adjustments_spec.rb
493
- - spec/features/caching/products_spec.rb
494
- - spec/features/caching/taxons_spec.rb
495
- - spec/features/cart_spec.rb
496
- - spec/features/checkout_spec.rb
497
- - spec/features/checkout_unshippable_spec.rb
498
- - spec/features/coupon_code_spec.rb
499
- - spec/features/currency_spec.rb
500
- - spec/features/free_shipping_promotions_spec.rb
501
- - spec/features/locale_spec.rb
502
- - spec/features/microdata_spec.rb
503
- - spec/features/order_spec.rb
504
- - spec/features/page_promotions_spec.rb
505
- - spec/features/products_spec.rb
506
- - spec/features/taxons_spec.rb
507
- - spec/features/template_rendering_spec.rb
508
- - spec/fixtures/thinking-cat.jpg
509
- - spec/helpers/frontend_helper_spec.rb
510
- - spec/helpers/order_helper_spec.rb
511
- - spec/helpers/taxons_helper_spec.rb
512
- - spec/spec_helper.rb
513
- - spec/support/shared_contexts/checkout_setup.rb
514
- - spec/support/shared_contexts/custom_products.rb
515
- - spec/support/shared_contexts/product_prototypes.rb
516
- - spec/views/spree/checkout/_summary_spec.rb
517
479
  - spree_frontend.gemspec
518
480
  - vendor/assets/javascripts/jquery.validate/additional-methods.min.js
519
481
  - vendor/assets/javascripts/jquery.validate/jquery.validate.min.js
@@ -586,46 +548,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
586
548
  requirements:
587
549
  - none
588
550
  rubyforge_project:
589
- rubygems_version: 2.6.10
551
+ rubygems_version: 2.6.11
590
552
  signing_key:
591
553
  specification_version: 4
592
554
  summary: Frontend e-commerce functionality for the Spree project.
593
- test_files:
594
- - spec/controllers/controller_extension_spec.rb
595
- - spec/controllers/controller_helpers_spec.rb
596
- - spec/controllers/spree/checkout_controller_spec.rb
597
- - spec/controllers/spree/checkout_controller_with_views_spec.rb
598
- - spec/controllers/spree/content_controller_spec.rb
599
- - spec/controllers/spree/current_order_tracking_spec.rb
600
- - spec/controllers/spree/home_controller_spec.rb
601
- - spec/controllers/spree/orders_controller_ability_spec.rb
602
- - spec/controllers/spree/orders_controller_spec.rb
603
- - spec/controllers/spree/orders_controller_transitions_spec.rb
604
- - spec/controllers/spree/products_controller_spec.rb
605
- - spec/controllers/spree/taxons_controller_spec.rb
606
- - spec/features/address_spec.rb
607
- - spec/features/automatic_promotion_adjustments_spec.rb
608
- - spec/features/caching/products_spec.rb
609
- - spec/features/caching/taxons_spec.rb
610
- - spec/features/cart_spec.rb
611
- - spec/features/checkout_spec.rb
612
- - spec/features/checkout_unshippable_spec.rb
613
- - spec/features/coupon_code_spec.rb
614
- - spec/features/currency_spec.rb
615
- - spec/features/free_shipping_promotions_spec.rb
616
- - spec/features/locale_spec.rb
617
- - spec/features/microdata_spec.rb
618
- - spec/features/order_spec.rb
619
- - spec/features/page_promotions_spec.rb
620
- - spec/features/products_spec.rb
621
- - spec/features/taxons_spec.rb
622
- - spec/features/template_rendering_spec.rb
623
- - spec/fixtures/thinking-cat.jpg
624
- - spec/helpers/frontend_helper_spec.rb
625
- - spec/helpers/order_helper_spec.rb
626
- - spec/helpers/taxons_helper_spec.rb
627
- - spec/spec_helper.rb
628
- - spec/support/shared_contexts/checkout_setup.rb
629
- - spec/support/shared_contexts/custom_products.rb
630
- - spec/support/shared_contexts/product_prototypes.rb
631
- - spec/views/spree/checkout/_summary_spec.rb
555
+ test_files: []
@@ -1,126 +0,0 @@
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
@@ -1,122 +0,0 @@
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
- let!(:available_locales) { [:en, :de] }
9
- let!(:available_locale) { :de }
10
- let!(:unavailable_locale) { :ru }
11
-
12
- before do
13
- I18n.enforce_available_locales = false
14
- expect(I18n).to receive(:available_locales).and_return(available_locales)
15
- end
16
-
17
- after do
18
- Spree::Frontend::Config[:locale] = :en
19
- Rails.application.config.i18n.default_locale = :en
20
- I18n.locale = :en
21
- I18n.enforce_available_locales = true
22
- end
23
-
24
- # Regression test for #1184
25
- context 'when session locale not set' do
26
- before(:each) do
27
- session[:locale] = nil
28
- end
29
-
30
- context 'when Spree::Frontend::Config[:locale] not present' do
31
- before(:each) do
32
- Spree::Frontend::Config[:locale] = nil
33
- end
34
-
35
- context 'when rails application default locale not set' do
36
- before(:each) do
37
- Rails.application.config.i18n.default_locale = nil
38
- end
39
-
40
- it "sets the I18n default locale" do
41
- spree_get :index
42
- expect(I18n.locale).to eq(I18n.default_locale)
43
- end
44
- end
45
-
46
- context 'when rails application default locale is set' do
47
- context 'and not in available_locales' do
48
- before(:each) do
49
- Rails.application.config.i18n.default_locale = unavailable_locale
50
- end
51
-
52
- it "sets the I18n default locale" do
53
- spree_get :index
54
- expect(I18n.locale).to eq(I18n.default_locale)
55
- end
56
- end
57
-
58
- context 'and in available_locales' do
59
- before(:each) do
60
- Rails.application.config.i18n.default_locale = available_locale
61
- end
62
-
63
- it "sets the rails app locale" do
64
- expect(I18n.locale).to eq(:en)
65
- spree_get :index
66
- expect(I18n.locale).to eq(available_locale)
67
- end
68
- end
69
- end
70
- end
71
-
72
- context 'when Spree::Frontend::Config[:locale] is present' do
73
- context 'and not in available_locales' do
74
- before(:each) do
75
- Spree::Frontend::Config[:locale] = unavailable_locale
76
- end
77
-
78
- it "sets the I18n default locale" do
79
- spree_get :index
80
- expect(I18n.locale).to eq(I18n.default_locale)
81
- end
82
- end
83
-
84
- context 'and not in available_locales' do
85
- before(:each) do
86
- Spree::Frontend::Config[:locale] = available_locale
87
- end
88
-
89
- it "sets the default locale based on Spree::Frontend::Config[:locale]" do
90
- expect(I18n.locale).to eq(:en)
91
- spree_get :index
92
- expect(I18n.locale).to eq(available_locale)
93
- end
94
- end
95
- end
96
- end
97
-
98
- context 'when session locale is set' do
99
- context 'and not in available_locales' do
100
- before(:each) do
101
- session[:locale] = unavailable_locale
102
- end
103
-
104
- it "sets the I18n default locale" do
105
- spree_get :index
106
- expect(I18n.locale).to eq(I18n.default_locale)
107
- end
108
- end
109
-
110
- context 'and in available_locales' do
111
- before(:each) do
112
- session[:locale] = available_locale
113
- end
114
-
115
- it "sets the session locale" do
116
- expect(I18n.locale).to eq(:en)
117
- spree_get :index
118
- expect(I18n.locale).to eq(available_locale)
119
- end
120
- end
121
- end
122
- end
@@ -1,462 +0,0 @@
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
- end
82
-
83
- before do
84
- # Must have *a* shipping method and a payment method so updating from address works
85
- allow(order).to receive(:available_shipping_methods).
86
- and_return [stub_model(Spree::ShippingMethod)]
87
- allow(order).to receive(:available_payment_methods).
88
- and_return [stub_model(Spree::PaymentMethod)]
89
- allow(order).to receive(:ensure_available_shipping_rates).
90
- and_return true
91
- order.line_items << FactoryGirl.create(:line_item)
92
- end
93
-
94
- context "with the order in the cart state" do
95
- before do
96
- order.update_column(:state, "cart")
97
- allow(order).to receive_messages user: user
98
- end
99
-
100
- it "should assign order" do
101
- spree_post :update, state: "address"
102
- expect(assigns[:order]).not_to be_nil
103
- end
104
-
105
- it "should advance the state" do
106
- spree_post_address
107
- expect(order.reload.state).to eq("delivery")
108
- end
109
-
110
- it "should redirect the next state" do
111
- spree_post_address
112
- expect(response).to redirect_to spree.checkout_state_path("delivery")
113
- end
114
-
115
- context "current_user respond to save address method" do
116
- it "calls persist order address on user" do
117
- expect(user).to receive(:persist_order_address)
118
- spree_post :update,
119
- state: "address",
120
- order: {
121
- bill_address_attributes: address_params,
122
- use_billing: true
123
- },
124
- save_user_address: "1"
125
- end
126
- end
127
-
128
- context "current_user doesnt respond to persist_order_address" do
129
- it "doesnt raise any error" do
130
- expect do
131
- spree_post :update,
132
- state: "address",
133
- order: {
134
- bill_address_attributes: address_params,
135
- use_billing: true
136
- },
137
- save_user_address: "1"
138
- end.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
- let(:bill_address_params) do
151
- order.bill_address.attributes.except("created_at", "updated_at")
152
- end
153
- let(:ship_address_params) do
154
- order.ship_address.attributes.except("created_at", "updated_at")
155
- end
156
- let(:update_params) do
157
- {
158
- state: "address",
159
- order: {
160
- bill_address_attributes: bill_address_params,
161
- ship_address_attributes: ship_address_params,
162
- use_billing: false
163
- }
164
- }
165
- end
166
-
167
- before do
168
- @expected_bill_address_id = order.bill_address.id
169
- @expected_ship_address_id = order.ship_address.id
170
-
171
- spree_post :update, update_params
172
- order.reload
173
- end
174
-
175
- it "updates the same billing and shipping address" do
176
- expect(order.bill_address.id).to eq(@expected_bill_address_id)
177
- expect(order.ship_address.id).to eq(@expected_ship_address_id)
178
- end
179
- end
180
- end
181
-
182
- context "when in the confirm state" do
183
- before do
184
- allow(order).to receive_messages confirmation_required?: true
185
- order.update_column(:state, "confirm")
186
- allow(order).to receive_messages user: user
187
- # An order requires a payment to reach the complete state
188
- # This is because payment_required? is true on the order
189
- create(:payment, amount: order.total, order: order)
190
- order.payments.reload
191
- end
192
-
193
- # This inadvertently is a regression test for #2694
194
- it "should redirect to the order view" do
195
- spree_post :update, state: "confirm"
196
- expect(response).to redirect_to spree.order_path(order)
197
- end
198
-
199
- it "should populate the flash message" do
200
- spree_post :update, state: "confirm"
201
- expect(flash.notice).to eq(Spree.t(:order_processed_successfully))
202
- end
203
-
204
- it "should remove completed order from current_order" do
205
- spree_post :update, { state: "confirm" }, order_id: "foofah"
206
- expect(assigns(:current_order)).to be_nil
207
- expect(assigns(:order)).to eql controller.current_order
208
- end
209
- end
210
-
211
- # Regression test for #4190
212
- context "state_lock_version" do
213
- let(:post_params) do
214
- {
215
- state: "address",
216
- order: {
217
- bill_address_attributes: order.bill_address.attributes.except("created_at", "updated_at"),
218
- state_lock_version: 0,
219
- use_billing: true
220
- }
221
- }
222
- end
223
-
224
- context "correct" do
225
- it "should properly update and increment version" do
226
- spree_post :update, post_params
227
- expect(order.state_lock_version).to eq 1
228
- end
229
- end
230
-
231
- context "incorrect" do
232
- before do
233
- order.update_columns(state_lock_version: 1, state: "address")
234
- end
235
-
236
- it "order should receieve ensure_valid_order_version callback" do
237
- expect_any_instance_of(described_class).to receive(:ensure_valid_state_lock_version)
238
- spree_post :update, post_params
239
- end
240
-
241
- it "order should receieve with_lock message" do
242
- expect(order).to receive(:with_lock)
243
- spree_post :update, post_params
244
- end
245
-
246
- it "redirects back to current state" do
247
- spree_post :update, post_params
248
- expect(response).to redirect_to spree.checkout_state_path('address')
249
- expect(flash[:error]).to eq "The order has already been updated."
250
- end
251
- end
252
- end
253
- end
254
-
255
- context "save unsuccessful" do
256
- before do
257
- allow(order).to receive_messages user: user
258
- allow(order).to receive_messages update_attributes: false
259
- end
260
-
261
- it "should not assign order" do
262
- spree_post :update, state: "address"
263
- expect(assigns[:order]).not_to be_nil
264
- end
265
-
266
- it "should not change the order state" do
267
- spree_post :update, state: 'address'
268
- end
269
-
270
- it "should render the edit template" do
271
- spree_post :update, state: 'address'
272
- expect(response).to render_template :edit
273
- end
274
-
275
- it "should render order in payment state when payment fails" do
276
- order.update_column(:state, 'confirm')
277
- allow(controller).to receive(:insufficient_payment?).and_return(true)
278
- spree_post :update, state: 'confirm'
279
- expect(order.state).to eq('payment')
280
- end
281
- end
282
-
283
- context "when current_order is nil" do
284
- before { allow(controller).to receive_messages current_order: nil }
285
-
286
- it "should not change the state if order is completed" do
287
- expect(order).not_to receive(:update_attribute)
288
- spree_post :update, state: "confirm"
289
- end
290
-
291
- it "should redirect to the cart_path" do
292
- spree_post :update, state: "confirm"
293
- expect(response).to redirect_to spree.cart_path
294
- end
295
- end
296
-
297
- context "Spree::Core::GatewayError" do
298
- before do
299
- allow(order).to receive_messages user: user
300
- allow(order).to receive(:update_attributes).and_raise(Spree::Core::GatewayError.new("Invalid something or other."))
301
- spree_post :update, state: "address"
302
- end
303
-
304
- it "should render the edit template and display exception message" do
305
- expect(response).to render_template :edit
306
- expect(flash.now[:error]).to eq(Spree.t(:spree_gateway_error_flash_for_checkout))
307
- expect(assigns(:order).errors[:base]).to include("Invalid something or other.")
308
- end
309
- end
310
-
311
- context "fails to transition from address" do
312
- let(:order) do
313
- FactoryGirl.create(:order_with_line_items).tap do |order|
314
- order.next!
315
- expect(order.state).to eq('address')
316
- end
317
- end
318
-
319
- before do
320
- allow(controller).to receive_messages current_order: order
321
- allow(controller).to receive_messages check_authorization: true
322
- end
323
-
324
- context "when the country is not a shippable country" do
325
- before do
326
- order.ship_address.tap do |address|
327
- # A different country which is not included in the list of shippable countries
328
- address.country = FactoryGirl.create(:country, name: "Australia")
329
- address.state_name = 'Victoria'
330
- address.save
331
- end
332
- end
333
-
334
- it "due to no available shipping rates for any of the shipments" do
335
- expect(order.shipments.count).to eq(1)
336
- order.shipments.first.shipping_rates.delete_all
337
-
338
- spree_put :update, state: order.state, order: {}
339
- expect(flash[:error]).to eq(Spree.t(:items_cannot_be_shipped))
340
- expect(response).to redirect_to(spree.checkout_state_path('address'))
341
- end
342
- end
343
-
344
- context "when the order is invalid" do
345
- before do
346
- allow(order).to receive_messages(update_from_params: true, next: nil)
347
- order.errors.add(:base, 'Base error')
348
- order.errors.add(:adjustments, 'error')
349
- end
350
-
351
- it "due to the order having errors" do
352
- spree_put :update, state: order.state, order: {}
353
- expect(flash[:error]).to eql("Base error\nAdjustments error")
354
- expect(response).to redirect_to(spree.checkout_state_path('address'))
355
- end
356
- end
357
- end
358
-
359
- context "fails to transition from payment to complete" do
360
- let(:order) do
361
- FactoryGirl.create(:order_with_line_items).tap do |order|
362
- until order.state == 'payment'
363
- order.next!
364
- end
365
- # So that the confirmation step is skipped and we get straight to the action.
366
- payment_method = FactoryGirl.create(:simple_credit_card_payment_method)
367
- payment = FactoryGirl.create(:payment, payment_method: payment_method)
368
- order.payments << payment
369
- end
370
- end
371
-
372
- before do
373
- allow(controller).to receive_messages current_order: order
374
- allow(controller).to receive_messages check_authorization: true
375
- end
376
-
377
- it "when GatewayError is raised" do
378
- allow_any_instance_of(Spree::Payment).to receive(:process!).and_raise(Spree::Core::GatewayError.new(Spree.t(:payment_processing_failed)))
379
- spree_put :update, state: order.state, order: {}
380
- expect(flash[:error]).to eq(Spree.t(:payment_processing_failed))
381
- end
382
- end
383
- end
384
-
385
- context "When last inventory item has been purchased" do
386
- let(:product) { mock_model(Spree::Product, name: "Amazing Object") }
387
- let(:variant) { mock_model(Spree::Variant) }
388
- let(:line_item) { mock_model Spree::LineItem, insufficient_stock?: true, amount: 0 }
389
- let(:order) { create(:order) }
390
-
391
- before do
392
- allow(order).to receive_messages(line_items: [line_item], state: "payment")
393
-
394
- configure_spree_preferences do |config|
395
- config.track_inventory_levels = true
396
- end
397
- end
398
-
399
- context "and back orders are not allowed" do
400
- before do
401
- spree_post :update, state: "payment"
402
- end
403
-
404
- it "should redirect to cart" do
405
- expect(response).to redirect_to spree.cart_path
406
- end
407
-
408
- it "should set flash message for no inventory" do
409
- expect(flash[:error]).to eq(
410
- Spree.t(:inventory_error_flash_for_insufficient_quantity, names: "'#{product.name}'"))
411
- end
412
- end
413
- end
414
-
415
- context "order doesn't have a delivery step" do
416
- before do
417
- allow(order).to receive_messages(checkout_steps: ["cart", "address", "payment"])
418
- allow(order).to receive_messages state: "address"
419
- allow(controller).to receive_messages check_authorization: true
420
- end
421
-
422
- it "doesn't set shipping address on the order" do
423
- expect(order).to_not receive(:ship_address=)
424
- spree_post :update, state: order.state
425
- end
426
-
427
- it "doesn't remove unshippable items before payment" do
428
- expect { spree_post :update, state: "payment" }.
429
- to_not change { order.line_items }
430
- end
431
- end
432
-
433
- it "does remove unshippable items before payment" do
434
- allow(order).to receive_messages payment_required?: true
435
- allow(controller).to receive_messages check_authorization: true
436
-
437
- expect { spree_post :update, state: "payment" }.
438
- to change { order.reload.line_items.length }
439
- end
440
-
441
- context 'in the payment step' do
442
- let(:order) { OrderWalkthrough.up_to(:payment) }
443
- let(:payment_method_id) { Spree::PaymentMethod.first.id }
444
-
445
- before do
446
- expect(order.state).to eq 'payment'
447
- allow(order).to receive_messages user: user
448
- allow(order).to receive_messages confirmation_required?: true
449
- end
450
-
451
- it 'does not advance the order extra even when called twice' do
452
- spree_put :update, state: 'payment',
453
- order: { payments_attributes: [{ payment_method_id: payment_method_id }] }
454
- order.reload
455
- expect(order.state).to eq 'confirm'
456
- spree_put :update, state: 'payment',
457
- order: { payments_attributes: [{ payment_method_id: payment_method_id }] }
458
- order.reload
459
- expect(order.state).to eq 'confirm'
460
- end
461
- end
462
- end