Skip to content
This repository was archived by the owner on Jun 27, 2023. It is now read-only.

Commit 30eb3b3

Browse files
committed
user can delete a postal address
1 parent 020fc85 commit 30eb3b3

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

app/controllers/users_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def user_params
108108
:application_location, :application_minimum_money, :application_money, :application_goals, :application_code_background,
109109
interested_in: [],
110110
roles_attributes: [:id, :name, :team_id, :_destroy],
111-
postal_address_attributes: [:id, :address_line_1, :address_line_2, :city, :state_or_province, :postal_code, :country]
111+
postal_address_attributes: [:id, :address_line_1, :address_line_2, :city, :state_or_province, :postal_code, :country, :_destroy]
112112
)
113113
end
114114
end

app/views/users/edit.html.slim

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,15 @@
108108
= f.input :tshirt_size, as: :select, collection: User::TSHIRT_SIZES.map { |k| [k, k] }, label: 'T-Shirt size', blank: false, required: false, hint: 'For sponsor T-Shirts, in case they send some.'
109109
= f.input :tshirt_cut, as: :select, collection: User::TSHIRT_CUTS.map { |s| [s, s] }, label: 'T-Shirt cut', include_blank: true
110110
h4 Shipping Address
111+
- if @user.postal_address
112+
= link_to "Remove Address", user_path(@user, user: { postal_address_attributes: { id: @user.postal_address.id, "_destroy" => true }}), method: :put, data: { confirm: 'You sure?' }
111113
= f.simple_fields_for :postal_address_attributes, @user.postal_address do |pa|
112114
= pa.input :address_line_1, required: false
113115
= pa.input :address_line_2, required: false
114116
= pa.input :city, required: false
115117
= pa.input :state_or_province, required: false
116118
= pa.input :postal_code, required: false
117-
= pa.input :country, as: :country, label: "Country", prompt: "Select your country", required: false
119+
= pa.input :country, prompt: "Select your country", required: false, include_blank: true
118120

119121

120122
- if admin?

spec/features/users/postal_address_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,23 @@
4848
expect(page).to have_selector("input[value='#{user.postal_address.state_or_province}']")
4949
expect(page).to have_selector("input[value='#{user.postal_address.postal_code}']")
5050
end
51+
52+
it 'lets you delete an existing postal address' do
53+
user.update(postal_address: address)
54+
visit edit_user_path(user)
55+
56+
accept_alert do
57+
click_on 'Remove Address'
58+
end
59+
60+
expect(current_path).to eq user_path(user)
61+
62+
expect(page).to_not have_content address.address_line_1
63+
expect(page).to_not have_content address.address_line_2
64+
expect(page).to_not have_content address.city
65+
expect(page).to_not have_content address.state_or_province
66+
expect(page).to_not have_content address.postal_code
67+
end
5168
end
5269
end
5370
end

0 commit comments

Comments
 (0)