From 963cb0192c954f50120d0bcee28e71aea969f324 Mon Sep 17 00:00:00 2001 From: Maciej Litwiniuk Date: Tue, 13 Aug 2024 10:17:08 +0200 Subject: [PATCH 1/4] WIP - v2, rails 7.x support, only ruby 3.2+ --- .gitignore | 1 + .ruby-gemset | 1 - .ruby-version | 2 +- .travis.yml | 17 +- Appraisals | 97 ++-- CHANGELOG.md | 2 + README.md | 16 +- app/models/lit/localization.rb | 16 +- app/services/synchronize_source_service.rb | 19 +- .../_localizations_list.html.erb | 4 +- .../_previous_versions_rows.html.erb | 2 +- app/views/lit/localizations/edit.js.erb | 2 +- .../localizations/previous_versions.js.erb | 2 +- app/views/lit/localizations/update.js.erb | 3 +- app/views/lit/sources/index.html.erb | 58 +-- app/views/lit/sources/show.html.erb | 5 +- .../20180101010101_lit_create_lit_locales.rb | 5 +- ...010102_lit_create_lit_localization_keys.rb | 5 +- ...0101010103_lit_create_lit_localizations.rb | 5 +- ...ted_and_is_starred_to_localization_keys.rb | 10 +- ...0101010105_lit_add_is_hidden_to_locales.rb | 5 +- ...06_lit_create_lit_localization_versions.rb | 5 +- .../20180101010107_lit_create_lit_sources.rb | 5 +- ..._lit_create_lit_incomming_localizations.rb | 5 +- ...09_lit_add_sync_complete_to_lit_sources.rb | 5 +- ...lit_add_is_deleted_to_localization_keys.rb | 6 +- ...ion_key_is_deleted_to_localization_keys.rb | 6 +- ...d_is_visited_again_to_localization_keys.rb | 6 +- ...ey_locale_unique_index_to_localizations.rb | 6 +- gemfiles/rails_5.2.gemfile.lock | 283 ----------- gemfiles/rails_6.0.gemfile | 23 - gemfiles/rails_6.0.gemfile.lock | 299 ------------ gemfiles/rails_6.1.gemfile.lock | 348 ------------- .../{rails_6.1.gemfile => rails_7.0.gemfile} | 10 +- gemfiles/rails_7.0.gemfile.lock | 431 ++++++++++++++++ .../{rails_5.2.gemfile => rails_7.1.gemfile} | 10 +- gemfiles/rails_7.1.gemfile.lock | 460 ++++++++++++++++++ lib/lit.rb | 24 +- lib/lit/cloud_translation/providers/google.rb | 43 +- lib/lit/cloud_translation/providers/yandex.rb | 22 +- lib/lit/i18n_backend.rb | 77 ++- lib/lit/version.rb | 8 +- lit.gemspec | 43 +- test/dummy/config/initializers/lit.rb | 8 +- test/dummy/db/schema.rb | 75 ++- .../api/v1/localizations_controller_test.rb | 25 +- ...incomming_localizations_controller_test.rb | 16 +- .../functional/lit/sources_controller_test.rb | 54 +- test/functional/welcome_controller_test.rb | 27 +- test/test_helper.rb | 35 +- test/unit/i18n_backend_test.rb | 38 +- .../cloud_translation/providers/examples.rb | 45 +- .../providers/google_test.rb | 59 ++- test/unit/lit/incomming_localization_test.rb | 56 +-- test/unit/lit/source_test.rb | 40 +- test/unit/lit_behaviour_test.rb | 234 ++++----- 56 files changed, 1501 insertions(+), 1613 deletions(-) delete mode 100644 .ruby-gemset delete mode 100644 gemfiles/rails_5.2.gemfile.lock delete mode 100644 gemfiles/rails_6.0.gemfile delete mode 100644 gemfiles/rails_6.0.gemfile.lock delete mode 100644 gemfiles/rails_6.1.gemfile.lock rename gemfiles/{rails_6.1.gemfile => rails_7.0.gemfile} (63%) create mode 100644 gemfiles/rails_7.0.gemfile.lock rename gemfiles/{rails_5.2.gemfile => rails_7.1.gemfile} (63%) create mode 100644 gemfiles/rails_7.1.gemfile.lock diff --git a/.gitignore b/.gitignore index 65520262..9d53b199 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ test/dummy/tmp/ test/dummy/.sass-cache .sass-cache/ /lit-*.gem +/*.json **.DS_Store Gemfile.lock vendor/bundle diff --git a/.ruby-gemset b/.ruby-gemset deleted file mode 100644 index 5bc6f303..00000000 --- a/.ruby-gemset +++ /dev/null @@ -1 +0,0 @@ -lit diff --git a/.ruby-version b/.ruby-version index a4dd9dba..5ae69bd5 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.7.4 +3.2.5 diff --git a/.travis.yml b/.travis.yml index 540bb636..9a1f6935 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,15 +1,14 @@ language: ruby -jobs: - exclude: - - rvm: 3.0.1 - gemfile: gemfiles/rails_5.2.gemfile +# jobs: +# exclude: +# - rvm: 3.0.1 +# gemfile: gemfiles/rails_5.2.gemfile rvm: - - 2.7.3 - - 3.0.1 + - 3.2.5 + - 3.3.3 gemfile: - - gemfiles/rails_5.2.gemfile - - gemfiles/rails_6.0.gemfile - - gemfiles/rails_6.1.gemfile + - gemfiles/rails_7.0.gemfile + - gemfiles/rails_7.1.gemfile services: - postgresql - redis-server diff --git a/Appraisals b/Appraisals index 01263a2a..86ca236e 100644 --- a/Appraisals +++ b/Appraisals @@ -1,62 +1,45 @@ -appraise 'rails-5.2' do +appraise 'rails-7.0' do source 'https://rubygems.org' - gem 'rails', '~> 5.2.0' - gem 'devise' - gem 'pg', '~> 1.2.3' - gem 'redis' - gem 'capybara' - gem 'database_cleaner' - gem 'test_declarative' - gem 'mocha' - gem 'webmock' - gem 'sass-rails' - gem 'jquery-rails' - gem 'coffee-rails' - gem 'pry-rails' - gem 'rails-controller-testing' - gem 'minitest' - gem 'm', '~> 1.5.0' - gem 'google-cloud-translate', '~> 1.2.4' + gem "rails", "~> 7.0.8.4" + gem "devise" + gem "pg", "~> 1.0" + gem "redis" + gem "capybara" + gem "database_cleaner" + gem "test_declarative" + gem "mocha" + gem "webmock" + gem "sass-rails" + gem "jquery-rails" + gem "coffee-rails" + gem "pry-rails" + gem "pry-stack_explorer" + gem "rails-controller-testing" + gem "minitest" + gem "minitest-vcr", github: "manuelvanrijn/minitest-vcr" + gem "m", "~> 1.6" + gem "google-cloud-translate", "~> 2.0" end -appraise 'rails-6.0' do +appraise 'rails-7.1' do source 'https://rubygems.org' - gem 'rails', '~> 6.0.3' - gem 'devise' - gem 'pg', '~> 1.2.3' - gem 'redis' - gem 'capybara' - gem 'database_cleaner' - gem 'test_declarative' - gem 'mocha' - gem 'webmock' - gem 'sass-rails' - gem 'jquery-rails' - gem 'coffee-rails' - gem 'pry-rails' - gem 'rails-controller-testing' - gem 'minitest' - gem 'm', '~> 1.5.0' - gem 'google-cloud-translate', '~> 1.2.4' -end - -appraise 'rails-6.1' do - source 'https://rubygems.org' - gem 'rails', '~> 6.1.4.1' - gem 'devise' - gem 'pg', '~> 1.2.3' - gem 'redis' - gem 'capybara' - gem 'database_cleaner' - gem 'test_declarative' - gem 'mocha' - gem 'webmock' - gem 'sass-rails' - gem 'jquery-rails' - gem 'coffee-rails' - gem 'pry-rails' - gem 'rails-controller-testing' - gem 'minitest' - gem 'm', '~> 1.5.0' - gem 'google-cloud-translate', '~> 2.1.2' + gem "rails", "~> 7.1.3.4" + gem "devise" + gem "pg", "~> 1.0" + gem "redis" + gem "capybara" + gem "database_cleaner" + gem "test_declarative" + gem "mocha" + gem "webmock" + gem "sass-rails" + gem "jquery-rails" + gem "coffee-rails" + gem "pry-rails" + gem "pry-stack_explorer" + gem "rails-controller-testing" + gem "minitest" + gem "minitest-vcr", github: "manuelvanrijn/minitest-vcr" + gem "m", "~> 1.6" + gem "google-cloud-translate", "~> 2.0" end diff --git a/CHANGELOG.md b/CHANGELOG.md index 86e86ab4..7e104fbf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ## [Unreleased] ## [WIP] +- Defaults to ruby 3.2.5+ +- Supports Rails 7.x only, drops support for older versions - Efforts to use Vanilla JS and remove jQuery [WIP] - Fix for `Undefined method 'id' for False class` error in view partial [WIP] diff --git a/README.md b/README.md index 6552dcfa..79c5075c 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ### Rails i18n web interface Translate your apps with pleasure (sort of...) and for free. It's simple i18n -web interface, build on top of twitter bootstrap, that one may find helpful in +web interface,that one may find helpful in translating app by non-technicals. Highly inspired by Copycopter by thoughtbot. @@ -40,6 +40,10 @@ gem 'lit' For Ruby < 1.9 use `gem 'lit', '= 0.2.4'`, as next versions introduced new ruby hash syntax. + For Ruby < 3.x use `gem 'lit', '< 2.0'` + + Starting with version 2.x support for Rails < 7.0 and Ruby < 3.2.5 has been dropped. + 2. run `bundle install` 3. Add `config.i18n.available_locales = [...]` to `application.rb` - it's required to precompile appropriate language flags in lit backend. @@ -133,10 +137,6 @@ Lit::CloudTranslation.provider = Lit::CloudTranslation::Providers::Google ...and make sure you have this in your Gemfile: ``` -gem 'google-cloud-translate', '~> 1.2.4' -``` -...we also support V2 of Google Cloud Translate gem, should you need it: -``` gem 'google-cloud-translate', '~> 2.1.2' ``` @@ -185,6 +185,12 @@ Lit::CloudTranslation.configure do |config| end ``` +### 1.x -> 2.0.x upgrade guide + +Also applies to upgrading from `1.x` versions. + +1. Specify `gem 'lit', '~> 2.0.0'` in your Gemfile and run `bundle update lit`. + ### 0.3 -> 1.0 upgrade guide Also applies to upgrading from `0.4.pre.alpha` versions. diff --git a/app/models/lit/localization.rb b/app/models/lit/localization.rb index e1659fd4..6c6c19d9 100644 --- a/app/models/lit/localization.rb +++ b/app/models/lit/localization.rb @@ -8,14 +8,14 @@ class Localization < Lit::Base scope :not_changed, -> { where is_changed: false } # @HACK: dirty, find a way to round date to full second - scope :after, lambda { |dt| where('updated_at >= ?', dt + 1.second).where(is_changed: true) } - scope :active, lambda { joins(:localization_key).where(Lit::LocalizationKey.table_name => { is_deleted: false }) } + scope :after, ->(dt) { where("updated_at >= ?", dt + 1.second).where(is_changed: true) } + scope :active, -> { joins(:localization_key).where(Lit::LocalizationKey.table_name => {is_deleted: false}) } ## ASSOCIATIONS belongs_to :locale, required: true belongs_to :localization_key, touch: true, required: true has_many :localization_versions, dependent: :destroy - has_many :versions, class_name: '::Lit::LocalizationVersion' + has_many :versions, class_name: "::Lit::LocalizationVersion" ## DELEGATIONS delegate :is_deleted, to: :localization_key @@ -39,11 +39,11 @@ def to_s end def full_key - full_key_str || [locale.locale, localization_key.localization_key].join('.') + full_key_str || [locale.locale, localization_key.localization_key].join(".") end def translation - is_changed? && !translated_value.nil? ? translated_value : default_value + (is_changed? && !translated_value.nil?) ? translated_value : default_value end def value @@ -63,11 +63,12 @@ def locale_str end def last_change - updated_at.to_s(:db) + updated_at.to_fs(:db) end def update_default_value(value) return true if persisted? && default_value == value + if persisted? update(default_value: value) else @@ -84,8 +85,9 @@ def update_cache def create_version return if translated_value.blank? + translated_value = translated_value_was || default_value - localization_versions.new(translated_value: translated_value) + localization_versions.new(translated_value:) end end end diff --git a/app/services/synchronize_source_service.rb b/app/services/synchronize_source_service.rb index 8a12faff..a5d78eb7 100644 --- a/app/services/synchronize_source_service.rb +++ b/app/services/synchronize_source_service.rb @@ -11,28 +11,29 @@ def execute private def synchronize_localizations - after_date = @source.last_updated_at&.to_s(:db) + after_date = @source.last_updated_at&.to_fs(:db) result = interactor.send_request Lit::Source::LOCALIZATIONS_PATH, after: after_date return unless result&.is_a?(Array) + result.each { |loc| synchronize_localization loc } end def synchronize_localization(loc) inc_loc = find_incomming_localization(loc) inc_loc.source = @source - inc_loc.locale_str = loc['locale_str'] - inc_loc.locale = Lit::Locale.find_by(locale: loc['locale_str']) - inc_loc.localization_key_str = loc['localization_key_str'] + inc_loc.locale_str = loc["locale_str"] + inc_loc.locale = Lit::Locale.find_by(locale: loc["locale_str"]) + inc_loc.localization_key_str = loc["localization_key_str"] inc_loc.localization_key_is_deleted = localization_key_deleted?(loc) inc_loc.localization_key = find_localization_key(inc_loc) - inc_loc.translated_value = loc['value'] - return if inc_loc.duplicated?(loc['value']) + inc_loc.translated_value = loc["value"] + return if inc_loc.duplicated?(loc["value"]) inc_loc.save! end def find_incomming_localization(localization) - Lit::IncommingLocalization.find_or_initialize_by(incomming_id: localization['id']) + Lit::IncommingLocalization.find_or_initialize_by(incomming_id: localization["id"]) end def find_localization_key(inc_loc) @@ -40,7 +41,7 @@ def find_localization_key(inc_loc) end def localization_key_deleted?(loc) - loc['localization_key_is_deleted'] || false + loc["localization_key_is_deleted"] || false end def update_timestamps @@ -50,7 +51,7 @@ def update_timestamps end def fetch_last_change - interactor.send_request(Lit::Source::LAST_CHANGE_PATH)['last_change'] + interactor.send_request(Lit::Source::LAST_CHANGE_PATH)["last_change"] end def interactor diff --git a/app/views/lit/localization_keys/_localizations_list.html.erb b/app/views/lit/localization_keys/_localizations_list.html.erb index 8c245b37..6d5e284a 100644 --- a/app/views/lit/localization_keys/_localizations_list.html.erb +++ b/app/views/lit/localization_keys/_localizations_list.html.erb @@ -46,7 +46,7 @@ <% if localization %> - <%= draw_icon 'clock-o', title: "Last updated at #{localization.updated_at.to_s(:db)}" %> + <%= draw_icon 'clock-o', title: "Last updated at #{localization.updated_at.to_fs(:db)}" %> <%= link_to lit.previous_versions_localization_key_localization_path(lk, localization, format: :js), class: "js-show_prev_versions #{'hidden' unless versions?(localization)}", remote: true do %> <%= draw_icon 'random', title: I18n.t('lit.common.previous_versions', default: 'Previous versions') %> <% end %> @@ -78,7 +78,7 @@ Note: you might not have access to those pages! diff --git a/app/views/lit/localizations/_previous_versions_rows.html.erb b/app/views/lit/localizations/_previous_versions_rows.html.erb index 8128dc08..2e6d162b 100644 --- a/app/views/lit/localizations/_previous_versions_rows.html.erb +++ b/app/views/lit/localizations/_previous_versions_rows.html.erb @@ -7,7 +7,7 @@ <% @versions.each do |v| %> - <%= render :partial=>"/lit/localization_keys/localization_row", formats: ['html'], :locals=>{:localization=>v.translated_value} %> + <%= render partial: "lit/localization_keys/localization_row", locals: {localization: v.translated_value} %> <%= I18n.l v.created_at, format: :long %> diff --git a/app/views/lit/localizations/edit.js.erb b/app/views/lit/localizations/edit.js.erb index 37ed6b6d..292e79d3 100644 --- a/app/views/lit/localizations/edit.js.erb +++ b/app/views/lit/localizations/edit.js.erb @@ -1,6 +1,6 @@ var $row = $('td.localization_row[data-id="<%= @localization.id %>"]'); $row.data('editing', 1); -$row.html("<%= ejs render(partial: 'form', formats: ['html']) %>"); +$row.html("<%= ejs render(partial: 'form') %>"); $row.find('textarea').focus(); <% if @localization.full_key.ends_with?('_html') -%> $row.find('.wysiwyg_switch').click(); diff --git a/app/views/lit/localizations/previous_versions.js.erb b/app/views/lit/localizations/previous_versions.js.erb index 5e8e37f3..ee54f0fe 100644 --- a/app/views/lit/localizations/previous_versions.js.erb +++ b/app/views/lit/localizations/previous_versions.js.erb @@ -1,3 +1,3 @@ var row = $('.localization_versions_row[data-id="<%= @localization.id %>"]'); row.removeClass('hidden'); -row.children('td').html("<%= j render(:partial=>'previous_versions_rows', formats: ['html'], :locals=>{:localization=>@localization, :versions=>@versions}) %>"); +row.children('td').html("<%= j render(partial: 'lit/localizations/previous_versions_rows', locals: {localization: @localization, versions: @versions}) %>"); diff --git a/app/views/lit/localizations/update.js.erb b/app/views/lit/localizations/update.js.erb index ddebae21..c7d7d7f8 100644 --- a/app/views/lit/localizations/update.js.erb +++ b/app/views/lit/localizations/update.js.erb @@ -1,6 +1,5 @@ var $row = $('td.localization_row[data-id="<%= @localization.id %>"]'); $row.data('editing', 0); -$row.html("<%= ejs render(:partial=>"/lit/localization_keys/localization_row", formats: ['html'], :locals=>{:localization=>@localization.translated_value }) %>"); +$row.html("<%= ejs render(partial: "/lit/localization_keys/localization_row", locals: {localization: @localization.translated_value }) %>"); $row.siblings().find('.js-show_prev_versions').removeClass('hidden'); $('a.change_completed_<%= @localization.id %> input[type=checkbox]').prop("checked", true); - diff --git a/app/views/lit/sources/index.html.erb b/app/views/lit/sources/index.html.erb index 851b884f..0662a814 100644 --- a/app/views/lit/sources/index.html.erb +++ b/app/views/lit/sources/index.html.erb @@ -1,5 +1,4 @@

Synchronization sources

- @@ -7,36 +6,33 @@ - -<% @sources.each do |source| %> - - - - - - -<% end %> + <% @sources.each do |source| %> + + + + + + + <% end %>
IdentifierLast change (remote)
<%= link_to source.identifier, lit.source_path(source) %><%= source.last_updated_at.to_s(:db) unless source.last_updated_at.nil? %><%= source.last_change %> - <%= link_to lit.source_incomming_localizations_path(source), :title=>t('lit.common.browse_incomming', :default=>"Browse incomming localizations") do %> - <%= draw_icon 'search' %> - <% end %> - <%= link_to lit.synchronize_source_path(source), :title=>t('lit.common.synchronize', :default=>"Synchronize") do %> - <%= draw_icon 'refresh' %> - <% end %> - <%= link_to lit.source_path(source), :title=>t('lit.common.show', :default=>"Show") do %> - <%= draw_icon 'zoom-in' %> - <% end %> - <%= link_to lit.edit_source_path(source), :title=>t('lit.common.edit', :default=>"Edit") do %> - <%= draw_icon 'pencil' %> - <% end %> - <%= link_to lit.touch_source_path(source), :title=>t('lit.common.touch', :default=>"Touch (update) last_updated_at"), :method => :put, :data => { :confirm => 'Are you sure?' } do %> - <%= draw_icon 'clock-o' %> - <% end %> - <%= link_to lit.source_path(source), :method => :delete, :data => { :confirm => 'Are you sure?' }, :title=>t('lit.common.delete', :default=>"Delete") do %> - <%= draw_icon 'trash-o' %> - <% end %> -
<%= link_to source.identifier, lit.source_path(source) %><%= source.last_updated_at.to_fs(:db) unless source.last_updated_at.nil? %><%= source.last_change %> + <%= link_to lit.source_incomming_localizations_path(source), :title=>t('lit.common.browse_incomming', :default=>"Browse incomming localizations") do %> + <%= draw_icon 'search' %> + <% end %> + <%= link_to lit.synchronize_source_path(source), :title=>t('lit.common.synchronize', :default=>"Synchronize") do %> + <%= draw_icon 'refresh' %> + <% end %> + <%= link_to lit.source_path(source), :title=>t('lit.common.show', :default=>"Show") do %> + <%= draw_icon 'zoom-in' %> + <% end %> + <%= link_to lit.edit_source_path(source), :title=>t('lit.common.edit', :default=>"Edit") do %> + <%= draw_icon 'pencil' %> + <% end %> + <%= link_to lit.touch_source_path(source), :title=>t('lit.common.touch', :default=>"Touch (update) last_updated_at"), :method => :put, :data => { :confirm => 'Are you sure?' } do %> + <%= draw_icon 'clock-o' %> + <% end %> + <%= link_to lit.source_path(source), :method => :delete, :data => { :confirm => 'Are you sure?' }, :title=>t('lit.common.delete', :default=>"Delete") do %> + <%= draw_icon 'trash-o' %> + <% end %> +
-
- <%= link_to 'New Source', new_source_path %> diff --git a/app/views/lit/sources/show.html.erb b/app/views/lit/sources/show.html.erb index 359226ea..8ca4e37b 100644 --- a/app/views/lit/sources/show.html.erb +++ b/app/views/lit/sources/show.html.erb @@ -1,5 +1,4 @@

<%= notice %>

- Indetifier: <%= @source.identifier %>
@@ -10,10 +9,8 @@ <%= @source.api_key %>
Last updated at: -<%= @source.last_updated_at.to_s(:db) unless @source.last_updated_at.nil? %> +<%= @source.last_updated_at.to_fs(:db) unless @source.last_updated_at.nil? %> <%= link_to '(touch!)', touch_source_path(@source), :method => :put, :data => { :confirm => 'Are you sure?' } %>
- - <%= link_to 'Edit', edit_source_path(@source) %> | <%= link_to 'Back', sources_path %> diff --git a/db/migrate/20180101010101_lit_create_lit_locales.rb b/db/migrate/20180101010101_lit_create_lit_locales.rb index 6895c75d..ec65d873 100644 --- a/db/migrate/20180101010101_lit_create_lit_locales.rb +++ b/db/migrate/20180101010101_lit_create_lit_locales.rb @@ -1,8 +1,7 @@ -class LitCreateLitLocales < Rails::VERSION::MAJOR >= 5 ? - ActiveRecord::Migration[4.2] : - ActiveRecord::Migration +class LitCreateLitLocales < ActiveRecord::Migration[7.0] def up return if table_exists?(:lit_locales) + create_table :lit_locales do |t| t.string :locale diff --git a/db/migrate/20180101010102_lit_create_lit_localization_keys.rb b/db/migrate/20180101010102_lit_create_lit_localization_keys.rb index 434ab7d9..277dc90e 100644 --- a/db/migrate/20180101010102_lit_create_lit_localization_keys.rb +++ b/db/migrate/20180101010102_lit_create_lit_localization_keys.rb @@ -1,8 +1,7 @@ -class LitCreateLitLocalizationKeys < Rails::VERSION::MAJOR >= 5 ? - ActiveRecord::Migration[4.2] : - ActiveRecord::Migration +class LitCreateLitLocalizationKeys < ActiveRecord::Migration[7.0] def up return if table_exists?(:lit_localization_keys) + create_table :lit_localization_keys do |t| t.string :localization_key diff --git a/db/migrate/20180101010103_lit_create_lit_localizations.rb b/db/migrate/20180101010103_lit_create_lit_localizations.rb index ae759272..e1d56e17 100644 --- a/db/migrate/20180101010103_lit_create_lit_localizations.rb +++ b/db/migrate/20180101010103_lit_create_lit_localizations.rb @@ -1,8 +1,7 @@ -class LitCreateLitLocalizations < Rails::VERSION::MAJOR >= 5 ? - ActiveRecord::Migration[4.2] : - ActiveRecord::Migration +class LitCreateLitLocalizations < ActiveRecord::Migration[7.0] def up return if table_exists?(:lit_localizations) + create_table :lit_localizations do |t| t.integer :locale_id t.integer :localization_key_id diff --git a/db/migrate/20180101010104_lit_add_is_completed_and_is_starred_to_localization_keys.rb b/db/migrate/20180101010104_lit_add_is_completed_and_is_starred_to_localization_keys.rb index 9d8f4452..6d1769ad 100644 --- a/db/migrate/20180101010104_lit_add_is_completed_and_is_starred_to_localization_keys.rb +++ b/db/migrate/20180101010104_lit_add_is_completed_and_is_starred_to_localization_keys.rb @@ -1,13 +1,11 @@ -class LitAddIsCompletedAndIsStarredToLocalizationKeys < Rails::VERSION::MAJOR >= 5 ? - ActiveRecord::Migration[4.2] : - ActiveRecord::Migration +class LitAddIsCompletedAndIsStarredToLocalizationKeys < ActiveRecord::Migration[7.0] def up unless column_exists?(:lit_localization_keys, :is_completed) add_column :lit_localization_keys, :is_completed, :boolean, default: false end - unless column_exists?(:lit_localization_keys, :is_starred) - add_column :lit_localization_keys, :is_starred, :boolean, default: false - end + return if column_exists?(:lit_localization_keys, :is_starred) + + add_column :lit_localization_keys, :is_starred, :boolean, default: false end def down diff --git a/db/migrate/20180101010105_lit_add_is_hidden_to_locales.rb b/db/migrate/20180101010105_lit_add_is_hidden_to_locales.rb index 13760fab..7d1e5e83 100644 --- a/db/migrate/20180101010105_lit_add_is_hidden_to_locales.rb +++ b/db/migrate/20180101010105_lit_add_is_hidden_to_locales.rb @@ -1,8 +1,7 @@ -class LitAddIsHiddenToLocales < Rails::VERSION::MAJOR >= 5 ? - ActiveRecord::Migration[4.2] : - ActiveRecord::Migration +class LitAddIsHiddenToLocales < ActiveRecord::Migration[7.0] def up return if column_exists?(:lit_locales, :is_hidden) + add_column :lit_locales, :is_hidden, :boolean, default: false end diff --git a/db/migrate/20180101010106_lit_create_lit_localization_versions.rb b/db/migrate/20180101010106_lit_create_lit_localization_versions.rb index 074e294b..8bf983f9 100644 --- a/db/migrate/20180101010106_lit_create_lit_localization_versions.rb +++ b/db/migrate/20180101010106_lit_create_lit_localization_versions.rb @@ -1,8 +1,7 @@ -class LitCreateLitLocalizationVersions < Rails::VERSION::MAJOR >= 5 ? - ActiveRecord::Migration[4.2] : - ActiveRecord::Migration +class LitCreateLitLocalizationVersions < ActiveRecord::Migration[7.0] def up return if table_exists?(:lit_localization_versions) + create_table :lit_localization_versions do |t| t.text :translated_value t.integer :localization_id diff --git a/db/migrate/20180101010107_lit_create_lit_sources.rb b/db/migrate/20180101010107_lit_create_lit_sources.rb index a2a24f40..ff033ea6 100644 --- a/db/migrate/20180101010107_lit_create_lit_sources.rb +++ b/db/migrate/20180101010107_lit_create_lit_sources.rb @@ -1,8 +1,7 @@ -class LitCreateLitSources < Rails::VERSION::MAJOR >= 5 ? - ActiveRecord::Migration[4.2] : - ActiveRecord::Migration +class LitCreateLitSources < ActiveRecord::Migration[7.0] def up return if table_exists?(:lit_sources) + create_table :lit_sources do |t| t.string :identifier t.string :url diff --git a/db/migrate/20180101010108_lit_create_lit_incomming_localizations.rb b/db/migrate/20180101010108_lit_create_lit_incomming_localizations.rb index 288d8514..2237622f 100644 --- a/db/migrate/20180101010108_lit_create_lit_incomming_localizations.rb +++ b/db/migrate/20180101010108_lit_create_lit_incomming_localizations.rb @@ -1,8 +1,7 @@ -class LitCreateLitIncommingLocalizations < Rails::VERSION::MAJOR >= 5 ? - ActiveRecord::Migration[4.2] : - ActiveRecord::Migration +class LitCreateLitIncommingLocalizations < ActiveRecord::Migration[7.0] def up return if table_exists?(:lit_incomming_localizations) + create_table :lit_incomming_localizations do |t| t.text :translated_value t.integer :locale_id diff --git a/db/migrate/20180101010109_lit_add_sync_complete_to_lit_sources.rb b/db/migrate/20180101010109_lit_add_sync_complete_to_lit_sources.rb index 401398ec..a13d6bec 100644 --- a/db/migrate/20180101010109_lit_add_sync_complete_to_lit_sources.rb +++ b/db/migrate/20180101010109_lit_add_sync_complete_to_lit_sources.rb @@ -1,8 +1,7 @@ -class LitAddSyncCompleteToLitSources < Rails::VERSION::MAJOR >= 5 ? - ActiveRecord::Migration[4.2] : - ActiveRecord::Migration +class LitAddSyncCompleteToLitSources < ActiveRecord::Migration[7.0] def up return if column_exists?(:lit_sources, :sync_complete) + add_column :lit_sources, :sync_complete, :boolean end diff --git a/db/migrate/20181017123839_lit_add_is_deleted_to_localization_keys.rb b/db/migrate/20181017123839_lit_add_is_deleted_to_localization_keys.rb index 779fcf90..1f960c6f 100644 --- a/db/migrate/20181017123839_lit_add_is_deleted_to_localization_keys.rb +++ b/db/migrate/20181017123839_lit_add_is_deleted_to_localization_keys.rb @@ -1,8 +1,6 @@ -class LitAddIsDeletedToLocalizationKeys < Rails::VERSION::MAJOR >= 5 ? - ActiveRecord::Migration[4.2] : - ActiveRecord::Migration +class LitAddIsDeletedToLocalizationKeys < ActiveRecord::Migration[7.0] def change add_column :lit_localization_keys, :is_deleted, :boolean, - default: false, null: false + default: false, null: false end end diff --git a/db/migrate/20181018075955_lit_add_localization_key_is_deleted_to_localization_keys.rb b/db/migrate/20181018075955_lit_add_localization_key_is_deleted_to_localization_keys.rb index fed4b4a9..079d978e 100644 --- a/db/migrate/20181018075955_lit_add_localization_key_is_deleted_to_localization_keys.rb +++ b/db/migrate/20181018075955_lit_add_localization_key_is_deleted_to_localization_keys.rb @@ -1,8 +1,6 @@ -class LitAddLocalizationKeyIsDeletedToLocalizationKeys < Rails::VERSION::MAJOR >= 5 ? - ActiveRecord::Migration[4.2] : - ActiveRecord::Migration +class LitAddLocalizationKeyIsDeletedToLocalizationKeys < ActiveRecord::Migration[7.0] def change add_column :lit_incomming_localizations, :localization_key_is_deleted, - :boolean, null: false, default: false + :boolean, null: false, default: false end end diff --git a/db/migrate/20181030111522_lit_add_is_visited_again_to_localization_keys.rb b/db/migrate/20181030111522_lit_add_is_visited_again_to_localization_keys.rb index 654e2530..e15aaa9c 100644 --- a/db/migrate/20181030111522_lit_add_is_visited_again_to_localization_keys.rb +++ b/db/migrate/20181030111522_lit_add_is_visited_again_to_localization_keys.rb @@ -1,8 +1,6 @@ -class LitAddIsVisitedAgainToLocalizationKeys < Rails::VERSION::MAJOR >= 5 ? - ActiveRecord::Migration[4.2] : - ActiveRecord::Migration +class LitAddIsVisitedAgainToLocalizationKeys < ActiveRecord::Migration[7.0] def change add_column :lit_localization_keys, :is_visited_again, :boolean, - null: false, default: false + null: false, default: false end end diff --git a/db/migrate/20181129103819_lit_add_localization_key_locale_unique_index_to_localizations.rb b/db/migrate/20181129103819_lit_add_localization_key_locale_unique_index_to_localizations.rb index b44ccd11..185edf53 100644 --- a/db/migrate/20181129103819_lit_add_localization_key_locale_unique_index_to_localizations.rb +++ b/db/migrate/20181129103819_lit_add_localization_key_locale_unique_index_to_localizations.rb @@ -1,7 +1,5 @@ -class LitAddLocalizationKeyLocaleUniqueIndexToLocalizations < Rails::VERSION::MAJOR >= 5 ? - ActiveRecord::Migration[4.2] : - ActiveRecord::Migration +class LitAddLocalizationKeyLocaleUniqueIndexToLocalizations < ActiveRecord::Migration[7.0] def change - add_index :lit_localizations, [:localization_key_id, :locale_id], unique: true + add_index :lit_localizations, %i[localization_key_id locale_id], unique: true end end diff --git a/gemfiles/rails_5.2.gemfile.lock b/gemfiles/rails_5.2.gemfile.lock deleted file mode 100644 index 10012374..00000000 --- a/gemfiles/rails_5.2.gemfile.lock +++ /dev/null @@ -1,283 +0,0 @@ -PATH - remote: .. - specs: - lit (1.1.6) - coffee-rails - emoji_flag - jquery-rails - rails (>= 5.2.0) - sass-rails - -GEM - remote: https://rubygems.org/ - specs: - actioncable (5.2.6) - actionpack (= 5.2.6) - nio4r (~> 2.0) - websocket-driver (>= 0.6.1) - actionmailer (5.2.6) - actionpack (= 5.2.6) - actionview (= 5.2.6) - activejob (= 5.2.6) - mail (~> 2.5, >= 2.5.4) - rails-dom-testing (~> 2.0) - actionpack (5.2.6) - actionview (= 5.2.6) - activesupport (= 5.2.6) - rack (~> 2.0, >= 2.0.8) - rack-test (>= 0.6.3) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.2.6) - activesupport (= 5.2.6) - builder (~> 3.1) - erubi (~> 1.4) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (5.2.6) - activesupport (= 5.2.6) - globalid (>= 0.3.6) - activemodel (5.2.6) - activesupport (= 5.2.6) - activerecord (5.2.6) - activemodel (= 5.2.6) - activesupport (= 5.2.6) - arel (>= 9.0) - activestorage (5.2.6) - actionpack (= 5.2.6) - activerecord (= 5.2.6) - marcel (~> 1.0.0) - activesupport (5.2.6) - concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 0.7, < 2) - minitest (~> 5.1) - tzinfo (~> 1.1) - addressable (2.7.0) - public_suffix (>= 2.0.2, < 5.0) - appraisal (2.4.0) - bundler - rake - thor (>= 0.14.0) - arel (9.0.0) - bcrypt (3.1.16) - builder (3.2.4) - byebug (11.1.3) - capybara (3.35.3) - addressable - mini_mime (>= 0.1.3) - nokogiri (~> 1.8) - rack (>= 1.6.0) - rack-test (>= 0.6.3) - regexp_parser (>= 1.5, < 3.0) - xpath (~> 3.2) - coderay (1.1.3) - coffee-rails (5.0.0) - coffee-script (>= 2.2.0) - railties (>= 5.2.0) - coffee-script (2.4.1) - coffee-script-source - execjs - coffee-script-source (1.12.2) - concurrent-ruby (1.1.9) - crack (0.4.5) - rexml - crass (1.0.6) - database_cleaner (2.0.1) - database_cleaner-active_record (~> 2.0.0) - database_cleaner-active_record (2.0.0) - activerecord (>= 5.a) - database_cleaner-core (~> 2.0.0) - database_cleaner-core (2.0.1) - devise (4.7.3) - bcrypt (~> 3.0) - orm_adapter (~> 0.1) - railties (>= 4.1.0) - responders - warden (~> 1.2.3) - emoji_flag (0.1.1) - erubi (1.10.0) - execjs (2.7.0) - faraday (0.17.4) - multipart-post (>= 1.2, < 3) - ffi (1.15.0) - globalid (1.0.0) - activesupport (>= 5.0) - google-cloud-core (1.6.0) - google-cloud-env (~> 1.0) - google-cloud-errors (~> 1.0) - google-cloud-env (1.5.0) - faraday (>= 0.17.3, < 2.0) - google-cloud-errors (1.1.0) - google-cloud-translate (1.2.4) - faraday (~> 0.13) - google-cloud-core (~> 1.2) - googleauth (~> 0.6.2) - googleauth (0.6.7) - faraday (~> 0.12) - jwt (>= 1.4, < 3.0) - memoist (~> 0.16) - multi_json (~> 1.11) - os (>= 0.9, < 2.0) - signet (~> 0.7) - hashdiff (1.0.1) - i18n (1.8.11) - concurrent-ruby (~> 1.0) - jquery-rails (4.4.0) - rails-dom-testing (>= 1, < 3) - railties (>= 4.2.0) - thor (>= 0.14, < 2.0) - jwt (2.2.2) - loofah (2.13.0) - crass (~> 1.0.2) - nokogiri (>= 1.5.9) - m (1.5.1) - method_source (>= 0.6.7) - rake (>= 0.9.2.2) - mail (2.7.1) - mini_mime (>= 0.1.1) - marcel (1.0.2) - memoist (0.16.2) - method_source (1.0.0) - mini_mime (1.1.2) - mini_portile2 (2.6.1) - minispec-metadata (2.0.0) - minitest - minitest (5.15.0) - minitest-vcr (1.4.0) - minispec-metadata (~> 2.0) - minitest (>= 4.7.5) - vcr (>= 2.9) - mocha (1.12.0) - multi_json (1.15.0) - multipart-post (2.1.1) - nio4r (2.5.8) - nokogiri (1.12.5) - mini_portile2 (~> 2.6.1) - racc (~> 1.4) - nokogiri (1.12.5-x86_64-darwin) - racc (~> 1.4) - nokogiri (1.12.5-x86_64-linux) - racc (~> 1.4) - orm_adapter (0.5.0) - os (1.1.1) - pg (1.2.3) - pry (0.13.1) - coderay (~> 1.1) - method_source (~> 1.0) - pry-byebug (3.9.0) - byebug (~> 11.0) - pry (~> 0.13.0) - pry-rails (0.3.9) - pry (>= 0.10.4) - public_suffix (4.0.6) - racc (1.6.0) - rack (2.2.3) - rack-test (1.1.0) - rack (>= 1.0, < 3) - rails (5.2.6) - actioncable (= 5.2.6) - actionmailer (= 5.2.6) - actionpack (= 5.2.6) - actionview (= 5.2.6) - activejob (= 5.2.6) - activemodel (= 5.2.6) - activerecord (= 5.2.6) - activestorage (= 5.2.6) - activesupport (= 5.2.6) - bundler (>= 1.3.0) - railties (= 5.2.6) - sprockets-rails (>= 2.0.0) - rails-controller-testing (1.0.5) - actionpack (>= 5.0.1.rc1) - actionview (>= 5.0.1.rc1) - activesupport (>= 5.0.1.rc1) - rails-dom-testing (2.0.3) - activesupport (>= 4.2.0) - nokogiri (>= 1.6) - rails-html-sanitizer (1.4.2) - loofah (~> 2.3) - railties (5.2.6) - actionpack (= 5.2.6) - activesupport (= 5.2.6) - method_source - rake (>= 0.8.7) - thor (>= 0.19.0, < 2.0) - rake (13.0.6) - redis (4.2.5) - regexp_parser (2.1.1) - responders (3.0.1) - actionpack (>= 5.0) - railties (>= 5.0) - rexml (3.2.5) - sass-rails (6.0.0) - sassc-rails (~> 2.1, >= 2.1.1) - sassc (2.4.0) - ffi (~> 1.9) - sassc-rails (2.1.2) - railties (>= 4.0.0) - sassc (>= 2.0) - sprockets (> 3.0) - sprockets-rails - tilt - signet (0.15.0) - addressable (~> 2.3) - faraday (>= 0.17.3, < 2.0) - jwt (>= 1.5, < 3.0) - multi_json (~> 1.10) - sprockets (4.0.2) - concurrent-ruby (~> 1.0) - rack (> 1, < 3) - sprockets-rails (3.4.2) - actionpack (>= 5.2) - activesupport (>= 5.2) - sprockets (>= 3.0.0) - test_declarative (0.0.6) - thor (1.1.0) - thread_safe (0.3.6) - tilt (2.0.10) - tzinfo (1.2.9) - thread_safe (~> 0.1) - vcr (4.0.0) - warden (1.2.9) - rack (>= 2.0.9) - webmock (3.12.2) - addressable (>= 2.3.6) - crack (>= 0.3.2) - hashdiff (>= 0.4.0, < 2.0.0) - websocket-driver (0.7.5) - websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.5) - xpath (3.2.0) - nokogiri (~> 1.8) - -PLATFORMS - ruby - x86_64-darwin-20 - x86_64-linux - -DEPENDENCIES - appraisal (~> 2.4.0) - capybara - coffee-rails - database_cleaner - devise - google-cloud-translate (~> 1.2.4) - jquery-rails - lit! - m (~> 1.5.0) - minitest - minitest-vcr (~> 1.4.0) - mocha - pg (~> 1.2.3) - pry-byebug (~> 3.9.0) - pry-rails - rails (~> 5.2.0) - rails-controller-testing - redis - sass-rails - test_declarative - vcr (~> 4.0.0) - webmock - -BUNDLED WITH - 2.2.25 diff --git a/gemfiles/rails_6.0.gemfile b/gemfiles/rails_6.0.gemfile deleted file mode 100644 index 12c20b47..00000000 --- a/gemfiles/rails_6.0.gemfile +++ /dev/null @@ -1,23 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org" - -gem "rails", "~> 6.0.3" -gem "devise" -gem "pg", "~> 1.2.3" -gem "redis" -gem "capybara" -gem "database_cleaner" -gem "test_declarative" -gem "mocha" -gem "webmock" -gem "sass-rails" -gem "jquery-rails" -gem "coffee-rails" -gem "pry-rails" -gem "rails-controller-testing" -gem "minitest" -gem "m", "~> 1.5.0" -gem "google-cloud-translate", "~> 1.2.4" - -gemspec path: "../" diff --git a/gemfiles/rails_6.0.gemfile.lock b/gemfiles/rails_6.0.gemfile.lock deleted file mode 100644 index c6b575f9..00000000 --- a/gemfiles/rails_6.0.gemfile.lock +++ /dev/null @@ -1,299 +0,0 @@ -PATH - remote: .. - specs: - lit (1.1.6) - coffee-rails - emoji_flag - jquery-rails - rails (>= 5.2.0) - sass-rails - -GEM - remote: https://rubygems.org/ - specs: - actioncable (6.0.4.4) - actionpack (= 6.0.4.4) - nio4r (~> 2.0) - websocket-driver (>= 0.6.1) - actionmailbox (6.0.4.4) - actionpack (= 6.0.4.4) - activejob (= 6.0.4.4) - activerecord (= 6.0.4.4) - activestorage (= 6.0.4.4) - activesupport (= 6.0.4.4) - mail (>= 2.7.1) - actionmailer (6.0.4.4) - actionpack (= 6.0.4.4) - actionview (= 6.0.4.4) - activejob (= 6.0.4.4) - mail (~> 2.5, >= 2.5.4) - rails-dom-testing (~> 2.0) - actionpack (6.0.4.4) - actionview (= 6.0.4.4) - activesupport (= 6.0.4.4) - rack (~> 2.0, >= 2.0.8) - rack-test (>= 0.6.3) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (6.0.4.4) - actionpack (= 6.0.4.4) - activerecord (= 6.0.4.4) - activestorage (= 6.0.4.4) - activesupport (= 6.0.4.4) - nokogiri (>= 1.8.5) - actionview (6.0.4.4) - activesupport (= 6.0.4.4) - builder (~> 3.1) - erubi (~> 1.4) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.1, >= 1.2.0) - activejob (6.0.4.4) - activesupport (= 6.0.4.4) - globalid (>= 0.3.6) - activemodel (6.0.4.4) - activesupport (= 6.0.4.4) - activerecord (6.0.4.4) - activemodel (= 6.0.4.4) - activesupport (= 6.0.4.4) - activestorage (6.0.4.4) - actionpack (= 6.0.4.4) - activejob (= 6.0.4.4) - activerecord (= 6.0.4.4) - marcel (~> 1.0.0) - activesupport (6.0.4.4) - concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 0.7, < 2) - minitest (~> 5.1) - tzinfo (~> 1.1) - zeitwerk (~> 2.2, >= 2.2.2) - addressable (2.7.0) - public_suffix (>= 2.0.2, < 5.0) - appraisal (2.4.0) - bundler - rake - thor (>= 0.14.0) - bcrypt (3.1.16) - builder (3.2.4) - byebug (11.1.3) - capybara (3.35.3) - addressable - mini_mime (>= 0.1.3) - nokogiri (~> 1.8) - rack (>= 1.6.0) - rack-test (>= 0.6.3) - regexp_parser (>= 1.5, < 3.0) - xpath (~> 3.2) - coderay (1.1.3) - coffee-rails (5.0.0) - coffee-script (>= 2.2.0) - railties (>= 5.2.0) - coffee-script (2.4.1) - coffee-script-source - execjs - coffee-script-source (1.12.2) - concurrent-ruby (1.1.9) - crack (0.4.5) - rexml - crass (1.0.6) - database_cleaner (2.0.1) - database_cleaner-active_record (~> 2.0.0) - database_cleaner-active_record (2.0.0) - activerecord (>= 5.a) - database_cleaner-core (~> 2.0.0) - database_cleaner-core (2.0.1) - devise (4.7.3) - bcrypt (~> 3.0) - orm_adapter (~> 0.1) - railties (>= 4.1.0) - responders - warden (~> 1.2.3) - emoji_flag (0.1.1) - erubi (1.10.0) - execjs (2.7.0) - faraday (0.17.4) - multipart-post (>= 1.2, < 3) - ffi (1.15.0) - globalid (1.0.0) - activesupport (>= 5.0) - google-cloud-core (1.6.0) - google-cloud-env (~> 1.0) - google-cloud-errors (~> 1.0) - google-cloud-env (1.5.0) - faraday (>= 0.17.3, < 2.0) - google-cloud-errors (1.1.0) - google-cloud-translate (1.2.4) - faraday (~> 0.13) - google-cloud-core (~> 1.2) - googleauth (~> 0.6.2) - googleauth (0.6.7) - faraday (~> 0.12) - jwt (>= 1.4, < 3.0) - memoist (~> 0.16) - multi_json (~> 1.11) - os (>= 0.9, < 2.0) - signet (~> 0.7) - hashdiff (1.0.1) - i18n (1.8.11) - concurrent-ruby (~> 1.0) - jquery-rails (4.4.0) - rails-dom-testing (>= 1, < 3) - railties (>= 4.2.0) - thor (>= 0.14, < 2.0) - jwt (2.2.2) - loofah (2.13.0) - crass (~> 1.0.2) - nokogiri (>= 1.5.9) - m (1.5.1) - method_source (>= 0.6.7) - rake (>= 0.9.2.2) - mail (2.7.1) - mini_mime (>= 0.1.1) - marcel (1.0.2) - memoist (0.16.2) - method_source (1.0.0) - mini_mime (1.1.2) - mini_portile2 (2.6.1) - minispec-metadata (2.0.0) - minitest - minitest (5.15.0) - minitest-vcr (1.4.0) - minispec-metadata (~> 2.0) - minitest (>= 4.7.5) - vcr (>= 2.9) - mocha (1.12.0) - multi_json (1.15.0) - multipart-post (2.1.1) - nio4r (2.5.8) - nokogiri (1.12.5) - mini_portile2 (~> 2.6.1) - racc (~> 1.4) - nokogiri (1.12.5-x86_64-darwin) - racc (~> 1.4) - nokogiri (1.12.5-x86_64-linux) - racc (~> 1.4) - orm_adapter (0.5.0) - os (1.1.1) - pg (1.2.3) - pry (0.13.1) - coderay (~> 1.1) - method_source (~> 1.0) - pry-byebug (3.9.0) - byebug (~> 11.0) - pry (~> 0.13.0) - pry-rails (0.3.9) - pry (>= 0.10.4) - public_suffix (4.0.6) - racc (1.6.0) - rack (2.2.3) - rack-test (1.1.0) - rack (>= 1.0, < 3) - rails (6.0.4.4) - actioncable (= 6.0.4.4) - actionmailbox (= 6.0.4.4) - actionmailer (= 6.0.4.4) - actionpack (= 6.0.4.4) - actiontext (= 6.0.4.4) - actionview (= 6.0.4.4) - activejob (= 6.0.4.4) - activemodel (= 6.0.4.4) - activerecord (= 6.0.4.4) - activestorage (= 6.0.4.4) - activesupport (= 6.0.4.4) - bundler (>= 1.3.0) - railties (= 6.0.4.4) - sprockets-rails (>= 2.0.0) - rails-controller-testing (1.0.5) - actionpack (>= 5.0.1.rc1) - actionview (>= 5.0.1.rc1) - activesupport (>= 5.0.1.rc1) - rails-dom-testing (2.0.3) - activesupport (>= 4.2.0) - nokogiri (>= 1.6) - rails-html-sanitizer (1.4.2) - loofah (~> 2.3) - railties (6.0.4.4) - actionpack (= 6.0.4.4) - activesupport (= 6.0.4.4) - method_source - rake (>= 0.8.7) - thor (>= 0.20.3, < 2.0) - rake (13.0.6) - redis (4.2.5) - regexp_parser (2.1.1) - responders (3.0.1) - actionpack (>= 5.0) - railties (>= 5.0) - rexml (3.2.5) - sass-rails (6.0.0) - sassc-rails (~> 2.1, >= 2.1.1) - sassc (2.4.0) - ffi (~> 1.9) - sassc-rails (2.1.2) - railties (>= 4.0.0) - sassc (>= 2.0) - sprockets (> 3.0) - sprockets-rails - tilt - signet (0.15.0) - addressable (~> 2.3) - faraday (>= 0.17.3, < 2.0) - jwt (>= 1.5, < 3.0) - multi_json (~> 1.10) - sprockets (4.0.2) - concurrent-ruby (~> 1.0) - rack (> 1, < 3) - sprockets-rails (3.4.2) - actionpack (>= 5.2) - activesupport (>= 5.2) - sprockets (>= 3.0.0) - test_declarative (0.0.6) - thor (1.1.0) - thread_safe (0.3.6) - tilt (2.0.10) - tzinfo (1.2.9) - thread_safe (~> 0.1) - vcr (4.0.0) - warden (1.2.9) - rack (>= 2.0.9) - webmock (3.12.2) - addressable (>= 2.3.6) - crack (>= 0.3.2) - hashdiff (>= 0.4.0, < 2.0.0) - websocket-driver (0.7.5) - websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.5) - xpath (3.2.0) - nokogiri (~> 1.8) - zeitwerk (2.5.1) - -PLATFORMS - ruby - x86_64-darwin-20 - x86_64-linux - -DEPENDENCIES - appraisal (~> 2.4.0) - capybara - coffee-rails - database_cleaner - devise - google-cloud-translate (~> 1.2.4) - jquery-rails - lit! - m (~> 1.5.0) - minitest - minitest-vcr (~> 1.4.0) - mocha - pg (~> 1.2.3) - pry-byebug (~> 3.9.0) - pry-rails - rails (~> 6.0.3) - rails-controller-testing - redis - sass-rails - test_declarative - vcr (~> 4.0.0) - webmock - -BUNDLED WITH - 2.2.25 diff --git a/gemfiles/rails_6.1.gemfile.lock b/gemfiles/rails_6.1.gemfile.lock deleted file mode 100644 index f4be92b0..00000000 --- a/gemfiles/rails_6.1.gemfile.lock +++ /dev/null @@ -1,348 +0,0 @@ -PATH - remote: .. - specs: - lit (1.1.6) - coffee-rails - emoji_flag - jquery-rails - rails (>= 5.2.0) - sass-rails - -GEM - remote: https://rubygems.org/ - specs: - actioncable (6.1.4.4) - actionpack (= 6.1.4.4) - activesupport (= 6.1.4.4) - nio4r (~> 2.0) - websocket-driver (>= 0.6.1) - actionmailbox (6.1.4.4) - actionpack (= 6.1.4.4) - activejob (= 6.1.4.4) - activerecord (= 6.1.4.4) - activestorage (= 6.1.4.4) - activesupport (= 6.1.4.4) - mail (>= 2.7.1) - actionmailer (6.1.4.4) - actionpack (= 6.1.4.4) - actionview (= 6.1.4.4) - activejob (= 6.1.4.4) - activesupport (= 6.1.4.4) - mail (~> 2.5, >= 2.5.4) - rails-dom-testing (~> 2.0) - actionpack (6.1.4.4) - actionview (= 6.1.4.4) - activesupport (= 6.1.4.4) - rack (~> 2.0, >= 2.0.9) - rack-test (>= 0.6.3) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (6.1.4.4) - actionpack (= 6.1.4.4) - activerecord (= 6.1.4.4) - activestorage (= 6.1.4.4) - activesupport (= 6.1.4.4) - nokogiri (>= 1.8.5) - actionview (6.1.4.4) - activesupport (= 6.1.4.4) - builder (~> 3.1) - erubi (~> 1.4) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.1, >= 1.2.0) - activejob (6.1.4.4) - activesupport (= 6.1.4.4) - globalid (>= 0.3.6) - activemodel (6.1.4.4) - activesupport (= 6.1.4.4) - activerecord (6.1.4.4) - activemodel (= 6.1.4.4) - activesupport (= 6.1.4.4) - activestorage (6.1.4.4) - actionpack (= 6.1.4.4) - activejob (= 6.1.4.4) - activerecord (= 6.1.4.4) - activesupport (= 6.1.4.4) - marcel (~> 1.0.0) - mini_mime (>= 1.1.0) - activesupport (6.1.4.4) - concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 1.6, < 2) - minitest (>= 5.1) - tzinfo (~> 2.0) - zeitwerk (~> 2.3) - addressable (2.7.0) - public_suffix (>= 2.0.2, < 5.0) - appraisal (2.4.0) - bundler - rake - thor (>= 0.14.0) - bcrypt (3.1.16) - builder (3.2.4) - byebug (11.1.3) - capybara (3.35.3) - addressable - mini_mime (>= 0.1.3) - nokogiri (~> 1.8) - rack (>= 1.6.0) - rack-test (>= 0.6.3) - regexp_parser (>= 1.5, < 3.0) - xpath (~> 3.2) - coderay (1.1.3) - coffee-rails (5.0.0) - coffee-script (>= 2.2.0) - railties (>= 5.2.0) - coffee-script (2.4.1) - coffee-script-source - execjs - coffee-script-source (1.12.2) - concurrent-ruby (1.1.9) - crack (0.4.5) - rexml - crass (1.0.6) - database_cleaner (2.0.1) - database_cleaner-active_record (~> 2.0.0) - database_cleaner-active_record (2.0.0) - activerecord (>= 5.a) - database_cleaner-core (~> 2.0.0) - database_cleaner-core (2.0.1) - devise (4.7.3) - bcrypt (~> 3.0) - orm_adapter (~> 0.1) - railties (>= 4.1.0) - responders - warden (~> 1.2.3) - emoji_flag (0.1.1) - erubi (1.10.0) - execjs (2.7.0) - faraday (1.8.0) - faraday-em_http (~> 1.0) - faraday-em_synchrony (~> 1.0) - faraday-excon (~> 1.1) - faraday-httpclient (~> 1.0.1) - faraday-net_http (~> 1.0) - faraday-net_http_persistent (~> 1.1) - faraday-patron (~> 1.0) - faraday-rack (~> 1.0) - multipart-post (>= 1.2, < 3) - ruby2_keywords (>= 0.0.4) - faraday-em_http (1.0.0) - faraday-em_synchrony (1.0.0) - faraday-excon (1.1.0) - faraday-httpclient (1.0.1) - faraday-net_http (1.0.1) - faraday-net_http_persistent (1.2.0) - faraday-patron (1.0.0) - faraday-rack (1.0.0) - ffi (1.15.0) - globalid (1.0.0) - activesupport (>= 5.0) - google-cloud-core (1.6.0) - google-cloud-env (~> 1.0) - google-cloud-errors (~> 1.0) - google-cloud-env (1.5.0) - faraday (>= 0.17.3, < 2.0) - google-cloud-errors (1.2.0) - google-cloud-translate (2.1.2) - faraday (>= 0.17.3, < 2.0) - google-cloud-core (~> 1.2) - google-gax (~> 1.8) - googleapis-common-protos (>= 1.3.9, < 2.0) - googleapis-common-protos-types (>= 1.0.4, < 2.0) - google-gax (1.8.2) - google-protobuf (~> 3.9) - googleapis-common-protos (>= 1.3.9, < 2.0) - googleapis-common-protos-types (>= 1.0.4, < 2.0) - googleauth (~> 0.9) - grpc (~> 1.24) - rly (~> 0.2.3) - google-protobuf (3.17.3) - google-protobuf (3.17.3-universal-darwin) - google-protobuf (3.17.3-x86_64-linux) - googleapis-common-protos (1.3.12) - google-protobuf (~> 3.14) - googleapis-common-protos-types (~> 1.2) - grpc (~> 1.27) - googleapis-common-protos-types (1.3.0) - google-protobuf (~> 3.14) - googleauth (0.17.1) - faraday (>= 0.17.3, < 2.0) - jwt (>= 1.4, < 3.0) - memoist (~> 0.16) - multi_json (~> 1.11) - os (>= 0.9, < 2.0) - signet (~> 0.15) - grpc (1.41.0) - google-protobuf (~> 3.17) - googleapis-common-protos-types (~> 1.0) - grpc (1.41.0-universal-darwin) - google-protobuf (~> 3.17) - googleapis-common-protos-types (~> 1.0) - grpc (1.41.0-x86_64-linux) - google-protobuf (~> 3.17) - googleapis-common-protos-types (~> 1.0) - hashdiff (1.0.1) - i18n (1.8.11) - concurrent-ruby (~> 1.0) - jquery-rails (4.4.0) - rails-dom-testing (>= 1, < 3) - railties (>= 4.2.0) - thor (>= 0.14, < 2.0) - jwt (2.3.0) - loofah (2.13.0) - crass (~> 1.0.2) - nokogiri (>= 1.5.9) - m (1.5.1) - method_source (>= 0.6.7) - rake (>= 0.9.2.2) - mail (2.7.1) - mini_mime (>= 0.1.1) - marcel (1.0.2) - memoist (0.16.2) - method_source (1.0.0) - mini_mime (1.1.2) - mini_portile2 (2.6.1) - minispec-metadata (2.0.0) - minitest - minitest (5.15.0) - minitest-vcr (1.4.0) - minispec-metadata (~> 2.0) - minitest (>= 4.7.5) - vcr (>= 2.9) - mocha (1.12.0) - multi_json (1.15.0) - multipart-post (2.1.1) - nio4r (2.5.8) - nokogiri (1.12.5) - mini_portile2 (~> 2.6.1) - racc (~> 1.4) - nokogiri (1.12.5-x86_64-darwin) - racc (~> 1.4) - nokogiri (1.12.5-x86_64-linux) - racc (~> 1.4) - orm_adapter (0.5.0) - os (1.1.1) - pg (1.2.3) - pry (0.13.1) - coderay (~> 1.1) - method_source (~> 1.0) - pry-byebug (3.9.0) - byebug (~> 11.0) - pry (~> 0.13.0) - pry-rails (0.3.9) - pry (>= 0.10.4) - public_suffix (4.0.6) - racc (1.6.0) - rack (2.2.3) - rack-test (1.1.0) - rack (>= 1.0, < 3) - rails (6.1.4.4) - actioncable (= 6.1.4.4) - actionmailbox (= 6.1.4.4) - actionmailer (= 6.1.4.4) - actionpack (= 6.1.4.4) - actiontext (= 6.1.4.4) - actionview (= 6.1.4.4) - activejob (= 6.1.4.4) - activemodel (= 6.1.4.4) - activerecord (= 6.1.4.4) - activestorage (= 6.1.4.4) - activesupport (= 6.1.4.4) - bundler (>= 1.15.0) - railties (= 6.1.4.4) - sprockets-rails (>= 2.0.0) - rails-controller-testing (1.0.5) - actionpack (>= 5.0.1.rc1) - actionview (>= 5.0.1.rc1) - activesupport (>= 5.0.1.rc1) - rails-dom-testing (2.0.3) - activesupport (>= 4.2.0) - nokogiri (>= 1.6) - rails-html-sanitizer (1.4.2) - loofah (~> 2.3) - railties (6.1.4.4) - actionpack (= 6.1.4.4) - activesupport (= 6.1.4.4) - method_source - rake (>= 0.13) - thor (~> 1.0) - rake (13.0.6) - redis (4.2.5) - regexp_parser (2.1.1) - responders (3.0.1) - actionpack (>= 5.0) - railties (>= 5.0) - rexml (3.2.5) - rly (0.2.3) - ruby2_keywords (0.0.5) - sass-rails (6.0.0) - sassc-rails (~> 2.1, >= 2.1.1) - sassc (2.4.0) - ffi (~> 1.9) - sassc-rails (2.1.2) - railties (>= 4.0.0) - sassc (>= 2.0) - sprockets (> 3.0) - sprockets-rails - tilt - signet (0.15.0) - addressable (~> 2.3) - faraday (>= 0.17.3, < 2.0) - jwt (>= 1.5, < 3.0) - multi_json (~> 1.10) - sprockets (4.0.2) - concurrent-ruby (~> 1.0) - rack (> 1, < 3) - sprockets-rails (3.4.2) - actionpack (>= 5.2) - activesupport (>= 5.2) - sprockets (>= 3.0.0) - test_declarative (0.0.6) - thor (1.1.0) - tilt (2.0.10) - tzinfo (2.0.4) - concurrent-ruby (~> 1.0) - vcr (4.0.0) - warden (1.2.9) - rack (>= 2.0.9) - webmock (3.12.2) - addressable (>= 2.3.6) - crack (>= 0.3.2) - hashdiff (>= 0.4.0, < 2.0.0) - websocket-driver (0.7.5) - websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.5) - xpath (3.2.0) - nokogiri (~> 1.8) - zeitwerk (2.5.1) - -PLATFORMS - ruby - x86_64-darwin-20 - x86_64-linux - -DEPENDENCIES - appraisal (~> 2.4.0) - capybara - coffee-rails - database_cleaner - devise - google-cloud-translate (~> 2.1.2) - jquery-rails - lit! - m (~> 1.5.0) - minitest - minitest-vcr (~> 1.4.0) - mocha - pg (~> 1.2.3) - pry-byebug (~> 3.9.0) - pry-rails - rails (~> 6.1.4.1) - rails-controller-testing - redis - sass-rails - test_declarative - vcr (~> 4.0.0) - webmock - -BUNDLED WITH - 2.2.25 diff --git a/gemfiles/rails_6.1.gemfile b/gemfiles/rails_7.0.gemfile similarity index 63% rename from gemfiles/rails_6.1.gemfile rename to gemfiles/rails_7.0.gemfile index 81a097c8..2567bf74 100644 --- a/gemfiles/rails_6.1.gemfile +++ b/gemfiles/rails_7.0.gemfile @@ -2,9 +2,9 @@ source "https://rubygems.org" -gem "rails", "~> 6.1.4.1" +gem "rails", "~> 7.0.8.4" gem "devise" -gem "pg", "~> 1.2.3" +gem "pg", "~> 1.0" gem "redis" gem "capybara" gem "database_cleaner" @@ -15,9 +15,11 @@ gem "sass-rails" gem "jquery-rails" gem "coffee-rails" gem "pry-rails" +gem "pry-stack_explorer" gem "rails-controller-testing" gem "minitest" -gem "m", "~> 1.5.0" -gem "google-cloud-translate", "~> 2.1.2" +gem "minitest-vcr", github: "manuelvanrijn/minitest-vcr" +gem "m", "~> 1.6" +gem "google-cloud-translate", "~> 2.0" gemspec path: "../" diff --git a/gemfiles/rails_7.0.gemfile.lock b/gemfiles/rails_7.0.gemfile.lock new file mode 100644 index 00000000..2aa156fb --- /dev/null +++ b/gemfiles/rails_7.0.gemfile.lock @@ -0,0 +1,431 @@ +GIT + remote: https://github.com/manuelvanrijn/minitest-vcr.git + revision: e9f10dbd85d939f826364eef909abb441203d717 + specs: + minitest-vcr (1.4.0) + minispec-metadata (>= 2.0) + minitest (>= 5.19.0) + vcr (>= 2.9) + +PATH + remote: .. + specs: + lit (2.0.0) + emoji_flag + jquery-rails + rails (>= 7.0) + +GEM + remote: https://rubygems.org/ + specs: + actioncable (7.0.8.4) + actionpack (= 7.0.8.4) + activesupport (= 7.0.8.4) + nio4r (~> 2.0) + websocket-driver (>= 0.6.1) + actionmailbox (7.0.8.4) + actionpack (= 7.0.8.4) + activejob (= 7.0.8.4) + activerecord (= 7.0.8.4) + activestorage (= 7.0.8.4) + activesupport (= 7.0.8.4) + mail (>= 2.7.1) + net-imap + net-pop + net-smtp + actionmailer (7.0.8.4) + actionpack (= 7.0.8.4) + actionview (= 7.0.8.4) + activejob (= 7.0.8.4) + activesupport (= 7.0.8.4) + mail (~> 2.5, >= 2.5.4) + net-imap + net-pop + net-smtp + rails-dom-testing (~> 2.0) + actionpack (7.0.8.4) + actionview (= 7.0.8.4) + activesupport (= 7.0.8.4) + rack (~> 2.0, >= 2.2.4) + rack-test (>= 0.6.3) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.2.0) + actiontext (7.0.8.4) + actionpack (= 7.0.8.4) + activerecord (= 7.0.8.4) + activestorage (= 7.0.8.4) + activesupport (= 7.0.8.4) + globalid (>= 0.6.0) + nokogiri (>= 1.8.5) + actionview (7.0.8.4) + activesupport (= 7.0.8.4) + builder (~> 3.1) + erubi (~> 1.4) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.1, >= 1.2.0) + activejob (7.0.8.4) + activesupport (= 7.0.8.4) + globalid (>= 0.3.6) + activemodel (7.0.8.4) + activesupport (= 7.0.8.4) + activerecord (7.0.8.4) + activemodel (= 7.0.8.4) + activesupport (= 7.0.8.4) + activestorage (7.0.8.4) + actionpack (= 7.0.8.4) + activejob (= 7.0.8.4) + activerecord (= 7.0.8.4) + activesupport (= 7.0.8.4) + marcel (~> 1.0) + mini_mime (>= 1.1.0) + activesupport (7.0.8.4) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 1.6, < 2) + minitest (>= 5.1) + tzinfo (~> 2.0) + addressable (2.8.7) + public_suffix (>= 2.0.2, < 7.0) + appraisal (2.5.0) + bundler + rake + thor (>= 0.14.0) + ast (2.4.2) + base64 (0.2.0) + bcrypt (3.1.20) + bigdecimal (3.1.8) + binding_of_caller (1.0.1) + debug_inspector (>= 1.2.0) + builder (3.3.0) + byebug (11.1.3) + capybara (3.40.0) + addressable + matrix + mini_mime (>= 0.1.3) + nokogiri (~> 1.11) + rack (>= 1.6.0) + rack-test (>= 0.6.3) + regexp_parser (>= 1.5, < 3.0) + xpath (~> 3.2) + coderay (1.1.3) + coffee-rails (5.0.0) + coffee-script (>= 2.2.0) + railties (>= 5.2.0) + coffee-script (2.4.1) + coffee-script-source + execjs + coffee-script-source (1.12.2) + concurrent-ruby (1.3.3) + connection_pool (2.4.1) + crack (1.0.0) + bigdecimal + rexml + crass (1.0.6) + database_cleaner (2.0.2) + database_cleaner-active_record (>= 2, < 3) + database_cleaner-active_record (2.2.0) + activerecord (>= 5.a) + database_cleaner-core (~> 2.0.0) + database_cleaner-core (2.0.1) + date (3.3.4) + debug_inspector (1.2.0) + devise (4.9.4) + bcrypt (~> 3.0) + orm_adapter (~> 0.1) + railties (>= 4.1.0) + responders + warden (~> 1.2.3) + emoji_flag (0.1.1) + erubi (1.13.0) + execjs (2.9.1) + faraday (1.10.3) + faraday-em_http (~> 1.0) + faraday-em_synchrony (~> 1.0) + faraday-excon (~> 1.1) + faraday-httpclient (~> 1.0) + faraday-multipart (~> 1.0) + faraday-net_http (~> 1.0) + faraday-net_http_persistent (~> 1.0) + faraday-patron (~> 1.0) + faraday-rack (~> 1.0) + faraday-retry (~> 1.0) + ruby2_keywords (>= 0.0.4) + faraday-em_http (1.0.0) + faraday-em_synchrony (1.0.0) + faraday-excon (1.1.0) + faraday-httpclient (1.0.1) + faraday-multipart (1.0.4) + multipart-post (~> 2) + faraday-net_http (1.0.2) + faraday-net_http_persistent (1.2.0) + faraday-patron (1.0.0) + faraday-rack (1.0.0) + faraday-retry (1.0.3) + ffi (1.17.0-arm64-darwin) + globalid (1.2.1) + activesupport (>= 6.1) + google-cloud-core (1.7.1) + google-cloud-env (>= 1.0, < 3.a) + google-cloud-errors (~> 1.0) + google-cloud-env (2.1.1) + faraday (>= 1.0, < 3.a) + google-cloud-errors (1.4.0) + google-cloud-translate (2.3.0) + faraday (>= 0.17.3, < 2.0) + google-cloud-core (~> 1.2) + google-gax (~> 1.8) + googleapis-common-protos (>= 1.3.9, < 2.0) + googleapis-common-protos-types (>= 1.0.4, < 2.0) + google-gax (1.8.2) + google-protobuf (~> 3.9) + googleapis-common-protos (>= 1.3.9, < 2.0) + googleapis-common-protos-types (>= 1.0.4, < 2.0) + googleauth (~> 0.9) + grpc (~> 1.24) + rly (~> 0.2.3) + google-protobuf (3.25.4-arm64-darwin) + googleapis-common-protos (1.6.0) + google-protobuf (>= 3.18, < 5.a) + googleapis-common-protos-types (~> 1.7) + grpc (~> 1.41) + googleapis-common-protos-types (1.15.0) + google-protobuf (>= 3.18, < 5.a) + googleauth (0.17.1) + faraday (>= 0.17.3, < 2.0) + jwt (>= 1.4, < 3.0) + memoist (~> 0.16) + multi_json (~> 1.11) + os (>= 0.9, < 2.0) + signet (~> 0.15) + grpc (1.65.2-arm64-darwin) + google-protobuf (>= 3.25, < 5.0) + googleapis-common-protos-types (~> 1.0) + hashdiff (1.1.1) + i18n (1.14.5) + concurrent-ruby (~> 1.0) + jquery-rails (4.6.0) + rails-dom-testing (>= 1, < 3) + railties (>= 4.2.0) + thor (>= 0.14, < 2.0) + json (2.7.2) + jwt (2.8.2) + base64 + language_server-protocol (3.17.0.3) + lint_roller (1.1.0) + loofah (2.22.0) + crass (~> 1.0.2) + nokogiri (>= 1.12.0) + m (1.6.2) + method_source (>= 0.6.7) + rake (>= 0.9.2.2) + mail (2.8.1) + mini_mime (>= 0.1.1) + net-imap + net-pop + net-smtp + marcel (1.0.4) + matrix (0.4.2) + memoist (0.16.2) + method_source (1.1.0) + mini_mime (1.1.5) + minispec-metadata (3.5.0) + minitest + minitest (5.24.1) + mocha (2.4.5) + ruby2_keywords (>= 0.0.5) + multi_json (1.15.0) + multipart-post (2.4.1) + net-imap (0.4.14) + date + net-protocol + net-pop (0.1.2) + net-protocol + net-protocol (0.2.2) + timeout + net-smtp (0.5.0) + net-protocol + nio4r (2.7.3) + nokogiri (1.16.7-arm64-darwin) + racc (~> 1.4) + orm_adapter (0.5.0) + os (1.1.4) + parallel (1.26.1) + parser (3.3.4.2) + ast (~> 2.4.1) + racc + pg (1.5.7) + pry (0.14.2) + coderay (~> 1.1) + method_source (~> 1.0) + pry-byebug (3.10.1) + byebug (~> 11.0) + pry (>= 0.13, < 0.15) + pry-rails (0.3.11) + pry (>= 0.13.0) + pry-stack_explorer (0.6.1) + binding_of_caller (~> 1.0) + pry (~> 0.13) + public_suffix (6.0.1) + racc (1.8.1) + rack (2.2.9) + rack-test (2.1.0) + rack (>= 1.3) + rails (7.0.8.4) + actioncable (= 7.0.8.4) + actionmailbox (= 7.0.8.4) + actionmailer (= 7.0.8.4) + actionpack (= 7.0.8.4) + actiontext (= 7.0.8.4) + actionview (= 7.0.8.4) + activejob (= 7.0.8.4) + activemodel (= 7.0.8.4) + activerecord (= 7.0.8.4) + activestorage (= 7.0.8.4) + activesupport (= 7.0.8.4) + bundler (>= 1.15.0) + railties (= 7.0.8.4) + rails-controller-testing (1.0.5) + actionpack (>= 5.0.1.rc1) + actionview (>= 5.0.1.rc1) + activesupport (>= 5.0.1.rc1) + rails-dom-testing (2.2.0) + activesupport (>= 5.0.0) + minitest + nokogiri (>= 1.6) + rails-html-sanitizer (1.6.0) + loofah (~> 2.21) + nokogiri (~> 1.14) + railties (7.0.8.4) + actionpack (= 7.0.8.4) + activesupport (= 7.0.8.4) + method_source + rake (>= 12.2) + thor (~> 1.0) + zeitwerk (~> 2.5) + rainbow (3.1.1) + rake (13.2.1) + redis (5.2.0) + redis-client (>= 0.22.0) + redis-client (0.22.2) + connection_pool + regexp_parser (2.9.2) + responders (3.1.1) + actionpack (>= 5.2) + railties (>= 5.2) + rexml (3.3.4) + strscan + rly (0.2.3) + rubocop (1.64.1) + json (~> 2.3) + language_server-protocol (>= 3.17.0) + parallel (~> 1.10) + parser (>= 3.3.0.2) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.31.1, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.32.0) + parser (>= 3.3.1.0) + rubocop-performance (1.21.1) + rubocop (>= 1.48.1, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) + rubocop-rails (2.25.1) + activesupport (>= 4.2.0) + rack (>= 1.1) + rubocop (>= 1.33.0, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) + ruby-progressbar (1.13.0) + ruby2_keywords (0.0.5) + sass-rails (6.0.0) + sassc-rails (~> 2.1, >= 2.1.1) + sassc (2.4.0) + ffi (~> 1.9) + sassc-rails (2.1.2) + railties (>= 4.0.0) + sassc (>= 2.0) + sprockets (> 3.0) + sprockets-rails + tilt + signet (0.19.0) + addressable (~> 2.8) + faraday (>= 0.17.5, < 3.a) + jwt (>= 1.5, < 3.0) + multi_json (~> 1.10) + sprockets (4.2.1) + concurrent-ruby (~> 1.0) + rack (>= 2.2.4, < 4) + sprockets-rails (3.5.2) + actionpack (>= 6.1) + activesupport (>= 6.1) + sprockets (>= 3.0.0) + standard (1.39.2) + language_server-protocol (~> 3.17.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.64.0) + standard-custom (~> 1.0.0) + standard-performance (~> 1.4) + standard-custom (1.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.50) + standard-performance (1.4.0) + lint_roller (~> 1.1) + rubocop-performance (~> 1.21.0) + standard-rails (1.1.0) + lint_roller (~> 1.0) + rubocop-rails (~> 2.25.0) + strscan (3.1.0) + test_declarative (0.0.6) + thor (1.3.1) + tilt (2.4.0) + timeout (0.4.1) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) + unicode-display_width (2.5.0) + vcr (6.2.0) + warden (1.2.9) + rack (>= 2.0.9) + webmock (3.23.1) + addressable (>= 2.8.0) + crack (>= 0.3.2) + hashdiff (>= 0.4.0, < 2.0.0) + websocket-driver (0.7.6) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.5) + xpath (3.2.0) + nokogiri (~> 1.8) + zeitwerk (2.6.17) + +PLATFORMS + arm64-darwin-23 + +DEPENDENCIES + appraisal (~> 2.5.0) + capybara + coffee-rails + database_cleaner + devise + google-cloud-translate (~> 2.0) + jquery-rails + lit! + m (~> 1.6) + minitest + minitest-vcr! + mocha + pg (~> 1.0) + pry-byebug (~> 3.9) + pry-rails + pry-stack_explorer + rails (~> 7.0.8.4) + rails-controller-testing + redis + sass-rails + standard + standard-performance + standard-rails + test_declarative + vcr (~> 6.0) + webmock + +BUNDLED WITH + 2.4.19 diff --git a/gemfiles/rails_5.2.gemfile b/gemfiles/rails_7.1.gemfile similarity index 63% rename from gemfiles/rails_5.2.gemfile rename to gemfiles/rails_7.1.gemfile index 39387ba9..6bb85966 100644 --- a/gemfiles/rails_5.2.gemfile +++ b/gemfiles/rails_7.1.gemfile @@ -2,9 +2,9 @@ source "https://rubygems.org" -gem "rails", "~> 5.2.0" +gem "rails", "~> 7.1.3.4" gem "devise" -gem "pg", "~> 1.2.3" +gem "pg", "~> 1.0" gem "redis" gem "capybara" gem "database_cleaner" @@ -15,9 +15,11 @@ gem "sass-rails" gem "jquery-rails" gem "coffee-rails" gem "pry-rails" +gem "pry-stack_explorer" gem "rails-controller-testing" gem "minitest" -gem "m", "~> 1.5.0" -gem "google-cloud-translate", "~> 1.2.4" +gem "minitest-vcr", github: "manuelvanrijn/minitest-vcr" +gem "m", "~> 1.6" +gem "google-cloud-translate", "~> 2.0" gemspec path: "../" diff --git a/gemfiles/rails_7.1.gemfile.lock b/gemfiles/rails_7.1.gemfile.lock new file mode 100644 index 00000000..7e681bde --- /dev/null +++ b/gemfiles/rails_7.1.gemfile.lock @@ -0,0 +1,460 @@ +GIT + remote: https://github.com/manuelvanrijn/minitest-vcr.git + revision: e9f10dbd85d939f826364eef909abb441203d717 + specs: + minitest-vcr (1.4.0) + minispec-metadata (>= 2.0) + minitest (>= 5.19.0) + vcr (>= 2.9) + +PATH + remote: .. + specs: + lit (2.0.0) + emoji_flag + jquery-rails + rails (>= 7.0) + +GEM + remote: https://rubygems.org/ + specs: + actioncable (7.1.3.4) + actionpack (= 7.1.3.4) + activesupport (= 7.1.3.4) + nio4r (~> 2.0) + websocket-driver (>= 0.6.1) + zeitwerk (~> 2.6) + actionmailbox (7.1.3.4) + actionpack (= 7.1.3.4) + activejob (= 7.1.3.4) + activerecord (= 7.1.3.4) + activestorage (= 7.1.3.4) + activesupport (= 7.1.3.4) + mail (>= 2.7.1) + net-imap + net-pop + net-smtp + actionmailer (7.1.3.4) + actionpack (= 7.1.3.4) + actionview (= 7.1.3.4) + activejob (= 7.1.3.4) + activesupport (= 7.1.3.4) + mail (~> 2.5, >= 2.5.4) + net-imap + net-pop + net-smtp + rails-dom-testing (~> 2.2) + actionpack (7.1.3.4) + actionview (= 7.1.3.4) + activesupport (= 7.1.3.4) + nokogiri (>= 1.8.5) + racc + rack (>= 2.2.4) + rack-session (>= 1.0.1) + rack-test (>= 0.6.3) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + actiontext (7.1.3.4) + actionpack (= 7.1.3.4) + activerecord (= 7.1.3.4) + activestorage (= 7.1.3.4) + activesupport (= 7.1.3.4) + globalid (>= 0.6.0) + nokogiri (>= 1.8.5) + actionview (7.1.3.4) + activesupport (= 7.1.3.4) + builder (~> 3.1) + erubi (~> 1.11) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + activejob (7.1.3.4) + activesupport (= 7.1.3.4) + globalid (>= 0.3.6) + activemodel (7.1.3.4) + activesupport (= 7.1.3.4) + activerecord (7.1.3.4) + activemodel (= 7.1.3.4) + activesupport (= 7.1.3.4) + timeout (>= 0.4.0) + activestorage (7.1.3.4) + actionpack (= 7.1.3.4) + activejob (= 7.1.3.4) + activerecord (= 7.1.3.4) + activesupport (= 7.1.3.4) + marcel (~> 1.0) + activesupport (7.1.3.4) + base64 + bigdecimal + concurrent-ruby (~> 1.0, >= 1.0.2) + connection_pool (>= 2.2.5) + drb + i18n (>= 1.6, < 2) + minitest (>= 5.1) + mutex_m + tzinfo (~> 2.0) + addressable (2.8.7) + public_suffix (>= 2.0.2, < 7.0) + appraisal (2.5.0) + bundler + rake + thor (>= 0.14.0) + ast (2.4.2) + base64 (0.2.0) + bcrypt (3.1.20) + bigdecimal (3.1.8) + binding_of_caller (1.0.1) + debug_inspector (>= 1.2.0) + builder (3.3.0) + byebug (11.1.3) + capybara (3.40.0) + addressable + matrix + mini_mime (>= 0.1.3) + nokogiri (~> 1.11) + rack (>= 1.6.0) + rack-test (>= 0.6.3) + regexp_parser (>= 1.5, < 3.0) + xpath (~> 3.2) + coderay (1.1.3) + coffee-rails (5.0.0) + coffee-script (>= 2.2.0) + railties (>= 5.2.0) + coffee-script (2.4.1) + coffee-script-source + execjs + coffee-script-source (1.12.2) + concurrent-ruby (1.3.3) + connection_pool (2.4.1) + crack (1.0.0) + bigdecimal + rexml + crass (1.0.6) + database_cleaner (2.0.2) + database_cleaner-active_record (>= 2, < 3) + database_cleaner-active_record (2.2.0) + activerecord (>= 5.a) + database_cleaner-core (~> 2.0.0) + database_cleaner-core (2.0.1) + date (3.3.4) + debug_inspector (1.2.0) + devise (4.9.4) + bcrypt (~> 3.0) + orm_adapter (~> 0.1) + railties (>= 4.1.0) + responders + warden (~> 1.2.3) + drb (2.2.1) + emoji_flag (0.1.1) + erubi (1.13.0) + execjs (2.9.1) + faraday (1.10.3) + faraday-em_http (~> 1.0) + faraday-em_synchrony (~> 1.0) + faraday-excon (~> 1.1) + faraday-httpclient (~> 1.0) + faraday-multipart (~> 1.0) + faraday-net_http (~> 1.0) + faraday-net_http_persistent (~> 1.0) + faraday-patron (~> 1.0) + faraday-rack (~> 1.0) + faraday-retry (~> 1.0) + ruby2_keywords (>= 0.0.4) + faraday-em_http (1.0.0) + faraday-em_synchrony (1.0.0) + faraday-excon (1.1.0) + faraday-httpclient (1.0.1) + faraday-multipart (1.0.4) + multipart-post (~> 2) + faraday-net_http (1.0.2) + faraday-net_http_persistent (1.2.0) + faraday-patron (1.0.0) + faraday-rack (1.0.0) + faraday-retry (1.0.3) + ffi (1.17.0-arm64-darwin) + globalid (1.2.1) + activesupport (>= 6.1) + google-cloud-core (1.7.1) + google-cloud-env (>= 1.0, < 3.a) + google-cloud-errors (~> 1.0) + google-cloud-env (2.1.1) + faraday (>= 1.0, < 3.a) + google-cloud-errors (1.4.0) + google-cloud-translate (2.3.0) + faraday (>= 0.17.3, < 2.0) + google-cloud-core (~> 1.2) + google-gax (~> 1.8) + googleapis-common-protos (>= 1.3.9, < 2.0) + googleapis-common-protos-types (>= 1.0.4, < 2.0) + google-gax (1.8.2) + google-protobuf (~> 3.9) + googleapis-common-protos (>= 1.3.9, < 2.0) + googleapis-common-protos-types (>= 1.0.4, < 2.0) + googleauth (~> 0.9) + grpc (~> 1.24) + rly (~> 0.2.3) + google-protobuf (3.25.4-arm64-darwin) + googleapis-common-protos (1.6.0) + google-protobuf (>= 3.18, < 5.a) + googleapis-common-protos-types (~> 1.7) + grpc (~> 1.41) + googleapis-common-protos-types (1.15.0) + google-protobuf (>= 3.18, < 5.a) + googleauth (0.17.1) + faraday (>= 0.17.3, < 2.0) + jwt (>= 1.4, < 3.0) + memoist (~> 0.16) + multi_json (~> 1.11) + os (>= 0.9, < 2.0) + signet (~> 0.15) + grpc (1.65.2-arm64-darwin) + google-protobuf (>= 3.25, < 5.0) + googleapis-common-protos-types (~> 1.0) + hashdiff (1.1.1) + i18n (1.14.5) + concurrent-ruby (~> 1.0) + io-console (0.7.2) + irb (1.14.0) + rdoc (>= 4.0.0) + reline (>= 0.4.2) + jquery-rails (4.6.0) + rails-dom-testing (>= 1, < 3) + railties (>= 4.2.0) + thor (>= 0.14, < 2.0) + json (2.7.2) + jwt (2.8.2) + base64 + language_server-protocol (3.17.0.3) + lint_roller (1.1.0) + loofah (2.22.0) + crass (~> 1.0.2) + nokogiri (>= 1.12.0) + m (1.6.2) + method_source (>= 0.6.7) + rake (>= 0.9.2.2) + mail (2.8.1) + mini_mime (>= 0.1.1) + net-imap + net-pop + net-smtp + marcel (1.0.4) + matrix (0.4.2) + memoist (0.16.2) + method_source (1.1.0) + mini_mime (1.1.5) + minispec-metadata (3.5.0) + minitest + minitest (5.24.1) + mocha (2.4.5) + ruby2_keywords (>= 0.0.5) + multi_json (1.15.0) + multipart-post (2.4.1) + mutex_m (0.2.0) + net-imap (0.4.14) + date + net-protocol + net-pop (0.1.2) + net-protocol + net-protocol (0.2.2) + timeout + net-smtp (0.5.0) + net-protocol + nio4r (2.7.3) + nokogiri (1.16.7-arm64-darwin) + racc (~> 1.4) + orm_adapter (0.5.0) + os (1.1.4) + parallel (1.26.1) + parser (3.3.4.2) + ast (~> 2.4.1) + racc + pg (1.5.7) + pry (0.14.2) + coderay (~> 1.1) + method_source (~> 1.0) + pry-byebug (3.10.1) + byebug (~> 11.0) + pry (>= 0.13, < 0.15) + pry-rails (0.3.11) + pry (>= 0.13.0) + pry-stack_explorer (0.6.1) + binding_of_caller (~> 1.0) + pry (~> 0.13) + psych (5.1.2) + stringio + public_suffix (6.0.1) + racc (1.8.1) + rack (3.1.7) + rack-session (2.0.0) + rack (>= 3.0.0) + rack-test (2.1.0) + rack (>= 1.3) + rackup (2.1.0) + rack (>= 3) + webrick (~> 1.8) + rails (7.1.3.4) + actioncable (= 7.1.3.4) + actionmailbox (= 7.1.3.4) + actionmailer (= 7.1.3.4) + actionpack (= 7.1.3.4) + actiontext (= 7.1.3.4) + actionview (= 7.1.3.4) + activejob (= 7.1.3.4) + activemodel (= 7.1.3.4) + activerecord (= 7.1.3.4) + activestorage (= 7.1.3.4) + activesupport (= 7.1.3.4) + bundler (>= 1.15.0) + railties (= 7.1.3.4) + rails-controller-testing (1.0.5) + actionpack (>= 5.0.1.rc1) + actionview (>= 5.0.1.rc1) + activesupport (>= 5.0.1.rc1) + rails-dom-testing (2.2.0) + activesupport (>= 5.0.0) + minitest + nokogiri (>= 1.6) + rails-html-sanitizer (1.6.0) + loofah (~> 2.21) + nokogiri (~> 1.14) + railties (7.1.3.4) + actionpack (= 7.1.3.4) + activesupport (= 7.1.3.4) + irb + rackup (>= 1.0.0) + rake (>= 12.2) + thor (~> 1.0, >= 1.2.2) + zeitwerk (~> 2.6) + rainbow (3.1.1) + rake (13.2.1) + rdoc (6.7.0) + psych (>= 4.0.0) + redis (5.2.0) + redis-client (>= 0.22.0) + redis-client (0.22.2) + connection_pool + regexp_parser (2.9.2) + reline (0.5.9) + io-console (~> 0.5) + responders (3.1.1) + actionpack (>= 5.2) + railties (>= 5.2) + rexml (3.3.4) + strscan + rly (0.2.3) + rubocop (1.64.1) + json (~> 2.3) + language_server-protocol (>= 3.17.0) + parallel (~> 1.10) + parser (>= 3.3.0.2) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.31.1, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.32.0) + parser (>= 3.3.1.0) + rubocop-performance (1.21.1) + rubocop (>= 1.48.1, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) + rubocop-rails (2.25.1) + activesupport (>= 4.2.0) + rack (>= 1.1) + rubocop (>= 1.33.0, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) + ruby-progressbar (1.13.0) + ruby2_keywords (0.0.5) + sass-rails (6.0.0) + sassc-rails (~> 2.1, >= 2.1.1) + sassc (2.4.0) + ffi (~> 1.9) + sassc-rails (2.1.2) + railties (>= 4.0.0) + sassc (>= 2.0) + sprockets (> 3.0) + sprockets-rails + tilt + signet (0.19.0) + addressable (~> 2.8) + faraday (>= 0.17.5, < 3.a) + jwt (>= 1.5, < 3.0) + multi_json (~> 1.10) + sprockets (4.2.1) + concurrent-ruby (~> 1.0) + rack (>= 2.2.4, < 4) + sprockets-rails (3.5.2) + actionpack (>= 6.1) + activesupport (>= 6.1) + sprockets (>= 3.0.0) + standard (1.39.2) + language_server-protocol (~> 3.17.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.64.0) + standard-custom (~> 1.0.0) + standard-performance (~> 1.4) + standard-custom (1.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.50) + standard-performance (1.4.0) + lint_roller (~> 1.1) + rubocop-performance (~> 1.21.0) + standard-rails (1.1.0) + lint_roller (~> 1.0) + rubocop-rails (~> 2.25.0) + stringio (3.1.1) + strscan (3.1.0) + test_declarative (0.0.6) + thor (1.3.1) + tilt (2.4.0) + timeout (0.4.1) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) + unicode-display_width (2.5.0) + vcr (6.2.0) + warden (1.2.9) + rack (>= 2.0.9) + webmock (3.23.1) + addressable (>= 2.8.0) + crack (>= 0.3.2) + hashdiff (>= 0.4.0, < 2.0.0) + webrick (1.8.1) + websocket-driver (0.7.6) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.5) + xpath (3.2.0) + nokogiri (~> 1.8) + zeitwerk (2.6.17) + +PLATFORMS + arm64-darwin-23 + +DEPENDENCIES + appraisal (~> 2.5.0) + capybara + coffee-rails + database_cleaner + devise + google-cloud-translate (~> 2.0) + jquery-rails + lit! + m (~> 1.6) + minitest + minitest-vcr! + mocha + pg (~> 1.0) + pry-byebug (~> 3.9) + pry-rails + pry-stack_explorer + rails (~> 7.1.3.4) + rails-controller-testing + redis + sass-rails + standard + standard-performance + standard-rails + test_declarative + vcr (~> 6.0) + webmock + +BUNDLED WITH + 2.4.19 diff --git a/lib/lit.rb b/lib/lit.rb index 06af449a..62964218 100644 --- a/lib/lit.rb +++ b/lib/lit.rb @@ -1,6 +1,6 @@ -require 'lit/engine' -require 'lit/loader' -require 'lit/adapters' +require "lit/engine" +require "lit/loader" +require "lit/adapters" module Lit mattr_accessor :authentication_function @@ -33,10 +33,10 @@ def self.init Lit.humanize_key_ignored_keys = [] if Lit.humanize_key_ignored_keys.nil? Lit.humanize_key_ignored = %w[i18n date datetime number time support] Lit.humanize_key_ignored |= Lit.humanize_key_ignored_keys - Lit.humanize_key_ignored = Regexp.new("(#{Lit.humanize_key_ignored.join('|')}).*") + Lit.humanize_key_ignored = Regexp.new("(#{Lit.humanize_key_ignored.join("|")}).*") Lit.ignore_yaml_on_startup = true if Lit.ignore_yaml_on_startup.nil? - Lit.ignored_keys = Lit.ignored_keys.split(',').map(&:strip) if Lit.ignored_keys.is_a?(String) + Lit.ignored_keys = Lit.ignored_keys.split(",").map(&:strip) if Lit.ignored_keys.is_a?(String) Lit.ignored_keys = [] unless Lit.ignored_keys.is_a?(Array) Lit.ignored_keys = Lit.ignored_keys.map(&:freeze).freeze @@ -68,18 +68,18 @@ def self.check_if_table_exists def self.get_key_value_engine case Lit.key_value_engine - when 'redis' - require 'lit/adapters/redis_storage' - return ::Lit::Adapters::RedisStorage.new + when "redis" + require "lit/adapters/redis_storage" + ::Lit::Adapters::RedisStorage.new else - require 'lit/adapters/hash_storage' - return ::Lit::Adapters::HashStorage.new + require "lit/adapters/hash_storage" + ::Lit::Adapters::HashStorage.new end end def self.fallback=(_value) - ::Rails.logger.error '[DEPRECATION] Lit.fallback= has been deprecated, please use `config.i18n.fallbacks` instead' + ::Rails.logger.error "[DEPRECATION] Lit.fallback= has been deprecated, please use `config.i18n.fallbacks` instead" end end -require 'lit/rails' if defined?(Rails) +require "lit/rails" if defined?(Rails) diff --git a/lib/lit/cloud_translation/providers/google.rb b/lib/lit/cloud_translation/providers/google.rb index c5f56209..62e17479 100644 --- a/lib/lit/cloud_translation/providers/google.rb +++ b/lib/lit/cloud_translation/providers/google.rb @@ -1,10 +1,11 @@ # frozen_string_literal: true -require_relative 'base' +require_relative "base" begin - require 'google/cloud/translate' + require "google/cloud/translate" rescue LoadError - raise StandardError, 'You need to add "gem \'google-cloud-translate\'" to your Gemfile to support Google Cloud Translation' + raise StandardError, + 'You need to add "gem \'google-cloud-translate\'" to your Gemfile to support Google Cloud Translation' end module Lit::CloudTranslation::Providers @@ -44,8 +45,8 @@ module Lit::CloudTranslation::Providers # } # end class Google < Base - def translate(text:, from: nil, to:, **opts) - result = client.translate(sanitize_text(text), from: from, to: to, **opts) + def translate(text:, to:, from: nil, **) + result = client.translate(sanitize_text(text), from:, to:, **) unsanitize_text( case result when translation_class then result.text @@ -54,10 +55,10 @@ def translate(text:, from: nil, to:, **opts) ) rescue Signet::AuthorizationError => e error_description = - 'Google credentials error: ' + # rubocop:disable Style/RescueModifier - JSON.parse(e.response.body)['error_description'] rescue 'Unknown error' + "Google credentials error: " + # rubocop:disable Style/RescueModifier + JSON.parse(e.response.body)["error_description"] rescue "Unknown error" raise ::Lit::CloudTranslation::TranslationError, error_description, - cause: e + cause: e rescue ::Google::Cloud::Error => e raise ::Lit::CloudTranslation::TranslationError, e.message, cause: e end @@ -67,28 +68,21 @@ def translate(text:, from: nil, to:, **opts) def client @client ||= begin args = { - project_id: config.keyfile_hash['project_id'], credentials: config.keyfile_hash, + project_id: config.keyfile_hash["project_id"], credentials: config.keyfile_hash, version: :v2 } - if Gem.loaded_specs['google-cloud-translate'].version < Gem::Version.create('2.0') - args = args.tap { |hs| hs.delete(:version) } - end ::Google::Cloud::Translate.new(**args) end end def translation_class - if Gem.loaded_specs['google-cloud-translate'].version < Gem::Version.create('2.0') - ::Google::Cloud::Translate::Translation - else - ::Google::Cloud::Translate::V2::Translation - end + ::Google::Cloud::Translate::V2::Translation end def default_config - if ENV['GOOGLE_TRANSLATE_API_KEYFILE'].blank? + if ENV["GOOGLE_TRANSLATE_API_KEYFILE"].blank? env_keys = ENV.keys.grep(/\AGOOGLE_TRANSLATE_API_/) - keyfile_keys = env_keys.map(&:downcase).map { |k| k.gsub('google_translate_api_', '') } + keyfile_keys = env_keys.map(&:downcase).map { |k| k.gsub("google_translate_api_", "") } keyfile_key_to_env_key_mapping = keyfile_keys.zip(env_keys).to_h return { keyfile_hash: keyfile_key_to_env_key_mapping.transform_values do |env_key| @@ -96,26 +90,27 @@ def default_config end } end - { keyfile_hash: JSON.parse(File.read(ENV['GOOGLE_TRANSLATE_API_KEYFILE'])) } + {keyfile_hash: JSON.parse(File.read(ENV["GOOGLE_TRANSLATE_API_KEYFILE"]))} rescue JSON::ParserError raise rescue Errno::ENOENT - { keyfile_hash: nil } + {keyfile_hash: nil} end def require_config! return if config.keyfile_hash.present? - raise 'GOOGLE_TRANSLATE_API_KEYFILE env or `config.keyfile_hash` not given' + + raise "GOOGLE_TRANSLATE_API_KEYFILE env or `config.keyfile_hash` not given" end def sanitize_text(text_or_array) case text_or_array when String - text_or_array.gsub(/%{(.+?)}/, '__LIT__\1__LIT__').gsub(/\r\n/, '0') + text_or_array.gsub(/%{(.+?)}/, '__LIT__\1__LIT__').gsub("\r\n", "0") when Array text_or_array.map { |s| sanitize_text(s) } when nil - '' + "" else raise TypeError end diff --git a/lib/lit/cloud_translation/providers/yandex.rb b/lib/lit/cloud_translation/providers/yandex.rb index 30c07d6b..118d8d7f 100644 --- a/lib/lit/cloud_translation/providers/yandex.rb +++ b/lib/lit/cloud_translation/providers/yandex.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require_relative 'base' -require 'net/http' +require_relative "base" +require "net/http" module Lit::CloudTranslation::Providers # Yandex Translate API provider for Lit translation suggestions. @@ -20,14 +20,14 @@ module Lit::CloudTranslation::Providers # config.api_key = 'the_api_key' # end class Yandex < Base - def translate(text:, from: nil, to:, **opts) # rubocop:disable Metrics/MethodLength, Metrics/LineLength + def translate(text:, to:, from: nil, **opts) # rubocop:disable Metrics/MethodLength, Metrics/LineLength # puts "api key is: #{config.api_key}" # puts "translating #{text} from #{from} to #{to}" - uri = URI('https://translate.yandex.net/api/v1.5/tr.json/translate') + uri = URI("https://translate.yandex.net/api/v1.5/tr.json/translate") params = { key: config.api_key, text: sanitize_text(text), - lang: [from, to].compact.join('-'), + lang: [from, to].compact.join("-"), format: opts[:format], options: opts[:options] }.compact @@ -37,11 +37,11 @@ def translate(text:, from: nil, to:, **opts) # rubocop:disable Metrics/MethodLen unsanitize_text( case res when Net::HTTPOK - translations = JSON.parse(res.body)['text'] - translations.size == 1 ? translations.first : translations + translations = JSON.parse(res.body)["text"] + (translations.size == 1) ? translations.first : translations else raise ::Lit::CloudTranslation::TranslationError, - (JSON.parse(res.body)['message'] rescue "Unknown error: #{res.body}") # rubocop:disable Style/RescueModifier, Metrics/LineLength + (JSON.parse(res.body)["message"] rescue "Unknown error: #{res.body}") # rubocop:disable Style/RescueModifier, Metrics/LineLength end ) end @@ -49,12 +49,12 @@ def translate(text:, from: nil, to:, **opts) # rubocop:disable Metrics/MethodLen private def default_config - { api_key: ENV['YANDEX_TRANSLATE_API_KEY'] } + {api_key: ENV["YANDEX_TRANSLATE_API_KEY"]} end def require_config! return if config.api_key.present? - raise 'YANDEX_TRANSLATE_API_KEY env or `config.api_key` not given' + raise "YANDEX_TRANSLATE_API_KEY env or `config.api_key` not given" end def sanitize_text(text_or_array) @@ -64,7 +64,7 @@ def sanitize_text(text_or_array) when Array text_or_array.map { |s| sanitize_text(s) } when nil - '' + "" else raise TypeError end diff --git a/lib/lit/i18n_backend.rb b/lib/lit/i18n_backend.rb index a3e310b8..9d34a6c6 100644 --- a/lib/lit/i18n_backend.rb +++ b/lib/lit/i18n_backend.rb @@ -1,11 +1,13 @@ -require 'i18n' -require 'lit/services/humanize_service' +require "i18n" +require "lit/services/humanize_service" module Lit class I18nBackend include I18n::Backend::Simple::Implementation include I18n::Backend::Pluralization + MISSING_TRANSLATION = -(2**60) # :nodoc: + attr_reader :cache def initialize(cache) @@ -23,14 +25,12 @@ def initialize(cache) ## Any calls in Lit to `super` go straight to I18n def translate(locale, key, options = {}) options[:lit_default_copy] = options[:default].dup if can_dup_default(options) - content = super(locale, key, options) + content = super - if on_rails_6_1_or_higher? - @untranslated_key = key if key.present? && options[:default].instance_of?(Object) + @untranslated_key = key if key.present? && (options[:default].instance_of?(Object) || options[:default] == MISSING_TRANSLATION) - if key.nil? && options[:lit_default_copy].present? - update_default_localization(locale, options) - end + if key.nil? && options[:lit_default_copy].present? + update_default_localization(locale, options) end if Lit.all_translations_are_html_safe && content.respond_to?(:html_safe) @@ -43,10 +43,10 @@ def translate(locale, key, options = {}) def available_locales return @available_locales_cache unless @available_locales_cache.nil? @locales ||= ::Rails.configuration.i18n.available_locales - if @locales && !@locales.empty? - @available_locales_cache = @locales.map(&:to_sym) + @available_locales_cache = if @locales && !@locales.empty? + @locales.map(&:to_sym) else - @available_locales_cache = Lit::Locale.ordered.visible.map { |l| l.locale.to_sym } + Lit::Locale.ordered.visible.map { |l| l.locale.to_sym } end @available_locales_cache end @@ -61,21 +61,18 @@ def reset_available_locales_cache # @param [Hash] data nested key-value pairs to be added as blurbs def store_translations(locale, data, options = {}) super - ActiveRecord::Base.transaction do - store_item(locale, data) - end if store_items? && valid_locale?(locale) + if store_items? && valid_locale?(locale) + ActiveRecord::Base.transaction do + store_item(locale, data) + end + end end private - def on_rails_6_1_or_higher? - "#{::Rails::VERSION::MAJOR}#{::Rails::VERSION::MINOR}".to_i == 61 || - ::Rails::VERSION::MAJOR >= 7 - end - def update_default_localization(locale, options) parts = I18n.normalize_keys(locale, @untranslated_key, options[:scope], options[:separator]) - key_with_locale = parts.join('.') + key_with_locale = parts.join(".") content = options[:lit_default_copy] # we do not force array on singular strings packed into Array @cache.update_locale(key_with_locale, content, content.is_a?(Array) && content.length > 1) @@ -84,10 +81,10 @@ def update_default_localization(locale, options) def can_dup_default(options = {}) return false unless options.key?(:default) return true if options[:default].is_a?(String) - return true if options[:default].is_a?(Array) && \ - (options[:default].first.is_a?(String) || \ - options[:default].first.is_a?(Symbol) || \ - options[:default].first.is_a?(Array)) + return true if options[:default].is_a?(Array) && + (options[:default].first.is_a?(String) || + options[:default].first.is_a?(Symbol) || + options[:default].first.is_a?(Array)) false end @@ -95,7 +92,7 @@ def lookup(locale, key, scope = [], options = {}) init_translations unless initialized? parts = I18n.normalize_keys(locale, key, scope, options[:separator]) - key_with_locale = parts.join('.') + key_with_locale = parts.join(".") # we might want to return content later, but we first need to check if it's in cache. # it's important to rememver, that accessing non-existen key modifies cache by creating one @@ -118,13 +115,13 @@ def lookup(locale, key, scope = [], options = {}) # check if default was provided if options[:lit_default_copy].present? # default most likely will be an array - if options[:lit_default_copy].is_a?(Array) - default = options[:lit_default_copy].map do |key_or_value| + default = if options[:lit_default_copy].is_a?(Array) + options[:lit_default_copy].map do |key_or_value| if key_or_value.is_a?(Symbol) normalized = I18n.normalize_keys( nil, key_or_value.to_s, options[:scope], options[:separator] - ).join('.') - if on_rails_6_1_or_higher? && Lit::Services::HumanizeService.should_humanize?(key) + ).join(".") + if Lit::Services::HumanizeService.should_humanize?(key) Lit::Services::HumanizeService.humanize(normalized) else normalized.to_sym @@ -134,19 +131,19 @@ def lookup(locale, key, scope = [], options = {}) end end else - default = options[:lit_default_copy] + options[:lit_default_copy] end content = default end # if we have content now, let's store it in cache - if content.present? - content = Array.wrap(content).compact.reject(&:empty?).reverse.find do |default_cand| + if content.present? && content != MISSING_TRANSLATION + content = Array.wrap(content).compact.reject { |e| e == MISSING_TRANSLATION }.reject(&:empty?).reverse.find do |default_cand| @cache[key_with_locale] = default_cand @cache[key_with_locale] end end - if content.nil? && !on_rails_6_1_or_higher? && Lit::Services::HumanizeService.should_humanize?(key) + if content.nil? && Lit::Services::HumanizeService.should_humanize?(key) @cache[key_with_locale] = Lit::Services::HumanizeService.humanize(key) content = @cache[key_with_locale] end @@ -157,20 +154,20 @@ def lookup(locale, key, scope = [], options = {}) end def store_item(locale, data, scope = [], startup_process = false) - key = ([locale] + scope).join('.') + key = ([locale] + scope).join(".") if data.respond_to?(:to_hash) # ActiveRecord::Base.transaction do - data.to_hash.each do |k, value| - store_item(locale, value, scope + [k], startup_process) - end + data.to_hash.each do |k, value| + store_item(locale, value, scope + [k], startup_process) + end # end elsif data.respond_to?(:to_str) || data.is_a?(Array) - key = ([locale] + scope).join('.') + key = ([locale] + scope).join(".") return if startup_process && Lit.ignore_yaml_on_startup && (Thread.current[:lit_cache_keys] || @cache.keys).member?(key) @cache.update_locale(key, data, data.is_a?(Array), startup_process) elsif data.nil? return if startup_process - key = ([locale] + scope).join('.') + key = ([locale] + scope).join(".") @cache.delete_locale(key) end end @@ -215,7 +212,7 @@ def valid_locale?(locale) end def is_ignored_key(key_without_locale) - Lit.ignored_keys.any?{ |k| key_without_locale.start_with?(k) } + Lit.ignored_keys.any? { |k| key_without_locale.start_with?(k) } end # checks if should cache. `had_key` is passed, as once cache has been accesed, it's already modified and key exists diff --git a/lib/lit/version.rb b/lib/lit/version.rb index 92db8607..f3c78c53 100644 --- a/lib/lit/version.rb +++ b/lib/lit/version.rb @@ -8,10 +8,10 @@ def version end module Version - MAJOR = 1 - MINOR = 1 - TINY = 6 + MAJOR = 2 + MINOR = 0 + TINY = 0 - STRING = [MAJOR, MINOR, TINY].compact.join('.') + STRING = [MAJOR, MINOR, TINY].compact.join(".") end end diff --git a/lit.gemspec b/lit.gemspec index b7222470..c4e9a915 100644 --- a/lit.gemspec +++ b/lit.gemspec @@ -1,33 +1,34 @@ -$LOAD_PATH.push File.expand_path('../lib', __FILE__) +$LOAD_PATH.push File.expand_path("lib", __dir__) -require 'lit/version' +require "lit/version" Gem::Specification.new do |s| - s.name = 'lit' + s.name = "lit" s.version = Lit.version - s.authors = ['Maciej Litwiniuk', 'Piotr Boniecki', 'Michał Buszkiewicz', 'Szymon Soppa'] - s.email = ['maciej@litwiniuk.net'] - s.license = 'MIT' - s.homepage = 'https://github.com/prograils/lit' - s.summary = 'Database powered i18n backend with web gui' + s.authors = ["Maciej Litwiniuk", "Piotr Boniecki", "Michał Buszkiewicz", "Szymon Soppa"] + s.email = ["maciej@litwiniuk.net"] + s.license = "MIT" + s.homepage = "https://github.com/prograils/lit" + s.summary = "Database powered i18n backend with web gui" s.description = "Translate your apps with pleasure (sort of...) and for free. It's simple i18n web interface, build on top of twitter bootstrap, that one may find helpful in translating app by non-technicals. " - s.files = Dir['{app,config,db,lib}/**/*'] + %w[MIT-LICENSE Rakefile README.md] - s.add_dependency 'rails', '>= 5.2.0' - s.add_dependency 'jquery-rails' - s.add_dependency 'coffee-rails' - s.add_dependency 'sass-rails' - s.add_dependency 'emoji_flag' + s.files = Dir["{app,config,db,lib}/**/*"] + %w[MIT-LICENSE Rakefile README.md] + s.add_dependency "emoji_flag" + s.add_dependency "jquery-rails" + s.add_dependency "rails", ">= 7.0" - s.add_development_dependency 'appraisal', '~> 2.4.0' - s.add_development_dependency 'devise', '~> 4.7.1' - s.add_development_dependency 'minitest', '~> 5.11.3' - s.add_development_dependency 'minitest-vcr', '~> 1.4.0' - s.add_development_dependency 'pry-byebug', '~> 3.9.0' - s.add_development_dependency 'vcr', '~> 4.0.0' - s.add_development_dependency 'webmock', '~> 3.4.2' + s.add_development_dependency "appraisal", "~> 2.5.0" + s.add_development_dependency "devise", "~> 4.8.0" + s.add_development_dependency "minitest", "~> 5.20" + s.add_development_dependency "pry-byebug", "~> 3.9" + s.add_development_dependency "pry-stack_explorer", "~> 0.6.0" + s.add_development_dependency "standard" + s.add_development_dependency "standard-performance" + s.add_development_dependency "standard-rails" + s.add_development_dependency "vcr", "~> 6.0" + s.add_development_dependency "webmock", "~> 3.4" end diff --git a/test/dummy/config/initializers/lit.rb b/test/dummy/config/initializers/lit.rb index 4083236d..4c015423 100644 --- a/test/dummy/config/initializers/lit.rb +++ b/test/dummy/config/initializers/lit.rb @@ -1,9 +1,11 @@ Lit.authentication_function = :authenticate_admin! Lit.authentication_verification = :admin_signed_in? -Lit.key_value_engine = ENV['LIT_STORAGE'] || 'redis' +Lit.key_value_engine = ENV["LIT_STORAGE"] || "redis" Lit.humanize_key = false Lit.ignore_yaml_on_startup = true Lit.api_enabled = true -Lit.api_key = 'ala' +Lit.api_key = "ala" Lit.all_translations_are_html_safe = true -Lit.init +Rails.application.config.after_initialize do + Lit.init +end diff --git a/test/dummy/db/schema.rb b/test/dummy/db/schema.rb index 00ac0d71..bad72b52 100644 --- a/test/dummy/db/schema.rb +++ b/test/dummy/db/schema.rb @@ -2,37 +2,36 @@ # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. # -# This file is the source Rails uses to define your schema when running `rails -# db:schema:load`. When creating a new database, `rails db:schema:load` tends to +# This file is the source Rails uses to define your schema when running `bin/rails +# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to # be faster and is potentially less error prone than running all of your # migrations from scratch. Old migrations may fail to apply correctly if those # migrations use external dependencies or application code. # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2018_11_29_103819) do - +ActiveRecord::Schema[7.0].define(version: 2018_11_29_103819) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" create_table "admins", id: :serial, force: :cascade do |t| - t.string "email", limit: 255, default: "", null: false - t.string "encrypted_password", limit: 255, default: "", null: false - t.string "reset_password_token", limit: 255 - t.datetime "reset_password_sent_at" - t.datetime "remember_created_at" + t.string "email", default: "", null: false + t.string "encrypted_password", default: "", null: false + t.string "reset_password_token" + t.datetime "reset_password_sent_at", precision: nil + t.datetime "remember_created_at", precision: nil t.integer "sign_in_count", default: 0 - t.datetime "current_sign_in_at" - t.datetime "last_sign_in_at" - t.string "current_sign_in_ip", limit: 255 - t.string "last_sign_in_ip", limit: 255 - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "current_sign_in_at", precision: nil + t.datetime "last_sign_in_at", precision: nil + t.string "current_sign_in_ip" + t.string "last_sign_in_ip" + t.datetime "created_at", precision: nil + t.datetime "updated_at", precision: nil t.index ["email"], name: "index_admins_on_email", unique: true t.index ["reset_password_token"], name: "index_admins_on_reset_password_token", unique: true end - create_table "lit_incomming_localizations", id: :serial, force: :cascade do |t| + create_table "lit_incomming_localizations", force: :cascade do |t| t.text "translated_value" t.integer "locale_id" t.integer "localization_key_id" @@ -41,8 +40,8 @@ t.string "localization_key_str" t.integer "source_id" t.integer "incomming_id" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.boolean "localization_key_is_deleted", default: false, null: false t.index ["incomming_id"], name: "index_lit_incomming_localizations_on_incomming_id" t.index ["locale_id"], name: "index_lit_incomming_localizations_on_locale_id" @@ -51,17 +50,17 @@ t.index ["source_id"], name: "index_lit_incomming_localizations_on_source_id" end - create_table "lit_locales", id: :serial, force: :cascade do |t| - t.string "locale", limit: 255 - t.datetime "created_at" - t.datetime "updated_at" + create_table "lit_locales", force: :cascade do |t| + t.string "locale" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.boolean "is_hidden", default: false end - create_table "lit_localization_keys", id: :serial, force: :cascade do |t| - t.string "localization_key", limit: 255 - t.datetime "created_at" - t.datetime "updated_at" + create_table "lit_localization_keys", force: :cascade do |t| + t.string "localization_key" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.boolean "is_completed", default: false t.boolean "is_starred", default: false t.boolean "is_deleted", default: false, null: false @@ -69,41 +68,41 @@ t.index ["localization_key"], name: "index_lit_localization_keys_on_localization_key", unique: true end - create_table "lit_localization_versions", id: :serial, force: :cascade do |t| + create_table "lit_localization_versions", force: :cascade do |t| t.text "translated_value" t.integer "localization_id" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.index ["localization_id"], name: "index_lit_localization_versions_on_localization_id" end - create_table "lit_localizations", id: :serial, force: :cascade do |t| + create_table "lit_localizations", force: :cascade do |t| t.integer "locale_id" t.integer "localization_key_id" t.text "default_value" t.text "translated_value" t.boolean "is_changed", default: false - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.index ["locale_id"], name: "index_lit_localizations_on_locale_id" t.index ["localization_key_id", "locale_id"], name: "index_lit_localizations_on_localization_key_id_and_locale_id", unique: true t.index ["localization_key_id"], name: "index_lit_localizations_on_localization_key_id" end - create_table "lit_sources", id: :serial, force: :cascade do |t| + create_table "lit_sources", force: :cascade do |t| t.string "identifier" t.string "url" t.string "api_key" t.datetime "last_updated_at" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.boolean "sync_complete" end create_table "projects", id: :serial, force: :cascade do |t| - t.string "name", limit: 255 - t.datetime "created_at" - t.datetime "updated_at" + t.string "name" + t.datetime "created_at", precision: nil + t.datetime "updated_at", precision: nil end end diff --git a/test/functional/lit/api/v1/localizations_controller_test.rb b/test/functional/lit/api/v1/localizations_controller_test.rb index 44ae7143..4c5729a8 100644 --- a/test/functional/lit/api/v1/localizations_controller_test.rb +++ b/test/functional/lit/api/v1/localizations_controller_test.rb @@ -1,4 +1,4 @@ -require 'test_helper' +require "test_helper" module Lit class Api::V1::LocalizationsControllerTest < ActionController::TestCase @@ -8,11 +8,11 @@ def setup Lit::LocalizationVersion.delete_all Lit.loader = nil Lit.api_enabled = true - Lit.api_key = 'test' + Lit.api_key = "test" Lit::Engine.routes.clear! Dummy::Application.reload_routes! @routes = Lit::Engine.routes - request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Token.encode_credentials('test') + request.env["HTTP_AUTHORIZATION"] = ActionController::HttpAuthentication::Token.encode_credentials("test") Lit.ignore_yaml_on_startup = false Lit.init end @@ -21,35 +21,34 @@ def teardown Lit.ignore_yaml_on_startup = nil end - test 'should get index' do + test "should get index" do get :index, format: :json assert_response :success end - test 'should only changed records' do + test "should only changed records" do I18n.l(Time.now) - Lit::Localization.update_all ['updated_at=?', 2.hours.ago] + Lit::Localization.update_all ["updated_at=?", 2.hours.ago] l = Lit::Localization.last - l.translated_value = 'test' + l.translated_value = "test" l.is_changed = true l.save - get :index, params: { format: :json, after: 2.seconds.ago.to_s(:db) } + get :index, params: {format: :json, after: 2.seconds.ago.to_fs(:db)} assert_response :success assert_equal 1, assigns(:localizations).count assert response.body =~ /#{l.value}/ end - test 'should return last update date' do + test "should return last update date" do I18n.l(Time.now) - Lit::Localization.update_all ['updated_at=?', 2.hours.ago] + Lit::Localization.update_all ["updated_at=?", 2.hours.ago] l = Lit::Localization.last - l.translated_value = 'test' + l.translated_value = "test" l.save get :last_change, format: :json assert_response :success assert_equal l, assigns(:localization) - assert response.body =~ /#{l.updated_at.to_s(:db)}/ - + assert response.body =~ /#{l.updated_at.to_fs(:db)}/ end end end diff --git a/test/functional/lit/incomming_localizations_controller_test.rb b/test/functional/lit/incomming_localizations_controller_test.rb index 7186554d..e967573f 100644 --- a/test/functional/lit/incomming_localizations_controller_test.rb +++ b/test/functional/lit/incomming_localizations_controller_test.rb @@ -1,24 +1,24 @@ -require 'test_helper' +require "test_helper" module Lit class IncommingLocalizationsControllerTest < ActionController::TestCase - fixtures 'lit/sources' + fixtures "lit/sources" set_fixture_class lit_sources: Lit::Source def setup Lit.authentication_function = nil @routes = Lit::Engine.routes - stub_request(:get, 'http://testhost.com/lit/api/v1/last_change.json'). - to_return(body: { last_change: 1.hour.ago.to_s(:db) }.to_json) + stub_request(:get, "http://testhost.com/lit/api/v1/last_change.json") + .to_return(body: {last_change: 1.hour.ago.to_fs(:db)}.to_json) @source = lit_sources(:test) end - test 'should get index' do - get :index, params: { source_id: @source.id } + test "should get index" do + get :index, params: {source_id: @source.id} assert_response :success end - test 'should properly return to index' do - get :accept_all, params: { source_id: @source.id } + test "should properly return to index" do + get :accept_all, params: {source_id: @source.id} assert_response :redirect end end diff --git a/test/functional/lit/sources_controller_test.rb b/test/functional/lit/sources_controller_test.rb index 96df2bd5..61074f82 100644 --- a/test/functional/lit/sources_controller_test.rb +++ b/test/functional/lit/sources_controller_test.rb @@ -1,77 +1,77 @@ -require 'test_helper' +require "test_helper" module Lit class SourcesControllerTest < ActionController::TestCase - fixtures 'lit/sources' + fixtures "lit/sources" setup do Lit.authentication_function = nil @routes = Lit::Engine.routes - stub_request(:get, 'http://testhost.com/lit/api/v1/last_change.json'). - to_return(body: { last_change: 1.hour.ago.to_s(:db) }.to_json) + stub_request(:get, "http://testhost.com/lit/api/v1/last_change.json") + .to_return(body: {last_change: 1.hour.ago.to_fs(:db)}.to_json) @source = lit_sources(:test) end - test 'should get index' do + test "should get index" do get :index assert_response :success assert_not_nil assigns(:sources) end - test 'should get new' do + test "should get new" do get :new assert_response :success end - test 'should create source' do - assert_difference('Source.count') do + test "should create source" do + assert_difference("Source.count") do post :create, params: { - source: { identifier: 'test2', - url: 'http://testhost.com/lit', - api_key: 'blabla' } - } + source: {identifier: "test2", + url: "http://testhost.com/lit", + api_key: "blabla"} + } end assert_redirected_to source_path(assigns(:source)) end - test 'should show source' do - get :show, params: { id: @source } + test "should show source" do + get :show, params: {id: @source} assert_response :success end - test 'should get edit' do - get :edit, params: { id: @source } + test "should get edit" do + get :edit, params: {id: @source} assert_response :success end - test 'should update source' do - put :update, params: { id: @source, source: { identifier: 'test2' } } + test "should update source" do + put :update, params: {id: @source, source: {identifier: "test2"}} assert_redirected_to source_path(assigns(:source)) @source.reload - assert_equal 'test2', @source.identifier + assert_equal "test2", @source.identifier end - test 'should update last_updates_at' do + test "should update last_updates_at" do prev_last_updated_at = @source.last_updated_at - put :touch, params: { id: @source } + put :touch, params: {id: @source} assert_redirected_to source_path(assigns(:source)) @source.reload assert_redirected_to @source assert @source.last_updated_at > prev_last_updated_at end - test 'should destroy source' do - assert_difference('Source.count', -1) do - delete :destroy, params: { id: @source } + test "should destroy source" do + assert_difference("Source.count", -1) do + delete :destroy, params: {id: @source} end assert_redirected_to sources_path end - test 'should indicate sync completion' do + test "should indicate sync completion" do @source.update_column(:sync_complete, true) - get :sync_complete, params: { format: :json, id: @source.id } + get :sync_complete, params: {format: :json, id: @source.id} body = JSON.parse(response.body) - assert_equal true, body['sync_complete'] + assert_equal true, body["sync_complete"] end end end diff --git a/test/functional/welcome_controller_test.rb b/test/functional/welcome_controller_test.rb index e02cec3e..65f311bd 100644 --- a/test/functional/welcome_controller_test.rb +++ b/test/functional/welcome_controller_test.rb @@ -1,4 +1,4 @@ -require 'test_helper' +require "test_helper" class WelcomeControllerTest < ActionController::TestCase def setup @@ -14,27 +14,28 @@ def teardown Lit.ignore_yaml_on_startup = nil end - test 'should properly show index' do + test "should properly show index" do # $redis.flushall - get :index, params: { locale: :en } + get :index, params: {locale: :en} assert_response :success assert I18n.locale == :en end - test 'should properly load value from yaml' do - get :index, params: { locale: :en } - assert Lit::LocalizationKey.where(localization_key: 'date.abbr_day_names').exists? - assert_equal I18n.t('date.abbr_day_names'), %w( Sun Mon Tue Wed Thu Fri Sat ) + test "should properly load value from yaml" do + get :index, params: {locale: :en} + assert Lit::LocalizationKey.where(localization_key: "date.abbr_day_names").exists? + assert_equal I18n.t("date.abbr_day_names"), %w[Sun Mon Tue Wed Thu Fri Sat] end - test 'should properly store key with default value' do - get :index, params: { locale: :en } - localization_key = Lit::LocalizationKey.where(localization_key: 'scope.text_with_default').first + test "should properly store key with default value" do + get :index, params: {locale: :en} + localization_key = Lit::LocalizationKey.where(localization_key: "scope.text_with_default").first assert localization_key.present? locale = Lit::Locale.find_by(locale: :en) localization = localization_key.localizations.find_by(locale_id: locale.id) - assert_equal localization.translation, 'Default content' - assert_equal localization.to_s, 'Default content' - assert_equal localization.default_value, 'Default content' + + assert_equal "Default content", localization.translation + assert_equal "Default content", localization.to_s + assert_equal "Default content", localization.default_value end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 0a9009a4..c39b4e30 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,5 +1,5 @@ # Configure Rails Environment -ENV['RAILS_ENV'] = 'test' +ENV["RAILS_ENV"] = "test" # We get a whole bunch of method redefinition warnings, mostly coming # from Devise - e.g. when routes are reloaded in controller tests. @@ -7,18 +7,19 @@ # when using `rails test` instead of `rake` is `false`) $VERBOSE = false # equivalent to `ruby -W1` -require File.expand_path('../dummy/config/environment.rb', __FILE__) -require 'rails/test_help' -require 'capybara/rails' -require 'database_cleaner' -require 'test_declarative' -require 'mocha/setup' -require 'webmock' -require 'vcr' -require 'minitest-vcr' +require File.expand_path("dummy/config/environment.rb", __dir__) +require "rails/test_help" +require "capybara/rails" +require "database_cleaner" +require "test_declarative" +require "minitest/autorun" +require "mocha/minitest" +require "vcr" +require "minitest-vcr" +require "webmock" begin - require 'rails-controller-testing' + require "rails-controller-testing" Rails::Controller::Testing.install rescue LoadError end @@ -35,7 +36,7 @@ def load_sample_yml(fname) I18n.load_path << "#{File.dirname(__FILE__)}/support/#{fname}" end -ActiveSupport::TestCase.fixture_path = File.expand_path('../fixtures', __FILE__) +ActiveSupport::TestCase.fixture_path = File.expand_path("fixtures", __dir__) ## do not enforce available locales I18n.config.enforce_available_locales = false @@ -109,20 +110,22 @@ def non_kwarg_request_warning # @example # call_action :get, :show, params: { ... } def call_action(verb, action, params: {}) - send verb, action, params: params + send verb, action, params: end end VCR.configure do |config| - config.cassette_library_dir = 'test/cassettes' + # config.allow_http_connections_when_no_cassette = true + config.cassette_library_dir = "test/cassettes" config.hook_into :webmock + config.ignore_localhost = true end MinitestVcr::Spec.configure! def assert_no_database_queries - ActiveRecord::Base.connection.stubs(:execute). - raises(Minitest::Assertion, 'The block should not make any database calls') + ActiveRecord::Base.connection.stubs(:execute) + .raises(Minitest::Assertion, "The block should not make any database calls") yield ActiveRecord::Base.connection.unstub(:execute) end diff --git a/test/unit/i18n_backend_test.rb b/test/unit/i18n_backend_test.rb index 95f15f4c..f222ffce 100644 --- a/test/unit/i18n_backend_test.rb +++ b/test/unit/i18n_backend_test.rb @@ -1,7 +1,7 @@ -require 'test_helper' +require "test_helper" class I18nBackendTest < ActiveSupport::TestCase - fixtures 'lit/locales' + fixtures "lit/locales" class Backend < Lit::I18nBackend end @@ -20,7 +20,7 @@ def teardown Lit.humanize_key = @old_humanize_key end - test 'properly returns available locales' do + test "properly returns available locales" do I18n.backend = Backend.new(Lit.loader.cache) assert_equal 2, I18n.backend.available_locales.count ::Rails.configuration.i18n.available_locales = [:en, :pl] @@ -31,48 +31,34 @@ def teardown assert_equal 1, I18n.backend.available_locales.count end - test 'auto-humanizes key when Lit.humanize_key=true' do - # since Rails 6.1 pure i18n calls should not be humanized - skip if I18n.backend.send(:on_rails_6_1_or_higher?) + test "wont humanize key, if key is ignored" do Lit.humanize_key = true I18n.locale = :en - test_key = 'this_will_get_humanized' - humanized_key = 'This will get humanized' - assert_equal I18n.t(test_key), humanized_key + test_key = "date.this_will_get_humanized" + assert_equal I18n.t(test_key), "Translation missing: en.date.this_will_get_humanized" lk = Lit::LocalizationKey.find_by localization_key: test_key - locale = Lit::Locale.find_by locale: 'en' - l = lk.localizations.where(locale: locale).first - assert_equal l.default_value, humanized_key - end - - test 'wont humanize key, if key is ignored' do - Lit.humanize_key = true - I18n.locale = :en - test_key = 'date.this_will_get_humanized' - assert_equal I18n.t(test_key), 'translation missing: en.date.this_will_get_humanized' - lk = Lit::LocalizationKey.find_by localization_key: test_key - locale = Lit::Locale.find_by locale: 'en' + locale = Lit::Locale.find_by locale: "en" l = lk.localizations.where(locale: locale).first assert_nil l.default_value end - test 'will not call additional queries when nil values in a fallback key chain have been cached' do + test "will not call additional queries when nil values in a fallback key chain have been cached" do Lit.humanize_key = false I18n.locale = :en - test_key = :'test.key' - fallback_key = :'test.fallback' + test_key = :"test.key" + fallback_key = :"test.fallback" # first, when these keys don't exist in the DB yet, they should be created: loc_key_count = -> { Lit::LocalizationKey.where(localization_key: [test_key, fallback_key]).count } assert_equal 0, loc_key_count.call - assert_equal 'foobar', I18n.t(test_key, default: [fallback_key, 'foobar']) + assert_equal "foobar", I18n.t(test_key, default: [fallback_key, "foobar"]) # We do not create localization key record for fallback keys if value is found assert_equal 1, loc_key_count.call # on subsequent translation calls, they should not be fetched from DB assert_no_database_queries do - assert_equal 'foobar', I18n.t(test_key, default: [fallback_key, 'foobar']) + assert_equal "foobar", I18n.t(test_key, default: [fallback_key, "foobar"]) end end end diff --git a/test/unit/lit/cloud_translation/providers/examples.rb b/test/unit/lit/cloud_translation/providers/examples.rb index 1b42ad2d..e8f4e997 100644 --- a/test/unit/lit/cloud_translation/providers/examples.rb +++ b/test/unit/lit/cloud_translation/providers/examples.rb @@ -1,66 +1,65 @@ # frozen_string_literal: true def cloud_provider_examples(described_klass) - let(:text) { 'The quick brown fox jumps over the lazy dog.' } - let(:from) { 'en' } - let(:to) { 'pl' } + let(:text) { "The quick brown fox jumps over the lazy dog." } + let(:from) { "en" } + let(:to) { "pl" } - describe 'when only :to language is given' do + describe "when only :to language is given" do subject do - described_klass.translate(text: text, to: to) + described_klass.translate(text:, to:) end - describe 'when single string is given' do - it 'translates single string to target language' do + describe "when single string is given" do + it "translates single string to target language" do _(subject).must_match(/\blis\b/) end - describe 'when string contains interpolation' do - let(:text) { 'here is your %{meal}, enjoy' } + describe "when string contains interpolation" do + let(:text) { "here is your %{meal}, enjoy" } - it 'does not translate stuff enclosed in %{}' do + it "does not translate stuff enclosed in %{}" do _(subject).must_match(/%{meal}/) end end - end - describe 'when array of strings is given' do + describe "when array of strings is given" do let(:text) { %w[awesome stuff] } - it 'translates array of strings to target language' do + it "translates array of strings to target language" do _(subject.length).must_equal 2 end end - describe 'when array containing nil values is given' do - let(:text) { [nil, 'awesome', nil, 'stuff'] } + describe "when array containing nil values is given" do + let(:text) { [nil, "awesome", nil, "stuff"] } it 'translates array to target language, converting nil to ""' do - _(subject.first).must_equal '' + _(subject.first).must_equal "" _(subject.second).must_be :present? - _(subject.third).must_equal '' + _(subject.third).must_equal "" _(subject.fourth).must_be :present? _(subject.length).must_equal 4 end end end - describe 'when :from and :to languages are given' do + describe "when :from and :to languages are given" do subject do - described_klass.translate(text: text, from: from, to: to) + described_klass.translate(text:, from:, to:) end - describe 'when single string is given' do - it 'translates single string to target language' do + describe "when single string is given" do + it "translates single string to target language" do _(subject).must_match(/\blis\b/) end end - describe 'when array of strings is given' do + describe "when array of strings is given" do let(:text) { %w[awesome stuff] } - it 'translates array of strings to target language' do + it "translates array of strings to target language" do _(subject.length).must_equal 2 end end diff --git a/test/unit/lit/cloud_translation/providers/google_test.rb b/test/unit/lit/cloud_translation/providers/google_test.rb index 7efe9ed8..e758825f 100644 --- a/test/unit/lit/cloud_translation/providers/google_test.rb +++ b/test/unit/lit/cloud_translation/providers/google_test.rb @@ -1,27 +1,28 @@ # frozen_string_literal: true -require 'test_helper' -require 'lit/cloud_translation/providers/google' -require 'minitest/mock' +require "test_helper" +require "lit/cloud_translation/providers/google" +require "google/cloud/translate/v2" +require "minitest/mock" -require_relative 'examples' +require_relative "examples" -describe Lit::CloudTranslation::Providers::Google, vcr: { record: :none } do +describe Lit::CloudTranslation::Providers::Google, vcr: {record: :none} do before do # comment this stubbing block out, provide a .json keyfile and point to its location # via GOOGLE_TRANSLATE_API_KEYFILE env to write tests (also set record: :all) Lit::CloudTranslation::Providers::Google.any_instance.stubs(:default_config).returns( # rubocop:disable Metrics/LineLength - keyfile_hash: { 'type' => 'service_account', - 'project_id' => 'redacted', - 'private_key_id' => 'redacted', - 'private_key' => 'redacted', - 'client_email' => 'redacted@redacted.iam.gserviceaccount.com', - 'client_id' => 'redacted', - 'auth_uri' => 'https://accounts.google.com/o/oauth2/auth', - 'token_uri' => 'https://oauth2.googleapis.com/token', - 'auth_provider_x509_cert_url' => 'https://www.googleapis.com/oauth2/v1/certs', - 'client_x509_cert_url' => 'https://www.googleapis.com/robot/v1/metadata/x509/redacted@redacted.iam.gserviceaccount.com' } + keyfile_hash: {"type" => "service_account", + "project_id" => "redacted", + "private_key_id" => "redacted", + "private_key" => "redacted", + "client_email" => "redacted@redacted.iam.gserviceaccount.com", + "client_id" => "redacted", + "auth_uri" => "https://accounts.google.com/o/oauth2/auth", + "token_uri" => "https://oauth2.googleapis.com/token", + "auth_provider_x509_cert_url" => "https://www.googleapis.com/oauth2/v1/certs", + "client_x509_cert_url" => "https://www.googleapis.com/robot/v1/metadata/x509/redacted@redacted.iam.gserviceaccount.com"} # rubocop:enable Metrics/LineLength ) Google::Auth::Credentials.stubs(:new).returns(OpenStruct.new) @@ -30,36 +31,32 @@ cloud_provider_examples(Lit::CloudTranslation::Providers::Google) def gtranslate_api_class - if Gem.loaded_specs['google-cloud-translate'].version < Gem::Version.create('2.0') - ::Google::Cloud::Translate::Api - else - ::Google::Cloud::Translate::V2::Api - end + ::Google::Cloud::Translate::V2::Api end - describe 'errors' do - describe 'when credentials error occurs' do + describe "errors" do + describe "when credentials error occurs" do before do gtranslate_api_class .any_instance.stubs(:translate) - .raises(Signet::AuthorizationError, 'Credentials error') + .raises(Signet::AuthorizationError, "Credentials error") end - it 'raises Lit::CloudTranslation::TranslationError' do + it "raises Lit::CloudTranslation::TranslationError" do assert_raises Lit::CloudTranslation::TranslationError do Lit::CloudTranslation::Providers::Google.translate(text: text, to: to) end end end - describe 'when translation error occurs' do + describe "when translation error occurs" do before do gtranslate_api_class .any_instance.stubs(:translate) - .raises(::Google::Cloud::InternalError, 'Google failure') + .raises(::Google::Cloud::InternalError, "Google failure") end - it 'raises Lit::CloudTranslation::TranslationError' do + it "raises Lit::CloudTranslation::TranslationError" do assert_raises Lit::CloudTranslation::TranslationError do Lit::CloudTranslation::Providers::Google.translate(text: text, to: to) end @@ -67,12 +64,12 @@ def gtranslate_api_class end end - describe 'edge cases' do - describe 'when text contains newline characters' do + describe "edge cases" do + describe "when text contains newline characters" do let(:text) { "Some longer paragraph text\r\nOne line below" } - it 'translation comes back preserving those characters' do - result = Lit::CloudTranslation::Providers::Google.translate(text: text, to: 'pl') + it "translation comes back preserving those characters" do + result = Lit::CloudTranslation::Providers::Google.translate(text: text, to: "pl") assert result.include?("\r\n") assert result.include?("tekstu akapitu \r\n Jeden wiersz") end diff --git a/test/unit/lit/incomming_localization_test.rb b/test/unit/lit/incomming_localization_test.rb index 9b978d87..bde828c8 100644 --- a/test/unit/lit/incomming_localization_test.rb +++ b/test/unit/lit/incomming_localization_test.rb @@ -1,24 +1,24 @@ -require 'test_helper' +require "test_helper" module Lit class IncommingLocalizationTest < ActiveSupport::TestCase def setup DatabaseCleaner.clean_with :truncation - stub_request(:get, 'http://testhost.com/lit/api/v1/last_change.json').to_return( - body: { last_change: 1.hour.ago.to_s(:db) }.to_json, + stub_request(:get, "http://testhost.com/lit/api/v1/last_change.json").to_return( + body: {last_change: 1.hour.ago.to_fs(:db)}.to_json ) - @source = Lit::Source.create url: 'http://testhost.com/lit', api_key: 'test', identifier: 'test' + @source = Lit::Source.create url: "http://testhost.com/lit", api_key: "test", identifier: "test" end - test 'on accept deletes itself and creates all missing records' do + test "on accept deletes itself and creates all missing records" do assert_equal 0, Locale.count assert_equal 0, Localization.count assert_equal 0, LocalizationKey.count il = - IncommingLocalization.create locale_str: 'de', - localization_key_str: 'scope.test', - translated_value: 'scope.test', - source: @source + IncommingLocalization.create locale_str: "de", + localization_key_str: "scope.test", + translated_value: "scope.test", + source: @source assert_equal 0, Locale.count assert_equal 0, Localization.count assert_equal 0, LocalizationKey.count @@ -29,31 +29,31 @@ def setup assert_equal true, Localization.first.is_changed? end - test '#duplicated? returns true when localization key is deleted' do - locale = Locale.create locale: 'en' - l_k = LocalizationKey.create localization_key: 'test' - localization = Localization.create locale: locale, localization_key: l_k, default_value: 'test test' + test "#duplicated? returns true when localization key is deleted" do + locale = Locale.create locale: "en" + l_k = LocalizationKey.create localization_key: "test" + localization = Localization.create locale:, localization_key: l_k, default_value: "test test" il = IncommingLocalization.create locale_str: locale.locale, - localization_key_str: l_k.localization_key, - translated_value: localization.translated_value, - localization: localization, - source: @source - assert il.duplicated?('test test') + localization_key_str: l_k.localization_key, + translated_value: localization.translated_value, + localization:, + source: @source + assert il.duplicated?("test test") end - test '#duplicated? returns false when incomming localization key is deleted' do - locale = Locale.create locale: 'en' - l_k = LocalizationKey.create localization_key: 'test' - localization = Localization.create locale: locale, localization_key: l_k, translated_value: 'test test' + test "#duplicated? returns false when incomming localization key is deleted" do + locale = Locale.create locale: "en" + l_k = LocalizationKey.create localization_key: "test" + localization = Localization.create locale:, localization_key: l_k, translated_value: "test test" il = IncommingLocalization.create locale_str: locale.locale, - localization_key_str: l_k.localization_key, - translated_value: localization.translated_value, - localization: localization, - source: @source, - localization_key_is_deleted: true - assert_not il.duplicated?('test test') + localization_key_str: l_k.localization_key, + translated_value: localization.translated_value, + localization:, + source: @source, + localization_key_is_deleted: true + assert_not il.duplicated?("test test") end end end diff --git a/test/unit/lit/source_test.rb b/test/unit/lit/source_test.rb index a7205451..01c44a5b 100644 --- a/test/unit/lit/source_test.rb +++ b/test/unit/lit/source_test.rb @@ -1,27 +1,27 @@ -require 'test_helper' +require "test_helper" module Lit class SourceTest < ActiveSupport::TestCase - fixtures 'lit/sources' + fixtures "lit/sources" def setup - stub_request(:get, 'http://testhost.com/lit/api/v1/last_change.json'). - to_return(body: { last_change: 1.hour.ago.to_s(:db) }.to_json) - stub_request(:get, 'http://testhost.nope/lit/api/v1/last_change.json'). - to_return(body: 'Nothing to be found around here', status: 404) + stub_request(:get, "http://testhost.com/lit/api/v1/last_change.json") + .to_return(body: {last_change: 1.hour.ago.to_fs(:db)}.to_json) + stub_request(:get, "http://testhost.nope/lit/api/v1/last_change.json") + .to_return(body: "Nothing to be found around here", status: 404) end - test 'validates url validation' do + test "validates url validation" do s = Lit::Source.new - s.url = 'http://testhost.com/lit' - s.api_key = 'test' - s.identifier = 'test' + s.url = "http://testhost.com/lit" + s.api_key = "test" + s.identifier = "test" assert s.valid? assert s.errors.empty? - s.url = 'http://testhost.nope/lit' + s.url = "http://testhost.nope/lit" assert !s.valid? assert !s.errors.empty? end - test 'touch_last_update_at! updates timestamp' do + test "touch_last_update_at! updates timestamp" do s = lit_sources(:test) assert s.last_updated_at < 5.seconds.ago previous_updated_at = s.last_updated_at @@ -30,23 +30,23 @@ def setup assert s.last_updated_at > previous_updated_at end - test 'should set last_updated_at upon source creation' do + test "should set last_updated_at upon source creation" do Lit.set_last_updated_at_upon_creation = true s = Lit::Source.new - s.url = 'http://testhost.com/lit' - s.api_key = 'test' - s.identifier = 'test' + s.url = "http://testhost.com/lit" + s.api_key = "test" + s.identifier = "test" s.save! s.reload assert s.last_updated_at.present? end - test 'should not set last_updated_at upon source creation if asked' do + test "should not set last_updated_at upon source creation if asked" do Lit.set_last_updated_at_upon_creation = false s = Lit::Source.new - s.url = 'http://testhost.com/lit' - s.api_key = 'test' - s.identifier = 'test' + s.url = "http://testhost.com/lit" + s.api_key = "test" + s.identifier = "test" s.save! s.reload assert s.last_updated_at.nil? diff --git a/test/unit/lit_behaviour_test.rb b/test/unit/lit_behaviour_test.rb index 8c87bf5b..395c0424 100644 --- a/test/unit/lit_behaviour_test.rb +++ b/test/unit/lit_behaviour_test.rb @@ -1,4 +1,4 @@ -require 'test_helper' +require "test_helper" class LitBehaviourTest < ActiveSupport::TestCase class Backend < Lit::I18nBackend @@ -28,90 +28,90 @@ def teardown super end - test 'returned strings must not be html_safe if all_translations_are_html_safe is false' do + test "returned strings must not be html_safe if all_translations_are_html_safe is false" do with_all_translations_are_html_safe false do - I18n.backend.store_translations(:en, foo: 'foo') - assert_equal false, I18n.t('foo').html_safe? + I18n.backend.store_translations(:en, foo: "foo") + assert_equal false, I18n.t("foo").html_safe? end end - test 'returned strings must be html_safe if all_translations_are_html_safe is true' do + test "returned strings must be html_safe if all_translations_are_html_safe is true" do with_all_translations_are_html_safe true do - I18n.backend.store_translations(:en, foo: 'foo') - assert I18n.t('foo').html_safe? + I18n.backend.store_translations(:en, foo: "foo") + assert I18n.t("foo").html_safe? end end - test 'should not save in other languages than I18n.available_locales' do + test "should not save in other languages than I18n.available_locales" do ::Rails.configuration.i18n.stubs(:available_locales).returns([:fr]) I18n.backend.expects(:store_item).times(0) - I18n.backend.store_translations(:dk, foo: 'foo') + I18n.backend.store_translations(:dk, foo: "foo") end - test 'should save in other languages if I18n.available_locales is empty' do + test "should save in other languages if I18n.available_locales is empty" do I18n.backend.expects(:store_item).times(1) - I18n.backend.store_translations(:dk, foo: 'foo') + I18n.backend.store_translations(:dk, foo: "foo") end - test 'should override default gems translations' do - load_paths = @old_load_path. - select { |p| p.include?('lib/active_support/locale/en.yml') } + test "should override default gems translations" do + load_paths = @old_load_path + .select { |p| p.include?("lib/active_support/locale/en.yml") } load_paths << - File.expand_path('../../dummy/config/locales/active_support_extensions.yml', __FILE__) + File.expand_path("../../dummy/config/locales/active_support_extensions.yml", __FILE__) I18n.load_path = load_paths - assert_equal '%B %d, %Y extended', - I18n.backend.translate(:en, :"date.formats.long") + assert_equal "%B %d, %Y extended", + I18n.backend.translate(:en, :"date.formats.long") # check once again if I18n.backend.translate returns expected value. There # where a bug with cache initialized to late and first call to translate # returned other results then second call. - assert_equal '%B %d, %Y extended', - I18n.backend.translate(:en, :"date.formats.long") + assert_equal "%B %d, %Y extended", + I18n.backend.translate(:en, :"date.formats.long") end - test 'translating the same not existing key twice should not set Lit::Localizaiton#is_changed to true' do - key = 'not_existing_translation' + test "translating the same not existing key twice should not set Lit::Localizaiton#is_changed to true" do + key = "not_existing_translation" - assert_nil find_localization_for(key, 'en') + assert_nil find_localization_for(key, "en") - assert_equal "translation missing: en.#{key}", I18n.t(key) - assert_equal false, find_localization_for(key, 'en').is_changed? + assert_equal "Translation missing: en.#{key}", I18n.t(key) + assert_equal false, find_localization_for(key, "en").is_changed? - assert_equal "translation missing: en.#{key}", I18n.t(key) - assert_equal false, find_localization_for(key, 'en').is_changed? + assert_equal "Translation missing: en.#{key}", I18n.t(key) + assert_equal false, find_localization_for(key, "en").is_changed? end - test 'translations with scope, default and interpolation should use interpolation every time' do - I18n.backend.store_translations(:en, :'scope.foo' => 'foo %{bar}') + test "translations with scope, default and interpolation should use interpolation every time" do + I18n.backend.store_translations(:en, "scope.foo": "foo %{bar}") - assert_equal 'foo bar', I18n.t(:"scope.blank", default: :'scope.foo', bar: 'bar') - assert_equal 'foo bar bis', I18n.t(:"scope.blank", default: :'scope.foo', bar: 'bar bis') + assert_equal "foo bar", I18n.t(:"scope.blank", default: :"scope.foo", bar: "bar") + assert_equal "foo bar bis", I18n.t(:"scope.blank", default: :"scope.foo", bar: "bar bis") - I18n.backend.store_translations(:en, :'next_scope.foo' => 'foo %{bar}') - assert_equal 'foo bar', I18n.t(:blank, scope: :next_scope, default: :foo, bar: 'bar') - assert_equal 'foo bar bis', I18n.t(:blank, scope: :next_scope, default: :foo, bar: 'bar bis') + I18n.backend.store_translations(:en, "next_scope.foo": "foo %{bar}") + assert_equal "foo bar", I18n.t(:blank, scope: :next_scope, default: :foo, bar: "bar") + assert_equal "foo bar bis", I18n.t(:blank, scope: :next_scope, default: :foo, bar: "bar bis") end - test 'lit should respect :scope when setting default_value from defaults' do - I18n.backend.store_translations(:en, :'scope.foo' => 'translated foo') + test "lit should respect :scope when setting default_value from defaults" do + I18n.backend.store_translations(:en, "scope.foo": "translated foo") - assert_equal 'translated foo', I18n.t(:not_existing, scope: ['scope'], default: [:foo]) - assert_equal 'translated foo', find_localization_for('scope.not_existing', 'en').default_value + assert_equal "translated foo", I18n.t(:not_existing, scope: ["scope"], default: [:foo]) + assert_equal "translated foo", find_localization_for("scope.not_existing", "en").default_value end - test 'it stores translations upon first invokation' do - key = 'test.of.storage' + test "it stores translations upon first invokation" do + key = "test.of.storage" I18n.t(key) assert Lit::LocalizationKey.where(localization_key: key).exists? end - test 'it wont store key if prefix is added to ignored' do + test "it wont store key if prefix is added to ignored" do old_loader = Lit.loader - key = 'test.of.storage' - existing_key = 'existing.string' - Lit.ignored_keys = ['test.of'] + key = "test.of.storage" + existing_key = "existing.string" + Lit.ignored_keys = ["test.of"] Lit.loader = nil Lit.init I18n.t(key) @@ -121,12 +121,12 @@ def teardown Lit.loader = old_loader end - test 'it wont store key if ignored_key prefix is a string' do + test "it wont store key if ignored_key prefix is a string" do old_loader = Lit.loader - first_key = 'test.of.storage' - second_key = 'secondary.key.to.test' - existing_key = 'existing.string' - Lit.ignored_keys = 'test.of, secondary.key ' + first_key = "test.of.storage" + second_key = "secondary.key.to.test" + existing_key = "existing.string" + Lit.ignored_keys = "test.of, secondary.key " Lit.loader = nil Lit.init I18n.t(first_key) @@ -138,150 +138,150 @@ def teardown Lit.loader = old_loader end - test 'it wont overwrite existing UI-changed values with those from yaml' do - load_sample_yml('en.yml') + test "it wont overwrite existing UI-changed values with those from yaml" do + load_sample_yml("en.yml") old_loader = Lit.loader Lit.loader = nil Lit.ignore_yaml_on_startup = false Lit.init # Defaults from yml: en.foo: bar, en.nil_thing: [nothing] - assert_equal 'bar', I18n.t('foo') - assert_equal 'no longer nil', I18n.t('nil_thing', default: 'no longer nil') + assert_equal "bar", I18n.t("foo") + assert_equal "no longer nil", I18n.t("nil_thing", default: "no longer nil") - foo_loc = Lit::LocalizationKey.find_by_localization_key('foo').localizations.first - nil_loc = Lit::LocalizationKey.find_by_localization_key('nil_thing').localizations.first + foo_loc = Lit::LocalizationKey.find_by_localization_key("foo").localizations.first + nil_loc = Lit::LocalizationKey.find_by_localization_key("nil_thing").localizations.first # Check if default values have been loaded into DB - assert_equal 'bar', foo_loc.default_value - assert_equal 'no longer nil', nil_loc.default_value + assert_equal "bar", foo_loc.default_value + assert_equal "no longer nil", nil_loc.default_value # Translate as if it was done in UI (is_changed set to true) - foo_loc.update(translated_value: 'barbar', is_changed: true) - nil_loc.update(translated_value: 'new one', is_changed: true) + foo_loc.update(translated_value: "barbar", is_changed: true) + nil_loc.update(translated_value: "new one", is_changed: true) [foo_loc, nil_loc].each do |loc| Lit.init.cache.update_cache loc.full_key, loc.translation end # Translations should be changed as intended - assert_equal 'barbar', I18n.t('foo') - assert_equal 'new one', I18n.t('nil_thing') + assert_equal "barbar", I18n.t("foo") + assert_equal "new one", I18n.t("nil_thing") # Reload Lit, UI-changed translations should be intact Lit.loader = nil Lit.init - assert_equal 'barbar', I18n.t('foo') - assert_equal 'new one', I18n.t('nil_thing') + assert_equal "barbar", I18n.t("foo") + assert_equal "new one", I18n.t("nil_thing") Lit.loader = old_loader end - test 'it will overwrite existing values with those from yaml for unchanged localizations' do + test "it will overwrite existing values with those from yaml for unchanged localizations" do Lit.ignore_yaml_on_startup = false - load_sample_yml('en.yml') + load_sample_yml("en.yml") old_loader = Lit.loader Lit.loader = nil Lit.init # Defaults from en.yml: en.foo: bar, en.nil_thing: [nothing] - assert_equal 'bar', I18n.t('foo') - assert_equal 'no longer nil', I18n.t('nil_thing', default: 'no longer nil') + assert_equal "bar", I18n.t("foo") + assert_equal "no longer nil", I18n.t("nil_thing", default: "no longer nil") - foo_loc = Lit::LocalizationKey.find_by_localization_key('foo') - .localizations.first - nil_loc = Lit::LocalizationKey.find_by_localization_key('nil_thing') - .localizations.first + foo_loc = Lit::LocalizationKey.find_by_localization_key("foo") + .localizations.first + nil_loc = Lit::LocalizationKey.find_by_localization_key("nil_thing") + .localizations.first # Check if default values have been loaded into DB - assert_equal 'bar', foo_loc.default_value - assert_equal 'no longer nil', nil_loc.default_value + assert_equal "bar", foo_loc.default_value + assert_equal "no longer nil", nil_loc.default_value # Defaults from en_changed.yml en.foo: barbar, en.nil_thing: not nil anymore # Swap yml file and reload Lit, changes in yml file should be visible I18n.load_path = [] - load_sample_yml('en_changed.yml') + load_sample_yml("en_changed.yml") Lit.loader = nil Lit.init - assert_equal 'barbar', I18n.t('foo') - assert_equal 'not nil anymore', I18n.t('nil_thing') + assert_equal "barbar", I18n.t("foo") + assert_equal "not nil anymore", I18n.t("nil_thing") Lit.loader = old_loader end test 'it replaces nil ("translation missing") values with new defaults' do - assert_nil find_localization_for('foo', :en) - I18n.t('foo') - assert_not_nil find_localization_for('foo', :en) - I18n.t('foo', default: 'bar') - assert_equal 'bar', I18n.t('foo') + assert_nil find_localization_for("foo", :en) + I18n.t("foo") + assert_not_nil find_localization_for("foo", :en) + I18n.t("foo", default: "bar") + assert_equal "bar", I18n.t("foo") end - if Lit.key_value_engine == 'redis' - test 'it does not overwrite values in DB with nil if default option is removed from I18n.t call after value is deleted from redis' do - I18n.t('foo', default: 'bar') - assert_equal 'bar', find_localization_for('foo', :en).value + if Lit.key_value_engine == "redis" + test "it does not overwrite values in DB with nil if default option is removed from I18n.t call after value is deleted from redis" do + I18n.t("foo", default: "bar") + assert_equal "bar", find_localization_for("foo", :en).value $redis.flushdb # rubocop:disable Style/GlobalVars - I18n.t('foo') - assert_equal 'bar', find_localization_for('foo', :en).value + I18n.t("foo") + assert_equal "bar", find_localization_for("foo", :en).value end end - test 'it does not create duplicate db records when a previously deleted key appears again' do + test "it does not create duplicate db records when a previously deleted key appears again" do loc_count = Lit::Localization.count - I18n.t('foo', default: 'bar') + I18n.t("foo", default: "bar") assert Lit::Localization.count == loc_count + 1 - Lit::LocalizationKey.find_by(localization_key: 'foo').soft_destroy - I18n.t('foo', default: 'baz') + Lit::LocalizationKey.find_by(localization_key: "foo").soft_destroy + I18n.t("foo", default: "baz") assert Lit::Localization.count == loc_count + 1 end - test 'cache tree structure of keys and retrieve it from redis like I18n does' do + test "cache tree structure of keys and retrieve it from redis like I18n does" do Lit.humanize_key = true - assert_difference 'Lit::LocalizationKey.count', 2 do - I18n.t('scopes.hash.sub_one', default: 'Left leaf') - I18n.t('scopes.hash.sub_two', default: 'Right leaf') + assert_difference "Lit::LocalizationKey.count", 2 do + I18n.t("scopes.hash.sub_one", default: "Left leaf") + I18n.t("scopes.hash.sub_two", default: "Right leaf") end assert_no_database_queries do - assert_equal 'Left leaf', I18n.t('scopes.hash.sub_one') - assert_equal 'Right leaf', I18n.t('scopes.hash.sub_two') + assert_equal "Left leaf", I18n.t("scopes.hash.sub_one") + assert_equal "Right leaf", I18n.t("scopes.hash.sub_two") end - hash_result = I18n.t('scopes.hash') + hash_result = I18n.t("scopes.hash") assert hash_result.is_a?(Hash) assert hash_result.key?(:sub_one) assert hash_result.key?(:sub_two) - assert_equal hash_result[:sub_one], 'Left leaf' + assert_equal hash_result[:sub_one], "Left leaf" end - test 'it must not overwrite default with I18n content when calling same key twice ' \ - 'with different interpolations' do - assert_difference 'Lit::LocalizationKey.count', 1 do - I18n.t('interpolated_key', default: 'Candidate %{name}', name: 'Tester') + test "it must not overwrite default with I18n content when calling same key twice " \ + "with different interpolations" do + assert_difference "Lit::LocalizationKey.count", 1 do + I18n.t("interpolated_key", default: "Candidate %{name}", name: "Tester") end - assert_no_difference 'Lit::LocalizationKey.count' do - result = I18n.t('interpolated_key', default: 'Candidate %{name}', name: 'Famous person') - assert_equal result, 'Candidate Famous person' + assert_no_difference "Lit::LocalizationKey.count" do + result = I18n.t("interpolated_key", default: "Candidate %{name}", name: "Famous person") + assert_equal result, "Candidate Famous person" end - assert_equal find_localization_for('interpolated_key', :en).default_value, 'Candidate %{name}' + assert_equal find_localization_for("interpolated_key", :en).default_value, "Candidate %{name}" end - test 'it does not break on simple form/complicated keys when using regex in hash storage' do + test "it does not break on simple form/complicated keys when using regex in hash storage" do prev_kv_engine = Lit.key_value_engine - Lit.key_value_engine = 'hash' - key = 'helpers.label.meta_signings.contract_signings_attributes][0]' \ - '[contract_documents.contract]' - result = I18n.t(key, default: 'Contract') - assert_equal result, 'Contract' - assert_equal find_localization_for(key, :en).default_value, 'Contract' + Lit.key_value_engine = "hash" + key = "helpers.label.meta_signings.contract_signings_attributes][0]" \ + "[contract_documents.contract]" + result = I18n.t(key, default: "Contract") + assert_equal result, "Contract" + assert_equal find_localization_for(key, :en).default_value, "Contract" Lit.key_value_engine = prev_kv_engine end private def find_localization_for(key, locale) - Lit::Localization. - joins(:localization_key, :locale). - where(lit_localization_keys: { localization_key: key }). - where(lit_locales: { locale: locale }).first + Lit::Localization + .joins(:localization_key, :locale) + .where(lit_localization_keys: {localization_key: key}) + .where(lit_locales: {locale: locale}).first end def with_all_translations_are_html_safe(value) From 000eee9a4cd5f228d1ae754985c8f4a5660f1118 Mon Sep 17 00:00:00 2001 From: Maciej Litwiniuk Date: Mon, 19 Aug 2024 10:14:30 +0200 Subject: [PATCH 2/4] WIP - start refactoring humanize_key to store_humanized_key --- Appraisals | 2 + CHANGELOG.md | 1 + app/helpers/lit/frontend_helper.rb | 28 ++++++------ .../lit/localization_keys/_sidebar.html.erb | 10 ++--- gemfiles/rails_7.0.gemfile | 1 + gemfiles/rails_7.0.gemfile.lock | 3 ++ gemfiles/rails_7.1.gemfile | 1 + gemfiles/rails_7.1.gemfile.lock | 3 ++ .../lit/install/templates/initializer.erb | 17 +++++--- lib/lit.rb | 10 ++--- lib/lit/i18n_backend.rb | 2 +- lib/lit/services/humanize_service.rb | 6 +-- test/dummy/config/environments/development.rb | 7 +-- test/dummy/config/environments/test.rb | 29 +++---------- test/dummy/config/initializers/lit.rb | 4 +- test/dummy/config/puma.rb | 43 +++++++++++++++++++ test/unit/i18n_backend_test.rb | 8 ++-- 17 files changed, 106 insertions(+), 69 deletions(-) create mode 100644 test/dummy/config/puma.rb diff --git a/Appraisals b/Appraisals index 86ca236e..5d82150a 100644 --- a/Appraisals +++ b/Appraisals @@ -19,6 +19,7 @@ appraise 'rails-7.0' do gem "minitest-vcr", github: "manuelvanrijn/minitest-vcr" gem "m", "~> 1.6" gem "google-cloud-translate", "~> 2.0" + gem "puma" end appraise 'rails-7.1' do @@ -42,4 +43,5 @@ appraise 'rails-7.1' do gem "minitest-vcr", github: "manuelvanrijn/minitest-vcr" gem "m", "~> 1.6" gem "google-cloud-translate", "~> 2.0" + gem "puma" end diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e104fbf..f43cd23f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Supports Rails 7.x only, drops support for older versions - Efforts to use Vanilla JS and remove jQuery [WIP] - Fix for `Undefined method 'id' for False class` error in view partial [WIP] +- REMOVED Lit.humanize_key - it's replaced by Lit.store_humanized_key variable ## [1.1.6] - 2022-03-28 ### Fixed diff --git a/app/helpers/lit/frontend_helper.rb b/app/helpers/lit/frontend_helper.rb index 3d247a80..1d3b487c 100644 --- a/app/helpers/lit/frontend_helper.rb +++ b/app/helpers/lit/frontend_helper.rb @@ -17,7 +17,7 @@ def pluralized_key(key, count) pluralizer = I18n.backend.send(:pluralizer, locale) return unless pluralizer.respond_to?(:call) last = count.zero? ? :zero : pluralizer.call(count) - format '%s.%s', key: key, last: last + format "%s.%s", key: key, last: last end def t(key, options = {}) @@ -31,25 +31,27 @@ def missing_translation(key, options) # Humanizing key should be last resort if Lit::Services::HumanizeService.should_humanize?(key) return Lit::Services::HumanizeService.humanize_and_cache(key, options) + else + return Lit::Services::HumanizeService.humanize(key, options) end - super(key, options) + super end end prepend Lit::FrontendHelper::TranslationKeyWrapper def javascript_lit_tag - javascript_include_tag 'lit/lit_frontend', defer: true + javascript_include_tag "lit/lit_frontend", defer: true end def stylesheet_lit_tag - stylesheet_link_tag 'lit/lit_frontend' + stylesheet_link_tag "lit/lit_frontend" end def lit_frontend_assets return unless lit_authorized? - meta = content_tag :meta, '', value: lit.find_localization_localization_keys_path, name: 'lit-url-base' + meta = content_tag :meta, "", value: lit.find_localization_localization_keys_path, name: "lit-url-base" safe_join [javascript_lit_tag, stylesheet_lit_tag, meta] end @@ -57,15 +59,15 @@ def lit_translations_info return if Thread.current[:lit_request_keys].nil? return unless lit_authorized? - content_tag :div, class: 'lit-translations-info collapsed' do - concat content_tag(:span, 'Show translations', class: 'lit-open-button') - concat content_tag(:span, 'X', class: 'lit-close-button') + content_tag :div, class: "lit-translations-info collapsed" do + concat content_tag(:span, "Show translations", class: "lit-open-button") + concat content_tag(:span, "X", class: "lit-close-button") concat translations_list_content_tag end end def translations_list_content_tag - content_tag :ul, class: 'lit-translations-list' do + content_tag :ul, class: "lit-translations-list" do Lit .init .cache @@ -74,8 +76,8 @@ def translations_list_content_tag concat( content_tag(:li) do concat content_tag(:code, "#{k}:") - concat get_translateable_span(k, v, alternative_text: '[empty]') - end, + concat get_translateable_span(k, v, alternative_text: "[empty]") + end ) end end @@ -88,8 +90,8 @@ def lit_authorized? end def get_translateable_span(key, localization, alternative_text: nil) - content_tag :span, class: 'lit-key-generic', data: { key: key, locale: I18n.locale } do - localization.blank? ? alternative_text : localization + content_tag :span, class: "lit-key-generic", data: {key: key, locale: I18n.locale} do + localization.blank? ? alternative_text : localization.to_s end end end diff --git a/app/views/lit/localization_keys/_sidebar.html.erb b/app/views/lit/localization_keys/_sidebar.html.erb index 7de3365e..d78090b3 100644 --- a/app/views/lit/localization_keys/_sidebar.html.erb +++ b/app/views/lit/localization_keys/_sidebar.html.erb @@ -36,7 +36,7 @@ deleted and visited again <% end %> - + <% Lit::LocalizationKey.order_options.each do |order| %>
  • "> <%= link_to url_for(@search_options.merge(:order => order)) do %> @@ -55,10 +55,10 @@ <% end %> <% @prefixes.each do |p| %>
  • - <%= link_to url_for(@search_options.merge(:key_prefix=>p)) do %> - <%= draw_icon('chevron-right') %> - <%= p.split('.').last %> - <% end %> + <%= link_to url_for(@search_options.merge(:key_prefix=>p)) do %> + <%= draw_icon('chevron-right') %> + <%= p.split('.').last %> + <% end %>
  • <% end %> diff --git a/gemfiles/rails_7.0.gemfile b/gemfiles/rails_7.0.gemfile index 2567bf74..81149c9e 100644 --- a/gemfiles/rails_7.0.gemfile +++ b/gemfiles/rails_7.0.gemfile @@ -21,5 +21,6 @@ gem "minitest" gem "minitest-vcr", github: "manuelvanrijn/minitest-vcr" gem "m", "~> 1.6" gem "google-cloud-translate", "~> 2.0" +gem "puma" gemspec path: "../" diff --git a/gemfiles/rails_7.0.gemfile.lock b/gemfiles/rails_7.0.gemfile.lock index 2aa156fb..1522cb3d 100644 --- a/gemfiles/rails_7.0.gemfile.lock +++ b/gemfiles/rails_7.0.gemfile.lock @@ -265,6 +265,8 @@ GEM binding_of_caller (~> 1.0) pry (~> 0.13) public_suffix (6.0.1) + puma (6.4.2) + nio4r (~> 2.0) racc (1.8.1) rack (2.2.9) rack-test (2.1.0) @@ -416,6 +418,7 @@ DEPENDENCIES pry-byebug (~> 3.9) pry-rails pry-stack_explorer + puma rails (~> 7.0.8.4) rails-controller-testing redis diff --git a/gemfiles/rails_7.1.gemfile b/gemfiles/rails_7.1.gemfile index 6bb85966..2224ea63 100644 --- a/gemfiles/rails_7.1.gemfile +++ b/gemfiles/rails_7.1.gemfile @@ -21,5 +21,6 @@ gem "minitest" gem "minitest-vcr", github: "manuelvanrijn/minitest-vcr" gem "m", "~> 1.6" gem "google-cloud-translate", "~> 2.0" +gem "puma" gemspec path: "../" diff --git a/gemfiles/rails_7.1.gemfile.lock b/gemfiles/rails_7.1.gemfile.lock index 7e681bde..7264d3ae 100644 --- a/gemfiles/rails_7.1.gemfile.lock +++ b/gemfiles/rails_7.1.gemfile.lock @@ -282,6 +282,8 @@ GEM psych (5.1.2) stringio public_suffix (6.0.1) + puma (6.4.2) + nio4r (~> 2.0) racc (1.8.1) rack (3.1.7) rack-session (2.0.0) @@ -445,6 +447,7 @@ DEPENDENCIES pry-byebug (~> 3.9) pry-rails pry-stack_explorer + puma rails (~> 7.1.3.4) rails-controller-testing redis diff --git a/lib/generators/lit/install/templates/initializer.erb b/lib/generators/lit/install/templates/initializer.erb index c664f75c..4f56b599 100644 --- a/lib/generators/lit/install/templates/initializer.erb +++ b/lib/generators/lit/install/templates/initializer.erb @@ -23,15 +23,18 @@ Lit.key_value_engine = '<%= @key_value_engine %>' # If true all translations are returned as html_safe strings Lit.all_translations_are_html_safe = false -# Translations without default will be humanized (default string will be added) +# Translations without default will be humanized always. Setting this to true +# will set default value to humanized version, rather than leaving it as nil # ie. scope.page_header will become "Page header" -# If `false` then will serve nil instead (but translation will be wrapped in -# -Lit.humanize_key = false +# If `false` then will serve humanized version anyway (wrapped in span) and store nil value +Lit.store_humanized_key = false + +# Key prefixes in this array won't ever be humanized +# Lit.store_humanized_key_ignored_keys = ['welcome'] # If set to `false` will always parse yaml files upon startup and update cached # values with ones with yaml (but only, if those keys haven't been changed via -# web ui before) +# web ui before). To add those keys, import them via rake command Lit.ignore_yaml_on_startup = true # Array of ignored keys or key prefixes @@ -59,6 +62,8 @@ Lit.store_request_info = false Lit.store_request_keys = false # Initialize lit -Lit.init +Rails.application.config.after_initialize do + Lit.init +end diff --git a/lib/lit.rb b/lib/lit.rb index 62964218..e8d50e05 100644 --- a/lib/lit.rb +++ b/lib/lit.rb @@ -8,8 +8,8 @@ module Lit mattr_accessor :key_value_engine mattr_accessor :redis_url mattr_accessor :storage_options - mattr_accessor :humanize_key - mattr_accessor :humanize_key_ignored_keys + mattr_accessor :store_humanized_key + mattr_accessor :store_humanized_key_ignored_keys mattr_accessor :humanize_key_ignored mattr_accessor :ignored_keys mattr_accessor :ignore_yaml_on_startup @@ -29,10 +29,10 @@ def self.init @@table_exists ||= check_if_table_exists if loader.nil? && @@table_exists self.loader ||= Loader.new - Lit.humanize_key = false if Lit.humanize_key.nil? - Lit.humanize_key_ignored_keys = [] if Lit.humanize_key_ignored_keys.nil? + Lit.store_humanized_key = false if Lit.store_humanized_key.nil? + Lit.store_humanized_key_ignored_keys = [] if Lit.store_humanized_key_ignored_keys.nil? Lit.humanize_key_ignored = %w[i18n date datetime number time support] - Lit.humanize_key_ignored |= Lit.humanize_key_ignored_keys + Lit.humanize_key_ignored |= Lit.store_humanized_key_ignored_keys Lit.humanize_key_ignored = Regexp.new("(#{Lit.humanize_key_ignored.join("|")}).*") Lit.ignore_yaml_on_startup = true if Lit.ignore_yaml_on_startup.nil? diff --git a/lib/lit/i18n_backend.rb b/lib/lit/i18n_backend.rb index 9d34a6c6..b8c84d31 100644 --- a/lib/lit/i18n_backend.rb +++ b/lib/lit/i18n_backend.rb @@ -136,7 +136,7 @@ def lookup(locale, key, scope = [], options = {}) content = default end # if we have content now, let's store it in cache - if content.present? && content != MISSING_TRANSLATION + if content.present? content = Array.wrap(content).compact.reject { |e| e == MISSING_TRANSLATION }.reject(&:empty?).reverse.find do |default_cand| @cache[key_with_locale] = default_cand @cache[key_with_locale] diff --git a/lib/lit/services/humanize_service.rb b/lib/lit/services/humanize_service.rb index 95603a7e..6f42fe1a 100644 --- a/lib/lit/services/humanize_service.rb +++ b/lib/lit/services/humanize_service.rb @@ -7,11 +7,11 @@ module Services # Caches the value of humanization class HumanizeService def self.should_humanize?(key) - Lit.humanize_key && Lit.humanize_key_ignored.match(key).nil? + Lit.store_humanizes_key && Lit.humanize_key_ignored.match(key).nil? end def self.humanize(key) - key.to_s.split('.').last.humanize + key.to_s.split(".").last.humanize end def self.humanize_and_cache(key, options) @@ -19,7 +19,7 @@ def self.humanize_and_cache(key, options) parts = I18n.normalize_keys( options[:locale] || I18n.locale, key, options[:scope], options[:separator] ) - key_with_locale = parts.join('.') + key_with_locale = parts.join(".") I18n.cache_store[key_with_locale] = content I18n.cache_store[key_with_locale] end diff --git a/test/dummy/config/environments/development.rb b/test/dummy/config/environments/development.rb index 9fedb0dc..15e44afa 100644 --- a/test/dummy/config/environments/development.rb +++ b/test/dummy/config/environments/development.rb @@ -10,7 +10,7 @@ config.whiny_nils = true # Show full error reports and disable caching - config.consider_all_requests_local = true + config.consider_all_requests_local = true config.action_controller.perform_caching = false # Don't care if the mailer can't send @@ -22,11 +22,6 @@ # Only use best-standards-support built into browsers config.action_dispatch.best_standards_support = :builtin - if ::Rails::VERSION::MAJOR < 4 - # Raise exception on mass assignment protection for Active Record models - config.active_record.mass_assignment_sanitizer = :strict - end - # Do not compress assets config.assets.compress = false diff --git a/test/dummy/config/environments/test.rb b/test/dummy/config/environments/test.rb index 46b501c7..9a0835f8 100644 --- a/test/dummy/config/environments/test.rb +++ b/test/dummy/config/environments/test.rb @@ -10,44 +10,25 @@ config.eager_load = false # Configure static asset server for tests with Cache-Control for performance - if config.respond_to?(:public_file_server) - config.public_file_server.enabled = true - config.public_file_server.headers = { 'Cache-Control' => 'public, max-age=3600' } - else - if config.respond_to?(:serve_static_files) - config.serve_static_files = true - else - config.serve_static_assets = true - end - config.static_cache_control = 'public, max-age=3600' - end - - if ::Rails::VERSION::MAJOR < 4 - # Log error messages when you accidentally call methods on nil - config.whiny_nils = true - end + config.public_file_server.enabled = true + config.public_file_server.headers = {"Cache-Control" => "public, max-age=3600"} # Show full error reports and disable caching - config.consider_all_requests_local = true + config.consider_all_requests_local = true config.action_controller.perform_caching = false # Raise exceptions instead of rendering exception templates config.action_dispatch.show_exceptions = false # Disable request forgery protection in test environment - config.action_controller.allow_forgery_protection = false + config.action_controller.allow_forgery_protection = false # Tell Action Mailer not to deliver emails to the real world. # The :test delivery method accumulates sent emails in the # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test - if ::Rails::VERSION::MAJOR < 4 - # Raise exception on mass assignment protection for Active Record models - config.active_record.mass_assignment_sanitizer = :strict - else - config.i18n.enforce_available_locales = false - end + config.i18n.enforce_available_locales = false # Print deprecation notices to the stderr config.active_support.deprecation = :stderr diff --git a/test/dummy/config/initializers/lit.rb b/test/dummy/config/initializers/lit.rb index 4c015423..a90423c9 100644 --- a/test/dummy/config/initializers/lit.rb +++ b/test/dummy/config/initializers/lit.rb @@ -1,8 +1,8 @@ Lit.authentication_function = :authenticate_admin! Lit.authentication_verification = :admin_signed_in? Lit.key_value_engine = ENV["LIT_STORAGE"] || "redis" -Lit.humanize_key = false -Lit.ignore_yaml_on_startup = true +Lit.store_humanized_key = false +Lit.ignore_yaml_on_startup = false Lit.api_enabled = true Lit.api_key = "ala" Lit.all_translations_are_html_safe = true diff --git a/test/dummy/config/puma.rb b/test/dummy/config/puma.rb new file mode 100644 index 00000000..daaf0369 --- /dev/null +++ b/test/dummy/config/puma.rb @@ -0,0 +1,43 @@ +# Puma can serve each request in a thread from an internal thread pool. +# The `threads` method setting takes two numbers: a minimum and maximum. +# Any libraries that use thread pools should be configured to match +# the maximum value specified for Puma. Default is set to 5 threads for minimum +# and maximum; this matches the default thread size of Active Record. +# +max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } +min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count } +threads min_threads_count, max_threads_count + +# Specifies the `worker_timeout` threshold that Puma will use to wait before +# terminating a worker in development environments. +# +worker_timeout 3600 if ENV.fetch("RAILS_ENV", "development") == "development" + +# Specifies the `port` that Puma will listen on to receive requests; default is 3000. +# +port ENV.fetch("PORT") { 3000 } + +# Specifies the `environment` that Puma will run in. +# +environment ENV.fetch("RAILS_ENV") { "development" } + +# Specifies the `pidfile` that Puma will use. +pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" } + +# Specifies the number of `workers` to boot in clustered mode. +# Workers are forked web server processes. If using threads and workers together +# the concurrency of the application would be max `threads` * `workers`. +# Workers do not work on JRuby or Windows (both of which do not support +# processes). +# +# workers ENV.fetch("WEB_CONCURRENCY") { 2 } + +# Use the `preload_app!` method when specifying a `workers` number. +# This directive tells Puma to first boot the application and load code +# before forking the application. This takes advantage of Copy On Write +# process behavior so workers use less memory. +# +# preload_app! + +# Allow puma to be restarted by `bin/rails restart` command. +plugin :tmp_restart diff --git a/test/unit/i18n_backend_test.rb b/test/unit/i18n_backend_test.rb index f222ffce..e5108f8b 100644 --- a/test/unit/i18n_backend_test.rb +++ b/test/unit/i18n_backend_test.rb @@ -8,7 +8,7 @@ class Backend < Lit::I18nBackend def setup @old_backend = I18n.backend @old_locale = I18n.locale - @old_humanize_key = Lit.humanize_key + @old_humanize_key = Lit.store_humanized_key @old_available_locales = ::Rails.configuration.i18n.available_locales end @@ -17,7 +17,7 @@ def teardown I18n.backend = @old_backend I18n.backend = @old_backend I18n.locale = @old_locale - Lit.humanize_key = @old_humanize_key + Lit.store_humanizes_key = @old_humanize_key end test "properly returns available locales" do @@ -32,7 +32,7 @@ def teardown end test "wont humanize key, if key is ignored" do - Lit.humanize_key = true + Lit.store_humanized_key = true I18n.locale = :en test_key = "date.this_will_get_humanized" assert_equal I18n.t(test_key), "Translation missing: en.date.this_will_get_humanized" @@ -43,7 +43,7 @@ def teardown end test "will not call additional queries when nil values in a fallback key chain have been cached" do - Lit.humanize_key = false + Lit.store_humanized_key = false I18n.locale = :en test_key = :"test.key" From da68a12c7f1a1e17f9849dec4134c58a5b64abe1 Mon Sep 17 00:00:00 2001 From: Maciej Litwiniuk Date: Mon, 19 Aug 2024 23:13:38 +0200 Subject: [PATCH 3/4] Refactor humanize_key to store_humanized_key --- README.md | 2 + app/helpers/lit/frontend_helper.rb | 2 +- lib/lit.rb | 5 + lib/lit/services/humanize_service.rb | 4 +- .../app/views/layouts/application.html.erb | 22 ++-- test/dummy/config/environments/development.rb | 3 + test/integration/lit/backend_test.rb | 13 +- test/integration/lit/locales_test.rb | 16 ++- test/integration/lit/projects_test.rb | 47 ++++---- test/integration/lit/welcome_test.rb | 111 +++++++++--------- test/unit/i18n_backend_test.rb | 2 +- test/unit/lit_behaviour_test.rb | 8 +- test/unit/pure_i18n_compatibility_test.rb | 10 +- 13 files changed, 122 insertions(+), 123 deletions(-) diff --git a/README.md b/README.md index 79c5075c..3fbcaeb7 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,8 @@ gem 'lit' You may want to take a look at generated initializer in `config/initializers/lit.rb` and change some default configuration options. +Note `Lit.ignore_yaml_on_startup = true` setting - when it's set to true, Lit won't automatically import translations from yaml and add them to interface. Either change this to `false` or import using rake task + ### So... again - what is it and how to use it? *Lit* is Rails engine - it runs in it's own namespace, by default it's available under `/lit`. It provides UI for managing translations of your app. diff --git a/app/helpers/lit/frontend_helper.rb b/app/helpers/lit/frontend_helper.rb index 1d3b487c..e6038d03 100644 --- a/app/helpers/lit/frontend_helper.rb +++ b/app/helpers/lit/frontend_helper.rb @@ -32,7 +32,7 @@ def missing_translation(key, options) if Lit::Services::HumanizeService.should_humanize?(key) return Lit::Services::HumanizeService.humanize_and_cache(key, options) else - return Lit::Services::HumanizeService.humanize(key, options) + return Lit::Services::HumanizeService.humanize(key) end super diff --git a/lib/lit.rb b/lib/lit.rb index e8d50e05..e324dafa 100644 --- a/lib/lit.rb +++ b/lib/lit.rb @@ -80,6 +80,11 @@ def self.get_key_value_engine def self.fallback=(_value) ::Rails.logger.error "[DEPRECATION] Lit.fallback= has been deprecated, please use `config.i18n.fallbacks` instead" end + + def self.humanize_key=(value) + ::Rails.logger.error "[DEPRECATION] Lit.humanize_key= has been deprecated, please use `Lit.store_humanized_key` instead" + Lit.store_humanized_key = value + end end require "lit/rails" if defined?(Rails) diff --git a/lib/lit/services/humanize_service.rb b/lib/lit/services/humanize_service.rb index 6f42fe1a..b02b5fc0 100644 --- a/lib/lit/services/humanize_service.rb +++ b/lib/lit/services/humanize_service.rb @@ -7,11 +7,11 @@ module Services # Caches the value of humanization class HumanizeService def self.should_humanize?(key) - Lit.store_humanizes_key && Lit.humanize_key_ignored.match(key).nil? + Lit.store_humanized_key && Lit.humanize_key_ignored.match(key).nil? end def self.humanize(key) - key.to_s.split(".").last.humanize + key.to_s.split(".").last.humanize.titleize end def self.humanize_and_cache(key, options) diff --git a/test/dummy/app/views/layouts/application.html.erb b/test/dummy/app/views/layouts/application.html.erb index 313f3f4b..71c0e684 100644 --- a/test/dummy/app/views/layouts/application.html.erb +++ b/test/dummy/app/views/layouts/application.html.erb @@ -1,15 +1,13 @@ - - Dummy - <%= stylesheet_link_tag "application", :media => "all" %> - <%= javascript_include_tag "application" %> - <%= csrf_meta_tags %> - <%= lit_frontend_assets %> - - - -<%= yield %> - - + + Dummy + <%= stylesheet_link_tag "application", :media => "all" %> + <%= javascript_include_tag "application" %> + <%= csrf_meta_tags %> + <%= lit_frontend_assets %> + + + <%= yield %> + diff --git a/test/dummy/config/environments/development.rb b/test/dummy/config/environments/development.rb index 15e44afa..23740734 100644 --- a/test/dummy/config/environments/development.rb +++ b/test/dummy/config/environments/development.rb @@ -27,4 +27,7 @@ # Expands the lines which load the assets config.assets.debug = true + + # Highlight code that triggered database queries in logs. + config.active_record.verbose_query_logs = true end diff --git a/test/integration/lit/backend_test.rb b/test/integration/lit/backend_test.rb index bff15a29..fce9cc6f 100644 --- a/test/integration/lit/backend_test.rb +++ b/test/integration/lit/backend_test.rb @@ -1,5 +1,4 @@ -# encoding: utf-8 -require 'test_helper' +require "test_helper" class BackendTest < ActionDispatch::IntegrationTest def setup @@ -11,13 +10,13 @@ def teardown I18n.locale = @old_locale end - test 'when generating locale while listing localizations it should copy default_value' do + test "when generating locale while listing localizations it should copy default_value" do Lit.authentication_function = nil - Lit::Locale.where(locale: 'en').first_or_create - I18n.t('prograils.swag', default: 'Prograils codelovers') - lk = Lit::LocalizationKey.find_by(localization_key: 'prograils.swag') + Lit::Locale.where(locale: "en").first_or_create + I18n.t("prograils.swag", default: "Prograils codelovers") + lk = Lit::LocalizationKey.find_by(localization_key: "prograils.swag") assert lk.present? - visit('/lit/localization_keys') + visit("/lit/localization_keys") lk.reload assert lk.localizations.map(&:default_value).compact.count == Lit::Locale.all.count end diff --git a/test/integration/lit/locales_test.rb b/test/integration/lit/locales_test.rb index 3067bbf1..2f7aebfc 100644 --- a/test/integration/lit/locales_test.rb +++ b/test/integration/lit/locales_test.rb @@ -1,5 +1,4 @@ -# encoding: utf-8 -require 'test_helper' +require "test_helper" class LocalesTest < ActionDispatch::IntegrationTest def setup @@ -11,20 +10,19 @@ def teardown Lit.ignore_yaml_on_startup = nil end - test 'should allow hiding locale' do + test "should allow hiding locale" do Lit.authentication_function = nil # visit('/pl/welcome') - visit('/lit/localization_keys') + visit("/lit/localization_keys") # within('td.locale_row:last-child') do # Lit.init.logger.info page.body # assert has_content?('pl') # end - assert(all('td.locale_row').last.text =~ /pl/) - l = Lit::Locale.where(locale: 'pl').first + assert(all("td.locale_row").last.text =~ /pl/) + l = Lit::Locale.where(locale: "pl").first l.is_hidden = true l.save - visit('/lit/localization_keys') - assert(!(all('td.locale_row').last.text =~ /pl/)) - + visit("/lit/localization_keys") + assert(!(all("td.locale_row").last.text =~ /pl/)) end end diff --git a/test/integration/lit/projects_test.rb b/test/integration/lit/projects_test.rb index d88aef34..c6a11585 100644 --- a/test/integration/lit/projects_test.rb +++ b/test/integration/lit/projects_test.rb @@ -1,44 +1,39 @@ -# encoding: utf-8 -require 'test_helper' +require "test_helper" class ProjectsTest < ActionDispatch::IntegrationTest setup do - @old = Lit.humanize_key + @old = Lit.store_humanized_key end teardown do - Lit.humanize_key = @old + Lit.store_humanized_key = @old end - test 'should display translated project name' do - Lit.humanize_key = true - visit('/en/projects/new') - locale = Lit::Locale.where('locale=?', 'en').first - localization_key = Lit::LocalizationKey.find_by_localization_key! 'helpers.label.project.name' + test "should display translated project name" do + Lit.store_humanized_key = true + visit("/en/projects/new") + locale = Lit::Locale.where("locale=?", "en").first + localization_key = Lit::LocalizationKey.find_by_localization_key! "helpers.label.project.name" localization = localization_key.localizations.where(locale_id: locale.id).first - assert_equal 'Name', localization.to_s - assert_equal 'Name', localization.default_value + assert_equal "Name", localization.to_s + assert_equal "Name", localization.default_value end - test 'should have error messages' do - post '/en/projects', params: { project: { name: '' } } - locale = Lit::Locale.where('locale=?', 'en').first - localization_key = Lit::LocalizationKey.find_by_localization_key! 'activerecord.errors.models.project.attributes.name.blank' + test "should have error messages" do + post "/en/projects", params: {project: {name: ""}} + locale = Lit::Locale.where("locale=?", "en").first + localization_key = Lit::LocalizationKey.find_by_localization_key! "activerecord.errors.models.project.attributes.name.blank" localization = localization_key.localizations.where(locale_id: locale.id).first assert_nil localization.to_s assert_nil localization.default_value end - test 'should have error message humanized' do - Lit.humanize_key = true - if ::Rails::VERSION::MAJOR < 5 - post '/en/projects', project: { name: '' } - else - post '/en/projects', params: { project: { name: '' } } - end - locale = Lit::Locale.where('locale=?', 'en').first - localization_key = Lit::LocalizationKey.find_by_localization_key! 'activerecord.errors.models.project.attributes.name.blank' + test "should have error message humanized" do + Lit.store_humanized_key = true + post "/en/projects", params: {project: {name: ""}} + locale = Lit::Locale.where("locale=?", "en").first + localization_key = Lit::LocalizationKey.find_by_localization_key! "activerecord.errors.models.project.attributes.name.blank" localization = localization_key.localizations.where(locale_id: locale.id).first - assert_equal 'Blank', localization.to_s - assert_equal 'Blank', localization.default_value + assert_equal "Blank", localization.to_s + assert_equal "Blank", localization.default_value end end diff --git a/test/integration/lit/welcome_test.rb b/test/integration/lit/welcome_test.rb index 2fe5ae47..956c27dd 100644 --- a/test/integration/lit/welcome_test.rb +++ b/test/integration/lit/welcome_test.rb @@ -1,78 +1,77 @@ -# encoding: utf-8 -require 'test_helper' +require "test_helper" class WelcomeTest < ActionDispatch::IntegrationTest def setup - @old_humanize_key = Lit.humanize_key + @old_humanize_key = Lit.store_humanized_key @old_fallbacks = Rails.application.config.i18n.fallbacks Lit.ignore_yaml_on_startup = false Lit.init end def teardown - Lit.humanize_key = @old_humanize_key + Lit.store_humanized_key = @old_humanize_key Rails.application.config.i18n.fallbacks = @old_fallbacks Lit.ignore_yaml_on_startup = nil end test "should properly display 'Hello world' in english" do - visit('/en/welcome') - assert page.has_content?('Hello World') + visit("/en/welcome") + assert page.has_content?("Hello World") end - test 'should properly display text without default and humanize=false' do - Lit.humanize_key = false - visit('/en/welcome') - assert page.has_content?('Text Without Default') - visit('/pl/welcome') - assert page.has_content?('Text Without Default') + test "should properly display text without default and humanize=false" do + Lit.store_humanized_key = false + visit("/en/welcome") + assert page.has_content?("Text Without Default") + visit("/pl/welcome") + assert page.has_content?("Text Without Default") end - test 'should properly display text without default and humanize=true' do - Lit.humanize_key = true - visit('/en/welcome') - assert page.has_content?('Text without default') - visit('/pl/welcome') - assert page.has_content?('Text without default') + test "should properly display text without default and humanize=true" do + Lit.store_humanized_key = true + visit("/en/welcome") + assert page.has_content?("Text Without Default") + visit("/pl/welcome") + assert page.has_content?("Text Without Default") end - test 'should properly display text with default' do - Lit.humanize_key = false - visit('/en/welcome') - assert page.has_content?('Default content') - visit('/pl/welcome') - assert page.has_content?('Default content') + test "should properly display text with default" do + Lit.store_humanized_key = false + visit("/en/welcome") + assert page.has_content?("Default content") + visit("/pl/welcome") + assert page.has_content?("Default content") end - test 'should properly display saturday abbr in polish' do - visit('/pl/welcome') - assert page.has_content?('Sob') + test "should properly display saturday abbr in polish" do + visit("/pl/welcome") + assert page.has_content?("Sob") end - test 'should use interpolation instead of default value' do + test "should use interpolation instead of default value" do Rails.application.config.i18n.fallbacks = false - Lit.humanize_key = false - visit('/pl/welcome') - assert page.has_content?('Abrakadabra dwa kije') - visit('/en/welcome') - assert page.has_content?('Some Strange Key') + Lit.store_humanized_key = false + visit("/pl/welcome") + assert page.has_content?("Abrakadabra dwa kije") + visit("/en/welcome") + assert page.has_content?("Some Strange Key") end test "should properly display 'Hello world' in polish" do - visit('/pl/welcome') - assert page.has_content?('Witaj świecie') + visit("/pl/welcome") + assert page.has_content?("Witaj świecie") end test "should properly display 'Hello world' in polish after change" do - visit('/pl/welcome') - locale = Lit::Locale.find_by_locale!('pl') - localization_key = Lit::LocalizationKey.find_by_localization_key!('scope.hello_world') + visit("/pl/welcome") + locale = Lit::Locale.find_by_locale!("pl") + localization_key = Lit::LocalizationKey.find_by_localization_key!("scope.hello_world") localization = Lit::Localization.find_by_locale_id_and_localization_key_id!(locale.id, localization_key.id) text = localization.translation assert text.present? assert page.has_content?(text) - text = 'Żegnaj okrutny świecie' + text = "Żegnaj okrutny świecie" localization.translated_value = text localization.save! localization.update_column :is_changed, true @@ -80,32 +79,32 @@ def teardown # check lit/lit/cache.rb:198 localization.update_column :updated_at, localization.reload.updated_at + 1.second Lit.init.cache.refresh_key(localization.full_key) - visit('/pl/welcome') + visit("/pl/welcome") localization.reload assert page.has_content?(text) end - test 'should not fallback if not asked to' do - Lit.humanize_key = false + test "should not fallback if not asked to" do + Lit.store_humanized_key = false Rails.application.config.i18n.fallbacks = false - visit('/en/welcome') - assert page.has_content?('English translation') - visit('/pl/welcome') - assert page.has_content?('Text With Translation In English') + visit("/en/welcome") + assert page.has_content?("English translation") + visit("/pl/welcome") + assert page.has_content?("Text With Translation In English") end - test 'should properly fallback' do + test "should properly fallback" do Rails.application.config.i18n.fallbacks = [:en] - visit('/en/welcome') - assert page.has_content?('English translation') - visit('/pl/welcome') - assert page.has_content?('English translation') + visit("/en/welcome") + assert page.has_content?("English translation") + visit("/pl/welcome") + assert page.has_content?("English translation") end - test 'shoud properly save default value' do - assert !Lit::Localization.where(default_value: 'Simple test with default value').exists? - visit('/en/welcome') - assert page.has_content?('Simple test with default value') - assert Lit::Localization.where(default_value: 'Simple test with default value').exists? + test "shoud properly save default value" do + assert !Lit::Localization.where(default_value: "Simple test with default value").exists? + visit("/en/welcome") + assert page.has_content?("Simple test with default value") + assert Lit::Localization.where(default_value: "Simple test with default value").exists? end end diff --git a/test/unit/i18n_backend_test.rb b/test/unit/i18n_backend_test.rb index e5108f8b..7a14984b 100644 --- a/test/unit/i18n_backend_test.rb +++ b/test/unit/i18n_backend_test.rb @@ -17,7 +17,7 @@ def teardown I18n.backend = @old_backend I18n.backend = @old_backend I18n.locale = @old_locale - Lit.store_humanizes_key = @old_humanize_key + Lit.store_humanized_key = @old_humanize_key end test "properly returns available locales" do diff --git a/test/unit/lit_behaviour_test.rb b/test/unit/lit_behaviour_test.rb index 395c0424..19c9df78 100644 --- a/test/unit/lit_behaviour_test.rb +++ b/test/unit/lit_behaviour_test.rb @@ -10,18 +10,18 @@ def setup Lit::LocalizationVersion.delete_all @old_load_path = I18n.load_path - @old_humanize_key = Lit.humanize_key + @old_humanize_key = Lit.store_humanized_key @old_backend = I18n.backend @old_ignore = Lit.ignore_yaml_on_startup I18n.load_path = [] - Lit.humanize_key = false + Lit.store_humanized_key = false I18n.backend = Backend.new(Lit::Cache.new) super end def teardown - Lit.humanize_key = @old_humanize_key + Lit.store_humanized_key = @old_humanize_key I18n.backend = @old_backend I18n.load_path = @old_load_path Lit.ignore_yaml_on_startup = @old_ignore @@ -236,7 +236,7 @@ def teardown end test "cache tree structure of keys and retrieve it from redis like I18n does" do - Lit.humanize_key = true + Lit.store_humanized_key = true assert_difference "Lit::LocalizationKey.count", 2 do I18n.t("scopes.hash.sub_one", default: "Left leaf") I18n.t("scopes.hash.sub_two", default: "Right leaf") diff --git a/test/unit/pure_i18n_compatibility_test.rb b/test/unit/pure_i18n_compatibility_test.rb index 8b0fe9a3..05c57893 100644 --- a/test/unit/pure_i18n_compatibility_test.rb +++ b/test/unit/pure_i18n_compatibility_test.rb @@ -1,4 +1,4 @@ -require 'test_helper' +require "test_helper" class PureI18nCompatibilityTest < ActiveSupport::TestCase class Backend < Lit::I18nBackend @@ -11,17 +11,17 @@ def setup Lit::LocalizationVersion.delete_all @old_load_path = I18n.load_path - @old_humanize_key = Lit.humanize_key + @old_humanize_key = Lit.store_humanized_key @old_backend = I18n.backend I18n.load_path = [] - Lit.humanize_key = false + Lit.store_humanized_key = false I18n.backend = Backend.new(Lit.loader.cache) super end def teardown - Lit.humanize_key = @old_humanize_key + Lit.store_humanized_key = @old_humanize_key I18n.backend = @old_backend I18n.load_path = @old_load_path super @@ -39,7 +39,7 @@ def teardown include I18n::Tests::Localization::Time include I18n::Tests::Localization::Procs - test 'make sure we use the Lit::I18n backend' do + test "make sure we use the Lit::I18n backend" do assert_equal Backend, I18n.backend.class end end From 7e03e96489f628c6924390d0f2836fde70894cbb Mon Sep 17 00:00:00 2001 From: Maciej Litwiniuk Date: Mon, 19 Aug 2024 23:30:17 +0200 Subject: [PATCH 4/4] Added coffee-rails and sassc to gem dependencies Those should be removed before releasing new version of the gem --- config/routes.rb | 6 ++-- lib/generators/lit/install_generator.rb | 40 ++++++++++++------------- lit.gemspec | 2 ++ 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index d0e88571..69efd18a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,11 +2,11 @@ if Lit.api_enabled namespace :api do namespace :v1 do - get '/last_change' => 'localizations#last_change' + get "/last_change" => "localizations#last_change" resources :locales, only: [:index] resources :localization_keys, only: [:index] resources :localizations, only: [:index] do - get 'last_change', on: :collection + get "last_change", on: :collection end end end @@ -53,5 +53,5 @@ resource :cloud_translation, only: :show - root to: 'dashboard#index' + root to: "dashboard#index" end diff --git a/lib/generators/lit/install_generator.rb b/lib/generators/lit/install_generator.rb index cd95af1f..530b0f65 100644 --- a/lib/generators/lit/install_generator.rb +++ b/lib/generators/lit/install_generator.rb @@ -1,32 +1,32 @@ -require 'rails/generators' +require "rails/generators" module Lit module Generators class InstallGenerator < ::Rails::Generators::Base - class_option 'key-value-engine', type: :string - class_option 'authentication-function', type: :string - class_option 'no-migrate', type: :boolean + class_option "key-value-engine", type: :string + class_option "authentication-function", type: :string + class_option "no-migrate", type: :boolean - source_root File.expand_path('../install/templates', __FILE__) + source_root File.expand_path("../install/templates", __FILE__) - desc 'Automates Lit installation' + desc "Automates Lit installation" def set_authentication_function @authentication_function = - options['authentication-function'].presence || - ask("What's the authentication function, ie. :authenticate_user! :").presence || nil + options["authentication-function"].presence || + ask("What's the authentication function, ie. :authenticate_user! :").presence || nil end def set_key_value_engine @key_value_engine = - options['key-value-engine'].presence || ask("What's the key value engine? ([hash] OR redis):").presence || - :hash + options["key-value-engine"].presence || ask("What's the key value engine? ([hash] OR redis):").presence || + :hash end def add_redis_dependency - if @key_value_engine == 'redis' - puts 'Adding redis dependency' - gem 'redis' - Bundler.with_clean_env { run 'bundle install' } + if @key_value_engine == "redis" + puts "Adding redis dependency" + gem "redis" + Bundler.with_clean_env { run "bundle install" } end end @@ -37,17 +37,17 @@ def generate_api_key def add_lit_initializer path = "#{::Rails.root}/config/initializers/lit.rb" if File.exist?(path) - puts 'Skipping config/initializers/lit.rb creation, file already exists!' + puts "Skipping config/initializers/lit.rb creation, file already exists!" else - puts 'Adding lit initializer (config/initializers/lit.rb)...' - template 'initializer.erb', path + puts "Adding lit initializer (config/initializers/lit.rb)..." + template "initializer.erb", path end end def run_migrations - unless options['no-migrate'] - puts 'Running rake db:migrate' - `rake db:migrate` + unless options["no-migrate"] + puts "Running rails db:migrate" + `rails db:migrate` end end diff --git a/lit.gemspec b/lit.gemspec index c4e9a915..610f5ae8 100644 --- a/lit.gemspec +++ b/lit.gemspec @@ -19,6 +19,8 @@ Gem::Specification.new do |s| s.files = Dir["{app,config,db,lib}/**/*"] + %w[MIT-LICENSE Rakefile README.md] s.add_dependency "emoji_flag" s.add_dependency "jquery-rails" + s.add_dependency "coffee-rails" + s.add_dependency "sassc" s.add_dependency "rails", ">= 7.0" s.add_development_dependency "appraisal", "~> 2.5.0"