spree_frontend 3.0.10 → 3.1.0.rc1

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 (43) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/app/assets/javascripts/spree/frontend.js +3 -0
  4. data/app/assets/javascripts/spree/frontend/checkout.js.coffee +12 -7
  5. data/app/assets/javascripts/spree/frontend/checkout/payment.js.coffee +5 -3
  6. data/app/assets/javascripts/spree/frontend/product.js.coffee +11 -4
  7. data/app/assets/stylesheets/spree/frontend.css +0 -1
  8. data/app/assets/stylesheets/spree/frontend/frontend_bootstrap.css.scss +2 -2
  9. data/app/controllers/spree/checkout_controller.rb +17 -1
  10. data/app/controllers/spree/home_controller.rb +1 -1
  11. data/app/controllers/spree/orders_controller.rb +4 -2
  12. data/app/controllers/spree/products_controller.rb +7 -4
  13. data/app/controllers/spree/store_controller.rb +23 -18
  14. data/app/controllers/spree/taxons_controller.rb +1 -6
  15. data/app/helpers/spree/frontend_helper.rb +3 -2
  16. data/app/helpers/spree/taxons_helper.rb +3 -2
  17. data/app/views/spree/address/_form.html.erb +28 -15
  18. data/app/views/spree/checkout/_payment.html.erb +3 -2
  19. data/app/views/spree/checkout/_summary.html.erb +7 -0
  20. data/app/views/spree/checkout/edit.html.erb +3 -1
  21. data/app/views/spree/checkout/payment/_gateway.html.erb +13 -5
  22. data/app/views/spree/checkout/payment/_storecredit.html.erb +16 -0
  23. data/app/views/spree/payments/_payment.html.erb +2 -0
  24. data/app/views/spree/products/_cart_form.html.erb +24 -15
  25. data/app/views/spree/products/_taxons.html.erb +7 -11
  26. data/app/views/spree/products/show.html.erb +8 -6
  27. data/app/views/spree/shared/_filters.html.erb +1 -1
  28. data/app/views/spree/shared/_header.html.erb +1 -1
  29. data/app/views/spree/shared/_nav_bar.html.erb +1 -1
  30. data/app/views/spree/shared/_order_details.html.erb +6 -6
  31. data/app/views/spree/shared/_products.html.erb +12 -14
  32. data/app/views/spree/shared/forbidden.html.erb +0 -0
  33. data/config/routes.rb +15 -19
  34. data/spec/controllers/controller_helpers_spec.rb +102 -6
  35. data/spec/controllers/spree/checkout_controller_spec.rb +7 -0
  36. data/spec/features/checkout_spec.rb +223 -165
  37. data/spec/features/checkout_unshippable_spec.rb +1 -1
  38. data/spec/features/microdata_spec.rb +0 -0
  39. data/spec/features/products_spec.rb +79 -7
  40. data/spec/helpers/frontend_helper_spec.rb +16 -0
  41. data/spec/spec_helper.rb +1 -0
  42. metadata +13 -10
  43. data/CHANGELOG.md +0 -1
@@ -61,5 +61,12 @@
61
61
  <td><strong><%= Spree.t(:order_total) %>:</strong></td>
62
62
  <td><strong><span id='summary-order-total' class="lead text-primary"><%= order.display_total.to_html %></span></strong></td>
63
63
  </tr>
64
+
65
+ <% if order.using_store_credit? %>
66
+ <tr data-hook="order_details_store_credit">
67
+ <td><%= Spree.t(:store_credit_name) %>:</strong></td>
68
+ <td><span id='summary-store-credit'><%= order.display_total_applied_store_credit.to_html %></span></td>
69
+ </tr>
70
+ <% end %>
64
71
  </tbody>
65
72
  </table>
@@ -9,7 +9,9 @@
9
9
  <div class="col-sm-3">
10
10
  <h1 data-hook="checkout_title"><%= Spree.t(:checkout) %></h1>
11
11
  </div>
12
- <div class="col-sm-9" data-hook="checkout_progress"><%= checkout_progress %></div>
12
+ <div class="col-sm-9" data-hook="checkout_progress">
13
+ <%= checkout_progress %>
14
+ </div>
13
15
  </div>
14
16
 
15
17
  <div class="row" data-hook="checkout_content">
