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

Commit 89c8a4c

Browse files
committed
formatting address on user profile page
1 parent e57bc9c commit 89c8a4c

3 files changed

Lines changed: 10 additions & 3 deletions

File tree

app/models/postal_address.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1+
# frozen_string_literal: true
12
class PostalAddress < ApplicationRecord
23
belongs_to :user
34
validates_presence_of :address_line_1, :city, :postal_code, :country
45

56
def formatted
6-
"#{address_line_1.split.map(&:capitalize).join(' ')} #{address_line_2} #{city}, #{state_or_province} #{postal_code} #{country}"
7+
"#{capitalize(address_line_1)} #{capitalize(address_line_2)} #{capitalize(city)}, #{state_or_province} #{postal_code} #{country}"
8+
end
9+
10+
private
11+
12+
def capitalize(string)
13+
string.split.map(&:capitalize).join(' ')
714
end
815
end

spec/factories/postal_address.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
city { FFaker::AddressUS.city}
77
state_or_province { FFaker::AddressUS.state}
88
postal_code { FFaker::AddressUS.zip_code}
9-
country "Barbados"
9+
country { FFaker::Address.country }
1010
end
1111
end

spec/features/users/postal_address_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
expect(page).to have_content address.city
2727
expect(page).to have_content address.state_or_province
2828
expect(page).to have_content address.postal_code
29-
# expect(page).to have_content address.country
29+
expect(page).to have_content user.postal_address.country
3030
end
3131

3232
it 'does not allow a postal address to be added if required fields are missing' do

0 commit comments

Comments
 (0)