Skip to content

Commit abd066d

Browse files
maebealeclaude
andcommitted
Scope transfer destinations to the source event's kind
A facilitator training only transfers to another facilitator training, and a non-training only to another non-training, so the destination picker matches the source event's facilitator_training flag. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 8abc9a7 commit abd066d

3 files changed

Lines changed: 25 additions & 6 deletions

File tree

‎app/controllers/event_registrations_controller.rb‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,10 +358,12 @@ def set_event_registration
358358
@event_registration = EventRegistration.includes({ registrant: [ :user, { affiliations: :organization } ] }, { event: [ :location, :event_forms ] }, :organizations, comments: [ :created_by, :updated_by ]).find(params[:id])
359359
end
360360

361-
# Events a registrant can be transferred into: any published event other than
362-
# the one they're transferring out of, most recent first.
361+
# Events a registrant can be transferred into: published events of the same
362+
# kind as the one they're leaving — a facilitator training only transfers to
363+
# another facilitator training, and a non-training only to another
364+
# non-training — excluding the source event, most recent first.
363365
def transfer_destination_events
364-
Event.where(published: true)
366+
Event.where(published: true, facilitator_training: @event_registration.event.facilitator_training)
365367
.where.not(id: @event_registration.event_id)
366368
.order(start_date: :desc)
367369
end

‎app/views/event_registrations/transfer.html.erb‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@
4444
include_blank: "Select an event…",
4545
required: true,
4646
class: "w-full rounded-lg border border-gray-300 px-3 py-2 text-sm text-gray-700 shadow-sm focus:border-blue-500 focus:ring focus:ring-blue-200 focus:outline-none" %>
47+
<p class="mt-1.5 text-xs text-gray-500">
48+
Only <%= source.event.facilitator_training? ? "other facilitator trainings" : "other (non-training) events" %> are shown.
49+
</p>
4750
</div>
4851

4952
<div class="flex items-center gap-3 border-t border-gray-200 pt-4">

‎spec/requests/event_registrations_spec.rb‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -396,15 +396,29 @@ def toggle_day(field, value)
396396
let!(:source) { create(:event_registration, event: event, status: "transferred_out") }
397397

398398
describe "GET /event_registrations/:id/transfer" do
399-
it "renders the destination picker, excluding the source event" do
400-
other = create(:event, title: "Destination Event", published: true)
399+
it "offers same-kind events, excluding the source and the other kind" do
400+
same_kind = create(:event, title: "Destination Event", published: true, facilitator_training: false)
401+
other_kind = create(:event, title: "A Facilitator Training", published: true, facilitator_training: true)
401402

402403
get transfer_event_registration_path(source)
403404

404405
expect(response).to have_http_status(:success)
405406
expect(response.body).to include("Destination Event")
406-
# The source event isn't offered as a transfer destination.
407+
# The source event and the opposite kind aren't offered as destinations.
407408
expect(response.body).not_to include("<option value=\"#{event.id}\"")
409+
expect(response.body).not_to include("<option value=\"#{other_kind.id}\"")
410+
end
411+
412+
it "offers only other facilitator trainings when transferring out of one" do
413+
training = create(:event, title: "Source Training", facilitator_training: true)
414+
training_source = create(:event_registration, event: training, status: "transferred_out")
415+
another_training = create(:event, title: "Another Training", published: true, facilitator_training: true)
416+
non_training = create(:event, title: "A Non-Training Event", published: true, facilitator_training: false)
417+
418+
get transfer_event_registration_path(training_source)
419+
420+
expect(response.body).to include("<option value=\"#{another_training.id}\"")
421+
expect(response.body).not_to include("<option value=\"#{non_training.id}\"")
408422
end
409423
end
410424

0 commit comments

Comments
 (0)