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

Commit dd200a3

Browse files
committed
adding postal address factory and happy path testing for adding shipping address
1 parent 08bb3d2 commit dd200a3

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

app/views/users/edit.html.slim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
= pa.input :address_line_2, required: false
114114
= pa.input :city, required: false
115115
= pa.input :state_or_province, required: false
116+
= pa.input :postal_code, required: false
116117
= pa.input :country, required: false
117118

118119

spec/factories/postal_address.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FactoryBot.define do
2+
factory :postal_address do
3+
user
4+
address_line_1 { FFaker::AddressUS.street_address }
5+
address_line_2 { FFaker::AddressUS.secondary_address }
6+
city { FFaker::AddressUS.city}
7+
state_or_province { FFaker::AddressUS.state}
8+
postal_code { FFaker::AddressUS.zip_code}
9+
country { FFaker::AddressUS.country}
10+
end
11+
end
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
require 'rails_helper'
2+
3+
RSpec.describe 'Add Postal Address', type: :feature do
4+
let(:user) { create(:user) }
5+
let(:address) { create(:postal_address) }
6+
7+
context 'signed in' do
8+
before { sign_in user }
9+
10+
context 'in the user edit page' do
11+
before { visit edit_user_path(user) }
12+
13+
it 'allows creation of postal address if all required address fields are entered' do
14+
fill_in 'user_postal_addresses_address_line_1', with: address.address_line_1
15+
fill_in 'user_postal_addresses_address_line_2', with: address.address_line_2
16+
fill_in 'user_postal_addresses_city', with: address.city
17+
fill_in 'user_postal_addresses_state_or_province', with: address.state_or_province
18+
fill_in 'user_postal_addresses_postal_code', with: address.postal_code
19+
select address.country, from: 'user_postal_addresses_country'
20+
click_on 'Save'
21+
22+
expect(current_path).to eq user_path(user)
23+
24+
expect(page).to have_content address.address_line_1
25+
expect(page).to have_content address.address_line_2
26+
expect(page).to have_content address.city
27+
expect(page).to have_content address.state_or_province
28+
expect(page).to have_content address.postal_code
29+
expect(page).to have_content address.country
30+
end
31+
end
32+
end
33+
end

0 commit comments

Comments
 (0)