diff --git a/Gemfile.lock b/Gemfile.lock index 5232669..437b644 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -511,10 +511,10 @@ GEM paper_trail (12.3.0) activerecord (>= 5.2) request_store (~> 1.1) - parallel (1.23.0) + parallel (1.24.0) parallel_tests (4.4.0) parallel - parser (3.2.2.3) + parser (3.3.0.2) ast (~> 2.4.1) racc pg (1.4.6) @@ -593,7 +593,7 @@ GEM ffi (~> 1.0) redcarpet (3.6.0) redis (4.8.1) - regexp_parser (2.8.1) + regexp_parser (2.9.0) request_store (1.5.1) rack (>= 1.4) responders (3.1.1) @@ -641,7 +641,7 @@ GEM rubocop-ast (>= 1.28.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.29.0) + rubocop-ast (1.30.0) parser (>= 3.2.1.0) rubocop-capybara (2.20.0) rubocop (~> 1.41) @@ -652,10 +652,11 @@ GEM rubocop (>= 0.82.0) rubocop-performance (1.6.1) rubocop (>= 0.71.0) - rubocop-rails (2.22.1) + rubocop-rails (2.23.1) activesupport (>= 4.2.0) rack (>= 1.1) rubocop (>= 1.33.0, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) rubocop-rspec (2.25.0) rubocop (~> 1.40) rubocop-capybara (~> 2.17) @@ -719,7 +720,7 @@ GEM tzinfo (2.0.6) concurrent-ruby (~> 1.0) uber (0.1.0) - unicode-display_width (2.4.2) + unicode-display_width (2.5.0) uniform_notifier (1.16.0) valid_email2 (4.0.6) activemodel (>= 3.2) diff --git a/app/commands/decidim/term_customizer/admin/create_translation.rb b/app/commands/decidim/term_customizer/admin/create_translation.rb index c749f99..081a688 100644 --- a/app/commands/decidim/term_customizer/admin/create_translation.rb +++ b/app/commands/decidim/term_customizer/admin/create_translation.rb @@ -45,8 +45,8 @@ def create_translations TermCustomizer::Translation.create!( translation_set: form.translation_set, key: form.key, - value: value, - locale: locale + value:, + locale: ) end end diff --git a/app/commands/decidim/term_customizer/admin/import_translation_keys.rb b/app/commands/decidim/term_customizer/admin/import_translation_keys.rb index 59469a5..c9a96f6 100644 --- a/app/commands/decidim/term_customizer/admin/import_translation_keys.rb +++ b/app/commands/decidim/term_customizer/admin/import_translation_keys.rb @@ -44,12 +44,12 @@ def create_translations items = form.keys.map do |key| form.current_organization.available_locales.map do |locale| attrs = { - key: key, - locale: locale + key:, + locale: } next unless form.translation_set.translations.find_by(attrs).nil? - attrs.merge(value: I18n.t(key, locale: locale, default: "")) + attrs.merge(value: I18n.t(key, locale:, default: "")) end end.flatten diff --git a/app/commands/decidim/term_customizer/admin/update_translation.rb b/app/commands/decidim/term_customizer/admin/update_translation.rb index fcddd5c..c4e4356 100644 --- a/app/commands/decidim/term_customizer/admin/update_translation.rb +++ b/app/commands/decidim/term_customizer/admin/update_translation.rb @@ -43,21 +43,21 @@ def update_translations! l_translation = TermCustomizer::Translation.find_by( translation_set: translation.translation_set, key: translation.key, - locale: locale + locale: ) if l_translation l_translation.update!( key: form.key, - value: value, - locale: locale + value:, + locale: ) else l_translation = TermCustomizer::Translation.create!( translation_set: translation.translation_set, key: form.key, - value: value, - locale: locale + value:, + locale: ) end diff --git a/app/controllers/decidim/term_customizer/admin/add_translations_controller.rb b/app/controllers/decidim/term_customizer/admin/add_translations_controller.rb index 5ceb072..7d089fe 100644 --- a/app/controllers/decidim/term_customizer/admin/add_translations_controller.rb +++ b/app/controllers/decidim/term_customizer/admin/add_translations_controller.rb @@ -16,7 +16,7 @@ def create enforce_permission_to :create, :translation @form = form(TranslationKeyImportForm).from_params( params, - current_organization: current_organization, + current_organization:, translation_set: set ) diff --git a/app/controllers/decidim/term_customizer/admin/translation_sets_controller.rb b/app/controllers/decidim/term_customizer/admin/translation_sets_controller.rb index 8a2cba8..d27f595 100644 --- a/app/controllers/decidim/term_customizer/admin/translation_sets_controller.rb +++ b/app/controllers/decidim/term_customizer/admin/translation_sets_controller.rb @@ -21,11 +21,16 @@ def new ) end + def edit + enforce_permission_to :update, :translation_set, translation_set: set + @form = form(TranslationSetForm).from_model(set) + end + def create enforce_permission_to :create, :translation_set @form = form(TranslationSetForm).from_params( params, - current_organization: current_organization + current_organization: ) CreateTranslationSet.call(@form) do @@ -41,16 +46,11 @@ def create end end - def edit - enforce_permission_to :update, :translation_set, translation_set: set - @form = form(TranslationSetForm).from_model(set) - end - def update enforce_permission_to :update, :translation_set, translation_set: set @form = form(TranslationSetForm).from_params( params, - current_organization: current_organization + current_organization: ) UpdateTranslationSet.call(@form, set) do @@ -84,7 +84,7 @@ def duplicate hash["name_#{locale}"] = I18n.t( "translation_sets.duplicate.copied_set_name", name: set.name[locale], - locale: locale, + locale:, scope: "decidim.term_customizer.admin" ) end @@ -92,7 +92,7 @@ def duplicate @form = form(TranslationSetForm).from_params( params.merge(name_attrs), - current_organization: current_organization + current_organization: ) DuplicateTranslationSet.call(@form, set) do diff --git a/app/controllers/decidim/term_customizer/admin/translations_controller.rb b/app/controllers/decidim/term_customizer/admin/translations_controller.rb index e431fa5..88be650 100644 --- a/app/controllers/decidim/term_customizer/admin/translations_controller.rb +++ b/app/controllers/decidim/term_customizer/admin/translations_controller.rb @@ -18,11 +18,16 @@ def new @form = form(TranslationForm).from_model(Translation.new) end + def edit + enforce_permission_to(:update, :translation, translation:) + @form = form(TranslationForm).from_model(translation) + end + def create enforce_permission_to :create, :translation @form = form(TranslationForm).from_params( params, - current_organization: current_organization, + current_organization:, translation_set: set ) @@ -39,16 +44,11 @@ def create end end - def edit - enforce_permission_to :update, :translation, translation: translation - @form = form(TranslationForm).from_model(translation) - end - def update - enforce_permission_to :update, :translation, translation: translation + enforce_permission_to(:update, :translation, translation:) @form = form(TranslationForm).from_params( params, - current_organization: current_organization, + current_organization:, translation_set: set ) @@ -66,7 +66,7 @@ def update end def destroy - enforce_permission_to :destroy, :translation, translation: translation + enforce_permission_to(:destroy, :translation, translation:) # Destroy all locales of the translation key pfm = TermCustomizer::PluralFormsManager.new(current_organization) @@ -104,7 +104,7 @@ def import @import = form(Admin::TranslationsImportForm).from_params( params, - current_organization: current_organization + current_organization: ) ImportSetTranslations.call(@import, set) do on(:ok) do diff --git a/app/controllers/decidim/term_customizer/admin/translations_destroys_controller.rb b/app/controllers/decidim/term_customizer/admin/translations_destroys_controller.rb index ba6b2e0..b2fb71b 100644 --- a/app/controllers/decidim/term_customizer/admin/translations_destroys_controller.rb +++ b/app/controllers/decidim/term_customizer/admin/translations_destroys_controller.rb @@ -39,7 +39,7 @@ def set_form @form = form(Admin::TranslationsDestroyForm).from_params( params ).with_context( - current_organization: current_organization, + current_organization:, translation_set: set ) end diff --git a/app/forms/decidim/term_customizer/admin/translation_form.rb b/app/forms/decidim/term_customizer/admin/translation_form.rb index 7130859..112cf2f 100644 --- a/app/forms/decidim/term_customizer/admin/translation_form.rb +++ b/app/forms/decidim/term_customizer/admin/translation_form.rb @@ -14,7 +14,7 @@ class TranslationForm < Decidim::Form translatable_attribute :value, String validates :key, presence: true - validates :key, format: { with: %r{\A([a-z0-9_/?\-]+\.)*[a-z0-9_/?\-]+\z} }, unless: -> { key.blank? } + validates :key, format: { with: %r{\A([a-z0-9_/?-]+\.)*[a-z0-9_/?-]+\z} }, unless: -> { key.blank? } validates :value, translatable_presence: true validate :key_uniqueness @@ -30,8 +30,8 @@ def map_model(model) def key_uniqueness errors.add(:key, :taken) if translation_set && translation_set.translations.where( locale: I18n.locale, - key: key - ).where.not(id: id).exists? + key: + ).where.not(id:).exists? end end end diff --git a/app/models/decidim/term_customizer/translation.rb b/app/models/decidim/term_customizer/translation.rb index fd3c728..7b85589 100644 --- a/app/models/decidim/term_customizer/translation.rb +++ b/app/models/decidim/term_customizer/translation.rb @@ -10,7 +10,7 @@ class Translation < TermCustomizer::ApplicationRecord validates :locale, presence: true validates :key, presence: true - validates :key, format: { with: %r{\A([a-z0-9_/?\-]+\.)*[a-z0-9_/?\-]+\z} }, unless: -> { key.blank? } + validates :key, format: { with: %r{\A([a-z0-9_/?-]+\.)*[a-z0-9_/?-]+\z} }, unless: -> { key.blank? } validates :key, uniqueness: { scope: [:translation_set, :locale] }, unless: -> { key.blank? } class << self diff --git a/lib/decidim/term_customizer/admin_engine.rb b/lib/decidim/term_customizer/admin_engine.rb index 29bd4e6..5b948bd 100644 --- a/lib/decidim/term_customizer/admin_engine.rb +++ b/lib/decidim/term_customizer/admin_engine.rb @@ -44,7 +44,7 @@ class AdminEngine < ::Rails::Engine end end - initializer "decidim_term_customizer.register_icons" do |_app| + initializer "decidim_term_customizer.register_icons" do |_app| Decidim.icons.register(name: "Decidim::TermCustomizer", icon: "translate", category: "system", description: "Term Customizer", engine: :admin) Decidim.icons.register(name: "git-branch-line", icon: "git-branch-line", category: "system", description: "fork icon", engine: :admin) end diff --git a/lib/decidim/term_customizer/context/job_context.rb b/lib/decidim/term_customizer/context/job_context.rb index 8f73764..5108778 100644 --- a/lib/decidim/term_customizer/context/job_context.rb +++ b/lib/decidim/term_customizer/context/job_context.rb @@ -4,6 +4,7 @@ module Decidim module TermCustomizer module Context class JobContext < Base + # rubocop:disable Metrics/CyclomaticComplexity # rubocop:disable Metrics/PerceivedComplexity def resolve! # Figure out the organization and user through the job arguments if @@ -28,6 +29,7 @@ def resolve! # it through the user (if the user was passed). @organization ||= user.organization if user end + # rubocop:enable Metrics/CyclomaticComplexity # rubocop:enable Metrics/PerceivedComplexity protected diff --git a/lib/decidim/term_customizer/plural_forms_manager.rb b/lib/decidim/term_customizer/plural_forms_manager.rb index c8a3ee9..b3331b5 100644 --- a/lib/decidim/term_customizer/plural_forms_manager.rb +++ b/lib/decidim/term_customizer/plural_forms_manager.rb @@ -71,14 +71,14 @@ def add_locales_for!(translation, target_key) # Check that the translation is not already added in the set next if translation.translation_set.translations.where( key: target_key, - locale: locale + locale: ).any? # Add the plural form translation.translation_set.translations.create!( key: target_key, - locale: locale, - value: I18n.t(target_key, locale: locale, default: "") + locale:, + value: I18n.t(target_key, locale:, default: "") ) end end @@ -91,7 +91,7 @@ def destroy_locales_for!(translation, target_key) # Find the plural form the plural form target = translation.translation_set.translations.find_by( key: target_key, - locale: locale + locale: ) next unless target diff --git a/lib/decidim/term_customizer/resolver.rb b/lib/decidim/term_customizer/resolver.rb index 4ce043e..fc02b4b 100644 --- a/lib/decidim/term_customizer/resolver.rb +++ b/lib/decidim/term_customizer/resolver.rb @@ -68,7 +68,7 @@ def constraints_add_organization_query(query) query.or!( TermCustomizer::Constraint.where( - organization: organization, + organization:, subject_type: nil, subject_id: nil ) @@ -80,13 +80,13 @@ def constraints_add_space_query(query) query.or!( TermCustomizer::Constraint.where( - organization: organization, + organization:, subject: space ) ) query.or!( TermCustomizer::Constraint.where( - organization: organization, + organization:, subject_type: space.class.name, subject_id: nil ) @@ -98,7 +98,7 @@ def constraints_add_component_query(query) query.or!( TermCustomizer::Constraint.where( - organization: organization, + organization:, subject: component ) ) diff --git a/lib/decidim/term_customizer/test/factories.rb b/lib/decidim/term_customizer/test/factories.rb index a1c9471..4553aa9 100644 --- a/lib/decidim/term_customizer/test/factories.rb +++ b/lib/decidim/term_customizer/test/factories.rb @@ -3,7 +3,7 @@ FactoryBot.define do # Create as a sequence to avoid key collisions sequence :translation_key do |n| - "#{::Faker::Lorem.words(number: rand(1..3)).join(".").downcase}.tr#{n}" + "#{Faker::Lorem.words(number: rand(1..3)).join(".").downcase}.tr#{n}" end factory :translation_set, class: "Decidim::TermCustomizer::TranslationSet" do @@ -31,13 +31,13 @@ factory :translation, class: "Decidim::TermCustomizer::Translation" do locale { :en } key { generate(:translation_key) } - value { ::Faker::Lorem.words(number: rand(1..10)).join(" ") } - translation_set { create(:translation_set) } + value { Faker::Lorem.words(number: rand(1..10)).join(" ") } + translation_set end factory :translation_set_constraint, class: "Decidim::TermCustomizer::Constraint" do - organization { create(:organization) } - translation_set { create(:translation_set) } - subject { create(:participatory_process, organization: organization) } + organization + translation_set + subject { association(:participatory_process, organization:) } end end diff --git a/lib/decidim/term_customizer/translation_directory.rb b/lib/decidim/term_customizer/translation_directory.rb index 2fd302d..9d95a66 100644 --- a/lib/decidim/term_customizer/translation_directory.rb +++ b/lib/decidim/term_customizer/translation_directory.rb @@ -26,7 +26,7 @@ def translations_by_key(search) # rubocop:disable Rails/Delegate end def translations_by_term(search, case_sensitive: false) - translations.by_term(search, case_sensitive: case_sensitive) + translations.by_term(search, case_sensitive:) end private diff --git a/lib/decidim/term_customizer/translation_import_collection.rb b/lib/decidim/term_customizer/translation_import_collection.rb index e05e623..21a95df 100644 --- a/lib/decidim/term_customizer/translation_import_collection.rb +++ b/lib/decidim/term_customizer/translation_import_collection.rb @@ -56,9 +56,9 @@ def attributes_for_all_locales # the found item to the final array. if item.nil? { - key: key, + key:, locale: locale.to_s, - value: I18n.t(key, locale: locale, default: "") + value: I18n.t(key, locale:, default: "") } else item diff --git a/lib/decidim/term_customizer/translation_store.rb b/lib/decidim/term_customizer/translation_store.rb index dbf19bf..d43f0a5 100644 --- a/lib/decidim/term_customizer/translation_store.rb +++ b/lib/decidim/term_customizer/translation_store.rb @@ -19,7 +19,7 @@ def by_key(search) def by_term(search, case_sensitive: false) @values.select do |_key, term| - includes_string?(term, search, case_sensitive: case_sensitive) + includes_string?(term, search, case_sensitive:) end end diff --git a/spec/commands/decidim/term_customizer/admin/create_translation_set_spec.rb b/spec/commands/decidim/term_customizer/admin/create_translation_set_spec.rb index 2627aae..1e54d48 100644 --- a/spec/commands/decidim/term_customizer/admin/create_translation_set_spec.rb +++ b/spec/commands/decidim/term_customizer/admin/create_translation_set_spec.rb @@ -6,7 +6,7 @@ let(:form_klass) { Decidim::TermCustomizer::Admin::TranslationSetForm } let(:organization) { create(:organization) } - let(:user) { create :user, :admin, :confirmed, organization: organization } + let(:user) { create(:user, :admin, :confirmed, organization:) } let(:form) do form_klass.from_params( form_params @@ -17,7 +17,7 @@ end describe "call" do - let(:space) { create(:participatory_process, organization: organization) } + let(:space) { create(:participatory_process, organization:) } let(:form_params) do { diff --git a/spec/commands/decidim/term_customizer/admin/create_translation_spec.rb b/spec/commands/decidim/term_customizer/admin/create_translation_spec.rb index 60d3d0b..573f2ae 100644 --- a/spec/commands/decidim/term_customizer/admin/create_translation_spec.rb +++ b/spec/commands/decidim/term_customizer/admin/create_translation_spec.rb @@ -6,18 +6,18 @@ let(:form_klass) { Decidim::TermCustomizer::Admin::TranslationForm } let(:organization) { create(:organization) } - let(:user) { create :user, :admin, :confirmed, organization: organization } + let(:user) { create(:user, :admin, :confirmed, organization:) } let(:form) do form_klass.from_params( form_params ).with_context( current_organization: organization, current_user: user, - translation_set: translation_set + translation_set: ) end - let!(:translation_set) { create :translation_set } + let!(:translation_set) { create(:translation_set) } describe "call" do let(:form_params) do diff --git a/spec/commands/decidim/term_customizer/admin/destroy_translations_spec.rb b/spec/commands/decidim/term_customizer/admin/destroy_translations_spec.rb index 1ce3cc2..5519421 100644 --- a/spec/commands/decidim/term_customizer/admin/destroy_translations_spec.rb +++ b/spec/commands/decidim/term_customizer/admin/destroy_translations_spec.rb @@ -6,20 +6,20 @@ let(:form_klass) { Decidim::TermCustomizer::Admin::TranslationsDestroyForm } let(:organization) { create(:organization) } - let(:user) { create :user, :admin, :confirmed, organization: organization } + let(:user) { create(:user, :admin, :confirmed, organization:) } let(:form) do form_klass.from_params( form_params ).with_context( current_organization: organization, current_user: user, - translation_set: translation_set + translation_set: ) end let!(:translation_set) { create(:translation_set) } let!(:translations) do - create_list(:translation, 10, translation_set: translation_set) + create_list(:translation, 10, translation_set:) end describe "call" do @@ -67,7 +67,7 @@ [ create( :translation, - translation_set: translation_set, + translation_set:, key: "test.plural.one" ) ] @@ -77,7 +77,7 @@ # Add a plural form that should also get destroyed create( :translation, - translation_set: translation_set, + translation_set:, key: "test.plural.other" ) end diff --git a/spec/commands/decidim/term_customizer/admin/duplicate_translation_set_spec.rb b/spec/commands/decidim/term_customizer/admin/duplicate_translation_set_spec.rb index 6b09242..eb55c46 100644 --- a/spec/commands/decidim/term_customizer/admin/duplicate_translation_set_spec.rb +++ b/spec/commands/decidim/term_customizer/admin/duplicate_translation_set_spec.rb @@ -6,7 +6,7 @@ let(:form_klass) { Decidim::TermCustomizer::Admin::TranslationSetForm } let(:organization) { create(:organization) } - let(:user) { create :user, :admin, :confirmed, organization: organization } + let(:user) { create(:user, :admin, :confirmed, organization:) } let(:form) do form_klass.from_params( form_params @@ -15,10 +15,10 @@ current_user: user ) end - let!(:translation_set) { create :translation_set } + let!(:translation_set) { create(:translation_set) } describe "call" do - let(:space) { create(:participatory_process, organization: organization) } + let(:space) { create(:participatory_process, organization:) } let(:form_params) { { name: { en: "Name of the set" } } } @@ -45,15 +45,15 @@ describe "when the form is valid" do before do translation_set.constraints.create!( - organization: organization + organization: ) translation_set.constraints.create!( - organization: organization, + organization:, subject_type: "Decidim::ParticipatoryProcess", subject: space ) translation_set.constraints.create!( - organization: organization, + organization:, subject_type: "Decidim::Assembly" ) diff --git a/spec/commands/decidim/term_customizer/admin/import_set_translations_spec.rb b/spec/commands/decidim/term_customizer/admin/import_set_translations_spec.rb index 0c08982..adcc6a1 100644 --- a/spec/commands/decidim/term_customizer/admin/import_set_translations_spec.rb +++ b/spec/commands/decidim/term_customizer/admin/import_set_translations_spec.rb @@ -7,9 +7,9 @@ let(:locales) { [:en, :fi] } let(:organization) { create(:organization, available_locales: locales) } - let(:translation_set) { create(:translation_set, organization: organization) } + let(:translation_set) { create(:translation_set, organization:) } let(:file) { nil } - let(:form_params) { { file: file } } + let(:form_params) { { file: } } let(:form) do form_klass.from_params( form_params diff --git a/spec/commands/decidim/term_customizer/admin/import_translation_keys_spec.rb b/spec/commands/decidim/term_customizer/admin/import_translation_keys_spec.rb index 72294b1..a26d6a2 100644 --- a/spec/commands/decidim/term_customizer/admin/import_translation_keys_spec.rb +++ b/spec/commands/decidim/term_customizer/admin/import_translation_keys_spec.rb @@ -6,7 +6,7 @@ let(:form_klass) { Decidim::TermCustomizer::Admin::TranslationKeyImportForm } let(:organization) { create(:organization) } - let(:translation_set) { create(:translation_set, organization: organization) } + let(:translation_set) { create(:translation_set, organization:) } let(:keys) do [ "decidim.admin.actions.new_translation", @@ -20,12 +20,12 @@ form_params ).with_context( current_organization: organization, - translation_set: translation_set + translation_set: ) end describe "call" do - let(:form_params) { { keys: keys } } + let(:form_params) { { keys: } } let(:command) do described_class.new(form) @@ -61,7 +61,7 @@ keys.each do |key| expect( - Decidim::TermCustomizer::Translation.where(key: key).count + Decidim::TermCustomizer::Translation.where(key:).count ).to eq(3) end end @@ -69,7 +69,7 @@ context "when the key exists in another translation set" do let!(:translation_set2) do - create(:translation_set, organization: organization) + create(:translation_set, organization:) end let(:key) { "decidim.admin.actions.new_translation" } let!(:translation) do @@ -77,7 +77,7 @@ :translation, translation_set: translation_set2, locale: :en, - key: key + key: ) end @@ -85,7 +85,7 @@ command.call expect( - Decidim::TermCustomizer::Translation.where(key: key).count + Decidim::TermCustomizer::Translation.where(key:).count ).to eq(4) end end diff --git a/spec/commands/decidim/term_customizer/admin/update_translation_set_spec.rb b/spec/commands/decidim/term_customizer/admin/update_translation_set_spec.rb index 52aaada..571cea4 100644 --- a/spec/commands/decidim/term_customizer/admin/update_translation_set_spec.rb +++ b/spec/commands/decidim/term_customizer/admin/update_translation_set_spec.rb @@ -6,7 +6,7 @@ let(:form_klass) { Decidim::TermCustomizer::Admin::TranslationSetForm } let(:organization) { create(:organization) } - let(:user) { create :user, :admin, :confirmed, organization: organization } + let(:user) { create(:user, :admin, :confirmed, organization:) } let(:form) do form_klass.from_params( form_params @@ -16,10 +16,10 @@ ) end - let!(:translation_set) { create :translation_set } + let!(:translation_set) { create(:translation_set) } describe "call" do - let(:space) { create(:participatory_process, organization: organization) } + let(:space) { create(:participatory_process, organization:) } let(:form_params) do { diff --git a/spec/commands/decidim/term_customizer/admin/update_translation_spec.rb b/spec/commands/decidim/term_customizer/admin/update_translation_spec.rb index 5cbc58d..d904413 100644 --- a/spec/commands/decidim/term_customizer/admin/update_translation_spec.rb +++ b/spec/commands/decidim/term_customizer/admin/update_translation_spec.rb @@ -6,7 +6,7 @@ let(:form_klass) { Decidim::TermCustomizer::Admin::TranslationForm } let(:organization) { create(:organization) } - let(:user) { create :user, :admin, :confirmed, organization: organization } + let(:user) { create(:user, :admin, :confirmed, organization:) } let(:form) do form_klass.from_params( form_params @@ -16,10 +16,10 @@ ) end - let!(:translation) { create :translation, locale: :en, value: "Original value" } + let!(:translation) { create(:translation, locale: :en, value: "Original value") } describe "call" do - let(:space) { create(:participatory_process, organization: organization) } + let(:space) { create(:participatory_process, organization:) } let(:form_params) do { diff --git a/spec/controllers/decidim/term_customizer/admin/add_translations_controller_spec.rb b/spec/controllers/decidim/term_customizer/admin/add_translations_controller_spec.rb index f319b24..8c3f97b 100644 --- a/spec/controllers/decidim/term_customizer/admin/add_translations_controller_spec.rb +++ b/spec/controllers/decidim/term_customizer/admin/add_translations_controller_spec.rb @@ -4,14 +4,14 @@ module Decidim module TermCustomizer - describe Admin::AddTranslationsController, type: :controller do + describe Admin::AddTranslationsController do include_context "with setup initializer" routes { Decidim::TermCustomizer::AdminEngine.routes } let(:organization) { create(:organization) } - let(:user) { create(:user, :confirmed, :admin, organization: organization) } - let(:translation_set) { create(:translation_set, organization: organization) } + let(:user) { create(:user, :confirmed, :admin, organization:) } + let(:translation_set) { create(:translation_set, organization:) } let(:params) do { @@ -26,7 +26,7 @@ module TermCustomizer describe "GET index" do it "renders the index template" do - get :index, params: params + get(:index, params:) expect(response).to have_http_status(:ok) expect(subject).to render_template(:index) end @@ -50,10 +50,10 @@ module TermCustomizer describe "GET search" do context "with no search term provided" do it "renders an empty search results JSON" do - get :search, params: params + get(:search, params:) expect(response).to have_http_status(:ok) - json = JSON.parse(response.body) + json = response.parsed_body expect(json.length).to eq(0) end end @@ -65,7 +65,7 @@ module TermCustomizer ) expect(response).to have_http_status(:ok) - json = JSON.parse(response.body) + json = response.parsed_body expect(json.length).to eq(76) end end diff --git a/spec/controllers/decidim/term_customizer/admin/caches_controller_spec.rb b/spec/controllers/decidim/term_customizer/admin/caches_controller_spec.rb index d6d6967..ce59972 100644 --- a/spec/controllers/decidim/term_customizer/admin/caches_controller_spec.rb +++ b/spec/controllers/decidim/term_customizer/admin/caches_controller_spec.rb @@ -4,13 +4,13 @@ module Decidim module TermCustomizer - describe Admin::CachesController, type: :controller do + describe Admin::CachesController do include_context "with setup initializer" routes { Decidim::TermCustomizer::AdminEngine.routes } let(:organization) { create(:organization) } - let(:user) { create(:user, :confirmed, :admin, organization: organization) } + let(:user) { create(:user, :confirmed, :admin, organization:) } before do request.env["decidim.current_organization"] = organization diff --git a/spec/controllers/decidim/term_customizer/admin/translation_sets_controller_spec.rb b/spec/controllers/decidim/term_customizer/admin/translation_sets_controller_spec.rb index cd99075..c3230df 100644 --- a/spec/controllers/decidim/term_customizer/admin/translation_sets_controller_spec.rb +++ b/spec/controllers/decidim/term_customizer/admin/translation_sets_controller_spec.rb @@ -4,14 +4,14 @@ module Decidim module TermCustomizer - describe Admin::TranslationSetsController, type: :controller do + describe Admin::TranslationSetsController do include_context "with setup initializer" routes { Decidim::TermCustomizer::AdminEngine.routes } let(:organization) { create(:organization) } let(:other_organization) { create(:organization) } - let(:user) { create(:user, :confirmed, :admin, organization: organization) } + let(:user) { create(:user, :confirmed, :admin, organization:) } before do request.env["decidim.current_organization"] = organization @@ -20,7 +20,7 @@ module TermCustomizer describe "GET index" do before do - create_list(:translation_set, 10, organization: organization) + create_list(:translation_set, 10, organization:) create_list(:translation_set, 10, organization: other_organization) end @@ -44,7 +44,7 @@ module TermCustomizer context "when participatory space exists" do before do - create(:participatory_process, organization: organization) + create(:participatory_process, organization:) end it "is available for selection" do @@ -68,7 +68,7 @@ module TermCustomizer end describe "GET edit" do - let(:translation_set) { create(:translation_set, organization: organization) } + let(:translation_set) { create(:translation_set, organization:) } it "renders the edit form" do get :edit, params: { id: translation_set.id } @@ -78,7 +78,7 @@ module TermCustomizer end describe "PUT update" do - let(:translation_set) { create(:translation_set, organization: organization) } + let(:translation_set) { create(:translation_set, organization:) } it "updates the translation set" do put :update, params: { @@ -92,7 +92,7 @@ module TermCustomizer end describe "DELETE destroy" do - let(:translation_set) { create(:translation_set, organization: organization) } + let(:translation_set) { create(:translation_set, organization:) } it "destroys the translation set" do delete :destroy, params: { id: translation_set.id } @@ -103,7 +103,7 @@ module TermCustomizer end describe "POST duplicate" do - let(:translation_set) { create(:translation_set, organization: organization) } + let(:translation_set) { create(:translation_set, organization:) } it "duplicates a translation set" do post :duplicate, params: { id: translation_set.id } diff --git a/spec/controllers/decidim/term_customizer/admin/translations_controller_spec.rb b/spec/controllers/decidim/term_customizer/admin/translations_controller_spec.rb index 8115e5c..0121e0f 100644 --- a/spec/controllers/decidim/term_customizer/admin/translations_controller_spec.rb +++ b/spec/controllers/decidim/term_customizer/admin/translations_controller_spec.rb @@ -4,15 +4,15 @@ module Decidim module TermCustomizer - describe Admin::TranslationsController, type: :controller do + describe Admin::TranslationsController do include_context "with setup initializer" routes { Decidim::TermCustomizer::AdminEngine.routes } let(:organization) { create(:organization) } let(:other_organization) { create(:organization) } - let(:user) { create(:user, :confirmed, :admin, organization: organization) } - let(:translation_set) { create(:translation_set, organization: organization) } + let(:user) { create(:user, :confirmed, :admin, organization:) } + let(:translation_set) { create(:translation_set, organization:) } let(:other_translation_set) { create(:translation_set, organization: other_organization) } let(:params) do @@ -28,12 +28,12 @@ module TermCustomizer describe "GET index" do before do - create_list(:translation, 10, translation_set: translation_set) + create_list(:translation, 10, translation_set:) create_list(:translation, 10, translation_set: other_translation_set) end it "renders the index listing" do - get :index, params: params + get(:index, params:) expect(response).to have_http_status(:ok) expect(subject).to render_template(:index) expect(assigns(:translations).count).to eq(10) @@ -42,7 +42,7 @@ module TermCustomizer describe "GET new" do it "renders the empty form" do - get :new, params: params + get(:new, params:) expect(response).to have_http_status(:ok) expect(subject).to render_template(:new) end @@ -61,7 +61,7 @@ module TermCustomizer end describe "GET edit" do - let(:translation) { create(:translation, translation_set: translation_set) } + let(:translation) { create(:translation, translation_set:) } it "renders the edit form" do get :edit, params: params.merge(id: translation.id) @@ -71,7 +71,7 @@ module TermCustomizer end describe "PUT update" do - let(:translation) { create(:translation, translation_set: translation_set) } + let(:translation) { create(:translation, translation_set:) } it "updates the translation" do put :update, params: params.merge( @@ -86,7 +86,7 @@ module TermCustomizer end describe "POST export" do - let(:translation_set) { create(:translation_set, organization: organization) } + let(:translation_set) { create(:translation_set, organization:) } it "exports the translations" do post :export, params: params.merge(format: "JSON") @@ -97,7 +97,7 @@ module TermCustomizer end describe "DELETE destroy" do - let(:translation) { create(:translation, translation_set: translation_set) } + let(:translation) { create(:translation, translation_set:) } it "destroys the translation" do delete :destroy, params: params.merge(id: translation.id) @@ -109,7 +109,7 @@ module TermCustomizer describe "GET import" do it "renders the import form" do - get :new_import, params: params + get(:new_import, params:) expect(response).to have_http_status(:ok) expect(subject).to render_template(:new_import) @@ -127,7 +127,7 @@ module TermCustomizer end it "runs the import" do - post :import, params: params.merge(file: file) + post :import, params: params.merge(file:) expect(flash[:notice]).not_to be_empty expect(response).to have_http_status(:found) diff --git a/spec/controllers/decidim/term_customizer/admin/translations_destroys_controller_spec.rb b/spec/controllers/decidim/term_customizer/admin/translations_destroys_controller_spec.rb index 1783131..bea9c56 100644 --- a/spec/controllers/decidim/term_customizer/admin/translations_destroys_controller_spec.rb +++ b/spec/controllers/decidim/term_customizer/admin/translations_destroys_controller_spec.rb @@ -4,16 +4,16 @@ module Decidim module TermCustomizer - describe Admin::TranslationsDestroysController, type: :controller do + describe Admin::TranslationsDestroysController do include_context "with setup initializer" routes { Decidim::TermCustomizer::AdminEngine.routes } let(:organization) { create(:organization) } let(:other_organization) { create(:organization) } - let(:user) { create(:user, :confirmed, :admin, organization: organization) } - let(:translation_set) { create(:translation_set, organization: organization) } - let!(:translations) { create_list(:translation, 10, translation_set: translation_set) } + let(:user) { create(:user, :confirmed, :admin, organization:) } + let(:translation_set) { create(:translation_set, organization:) } + let!(:translations) { create_list(:translation, 10, translation_set:) } let(:params) do { @@ -29,7 +29,7 @@ module TermCustomizer describe "GET new" do it "renders the confirm view" do - get :new, params: params + get(:new, params:) expect(response).to have_http_status(:ok) expect(subject).to render_template(:new) expect(assigns(:form).translations.count).to eq(10) @@ -37,10 +37,10 @@ module TermCustomizer end describe "DELETE destroy" do - let(:translation) { create(:translation, translation_set: translation_set) } + let(:translation) { create(:translation, translation_set:) } it "destroys the translations" do - delete :destroy, params: params + delete(:destroy, params:) expect(flash[:notice]).not_to be_empty expect(response).to have_http_status(:found) @@ -50,7 +50,7 @@ module TermCustomizer let!(:translations) { [] } it "redirects with an alert" do - delete :destroy, params: params + delete(:destroy, params:) expect(flash[:alert]).not_to be_empty expect(response).to have_http_status(:found) diff --git a/spec/forms/decidim/term_customizer/admin/translation_form_spec.rb b/spec/forms/decidim/term_customizer/admin/translation_form_spec.rb index 41788eb..5e3125d 100644 --- a/spec/forms/decidim/term_customizer/admin/translation_form_spec.rb +++ b/spec/forms/decidim/term_customizer/admin/translation_form_spec.rb @@ -9,16 +9,16 @@ module Admin subject { form } let(:organization) { create(:organization) } - let(:translation_set) { create(:translation_set, organization: organization) } + let(:translation_set) { create(:translation_set, organization:) } let(:key) { "translation.key" } let(:locale) { I18n.locale } let(:value) { Decidim::Faker::Localized.sentence(word_count: 3) } - let(:params) { { key: key, value: value } } + let(:params) { { key:, value: } } let(:form) do described_class.from_params(params).with_context( current_organization: organization, - translation_set: translation_set + translation_set: ) end @@ -27,8 +27,8 @@ module Admin end context "when updating an existing translation without changing the key" do - let(:translation) { create(:translation, key: key, translation_set: translation_set) } - let(:params) { { id: translation.id, key: key, value: value } } + let(:translation) { create(:translation, key:, translation_set:) } + let(:params) { { id: translation.id, key:, value: } } it { is_expected.to be_valid } end diff --git a/spec/forms/decidim/term_customizer/admin/translation_key_import_form_spec.rb b/spec/forms/decidim/term_customizer/admin/translation_key_import_form_spec.rb index aa152ff..31ffc4c 100644 --- a/spec/forms/decidim/term_customizer/admin/translation_key_import_form_spec.rb +++ b/spec/forms/decidim/term_customizer/admin/translation_key_import_form_spec.rb @@ -9,14 +9,14 @@ module Admin subject { form } let(:organization) { create(:organization) } - let(:translation_set) { create(:translation_set, organization: organization) } + let(:translation_set) { create(:translation_set, organization:) } let(:keys) { ["first.key", "second.key", "third.key"] } - let(:params) { { keys: keys } } + let(:params) { { keys: } } let(:form) do described_class.from_params(params).with_context( current_organization: organization, - translation_set: translation_set + translation_set: ) end diff --git a/spec/forms/decidim/term_customizer/admin/translation_set_constraint_form_spec.rb b/spec/forms/decidim/term_customizer/admin/translation_set_constraint_form_spec.rb index ded0897..6c569c8 100644 --- a/spec/forms/decidim/term_customizer/admin/translation_set_constraint_form_spec.rb +++ b/spec/forms/decidim/term_customizer/admin/translation_set_constraint_form_spec.rb @@ -10,7 +10,7 @@ module Admin let(:organization) { create(:organization) } let(:subject_manifest) { :particpatory_process } - let(:params) { { subject_manifest: subject_manifest } } + let(:params) { { subject_manifest: } } let(:form) do described_class.from_params(params).with_context( @@ -23,7 +23,7 @@ module Admin end describe "#to_param" do - subject { described_class.new(id: id) } + subject { described_class.new(id:) } context "with actual ID" do let(:id) { double } diff --git a/spec/forms/decidim/term_customizer/admin/translation_set_form_spec.rb b/spec/forms/decidim/term_customizer/admin/translation_set_form_spec.rb index bdab076..1037b2b 100644 --- a/spec/forms/decidim/term_customizer/admin/translation_set_form_spec.rb +++ b/spec/forms/decidim/term_customizer/admin/translation_set_form_spec.rb @@ -10,7 +10,7 @@ module Admin let(:organization) { create(:organization) } let(:name) { Decidim::Faker::Localized.sentence(word_count: 3) } - let(:params) { { name: name } } + let(:params) { { name: } } let(:form) do described_class.from_params(params).with_context( @@ -25,7 +25,7 @@ module Admin context "when the name is not defined" do let(:name) { nil } - it { is_expected.to be_invalid } + it { is_expected.not_to be_valid } end end end diff --git a/spec/forms/decidim/term_customizer/admin/translation_set_subject_component_form_spec.rb b/spec/forms/decidim/term_customizer/admin/translation_set_subject_component_form_spec.rb index 31ec59a..885441d 100644 --- a/spec/forms/decidim/term_customizer/admin/translation_set_subject_component_form_spec.rb +++ b/spec/forms/decidim/term_customizer/admin/translation_set_subject_component_form_spec.rb @@ -9,11 +9,11 @@ module Admin subject { form } let(:organization) { create(:organization) } - let(:space) { create(:participatory_process, organization: organization) } + let(:space) { create(:participatory_process, organization:) } let(:component) { create(:proposal_component, participatory_space: space) } let(:subject_id) { space.id } let(:component_id) { component.id } - let(:params) { { subject_id: subject_id, component_id: component_id } } + let(:params) { { subject_id:, component_id: } } let(:form) do described_class.from_params(params).with_context( diff --git a/spec/forms/decidim/term_customizer/admin/translation_set_subject_form_spec.rb b/spec/forms/decidim/term_customizer/admin/translation_set_subject_form_spec.rb index a1d420c..435abe0 100644 --- a/spec/forms/decidim/term_customizer/admin/translation_set_subject_form_spec.rb +++ b/spec/forms/decidim/term_customizer/admin/translation_set_subject_form_spec.rb @@ -10,7 +10,7 @@ module Admin let(:organization) { create(:organization) } let(:subject_manifest) { :particpatory_process } - let(:params) { { subject_manifest: subject_manifest } } + let(:params) { { subject_manifest: } } let(:form) do described_class.from_params(params).with_context( @@ -24,7 +24,7 @@ module Admin describe "#map_model" do context "with participatory space" do - let(:space) { create(:participatory_process, organization: organization) } + let(:space) { create(:participatory_process, organization:) } it "maps the model" do subject.map_model(space) @@ -36,7 +36,7 @@ module Admin end describe "#component" do - let(:space) { create(:participatory_process, organization: organization) } + let(:space) { create(:participatory_process, organization:) } let(:form_subject) { space } before do diff --git a/spec/forms/decidim/term_customizer/admin/translations_destroy_form_spec.rb b/spec/forms/decidim/term_customizer/admin/translations_destroy_form_spec.rb index abc0433..1f6483e 100644 --- a/spec/forms/decidim/term_customizer/admin/translations_destroy_form_spec.rb +++ b/spec/forms/decidim/term_customizer/admin/translations_destroy_form_spec.rb @@ -9,8 +9,8 @@ module Admin subject { form } let(:organization) { create(:organization) } - let(:translation_set) { create(:translation_set, organization: organization) } - let(:translations) { create_list(:translation, 10, translation_set: translation_set) } + let(:translation_set) { create(:translation_set, organization:) } + let(:translations) { create_list(:translation, 10, translation_set:) } let(:params) { { translation_ids: translations.map(&:id) } } let(:form_translation_set) { translation_set } @@ -50,8 +50,8 @@ module Admin translations.each do |tr| create( :translation, - translation_set: translation_set, - locale: locale, + translation_set:, + locale:, key: tr.key, value: Decidim::Faker::Localized.sentence(word_count: 3) ) diff --git a/spec/forms/decidim/term_customizer/admin/translations_import_form_spec.rb b/spec/forms/decidim/term_customizer/admin/translations_import_form_spec.rb index d3685b6..de66a51 100644 --- a/spec/forms/decidim/term_customizer/admin/translations_import_form_spec.rb +++ b/spec/forms/decidim/term_customizer/admin/translations_import_form_spec.rb @@ -17,7 +17,7 @@ module Admin ) ) end - let(:params) { { file: file } } + let(:params) { { file: } } let(:form) do described_class.from_params(params).with_context( diff --git a/spec/jobs/decidim/term_customizer/export_job_spec.rb b/spec/jobs/decidim/term_customizer/export_job_spec.rb index 576d65b..456c176 100644 --- a/spec/jobs/decidim/term_customizer/export_job_spec.rb +++ b/spec/jobs/decidim/term_customizer/export_job_spec.rb @@ -7,8 +7,8 @@ module TermCustomizer module Admin describe ExportJob do let(:organization) { create(:organization) } - let!(:translation_set) { create :translation_set, organization: organization } - let!(:user) { create(:user, organization: organization) } + let!(:translation_set) { create(:translation_set, organization:) } + let!(:user) { create(:user, organization:) } before do # Unsubscribe from the active job notification in order to avoid the diff --git a/spec/lib/decidim/term_customizer/admin_engine_spec.rb b/spec/lib/decidim/term_customizer/admin_engine_spec.rb index 8bee5e7..70db44b 100644 --- a/spec/lib/decidim/term_customizer/admin_engine_spec.rb +++ b/spec/lib/decidim/term_customizer/admin_engine_spec.rb @@ -44,12 +44,11 @@ def call(*args) expect(name).to eq(:admin_menu) context = context_class.new(&block) - allow(context).to receive(:decidim_admin_term_customizer).and_return(routes) - allow(context).to receive(:current_organization).and_return(organization) + allow(context).to receive_messages(decidim_admin_term_customizer: routes, current_organization: organization) allow(context).to receive(:allowed_to?).with( :update, :organization, - organization: organization + organization: ).and_return(allowed_to_result) allow(routes).to receive(:translation_sets_path).and_return(path) expect(menu).to receive(:add_item).with( diff --git a/spec/lib/decidim/term_customizer/context/controller_context_spec.rb b/spec/lib/decidim/term_customizer/context/controller_context_spec.rb index a4aea14..f3ad2c3 100644 --- a/spec/lib/decidim/term_customizer/context/controller_context_spec.rb +++ b/spec/lib/decidim/term_customizer/context/controller_context_spec.rb @@ -5,7 +5,7 @@ describe Decidim::TermCustomizer::Context::ControllerContext do subject { described_class.new(data) } - let(:data) { { headers: headers } } + let(:data) { { headers: } } let(:headers) { double } let(:controller) { double } let(:organization) { double } diff --git a/spec/lib/decidim/term_customizer/context/job_context_spec.rb b/spec/lib/decidim/term_customizer/context/job_context_spec.rb index c37e49d..4ba69d8 100644 --- a/spec/lib/decidim/term_customizer/context/job_context_spec.rb +++ b/spec/lib/decidim/term_customizer/context/job_context_spec.rb @@ -5,7 +5,7 @@ describe Decidim::TermCustomizer::Context::JobContext do subject { described_class.new(data) } - let(:data) { { job: job } } + let(:data) { { job: } } let(:job) { double } let(:organization) { create(:organization) } @@ -50,7 +50,7 @@ end context "with participatory process passed in the arguments" do - let(:space) { create(:participatory_process, organization: organization) } + let(:space) { create(:participatory_process, organization:) } let(:arguments) { [organization, space] } it "resolves the participatory space" do @@ -61,7 +61,7 @@ end context "with object having a participatory process passed in the arguments" do - let(:space) { create(:participatory_process, organization: organization) } + let(:space) { create(:participatory_process, organization:) } let(:obj) { double } let(:arguments) { [organization, obj] } @@ -77,7 +77,7 @@ end context "with component passed in the arguments" do - let(:space) { create(:participatory_process, organization: organization) } + let(:space) { create(:participatory_process, organization:) } let(:component) do create(:component, manifest_name: :proposals, participatory_space: space) end @@ -91,8 +91,8 @@ end context "with component and space passed in the arguments" do - let(:other_space) { create(:participatory_process, organization: organization) } - let(:space) { create(:participatory_process, organization: organization) } + let(:other_space) { create(:participatory_process, organization:) } + let(:space) { create(:participatory_process, organization:) } let(:component) do create(:component, manifest_name: :proposals, participatory_space: space) end @@ -107,7 +107,7 @@ context "with organization and space passed in the arguments" do let(:other_organization) { create(:organization) } - let(:space) { create(:participatory_process, organization: organization) } + let(:space) { create(:participatory_process, organization:) } let(:arguments) { [other_organization, space] } it "resolves the participatory space based on the component" do @@ -118,7 +118,7 @@ end context "with object having a component passed in the arguments" do - let(:space) { create(:participatory_process, organization: organization) } + let(:space) { create(:participatory_process, organization:) } let(:component) do create(:component, manifest_name: :proposals, participatory_space: space) end diff --git a/spec/lib/decidim/term_customizer/engine_spec.rb b/spec/lib/decidim/term_customizer/engine_spec.rb index e6bdaa0..94a2403 100644 --- a/spec/lib/decidim/term_customizer/engine_spec.rb +++ b/spec/lib/decidim/term_customizer/engine_spec.rb @@ -99,8 +99,7 @@ let(:resolver) { double } before do - allow(dummy_job).to receive(:job_id).and_return(1) - allow(dummy_job).to receive(:queue_name).and_return("queue") + allow(dummy_job).to receive_messages(job_id: 1, queue_name: "queue") allow(dummy_job).to receive(:arguments).and_return(arguments) allow(Decidim::TermCustomizer::I18nBackend).to receive(:new).and_return(dummy_backend) diff --git a/spec/lib/decidim/term_customizer/i18n_backend_spec.rb b/spec/lib/decidim/term_customizer/i18n_backend_spec.rb index 9a53d57..dd8ac4c 100644 --- a/spec/lib/decidim/term_customizer/i18n_backend_spec.rb +++ b/spec/lib/decidim/term_customizer/i18n_backend_spec.rb @@ -58,7 +58,7 @@ before do locales.each do |locale| - create_list(:translation, 3, locale: locale) + create_list(:translation, 3, locale:) end end @@ -132,7 +132,8 @@ describe "#translate" do it "calls lookup" do allow(subject).to receive(:lookup).and_return("Translation") # rubocop:disable RSpec/SubjectStub - subject.translate(:en, "decidim.term1") + result = subject.translate(:en, "decidim.term1") + expect(result).to eq("Translation") end context "with actual translations" do diff --git a/spec/lib/decidim/term_customizer/loader_spec.rb b/spec/lib/decidim/term_customizer/loader_spec.rb index 43757b0..ae1ca18 100644 --- a/spec/lib/decidim/term_customizer/loader_spec.rb +++ b/spec/lib/decidim/term_customizer/loader_spec.rb @@ -39,7 +39,7 @@ objects = [] translations_list.each_with_object({}) do |(locale, v), _obj| objects << flatten_hash(v).map do |translation_key, translation_term| - create(:translation, locale: locale, key: translation_key, value: translation_term) + create(:translation, locale:, key: translation_key, value: translation_term) end end objects.flatten @@ -91,7 +91,7 @@ end context "with organization and space" do - let(:space) { create(:participatory_process, organization: organization) } + let(:space) { create(:participatory_process, organization:) } it "clears cache with correct key" do expect(Rails.cache).to receive(:delete_matched).with( @@ -103,7 +103,7 @@ end context "with organization, space and component" do - let(:space) { create(:participatory_process, organization: organization) } + let(:space) { create(:participatory_process, organization:) } let(:component) { create(:proposal_component, participatory_space: space) } it "clears cache with correct key" do @@ -148,7 +148,7 @@ end context "with organization and space" do - let(:space) { create(:participatory_process, organization: organization) } + let(:space) { create(:participatory_process, organization:) } it "clears cache with correct key" do expect(Rails.cache).to receive(:delete).with( @@ -163,7 +163,7 @@ end context "with organization, space and component" do - let(:space) { create(:participatory_process, organization: organization) } + let(:space) { create(:participatory_process, organization:) } let(:component) { create(:proposal_component, participatory_space: space) } it "clears cache with correct key" do @@ -215,7 +215,7 @@ end context "with organization and space" do - let(:space) { create(:participatory_process, organization: organization) } + let(:space) { create(:participatory_process, organization:) } it "clears cache with correct key" do expect(Rails.cache).to receive(:delete).with( @@ -230,7 +230,7 @@ end context "with organization, space and component" do - let(:space) { create(:participatory_process, organization: organization) } + let(:space) { create(:participatory_process, organization:) } let(:component) { create(:proposal_component, participatory_space: space) } it "clears cache with correct key" do diff --git a/spec/lib/decidim/term_customizer/plural_forms_manager_spec.rb b/spec/lib/decidim/term_customizer/plural_forms_manager_spec.rb index 06720ab..74ea43e 100644 --- a/spec/lib/decidim/term_customizer/plural_forms_manager_spec.rb +++ b/spec/lib/decidim/term_customizer/plural_forms_manager_spec.rb @@ -8,7 +8,7 @@ let(:locales) { [:en, :fi, :sv] } let(:plural_keys) { [:zero, :one, :few, :other] } let(:organization) { create(:organization, available_locales: locales) } - let(:translation_set) { create(:translation_set, organization: organization) } + let(:translation_set) { create(:translation_set, organization:) } before do I18n.available_locales = locales @@ -120,10 +120,10 @@ def create_translations(key, *locales) locales.map do |locale| create( :translation, - translation_set: translation_set, - key: key, + translation_set:, + key:, value: "Translation", - locale: locale + locale: ) end end diff --git a/spec/lib/decidim/term_customizer/resolver_spec.rb b/spec/lib/decidim/term_customizer/resolver_spec.rb index e6cdea2..c017644 100644 --- a/spec/lib/decidim/term_customizer/resolver_spec.rb +++ b/spec/lib/decidim/term_customizer/resolver_spec.rb @@ -9,7 +9,7 @@ let(:space) { nil } let(:component) { nil } let(:set) { create(:translation_set) } - let(:constraint) { set.constraints.create!(organization: organization) } + let(:constraint) { set.constraints.create!(organization:) } context "with organization" do let(:other_organization) { create(:organization) } @@ -33,19 +33,19 @@ end context "with participatory process" do - let(:space) { create(:participatory_process, organization: organization) } - let(:other_space) { create(:participatory_process, organization: organization) } + let(:space) { create(:participatory_process, organization:) } + let(:other_space) { create(:participatory_process, organization:) } let(:other_set) { create(:translation_set) } let(:constraint) do set.constraints.create!( - organization: organization, + organization:, subject: space ) end let!(:other_constraint) do other_set.constraints.create!( - organization: organization, + organization:, subject: other_space ) end @@ -68,13 +68,13 @@ context "when constraints are set for the subject type" do let(:constraint) do set.constraints.create!( - organization: organization, + organization:, subject_type: space.class.name ) end let!(:other_constraint) do other_set.constraints.create!( - organization: organization, + organization:, subject_type: other_space.class.name ) end @@ -97,21 +97,21 @@ end context "with component process" do - let(:space) { create(:participatory_process, organization: organization) } + let(:space) { create(:participatory_process, organization:) } let(:component) { create(:proposal_component, participatory_space: space) } - let(:other_space) { create(:participatory_process, organization: organization) } + let(:other_space) { create(:participatory_process, organization:) } let(:other_set) { create(:translation_set) } let(:other_component) { create(:proposal_component, participatory_space: other_space) } let(:constraint) do set.constraints.create!( - organization: organization, + organization:, subject: component ) end let!(:other_constraint) do other_set.constraints.create!( - organization: organization, + organization:, subject: other_component ) end diff --git a/spec/lib/decidim/term_customizer/translation_import_collection_spec.rb b/spec/lib/decidim/term_customizer/translation_import_collection_spec.rb index 5d77788..cb3e619 100644 --- a/spec/lib/decidim/term_customizer/translation_import_collection_spec.rb +++ b/spec/lib/decidim/term_customizer/translation_import_collection_spec.rb @@ -7,7 +7,7 @@ let(:translation_set) { create(:translation_set) } let(:records) do - build_list(:translation, 10, translation_set: translation_set) + build_list(:translation, 10, translation_set:) end let(:locales) { [:en] } @@ -54,7 +54,7 @@ locale: attr[:locale], key: attr[:key], value: attr[:value], - translation_set: translation_set + translation_set: ) end end diff --git a/spec/models/decidim/term_customizer/constraint_spec.rb b/spec/models/decidim/term_customizer/constraint_spec.rb index 6f1b0bb..60ba01a 100644 --- a/spec/models/decidim/term_customizer/constraint_spec.rb +++ b/spec/models/decidim/term_customizer/constraint_spec.rb @@ -8,7 +8,7 @@ module TermCustomizer subject { constraint } let(:organization) { create(:organization) } - let(:constraint) { build(:translation_set_constraint, organization: organization) } + let(:constraint) { build(:translation_set_constraint, organization:) } it { is_expected.to be_valid } diff --git a/spec/models/decidim/term_customizer/translation_set_spec.rb b/spec/models/decidim/term_customizer/translation_set_spec.rb index 0043687..37b052e 100644 --- a/spec/models/decidim/term_customizer/translation_set_spec.rb +++ b/spec/models/decidim/term_customizer/translation_set_spec.rb @@ -8,7 +8,7 @@ module TermCustomizer subject { translation_set } let(:organization) { create(:organization) } - let(:translation_set) { create(:translation_set, organization: organization) } + let(:translation_set) { create(:translation_set, organization:) } it { is_expected.to be_valid } diff --git a/spec/models/decidim/term_customizer/translation_spec.rb b/spec/models/decidim/term_customizer/translation_spec.rb index 9d44ede..3c92c30 100644 --- a/spec/models/decidim/term_customizer/translation_spec.rb +++ b/spec/models/decidim/term_customizer/translation_spec.rb @@ -8,14 +8,14 @@ module TermCustomizer subject { translation } let(:organization) { create(:organization) } - let(:translation_set) { create(:translation_set, organization: organization) } + let(:translation_set) { create(:translation_set, organization:) } let(:translation) do build( :translation, - translation_set: translation_set, - locale: locale, - key: key, - value: value + translation_set:, + locale:, + key:, + value: ) end let(:locale) { :en } @@ -31,7 +31,7 @@ module TermCustomizer context "when locale is empty" do let(:locale) { nil } - it { is_expected.to be_invalid } + it { is_expected.not_to be_valid } end it_behaves_like "translation validatable" diff --git a/spec/permissions/decidim/term_customizer/admin/permissions_spec.rb b/spec/permissions/decidim/term_customizer/admin/permissions_spec.rb index 15b596a..c6c0d9e 100644 --- a/spec/permissions/decidim/term_customizer/admin/permissions_spec.rb +++ b/spec/permissions/decidim/term_customizer/admin/permissions_spec.rb @@ -5,15 +5,15 @@ describe Decidim::TermCustomizer::Admin::Permissions do subject { described_class.new(user, permission_action, context).permissions.allowed? } - let(:user) { build :user, :admin, organization: organization } - let(:organization) { build :organization } + let(:user) { build(:user, :admin, organization:) } + let(:organization) { build(:organization) } let(:current_component) { create(:plan_component) } let(:translation_set) { nil } let(:translation) { nil } let(:context) do { - translation_set: translation_set, - translation: translation + translation_set:, + translation: } end let(:permission_action) { Decidim::PermissionAction.new(**action) } @@ -31,7 +31,7 @@ { scope: :admin, action: :read, subject: :translation_set } end - let(:translation_set) { create :translation_set, organization: organization } + let(:translation_set) { create(:translation_set, organization:) } it { is_expected.to be true } end @@ -41,7 +41,7 @@ { scope: :admin, action: :update, subject: :translation_set } end - let(:translation_set) { create :translation_set, organization: organization } + let(:translation_set) { create(:translation_set, organization:) } context "when everything is OK" do it { is_expected.to be true } @@ -53,7 +53,7 @@ { scope: :admin, action: :destroy, subject: :translation_set } end - let(:translation_set) { create :translation_set, organization: organization } + let(:translation_set) { create(:translation_set, organization:) } context "when everything is OK" do it { is_expected.to be true } @@ -65,7 +65,7 @@ { scope: :admin, action: :export, subject: :translation_set } end - let(:translation_set) { create :translation_set, organization: organization } + let(:translation_set) { create(:translation_set, organization:) } context "when everything is OK" do it { is_expected.to be true } @@ -85,8 +85,8 @@ { scope: :admin, action: :read, subject: :translation } end - let(:set) { create :translation_set, organization: organization } - let(:translation) { create :translation, translation_set: set } + let(:set) { create(:translation_set, organization:) } + let(:translation) { create(:translation, translation_set: set) } it { is_expected.to be true } end @@ -96,8 +96,8 @@ { scope: :admin, action: :update, subject: :translation } end - let(:set) { create :translation_set, organization: organization } - let(:translation) { create :translation, translation_set: set } + let(:set) { create(:translation_set, organization:) } + let(:translation) { create(:translation, translation_set: set) } context "when everything is OK" do it { is_expected.to be true } @@ -109,8 +109,8 @@ { scope: :admin, action: :destroy, subject: :translation } end - let(:set) { create :translation_set, organization: organization } - let(:translation) { create :translation, translation_set: set } + let(:set) { create(:translation_set, organization:) } + let(:translation) { create(:translation, translation_set: set) } context "when everything is OK" do it { is_expected.to be true } @@ -122,7 +122,7 @@ { scope: :admin, action: :import, subject: :translation_set } end - let(:translation_set) { create :translation_set, organization: organization } + let(:translation_set) { create(:translation_set, organization:) } context "when everything is OK" do it { is_expected.to be true } @@ -134,7 +134,7 @@ { scope: :admin, action: :destroy, subject: :translations } end - let(:translation_set) { create :translation_set, organization: organization } + let(:translation_set) { create(:translation_set, organization:) } context "when everything is OK" do it { is_expected.to be true } diff --git a/spec/queries/decidim/term_customizer/organization_translation_sets_spec.rb b/spec/queries/decidim/term_customizer/organization_translation_sets_spec.rb index 7f90f90..a64ca50 100644 --- a/spec/queries/decidim/term_customizer/organization_translation_sets_spec.rb +++ b/spec/queries/decidim/term_customizer/organization_translation_sets_spec.rb @@ -8,7 +8,7 @@ let(:organization) { create(:organization) } let(:other_organization) { create(:organization) } - let(:translation_set_list) { create_list(:translation_set, 10, organization: organization) } + let(:translation_set_list) { create_list(:translation_set, 10, organization:) } let(:other_translation_set_list) { create_list(:translation_set, 10, organization: other_organization) } it "returns translation sets included in an organization" do diff --git a/spec/queries/decidim/term_customizer/set_translations_spec.rb b/spec/queries/decidim/term_customizer/set_translations_spec.rb index 0f1cc9d..eb8184c 100644 --- a/spec/queries/decidim/term_customizer/set_translations_spec.rb +++ b/spec/queries/decidim/term_customizer/set_translations_spec.rb @@ -8,10 +8,10 @@ let(:organization) { create(:organization) } let(:other_organization) { create(:organization) } - let(:translation_set) { create(:translation_set, organization: organization) } + let(:translation_set) { create(:translation_set, organization:) } let(:other_translation_set) { create(:translation, organization: other_organization) } - let(:translations_list) { create_list(:translation, 10, translation_set: translation_set) } + let(:translations_list) { create_list(:translation, 10, translation_set:) } let(:other_translations_list) { create_list(:translation, 10, translation_set: other_translation_set) } it "returns translations included in a translation set" do @@ -22,10 +22,10 @@ subject { described_class.new(translation_set, locale) } let(:locale) { :en } - let(:translations_list) { create_list(:translation, 10, translation_set: translation_set, locale: locale) } + let(:translations_list) { create_list(:translation, 10, translation_set:, locale:) } before do - create_list(:translation, 10, translation_set: translation_set, locale: :fi) + create_list(:translation, 10, translation_set:, locale: :fi) end it "returns translations included in a translation set with the given locale" do diff --git a/spec/shared/translation_validator_examples.rb b/spec/shared/translation_validator_examples.rb index 8a9156a..0ff0434 100644 --- a/spec/shared/translation_validator_examples.rb +++ b/spec/shared/translation_validator_examples.rb @@ -36,44 +36,44 @@ context "when key is empty" do let(:key) { nil } - it { is_expected.to be_invalid } + it { is_expected.not_to be_valid } end context "when key is incorrect format" do context "with spaces" do let(:key) { "incorrect format key" } - it { is_expected.to be_invalid } + it { is_expected.not_to be_valid } end context "with uppercase characters" do let(:key) { "Translation.Key" } - it { is_expected.to be_invalid } + it { is_expected.not_to be_valid } end context "with blank character at the beginning" do let(:key) { " translation.key" } - it { is_expected.to be_invalid } + it { is_expected.not_to be_valid } end context "with blank character at the end" do let(:key) { "translation.key " } - it { is_expected.to be_invalid } + it { is_expected.not_to be_valid } end context "with a dot character at the beginning" do let(:key) { ".translation.key" } - it { is_expected.to be_invalid } + it { is_expected.not_to be_valid } end context "with a dot character at the end" do let(:key) { "translation.key." } - it { is_expected.to be_invalid } + it { is_expected.not_to be_valid } end context "with a long key repeating similar strings" do @@ -81,7 +81,7 @@ it "does not run exponentially long" do limit = 3.seconds.from_now - expect(subject).to be_invalid + expect(subject).not_to be_valid expect(Time.zone.now).to be < limit end end @@ -91,12 +91,12 @@ before do create( :translation, - translation_set: translation_set, - locale: locale, - key: key + translation_set:, + locale:, + key: ) end - it { is_expected.to be_invalid } + it { is_expected.not_to be_valid } end end