spree_frontend 3.2.9 → 3.3.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/spree/checkout_controller.rb +8 -2
  3. data/app/controllers/spree/orders_controller.rb +7 -3
  4. data/app/controllers/spree/products_controller.rb +3 -1
  5. data/app/helpers/spree/frontend_helper.rb +1 -1
  6. data/app/helpers/spree/taxons_helper.rb +2 -3
  7. data/app/views/spree/checkout/_confirm.html.erb +3 -0
  8. data/app/views/spree/checkout/_summary.html.erb +1 -1
  9. data/app/views/spree/checkout/payment/_storecredit.html.erb +1 -0
  10. data/app/views/spree/products/_cart_form.html.erb +3 -3
  11. data/app/views/spree/shared/_main_nav_bar.html.erb +1 -1
  12. data/app/views/spree/shared/_order_details.html.erb +0 -1
  13. data/app/views/spree/shared/_products.html.erb +4 -1
  14. data/spec/controllers/controller_extension_spec.rb +126 -0
  15. data/spec/controllers/controller_helpers_spec.rb +122 -0
  16. data/spec/controllers/spree/checkout_controller_spec.rb +547 -0
  17. data/spec/controllers/spree/checkout_controller_with_views_spec.rb +36 -0
  18. data/spec/controllers/spree/content_controller_spec.rb +12 -0
  19. data/spec/controllers/spree/current_order_tracking_spec.rb +44 -0
  20. data/spec/controllers/spree/home_controller_spec.rb +47 -0
  21. data/spec/controllers/spree/orders_controller_ability_spec.rb +96 -0
  22. data/spec/controllers/spree/orders_controller_spec.rb +134 -0
  23. data/spec/controllers/spree/orders_controller_transitions_spec.rb +31 -0
  24. data/spec/controllers/spree/products_controller_spec.rb +87 -0
  25. data/spec/controllers/spree/taxons_controller_spec.rb +12 -0
  26. data/spec/features/address_spec.rb +93 -0
  27. data/spec/features/automatic_promotion_adjustments_spec.rb +47 -0
  28. data/spec/features/caching/products_spec.rb +59 -0
  29. data/spec/features/caching/taxons_spec.rb +22 -0
  30. data/spec/features/cart_spec.rb +132 -0
  31. data/spec/features/checkout_spec.rb +723 -0
  32. data/spec/features/checkout_unshippable_spec.rb +34 -0
  33. data/spec/features/coupon_code_spec.rb +88 -0
  34. data/spec/features/currency_spec.rb +18 -0
  35. data/spec/features/delivery_spec.rb +64 -0
  36. data/spec/features/free_shipping_promotions_spec.rb +59 -0
  37. data/spec/features/locale_spec.rb +60 -0
  38. data/spec/features/microdata_spec.rb +0 -0
  39. data/spec/features/order_spec.rb +107 -0
  40. data/spec/features/page_promotions_spec.rb +36 -0
  41. data/spec/features/products_spec.rb +345 -0
  42. data/spec/features/taxons_spec.rb +147 -0
  43. data/spec/features/template_rendering_spec.rb +19 -0
  44. data/spec/helpers/frontend_helper_spec.rb +57 -0
  45. data/spec/helpers/taxons_helper_spec.rb +17 -0
  46. data/spec/spec_helper.rb +128 -0
  47. data/spec/support/shared_contexts/checkout_setup.rb +10 -0
  48. data/spec/support/shared_contexts/custom_products.rb +25 -0
  49. data/spec/support/shared_contexts/product_prototypes.rb +30 -0
  50. data/spec/views/spree/checkout/_summary_spec.rb +11 -0
  51. data/spree_frontend.gemspec +5 -4
  52. metadata +90 -15
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a87042361e61117e53fdf2d80e91b5ecca709132
4
- data.tar.gz: a98c7b6e0c15fc6d63e8fd2ed31b435e831952dc
3
+ metadata.gz: 895c04875fd5f5f2af102a55b9625f8a61a901c9
4
+ data.tar.gz: 8e081c1219e709db368ab3deb9f59cbb48518bcc
5
5
  SHA512:
6
- metadata.gz: 8426d0e03d77dc7f4664e2dd135a46d859faacbbd6de34772184aca714e81715cdbecbfbbfa3c00a1be776cb3c35e78a3f8de362affba8a6923b0da093e3be6d
7
- data.tar.gz: 4a04e2bc07dc6b959ecdb11e8a3845a8ecef037218293c33efaf9e02b303619aa0322fafe67c3133f9df95d2bdc9195c0c862bd01b3720ad6af70708810d6268
6
+ metadata.gz: 90a535919679f330a4b07abe0fc769a2a3eddc9daa8d91d9583597de65607dfd07323075a9ac0976e401d89c9b6740af930c31ab18b68735dc843424a33b2022
7
+ data.tar.gz: 83a4a268aa6426b1d6bba8f101a620aeab42d8aafb6b9e418b1fe7437b8baaed31c071c7acb1d551826d7c86fefd0e4dabf4e27bfce1b9a289cedd19862853b1
@@ -4,7 +4,6 @@ module Spree
4
4
  # checkout which has nothing to do with updating an order that this approach
