diff --git a/lib/rails/generators/mobility/templates/column_translations.rb b/lib/rails/generators/mobility/templates/column_translations.rb index b73f236bc..3e35f6d3d 100644 --- a/lib/rails/generators/mobility/templates/column_translations.rb +++ b/lib/rails/generators/mobility/templates/column_translations.rb @@ -4,7 +4,7 @@ def change <% I18n.available_locales.each do |locale| -%> <% column_name = Mobility.normalize_locale_accessor(attribute.name, locale) -%> <% if connection.column_exists?(table_name, column_name) -%> -<% warn "#{column_name} already exists, skipping." %> +<% warn "#{column_name} already exists, skipping." -%> <% else -%> add_column :<%= table_name %>, :<%= column_name %>, :<%= attribute.type %><%= attribute.inject_options %> <%- if attribute.has_index? -%> diff --git a/lib/rails/generators/mobility/templates/table_migration.rb b/lib/rails/generators/mobility/templates/table_migration.rb index 3620c9422..89cb1839f 100644 --- a/lib/rails/generators/mobility/templates/table_migration.rb +++ b/lib/rails/generators/mobility/templates/table_migration.rb @@ -9,7 +9,7 @@ def change <%- else -%> add_column :<%= table_name %>, :<%= attribute.name %>, :<%= attribute.type %><%= attribute.inject_options %> <%- if attribute.has_index? -%> - add_index :<%= table_name %>, :<%= attribute.index_name %><%= attribute.inject_index_options %> + add_index :<%= table_name %>, [:<%= attribute.index_name %><%= attribute.inject_index_options %>, :locale] <%- end -%> <%- end -%> <% end -%> diff --git a/lib/rails/generators/mobility/templates/table_translations.rb b/lib/rails/generators/mobility/templates/table_translations.rb index e001e9498..4c39a2586 100644 --- a/lib/rails/generators/mobility/templates/table_translations.rb +++ b/lib/rails/generators/mobility/templates/table_translations.rb @@ -22,7 +22,7 @@ def change add_index :<%= table_name %>, [:<%= foreign_key %>, :locale], name: :<%= translation_unique_index_name %>, unique: true <%- attributes_with_index.each do |attribute| -%> - add_index :<%= table_name %>, :<%= attribute.index_name %><%= attribute.inject_index_options %> + add_index :<%= table_name %>, [:<%= attribute.index_name %><%= attribute.inject_index_options %>, :locale] <%- end -%> end end diff --git a/lib/rails/generators/mobility/translations_generator.rb b/lib/rails/generators/mobility/translations_generator.rb index b149710cc..69df2f15c 100644 --- a/lib/rails/generators/mobility/translations_generator.rb +++ b/lib/rails/generators/mobility/translations_generator.rb @@ -29,16 +29,17 @@ module Mobility Other backends are not supported, for obvious reasons: * the +key_value+ backend does not need any model-specific migrations, simply run the install generator. -* +jsonb+, +hstore+ and +serialized+ backends simply require a single column on - a model table, which can be added with the normal Rails migration generator. +* +json+, +jsonb+, +hstore+, +serialized+, and +container+ backends simply + require a single column on a model table, which can be added with the normal + Rails migration generator. =end class TranslationsGenerator < ::Rails::Generators::NamedBase - SUPPORTED_BACKENDS = %w[column table] - BACKEND_OPTIONS = { type: :string, desc: "Backend to use for translations (defaults to Mobility.default_backend)" } + SUPPORTED_BACKENDS = %w[column table].freeze + BACKEND_OPTIONS = { type: :string, desc: "Backend to use for translations (defaults to Mobility.default_backend)" }.freeze argument :attributes, type: :array, default: [], banner: "field[:type][:index] field[:type][:index]" - class_option(:backend, BACKEND_OPTIONS) + class_option(:backend, BACKEND_OPTIONS.dup) invoke_from_option :backend def self.class_options(options = nil) diff --git a/spec/generators/rails/mobility/translations_generator_spec.rb b/spec/generators/rails/mobility/translations_generator_spec.rb index 9f3d6daca..3cf9ff13b 100644 --- a/spec/generators/rails/mobility/translations_generator_spec.rb +++ b/spec/generators/rails/mobility/translations_generator_spec.rb @@ -40,7 +40,7 @@ contains "add_index :post_translations, :post_id, name: :index_post_translations_on_post_id" contains "add_index :post_translations, :locale, name: :index_post_translations_on_locale" contains "add_index :post_translations, [:post_id, :locale], name: :index_post_translations_on_post_id_and_locale, unique: true" - contains "add_index :post_translations, :title" + contains "add_index :post_translations, [:title, :locale]" end end end @@ -66,7 +66,7 @@ contains "class CreatePostTitleAndContentTranslationsForMobilityTableBackend < ActiveRecord::Migration[#{version_string_}]" end contains "add_column :post_translations, :title, :string" - contains "add_index :post_translations, :title" + contains "add_index :post_translations, [:title, :locale]" contains "add_column :post_translations, :content, :text" end end