@@ -3,12 +3,16 @@
3
3
  <% param_prefix = "payment_source[#{payment_method.id}]" %>
4
4
 
5
5
  <p class="field">
6
- <%= label_tag "name_on_card_#{payment_method.id}", Spree.t(:name_on_card) %><span class="required">*</span><br />
7
- <%= text_field_tag "#{param_prefix}[name]", "#{@order.billing_firstname} #{@order.billing_lastname}", { id: "name_on_card_#{payment_method.id}", :class => 'form-control required'} %>
6
+ <%= label_tag "name_on_card_#{payment_method.id}" do %>
7
+ <%= Spree.t(:name_on_card) %><abbr class="required" title="required">*</abbr>
8
+ <% end %>
9
+ <%= text_field_tag "#{param_prefix}[name]", "#{@order.bill_address_firstname} #{@order.bill_address_lastname}", { id: "name_on_card_#{payment_method.id}", :class => 'form-control required'} %>
8
10
  </p>
9
11
 
10
12
  <p class="field" data-hook="card_number">
11
- <%= label_tag "card_number", Spree.t(:card_number) %><span class="required">*</span><br />
13
+ <%= label_tag "card_number" do %>
14
+ <%= Spree.t(:card_number) %><abbr class="required" title="required">*</abbr>
15
+ <% end %>
12
16
  <% options_hash = Rails.env.production? ? {:autocomplete => 'off'} : {} %>
13
17
  <%= text_field_tag "#{param_prefix}[number]", '', options_hash.merge(:id => 'card_number', :class => 'form-control required cardNumber', :size => 19, :maxlength => 19, :autocomplete => "off") %>
14
18
  &nbsp;
@@ -20,11 +24,15 @@
20
24
  </p>
21
25
  <div class="row">
22
26
  <div class="col-md-8 field" data-hook="card_expiration">
23
- <%= label_tag "card_expiry", Spree.t(:expiration) %><span class="required">*</span><br />
27
+ <%= label_tag "card_expiry" do %>
28
+ <%= Spree.t(:expiration) %><abbr class="required" title="required">*</abbr>
29
+ <% end %>
24
30
  <%= text_field_tag "#{param_prefix}[expiry]", '', :id => 'card_expiry', :class => "form-control required cardExpiry", :placeholder => "MM / YY" %>
25
31
  </div>
26
32
  <div class="col-md-4 field" data-hook="card_code">
27
- <%= label_tag "card_code", Spree.t(:card_code) %><span class="required">*</span><br />
33
+ <%= label_tag "card_code" do %>
34
+ <%= Spree.t(:card_code) %><abbr class="required" title="required">*</abbr>
35
+ <% end %>
28
36
  <%= text_field_tag "#{param_prefix}[verification_value]", '', options_hash.merge(:id => 'card_code', :class => 'form-control required cardCode', :size => 5) %>
29
37
  <%= link_to "(#{Spree.t(:what_is_this)})", spree.content_path('cvv'), :target => '_blank', "data-hook" => "cvv_link", :id => "cvv_link" %>
30
38
  </div>
@@ -0,0 +1,16 @@
1
+ <% if @order.using_store_credit? %>
2
+ <div class="alert alert-success text-center" data-hook="checkout_payment_store_credit_success">
3
+ <h3><%= Spree.t('store_credit.applicable_amount', amount: Spree::Money.new(@order.total_applicable_store_credit, { currency: @order.currency })) %></h3>
4
+ <% if @order.covered_by_store_credit? %>
5
+ <p><%= Spree.t('store_credit.remaining_amount', amount: @order.display_store_credit_remaining_after_capture) %></p>
6
+ <% else %>
7
+ <p><%= Spree.t('store_credit.additional_payment_needed', amount: @order.display_order_total_after_store_credit) %></p>
8
+ <% end %>
9
+ </div>
10
+
11
+ <% elsif @order.could_use_store_credit? %>
12
+ <div class="alert alert-info text-center" data-hook="checkout_payment_store_credit_available">
13
+ <h2><%= Spree.t('store_credit.available_amount', amount: @order.display_total_available_store_credit) %></h2>
14
+ <%= button_tag Spree.t('store_credit.apply'), name: 'apply_store_credit', class: 'continue btn btn-lg btn-primary' %>
15
+ </div>
16
+ <% end %>
@@ -14,3 +14,5 @@
14
14
  <% else %>