5
5
  # is waranted.
6
6
  class CheckoutController < Spree::StoreController
7
- before_action :expires_now, only: [:edit]
8
7
  before_action :load_order_with_lock
9
8
  before_action :ensure_valid_state_lock_version, only: [:update]
10
9
  before_action :set_state_if_present
@@ -18,7 +17,7 @@ module Spree
18
17
  before_action :check_authorization
19
18
 
20
19
  before_action :setup_for_current_state
21
- before_action :add_store_credit_payments, only: [:update]
20
+ before_action :add_store_credit_payments, :remove_store_credit_payments, only: [:update]
22
21
 
23
22
  helper 'spree/orders'
24
23
 
@@ -180,6 +179,13 @@ module Spree
180
179
  end
181
180
  end
182
181
 
182
+ def remove_store_credit_payments
183
+ if params.key?(:remove_store_credit)
184
+ @order.remove_store_credit_payments
185
+ redirect_to checkout_state_path(@order.state) and return
186
+ end
187
+ end
188
+
183
189
  def rescue_from_spree_gateway_error(exception)
184
190
  flash.now[:error] = Spree.t(:spree_gateway_error_flash_for_checkout)
185
191
  @order.errors.add(:base, exception.message)
@@ -10,7 +10,7 @@ module Spree
10
10
  skip_before_action :verify_authenticity_token, only: [:populate]
11
11
 
12
12
  def show
13
- @order = Order.includes(line_items: [variant: [:option_values, :images, :product]], bill_address: :state, ship_address: :state).find_by_number!(params[:id])
13
+ @order = Order.includes(line_items: [variant: [:option_values, :images, :product]], bill_address: :state, ship_address: :state).find_by!(number: params[:id])
14
14
  end
15
15
 
16
16
  def update
@@ -49,6 +49,9 @@ module Spree
49
49
  if quantity.between?(1, 2_147_483_647)
50
50
  begin
51
51
  order.contents.add(variant, quantity, options)
52
+ order.update_line_item_prices!
53
+ order.create_tax_charge!
54
+ order.update_with_updater!
52
55
  rescue ActiveRecord::RecordInvalid => e
53
56
  error = e.record.errors.full_messages.join(", ")
54
57
  end
@@ -68,7 +71,7 @@ module Spree
68
71
 
69
72
  def populate_redirect
70
73
  flash[:error] = Spree.t(:populate_get_error)
71
- redirect_to('/cart')
74
+ redirect_to cart_path
72
75
  end
73
76
 
74
77
  def empty
@@ -88,7 +91,8 @@ module Spree
88
91
  end
89
92
 
90
93
  def check_authorization
91
- order = Spree::Order.find_by_number(params[:id]) || current_order
94
+ order = Spree::Order.find_by(number: params[:id]) if params[:id].present?
95
+ order = current_order unless order
92
96
 
93
97
  if order
94
98
  authorize! :edit, order, cookies.signed[:guest_token]
@@ -41,7 +41,9 @@ module Spree
41
41
  else
42
42
  @products = Product.active(current_currency)
43
43
  end
44
- @product = @products.includes(:variants_including_master, variant_images: :viewable).friendly.find(params[:id])
44
+
45
+ @product = @products.includes(:variants_including_master, variant_images: :viewable).
46
+ friendly.distinct(false).find(params[:id])
45
47
  end
46
48
 
47
49
  def load_taxon
@@ -23,7 +23,7 @@ module Spree
23
23
  def checkout_progress(numbers: false)
24
24
  states = @order.checkout_steps
25
25
  items = states.each_with_index.map do |state, i|
26
- text = Spree.t("order_state.#{state}").titleize
26
+ text = Spree.t("order_states.#{state}").titleize
27
27
  text.prepend("#{i.succ}. ") if numbers
28
28
 
29
29
  css_classes = []
@@ -4,13 +4,12 @@ module Spree
4
4
  # that we can use configurations as well as make it easier for end users to override this determination. One idea is
5
5
  # to show the most popular products for a particular taxon (that is an exercise left to the developer.)
6
6
  def taxon_preview(taxon, max=4)
7
- products = taxon.active_products.select("spree_products.*, spree_products_taxons.position").limit(max)
7
+ products = taxon.active_products.select("DISTINCT (spree_products.id), spree_products.*, spree_products_taxons.position").limit(max)
8
8
  if (products.size < max)
9
9
  products_arel = Spree::Product.arel_table
10
10
  taxon.descendants.each do |taxon|
11
11
  to_get = max - products.length
