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.
Files changed (74) hide show
  1. checksums.yaml +5 -5
  2. data/Rakefile +1 -1
  3. data/app/controllers/awesome_translations/clean_ups_controller.rb +1 -1
  4. data/app/controllers/awesome_translations/groups_controller.rb +1 -0
  5. data/app/controllers/awesome_translations/handlers_controller.rb +1 -0
  6. data/app/helpers/awesome_translations/application_helper.rb +0 -1
  7. data/app/models/awesome_translations/group.rb +2 -2
  8. data/app/models/awesome_translations/translated_value.rb +4 -1
  9. data/app/models/awesome_translations/translation.rb +9 -4
  10. data/app/views/awesome_translations/duplicates/index.html.erb +2 -2
  11. data/app/views/awesome_translations/groups/show.html.erb +9 -4
  12. data/app/views/awesome_translations/handler_translations/index.html.erb +21 -6
  13. data/app/views/awesome_translations/handlers/show.html.erb +29 -6
  14. data/app/views/awesome_translations/movals/index.html.erb +2 -2
  15. data/lib/awesome_translations/cache_database_generator/group.rb +10 -3
  16. data/lib/awesome_translations/cache_database_generator/handler.rb +9 -2
  17. data/lib/awesome_translations/cache_database_generator/handler_translation.rb +13 -3
  18. data/lib/awesome_translations/cache_database_generator/translation_key.rb +4 -4
  19. data/lib/awesome_translations/cache_database_generator/translation_value.rb +3 -1
  20. data/lib/awesome_translations/cache_database_generator.rb +2 -2
  21. data/lib/awesome_translations/config.rb +3 -3
  22. data/lib/awesome_translations/engine.rb +0 -4
  23. data/lib/awesome_translations/erb_inspector/file_inspector.rb +7 -7
  24. data/lib/awesome_translations/erb_inspector/translation_inspector.rb +7 -7
  25. data/lib/awesome_translations/erb_inspector.rb +2 -1
  26. data/lib/awesome_translations/global_translator.rb +13 -27
  27. data/lib/awesome_translations/handlers/file_handler.rb +1 -0
  28. data/lib/awesome_translations/handlers/model_handler.rb +1 -1
  29. data/lib/awesome_translations/handlers/validations_handler.rb +4 -4
  30. data/lib/awesome_translations/handlers.rb +1 -0
  31. data/lib/awesome_translations/model_inspector.rb +19 -13
  32. data/lib/awesome_translations/translation_migrator.rb +1 -1
  33. data/lib/awesome_translations/version.rb +1 -1
  34. data/lib/awesome_translations.rb +1 -1
  35. data/lib/tasks/awesome_translations_tasks.rake +1 -1
  36. data/spec/controllers/groups_controller_spec.rb +5 -5
  37. data/spec/controllers/handlers_controller_spec.rb +1 -1
  38. data/spec/dummy/Rakefile +1 -1
  39. data/spec/dummy/app/assets/config/manifest.js +3 -0
  40. data/spec/dummy/app/assets/javascripts/translations.js +1 -0
  41. data/spec/dummy/app/controllers/users_controller.rb +1 -1
  42. data/spec/dummy/app/mailers/my_mailer.rb +1 -1
  43. data/spec/dummy/app/models/application_record.rb +3 -0
  44. data/spec/dummy/app/models/role.rb +1 -1
  45. data/spec/dummy/app/models/user.rb +1 -1
  46. data/spec/dummy/bin/bundle +1 -1
  47. data/spec/dummy/bin/rails +1 -1
  48. data/spec/dummy/config/application.rb +7 -2
  49. data/spec/dummy/config/boot.rb +2 -2
  50. data/spec/dummy/config/environment.rb +1 -1
  51. data/spec/dummy/config.ru +1 -1
  52. data/spec/factories/group.rb +2 -2
  53. data/spec/factories/handler.rb +4 -4
  54. data/spec/factories/handler_translation.rb +5 -5
  55. data/spec/factories/translation_key.rb +1 -1
  56. data/spec/factories/translation_value.rb +3 -3
  57. data/spec/features/clean_ups_spec.rb +1 -1
  58. data/spec/features/duplicates_spec.rb +4 -4
  59. data/spec/features/movals_spec.rb +7 -7
  60. data/spec/handlers/file_handler_spec.rb +8 -8
  61. data/spec/handlers/model_handler_spec.rb +4 -4
  62. data/spec/handlers/validations_handler_spec.rb +3 -3
  63. data/spec/handlers_spec.rb +1 -1
  64. data/spec/lib/cache_database_generator_spec.rb +3 -3
  65. data/spec/lib/erb_inspector/file_inspector_spec.rb +3 -2
  66. data/spec/lib/erb_inspector/translation_inspector_spec.rb +2 -2
  67. data/spec/lib/erb_inspector_spec.rb +5 -5
  68. data/spec/lib/model_inspector_spec.rb +4 -4
  69. data/spec/lib/translation_migrator_spec.rb +2 -2
  70. data/spec/models/awesome_translations/handler_spec.rb +1 -1
  71. data/spec/models/awesome_translations/translation_spec.rb +7 -2
  72. data/spec/spec_helper.rb +8 -6
  73. metadata +76 -94
  74. 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 { |model_inspector| model_inspector.clazz.name == group.name }
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 { |model_inspector| model_inspector.clazz.name == group.name }
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}"
@@ -11,6 +11,7 @@ class AwesomeTranslations::Handlers
11
11
 
