Skip to content

Commit

Permalink
Fix bugs with saved addresses (#122)
Browse files Browse the repository at this point in the history
There were two issues leftover from the address refactoring:

- The company address select dropdown was trying to prefill with the contact address
- If we called saved_address.uprn and there was no saved_address, we got an error

This commit fixes those.
  • Loading branch information
irisfaraway committed Apr 12, 2018
1 parent 2ea1cef commit 94d5ed7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions app/forms/address_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,17 @@ def look_up_addresses

# If an address has already been assigned to the transient registration, pre-select it
def preselect_existing_address
return unless @transient_registration.addresses.present?
return unless saved_address.uprn.present?
return unless can_preselect_address?
selected_address = temp_addresses.detect { |address| address["uprn"] == saved_address.uprn.to_s }
self.temp_address = selected_address["uprn"] if selected_address.present?
end

def can_preselect_address?
return false unless saved_address
return false unless saved_address.uprn.present?
true
end

def add_or_replace_address(selected_address_uprn)
return if selected_address_uprn.blank?

Expand Down
2 changes: 1 addition & 1 deletion app/forms/company_address_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def temp_postcode
end

def saved_address
@transient_registration.contact_address
@transient_registration.registered_address
end

def address_type
Expand Down

0 comments on commit 94d5ed7

Please sign in to comment.