12
- products += taxon.active_products.select("spree_products.*, spree_products_taxons.position").
13
- where(products_arel[:id].not_in(products.map(&:id))).limit(to_get)
12
+ products += taxon.active_products.select("DISTINCT (spree_products.id), spree_products.*, spree_products_taxons.position").where(products_arel[:id].not_in(products.map(&:id))).limit(to_get)
14
13
  break if products.size >= max
15
14
  end
16
15
  end
@@ -8,6 +8,9 @@
8
8
  </div>
9
9
 
10
10
  <div class="well text-right form-buttons" data-hook="buttons">
11
+ <% if @order.using_store_credit? %>
12
+ <%= button_tag Spree.t('store_credit.remove'), name: 'remove_store_credit', class: 'continue btn' %>
13
+ <% end %>
11
14
  <%= submit_tag Spree.t(:place_order), class: 'btn btn-lg btn-success' %>
12
15
  <script>Spree.disableSaveOnClick();</script>
13
16
  </div>
@@ -64,7 +64,7 @@
64
64
 
65
65
  <% if order.using_store_credit? %>
66
66
  <tr data-hook="order_details_store_credit">
67
- <td><%= Spree.t(:store_credit_name) %>:</strong></td>
67
+ <td><strong><%= Spree.t(:store_credit_name) %>:</strong></td>
68
68
  <td><span id='summary-store-credit'><%= order.display_total_applied_store_credit.to_html %></span></td>
69
69
  </tr>
70
70
  <% end %>
@@ -5,6 +5,7 @@
5
5
  <p><%= Spree.t('store_credit.remaining_amount', amount: @order.display_store_credit_remaining_after_capture) %></p>
6
6
  <% else %>
7
7
  <p><%= Spree.t('store_credit.additional_payment_needed', amount: @order.display_order_total_after_store_credit) %></p>
8
+ <%= button_tag Spree.t('store_credit.remove'), name: 'remove_store_credit', class: 'continue btn' %>
8
9
  <% end %>
9
10
  </div>
10
11
 
@@ -7,7 +7,7 @@
7
7
  <% @product.variants_and_option_values(current_currency).each_with_index do |variant, index| %>
8
8
  <li>
9
9
  <%= radio_button_tag "variant_id", variant.id, index == 0,
10
- 'data-price' => variant.price_in(current_currency).money,
10
+ 'data-price' => variant.price_in(current_currency).money,
11
11
  'data-in-stock' => variant.can_supply?
12
12
  %>
13
13
  <%= label_tag "variant_id_#{ variant.id }" do %>
@@ -34,10 +34,10 @@
34
34
  <div id="product-price">
35
35
  <h6 class="product-section-title"><%= Spree.t(:price) %></h6>
36
36
  <div>
37
- <span class="lead price selling" itemprop="price">
37
+ <span class="lead price selling" itemprop="price" content="<%= @product.price_in(current_currency).amount.to_d %>">
38
38
  <%= display_price(@product) %>
39
39
  </span>
40
- <span itemprop="priceCurrency" content="<%= @product.currency %>"></span>
40
+ <span itemprop="priceCurrency" content="<%= current_currency %>"></span>
41
41
  </div>
42
42
 
43
43
  <% if @product.master.can_supply? %>
@@ -6,7 +6,7 @@
6
6
  <ul class="nav navbar-nav navbar-right" data-hook>
7
7
  <li id="link-to-cart" data-hook>
8
8
  <noscript>
9
- <%= link_to Spree.t(:cart), '/cart' %>
9
+ <%= link_to_cart %>
10
10
  </noscript>
11
11
  &nbsp;
12
12
  </li>
@@ -16,7 +16,6 @@
16
16
  <div class="delivery">
17
17
  <% order.shipments.each do |shipment| %>
18
18
  <div>
19
- <i class='fa fa-truck'></i>
20
19
  <%= Spree.t(:shipment_details, stock_location: shipment.stock_location.name, shipping_method: shipment.selected_shipping_rate.name) %>
21
20
  </div>
22
21
  <% end %>
@@ -32,7 +32,10 @@
32
32
  </div>
33
33
  <div class="panel-footer text-center">
34
34
  <span itemprop="offers" itemscope itemtype="https://schema.org/Offer">
35
- <span class="price selling lead" itemprop="price"><%= display_price(product) %></span>
35
+ <span class="price selling lead" itemprop="price" content="<%= product.price_in(current_currency).amount.to_d %>">
36
+ <%= display_price(product) %>
37
+ </span>
38
+ <span itemprop="priceCurrency" content="<%= current_currency %>"></span>
36
39
  </span>
37
40
  </div>
38
41
  <% 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 plain: "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 plain: '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(plain: 'success!!!') } } })
63
+ respond_override(index: { html: { failure: lambda { render(plain: '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(plain: '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(plain: 'success!!!') } } })
97
+ respond_override(create: { html: { failure: lambda { render(plain: '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(plain: '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,122 @@
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