12
12
  const_name_snake = "#{match[1]}_handler"
13
13
  next if const_name_snake == "base_handler"
14
+
14
15
  const_name_camel = StringCases.snake_to_camel(const_name_snake)
15
16
 
16
17
  handler = AwesomeTranslations::Handler.new(
@@ -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
- Paperclip::AttachmentRegistry.names_for(@clazz).each do |name|
39
- yield name
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 do |key, reflection|
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
- $stderr.puts "Could not load model in #{model_path}"
129
- $stderr.puts e.inspect
130
- $stderr.puts e.backtrace
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.update_attributes!(file_path: @new_path) if @new_path
47
+ @translation_value.update!(file_path: @new_path) if @new_path
48
48
  end
49
49
 
50
50
  private
@@ -1,3 +1,3 @@
1
1
  module AwesomeTranslations
2
- VERSION = "0.0.56".freeze
2
+ VERSION = "0.0.60".freeze
3
3
  end
@@ -11,6 +11,6 @@ module AwesomeTranslations
11
11
  end
12
12
 
13
13
  def self.load_object_extensions
14
- ::Object.__send__(:include, AwesomeTranslations::ObjectExtensions)
14
+ ::Object.include AwesomeTranslations::ObjectExtensions
15
15
  end
16
16
  end
@@ -5,7 +5,7 @@
5
5
 
6
6
  namespace :awesome_translations do
7
7
  task "install" => :environment do
8
- yml_root = "#{Rails.root}/config/locales/awesome_translations"
8
+ yml_root = Rails.root.join("config/locales/awesome_translations")
9
9
 
10
10
  dirs = [
11
11
  yml_root,
@@ -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", "locales", "awesome_translations", "models").to_s }
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", "locales", "awesome_translations", "date_time", "da.yml").to_s }
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).to_not include model_locales_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).to_not eq nil
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).to_not eq nil
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
@@ -31,7 +31,7 @@ describe AwesomeTranslations::HandlersController do
31
31
  groups = assigns(:groups)
32
32
 
33
33
  expect(all_groups.length).to be > groups.length
34
- expect(groups.length).to eq 4
34
+ expect(groups.length).to eq 5
35
35
  expect(response).to be_success
36
36
  end
37
37
  end
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("../config/application", __FILE__)
4
+ require File.expand_path("config/application", __dir__)
5
5
 
6
6
  Dummy::Application.load_tasks
@@ -0,0 +1,3 @@
1
+ //= link_tree ../images
2
+ //= link_directory ../javascripts .js
3
+ //= link_directory ../stylesheets .css
@@ -1,2 +1,3 @@
1
1
  console.log(I18n.t(".hello_world"))
2
2
  console.log(I18n.t("javascripts.absolute.key"))
3
+ console.log(I18n.t("javascripts.absolute.key_with_args", {some_arg: "Hello", some_other_arg: "World"}))
@@ -22,7 +22,7 @@ class UsersController < ApplicationController
22
22
  def edit; end
23
23
 
24
24
  def update
25
- if @user.update_attributes(user_params)
25
+ if @user.update(user_params)
26
26
  flash[:notice] = controller_t(".user_was_updated")
27
27
  redirect_to user_path(@user)
28
28
  else
