solidus_i18n 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +20 -0
  3. data/.hound.yml +25 -0
  4. data/.rubocop.yml +7 -0
  5. data/.travis.yml +12 -0
  6. data/CONTRIBUTING.md +70 -0
  7. data/Gemfile +13 -0
  8. data/Guardfile +11 -0
  9. data/LICENSE.md +26 -0
  10. data/README.md +74 -0
  11. data/Rakefile +85 -0
  12. data/app/assets/javascripts/spree/backend/solidus_i18n.js +2 -0
  13. data/app/assets/javascripts/spree/backend/translations.js.coffee +5 -0
  14. data/app/assets/javascripts/spree/frontend/cart_decorator.js.coffee +5 -0
  15. data/app/assets/javascripts/spree/frontend/locale.js.coffee +3 -0
  16. data/app/assets/javascripts/spree/frontend/solidus_i18n.js +2 -0
  17. data/app/assets/stylesheets/spree/backend/solidus_i18n.css +8 -0
  18. data/app/assets/stylesheets/spree/frontend/solidus_i18n.css +8 -0
  19. data/app/controllers/spree/admin/general_settings_controller_decorator.rb +12 -0
  20. data/app/controllers/spree/api/base_controller_decorator.rb +3 -0
  21. data/app/controllers/spree/base_controller_decorator.rb +3 -0
  22. data/app/controllers/spree/locale_controller_decorator.rb +6 -0
  23. data/app/helpers/solidus_i18n/locale_helper.rb +31 -0
  24. data/app/overrides/spree/admin/general_settings/edit/localization_settings.html.erb.deface +20 -0
  25. data/app/overrides/spree/shared/_main_nav_bar/cart_link.html.erb.deface +9 -0
  26. data/app/overrides/spree/shared/_main_nav_bar/locale_selector.html.erb.deface +16 -0
  27. data/bin/rails +7 -0
  28. data/config/initializers/country_names.rb +51 -0
  29. data/config/initializers/routing_filter.rb +2 -0
  30. data/config/locales/bg.yml +1330 -0
  31. data/config/locales/ca.yml +1334 -0
  32. data/config/locales/cs.yml +1363 -0
  33. data/config/locales/da.yml +1336 -0
  34. data/config/locales/de-CH.yml +1288 -0
  35. data/config/locales/de.yml +1477 -0
  36. data/config/locales/en-AU.yml +1334 -0
  37. data/config/locales/en-GB.yml +1338 -0
  38. data/config/locales/en-IN.yml +1336 -0
  39. data/config/locales/en-NZ.yml +1334 -0
  40. data/config/locales/es-CL.yml +1398 -0
  41. data/config/locales/es-EC.yml +1338 -0
  42. data/config/locales/es-MX.yml +1337 -0
  43. data/config/locales/es.yml +1338 -0
  44. data/config/locales/et.yml +1316 -0
  45. data/config/locales/fa.yml +1163 -0
  46. data/config/locales/fi.yml +1352 -0
  47. data/config/locales/fr.yml +1588 -0
  48. data/config/locales/id.yml +1335 -0
  49. data/config/locales/it.yml +1395 -0
  50. data/config/locales/ja.yml +1336 -0
  51. data/config/locales/ko.yml +1294 -0
  52. data/config/locales/lv.yml +1328 -0
  53. data/config/locales/nb.yml +1339 -0
  54. data/config/locales/nl.yml +1338 -0
  55. data/config/locales/pl.yml +1345 -0
  56. data/config/locales/pt-BR.yml +1364 -0
  57. data/config/locales/pt.yml +1290 -0
  58. data/config/locales/ro.yml +1335 -0
  59. data/config/locales/ru.yml +1400 -0
  60. data/config/locales/sk.yml +1345 -0
  61. data/config/locales/sl-SI.yml +1288 -0
  62. data/config/locales/sv.yml +1372 -0
  63. data/config/locales/th.yml +1330 -0
  64. data/config/locales/tr.yml +1291 -0
  65. data/config/locales/uk.yml +1447 -0
  66. data/config/locales/vi.yml +1290 -0
  67. data/config/locales/zh-CN.yml +1345 -0
  68. data/config/locales/zh-TW.yml +1293 -0
  69. data/config/routes.rb +6 -0
  70. data/db/migrate/20150609154031_remove_translations_from_spree_tables.rb +65 -0
  71. data/lib/generators/solidus_i18n/install/install_generator.rb +27 -0
  72. data/lib/solidus_i18n/configuration.rb +9 -0
  73. data/lib/solidus_i18n/controller_locale_helper.rb +29 -0
  74. data/lib/solidus_i18n/engine.rb +45 -0
  75. data/lib/solidus_i18n/locale.rb +13 -0
  76. data/lib/solidus_i18n/utils.rb +56 -0
  77. data/lib/solidus_i18n/version.rb +18 -0
  78. data/lib/solidus_i18n.rb +8 -0
  79. data/lib/tasks/solidus_i18n/upgrade.rake +43 -0
  80. data/solidus_i18n.gemspec +46 -0
  81. data/spec/controllers/locales_controller_spec.rb +24 -0
  82. data/spec/features/admin/translations_spec.rb +33 -0
  83. data/spec/features/russian_errors_translation_spec.rb +17 -0
  84. data/spec/features/translation_spec.rb +31 -0
  85. data/spec/features/translations_spec.rb +28 -0
  86. data/spec/spec_helper.rb +31 -0
  87. data/spec/support/capybara.rb +11 -0
  88. data/spec/support/database_cleaner.rb +23 -0
  89. data/spec/support/factory_girl.rb +5 -0
  90. data/spec/support/i18n.rb +5 -0
  91. data/spec/support/spree.rb +12 -0
  92. metadata +411 -0
