Skip to content
Draft
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
16 changes: 16 additions & 0 deletions app/services/event_registration_services/public_registration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def call
organization = find_organization if field_value(ORGANIZATION_NAME_IDENTIFIER).present?
create_affiliation(person, organization) if organization
create_agency_address(organization) if organization && field_value("agency_city").present?
update_agency_type(organization) if organization && field_value("agency_type").present?

assign_tags(person, organization)

Expand Down Expand Up @@ -272,6 +273,21 @@ def create_agency_address(organization)
)
end

# Mirror the registrant's "Organization Type" answer onto the linked
# organization. The "Other" choice is a specify option, so its free text
# folds into the answer as "Other: <text>" β€” split the option label from the
# typed text, store the label on agency_type and the stripped text on
# agency_type_other (cleared for non-"Other" choices). Latest registration
# wins; AhoyTrackable records the before/after on the update.
def update_agency_type(organization)
raw = field_value("agency_type").to_s.strip
label, _separator, specified = raw.partition(":")

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ€– From Claude: partition(":") is safe here because none of the agency-type option labels contain a colon, so the split always yields the option label and (for "Other") the typed free text. agency_type_other is cleared for non-"Other" choices to avoid leaving stale text behind.

label = label.strip
other_text = FormField.other_option?(label) ? specified.strip.presence : nil

organization.update!(agency_type: label, agency_type_other: other_text)
end

def assign_tags(person, organization)
primary_sector_ids = collect_sector_ids(FormField::PRIMARY_SECTOR_FIELD_IDENTIFIERS)
additional_sector_ids = collect_sector_ids(FormField::ADDITIONAL_SECTOR_FIELD_IDENTIFIERS)
Expand Down
3 changes: 1 addition & 2 deletions app/services/form_builder_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,7 @@ def build_person_contact_info_fields(form, position)
position = add_field(form, position, "Organization Type", :single_select_radio,
key: "agency_type", group: "person_contact_info", required: false,
options: [
"501c3/nonprofit", "For-profit", "Government agency",
"Other (please specify below)"
"501c3/nonprofit", "For-profit", "Government agency", "Other"
])
position = add_field(form, position, "Organization Street Address", :free_form_input_one_line,
key: "agency_street", group: "person_contact_info", required: false)
Expand Down
2 changes: 1 addition & 1 deletion app/views/organizations/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
"501c3/nonprofit",
"For-profit",
"Government agency",
"Other (please specify below)"
"Other"
],
selected: f.object.agency_type,
input_html: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,59 @@ def register_with(position:)
end
end

describe "organization type sync" do
let!(:organization) { create(:organization, name: "Helping Hands") }

def register_with_agency_type(value)
params = base_form_params(first_name: "Sam", last_name: "Rowe", email: "sam@example.com").merge(
field_id(described_class::ORGANIZATION_NAME_IDENTIFIER) => "Helping Hands",
field_id("agency_type") => value
)
described_class.call(event: event, form: form, form_params: params)
organization.reload
end

it "folds an 'Other' answer into agency_type and the stripped free text into agency_type_other" do
register_with_agency_type("Other: Equine therapy")

expect(organization.agency_type).to eq("Other")
expect(organization.agency_type_other).to eq("Equine therapy")
end

it "stores the answer as 'Other: <text>' on the form submission, like other specify options" do
register_with_agency_type("Other: Equine therapy")

answer = FormAnswer.joins(:form_field)
.find_by(form_fields: { field_identifier: "agency_type" })
expect(answer.submitted_answer).to eq("Other: Equine therapy")
end

it "stores a non-'Other' classification with no agency_type_other" do
register_with_agency_type("501c3/nonprofit")

expect(organization.agency_type).to eq("501c3/nonprofit")
expect(organization.agency_type_other).to be_nil
end

it "overwrites a previously stored type with the latest registrant's answer" do
organization.update!(agency_type: "501c3/nonprofit", agency_type_other: nil)

register_with_agency_type("Other: Equine therapy")

expect(organization.agency_type).to eq("Other")
expect(organization.agency_type_other).to eq("Equine therapy")
end

it "clears a stale agency_type_other when the latest answer is no longer 'Other'" do
organization.update!(agency_type: "Other", agency_type_other: "Equine therapy")

register_with_agency_type("Government agency")

expect(organization.agency_type).to eq("Government agency")
expect(organization.agency_type_other).to be_nil
end
end

describe "matching an existing registrant by name" do
it "matches a person stored under a nickname when the registrant types their legal first name" do
existing = create(:person, first_name: "Bob", legal_first_name: "Robert",
Expand Down
7 changes: 6 additions & 1 deletion spec/services/form_builder_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,14 @@
it "offers the agency type as the four organization classifications" do
field = form.form_fields.find_by(field_identifier: "agency_type")
expect(field.answer_options.pluck(:name)).to contain_exactly(
"501c3/nonprofit", "For-profit", "Government agency", "Other (please specify below)"
"501c3/nonprofit", "For-profit", "Government agency", "Other"
)
end

it "treats the agency type 'Other' as a specify option that reveals a free-text box" do
field = form.form_fields.find_by(field_identifier: "agency_type")
expect(field.specify_option_labels).to contain_exactly("Other")
end
end

context "scholarship section" do
Expand Down