@@ -1,4 +1,4 @@
1
- class MyMailer < ActionMailer::Base
1
+ class MyMailer < ActionMailer::Base # rubocop:disable Rails/ApplicationMailer
2
2
  def mailer_action(_user_id)
3
3
  mail(subject: t(".custom_subject"))
4
4
  end
@@ -0,0 +1,3 @@
1
+ class ApplicationRecord < ActiveRecord::Base
2
+ self.abstract_class = true
3
+ end
@@ -1,4 +1,4 @@
1
- class Role < ActiveRecord::Base
1
+ class Role < ApplicationRecord
2
2
  translates :name
3
3
 
4
4
  belongs_to :user
@@ -1,4 +1,4 @@
1
- class User < ActiveRecord::Base
1
+ class User < ApplicationRecord
2
2
  validates :email, presence: true
3
3
  validates :email, uniqueness: true
4
4
  validates :email, length: {in: 2..255}, format: {with: /\A.+@.+\Z/}
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env ruby
2
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", __FILE__)
2
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
3
3
  load Gem.bin_path("bundler", "bundle")
data/spec/dummy/bin/rails CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
- APP_PATH = File.expand_path("../../config/application", __FILE__)
2
+ APP_PATH = File.expand_path("../config/application", __dir__)
3
3
  require_relative "../config/boot"
4
4
  require "rails/commands"
@@ -1,4 +1,4 @@
1
- require File.expand_path("../boot", __FILE__)
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", "locales", "**", "*.{rb,yml}").to_s]
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
@@ -1,5 +1,5 @@
1
1
  # Set up gems listed in the Gemfile.
2
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../../../Gemfile", __FILE__)
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("../../../../lib", __FILE__)
5
+ $LOAD_PATH.unshift File.expand_path("../../../lib", __dir__)
@@ -1,5 +1,5 @@
1
1
  # Load the Rails application.
2
- require File.expand_path("../application", __FILE__)
2
+ require File.expand_path("application", __dir__)
3
3
 
4
4
  # Initialize the Rails application.
5
5
  Dummy::Application.initialize!
data/spec/dummy/config.ru CHANGED
@@ -1,4 +1,4 @@
1
1
  # This file is used by Rack-based servers to start the application.
2
2
 
3
- require ::File.expand_path("../config/environment", __FILE__)
3
+ require ::File.expand_path("config/environment", __dir__)
4
4
  run Rails.application
@@ -2,7 +2,7 @@ FactoryBot.define do
2
2
  factory :group, class: "AwesomeTranslations::CacheDatabaseGenerator::Group" do
3
3
  handler
4
4
 
5
- identifier "tests"
6
- name "Tests"
5
+ identifier { "tests" }
6
+ name { "Tests" }
7
7
  end
8
8
  end
@@ -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 "#{Rails.root}/config/locales/awesome_translations/some/key"
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
@@ -3,6 +3,6 @@ FactoryBot.define do
3
3
  handler
4
4
  group
5
5
 
6
- key "some.key"
6
+ key { "some.key" }
7
7
  end
8
8
  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 "#{Rails.root}/config/locales/some_file.yml"
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: "#{Rails.root}/config/locales/awesome_translations/some_file.yml"
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", "locales", "some", "right", "path")
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", "locales", "some", "right", "path", "en.yml")
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", "locales", "some", "wrong", "path", "en.yml")
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(current_path).to eq duplicates_path
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", "locales", "some", "right", "path")
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", "locales", "some", "wrong", "path", "en.yml")
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(current_path).to eq movals_path
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", "locales", "some", "right", "path", "en.yml").to_s
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 "#{Rails.root}/config/locales/awesome_translations/layouts/application"
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).to_not eq nil
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).to_not eq nil
68
- expect(user_translation).to_not eq nil
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).to_not eq nil
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 "#{Rails.root}/config/locales/awesome_translations"
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 4
12
+ expect(groups.length).to eq 5
13
13
  end
14
14
 
15
- describe "#translations_for_group" do
16
- it "should find the right number of translations" do
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 4
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 "#{Rails.root}/config/locales/awesome_translations/models/user"
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).to_not be_blank
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
@@ -1,7 +1,7 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe AwesomeTranslations::Handlers do
4
- it "should not include base in list" do
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", "locales")
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).to_not eq nil
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).to_not eq nil
56
+ expect(translation).not_to eq nil
57
57
  end
58
58
  end
59
59
  end