diff --git a/.circleci/config.yml b/.circleci/config.yml
index 12bb10ef..e6ec0457 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -1,6 +1,9 @@
version: 2.1
orbs:
+ # Required for feature specs.
+ browser-tools: circleci/browser-tools@1.1
+
# Always take the latest version of the orb, this allows us to
# run specs against Solidus supported versions only without the need
# to change this configuration every time a Solidus version is released
@@ -8,20 +11,45 @@ orbs:
solidusio_extensions: solidusio/extensions@volatile
jobs:
- run-specs-with-postgres:
- executor: solidusio_extensions/postgres
+ run-specs:
+ parameters:
+ solidus:
+ type: string
+ default: main
+ db:
+ type: string
+ default: "postgres"
+ ruby:
+ type: string
+ default: "3.2"
+ executor:
+ name: solidusio_extensions/<< parameters.db >>
+ ruby_version: << parameters.ruby >>
steps:
- - solidusio_extensions/run-tests
- run-specs-with-mysql:
- executor: solidusio_extensions/mysql
+ - checkout
+ - browser-tools/install-chrome
+ - solidusio_extensions/run-tests-solidus-<< parameters.solidus >>
+
+ lint-code:
+ executor:
+ name: solidusio_extensions/sqlite
+ ruby_version: "3.2"
steps:
- - solidusio_extensions/run-tests
+ - solidusio_extensions/lint-code
workflows:
"Run specs on supported Solidus versions":
jobs:
- - run-specs-with-postgres
- - run-specs-with-mysql
+ - run-specs:
+ name: &name "run-specs-solidus-<< matrix.solidus >>-ruby-<< matrix.ruby >>-db-<< matrix.db >>"
+ matrix:
+ parameters: { solidus: ["main"], ruby: ["3.2"], db: ["postgres"] }
+ - run-specs:
+ name: *name
+ matrix:
+ parameters: { solidus: ["current"], ruby: ["3.1"], db: ["mysql"] }
+ - lint-code
+
"Weekly run specs against master":
triggers:
- schedule:
@@ -31,5 +59,11 @@ workflows:
only:
- master
jobs:
- - run-specs-with-postgres
- - run-specs-with-mysql
+ - run-specs:
+ name: *name
+ matrix:
+ parameters: { solidus: ["main"], ruby: ["3.2"], db: ["postgres"] }
+ - run-specs:
+ name: *name
+ matrix:
+ parameters: { solidus: ["current"], ruby: ["3.1"], db: ["mysql"] }
diff --git a/.github/stale.yml b/.github/stale.yml
index d9f65632..0d0b1c99 100644
--- a/.github/stale.yml
+++ b/.github/stale.yml
@@ -1,17 +1 @@
-# Number of days of inactivity before an issue becomes stale
-daysUntilStale: 60
-# Number of days of inactivity before a stale issue is closed
-daysUntilClose: 7
-# Issues with these labels will never be considered stale
-exemptLabels:
- - pinned
- - security
-# Label to use when marking an issue as stale
-staleLabel: wontfix
-# Comment to post when marking an issue as stale. Set to `false` to disable
-markComment: >
- This issue has been automatically marked as stale because it has not had
- recent activity. It will be closed if no further activity occurs. Thank you
- for your contributions.
-# Comment to post when closing a stale issue. Set to `false` to disable
-closeComment: false
\ No newline at end of file
+_extends: .github
diff --git a/.github_changelog_generator b/.github_changelog_generator
new file mode 100644
index 00000000..eac09621
--- /dev/null
+++ b/.github_changelog_generator
@@ -0,0 +1,2 @@
+issues=false
+exclude-labels=infrastructure
diff --git a/.gitignore b/.gitignore
index bcd4aea4..1ba20966 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,9 +8,14 @@
.sass-cache
coverage
Gemfile.lock
+Gemfile-local
tmp
nbproject
pkg
*.swp
spec/dummy
spec/examples.txt
+/sandbox
+.rvmrc
+.ruby-version
+.ruby-gemset
diff --git a/.rubocop.yml b/.rubocop.yml
index 81a15d54..ed101ebf 100644
--- a/.rubocop.yml
+++ b/.rubocop.yml
@@ -1,6 +1,7 @@
+inherit_from: .rubocop_todo.yml
+
require:
- solidus_dev_support/rubocop
-Rails/SkipsModelValidations:
- Exclude:
- - db/migrate/**/*
+AllCops:
+ NewCops: disable
diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml
index 63dd4a95..b47d97e1 100644
--- a/.rubocop_todo.yml
+++ b/.rubocop_todo.yml
@@ -1,33 +1,44 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
-# on 2019-11-14 12:59:11 +0100 using RuboCop version 0.76.0.
+# on 2023-05-23 11:06:18 UTC using RuboCop version 1.51.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.
# Offense count: 1
-Lint/AmbiguousBlockAssociation:
+Capybara/VisibilityMatcher:
Exclude:
- - 'spec/features/admin/translations_spec.rb'
+ - 'spec/features/admin/products_spec.rb'
# Offense count: 1
-Lint/BooleanSymbol:
+# Configuration parameters: Severity, Include.
+# Include: **/*.gemspec
+Gemspec/RequiredRubyVersion:
Exclude:
- - 'db/migrate/20191108162345_add_locale_to_friendly_id_slugs.rb'
+ - 'solidus_globalize.gemspec'
-# Offense count: 3
-# Cop supports --auto-correct.
-# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
-# URISchemes: http, https
-Metrics/LineLength:
- Max: 196
+# Offense count: 1
+# This cop supports safe autocorrection (--autocorrect).
+# Configuration parameters: AllowForAlignment, AllowBeforeTrailingComments, ForceEqualSignAlignment.
+Layout/ExtraSpacing:
+ Exclude:
+ - 'app/models/concerns/solidus_globalize/translatable.rb'
+
+# Offense count: 1
+# This cop supports safe autocorrection (--autocorrect).
+# Configuration parameters: AllowForAlignment, EnforcedStyleForExponentOperator.
+# SupportedStylesForExponentOperator: space, no_space
+Layout/SpaceAroundOperators:
+ Exclude:
+ - 'app/models/concerns/solidus_globalize/translatable.rb'
-# Offense count: 18
-# Configuration parameters: Prefixes.
+# Offense count: 20
+# Configuration parameters: Prefixes, AllowedPatterns.
# Prefixes: when, with, without
RSpec/ContextWording:
Exclude:
+ - 'spec/controllers/spree/admin/translations_controller_spec.rb'
- 'spec/controllers/spree/products_controller_spec.rb'
- 'spec/features/admin/products_spec.rb'
- 'spec/features/admin/translations_spec.rb'
@@ -35,12 +46,15 @@ RSpec/ContextWording:
- 'spec/models/product_spec.rb'
- 'spec/support/shared_contexts/translatable_context.rb'
-# Offense count: 3
-RSpec/DescribeClass:
+# Offense count: 4
+# Configuration parameters: Include, CustomTransform, IgnoreMethods, SpecSuffixOnly.
+# Include: **/*_spec*rb*, **/spec/**/*
+RSpec/FilePath:
Exclude:
- - 'spec/features/admin/products_spec.rb'
- - 'spec/features/admin/translations_spec.rb'
- - 'spec/features/translations_spec.rb'
+ - 'spec/models/product_property_spec.rb'
+ - 'spec/models/product_spec.rb'
+ - 'spec/models/shipping_method_spec.rb'
+ - 'spec/models/taxon_spec.rb'
# Offense count: 9
RSpec/LetSetup:
@@ -50,13 +64,18 @@ RSpec/LetSetup:
- 'spec/features/translations_spec.rb'
- 'spec/models/taxon_spec.rb'
-# Offense count: 9
-# Configuration parameters: AggregateFailuresByDefault.
+# Offense count: 1
+RSpec/MultipleDescribes:
+ Exclude:
+ - 'spec/models/translated_models_spec.rb'
+
+# Offense count: 10
RSpec/MultipleExpectations:
- Max: 3
+ Max: 4
# Offense count: 2
-# Configuration parameters: IgnoreSharedExamples.
+# Configuration parameters: EnforcedStyle, IgnoreSharedExamples.
+# SupportedStyles: always, named_only
RSpec/NamedSubject:
Exclude:
- 'spec/models/product_property_spec.rb'
@@ -64,28 +83,14 @@ RSpec/NamedSubject:
# Offense count: 1
# Configuration parameters: Include.
-# Include: app/**/*.rb, config/**/*.rb, db/**/*.rb, lib/**/*.rb
-Rails/Output:
+# Include: db/migrate/*.rb
+Rails/NotNullColumn:
Exclude:
- - 'lib/generators/solidus_globalize/install/install_generator.rb'
-
-# Offense count: 1
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle.
-# SupportedStyles: always, never
-Style/FrozenStringLiteralComment:
- Exclude:
- - 'spec/support/shared_contexts/translatable_context.rb'
+ - 'db/migrate/20191108162345_add_locale_to_friendly_id_slugs.rb'
-# Offense count: 8
-# Configuration parameters: MinBodyLength.
-Style/GuardClause:
- Exclude:
- - 'db/migrate/20130419041407_add_translations_to_main_models.rb'
- - 'db/migrate/20130518224827_add_translations_to_product_permalink.rb'
- - 'db/migrate/20131009091000_add_translations_to_option_value.rb'
- - 'db/migrate/20140206202524_rename_activator_translations_to_promotion_translations.rb'
- - 'db/migrate/20140219130603_update_spree_product_translations.rb'
- - 'db/migrate/20141112121313_add_translations_to_product_properties.rb'
- - 'db/migrate/20150224152415_add_deleted_at_to_translation_tables.rb'
- - 'db/migrate/20150323210949_add_translations_to_store.rb'
+# Offense count: 2
+# This cop supports safe autocorrection (--autocorrect).
+# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
+# URISchemes: http, https
+Layout/LineLength:
+ Max: 128
diff --git a/CHANGELOG.md b/CHANGELOG.md
new file mode 100644
index 00000000..825c32f0
--- /dev/null
+++ b/CHANGELOG.md
@@ -0,0 +1 @@
+# Changelog
diff --git a/Gemfile b/Gemfile
index 6d8428c1..5f7f2794 100644
--- a/Gemfile
+++ b/Gemfile
@@ -3,9 +3,18 @@
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
-branch = ENV.fetch('SOLIDUS_BRANCH', 'master')
+branch = ENV.fetch('SOLIDUS_BRANCH', 'main')
gem 'solidus', github: 'solidusio/solidus', branch: branch
+# The solidus_frontend gem has been pulled out since v3.2
+if branch >= 'v3.2'
+ gem 'solidus_frontend'
+elsif branch == 'main'
+ gem 'solidus_frontend', github: 'solidusio/solidus_frontend'
+else
+ gem 'solidus_frontend', github: 'solidusio/solidus', branch: branch
+end
+
# Needed to help Bundler figure out how to resolve dependencies,
# otherwise it takes forever to resolve them.
# See https://github.com/bundler/bundler/issues/6677
@@ -14,7 +23,7 @@ gem 'rails', '>0.a'
# Provides basic authentication functionality for testing parts of your engine
# gem 'solidus_auth_devise'
-gem 'routing-filter', github: "svenfuchs/routing-filter", branch: "master"
+gem 'friendly_id-globalize', github: 'norman/friendly_id-globalize', branch: "master"
case ENV['DB']
when 'mysql'
diff --git a/README.md b/README.md
index 3ef0a035..54e32aea 100644
--- a/README.md
+++ b/README.md
@@ -24,6 +24,14 @@ Add the following to your `Gemfile`:
gem 'solidus_globalize', github: 'solidusio-contrib/solidus_globalize'
```
+For Ruby 3.x you have to force the usage of the friendly_id-globalize master version:
+
+```ruby
+gem 'friendly_id-globalize', github: 'norman/friendly_id-globalize', branch: "master"
+gem 'solidus_globalize', github: 'solidusio-contrib/solidus_globalize'
+```
+
+
Run `bundle install`
You can use the generator to install migrations and append solidus_globalize assets to
@@ -57,6 +65,16 @@ into an initializer:
SolidusGlobalize::Config.supported_locales = [:en, :'pt-BR']
```
+Additionally, the translatable fields on individual models can be adjusted with configuration:
+
+```ruby
+SolidusGlobalize::Config[:translatable_fields].merge!(
+ {
+ 'Spree::OptionValue' => [:presentation]
+ }
+)
+```
+
**PS 1.** The languages you add to this configuration need to be supported by
your store. This means that you need to have a transations file for them
into `/config/locales/` (eg. `/config/locales/pt-BR.yml`).
diff --git a/app/assets/javascripts/spree/backend/solidus_globalize.js b/app/assets/javascripts/spree/backend/solidus_globalize.js
index d5d841c4..bf8a94eb 100644
--- a/app/assets/javascripts/spree/backend/solidus_globalize.js
+++ b/app/assets/javascripts/spree/backend/solidus_globalize.js
@@ -1,2 +1,101 @@
-//= require spree/backend
-//= require_tree .
+(function() {
+ var root;
+
+ root = typeof exports !== "undefined" && exports !== null ? exports : this;
+
+ root.taxon_tree_menu = function(obj, context) {
+ var admin_base_url, edit_url, id, translation_base_path, translation_url;
+ id = obj.attr("id");
+ admin_base_url = Spree.path_for("admin/taxonomies/" + obj.data('taxonomy-id') + "/taxons");
+ edit_url = admin_base_url.clone();
+ edit_url.setPath(edit_url.path() + '/' + id + "/edit");
+ translation_url = admin_base_url.clone();
+ translation_base_path = admin_base_url.path().replace(/taxons/, "translations");
+ translation_base_path = translation_base_path.replace(/taxonomies/, "taxons");
+ translation_base_path = translation_base_path.replace(/\d+/, id);
+ translation_url.setPath(translation_base_path);
+ return {
+ create: {
+ label: " " + Spree.translations.add,
+ action: function(obj) {
+ return context.create(obj);
+ }
+ },
+ rename: {
+ label: " " + Spree.translations.rename,
+ action: function(obj) {
+ return context.rename(obj);
+ }
+ },
+ remove: {
+ label: " " + Spree.translations.remove,
+ action: function(obj) {
+ return context.remove(obj);
+ }
+ },
+ edit: {
+ separator_before: true,
+ label: " " + Spree.translations.edit,
+ action: function(obj) {
+ return window.location = edit_url.toString();
+ }
+ },
+ translate: {
+ separator_before: true,
+ label: " " + Spree.translations.translations,
+ action: function(obj) {
+ return window.location = translation_url.toString();
+ }
+ }
+ };
+ };
+
+}).call(this);
+
+(function() {
+ var display_locale_fields;
+
+ display_locale_fields = function() {
+ var attr, display, locale, show, value;
+ attr = $('#attr_list a.active').data('attr');
+ locale = $('#locale').val();
+ show = $("select[name='show-only']").val();
+ $('#attr_fields .panel').hide();
+ value = $('#attr_fields .panel.' + attr + '.' + locale + ' :input').val().replace(/^\s+|\s+$/g, "");
+ if (show === 'incomplete') {
+ display = value === '';
+ } else if (show === 'complete') {
+ display = value !== '';
+ } else {
+ display = true;
+ }
+ if (display) {
+ $('#attr_fields .panel.' + attr + '.' + locale).show();
+ }
+ if ($('#attr_fields .panel:visible').length === 0 && show !== 'all') {
+ return $('#attr_fields .no-translations').show();
+ }
+ };
+
+ $(function() {
+ $('#attr_list a').click(function() {
+ $('#attr_list a').removeClass('active');
+ $(this).addClass('active');
+ display_locale_fields();
+ return false;
+ });
+ $('#locale, #supported_locales_').select2({
+ placeholder: Spree.translations['please_choose_language']
+ });
+ $('#locale').change(function() {
+ return display_locale_fields();
+ });
+ $("select[name='show-only']").change(function() {
+ return display_locale_fields();
+ });
+ if ($('#attr_list').is('*')) {
+ return display_locale_fields();
+ }
+ });
+
+}).call(this);
diff --git a/app/assets/javascripts/spree/backend/taxon_tree_menu.js.coffee b/app/assets/javascripts/spree/backend/taxon_tree_menu.js.coffee
deleted file mode 100644
index 3a64992f..00000000
--- a/app/assets/javascripts/spree/backend/taxon_tree_menu.js.coffee
+++ /dev/null
@@ -1,35 +0,0 @@
-root = exports ? this
-
-root.taxon_tree_menu = (obj, context) ->
-
- id = obj.attr("id")
-
- admin_base_url = Spree.url(Spree.routes.admin_taxonomy_taxons_path)
-
- edit_url = admin_base_url.clone()
- edit_url.setPath(edit_url.path() + '/' + id + "/edit");
-
- translation_url = admin_base_url.clone()
-
- translation_base_path = admin_base_url.path().replace(/taxons/, "translations")
- translation_base_path = translation_base_path.replace(/taxonomies/, "taxons")
- translation_base_path = translation_base_path.replace(/\d+/, id)
- translation_url.setPath(translation_base_path);
-
- create:
- label: " " + Spree.translations.add,
- action: (obj) -> context.create(obj)
- rename:
- label: " " + Spree.translations.rename,
- action: (obj) -> context.rename(obj)
- remove:
- label: " " + Spree.translations.remove,
- action: (obj) -> context.remove(obj)
- edit:
- separator_before: true,
- label: " " + Spree.translations.edit,
- action: (obj) -> window.location = edit_url.toString()
- translate:
- separator_before: true,
- label: " " + Spree.translations.translations,
- action: (obj) -> window.location = translation_url.toString()
diff --git a/app/assets/javascripts/spree/backend/translations.js.coffee b/app/assets/javascripts/spree/backend/translations.js.coffee
deleted file mode 100644
index 73dcf2aa..00000000
--- a/app/assets/javascripts/spree/backend/translations.js.coffee
+++ /dev/null
@@ -1,38 +0,0 @@
-display_locale_fields = () ->
- attr = $('#attr_list a.active').data('attr')
- locale = $('#locale').val()
- show = $("select[name='show-only']").val()
-
- $('#attr_fields .panel').hide()
-
- value = $('#attr_fields .panel.' + attr + '.' + locale + ' :input').val().replace /^\s+|\s+$/g, ""
- if show == 'incomplete'
- display = value == ''
- else if show == 'complete'
- display = value != ''
- else
- display = true
- if display
- $('#attr_fields .panel.' + attr + '.' + locale).show()
-
- if $('#attr_fields .panel:visible').length == 0 and show != 'all'
- $('#attr_fields .no-translations').show()
-
-$ ->
- $('#attr_list a').click ->
- $('#attr_list a').removeClass('active')
- $(this).addClass('active')
-
- display_locale_fields()
- false
-
- $('#locale, #supported_locales_').select2({placeholder: Spree.translations['please_choose_language']})
-
- $('#locale').change ->
- display_locale_fields()
-
- $("select[name='show-only']").change ->
- display_locale_fields()
-
- if $('#attr_list').is('*')
- display_locale_fields()
diff --git a/app/decorators/models/solidus_globalize/spree/option_type_decorator.rb b/app/decorators/models/solidus_globalize/spree/option_type_decorator.rb
index dcf82d30..60282788 100644
--- a/app/decorators/models/solidus_globalize/spree/option_type_decorator.rb
+++ b/app/decorators/models/solidus_globalize/spree/option_type_decorator.rb
@@ -4,8 +4,9 @@ module SolidusGlobalize
module Spree
module OptionTypeDecorator
def self.prepended(base)
+ translatable_fields = ::SolidusGlobalize::Config.translatable_fields[base.to_s]
base.class_eval do
- translates :name, :presentation, fallbacks_for_empty_translations: true
+ translates(*translatable_fields, fallbacks_for_empty_translations: true)
include SolidusGlobalize::Translatable
end
end
diff --git a/app/decorators/models/solidus_globalize/spree/option_value_decorator.rb b/app/decorators/models/solidus_globalize/spree/option_value_decorator.rb
index 1d481c4a..96d34712 100644
--- a/app/decorators/models/solidus_globalize/spree/option_value_decorator.rb
+++ b/app/decorators/models/solidus_globalize/spree/option_value_decorator.rb
@@ -4,8 +4,9 @@ module SolidusGlobalize
module Spree
module OptionValueDecorator
def self.prepended(base)
+ translatable_fields = ::SolidusGlobalize::Config.translatable_fields[base.to_s]
base.class_eval do
- translates :name, :presentation, fallbacks_for_empty_translations: true
+ translates(*translatable_fields, fallbacks_for_empty_translations: true)
include SolidusGlobalize::Translatable
end
end
diff --git a/app/decorators/models/solidus_globalize/spree/product_decorator.rb b/app/decorators/models/solidus_globalize/spree/product_decorator.rb
index 6a6cdc65..ecdf9cc5 100644
--- a/app/decorators/models/solidus_globalize/spree/product_decorator.rb
+++ b/app/decorators/models/solidus_globalize/spree/product_decorator.rb
@@ -4,16 +4,13 @@ module SolidusGlobalize
module Spree
module ProductDecorator
def self.prepended(base)
+ translatable_fields = ::SolidusGlobalize::Config.translatable_fields[base.to_s]
base.class_eval do
- translates :name,
- :description,
- :meta_description,
- :meta_keywords,
- :meta_title,
- :slug,
- fallbacks_for_empty_translations: true
-
- friendly_id :slug_candidates, use: [:history, :globalize]
+ translates(*translatable_fields, fallbacks_for_empty_translations: true)
+
+ if translatable_fields.include?(:slug)
+ friendly_id :slug_candidates, use: [:history, :globalize]
+ end
include SolidusGlobalize::Translatable
diff --git a/app/decorators/models/solidus_globalize/spree/product_property_decorator.rb b/app/decorators/models/solidus_globalize/spree/product_property_decorator.rb
index 23ac2830..806cc10d 100644
--- a/app/decorators/models/solidus_globalize/spree/product_property_decorator.rb
+++ b/app/decorators/models/solidus_globalize/spree/product_property_decorator.rb
@@ -4,8 +4,9 @@ module SolidusGlobalize
module Spree
module ProductPropertyDecorator
def self.prepended(base)
+ translatable_fields = ::SolidusGlobalize::Config.translatable_fields[base.to_s]
base.class_eval do
- translates :value, fallbacks_for_empty_translations: true
+ translates(*translatable_fields, fallbacks_for_empty_translations: true)
include SolidusGlobalize::Translatable
end
end
diff --git a/app/decorators/models/solidus_globalize/spree/promotion_decorator.rb b/app/decorators/models/solidus_globalize/spree/promotion_decorator.rb
index 635f75e2..f87ec7c5 100644
--- a/app/decorators/models/solidus_globalize/spree/promotion_decorator.rb
+++ b/app/decorators/models/solidus_globalize/spree/promotion_decorator.rb
@@ -4,8 +4,9 @@ module SolidusGlobalize
module Spree
module PromotionDecorator
def self.prepended(base)
+ translatable_fields = ::SolidusGlobalize::Config.translatable_fields[base.to_s]
base.class_eval do
- translates :name, :description, fallbacks_for_empty_translations: true
+ translates(*translatable_fields, fallbacks_for_empty_translations: true)
include SolidusGlobalize::Translatable
end
end
diff --git a/app/decorators/models/solidus_globalize/spree/property_decorator.rb b/app/decorators/models/solidus_globalize/spree/property_decorator.rb
index 42dea7c6..b51ac50b 100644
--- a/app/decorators/models/solidus_globalize/spree/property_decorator.rb
+++ b/app/decorators/models/solidus_globalize/spree/property_decorator.rb
@@ -4,8 +4,9 @@ module SolidusGlobalize
module Spree
module PropertyDecorator
def self.prepended(base)
+ translatable_fields = ::SolidusGlobalize::Config.translatable_fields[base.to_s]
base.class_eval do
- translates :name, :presentation, fallbacks_for_empty_translations: true
+ translates(*translatable_fields, fallbacks_for_empty_translations: true)
include SolidusGlobalize::Translatable
end
end
diff --git a/app/decorators/models/solidus_globalize/spree/shipping_method_decorator.rb b/app/decorators/models/solidus_globalize/spree/shipping_method_decorator.rb
index b5724159..d87d3bfc 100644
--- a/app/decorators/models/solidus_globalize/spree/shipping_method_decorator.rb
+++ b/app/decorators/models/solidus_globalize/spree/shipping_method_decorator.rb
@@ -4,8 +4,9 @@ module SolidusGlobalize
module Spree
module ShippingMethodDecorator
def self.prepended(base)
+ translatable_fields = ::SolidusGlobalize::Config.translatable_fields[base.to_s]
base.class_eval do
- translates :name, fallbacks_for_empty_translations: true
+ translates(*translatable_fields, fallbacks_for_empty_translations: true)
include SolidusGlobalize::Translatable
end
end
diff --git a/app/decorators/models/solidus_globalize/spree/store_decorator.rb b/app/decorators/models/solidus_globalize/spree/store_decorator.rb
index fd7e8e2d..b661bc5e 100644
--- a/app/decorators/models/solidus_globalize/spree/store_decorator.rb
+++ b/app/decorators/models/solidus_globalize/spree/store_decorator.rb
@@ -4,12 +4,9 @@ module SolidusGlobalize
module Spree
module StoreDecorator
def self.prepended(base)
+ translatable_fields = ::SolidusGlobalize::Config.translatable_fields[base.to_s]
base.class_eval do
- translates :name,
- :meta_description,
- :meta_keywords,
- :seo_title,
- fallbacks_for_empty_translations: true
+ translates(*translatable_fields, fallbacks_for_empty_translations: true)
include SolidusGlobalize::Translatable
end
end
diff --git a/app/decorators/models/solidus_globalize/spree/taxon_decorator.rb b/app/decorators/models/solidus_globalize/spree/taxon_decorator.rb
index 5bda292f..c9a256ab 100644
--- a/app/decorators/models/solidus_globalize/spree/taxon_decorator.rb
+++ b/app/decorators/models/solidus_globalize/spree/taxon_decorator.rb
@@ -4,14 +4,9 @@ module SolidusGlobalize
module Spree
module TaxonDecorator
def self.prepended(base)
+ translatable_fields = ::SolidusGlobalize::Config.translatable_fields[base.to_s]
base.class_eval do
- translates :name,
- :description,
- :meta_title,
- :meta_description,
- :meta_keywords,
- :permalink,
- fallbacks_for_empty_translations: true
+ translates(*translatable_fields, fallbacks_for_empty_translations: true)
include SolidusGlobalize::Translatable
end
end
diff --git a/app/decorators/models/solidus_globalize/spree/taxonomy_decorator.rb b/app/decorators/models/solidus_globalize/spree/taxonomy_decorator.rb
index a11e696b..c9edb123 100644
--- a/app/decorators/models/solidus_globalize/spree/taxonomy_decorator.rb
+++ b/app/decorators/models/solidus_globalize/spree/taxonomy_decorator.rb
@@ -4,8 +4,9 @@ module SolidusGlobalize
module Spree
module TaxonomyDecorator
def self.prepended(base)
+ translatable_fields = ::SolidusGlobalize::Config.translatable_fields[base.to_s]
base.class_eval do
- translates :name, fallbacks_for_empty_translations: true
+ translates(*translatable_fields, fallbacks_for_empty_translations: true)
include SolidusGlobalize::Translatable
end
end
diff --git a/app/models/concerns/solidus_globalize/translatable.rb b/app/models/concerns/solidus_globalize/translatable.rb
index 9a831d9f..0aaadc18 100644
--- a/app/models/concerns/solidus_globalize/translatable.rb
+++ b/app/models/concerns/solidus_globalize/translatable.rb
@@ -6,8 +6,25 @@ module Translatable
included do |klass|
accepts_nested_attributes_for :translations
- klass.whitelisted_ransackable_associations ||= []
- klass.whitelisted_ransackable_associations |= ['translations']
+ if ::Spree.solidus_gem_version < Gem::Version.new('3.3')
+ klass.whitelisted_ransackable_associations ||= []
+ klass.whitelisted_ransackable_associations |= ['translations']
+ else
+ klass.allowed_ransackable_associations ||= []
+ klass.allowed_ransackable_associations |= ['translations']
+ end
+
+ klass.const_set("TranslationRansackable", Module.new).module_eval do
+ def ransackable_attributes(*_args)
+ authorizable_ransackable_attributes
+ end
+
+ def ransackable_associations(*_args)
+ authorizable_ransackable_associations
+ end
+
+ "#{klass}::Translation".constantize.singleton_class.prepend(self)
+ end
end
class_methods do
diff --git a/app/overrides/spree/admin/products/index/replace_name_field_with_translations_name.html.erb.deface b/app/overrides/spree/admin/products/index/replace_name_field_with_translations_name.html.erb.deface
new file mode 100644
index 00000000..04fe51ef
--- /dev/null
+++ b/app/overrides/spree/admin/products/index/replace_name_field_with_translations_name.html.erb.deface
@@ -0,0 +1,3 @@
+
+<%= f.label :translations_name_cont, Spree::Product.human_attribute_name(:name) %>
+<%= f.text_field :translations_name_cont, size: 15 %>
diff --git a/bin/rails b/bin/rails
index c535fd20..6dbbbc36 100755
--- a/bin/rails
+++ b/bin/rails
@@ -1,15 +1,7 @@
#!/usr/bin/env ruby
-# frozen_string_literal: true
-
-app_root = 'spec/dummy'
-
-unless File.exist? "#{app_root}/bin/rails"
- system "bin/rake", app_root or begin # rubocop:disable Style/AndOr
- warn "Automatic creation of the dummy app failed"
- exit 1
- end
+if %w[g generate].include? ARGV.first
+ exec "#{__dir__}/rails-engine", *ARGV
+else
+ exec "#{__dir__}/rails-sandbox", *ARGV
end
-
-Dir.chdir app_root
-exec 'bin/rails', *ARGV
diff --git a/bin/rails-engine b/bin/rails-engine
new file mode 100755
index 00000000..59a707cb
--- /dev/null
+++ b/bin/rails-engine
@@ -0,0 +1,13 @@
+#!/usr/bin/env ruby
+# This command will automatically be run when you run "rails" with Rails gems
+# installed from the root of your application.
+
+ENGINE_ROOT = File.expand_path('..', __dir__)
+ENGINE_PATH = File.expand_path('../lib/solidus_globalize/engine', __dir__)
+
+# Set up gems listed in the Gemfile.
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
+require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
+
+require 'rails/all'
+require 'rails/engine/commands'
diff --git a/bin/rails-sandbox b/bin/rails-sandbox
new file mode 100755
index 00000000..ad2df04d
--- /dev/null
+++ b/bin/rails-sandbox
@@ -0,0 +1,16 @@
+#!/usr/bin/env ruby
+
+app_root = 'sandbox'
+
+unless File.exist? "#{app_root}/bin/rails"
+ warn 'Creating the sandbox app...'
+ Dir.chdir "#{__dir__}/.." do
+ system "#{__dir__}/sandbox" or begin
+ warn 'Automatic creation of the sandbox app failed'
+ exit 1
+ end
+ end
+end
+
+Dir.chdir app_root
+exec 'bin/rails', *ARGV
diff --git a/bin/rake b/bin/rake
new file mode 100755
index 00000000..1e6eacd3
--- /dev/null
+++ b/bin/rake
@@ -0,0 +1,7 @@
+#!/usr/bin/env ruby
+# frozen_string_literal: true
+
+require "rubygems"
+require "bundler/setup"
+
+load Gem.bin_path("rake", "rake")
diff --git a/bin/sandbox b/bin/sandbox
new file mode 100755
index 00000000..75a3890f
--- /dev/null
+++ b/bin/sandbox
@@ -0,0 +1,78 @@
+#!/usr/bin/env bash
+
+set -e
+test -z "${DEBUG+empty_string}" || set -x
+
+test "$DB" = "sqlite" && export DB="sqlite3"
+
+if [ -z "$SOLIDUS_BRANCH" ]
+then
+ echo "~~> Use 'export SOLIDUS_BRANCH=[master|v3.2|...]' to control the Solidus branch"
+ SOLIDUS_BRANCH="master"
+fi
+echo "~~> Using branch $SOLIDUS_BRANCH of solidus"
+
+if [ -z "$SOLIDUS_FRONTEND" ]
+then
+ echo "~~> Use 'export SOLIDUS_FRONTEND=[solidus_frontend|solidus_starter_frontend]' to control the Solidus frontend"
+ SOLIDUS_FRONTEND="solidus_frontend"
+fi
+echo "~~> Using branch $SOLIDUS_FRONTEND as the solidus frontend"
+
+extension_name="solidus_globalize"
+
+# Stay away from the bundler env of the containing extension.
+function unbundled {
+ ruby -rbundler -e'b = proc {system *ARGV}; Bundler.respond_to?(:with_unbundled_env) ? Bundler.with_unbundled_env(&b) : Bundler.with_clean_env(&b)' -- $@
+}
+
+rm -rf ./sandbox
+unbundled bundle exec rails new sandbox \
+ --database="${DB:-sqlite3}" \
+ --skip-bundle \
+ --skip-git \
+ --skip-keeps \
+ --skip-rc \
+ --skip-spring \
+ --skip-test \
+ --skip-javascript
+
+if [ ! -d "sandbox" ]; then
+ echo 'sandbox rails application failed'
+ exit 1
+fi
+
+cd ./sandbox
+cat <> Gemfile
+gem 'solidus', github: 'solidusio/solidus', branch: '$SOLIDUS_BRANCH'
+gem 'rails-i18n'
+gem 'solidus_i18n'
+
+gem '$extension_name', path: '..'
+
+group :test, :development do
+ platforms :mri do
+ gem 'pry-byebug'
+ end
+end
+RUBY
+
+unbundled bundle install --gemfile Gemfile
+
+unbundled bundle exec rake db:drop db:create
+
+unbundled bundle exec rails generate solidus:install \
+ --auto-accept \
+ --user_class=Spree::User \
+ --enforce_available_locales=true \
+ --with-authentication=true \
+ --payment-method=none \
+ --frontend=${SOLIDUS_FRONTEND} \
+ $@
+
+unbundled bundle exec rails generate solidus:auth:install --auto-run-migrations
+unbundled bundle exec rails generate ${extension_name}:install --auto-run-migrations
+
+echo
+echo "🚀 Sandbox app successfully created for $extension_name!"
+echo "🧪 This app is intended for test purposes."
diff --git a/bin/setup b/bin/setup
index 40d7811d..67d91932 100755
--- a/bin/setup
+++ b/bin/setup
@@ -5,4 +5,4 @@ set -vx
gem install bundler --conservative
bundle update
-bundle exec rake clobber
+bin/rake clobber
diff --git a/db/migrate/20130419041407_add_translations_to_main_models.rb b/db/migrate/20130419041407_add_translations_to_main_models.rb
index e5e0dfd0..b2c5581d 100644
--- a/db/migrate/20130419041407_add_translations_to_main_models.rb
+++ b/db/migrate/20130419041407_add_translations_to_main_models.rb
@@ -27,12 +27,12 @@ def up
Spree::Taxonomy.create_translation_table!({ name: :string }, migrate_data: true)
end
- unless table_exists?(:spree_taxon_translations)
- params = { name: :string, description: :text, meta_title: :string,
- meta_description: :string, meta_keywords: :string,
- permalink: :string }
- Spree::Taxon.create_translation_table!(params, migrate_data: true)
- end
+ return if table_exists?(:spree_taxon_translations)
+
+ params = { name: :string, description: :text, meta_title: :string,
+ meta_description: :string, meta_keywords: :string,
+ permalink: :string }
+ Spree::Taxon.create_translation_table!(params, migrate_data: true)
end
def down
diff --git a/db/migrate/20130518224827_add_translations_to_product_permalink.rb b/db/migrate/20130518224827_add_translations_to_product_permalink.rb
index 6ddaaa8c..46ab7493 100644
--- a/db/migrate/20130518224827_add_translations_to_product_permalink.rb
+++ b/db/migrate/20130518224827_add_translations_to_product_permalink.rb
@@ -8,9 +8,9 @@ def up
{ slug: :string }
end
- unless column_exists?(:spree_product_translations, fields.keys.first)
- Spree::Product.add_translation_fields!(fields, migrate_data: true)
- end
+ return if column_exists?(:spree_product_translations, fields.keys.first)
+
+ Spree::Product.add_translation_fields!(fields, migrate_data: true)
end
def down; end
diff --git a/db/migrate/20131009091000_add_translations_to_option_value.rb b/db/migrate/20131009091000_add_translations_to_option_value.rb
index 4e66ff5c..09dc7ff1 100644
--- a/db/migrate/20131009091000_add_translations_to_option_value.rb
+++ b/db/migrate/20131009091000_add_translations_to_option_value.rb
@@ -2,10 +2,10 @@
class AddTranslationsToOptionValue < SolidusSupport::Migration[4.2]
def up
- unless table_exists?(:spree_option_value_translations)
- params = { name: :string, presentation: :string }
- Spree::OptionValue.create_translation_table!(params, migrate_data: true)
- end
+ return if table_exists?(:spree_option_value_translations)
+
+ params = { name: :string, presentation: :string }
+ Spree::OptionValue.create_translation_table!(params, migrate_data: true)
end
def down
diff --git a/db/migrate/20140206202524_rename_activator_translations_to_promotion_translations.rb b/db/migrate/20140206202524_rename_activator_translations_to_promotion_translations.rb
index f9e541eb..ad5abe7b 100644
--- a/db/migrate/20140206202524_rename_activator_translations_to_promotion_translations.rb
+++ b/db/migrate/20140206202524_rename_activator_translations_to_promotion_translations.rb
@@ -2,9 +2,9 @@
class RenameActivatorTranslationsToPromotionTranslations < SolidusSupport::Migration[4.2]
def change
- if table_exists? 'spree_activator_translations'
- rename_table :spree_activator_translations, :spree_promotion_translations
- rename_column :spree_promotion_translations, :spree_activator_id, :spree_promotion_id
- end
+ return unless table_exists? 'spree_activator_translations'
+
+ rename_table :spree_activator_translations, :spree_promotion_translations
+ rename_column :spree_promotion_translations, :spree_activator_id, :spree_promotion_id
end
end
diff --git a/db/migrate/20140219130603_update_spree_product_translations.rb b/db/migrate/20140219130603_update_spree_product_translations.rb
index 5d507bd6..acff0edc 100644
--- a/db/migrate/20140219130603_update_spree_product_translations.rb
+++ b/db/migrate/20140219130603_update_spree_product_translations.rb
@@ -2,8 +2,8 @@
class UpdateSpreeProductTranslations < SolidusSupport::Migration[4.2]
def change
- if column_exists?(:spree_product_translations, :permalink)
- rename_column :spree_product_translations, :permalink, :slug
- end
+ return unless column_exists?(:spree_product_translations, :permalink)
+
+ rename_column :spree_product_translations, :permalink, :slug
end
end
diff --git a/db/migrate/20141112121313_add_translations_to_product_properties.rb b/db/migrate/20141112121313_add_translations_to_product_properties.rb
index 5f4f893d..5a6cdc55 100644
--- a/db/migrate/20141112121313_add_translations_to_product_properties.rb
+++ b/db/migrate/20141112121313_add_translations_to_product_properties.rb
@@ -2,10 +2,10 @@
class AddTranslationsToProductProperties < SolidusSupport::Migration[4.2]
def up
- unless table_exists?(:spree_product_property_translations)
- params = { value: :string }
- Spree::ProductProperty.create_translation_table!(params, migrate_data: true)
- end
+ return if table_exists?(:spree_product_property_translations)
+
+ params = { value: :string }
+ Spree::ProductProperty.create_translation_table!(params, migrate_data: true)
end
def down
diff --git a/db/migrate/20150224152415_add_deleted_at_to_translation_tables.rb b/db/migrate/20150224152415_add_deleted_at_to_translation_tables.rb
index 5f1f36cc..71b8ba23 100644
--- a/db/migrate/20150224152415_add_deleted_at_to_translation_tables.rb
+++ b/db/migrate/20150224152415_add_deleted_at_to_translation_tables.rb
@@ -2,9 +2,9 @@
class AddDeletedAtToTranslationTables < SolidusSupport::Migration[4.2]
def change
- unless column_exists?(:spree_product_translations, :deleted_at)
- add_column :spree_product_translations, :deleted_at, :datetime
- add_index :spree_product_translations, :deleted_at
- end
+ return if column_exists?(:spree_product_translations, :deleted_at)
+
+ add_column :spree_product_translations, :deleted_at, :datetime
+ add_index :spree_product_translations, :deleted_at
end
end
diff --git a/db/migrate/20150323210949_add_translations_to_store.rb b/db/migrate/20150323210949_add_translations_to_store.rb
index 5a8507b2..7d09e937 100644
--- a/db/migrate/20150323210949_add_translations_to_store.rb
+++ b/db/migrate/20150323210949_add_translations_to_store.rb
@@ -2,10 +2,10 @@
class AddTranslationsToStore < SolidusSupport::Migration[4.2]
def up
- unless table_exists?(:spree_store_translations)
- params = { name: :string, meta_description: :text, meta_keywords: :text, seo_title: :string }
- Spree::Store.create_translation_table!(params, migrate_data: true)
- end
+ return if table_exists?(:spree_store_translations)
+
+ params = { name: :string, meta_description: :text, meta_keywords: :text, seo_title: :string }
+ Spree::Store.create_translation_table!(params, migrate_data: true)
end
def down
diff --git a/db/migrate/20191108162345_add_locale_to_friendly_id_slugs.rb b/db/migrate/20191108162345_add_locale_to_friendly_id_slugs.rb
index 74387bf9..fbb186a7 100644
--- a/db/migrate/20191108162345_add_locale_to_friendly_id_slugs.rb
+++ b/db/migrate/20191108162345_add_locale_to_friendly_id_slugs.rb
@@ -2,12 +2,14 @@
class AddLocaleToFriendlyIdSlugs < SolidusSupport::Migration[4.2]
def change
- add_column :friendly_id_slugs, :locale, :string, length: 2, null: :false, after: :scope
+ add_column :friendly_id_slugs, :locale, :string, length: 2, null: false, after: :scope
remove_index :friendly_id_slugs, [:slug, :sluggable_type]
- add_index :friendly_id_slugs, [:slug, :sluggable_type, :locale], length: { slug: 140, sluggable_type: 50, locale: 2 }
+ add_index :friendly_id_slugs, [:slug, :sluggable_type, :locale],
+ length: { slug: 140, sluggable_type: 50, locale: 2 }
remove_index :friendly_id_slugs, [:slug, :sluggable_type, :scope]
- add_index :friendly_id_slugs, [:slug, :sluggable_type, :scope, :locale], length: { slug: 70, sluggable_type: 50, scope: 70, locale: 2 }, unique: true, name: :index_friendly_id_slugs_uniqueness
+ add_index :friendly_id_slugs, [:slug, :sluggable_type, :scope, :locale],
+ length: { slug: 70, sluggable_type: 50, scope: 70, locale: 2 }, unique: true, name: :index_friendly_id_slugs_uniqueness
add_index :friendly_id_slugs, :locale
end
end
diff --git a/lib/generators/solidus_globalize/install/install_generator.rb b/lib/generators/solidus_globalize/install/install_generator.rb
index 78196615..b17463e4 100644
--- a/lib/generators/solidus_globalize/install/install_generator.rb
+++ b/lib/generators/solidus_globalize/install/install_generator.rb
@@ -15,7 +15,8 @@ def add_migrations
end
def run_migrations
- run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]'))
+ run_migrations = options[:auto_run_migrations] || ['', 'y',
+ 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]'))
if run_migrations
run 'bundle exec rake db:migrate'
else
diff --git a/lib/generators/solidus_globalize/install/templates/initializer.rb b/lib/generators/solidus_globalize/install/templates/initializer.rb
new file mode 100644
index 00000000..8e91ed1b
--- /dev/null
+++ b/lib/generators/solidus_globalize/install/templates/initializer.rb
@@ -0,0 +1,6 @@
+# frozen_string_literal: true
+
+SolidusGlobalize.configure do |config|
+ # TODO: Remember to change this with the actual preferences you have implemented!
+ # config.sample_preference = 'sample_value'
+end
diff --git a/lib/solidus_globalize.rb b/lib/solidus_globalize.rb
index d0e4d9e4..3f756bd0 100644
--- a/lib/solidus_globalize.rb
+++ b/lib/solidus_globalize.rb
@@ -1,5 +1,7 @@
# frozen_string_literal: true
+require 'solidus_globalize/serialization_rails_7_1_globalize_6'
+
require 'solidus_core'
require 'solidus_support'
diff --git a/lib/solidus_globalize/configuration.rb b/lib/solidus_globalize/configuration.rb
index a0cbe6a9..bdd8b58b 100644
--- a/lib/solidus_globalize/configuration.rb
+++ b/lib/solidus_globalize/configuration.rb
@@ -10,5 +10,38 @@ class Configuration < Spree::Preferences::Configuration
# e.g. If available_locales are [:en, :es] admin can translate model records
# to spanish as well. Once it's done :es can be added to supported_locales
preference :supported_locales, :array, default: [:en]
+
+ preference(:translatable_fields, :hash,
+ default: {
+ 'Spree::OptionType' => [:name, :presentation],
+ 'Spree::OptionValue' => [:name, :presentation],
+ 'Spree::Product' => [
+ :name,
+ :description,
+ :meta_description,
+ :meta_keywords,
+ :meta_title,
+ :slug
+ ],
+ 'Spree::ProductProperty' => [:value],
+ 'Spree::Promotion' => [:name, :description],
+ 'Spree::Property' => [:name, :presentation],
+ 'Spree::ShippingMethod' => [:name],
+ 'Spree::Store' => [
+ :name,
+ :meta_description,
+ :meta_keywords,
+ :seo_title
+ ],
+ 'Spree::Taxon' => [
+ :name,
+ :description,
+ :meta_title,
+ :meta_description,
+ :meta_keywords,
+ :permalink
+ ],
+ 'Spree::Taxonomy' => [:name],
+ })
end
end
diff --git a/lib/solidus_globalize/serialization_rails_7_1_globalize_6.rb b/lib/solidus_globalize/serialization_rails_7_1_globalize_6.rb
new file mode 100644
index 00000000..e8a96b3c
--- /dev/null
+++ b/lib/solidus_globalize/serialization_rails_7_1_globalize_6.rb
@@ -0,0 +1,31 @@
+# frozen_string_literal: true
+
+require 'globalize'
+
+module SerializationRails71Globalize6
+ def serialize(attr_name, class_name_or_coder = nil, **options)
+ self.globalize_serialized_attributes = globalize_serialized_attributes.dup
+
+ if class_name_or_coder.nil?
+ globalize_serialized_attributes[attr_name] = options
+
+ super(attr_name, options[:type] || Object, **options)
+ elsif class_name_or_coder.is_a?(Hash)
+ globalize_serialized_attributes[attr_name] = class_name_or_coder
+
+ # https://github.com/rails/rails/blob/7-2-stable/activerecord/lib/active_record/attribute_methods/serialization.rb#L183
+ super(attr_name, class_name_or_coder[:type] || Object, **class_name_or_coder)
+ else
+ globalize_serialized_attributes[attr_name] = [class_name_or_coder, options]
+
+ # this is only needed for ACTIVE_RECORD_71. class_name_or_coder will be removed with Rails 7.2
+ # https://github.com/rails/rails/blob/7-1-stable/activerecord/lib/active_record/attribute_methods/serialization.rb#L183
+ super(attr_name, class_name_or_coder, **options)
+ end
+ end
+
+ if Rails.gem_version >= Gem::Version.new('7.1') &&
+ Gem.loaded_specs["globalize"]&.version&.public_send(:<, "7")
+ Globalize::AttributeMethods::Serialization.prepend(self)
+ end
+end
diff --git a/lib/solidus_globalize/factories.rb b/lib/solidus_globalize/testing_support/factories.rb
similarity index 100%
rename from lib/solidus_globalize/factories.rb
rename to lib/solidus_globalize/testing_support/factories.rb
diff --git a/solidus_globalize.gemspec b/solidus_globalize.gemspec
index e29e5972..e743dcef 100644
--- a/solidus_globalize.gemspec
+++ b/solidus_globalize.gemspec
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
s.metadata["source_code_uri"] = 'https://github.com/solidusio-contrib/solidus_globalize'
end
- s.required_ruby_version = '~> 2.4'
+ s.required_ruby_version = ['>= 2.4', '< 4.0']
s.files = Dir.chdir(File.expand_path(__dir__)) do
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
@@ -33,11 +33,10 @@ Gem::Specification.new do |s|
s.add_dependency 'deface', '~> 1.5'
s.add_dependency 'friendly_id-globalize'
s.add_dependency 'globalize', '~> 6.0'
- s.add_dependency 'solidus_core', ['>= 2.0.0', '< 4']
+ s.add_dependency 'solidus_core', ['>= 2.0.0', '< 5']
s.add_dependency 'solidus_support', '~> 0.8'
s.add_development_dependency 'byebug'
s.add_development_dependency 'pry-rails', '>= 0.3.0'
- s.add_development_dependency 'routing-filter', '~> 0.6'
s.add_development_dependency 'solidus_dev_support'
end
diff --git a/spec/features/admin/translations_spec.rb b/spec/features/admin/translations_spec.rb
index 4e605ff3..53eaca57 100644
--- a/spec/features/admin/translations_spec.rb
+++ b/spec/features/admin/translations_spec.rb
@@ -26,12 +26,12 @@
click_on "Translations"
within("#attr_fields .name.en") { fill_in_name "Pearl Jam" }
- select2("pt-BR", from: 'Select Locale')
+ select2("pt-BR", from: 'Select locale')
within("#attr_fields .name.pt-BR") { fill_in_name "Geleia de perola" }
click_on "Update"
click_on "Translations"
- select2("pt-BR", from: 'Select Locale')
+ select2("pt-BR", from: 'Select locale')
within("#attr_fields .name.pt-BR") do
expect(page).to have_field(with: 'Geleia de perola')
end
@@ -45,14 +45,14 @@
visit spree.admin_product_product_properties_path(product_property.product)
within_row(1) { click_icon :globe }
click_on "Value"
- select2("pt-BR", from: 'Select Locale')
+ select2("pt-BR", from: 'Select locale')
within("#attr_fields .value.pt-BR") { fill_in_name "vermelho" }
click_on "Update"
visit spree.admin_product_product_properties_path(product_property.product)
within_row(1) { click_icon :globe }
click_on "Value"
- select2("pt-BR", from: 'Select Locale')
+ select2("pt-BR", from: 'Select locale')
within("#attr_fields .value.pt-BR") do
expect(page).to have_field(with: 'vermelho')
end
@@ -68,14 +68,14 @@
within("#attr_fields .name.en") { fill_in_name "shirt sizes" }
within("#attr_list") { click_on "Presentation" }
within("#attr_fields .presentation.en") { fill_in_name "size" }
- select2("pt-BR", from: 'Select Locale')
+ select2("pt-BR", from: 'Select locale')
within("#attr_fields .presentation.pt-BR") { fill_in_name "tamanho" }
click_on "Update"
visit spree.admin_option_types_path
within_row(1) { click_icon :globe }
within("#attr_list") { click_on "Presentation" }
- select2("pt-BR", from: 'Select Locale')
+ select2("pt-BR", from: 'Select locale')
within("#attr_fields .presentation.pt-BR") do
expect(page).to have_field(with: 'tamanho')
end
@@ -104,14 +104,14 @@
within("#attr_fields .name.en") { fill_in_name "big" }
within("#attr_list") { click_on "Presentation" }
within("#attr_fields .presentation.en") { fill_in_name "big" }
- select2("pt-BR", from: 'Select Locale')
+ select2("pt-BR", from: 'Select locale')
within("#attr_fields .presentation.pt-BR") { fill_in_name "grande" }
click_on "Update"
visit spree.admin_option_types_path
within_row(1) { click_icon :globe }
within("#attr_list") { click_on "Presentation" }
- select2("pt-BR", from: 'Select Locale')
+ select2("pt-BR", from: 'Select locale')
within("#attr_fields .presentation.pt-BR") do
expect(page).to have_field(with: 'grande')
end
@@ -124,20 +124,20 @@
it "saves translated attributes properly" do
visit spree.admin_properties_path
within_row(1) { click_icon :globe }
- select2("pt-BR", from: 'Select Locale')
+ select2("pt-BR", from: 'Select locale')
within("#attr_fields .name.pt-BR") { fill_in_name "Modelo" }
within("#attr_list") { click_on "Presentation" }
select2("en", from: 'Select Locale')
within("#attr_fields .presentation.en") { fill_in_name "Model" }
- select2("pt-BR", from: 'Select Locale')
+ select2("pt-BR", from: 'Select locale')
within("#attr_fields .presentation.pt-BR") { fill_in_name "Modelo" }
click_on "Update"
visit spree.admin_properties_path
within_row(1) { click_icon :globe }
within("#attr_list") { click_on "Presentation" }
- select2("pt-BR", from: 'Select Locale')
+ select2("pt-BR", from: 'Select locale')
within("#attr_fields .presentation.pt-BR") do
expect(page).to have_field(with: 'Modelo')
end
@@ -153,13 +153,13 @@
within_row(1) { click_icon :globe }
within("#attr_fields .name.en") { fill_in_name "All free" }
- select2("pt-BR", from: 'Select Locale')
+ select2("pt-BR", from: 'Select locale')
within("#attr_fields .name.pt-BR") { fill_in_name "Salve salve" }
click_on "Update"
visit spree.admin_promotions_path
within_row(1) { click_icon :globe }
- select2("pt-BR", from: 'Select Locale')
+ select2("pt-BR", from: 'Select locale')
within("#attr_fields .name.pt-BR") do
expect(page).to have_field(with: 'Salve salve')
end
@@ -182,13 +182,13 @@
within_row(1) { click_icon :globe }
within("#attr_fields .name.en") { fill_in_name "Guitars" }
- select2("pt-BR", from: 'Select Locale')
+ select2("pt-BR", from: 'Select locale')
within("#attr_fields .name.pt-BR") { fill_in_name "Guitarras" }
click_on "Update"
visit spree.admin_taxonomies_path
within_row(1) { click_icon :globe }
- select2("pt-BR", from: 'Select Locale')
+ select2("pt-BR", from: 'Select locale')
within("#attr_fields .name.pt-BR") do
expect(page).to have_field(with: 'Guitarras')
end
@@ -203,7 +203,7 @@
visit spree.admin_translations_path('taxons', taxon.id)
within("#attr_fields .name.en") { fill_in_name "Acoustic" }
- select2("pt-BR", from: 'Select Locale')
+ select2("pt-BR", from: 'Select locale')
within("#attr_fields .name.pt-BR") { fill_in_name "Acusticas" }
click_on "Update"
@@ -212,13 +212,13 @@
# ensure we're not duplicating translated records on database
expect {
click_on "Update"
- }.not_to change { taxon.translations.count }
+ }.not_to(change { taxon.translations.count })
# ensure taxon is in root or it will not be visible
expect(taxonomy.root.children.count).to be(1)
visit spree.admin_translations_path('taxons', taxon.id)
- select2("pt-BR", from: 'Select Locale')
+ select2("pt-BR", from: 'Select locale')
within("#attr_fields .name.pt-BR") do
expect(page).to have_field(with: 'Acusticas')
end
@@ -229,13 +229,13 @@
it 'saves translated attributes properly' do
visit spree.edit_admin_general_settings_path
click_link I18n.t(:'spree.globalize.store_translations')
- select2("pt-BR", from: 'Select Locale')
+ select2("pt-BR", from: 'Select locale')
within("#attr_fields .name.pt-BR") { fill_in_name "nome store" }
click_on "Update"
visit spree.admin_translations_path('stores', store)
- select2("pt-BR", from: 'Select Locale')
+ select2("pt-BR", from: 'Select locale')
within("#attr_fields .name.pt-BR") do
expect(page).to have_field(with: 'nome store')
@@ -251,12 +251,12 @@
visit spree.admin_translations_path('shipping_methods', shipping_method.id)
within("#attr_fields .name.en") { fill_in_name "Urgent elivery" }
- select2("pt-BR", from: 'Select Locale')
+ select2("pt-BR", from: 'Select locale')
within("#attr_fields .name.pt-BR") { fill_in_name "Entrega urgente" }
click_on "Update"
visit spree.admin_translations_path('shipping_methods', shipping_method.id)
- select2("pt-BR", from: 'Select Locale')
+ select2("pt-BR", from: 'Select locale')
within("#attr_fields .name.pt-BR") do
expect(page).to have_field(with: 'Entrega urgente')
end
@@ -300,13 +300,13 @@
click_on "Translations"
click_on "Name"
- select2("pt-BR", from: 'Select Locale')
+ select2("pt-BR", from: 'Select locale')
within("#attr_fields .name.pt-BR") { fill_in_name "Produtos" }
click_on "Slug"
select2("en", from: 'Select Locale')
within("#attr_fields .slug.en") { fill_in_name "en_link" }
- select2("pt-BR", from: 'Select Locale')
+ select2("pt-BR", from: 'Select locale')
within("#attr_fields .slug.pt-BR") { fill_in_name "pt-BR_link" }
click_on "Update"
@@ -314,7 +314,7 @@
visit spree.product_path 'en_link'
expect(page).to have_text_like 'Product'
- visit '/pt-BR/products/pt-BR_link'
+ visit '/products/pt-BR_link?locale=pt-BR'
expect(page).to have_text_like 'Produtos'
end
end
diff --git a/spec/features/translations_spec.rb b/spec/features/translations_spec.rb
index 1e3fbf5d..57492cf4 100644
--- a/spec/features/translations_spec.rb
+++ b/spec/features/translations_spec.rb
@@ -11,6 +11,10 @@
Spree::Product::Translation.new(
locale: 'pt-BR',
name: 'Antimatéria'
+ ),
+ Spree::Product::Translation.new(
+ locale: 'en',
+ name: 'Antimatter'
)
])
end
@@ -26,12 +30,12 @@
end
it 'displays translated product page' do
- visit '/pt-BR/products/antimatter'
+ visit '/products/antimatter?locale=pt-BR'
expect(page.title).to have_content('Antimatéria')
end
it 'displays translated products list' do
- visit '/pt-BR/products'
+ visit '/products?locale=pt-BR'
expect(page).to have_content('Antimatéria')
end
end
diff --git a/spec/models/product_spec.rb b/spec/models/product_spec.rb
index d9e29eec..92ad6907 100644
--- a/spec/models/product_spec.rb
+++ b/spec/models/product_spec.rb
@@ -36,20 +36,20 @@ module Spree
it "with name" do
product.translations.create locale: "zh-CN",
- name: "创意马克杯",
- description: "一流工程师设计制造手工艺品
",
- meta_description: '顶尖工艺设计',
- meta_keywords: '工艺品'
+ name: "创意马克杯",
+ description: "一流工程师设计制造手工艺品
",
+ meta_description: '顶尖工艺设计',
+ meta_keywords: '工艺品'
expect(described_class.like_any([:name], ['创意'])).to include(product)
end
it "with name or description" do
product.translations.create locale: "zh-CN",
- name: "创意马克杯",
- description: "一流工程师设计制造手工艺品
",
- meta_description: '顶尖工艺设计',
- meta_keywords: '工艺品'
+ name: "创意马克杯",
+ description: "一流工程师设计制造手工艺品
",
+ meta_description: '顶尖工艺设计',
+ meta_keywords: '工艺品'
expect(described_class.like_any([:name, :description], ['手工艺品'])).to include(product)
end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index f7372189..22f1dbfd 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -6,19 +6,27 @@
# Run Coverage report
require 'solidus_dev_support/rspec/coverage'
-require File.expand_path('dummy/config/environment.rb', __dir__)
+# Create the dummy app if it's still missing.
+dummy_env = "#{__dir__}/dummy/config/environment.rb"
+system 'bin/rake extension:test_app' unless File.exist? dummy_env
+require dummy_env
# Requires factories and other useful helpers defined in spree_core.
require 'solidus_dev_support/rspec/feature_helper'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
-Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |f| require f }
+Dir["#{__dir__}/support/**/*.rb"].sort.each { |f| require f }
-# Requires factories defined in lib/solidus_globalize/factories.rb
-require 'solidus_globalize/factories'
+# Requires factories defined in Solidus core and this extension.
+# See: lib/solidus_globalize/testing_support/factories.rb
+SolidusDevSupport::TestingSupport::Factories.load_for(SolidusGlobalize::Engine)
RSpec.configure do |config|
config.infer_spec_type_from_file_location!
config.use_transactional_fixtures = false
+
+ if Spree.solidus_gem_version < Gem::Version.new('2.11')
+ config.extend Spree::TestingSupport::AuthorizationHelpers::Request, type: :system
+ end
end
diff --git a/spec/support/routing_filter.rb b/spec/support/routing_filter.rb
deleted file mode 100644
index 0c7be77d..00000000
--- a/spec/support/routing_filter.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-# frozen_string_literal: true
-
-require 'routing-filter'
-
-# In this support file we simulate how we want routes to be in a real
-# host application that uses solidus_i18n and solidus_globalize.
-RSpec.configure do |config|
- config.before(:all) do
- Rails.application.routes.draw do
- filter :locale
-
- mount Spree::Core::Engine, at: '/'
- end
- end
-end
diff --git a/spec/support/shared_contexts/locales.rb b/spec/support/shared_contexts/locales.rb
index 200819d0..218edf85 100644
--- a/spec/support/shared_contexts/locales.rb
+++ b/spec/support/shared_contexts/locales.rb
@@ -3,8 +3,8 @@
shared_context 'with pt-BR locale file in place' do
before do
I18n.backend.store_translations(:'pt-BR', spree: {
- i18n: { this_file_language: "Português brasileiro" },
- })
+ i18n: { this_file_language: "Português brasileiro" },
+ })
end
after do