15
15
  <%= content_tag(:span, payment.payment_method.name) %>
16
16
  <% end %>
17
+
18
+ <span class="payment-amount">(<%= payment.display_amount %>)</span>
@@ -1,4 +1,4 @@
1
- <%= form_for :order, :url => populate_orders_path do |f| %>
1
+ <%= form_for :order, url: populate_orders_path do |f| %>
2
2
  <div class="row" id="inside-product-cart-form" data-hook="inside_product_cart_form" itemprop="offers" itemscope itemtype="https://schema.org/Offer">
3
3
  <% if @product.variants_and_option_values(current_currency).any? %>
4
4
  <div id="product-variants" class="col-md-6">
@@ -6,7 +6,10 @@
6
6
  <ul class="list-group">
7
7
  <% @product.variants_and_option_values(current_currency).each_with_index do |variant, index| %>
8
8
  <li>
9
- <%= radio_button_tag "variant_id", variant.id, index == 0, 'data-price' => variant.price_in(current_currency).money %>
9
+ <%= radio_button_tag "variant_id", variant.id, index == 0,
10
+ 'data-price' => variant.price_in(current_currency).money,
11
+ 'data-in-stock' => variant.can_supply?
12
+ %>
10
13
  <%= label_tag "variant_id_#{ variant.id }" do %>
11
14
  <span class="variant-description">
12
15
  <%= variant_options variant %>
@@ -26,7 +29,7 @@
26
29
  <%= hidden_field_tag "variant_id", @product.master.id %>
27
30
  <% end %>
28
31
 
29
- <% if @product.price_in(current_currency) and !@product.price.nil? %>
32
+ <% if @product.price_in(current_currency) && !@product.price.nil? %>
30
33
  <div data-hook="product_price" class="col-md-5">
31
34
  <div id="product-price">
32
35
  <h6 class="product-section-title"><%= Spree.t(:price) %></h6>
@@ -45,22 +48,28 @@
45
48
  <% end %>
46
49
  </div>
47
50
 
48
- <div class="add-to-cart">
49
- <br/>
50
- <div class="input-group">
51
- <%= number_field_tag :quantity, 1, :class => 'title form-control', :min => 1 %>
52
- <span class="input-group-btn">
53
- <%= button_tag :class => 'btn btn-success', :id => 'add-to-cart-button', :type => :submit do %>
54
- <%= Spree.t(:add_to_cart) %>
55
- <% end %>
56
- </span>
51
+ <% if @product.can_supply? %>
52
+ <div class="add-to-cart">
53
+ <br />
54
+ <div class="input-group">
55
+ <%= number_field_tag :quantity, 1, class: 'title form-control', min: 1 %>
56
+ <span class="input-group-btn">
57
+ <%= button_tag class: 'btn btn-success', id: 'add-to-cart-button', type: :submit do %>
58
+ <%= Spree.t(:add_to_cart) %>
59
+ <% end %>
60
+ </span>
61
+ </div>
57
62
  </div>
58
- </div>
63
+ <% end %>
59
64
  </div>
60
65
  <% else %>
61
66
  <div id="product-price">
62
- <br>
63
- <div><span class="price selling" itemprop="price"><%= Spree.t('product_not_available_in_this_currency') %></span></div>
67
+ <br />
68
+ <div>
69
+ <span class="price selling" itemprop="price">
70
+ <%= Spree.t('product_not_available_in_this_currency') %>
71
+ </span>
72
+ </div>
64
73
  </div>
65
74
  <% end %>
66
75
  </div>
@@ -1,12 +1,8 @@
1
- <% if !@product.taxons.blank? %>
2
- <div id="taxon-crumbs" data-hook class=" five ">
3
- <h3 class="product-section-title"><%= Spree.t(:look_for_similar_items) %></h3>
4
- <div data-hook="product_taxons">
5
- <ul class="list-group" id="similar_items_by_taxon" data-hook>
6
- <% @product.taxons.each do |taxon| %>
7
- <li class="list-group-item"><%= link_to taxon.name, seo_url(taxon) %></li>
8
- <% end %>
9
- </ul>
10
- </div>
11
- </div>
1
+ <% if @product.taxons.present? %>
2
+ <h3 class="product-section-title"><%= Spree.t(:look_for_similar_items) %></h3>
3
+ <ul class="list-group" id="similar_items_by_taxon" data-hook>
4
+ <% @product.taxons.each do |taxon| %>
5
+ <li class="list-group-item"><%= link_to taxon.name, seo_url(taxon) %></li>
6
+ <% end %>
7
+ </ul>
12
8
  <% end %>
