solidus_frontend_devise_token_auth 2.8.0.alpha.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (163) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +26 -0
  3. data/README.md +42 -0
  4. data/Rakefile +17 -0
  5. data/app/assets/config/solidus_frontend_manifest.js +4 -0
  6. data/app/assets/images/credit_cards/amex_cid.gif +0 -0
  7. data/app/assets/images/credit_cards/credit_card.gif +0 -0
  8. data/app/assets/images/credit_cards/discover_cid.gif +0 -0
  9. data/app/assets/images/credit_cards/icons/american_express.png +0 -0
  10. data/app/assets/images/credit_cards/icons/cirrus.png +0 -0
  11. data/app/assets/images/credit_cards/icons/delta.png +0 -0
  12. data/app/assets/images/credit_cards/icons/diners_club.png +0 -0
  13. data/app/assets/images/credit_cards/icons/directdebit.png +0 -0
  14. data/app/assets/images/credit_cards/icons/discover.png +0 -0
  15. data/app/assets/images/credit_cards/icons/egold.png +0 -0
  16. data/app/assets/images/credit_cards/icons/maestro.png +0 -0
  17. data/app/assets/images/credit_cards/icons/master.png +0 -0
  18. data/app/assets/images/credit_cards/icons/paypal.png +0 -0
  19. data/app/assets/images/credit_cards/icons/solo.png +0 -0
  20. data/app/assets/images/credit_cards/icons/switch.png +0 -0
  21. data/app/assets/images/credit_cards/icons/visa.png +0 -0
  22. data/app/assets/images/credit_cards/icons/visaelectron.png +0 -0
  23. data/app/assets/images/credit_cards/icons/westernunion.png +0 -0
  24. data/app/assets/images/credit_cards/icons/wirecard.png +0 -0
  25. data/app/assets/images/credit_cards/icons/worldpay.png +0 -0
  26. data/app/assets/images/credit_cards/master_cid.jpg +0 -0
  27. data/app/assets/images/credit_cards/visa_cid.gif +0 -0
  28. data/app/assets/images/favicon.ico +0 -0
  29. data/app/assets/images/icons/add-to-cart.png +0 -0
  30. data/app/assets/images/icons/checkout.png +0 -0
  31. data/app/assets/images/icons/delete.png +0 -0
  32. data/app/assets/images/icons/update.png +0 -0
  33. data/app/assets/images/spinner.gif +0 -0
  34. data/app/assets/images/spree/frontend/cart.png +0 -0
  35. data/app/assets/javascripts/spree/frontend/cart.js +30 -0
  36. data/app/assets/javascripts/spree/frontend/checkout/address.js +127 -0
  37. data/app/assets/javascripts/spree/frontend/checkout/coupon-code.js +41 -0
  38. data/app/assets/javascripts/spree/frontend/checkout/payment.js +55 -0
  39. data/app/assets/javascripts/spree/frontend/checkout.js +24 -0
  40. data/app/assets/javascripts/spree/frontend/locale_selector.js +5 -0
  41. data/app/assets/javascripts/spree/frontend/product.js +81 -0
  42. data/app/assets/javascripts/spree/frontend.js +5 -0
  43. data/app/assets/stylesheets/spree/frontend/_skeleton.scss +242 -0
  44. data/app/assets/stylesheets/spree/frontend/_variables.scss +65 -0
  45. data/app/assets/stylesheets/spree/frontend/screen.css.scss +1387 -0
  46. data/app/assets/stylesheets/spree/frontend.css +5 -0
  47. data/app/controllers/spree/checkout_controller.rb +236 -0
  48. data/app/controllers/spree/content_controller.rb +11 -0
  49. data/app/controllers/spree/home_controller.rb +14 -0
  50. data/app/controllers/spree/locale_controller.rb +20 -0
  51. data/app/controllers/spree/orders_controller.rb +138 -0
  52. data/app/controllers/spree/products_controller.rb +52 -0
  53. data/app/controllers/spree/store_controller.rb +30 -0
  54. data/app/controllers/spree/taxons_controller.rb +31 -0
  55. data/app/helpers/spree/orders_helper.rb +18 -0
  56. data/app/helpers/spree/taxon_filters_helper.rb +13 -0
  57. data/app/models/spree/frontend_configuration.rb +10 -0
  58. data/app/views/spree/address/_form.html.erb +96 -0
  59. data/app/views/spree/address/_form_hidden.html.erb +12 -0
  60. data/app/views/spree/checkout/_address.html.erb +33 -0
  61. data/app/views/spree/checkout/_confirm.html.erb +25 -0
  62. data/app/views/spree/checkout/_coupon_code.html.erb +12 -0
  63. data/app/views/spree/checkout/_delivery.html.erb +108 -0
  64. data/app/views/spree/checkout/_payment.html.erb +67 -0
  65. data/app/views/spree/checkout/_summary.html.erb +76 -0
  66. data/app/views/spree/checkout/_terms_and_conditions.en.html.erb +1 -0
  67. data/app/views/spree/checkout/edit.html.erb +32 -0
  68. data/app/views/spree/checkout/existing_payment/_gateway.html.erb +9 -0
  69. data/app/views/spree/checkout/payment/_check.html.erb +0 -0
  70. data/app/views/spree/checkout/payment/_gateway.html.erb +36 -0
  71. data/app/views/spree/content/cvv.html.erb +13 -0
  72. data/app/views/spree/home/index.html.erb +12 -0
  73. data/app/views/spree/layouts/spree_application.html.erb +36 -0
  74. data/app/views/spree/orders/_adjustment_row.html.erb +8 -0
  75. data/app/views/spree/orders/_adjustments.html.erb +24 -0
  76. data/app/views/spree/orders/_form.html.erb +29 -0
  77. data/app/views/spree/orders/_line_item.html.erb +34 -0
  78. data/app/views/spree/orders/edit.html.erb +47 -0
  79. data/app/views/spree/orders/show.html.erb +22 -0
  80. data/app/views/spree/payments/_payment.html.erb +18 -0
  81. data/app/views/spree/products/_cart_form.html.erb +65 -0
  82. data/app/views/spree/products/_image.html.erb +8 -0
  83. data/app/views/spree/products/_promotions.html.erb +19 -0
  84. data/app/views/spree/products/_properties.html.erb +15 -0
  85. data/app/views/spree/products/_taxons.html.erb +14 -0
  86. data/app/views/spree/products/_thumbnails.html.erb +21 -0
  87. data/app/views/spree/products/index.html.erb +27 -0
  88. data/app/views/spree/products/show.html.erb +51 -0
  89. data/app/views/spree/shared/_address.html.erb +38 -0
  90. data/app/views/spree/shared/_filters.html.erb +27 -0
  91. data/app/views/spree/shared/_footer.html.erb +6 -0
  92. data/app/views/spree/shared/_head.html.erb +14 -0
  93. data/app/views/spree/shared/_header.html.erb +5 -0
  94. data/app/views/spree/shared/_image.html.erb +12 -0
  95. data/app/views/spree/shared/_link_to_cart.html.erb +1 -0
  96. data/app/views/spree/shared/_locale_selector.html.erb +25 -0
  97. data/app/views/spree/shared/_login_bar_items.html.erb +1 -0
  98. data/app/views/spree/shared/_main_nav_bar.html.erb +12 -0
  99. data/app/views/spree/shared/_nav_bar.html.erb +9 -0
  100. data/app/views/spree/shared/_order_details.html.erb +146 -0
  101. data/app/views/spree/shared/_products.html.erb +51 -0
  102. data/app/views/spree/shared/_search.html.erb +11 -0
  103. data/app/views/spree/shared/_shipment_tracking.html.erb +9 -0
  104. data/app/views/spree/shared/_sidebar.html.erb +3 -0
  105. data/app/views/spree/shared/_taxonomies.html.erb +9 -0
  106. data/app/views/spree/shared/unauthorized.html.erb +0 -0
  107. data/app/views/spree/store/cart_link.html.erb +1 -0
  108. data/app/views/spree/taxons/_taxon.html.erb +4 -0
  109. data/app/views/spree/taxons/show.html.erb +20 -0
  110. data/config/initializers/assets.rb +3 -0
  111. data/config/initializers/canonical_rails.rb +16 -0
  112. data/config/routes.rb +33 -0
  113. data/lib/generators/solidus/views/override_generator.rb +49 -0
  114. data/lib/solidus_frontend.rb +3 -0
  115. data/lib/spree/frontend/engine.rb +13 -0
  116. data/lib/spree/frontend/middleware/seo_assist.rb +52 -0
  117. data/lib/spree/frontend.rb +15 -0
  118. data/lib/spree_frontend.rb +3 -0
  119. data/lib/tasks/rake_util.rb +18 -0
  120. data/lib/tasks/taxon.rake +16 -0
  121. data/script/rails +10 -0
  122. data/solidus_frontend.gemspec +35 -0
  123. data/spec/controllers/controller_helpers_spec.rb +30 -0
  124. data/spec/controllers/locale_controller_spec.rb +57 -0
  125. data/spec/controllers/spree/checkout_controller_spec.rb +539 -0
  126. data/spec/controllers/spree/checkout_controller_with_views_spec.rb +37 -0
  127. data/spec/controllers/spree/content_controller_spec.rb +9 -0
  128. data/spec/controllers/spree/current_order_tracking_spec.rb +47 -0
  129. data/spec/controllers/spree/home_controller_spec.rb +29 -0
  130. data/spec/controllers/spree/orders_controller_ability_spec.rb +93 -0
  131. data/spec/controllers/spree/orders_controller_spec.rb +225 -0
  132. data/spec/controllers/spree/orders_controller_transitions_spec.rb +33 -0
  133. data/spec/controllers/spree/products_controller_spec.rb +38 -0
  134. data/spec/controllers/spree/taxons_controller_spec.rb +14 -0
  135. data/spec/features/address_spec.rb +78 -0
  136. data/spec/features/automatic_promotion_adjustments_spec.rb +49 -0
  137. data/spec/features/caching/products_spec.rb +48 -0
  138. data/spec/features/caching/taxons_spec.rb +21 -0
  139. data/spec/features/cart_spec.rb +85 -0
  140. data/spec/features/checkout_spec.rb +690 -0
  141. data/spec/features/checkout_unshippable_spec.rb +37 -0
  142. data/spec/features/coupon_code_spec.rb +266 -0
  143. data/spec/features/currency_spec.rb +20 -0
  144. data/spec/features/free_shipping_promotions_spec.rb +60 -0
  145. data/spec/features/locale_spec.rb +27 -0
  146. data/spec/features/order_spec.rb +73 -0
  147. data/spec/features/products_spec.rb +291 -0
  148. data/spec/features/promotion_code_invalidation_spec.rb +54 -0
  149. data/spec/features/quantity_promotions_spec.rb +130 -0
  150. data/spec/features/taxons_spec.rb +158 -0
  151. data/spec/features/template_rendering_spec.rb +20 -0
  152. data/spec/fixtures/thinking-cat.jpg +0 -0
  153. data/spec/generators/solidus/views/override_generator_spec.rb +50 -0
  154. data/spec/helpers/base_helper_spec.rb +13 -0
  155. data/spec/helpers/order_helper_spec.rb +14 -0
  156. data/spec/helpers/taxon_filters_helper_spec.rb +12 -0
  157. data/spec/spec_helper.rb +106 -0
  158. data/spec/support/features/fill_in_with_force.rb +12 -0
  159. data/spec/support/shared_contexts/checkout_setup.rb +12 -0
  160. data/spec/support/shared_contexts/custom_products.rb +28 -0
  161. data/spec/support/shared_contexts/locales.rb +16 -0
  162. data/spec/views/spree/checkout/_summary_spec.rb +11 -0
  163. metadata +337 -0
