Skip to content

Commit c1dc367

Browse files
committed
fix election edit
1 parent 6a3e018 commit c1dc367

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

decidim-elections/app/forms/decidim/elections/admin/election_form.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class ElectionForm < Decidim::Form
2525
validates :title, translatable_presence: true
2626
validates :results_availability, inclusion: { in: Decidim::Elections::Election::RESULTS_AVAILABILITY_OPTIONS }
2727
validates :start_at, date: { before: :end_at }, unless: :manual_start?
28-
validates :start_at, date: { after: proc { Time.current } }, if: :scheduled_election?
28+
validates :start_at, date: { after: proc { Time.current } }, if: ->(f) { f.election&.scheduled? && f.start_at.present? }
2929
validates :manual_start, acceptance: true, if: :per_question_not_started?
3030
validates :end_at, presence: true
3131
validates :end_at, date: { after: :start_at }, if: ->(f) { f.start_at.present? && f.end_at.present? }

decidim-elections/spec/forms/decidim/elections/admin/election_form_spec.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,34 @@ module Decidim::Elections
194194
it { is_expected.to be_valid }
195195
end
196196

197+
context "when editing a published election configured for manual start" do
198+
let(:election) { create(:election, :published, component:, start_at: nil, end_at: 4.days.from_now) }
199+
let(:manual_start) { true }
200+
let(:start_at) { nil }
201+
202+
context "and end_at is valid (in the future)" do
203+
let(:end_at) { 2.days.from_now }
204+
205+
it { is_expected.to be_valid }
206+
207+
it "does not validate start_at when it is nil" do
208+
expect(subject.valid?).to be true
209+
expect(subject.errors[:start_at]).to be_empty
210+
end
211+
end
212+
213+
context "and end_at is set in the past" do
214+
let(:end_at) { 1.day.ago }
215+
216+
it { is_expected.not_to be_valid }
217+
218+
it "still validates end_at to prevent moving the election into a finished state" do
219+
subject.valid?
220+
expect(subject.errors[:end_at]).not_to be_empty
221+
end
222+
end
223+
end
224+
197225
context "when election is not published" do
198226
let(:election) { create(:election, component:, start_at: 3.days.from_now, end_at: 4.days.from_now) }
199227

0 commit comments

Comments
 (0)