@@ -1,8 +1,8 @@
1
1
  <% @body_id = 'product-details' %>
2
2
 
3
- <% cache [I18n.locale, current_currency, @product, @product.possible_promotions] do %>
4
- <div data-hook="product_show" itemscope itemtype="https://schema.org/Product">
5
- <div class="col-md-4" data-hook="product_left_part">
3
+ <% cache cache_key_for_product do %>
4
+ <div data-hook="product_show" class="row" itemscope itemtype="https://schema.org/Product">
5
+ <div class="col-md-4 col-sm-5" data-hook="product_left_part">
6
6
  <div data-hook="product_left_part_wrap">
7
7
  <div id="product-images" data-hook="product_images">
8
8
  <div id="main-image" class="panel panel-default" data-hook>
@@ -25,13 +25,13 @@
25
25
  </div>
26
26
  </div>
27
27
 
28
- <div class="col-md-8" data-hook="product_right_part">
28
+ <div class="col-md-8 col-sm-7" data-hook="product_right_part">
29
29
  <div data-hook="product_right_part_wrap">
30
30
  <div id="product-description" data-hook="product_description">
31
31
  <h1 class="product-title" itemprop="name"><%= @product.name %></h1>
32
32
 
33
33
  <div class="well" itemprop="description" data-hook="description">
34
- <%= product_description(@product) rescue Spree.t(:product_has_no_description) %>
34
+ <%= product_description(@product) %>
35
35
  </div>
36
36
 
37
37
  <div id="cart-form" data-hook="cart_form">
@@ -39,7 +39,9 @@
39
39
  </div>
40
40
  </div>
41
41
 
42
- <%= render :partial => 'taxons' %>
42
+ <div id="taxon-crumbs" class=" five " data-hook="product_taxons">
43
+ <%= render :partial => 'taxons' %>
44
+ </div>
43
45
  </div>
44
46
  </div>
45
47
  </div>
@@ -16,7 +16,7 @@
16
16
  id="<%= label %>"
17
17
  name="search[<%= filter[:scope].to_s %>][]"
18
18
  value="<%= val %>"
19
- <%= params[:search] && params[:search][filter[:scope]] && params[:search][filter[:scope]].include?(val.to_s) ? "checked" : "" %> />
19
+ <%= params[:search].present? && params[:search][filter[:scope]] && params[:search][filter[:scope]].include?(val.to_s) ? "checked" : "" %> />
20
20
  <label class="nowrap" for="<%= label %>"> <%= nm %> </label>
21
21
  </li>
22
22
  <% end %>
@@ -2,7 +2,7 @@
2
2
  <header id="header" data-hook>
3
3
  <div class="container">
4
4
  <div class="row">
5
- <figure id="logo" class="col-md-4" data-hook>
5
+ <figure id="logo" class="col-md-4 col-sm-3" data-hook>
6
6
  <%= logo %>
7
7
  </figure>
8
8
  <%= render :partial => 'spree/shared/nav_bar' %>
@@ -1,4 +1,4 @@
1
- <nav class="navbar col-md-8" id="top-nav-bar">
1
+ <nav class="navbar col-md-8 col-sm-9" id="top-nav-bar">
2
2
  <ul id="nav-bar" class="nav navbar-nav navbar-right" data-hook>
3
3
  <li id="search-bar" data-hook>
4
4
  <%= render :partial => 'spree/shared/search' %>
@@ -1,17 +1,17 @@
1
1
  <div class="row steps-data">
2
2
  <% if order.has_step?("address") %>
3
- <div class="col-md-3" data-hook="order-bill-address">
3
+ <div class="col-md-3 col-sm-3 col-xs-6" data-hook="order-bill-address">
4
4
  <h4><%= Spree.t(:billing_address) %> <%= link_to "(#{Spree.t(:edit)})", checkout_state_path(:address) unless order.completed? %></h4>
