Skip to content

Commit

Permalink
Use monkey patching to override proposal title size
Browse files Browse the repository at this point in the history
  • Loading branch information
fblupi committed Jun 12, 2024
1 parent f8f4f02 commit 6f661c3
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions config/initializers/decidim_overrides.rb
Original file line number Diff line number Diff line change
@@ -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
15 changes: 0 additions & 15 deletions config/initializers/extend_proposal_title_size.rb

This file was deleted.

7 changes: 7 additions & 0 deletions spec/lib/overrides_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit 6f661c3

Please sign in to comment.