Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion app/models/signup_round.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ class SignupRound < ApplicationRecord
scope :reverse_chronological, -> { order("start DESC NULLS LAST") }

def self.execute_currently_due_rounds!
currently_due.chronological.includes(:convention).find_each(&:execute!)
# can't use find_each with ordered scopes so we'll roll our own
round_ids = currently_due.chronological.pluck(:id)
round_ids.in_groups_of(100) do |batch|
rounds = SignupRound.where(id: batch).includes(:convention)
rounds.sort_by { |round| batch.index(round.id) }.each(&:execute!)
end
end

def execute!
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class EnforceRankedChoiceOrderForRankedChoiceSignupRounds < ActiveRecord::Migration[8.0]
def change
reversible { |dir| dir.up { execute <<~SQL } }
UPDATE signup_rounds
SET ranked_choice_order = 'asc'
WHERE automation_action = 'execute_ranked_choice' AND ranked_choice_order IS NULL
SQL

add_check_constraint :signup_rounds,
"automation_action != 'execute_ranked_choice' OR ranked_choice_order IS NOT NULL",
name: "require_order_for_ranked_choice_rounds"
end
end
4 changes: 3 additions & 1 deletion db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2665,7 +2665,8 @@ CREATE TABLE public.signup_rounds (
ranked_choice_order text,
executed_at timestamp without time zone,
automation_action text,
CONSTRAINT chk_rails_4c92d587c4 CHECK (((maximum_event_signups = ANY (ARRAY['not_yet'::text, 'not_now'::text, 'unlimited'::text])) OR ((maximum_event_signups)::integer >= 1)))
CONSTRAINT chk_rails_4c92d587c4 CHECK (((maximum_event_signups = ANY (ARRAY['not_yet'::text, 'not_now'::text, 'unlimited'::text])) OR ((maximum_event_signups)::integer >= 1))),
CONSTRAINT require_order_for_ranked_choice_rounds CHECK (((automation_action <> 'execute_ranked_choice'::text) OR (ranked_choice_order IS NOT NULL)))
);


Expand Down Expand Up @@ -6134,6 +6135,7 @@ ALTER TABLE ONLY public.cms_files_pages
SET search_path TO "$user", public;

INSERT INTO "schema_migrations" (version) VALUES
('20251109200750'),
('20251001173716'),
('20250906190727'),
('20250324175507'),
Expand Down
8 changes: 7 additions & 1 deletion test/models/signup_round_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@ class SignupRoundTest < ActiveSupport::TestCase
mock_service = Minitest::Mock.new
mock_service.expect :call!, nil
convention = FactoryBot.create(:convention, signup_automation_mode: "ranked_choice")
signup_round = FactoryBot.create(:signup_round, convention:, automation_action: "execute_ranked_choice")
signup_round =
FactoryBot.create(
:signup_round,
convention:,
automation_action: "execute_ranked_choice",
ranked_choice_order: "asc"
)

ExecuteRankedChoiceSignupRoundService.stub :new, mock_service do
signup_round.execute!
Expand Down
Loading