5
5
  <%= render 'spree/shared/address', address: order.bill_address %>
6
6
  </div>
7
7
 
8
8
  <% if order.has_step?("delivery") %>
9
- <div class="col-md-3" data-hook="order-ship-address">
9
+ <div class="col-md-3 col-sm-3 col-xs-6" data-hook="order-ship-address">
10
10
  <h4><%= Spree.t(:shipping_address) %> <%= link_to "(#{Spree.t(:edit)})", checkout_state_path(:address) unless order.completed? %></h4>
11
11
  <%= render 'spree/shared/address', address: order.ship_address %>
12
12
  </div>
13
13
 
14
- <div class=" col-md-3" data-hook="order-shipment">
14
+ <div class="col-md-3 col-sm-3 col-xs-6" data-hook="order-shipment">
15
15
  <h4><%= Spree.t(:shipments) %> <%= link_to "(#{Spree.t(:edit)})", checkout_state_path(:delivery) unless order.completed? %></h4>
16
16
  <div class="delivery">
17
17
  <% order.shipments.each do |shipment| %>
@@ -25,9 +25,9 @@
25
25
  </div>
26
26
  <% end %>
27
27
  <% end %>
28
-
29
- <% if @order.has_step?("payment") %>
30
- <div class="col-md-3">
28
+
29
+ <% if order.has_step?("payment") %>
30
+ <div class="col-md-3 col-sm-3 col-xs-6" data-hook="order-payment">
31
31
  <h4><%= Spree.t(:payment_information) %> <%= link_to "(#{Spree.t(:edit)})", checkout_state_path(:payment) unless order.completed? %></h4>
32
32
  <div class="payment-info">
33
33
  <% order.payments.valid.each do |payment| %>
@@ -1,11 +1,6 @@
1
- <%
2
- paginated_products = @searcher.retrieve_products if params.key?(:keywords)
3
- paginated_products ||= products
4
- %>
5
-
6
1
  <% content_for :head do %>
7
- <% if paginated_products.respond_to?(:num_pages) %>
8
- <%= rel_next_prev_link_tags paginated_products %>
2
+ <% if products.respond_to?(:num_pages) %>
3
+ <%= rel_next_prev_link_tags products %>
9
4
  <% end %>
10
5
  <% end %>
11
6
 
@@ -24,13 +19,16 @@
24
19
  <% if products.any? %>
25
20
  <div id="products" class="row" data-hook>
26
21
  <% products.each do |product| %>
27
- <% url = spree.product_path(product, taxon_id: @taxon.try(:id)) %>
28
- <div id="product_<%= product.id %>" class="col-md-3 col-sm-6 product-list-item" data-hook="products_list_item" itemscope itemtype="https://schema.org/Product">
22
+ <% url = spree.product_url(product, taxon_id: @taxon.try(:id)) %>
23
+ <div id="product_<%= product.id %>" class="col-md-3 col-sm-6 col-xs-6 product-list-item" data-hook="products_list_item" itemscope itemtype="https://schema.org/Product">
29
24
  <div class="panel panel-default">
30
- <% cache(@taxon.present? ? [I18n.locale, current_currency, @taxon, product] : [I18n.locale, current_currency, product]) do %>
25
+ <% cache(@taxon.present? ? [I18n.locale, current_currency, @taxon, product] : cache_key_for_product(product)) do %>
31
26
  <div class="panel-body text-center product-body">
32
- <%= link_to small_image(product, itemprop: "image"), url, itemprop: 'url' %><br/>
33
- <%= link_to truncate(product.name, length: 50), url, class: 'info', itemprop: "name", title: product.name %>
27
+ <%= link_to url, itemprop: "url" do %>
28
+ <%= small_image(product, itemprop: "image") %><br/>
29
+ <%= content_tag(:span, truncate(product.name, length: 50), class: 'info', itemprop: "name", title: product.name) %>
30
+ <% end %>
31
+ <br/>
34
32
  </div>
35
33
  <div class="panel-footer text-center">
36
34
  <span itemprop="offers" itemscope itemtype="https://schema.org/Offer">
@@ -45,6 +43,6 @@
45
43
  </div>