data/config/routes.rb ADDED
@@ -0,0 +1,6 @@
1
+ Spree::Core::Engine.add_routes do
2
+ # from routing-filter gem
3
+ filter :locale
4
+
5
+ post '/locale/set', to: 'locale#set', defaults: { format: :json }, as: :set_locale
6
+ end
@@ -0,0 +1,65 @@
1
+ class RemoveTranslationsFromSpreeTables < ActiveRecord::Migration
2
+ def up
3
+ # Don't migrate if we still use Globalize, i.e. through spree_globalize Gem
4
+ return if defined?(Globalize)
5
+
6
+ %w(
7
+ OptionType
8
+ OptionValue
9
+ ProductProperty
10
+ Product
11
+ Promotion
12
+ Property
13
+ Store
14
+ Taxon
15
+ Taxonomy
16
+ ).each do |class_name|
17
+ migrate_translation_data!(class_name)
18
+ end
19
+ end
20
+
21
+ def down
22
+ return if defined?(Globalize)
23
+ raise ActiveRecord::IrreversibleMigration
24
+ end
25
+
26
+ private
27
+
28
+ def current_locale
29
+ I18n.default_locale || 'en'
30
+ end
31
+
32
+ def migrate_translation_data!(class_name)
33
+ klass = "Spree::#{class_name}".constantize
34
+ table_name = klass.table_name
35
+ singular_table_name = table_name.singularize
36
+
37
+ return if !table_exists?(table_name) || !table_exists?("#{singular_table_name}_translations")
38
+
39
+ # We can't rely on Globalize drop_translation_table! here,
40
+ # because the Gem has been already removed, so we need to run custom SQL
41
+ records = exec_query("SELECT * FROM #{singular_table_name}_translations WHERE locale = '#{current_locale}';")
42
+
43
+ records.each do |record|
44
+ id = record["#{singular_table_name}_id"]
45
+ attributes = record.except(
46
+ 'id',
47
+ "#{singular_table_name}_id",
48
+ 'locale',
49
+ 'deleted_at',
50
+ 'created_at',
51
+ 'updated_at'
52
+ )
53
+ object = if klass.respond_to?(:with_deleted)
54
+ klass.with_deleted.find(id)
55
+ else
56
+ klass.find(id)
57
+ end
58
+ object.update_columns(attributes)
59
+ end
60
+
61
+ say "Migrated #{current_locale} translation for #{class_name} back into original table."
62
+
63
+ drop_table "#{singular_table_name}_translations"
64
+ end
65
+ end
@@ -0,0 +1,27 @@
1
+ module SolidusI18n
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ class_option :auto_run_migrations, type: :boolean, default: true
5
+
6
+ def add_javascripts
7
+ append_file 'vendor/assets/javascripts/spree/backend/all.js',
8
+ "//= require spree/backend/solidus_i18n\n"
9
+ append_file 'vendor/assets/javascripts/spree/frontend/all.js',
10
+ "//= require spree/frontend/solidus_i18n\n"
11
+ end
12
+
13
+ def add_migrations
14
+ run 'bin/rake solidus_i18n:install:migrations'
15
+ end
16
+
17
+ def run_migrations
18
+ if options[:auto_run_migrations] ||
19
+ ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]'))
20
+ run 'bin/rake db:migrate'
21
+ else
22
+ puts "Skiping rake db:migrate, don't forget to run it!"
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,9 @@
1
+ module SolidusI18n
2
+ class Configuration < Spree::Preferences::Configuration
3
+ # These configs intend to, respectively:
4
+ #
5
+ # Set locales that should be available for end users
6
+ #
7
+ preference :available_locales, :array, default: [:en]
8
+ end
9
+ end
@@ -0,0 +1,29 @@
1
+ module SolidusI18n
2
+ # The fact this logic is in a single module also helps to apply a custom
3
+ # locale on the spree/api context since api base controller inherits from
4
+ # MetalController instead of Spree::BaseController
5
+ module ControllerLocaleHelper
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ prepend_before_filter :set_user_language
10
+
11
+ private
12
+
13
+ # Overrides the Spree::Core::ControllerHelpers::Common logic so that only
14
+ # supported locales defined by SolidusI18n::Config.supported_locales can
15
+ # actually be set
16
+ def set_user_language
17
+ # params[:locale] can be added by routing-filter gem
18
+ I18n.locale = \
19
+ if params[:locale] && Config.available_locales.include?(params[:locale].to_sym)
20
+ params[:locale]
21
+ elsif respond_to?(:config_locale, true) && !config_locale.blank?
22
+ config_locale
23
+ else
24
+ Rails.application.config.i18n.default_locale || I18n.default_locale
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,45 @@
1
+ require 'routing_filter'
2
+ require 'kaminari-i18n/engine'
3
+
4
+ module SolidusI18n
5
+ class Engine < Rails::Engine
6
+ engine_name 'solidus_i18n'
7
+
8
+ config.autoload_paths += %W(#{config.root}/lib)
9
+
10
+ initializer 'solidus.i18n' do |app|
11
+ SolidusI18n::Engine.instance_eval do
12
+ pattern = pattern_from app.config.i18n.available_locales
13
+
14
+ add("config/locales/#{pattern}/*.{rb,yml}")
15
+ add("config/locales/#{pattern}.{rb,yml}")
16
+ end
17
+ end
18
+
19
+ initializer 'solidus.i18n.environment', before: :load_config_initializers do |app|
20
+ app.config.i18n.fallbacks = true
21
+ I18n.locale = app.config.i18n.default_locale if app.config.i18n.default_locale
22
+ SolidusI18n::Config = SolidusI18n::Configuration.new
23
+ end
24
+
25
+ def self.activate
26
+ Dir.glob(File.join(File.dirname(__FILE__), '../../app/**/*_decorator*.rb')) do |c|
27
+ Rails.configuration.cache_classes ? require(c) : load(c)
28
+ end
29
+ end
30
+
31
+ config.to_prepare(&method(:activate).to_proc)
32
+
33
+ protected
34
+
35
+ def self.add(pattern)
36
+ files = Dir[File.join(File.dirname(__FILE__), '../..', pattern)]
37
+ I18n.load_path.concat(files)
38
+ end
39
+
40
+ def self.pattern_from(args)
41
+ array = Array(args || [])
42
+ array.blank? ? '*' : "{#{array.join ','}}"
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,13 @@
1
+ module SolidusI18n
2
+ class Locale
3
+ class << self
4
+ def all
5
+ Dir["#{dir}/*.yml"].map { |f| File.basename(f, '.yml').to_sym }
6
+ end
7
+
8
+ def dir
9
+ File.join(File.dirname(__FILE__), '/../../config/locales')
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,56 @@
1
+ require 'active_support/core_ext'
2
+
3
+ module SolidusI18n
4
+ module Utils
5
+ # Retrieve comments, translation data in hash form
6
+ def read_file(filename, basename)
7
+ # Add error checking for failed file read?
8
+ (comments, data) = IO.read(filename).split(/#{basename}:\s*\n/)
9
+ return comments, create_hash(data)
10
+ end
11
+ module_function :read_file
12
+
13
+ # Creates hash of translation data
14
+ def create_hash(data)
15
+ words = {}
16
+ return words unless data
17
+ parent = []
18
+ previous_key = 'base'
19
+ data.split("\n").each do |w|
20
+ next if w.strip.blank? || w.strip[0] == '#'
21
+ (key, value) = w.split(':', 2)
22
+ value ||= ''
23
+ # Determine level of current key in comparison to parent array
24
+ shift = (key =~ /\w/) / 2 - parent.size
25
+ key = key.sub(/^\s+/, '')
26
+ # If key is child of previous key, add previous key as parent
27
+ parent << previous_key if shift > 0
28
+ # If key is not related to previous key, remove parent keys
29
+ (shift*-1).times { parent.pop } if shift < 0
30
+ # Track key in case next key is child of this key
31
+ previous_key = key
32
+ words[parent.join(':') + ':' + key] = value
33
+ end
34
+ words
35
+ end
36
+ module_function :create_hash
37
+
38
+ # Writes to file from translation data hash structure
39
+ def write_file(filename, basename, _comments, words, comment_values = true, _fallback_values = {})
40
+ File.open(filename, 'w') do |log|
41
+ log.puts(basename + ": \n")
42
+ words.sort.each do |k, v|
43
+ keys = k.split(':')
44
+ # Add indentation for children keys
45
+ (keys.size - 1).times do
46
+ keys[keys.size - 1] = ' ' + keys[keys.size - 1]
47
+ end
48
+ value = v.strip
49
+ value = ('#' + value) if comment_values && !value.blank?
50
+ log.puts "#{keys[keys.size - 1]}: #{value}\n"
51
+ end
52
+ end
53
+ end
54
+ module_function :write_file
55
+ end
56
+ end
@@ -0,0 +1,18 @@
1
+ module SolidusI18n
2
+ module_function
3
+
4
+ # Returns the version of the currently loaded SolidusI18n as a
5
+ # <tt>Gem::Version</tt>.
6
+ def version
7
+ Gem::Version.new VERSION::STRING
8
+ end
9
+
10
+ module VERSION
11
+ MAJOR = 1
12
+ MINOR = 0
13
+ TINY = 0
14
+ PRE = nil
15
+
16
+ STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
17
+ end
18
+ end
@@ -0,0 +1,8 @@
1
+ require 'sass/rails'
2
+ require 'rails-i18n'
3
+ require 'solidus_core'
4
+ require 'solidus_i18n/engine'
5
+ require 'solidus_i18n/version'
6
+ require 'solidus_i18n/utils'
7
+ require 'coffee_script'
8
+ require 'deface'
@@ -0,0 +1,43 @@
1
+ require 'fileutils'
2
+
3
+ namespace :solidus_i18n do
4
+ desc 'Upgrades to version without globalize.'
5
+ task upgrade: :environment do
6
+ files = %w(
7
+ add_translations_to_main_models
8
+ add_translations_to_product_permalink
9
+ add_translations_to_option_value
10
+ rename_activator_translations_to_promotion_translations
11
+ update_spree_product_translations
12
+ add_translations_to_product_properties
13
+ remove_null_constraints_from_spree_tables
14
+ add_deleted_at_to_translation_tables
15
+ add_translations_to_store
16
+ ).collect do |file_name|
17
+ Dir.glob Rails.root.join('db', 'migrate', "*_#{file_name}*.rb")
18
+ end.flatten
19
+
20
+ # Delete old migrations
21
+ FileUtils.rm files
22
+
23
+ # Install new migrations
24
+ Rake::Task['solidus_i18n:install:migrations'].invoke
25
+
26
+ puts <<-DESC
27
+ Upgraded migrations successfully.
28
+
29
+ Now please remove these lines from your vendor/assets folder:
30
+
31
+ From `vendor/assets/javascripts/spree/backend/all.js`
32
+
33
+ //= require spree/backend/spree_i18n
34
+
35
+ and from `vendor/assets/stylesheets/spree/backend/all.css`
36
+
37
+ *= require spree/backend/spree_i18n
38
+
39
+ Don't forget to run `rake db:migrate` now.
40
+
41
+ DESC
42
+ end
43
+ end
@@ -0,0 +1,46 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib/', __FILE__)
3
+ $LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib)
4
+
5
+ require 'solidus_i18n/version'
6
+
7
+ Gem::Specification.new do |s|
8
+ s.platform = Gem::Platform::RUBY
9
+ s.name = 'solidus_i18n'
10
+ s.version = SolidusI18n.version
11
+ s.summary = 'Provides locale information for use in Solidus.'
12
+ s.description = s.summary
13
+
14
+ s.author = 'Thomas von Deyen'
15
+ s.email = 'tvd@magiclabs.de'
16
+ s.homepage = 'https://solidus.io'
17
+ s.license = 'BSD-3'
18
+
19
+ s.files = `git ls-files`.split("\n")
20
+ s.test_files = `git ls-files -- spec/*`.split("\n")
21
+ s.require_path = 'lib'
22
+ s.requirements << 'none'
23
+
24
+ s.has_rdoc = false
25
+
26
+ s.add_runtime_dependency 'i18n_data', '~> 0.7.0'
27
+ s.add_runtime_dependency 'rails-i18n', '~> 4.0.1'
28
+ s.add_runtime_dependency 'kaminari-i18n', '~> 0.3.2'
29
+ s.add_runtime_dependency 'routing-filter', '~> 0.5.0'
30
+ s.add_runtime_dependency 'solidus_core', '~> 1.0'
31
+ s.add_runtime_dependency 'deface', '~> 1.0'
32
+
33
+ s.add_development_dependency 'byebug'
34
+ s.add_development_dependency 'capybara', '~> 2.4.4'
35
+ s.add_development_dependency 'coffee-rails', '~> 4.0.0'
36
+ s.add_development_dependency 'database_cleaner', '~> 1.3'
37
+ s.add_development_dependency 'factory_girl', '~> 4.5'
38
+ s.add_development_dependency 'ffaker', '>= 1.25.0'
39
+ s.add_development_dependency 'poltergeist', '~> 1.5'
40
+ s.add_development_dependency 'pry-rails', '>= 0.3.0'
41
+ s.add_development_dependency 'rubocop', '>= 0.24.1'
42
+ s.add_development_dependency 'rspec-rails', '~> 3.1'
43
+ s.add_development_dependency 'sass-rails', '~> 5.0.0'
44
+ s.add_development_dependency 'simplecov', '~> 0.9'
45
+ s.add_development_dependency 'guard-rspec', '>= 4.2.0'
46
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Spree::HomeController, type: :controller do
4
+ routes { Spree::Core::Engine.routes }
5
+
6
+ before do
7
+ reset_spree_preferences
8
+ SolidusI18n::Config.available_locales = [:en, :es]
9
+ end
10
+
11
+ context 'tries not supported fr locale' do
12
+ it 'falls back do default locale' do
13
+ get :index, locale: 'fr'
14
+ expect(I18n.locale).to eq :en
15
+ end
16
+ end
17
+
18
+ context 'tries supported es locale' do
19
+ it 'takes this locale' do
20
+ get :index, locale: 'es'
21
+ expect(I18n.locale).to eq :es
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.feature 'Translations', :js do
4
+ stub_authorization!
5
+
6
+ given!(:store) { create(:store) }
7
+
8
+ background do
9
+ reset_spree_preferences
10
+ end
11
+
12
+ context 'localization settings' do
13
+ given(:language) { Spree.t(:this_file_language, scope: 'i18n', locale: 'de') }
14
+ given(:french) { Spree.t(:this_file_language, scope: 'i18n', locale: 'fr') }
15
+
16
+ background do
17
+ SolidusI18n::Config.available_locales = []
18
+ visit spree.edit_admin_general_settings_path
19
+ end
20
+
21
+ scenario 'adds german to available locales' do
22
+ targetted_select2_search(language, from: '#s2id_available_locales_')
23
+ click_on 'Update'
24
+ expect(SolidusI18n::Config.available_locales).to include(:de)
25
+ end
26
+
27
+ scenario 'adds french to available locales' do
28
+ targetted_select2_search(french, from: '#s2id_available_locales_')
29
+ click_on 'Update'
30
+ expect(SolidusI18n::Config.available_locales).to include(:fr)
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,17 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ RSpec.describe 'Russian errors translations' do
5
+ def translation(count)
6
+ Spree.t(:errors_prohibited_this_record_from_being_saved, count: count)
7
+ end
8
+
9
+ context 'when current locale is Russian' do
10
+ it 'translation is available' do
11
+ I18n.locale = :ru
12
+ expect(translation(1)).to eq 'Одна ошибка не позволяет сохранить запись в базе'
13
+ expect(translation(3)).to eq '3 ошибки не позволяют сохранить запись в базе'
14
+ expect(translation(10)).to eq '10 ошибок не позволяют сохранить запись в базе'
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ RSpec.describe 'Translation' do
5
+ def translation
6
+ I18n.t('activerecord.attributes.spree/address.zipcode')
7
+ end
8
+
9
+ context 'when current locale is en' do
10
+ it 'translation is available' do
11
+ I18n.locale = :en
12
+ expect(translation).to eq 'Zip Code'
13
+ end
14
+ end
15
+
16
+ # German is chosen as an example of language whose translations are found in a file.
17
+ context 'when current locale is German' do
18
+ it 'translation is available' do
19
+ I18n.locale = :de
20
+ expect(translation).to eq 'PLZ'
21
+ end
22
+ end
23
+
24
+ # Chilean spanish is chosen
25
+ context 'when current locale is Chilean Spanish' do
26
+ it 'translation is available' do
27
+ I18n.locale = :'es-CL'
28
+ expect(translation).to eq 'Código Postal'
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,28 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ RSpec.feature 'Translations', :js do
5
+ given(:language) { Spree.t(:this_file_language, scope: 'i18n', locale: 'pt-BR') }
6
+
7
+ background do
8
+ reset_spree_preferences
9
+ SolidusI18n::Config.available_locales = [:en, :'pt-BR']
10
+ end
11
+
12
+ context 'page' do
13
+ context 'switches locale from the dropdown' do
14
+ before do
15
+ visit spree.root_path
16
+ select(language, from: Spree.t(:language, scope: 'i18n'))
17
+ end
18
+
19
+ scenario 'selected translation is applied' do
20
+ expect(page).to have_content(/#{Spree.t(:home, locale: 'pt-BR')}/i)
21
+ end
22
+
23
+ scenario 'JS cart link is translated' do
24
+ expect(page).to have_content(/#{Spree.t(:cart, locale: 'pt-BR')}/i)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,31 @@
1
+ require 'simplecov'
2
+ SimpleCov.start 'rails'
3
+
4
+ ENV['RAILS_ENV'] ||= 'test'
5
+
6
+ begin
7
+ require File.expand_path('../dummy/config/environment', __FILE__)
8
+ rescue LoadError
9
+ puts 'Could not load dummy application. Please ensure you have run `bundle exec rake test_app`'
10
+ exit
11
+ end
12
+
13
+ require 'pry'
14
+ require 'ffaker'
15
+ require 'rspec/rails'
16
+
17
+ RSpec.configure do |config|
18
+ config.fail_fast = false
19
+ config.filter_run focus: true
20
+ config.infer_spec_type_from_file_location!
21
+ config.mock_with :rspec
22
+ config.raise_errors_for_deprecations!
23
+ config.run_all_when_everything_filtered = true
24
+ config.use_transactional_fixtures = false
25
+
26
+ config.expect_with :rspec do |expectations|
27
+ expectations.syntax = :expect
28
+ end
29
+ end
30
+
31
+ Dir[File.join(File.dirname(__FILE__), '/support/**/*.rb')].each { |file| require file }
@@ -0,0 +1,11 @@
1
+ require 'capybara/rspec'
2
+ require 'capybara/rails'
3
+ require 'capybara/poltergeist'
4
+
5
+ RSpec.configure do
6
+ Capybara.javascript_driver = :poltergeist
7
+
8
+ Capybara.register_driver(:poltergeist) do |app|
9
+ Capybara::Poltergeist::Driver.new app, timeout: 90
10
+ end
11
+ end
@@ -0,0 +1,23 @@
1
+ require 'database_cleaner'
2
+
3
+ RSpec.configure do |config|
4
+ config.before(:suite) do
5
+ DatabaseCleaner.clean_with :truncation
6
+ end
7
+
8
+ config.before do
9
+ DatabaseCleaner.strategy = :transaction
10
+ end
11
+
12
+ config.before(:each, :js) do
13
+ DatabaseCleaner.strategy = :truncation
14
+ end
15
+
16
+ config.before do
17
+ DatabaseCleaner.start
18
+ end
19
+
20
+ config.after do
21
+ DatabaseCleaner.clean
22
+ end
23
+ end
@@ -0,0 +1,5 @@
1
+ require 'factory_girl'
2
+
3
+ RSpec.configure do |config|
4
+ config.include FactoryGirl::Syntax::Methods
5
+ end
@@ -0,0 +1,5 @@
1
+ RSpec.configure do |config|
2
+ config.before do
3
+ I18n.locale = I18n.default_locale
4
+ end
5
+ end
@@ -0,0 +1,12 @@
1
+ require 'spree/testing_support/factories'
2
+ require 'spree/testing_support/preferences'
3
+ require 'spree/testing_support/url_helpers'
4
+ require 'spree/testing_support/capybara_ext'
5
+ require 'spree/testing_support/controller_requests'
6
+ require 'spree/testing_support/authorization_helpers'
7
+
8
+ RSpec.configure do |config|
9
+ config.include Spree::TestingSupport::UrlHelpers
10
+ config.include Spree::TestingSupport::Preferences
11
+ config.include Spree::TestingSupport::ControllerRequests, type: :controller
12
+ end