Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Delete blank contacts" #9093

Closed
wants to merge 1 commit into from
Closed
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
13 changes: 2 additions & 11 deletions app/controllers/admin/worldwide_offices_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,8 @@ def edit
end

def update
update_params = worldwide_office_params

update_params[:service_ids] ||= []

if update_params.dig(:contact_attributes, :contact_numbers_attributes)
update_params.dig(:contact_attributes, :contact_numbers_attributes).each do |_id, contact_number_attribute|
contact_number_attribute[:_destroy] = true if contact_number_attribute[:label].empty? && contact_number_attribute[:number].empty?
end
end

if @worldwide_office.update(update_params)
worldwide_office_params[:service_ids] ||= []
if @worldwide_office.update(worldwide_office_params)
handle_show_on_home_page_param
republish_draft_worldwide_organisation
redirect_to admin_worldwide_organisation_worldwide_offices_path(@worldwide_organisation), notice: "#{@worldwide_office.title} has been edited"
Expand Down
28 changes: 1 addition & 27 deletions test/functional/admin/worldwide_offices_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ class Admin::WorldwideOfficesControllerTest < ActionController::TestCase
assert_equal ["Main phone: 5678"], actual_numbers
end

test "PUT :update deletes contact numbers that are marked as to be destroyed" do
test "PUT :update deletes contact numbers that have only blank fields" do
worldwide_organisation, office = create_worldwide_organisation_and_office
contact_number = office.contact.contact_numbers.create!(label: "Phone", number: "1234")

Expand All @@ -306,32 +306,6 @@ class Admin::WorldwideOfficesControllerTest < ActionController::TestCase
assert_not ContactNumber.exists?(contact_number.id)
end

test "PUT :update deletes contact numbers that have only blank fields" do
worldwide_organisation, office = create_worldwide_organisation_and_office
contact_number = office.contact.contact_numbers.create!(label: "Phone", number: "1234")

put :update,
params: {
worldwide_office: {
contact_attributes: {
id: office.contact.id,
title: "Head office",
contact_numbers_attributes: {
"0" => {
id: contact_number.id,
label: "",
number: "",
},
},
},
},
id: office,
worldwide_organisation_id: worldwide_organisation,
}

assert_not ContactNumber.exists?(contact_number.id)
end

test "POST on :reorder_for_home_page takes id => ordering mappings and reorders the list based on this" do
worldwide_organisation, office1 = create_worldwide_organisation_and_office
office2 = worldwide_organisation.offices.create!(
Expand Down