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

Commit e57bc9c

Browse files
committed
user sees error if partially completing postal address field
1 parent 30eb3b3 commit e57bc9c

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

app/models/user.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def student
7474
validates :name, :email, :country, :location, presence: true, unless: :github_import
7575

7676
accepts_nested_attributes_for :roles, allow_destroy: true
77-
accepts_nested_attributes_for :postal_address, allow_destroy: true, reject_if: :postal_address_rejectable?
77+
accepts_nested_attributes_for :postal_address, allow_destroy: true, reject_if: :all_blank
7878

7979
def postal_address_rejectable?(attr)
8080
attr['address_line_1'].blank? || attr['city'].blank? || attr['postal_code'].blank? || attr['country'].blank?

app/views/users/edit.html.slim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
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
111111
- 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?' }
112+
= link_to "Remove Address", user_path(@user, user: { postal_address_attributes: { id: @user.postal_address.id, "_destroy" => true }}), method: :put, data: { confirm: 'Are you sure?' }
113113
= f.simple_fields_for :postal_address_attributes, @user.postal_address do |pa|
114114
= pa.input :address_line_1, required: false
115115
= pa.input :address_line_2, required: false

spec/features/users/postal_address_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@
3030
end
3131

3232
it 'does not allow a postal address to be added if required fields are missing' do
33+
expect(user.postal_address).to be_nil
3334
fill_in 'user[postal_address_attributes][address_line_1]', with: address.address_line_1
3435
fill_in 'user[postal_address_attributes][postal_code]', with: address.postal_code
3536
click_on 'Save'
3637

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."
38+
expect(page).to have_content "Postal address city can't be blank"
39+
expect(page).to have_content "Postal address country can't be blank"
4040
end
4141

4242
it 'autofills saved postal address info on edit form if it exists' do

0 commit comments

Comments
 (0)