46
44
  <% end %>
47
45
 
48
- <% if paginated_products.respond_to?(:num_pages) %>
49
- <%= paginate paginated_products, theme: 'twitter-bootstrap-3' %>
46
+ <% if products.respond_to?(:num_pages) %>
47
+ <%= paginate products, theme: 'twitter-bootstrap-3' %>
50
48
  <% end %>
File without changes
data/config/routes.rb CHANGED
@@ -1,36 +1,32 @@
1
1
  Spree::Core::Engine.add_routes do
2
2
 
3
- root :to => 'home#index'
4
-
5
- resources :products, :only => [:index, :show]
6
-
7
- get '/locale/set', :to => 'locale#set'
3
+ get '/locale/set', to: 'locale#set'
8
4
 
9
5
  # non-restful checkout stuff
10
- patch '/checkout/update/:state', :to => 'checkout#update', :as => :update_checkout
11
- get '/checkout/:state', :to => 'checkout#edit', :as => :checkout_state
12
- get '/checkout', :to => 'checkout#edit' , :as => :checkout
6
+ patch '/checkout/update/:state', to: 'checkout#update', as: :update_checkout
7
+ get '/checkout/:state', to: 'checkout#edit', as: :checkout_state
8
+ get '/checkout', to: 'checkout#edit', as: :checkout
13
9
 
14
10
  populate_redirect = redirect do |params, request|
15
11
  request.flash[:error] = Spree.t(:populate_get_error)
16
12
  request.referer || '/cart'
17
13
  end
18
14
 
19
- get '/orders/populate', :to => populate_redirect
15
+ get '/orders/populate', to: populate_redirect
20
16
 
21
- resources :orders, :except => [:index, :new, :create, :destroy] do
22
- post :populate, :on => :collection
17
+ resources :orders, except: [:index, :new, :create, :destroy] do
18
+ post :populate, on: :collection
23
19
  end
24
20
 
25
- get '/cart', :to => 'orders#edit', :as => :cart
26
- patch '/cart', :to => 'orders#update', :as => :update_cart
27
- put '/cart/empty', :to => 'orders#empty', :as => :empty_cart
21
+ get '/cart', to: 'orders#edit', as: :cart
22
+ patch '/cart', to: 'orders#update', as: :update_cart
23
+ put '/cart/empty', to: 'orders#empty', as: :empty_cart
28
24
 
29
25
  # route globbing for pretty nested taxon and product paths
30
- get '/t/*id', :to => 'taxons#show', :as => :nested_taxons
26
+ get '/t/*id', to: 'taxons#show', as: :nested_taxons
31
27
 
32
- get '/unauthorized', :to => 'home#unauthorized', :as => :unauthorized
33
- get '/content/cvv', :to => 'content#cvv', :as => :cvv
34
- get '/content/*path', :to => 'content#show', :as => :content
35
- get '/cart_link', :to => 'store#cart_link', :as => :cart_link
28
+ get '/unauthorized', to: 'home#unauthorized', as: :unauthorized
29
+ get '/content/cvv', to: 'content#cvv', as: :cvv
30
+ get '/content/*path', to: 'content#show', as: :content
31
+ get '/cart_link', to: 'store#cart_link', as: :cart_link
36
32
  end
@@ -5,22 +5,118 @@ require 'spec_helper'
5
5
  # ProductsController is good.
6
6
  describe Spree::ProductsController, :type => :controller do
7
7
 
8
+ let!(:available_locales) { [:en, :de] }
9
+ let!(:available_locale) { :de }
10
+ let!(:unavailable_locale) { :ru }
11
+
8
12
  before do
9
13
  I18n.enforce_available_locales = false
10
- expect(I18n).to receive(:available_locales).and_return([:en, :de])
11
- Spree::Frontend::Config[:locale] = :de
14
+ expect(I18n).to receive(:available_locales).and_return(available_locales)
12
15
  end
13
16
 
14
17
  after do
15
18
  Spree::Frontend::Config[:locale] = :en
19
+ Rails.application.config.i18n.default_locale = :en
16
20
  I18n.locale = :en
17
21
  I18n.enforce_available_locales = true
18
22
  end
19
23
 
20
24
  # 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
+ 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
25
121
  end
26
122
  end