@@ -0,0 +1,11 @@
1
+ <% @taxons = @taxon && @taxon.parent ? @taxon.parent.children : Spree::Taxon.roots %>
2
+ <%= form_tag spree.products_path, method: :get do %>
3
+ <% cache [I18n.locale, @taxons] do %>
4
+ <%= select_tag :taxon,
5
+ options_for_select([[t('spree.all_departments'), '']] +
6
+ @taxons.map {|t| [t.name, t.id]},
7
+ @taxon ? @taxon.id : params[:taxon]), 'aria-label' => 'Taxon' %>
8
+ <% end %>
9
+ <%= search_field_tag :keywords, params[:keywords], placeholder: t('spree.search') %>
10
+ <%= submit_tag t('spree.search'), name: nil %>
11
+ <% end %>
@@ -0,0 +1,9 @@
1
+ <% shipments = order.shipments.trackable %>
2
+ <% if shipments.any? %>
3
+ <h6><%= t('spree.tracking') %></h6>
4
+ <div class="tracking">
5
+ <% shipments.each do |shipment| %>
6
+ <%= link_to_tracking(shipment) %>
7
+ <% end %>
8
+ </div>
9
+ <% end %>
@@ -0,0 +1,3 @@
1
+ <aside id="sidebar" class="columns four" data-hook>
2
+ <%= yield :sidebar %>
3
+ </aside>
@@ -0,0 +1,9 @@
1
+ <% max_level = Spree::Config[:max_level_in_taxons_menu] || 1 %>
2
+ <nav id="taxonomies" class="sidebar-item" data-hook>
3
+ <% @taxonomies.each do |taxonomy| %>
4
+ <% cache [I18n.locale, taxonomy, @taxon, max_level] do %>
5
+ <h6 class='taxonomy-root'><%= t('spree.shop_by_taxonomy', taxonomy: taxonomy.name) %></h6>
6
+ <%= taxons_tree(taxonomy.root, @taxon, max_level) %>
7
+ <% end %>
8
+ <% end %>
9
+ </nav>
File without changes
@@ -0,0 +1 @@
1
+ <%= link_to_cart %>
@@ -0,0 +1,4 @@
1
+ <div class="taxon" data-hook="taxon">
2
+ <h5 class="subtaxon-title"><%= link_to taxon.name, seo_url(taxon), class: 'breadcrumbs' %></h5>
3
+ <%= render partial: 'spree/shared/products', locals: { products: taxon_preview(taxon), taxon: taxon } %>
4
+ </div>
@@ -0,0 +1,20 @@
1
+ <h1 class="taxon-title"><%= @taxon.name %></h1>
2
+
3
+ <% content_for :sidebar do %>
4
+ <div data-hook="taxon_sidebar_navigation">
5
+ <%= render partial: 'spree/shared/taxonomies' %>
6
+ <%= render partial: 'spree/shared/filters' if @taxon.children.empty? %>
7
+ </div>
8
+ <% end %>
9
+
10
+ <div data-hook="taxon_products">
11
+ <%= render partial: 'spree/shared/products', locals: { products: @products, taxon: @taxon } %>
12
+ </div>
13
+
14
+ <% unless params[:keywords].present? %>
15
+ <div data-hook="taxon_children">
16
+ <% cache [I18n.locale, @taxon] do %>
17
+ <%= render partial: 'taxon', collection: @taxon.children %>
18
+ <% end %>
19
+ </div>
20
+ <% end %>
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ Rails.application.config.assets.precompile << 'solidus_frontend_manifest.js'
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ CanonicalRails.setup do |config|
4
+ # http://en.wikipedia.org/wiki/URL_normalization
5
+ # Trailing slash represents semantics of a directory, ie a collection view - implying an :index get route;
6
+ # otherwise we have to assume semantics of an instance of a resource type, a member view - implying a :show get route
7
+ #
8
+ # Acts as a whitelist for routes to have trailing slashes
9
+
10
+ config.collection_actions # = [:index]
11
+
12
+ # Parameter spamming can cause index dilution by creating seemingly different URLs with identical or near-identical content.
13
+ # Unless whitelisted, these parameters will be omitted
14
+
15
+ config.whitelisted_parameters = [:keywords, :page, :search, :taxon]
16
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ Spree::Core::Engine.routes.draw do
4
+ root to: 'home#index'
5
+
6
+ resources :products, only: [:index, :show]
7
+
8
+ get '/locale/set', to: 'locale#set'
9
+ post '/locale/set', to: 'locale#set', as: :select_locale
10
+
11
+ # non-restful checkout stuff
12
+ patch '/checkout/update/:state', to: 'checkout#update', as: :update_checkout
13
+ get '/checkout/:state', to: 'checkout#edit', as: :checkout_state
14
+ get '/checkout', to: 'checkout#edit', as: :checkout
15
+
16
+ get '/orders/populate', to: 'orders#populate_redirect'
17
+ get '/orders/:id/token/:token' => 'orders#show', as: :token_order
18
+
19
+ resources :orders, except: [:index, :new, :create, :destroy] do
20
+ post :populate, on: :collection
21
+ end
22
+
23
+ get '/cart', to: 'orders#edit', as: :cart
24
+ patch '/cart', to: 'orders#update', as: :update_cart
25
+ put '/cart/empty', to: 'orders#empty', as: :empty_cart
26
+
27
+ # route globbing for pretty nested taxon and product paths
28
+ get '/t/*id', to: 'taxons#show', as: :nested_taxons
29
+
30
+ get '/unauthorized', to: 'home#unauthorized', as: :unauthorized
31
+ get '/content/cvv', to: 'content#cvv', as: :cvv
32
+ get '/cart_link', to: 'store#cart_link', as: :cart_link
33
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails'
4
+ require 'rails/generators'
5
+
6
+ module Solidus
7
+ module Views
8
+ class OverrideGenerator < ::Rails::Generators::Base
9
+ def self.views_folder
10
+ Spree::Frontend::Engine.root.join('app', 'views', 'spree')
11
+ end
12
+
13
+ VIEWS = Dir.glob(views_folder.join('**', '*'))
14
+
15
+ desc "Override solidus frontend views in your app. You can either provide single files or complete folders."
16
+
17
+ class_option :only,
18
+ type: :string,
19
+ default: nil,
20
+ desc: "Name of file or folder to copy exclusively. Can be a substring."
21
+
22
+ source_root views_folder
23
+
24
+ def copy_views
25
+ views_to_copy.each do |file|
26
+ next if File.directory?(file)
27
+ dest_file = Pathname.new(file).relative_path_from(source_dir)
28
+ copy_file file, Rails.root.join('app', 'views', 'spree', dest_file)
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ def views_to_copy
35
+ if @options['only']
36
+ VIEWS.select do |v|
37
+ Pathname.new(v).relative_path_from(source_dir).to_s.include?(@options['only'])
38
+ end
39
+ else
40
+ VIEWS
41
+ end
42
+ end
43
+
44
+ def source_dir
45
+ self.class.views_folder
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spree_frontend'
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spree
4
+ module Frontend
5
+ class Engine < ::Rails::Engine
6
+ config.middleware.use "Spree::Frontend::Middleware::SeoAssist"
7
+
8
+ initializer "spree.frontend.environment", before: :load_config_initializers do |_app|
9
+ Spree::Frontend::Config = Spree::FrontendConfiguration.new
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Make redirects for SEO needs
4
+ module Spree
5
+ module Frontend
6
+ module Middleware
7
+ class SeoAssist
8
+ def initialize(app)
9
+ @app = app
10
+ end
11
+
12
+ def call(env)
13
+ request = Rack::Request.new(env)
14
+ params = request.params
15
+
16
+ taxon_id = params['taxon']
17
+
18
+ # redirect requests using taxon id's to their permalinks
19
+ if !taxon_id.blank? && !taxon_id.is_a?(Hash) && taxon = Taxon.find(taxon_id)
20
+ params.delete('taxon')
21
+
22
+ return build_response(params, "#{request.script_name}t/#{taxon.permalink}" )
23
+ elsif env["PATH_INFO"] =~ /^\/(t|products)(\/\S+)?\/$/
24
+ # ensures no trailing / for taxon and product urls
25
+
26
+ return build_response(params, env["PATH_INFO"][0...-1])
27
+ end
28
+
29
+ @app.call(env)
30
+ end
31
+
32
+ private
33
+
34
+ def build_response(params, location)
35
+ query = build_query(params)
36
+ location += '?' + query unless query.blank?
37
+ [301, { 'Location' => location }, []]
38
+ end
39
+
40
+ def build_query(params)
41
+ params.map { |k, v|
42
+ if v.class == Array
43
+ build_query(v.map { |x| ["#{k}[]", x] })
44
+ else
45
+ k + "=" + Rack::Utils.escape(v)
46
+ end
47
+ }.join("&")
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/all'
4
+ require 'jquery-rails'
5
+ require 'canonical-rails'
6
+ require 'sassc-rails'
7
+ require 'font-awesome-rails'
8
+ require 'responders'
9
+ require 'kaminari'
10
+
11
+ require 'solidus_core'
12
+ require 'solidus_api'
13
+
14
+ require 'spree/frontend/middleware/seo_assist'
15
+ require 'spree/frontend/engine'
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spree/frontend'
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RakeUtil
4
+ def self.add_marker(msg)
5
+ puts "#" * 30 + " #{msg} " + '#' * 30
6
+ end
7
+
8
+ def self.warning(msg)
9
+ puts "#" * 50
10
+ puts msg
11
+ puts "#" * 50
12
+ end
13
+
14
+ def self.execute(cmd)
15
+ puts cmd
16
+ system cmd
17
+ end
18
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ namespace :spree do
4
+ desc "Resets all taxon permalinks"
5
+ task reset_taxon_permalinks: :environment do
6
+ Spree::Taxon.where(parent_id: nil).each { |taxon| redo_permalinks(taxon) }
7
+ end
8
+
9
+ def redo_permalinks(taxon)
10
+ taxon.permalink = nil
11
+ puts "#{taxon.permalink} => #{taxon.set_permalink}"
12
+ taxon.save
13
+
14
+ taxon.children.each { |t| redo_permalinks(t) }
15
+ end
16
+ end
data/script/rails ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
5
+
6
+ ENGINE_ROOT = File.expand_path('..', __dir__)
7
+ ENGINE_PATH = File.expand_path('../lib/spree/frontend/engine', __dir__)
8
+
9
+ require 'rails/all'
10
+ require 'rails/engine/commands'
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../core/lib/spree/core/version.rb'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.platform = Gem::Platform::RUBY
7
+ s.name = 'solidus_frontend_devise_token_auth'
8
+ s.version = Spree.solidus_version
9
+ s.summary = 'Cart and storefront for the Solidus e-commerce project.'
10
+ s.description = s.summary
11
+
12
+ s.author = 'Solidus Team'
13
+ s.email = 'contact@solidus.io'
14
+ s.homepage = 'http://solidus.io/'
15
+ s.license = 'BSD-3-Clause'
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.require_path = 'lib'
19
+ s.requirements << 'none'
20
+
21
+ s.required_ruby_version = '>= 2.2.2'
22
+ s.required_rubygems_version = '>= 1.8.23'
23
+
24
+ s.add_dependency 'solidus_api_devise_token_auth', s.version
25
+ s.add_dependency 'solidus_core_devise_token_auth', s.version
26
+
27
+ s.add_dependency 'canonical-rails', '~> 0.2.0'
28
+ s.add_dependency 'font-awesome-rails', '~> 4.0'
29
+ s.add_dependency 'jquery-rails'
30
+ s.add_dependency 'kaminari', '~> 1.1'
31
+ s.add_dependency 'sassc-rails'
32
+ s.add_dependency 'truncate_html', '~> 0.9', '>= 0.9.2'
33
+
34
+ s.add_development_dependency 'capybara-accessible'
35
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ # In this file, we want to test that the controller helpers function correctly
6
+ # So we need to use one of the controllers inside Spree.
7
+ # ProductsController is good.
8
+ describe Spree::ProductsController, type: :controller do
9
+ before do
10
+ I18n.enforce_available_locales = false
11
+ Spree::Frontend::Config[:locale] = :de
12
+ I18n.backend.store_translations(:de, spree: {
13
+ i18n: { this_file_language: "Deutsch (DE)" }
14
+ })
15
+ end
16
+
17
+ after do
18
+ I18n.reload!
19
+ Spree::Frontend::Config[:locale] = :en
20
+ I18n.locale = :en
21
+ I18n.enforce_available_locales = true
22
+ end
23
+
24
+ # Regression test for https://github.com/spree/spree/issues/1184
25
+ it "sets the default locale based off Spree::Frontend::Config[:locale]" do
26
+ expect(I18n.locale).to eq(:en)
27
+ get :index
28
+ expect(I18n.locale).to eq(:de)
29
+ end
30
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Spree::LocaleController, type: :controller do
6
+ include_context "fr locale"
7
+
8
+ context 'switch_to_locale specified' do
9
+ context "available locale" do
10
+ it 'sets locale and redirects' do
11
+ get :set, params: { switch_to_locale: 'fr' }
12
+ expect(I18n.locale).to eq :fr
13
+ expect(response).to redirect_to('/')
14
+ expect(session[:locale]).to eq('fr')
15
+ expect(flash[:notice]).to eq(I18n.t("spree.locale_changed"))
16
+ end
17
+ end
18
+
19
+ context "unavailable locale" do
20
+ it 'does not change locale and redirects' do
21
+ get :set, params: { switch_to_locale: 'klingon' }
22
+ expect(I18n.locale).to eq :en
23
+ expect(response).to redirect_to('/')
24
+ expect(flash[:error]).to eq(I18n.t("spree.locale_not_changed"))
25
+ end
26
+ end
27
+ end
28
+
29
+ context 'locale specified' do
30
+ context "available locale" do
31
+ it 'sets locale and redirects' do
32
+ get :set, params: { locale: 'fr' }
33
+ expect(I18n.locale).to eq :fr
34
+ expect(response).to redirect_to('/')
35
+ expect(flash[:notice]).to eq(I18n.t("spree.locale_changed"))
36
+ end
37
+ end
38
+
39
+ context "unavailable locale" do
40
+ it 'does not change locale and redirects' do
41
+ get :set, params: { locale: 'klingon' }
42
+ expect(I18n.locale).to eq :en
43
+ expect(response).to redirect_to('/')
44
+ expect(flash[:error]).to eq(I18n.t("spree.locale_not_changed"))
45
+ end
46
+ end
47
+ end
48
+
49
+ context 'both locale and switch_to_locale specified' do
50
+ it 'uses switch_to_locale value' do
51
+ get :set, params: { locale: 'en', switch_to_locale: 'fr' }
52
+ expect(I18n.locale).to eq :fr
53
+ expect(response).to redirect_to('/')
54
+ expect(flash[:notice]).to eq(I18n.t("spree.locale_changed"))
55
+ end
56
+ end
57
+ end