Skip to content
Open
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
19 changes: 18 additions & 1 deletion app/services/event_registration_services/public_registration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,24 @@ def sync_person_profile(person)

def sync_organization_profile(organization)
apply_value(organization, :website_url, field_value("agency_website"))
apply_value(organization, :agency_type, field_value("agency_type"))
sync_agency_type(organization)
end

# The "Organization Type" answer folds an "Other" choice's free text in as
# "Other: <text>" (a specify option). Split the option label from the typed
# text: the label drives agency_type and the stripped text fills
# agency_type_other, which is cleared for the non-"Other" classifications so
# no stale free text lingers. Follows the same latest-wins / never-clobber-on-
# blank contract as apply_value.
def sync_agency_type(organization)

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: Folded into sync_organization_profile on rebase: partition(":") splits the option label from the "Other" free text (safe β€” no agency-type label contains a colon). agency_type_other is cleared for the non-"Other" classifications so no stale text lingers.

raw = field_value("agency_type")&.strip
return if raw.blank?

label, _separator, specified = raw.partition(":")
label = label.strip
return if label.blank?
other_text = FormField.other_option?(label) ? specified.strip.presence : nil
organization.update!(agency_type: label, agency_type_other: other_text)
Comment on lines +203 to +207
end

# Write value onto attribute when a non-blank value was submitted, overwriting
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 @@ -288,6 +288,59 @@ def register_with_org(extra)
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