awesome_translations 0.0.56 → 0.0.60
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Rakefile +1 -1
- data/app/controllers/awesome_translations/clean_ups_controller.rb +1 -1
- data/app/controllers/awesome_translations/groups_controller.rb +1 -0
- data/app/controllers/awesome_translations/handlers_controller.rb +1 -0
- data/app/helpers/awesome_translations/application_helper.rb +0 -1
- data/app/models/awesome_translations/group.rb +2 -2
- data/app/models/awesome_translations/translated_value.rb +4 -1
- data/app/models/awesome_translations/translation.rb +9 -4
- data/app/views/awesome_translations/duplicates/index.html.erb +2 -2
- data/app/views/awesome_translations/groups/show.html.erb +9 -4
- data/app/views/awesome_translations/handler_translations/index.html.erb +21 -6
- data/app/views/awesome_translations/handlers/show.html.erb +29 -6
- data/app/views/awesome_translations/movals/index.html.erb +2 -2
- data/lib/awesome_translations/cache_database_generator/group.rb +10 -3
- data/lib/awesome_translations/cache_database_generator/handler.rb +9 -2
- data/lib/awesome_translations/cache_database_generator/handler_translation.rb +13 -3
- data/lib/awesome_translations/cache_database_generator/translation_key.rb +4 -4
- data/lib/awesome_translations/cache_database_generator/translation_value.rb +3 -1
- data/lib/awesome_translations/cache_database_generator.rb +2 -2
- data/lib/awesome_translations/config.rb +3 -3
- data/lib/awesome_translations/engine.rb +0 -4
- data/lib/awesome_translations/erb_inspector/file_inspector.rb +7 -7
- data/lib/awesome_translations/erb_inspector/translation_inspector.rb +7 -7
- data/lib/awesome_translations/erb_inspector.rb +2 -1
- data/lib/awesome_translations/global_translator.rb +13 -27
- data/lib/awesome_translations/handlers/file_handler.rb +1 -0
- data/lib/awesome_translations/handlers/model_handler.rb +1 -1
- data/lib/awesome_translations/handlers/validations_handler.rb +4 -4
- data/lib/awesome_translations/handlers.rb +1 -0
- data/lib/awesome_translations/model_inspector.rb +19 -13
- data/lib/awesome_translations/translation_migrator.rb +1 -1
- data/lib/awesome_translations/version.rb +1 -1
- data/lib/awesome_translations.rb +1 -1
- data/lib/tasks/awesome_translations_tasks.rake +1 -1
- data/spec/controllers/groups_controller_spec.rb +5 -5
- data/spec/controllers/handlers_controller_spec.rb +1 -1
- data/spec/dummy/Rakefile +1 -1
- data/spec/dummy/app/assets/config/manifest.js +3 -0
- data/spec/dummy/app/assets/javascripts/translations.js +1 -0
- data/spec/dummy/app/controllers/users_controller.rb +1 -1
- data/spec/dummy/app/mailers/my_mailer.rb +1 -1
- data/spec/dummy/app/models/application_record.rb +3 -0
- data/spec/dummy/app/models/role.rb +1 -1
- data/spec/dummy/app/models/user.rb +1 -1
- data/spec/dummy/bin/bundle +1 -1
- data/spec/dummy/bin/rails +1 -1
- data/spec/dummy/config/application.rb +7 -2
- data/spec/dummy/config/boot.rb +2 -2
- data/spec/dummy/config/environment.rb +1 -1
- data/spec/dummy/config.ru +1 -1
- data/spec/factories/group.rb +2 -2
- data/spec/factories/handler.rb +4 -4
- data/spec/factories/handler_translation.rb +5 -5
- data/spec/factories/translation_key.rb +1 -1
- data/spec/factories/translation_value.rb +3 -3
- data/spec/features/clean_ups_spec.rb +1 -1
- data/spec/features/duplicates_spec.rb +4 -4
- data/spec/features/movals_spec.rb +7 -7
- data/spec/handlers/file_handler_spec.rb +8 -8
- data/spec/handlers/model_handler_spec.rb +4 -4
- data/spec/handlers/validations_handler_spec.rb +3 -3
- data/spec/handlers_spec.rb +1 -1
- data/spec/lib/cache_database_generator_spec.rb +3 -3
- data/spec/lib/erb_inspector/file_inspector_spec.rb +3 -2
- data/spec/lib/erb_inspector/translation_inspector_spec.rb +2 -2
- data/spec/lib/erb_inspector_spec.rb +5 -5
- data/spec/lib/model_inspector_spec.rb +4 -4
- data/spec/lib/translation_migrator_spec.rb +2 -2
- data/spec/models/awesome_translations/handler_spec.rb +1 -1
- data/spec/models/awesome_translations/translation_spec.rb +7 -2
- data/spec/spec_helper.rb +8 -6
- metadata +76 -94
- data/config/initializers/simple_form_ransack.rb +0 -1
@@ -12,7 +12,7 @@ class AwesomeTranslations::Handlers::ModelHandler < AwesomeTranslations::Handler
|
|
12
12
|
|
13
13
|
def translations_for_group(group)
|
14
14
|
ArrayEnumerator.new do |yielder|
|
15
|
-
model_inspector = AwesomeTranslations::ModelInspector.model_classes.find { |
|
15
|
+
model_inspector = AwesomeTranslations::ModelInspector.model_classes.find { |model_inspector_i| model_inspector_i.clazz.name == group.name }
|
16
16
|
raise "No inspector by that name: #{group.name}" unless model_inspector
|
17
17
|
|
18
18
|
model_names(model_inspector).each { |translation| yielder << translation }
|
@@ -12,7 +12,7 @@ class AwesomeTranslations::Handlers::ValidationsHandler < AwesomeTranslations::H
|
|
12
12
|
|
13
13
|
def translations_for_group(group)
|
14
14
|
ArrayEnumerator.new do |yielder|
|
15
|
-
model_inspector = AwesomeTranslations::ModelInspector.model_classes.find { |
|
15
|
+
model_inspector = AwesomeTranslations::ModelInspector.model_classes.find { |model_inspector_i| model_inspector_i.clazz.name == group.name }
|
16
16
|
raise "No inspector by that name: #{group.name}" unless model_inspector
|
17
17
|
|
18
18
|
model_inspector.clazz._validators.each do |attribute_name, validators|
|
@@ -23,11 +23,11 @@ class AwesomeTranslations::Handlers::ValidationsHandler < AwesomeTranslations::H
|
|
23
23
|
translations_for_format_validator(validator, model_inspector, attribute_name, yielder)
|
24
24
|
elsif validator.is_a?(ActiveRecord::Validations::UniquenessValidator)
|
25
25
|
translations_for_uniqueness_validator(validator, model_inspector, attribute_name, yielder)
|
26
|
-
elsif validator.class.name == "ActiveRecord::Validations::PresenceValidator"
|
26
|
+
elsif validator.class.name == "ActiveRecord::Validations::PresenceValidator" # rubocop:disable Style/ClassEqualityComparison:
|
27
27
|
translations_for_presence_validator(validator, model_inspector, attribute_name, yielder)
|
28
|
-
elsif validator.class.name == "EmailValidator"
|
28
|
+
elsif validator.class.name == "EmailValidator" # rubocop:disable Style/ClassEqualityComparison:
|
29
29
|
translations_for_email_validator(validator, model_inspector, attribute_name, yielder)
|
30
|
-
elsif validator.class.name == "ActiveModel::Validations::ConfirmationValidator"
|
30
|
+
elsif validator.class.name == "ActiveModel::Validations::ConfirmationValidator" # rubocop:disable Style/ClassEqualityComparison:
|
31
31
|
translations_for_confirmation_validator(validator, model_inspector, attribute_name, yielder)
|
32
32
|
else
|
33
33
|
Rails.logger.error "Unhandeled validator: #{validator.class.name}"
|
@@ -2,6 +2,7 @@ class AwesomeTranslations::ModelInspector
|
|
2
2
|
autoload :Attribute, "#{File.dirname(__FILE__)}/model_inspector/attribute"
|
3
3
|
|
4
4
|
attr_reader :clazz
|
5
|
+
|
5
6
|
cattr_accessor :models_loaded
|
6
7
|
|
7
8
|
# Yields a model-inspector for each model found in the application.
|
@@ -16,6 +17,7 @@ class AwesomeTranslations::ModelInspector
|
|
16
17
|
ArrayEnumerator.new do |yielder|
|
17
18
|
find_subclasses(ActiveRecord::Base) do |model_inspector|
|
18
19
|
next if !model_inspector.clazz.name || @skip.include?(model_inspector.clazz.name)
|
20
|
+
|
19
21
|
yielder << model_inspector
|
20
22
|
end
|
21
23
|
end
|
@@ -33,11 +35,10 @@ class AwesomeTranslations::ModelInspector
|
|
33
35
|
end
|
34
36
|
end
|
35
37
|
|
36
|
-
def paperclip_attachments
|
38
|
+
def paperclip_attachments(&blk)
|
37
39
|
return unless ::Kernel.const_defined?("Paperclip")
|
38
|
-
|
39
|
-
|
40
|
-
end
|
40
|
+
|
41
|
+
Paperclip::AttachmentRegistry.names_for(@clazz, &blk)
|
41
42
|
end
|
42
43
|
|
43
44
|
def money_attributes
|
@@ -73,10 +74,8 @@ class AwesomeTranslations::ModelInspector
|
|
73
74
|
end
|
74
75
|
|
75
76
|
# TODO: Maybe this should yield a ModelInspector::Relationship instead?
|
76
|
-
def relationships
|
77
|
-
@clazz.reflections.each
|
78
|
-
yield key, reflection
|
79
|
-
end
|
77
|
+
def relationships(&blk)
|
78
|
+
@clazz.reflections.each(&blk)
|
80
79
|
end
|
81
80
|
|
82
81
|
def attribute_key(attribute_name)
|
@@ -93,6 +92,7 @@ class AwesomeTranslations::ModelInspector
|
|
93
92
|
|
94
93
|
def self.find_subclasses(clazz, &blk)
|
95
94
|
return if @scanned[clazz.name]
|
95
|
+
|
96
96
|
@scanned[clazz.name] = true
|
97
97
|
|
98
98
|
clazz.subclasses.each do |subclass|
|
@@ -121,14 +121,20 @@ class AwesomeTranslations::ModelInspector
|
|
121
121
|
|
122
122
|
# Loads models for the given app-directory (Rails-root or engine).
|
123
123
|
def self.load_models_for(root)
|
124
|
-
Dir.glob("#{root}/app/models/**/*.rb") do |model_path|
|
124
|
+
Dir.glob("#{root}/app/models/**/*.rb").sort.each do |model_path|
|
125
|
+
next if active_storage_path?(model_path)
|
126
|
+
|
125
127
|
begin
|
126
128
|
require model_path
|
127
|
-
rescue => e
|
128
|
-
|
129
|
-
|
130
|
-
|
129
|
+
rescue StandardError => e
|
130
|
+
warn "Could not load model in #{model_path}"
|
131
|
+
warn e.inspect
|
132
|
+
warn e.backtrace
|
131
133
|
end
|
132
134
|
end
|
133
135
|
end
|
136
|
+
|
137
|
+
def self.active_storage_path?(model_path)
|
138
|
+
model_path.match?(/\/gems\/activestorage-([\d.]+)\//)
|
139
|
+
end
|
134
140
|
end
|
@@ -44,7 +44,7 @@ class AwesomeTranslations::TranslationMigrator
|
|
44
44
|
File.open(@old_path, "w") { |fp| fp.write(YAML.dump(translations_hash)) }
|
45
45
|
end
|
46
46
|
|
47
|
-
@translation_value.
|
47
|
+
@translation_value.update!(file_path: @new_path) if @new_path
|
48
48
|
end
|
49
49
|
|
50
50
|
private
|
data/lib/awesome_translations.rb
CHANGED
@@ -3,10 +3,10 @@ require "spec_helper"
|
|
3
3
|
describe AwesomeTranslations::GroupsController do
|
4
4
|
routes { AwesomeTranslations::Engine.routes }
|
5
5
|
|
6
|
-
let(:model_locales_path) { Rails.root.join("config
|
6
|
+
let(:model_locales_path) { Rails.root.join("config/locales/awesome_translations/models").to_s }
|
7
7
|
let(:user_yml_path) { "#{model_locales_path}/user/da.yml" }
|
8
8
|
let(:role_yml_path) { "#{model_locales_path}/role/da.yml" }
|
9
|
-
let(:date_time_path) { Rails.root.join("config
|
9
|
+
let(:date_time_path) { Rails.root.join("config/locales/awesome_translations/date_time/da.yml").to_s }
|
10
10
|
|
11
11
|
before do
|
12
12
|
AwesomeTranslations::CacheDatabaseGenerator.current.cache_translations
|
@@ -22,7 +22,7 @@ describe AwesomeTranslations::GroupsController do
|
|
22
22
|
|
23
23
|
describe "#update" do
|
24
24
|
it "updates translations" do
|
25
|
-
expect(I18n.load_path).
|
25
|
+
expect(I18n.load_path).not_to include model_locales_path
|
26
26
|
|
27
27
|
put :update, params: {handler_id: "model_handler", id: "User", t: {
|
28
28
|
"activerecord.attributes.user.password" => {"da" => "Adgangskode", "de" => "Kenwort", "en" => "Password"}
|
@@ -47,10 +47,10 @@ describe AwesomeTranslations::GroupsController do
|
|
47
47
|
.joins(:translation_key)
|
48
48
|
.find_by(translation_keys: {key: key_to_update}, locale: "de")
|
49
49
|
|
50
|
-
expect(da_translation_value).
|
50
|
+
expect(da_translation_value).not_to eq nil
|
51
51
|
expect(da_translation_value.value).to eq "Rolle"
|
52
52
|
|
53
|
-
expect(de_translation_value).
|
53
|
+
expect(de_translation_value).not_to eq nil
|
54
54
|
expect(de_translation_value.value).to eq "Die type"
|
55
55
|
|
56
56
|
expect(I18n.load_path).to include role_yml_path
|
data/spec/dummy/Rakefile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
2
2
|
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
3
3
|
|
4
|
-
require File.expand_path("
|
4
|
+
require File.expand_path("config/application", __dir__)
|
5
5
|
|
6
6
|
Dummy::Application.load_tasks
|
data/spec/dummy/bin/bundle
CHANGED
data/spec/dummy/bin/rails
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.expand_path("
|
1
|
+
require File.expand_path("boot", __dir__)
|
2
2
|
|
3
3
|
# Pick the frameworks you want:
|
4
4
|
require "active_record/railtie"
|
@@ -24,7 +24,12 @@ class Dummy::Application < Rails::Application
|
|
24
24
|
# config.time_zone = 'Central Time (US & Canada)'
|
25
25
|
|
26
26
|
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
27
|
-
config.i18n.load_path += Dir[Rails.root.join("config
|
27
|
+
config.i18n.load_path += Dir[Rails.root.join("config/locales/**/*.{rb,yml}").to_s]
|
28
28
|
config.i18n.available_locales = [:da, :de, :en]
|
29
29
|
config.i18n.default_locale = :en
|
30
|
+
|
31
|
+
config.assets.precompile += %w[
|
32
|
+
awesome_translations/application.css
|
33
|
+
awesome_translations/application.js
|
34
|
+
]
|
30
35
|
end
|
data/spec/dummy/config/boot.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# Set up gems listed in the Gemfile.
|
2
|
-
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("
|
2
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../../Gemfile", __dir__)
|
3
3
|
|
4
4
|
require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"])
|
5
|
-
$LOAD_PATH.unshift File.expand_path("
|
5
|
+
$LOAD_PATH.unshift File.expand_path("../../../lib", __dir__)
|
data/spec/dummy/config.ru
CHANGED
data/spec/factories/group.rb
CHANGED
data/spec/factories/handler.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
FactoryBot.define do
|
2
2
|
factory :handler, class: "AwesomeTranslations::CacheDatabaseGenerator::Handler" do
|
3
|
-
identifier "rails_handler"
|
4
|
-
name "RailsHandler"
|
3
|
+
identifier { "rails_handler" }
|
4
|
+
name { "RailsHandler" }
|
5
5
|
|
6
6
|
factory :model_handler do
|
7
|
-
identifier "model_handler"
|
8
|
-
name "ModelHandler"
|
7
|
+
identifier { "model_handler" }
|
8
|
+
name { "ModelHandler" }
|
9
9
|
end
|
10
10
|
end
|
11
11
|
end
|
@@ -4,10 +4,10 @@ FactoryBot.define do
|
|
4
4
|
translation_key
|
5
5
|
group
|
6
6
|
|
7
|
-
key_show "some.key"
|
8
|
-
file_path nil
|
9
|
-
line_no nil
|
10
|
-
full_path nil
|
11
|
-
dir
|
7
|
+
key_show { "some.key" }
|
8
|
+
file_path { nil }
|
9
|
+
line_no { nil }
|
10
|
+
full_path { nil }
|
11
|
+
dir { Rails.root.join("config/locales/awesome_translations/some/key") }
|
12
12
|
end
|
13
13
|
end
|
@@ -2,8 +2,8 @@ FactoryBot.define do
|
|
2
2
|
factory :translation_value, class: "AwesomeTranslations::CacheDatabaseGenerator::TranslationValue" do
|
3
3
|
translation_key
|
4
4
|
|
5
|
-
file_path
|
6
|
-
locale "en"
|
7
|
-
value "English"
|
5
|
+
file_path { Rails.root.join("config/locales/some_file.yml") }
|
6
|
+
locale { "en" }
|
7
|
+
value { "English" }
|
8
8
|
end
|
9
9
|
end
|
@@ -7,7 +7,7 @@ describe AwesomeTranslations::CleanUpsController do
|
|
7
7
|
create :translation_value,
|
8
8
|
translation_key: translation_key,
|
9
9
|
locale: "da",
|
10
|
-
file_path:
|
10
|
+
file_path: Rails.root.join("config/locales/awesome_translations/some_file.yml")
|
11
11
|
end
|
12
12
|
let(:content) do
|
13
13
|
{
|
@@ -4,18 +4,18 @@ describe AwesomeTranslations::DuplicatesController do
|
|
4
4
|
let!(:handler_translation) do
|
5
5
|
create :handler_translation,
|
6
6
|
translation_key: translation_key,
|
7
|
-
dir: Rails.root.join("config
|
7
|
+
dir: Rails.root.join("config/locales/some/right/path")
|
8
8
|
end
|
9
9
|
let!(:translation_key) { create :translation_key, key: "some.key" }
|
10
10
|
let!(:translation_value) do
|
11
11
|
create :translation_value,
|
12
12
|
translation_key: translation_key,
|
13
|
-
file_path: Rails.root.join("config
|
13
|
+
file_path: Rails.root.join("config/locales/some/right/path/en.yml")
|
14
14
|
end
|
15
15
|
let!(:translation_value_duplicate) do
|
16
16
|
create :translation_value,
|
17
17
|
translation_key: translation_key,
|
18
|
-
file_path: Rails.root.join("config
|
18
|
+
file_path: Rails.root.join("config/locales/some/wrong/path/en.yml")
|
19
19
|
end
|
20
20
|
|
21
21
|
before do
|
@@ -40,7 +40,7 @@ describe AwesomeTranslations::DuplicatesController do
|
|
40
40
|
visit duplicates_path
|
41
41
|
|
42
42
|
expect(page).to have_http_status(:success)
|
43
|
-
expect(
|
43
|
+
expect(page).to have_current_path duplicates_path, ignore_query: true
|
44
44
|
|
45
45
|
find("input[type=checkbox][name='d[#{translation_value_duplicate.id}]']")
|
46
46
|
|
@@ -1,16 +1,16 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
describe AwesomeTranslations::MovalsController do
|
3
|
+
describe AwesomeTranslations::MovalsController do # rubocop:disable RSpec/MultipleMemoizedHelpers
|
4
4
|
let!(:handler_translation) do
|
5
5
|
create :handler_translation,
|
6
6
|
translation_key: translation_key,
|
7
|
-
dir: Rails.root.join("config
|
7
|
+
dir: Rails.root.join("config/locales/some/right/path")
|
8
8
|
end
|
9
9
|
let!(:translation_key) { create :translation_key, key: "some.key" }
|
10
10
|
let!(:translation_value) do
|
11
11
|
create :translation_value,
|
12
12
|
translation_key: translation_key,
|
13
|
-
file_path: Rails.root.join("config
|
13
|
+
file_path: Rails.root.join("config/locales/some/wrong/path/en.yml")
|
14
14
|
end
|
15
15
|
|
16
16
|
let!(:handler_translation_right_path) { create :handler_translation, translation_key: translation_key_right_path, dir: "/some/path" }
|
@@ -34,12 +34,12 @@ describe AwesomeTranslations::MovalsController do
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
describe "#index" do
|
37
|
+
describe "#index" do # rubocop:disable RSpec/MultipleMemoizedHelpers
|
38
38
|
it "renders the page and shows the correct results" do
|
39
39
|
visit movals_path
|
40
40
|
|
41
41
|
expect(page).to have_http_status(:success)
|
42
|
-
expect(
|
42
|
+
expect(page).to have_current_path movals_path, ignore_query: true
|
43
43
|
|
44
44
|
find("input[type=checkbox][value='#{handler_translation.id}']") # Expect to find
|
45
45
|
|
@@ -49,14 +49,14 @@ describe AwesomeTranslations::MovalsController do
|
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
-
describe "#create" do
|
52
|
+
describe "#create" do # rubocop:disable RSpec/MultipleMemoizedHelpers
|
53
53
|
it "moves the checked translations to the right path" do
|
54
54
|
visit movals_path
|
55
55
|
|
56
56
|
find("input[type=submit]").click
|
57
57
|
translation_value.reload
|
58
58
|
|
59
|
-
expect(translation_value.file_path).to eq Rails.root.join("config
|
59
|
+
expect(translation_value.file_path).to eq Rails.root.join("config/locales/some/right/path/en.yml").to_s
|
60
60
|
end
|
61
61
|
end
|
62
62
|
end
|
@@ -3,7 +3,7 @@ require "spec_helper"
|
|
3
3
|
describe AwesomeTranslations::Handlers::FileHandler do
|
4
4
|
let(:handler) { AwesomeTranslations::Handlers::FileHandler.new }
|
5
5
|
|
6
|
-
describe "erb stuff" do
|
6
|
+
describe "erb stuff" do # rubocop:disable RSpec/MultipleMemoizedHelpers
|
7
7
|
let(:users_index_group) { handler.groups.find { |group| group.name == "app/views/users/index.html.haml" } }
|
8
8
|
let(:users_index_translations) { users_index_group.translations }
|
9
9
|
let(:users_partial_test_translations) { handler.groups.find { |group| group.name == "app/views/users/_partial_test.html.erb" }.translations }
|
@@ -36,11 +36,11 @@ describe AwesomeTranslations::Handlers::FileHandler do
|
|
36
36
|
|
37
37
|
it "sets the correct translation path" do
|
38
38
|
danish_translation = layout_translations.find { |t| t.key == "layouts.application.danish" }
|
39
|
-
expect(danish_translation.dir).to eq
|
39
|
+
expect(danish_translation.dir).to eq Rails.root.join("config/locales/awesome_translations/layouts/application").to_s
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
describe "library stuff" do
|
43
|
+
describe "library stuff" do # rubocop:disable RSpec/MultipleMemoizedHelpers
|
44
44
|
let(:group) { handler.groups.find { |group| group.name == "app/models/role.rb" } }
|
45
45
|
let(:mailer_group) { handler.groups.find { |group| group.name == "app/mailers/my_mailer.rb" } }
|
46
46
|
let(:subject_translation) { mailer_group.translations.find { |translation| translation.key == "my_mailer.mailer_action.custom_subject" } }
|
@@ -51,7 +51,7 @@ describe AwesomeTranslations::Handlers::FileHandler do
|
|
51
51
|
let(:update_saved_translation) { users_controller_handler.translations.find { |translation| translation.key == "users.user_was_updated" } }
|
52
52
|
|
53
53
|
it "finds translations made with the t method" do
|
54
|
-
expect(admin_translation).
|
54
|
+
expect(admin_translation).not_to eq nil
|
55
55
|
expect(admin_translation.key).to eq "models.role.administrator"
|
56
56
|
expect(admin_translation.dir).to end_with "spec/dummy/config/locales/awesome_translations/models/role"
|
57
57
|
end
|
@@ -64,8 +64,8 @@ describe AwesomeTranslations::Handlers::FileHandler do
|
|
64
64
|
moderator_translation = group.translations.find { |translation| translation.key == "models.role.moderator" }
|
65
65
|
user_translation = group.translations.find { |translation| translation.key == "models.role.user" }
|
66
66
|
|
67
|
-
expect(moderator_translation).
|
68
|
-
expect(user_translation).
|
67
|
+
expect(moderator_translation).not_to eq nil
|
68
|
+
expect(user_translation).not_to eq nil
|
69
69
|
end
|
70
70
|
|
71
71
|
it "finds helpers translations using helper_t" do
|
@@ -73,7 +73,7 @@ describe AwesomeTranslations::Handlers::FileHandler do
|
|
73
73
|
end
|
74
74
|
|
75
75
|
it "finds translations with the controller_t-method" do
|
76
|
-
expect(update_saved_translation).
|
76
|
+
expect(update_saved_translation).not_to eq nil
|
77
77
|
expect(update_saved_translation.key).to eq "users.user_was_updated"
|
78
78
|
expect(update_saved_translation.dir).to end_with "spec/dummy/config/locales/awesome_translations/users"
|
79
79
|
end
|
@@ -93,7 +93,7 @@ describe AwesomeTranslations::Handlers::FileHandler do
|
|
93
93
|
end
|
94
94
|
|
95
95
|
it "sets the correct translation path" do
|
96
|
-
expect(yes_translation.dir).to eq
|
96
|
+
expect(yes_translation.dir).to eq Rails.root.join("config/locales/awesome_translations").to_s
|
97
97
|
end
|
98
98
|
|
99
99
|
it "detects absolute existing direct translations" do
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
describe AwesomeTranslations::Handlers::ModelHandler do
|
3
|
+
describe AwesomeTranslations::Handlers::ModelHandler do # rubocop:disable RSpec/MultipleMemoizedHelpers
|
4
4
|
let(:model_handler) { AwesomeTranslations::Handlers::ModelHandler.new }
|
5
5
|
let(:groups) { model_handler.groups.to_a }
|
6
6
|
let(:user_group) { model_handler.groups.detect { |group| group.name == "User" } }
|
@@ -9,11 +9,11 @@ describe AwesomeTranslations::Handlers::ModelHandler do
|
|
9
9
|
let(:role_translation_keys) { role_group.translations.map(&:key).to_a }
|
10
10
|
|
11
11
|
it "#groups" do
|
12
|
-
expect(groups.length).to eq
|
12
|
+
expect(groups.length).to eq 5
|
13
13
|
end
|
14
14
|
|
15
|
-
describe "#translations_for_group" do
|
16
|
-
it "
|
15
|
+
describe "#translations_for_group" do # rubocop:disable RSpec/MultipleMemoizedHelpers
|
16
|
+
it "finds the right number of translations" do
|
17
17
|
expect(user_group.translations.to_a.length).to eq 7
|
18
18
|
end
|
19
19
|
|
@@ -6,7 +6,7 @@ describe AwesomeTranslations::Handlers::ValidationsHandler do
|
|
6
6
|
let(:blank_email_translation) { user_group.translations.find { |translation| translation.key.include? "email.blank" } }
|
7
7
|
|
8
8
|
it "#groups" do
|
9
|
-
expect(validations_handler.groups.to_a.length).to eq
|
9
|
+
expect(validations_handler.groups.to_a.length).to eq 5
|
10
10
|
end
|
11
11
|
|
12
12
|
describe "#translations_for_group" do
|
@@ -19,12 +19,12 @@ describe AwesomeTranslations::Handlers::ValidationsHandler do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
it "finds the right directory" do
|
22
|
-
expect(blank_email_translation.dir).to eq
|
22
|
+
expect(blank_email_translation.dir).to eq Rails.root.join("config/locales/awesome_translations/models/user").to_s
|
23
23
|
end
|
24
24
|
|
25
25
|
it "finds confirmation translations" do
|
26
26
|
confirmation_translation = user_group.translations.find { |translation| translation.key.include? "email_confirmation" }
|
27
|
-
expect(confirmation_translation).
|
27
|
+
expect(confirmation_translation).not_to be_blank
|
28
28
|
expect(confirmation_translation.key).to eq "activerecord.errors.models.user.attributes.email_confirmation.confirmation"
|
29
29
|
end
|
30
30
|
end
|
data/spec/handlers_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe AwesomeTranslations::Handlers do
|
4
|
-
it "
|
4
|
+
it "does not include base in list" do
|
5
5
|
AwesomeTranslations::Handlers.list.each do |handler|
|
6
6
|
expect(handler.id.to_s.downcase.include?("base")).to eq false
|
7
7
|
end
|
@@ -6,7 +6,7 @@ describe AwesomeTranslations::CacheDatabaseGenerator do
|
|
6
6
|
let(:db) { cache_database_generator.db }
|
7
7
|
|
8
8
|
before do
|
9
|
-
locales_path = Rails.root.join("config
|
9
|
+
locales_path = Rails.root.join("config/locales")
|
10
10
|
FileUtils.rm_rf(locales_path)
|
11
11
|
Dir.mkdir(locales_path)
|
12
12
|
|
@@ -41,7 +41,7 @@ describe AwesomeTranslations::CacheDatabaseGenerator do
|
|
41
41
|
.where(translation_keys: {key: "activerecord.attributes.user.id"})
|
42
42
|
.first
|
43
43
|
|
44
|
-
expect(translation).
|
44
|
+
expect(translation).not_to eq nil
|
45
45
|
end
|
46
46
|
|
47
47
|
it "#cache_handler_translations" do
|
@@ -53,7 +53,7 @@ describe AwesomeTranslations::CacheDatabaseGenerator do
|
|
53
53
|
.where(translation_keys: {key: "activerecord.attributes.user.id"})
|
54
54
|
.first
|
55
55
|
|
56
|
-
expect(translation).
|
56
|
+
expect(translation).not_to eq nil
|
57
57
|
end
|
58
58
|
end
|
59
59
|
end
|