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

Commit 020fc85

Browse files
committed
nest attributes postal address form prepopulates with saved info
1 parent f3d0205 commit 020fc85

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

app/views/users/edit.html.slim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
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-
= f.simple_fields_for :postal_address_attributes do |pa|
111+
= f.simple_fields_for :postal_address_attributes, @user.postal_address do |pa|
112112
= pa.input :address_line_1, required: false
113113
= pa.input :address_line_2, required: false
114114
= pa.input :city, required: false

spec/features/users/postal_address_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,26 @@
2828
expect(page).to have_content address.postal_code
2929
# expect(page).to have_content address.country
3030
end
31+
32+
it 'does not allow a postal address to be added if required fields are missing' do
33+
fill_in 'user[postal_address_attributes][address_line_1]', with: address.address_line_1
34+
fill_in 'user[postal_address_attributes][postal_code]', with: address.postal_code
35+
click_on 'Save'
36+
37+
expect(current_path).to eq edit_user_path(user)
38+
39+
expect(page).to have_content "If adding a shipping address, please include all required fields."
40+
end
41+
42+
it 'autofills saved postal address info on edit form if it exists' do
43+
user.update(postal_address: create(:postal_address))
44+
visit edit_user_path(user)
45+
46+
expect(page).to have_selector("input[value='#{user.postal_address.address_line_1}']")
47+
expect(page).to have_selector("input[value='#{user.postal_address.city}']")
48+
expect(page).to have_selector("input[value='#{user.postal_address.state_or_province}']")
49+
expect(page).to have_selector("input[value='#{user.postal_address.postal_code}']")
50+
end
3151
end
3252
end
3353
end

0 commit comments

Comments
 (0)