diff --git a/app/forms/concerns/decidim/proposals/admin/proposal_form_override.rb b/app/forms/concerns/decidim/proposals/admin/proposal_form_override.rb new file mode 100644 index 0000000..7cb6864 --- /dev/null +++ b/app/forms/concerns/decidim/proposals/admin/proposal_form_override.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +module Decidim + module Proposals + module Admin + module ProposalFormOverride + extend ActiveSupport::Concern + + included do + translatable_attribute :title, String do |field, _locale| + validates field, length: { in: 15..250 }, if: proc { |resource| resource.send(field).present? } + end + end + end + end + end +end diff --git a/app/forms/concerns/decidim/proposals/proposal_wizard_create_step_form_override.rb b/app/forms/concerns/decidim/proposals/proposal_wizard_create_step_form_override.rb new file mode 100644 index 0000000..a9d4c74 --- /dev/null +++ b/app/forms/concerns/decidim/proposals/proposal_wizard_create_step_form_override.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module Decidim + module Proposals + module ProposalWizardCreateStepFormOverride + extend ActiveSupport::Concern + + included do + validates :title, length: { in: 15..250 } + end + end + end +end diff --git a/config/initializers/decidim_overrides.rb b/config/initializers/decidim_overrides.rb new file mode 100644 index 0000000..a012c62 --- /dev/null +++ b/config/initializers/decidim_overrides.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +Rails.application.config.to_prepare do + Decidim::Proposals::ProposalWizardCreateStepForm.include(Decidim::Proposals::ProposalWizardCreateStepFormOverride) + Decidim::Proposals::Admin::ProposalForm.include(Decidim::Proposals::Admin::ProposalFormOverride) +end diff --git a/config/initializers/extend_proposal_title_size.rb b/config/initializers/extend_proposal_title_size.rb deleted file mode 100644 index 1a74c13..0000000 --- a/config/initializers/extend_proposal_title_size.rb +++ /dev/null @@ -1,15 +0,0 @@ -# frozen_string_literal: true - -# extends the title size to 250 characters -Rails.application.configure do - config.after_initialize do - Decidim::Proposals::ProposalWizardCreateStepForm - .validators_on(:title).find { |v| v.is_a?(ActiveModel::Validations::LengthValidator) } - .instance_variable_set(:@options, { maximum: 250 }) - Decidim.available_locales.each do |locale| - Decidim::Proposals::Admin::ProposalForm - .validators_on("title_#{locale}".to_sym).find { |v| v.is_a?(ActiveModel::Validations::LengthValidator) } - .instance_variable_set(:@options, { maximum: 250 }) - end - end -end diff --git a/spec/lib/overrides_spec.rb b/spec/lib/overrides_spec.rb index ca4030e..1616344 100644 --- a/spec/lib/overrides_spec.rb +++ b/spec/lib/overrides_spec.rb @@ -6,6 +6,13 @@ # as the expected. If this test fails, it means that the overriden # file should be updated to match any change/bug fix introduced in the core checksums = [ + { + package: "decidim-proposals", + files: { + "/app/forms/decidim/proposals/proposal_wizard_create_step_form.rb" => "b495d37088ecebcbe4ac9563bb3498d5", + "/app/forms/decidim/proposals/admin/proposal_form.rb" => "fc671fc489c75bb3c190b1da09689c67" + } + }, { package: "decidim-direct_verifications", files: {