This repository was archived by the owner on Jun 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 137
Expand file tree
/
Copy pathpostal_address_spec.rb
More file actions
70 lines (56 loc) · 2.99 KB
/
Copy pathpostal_address_spec.rb
File metadata and controls
70 lines (56 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
require 'rails_helper'
RSpec.describe 'Add Postal Address', type: :feature do
let(:user) { create(:user) }
let(:address) { create(:postal_address) }
context 'signed in' do
before { sign_in user }
context 'in the user edit page' do
before { visit edit_user_path(user) }
it 'allows creation of postal address if all required address fields are entered' do
fill_in 'user[postal_address_attributes][address_line_1]', with: address.address_line_1
fill_in 'user[postal_address_attributes][address_line_2]', with: address.address_line_2
fill_in 'user[postal_address_attributes][city]', with: address.city
fill_in 'user[postal_address_attributes][state_or_province]', with: address.state_or_province
fill_in 'user[postal_address_attributes][postal_code]', with: address.postal_code
select address.country, from: 'user[postal_address_attributes][country]'
click_on 'Save'
expect(current_path).to eq user_path(user)
expect(page).to have_content address.address_line_1
expect(page).to have_content address.address_line_2
expect(page).to have_content address.city
expect(page).to have_content address.state_or_province
expect(page).to have_content address.postal_code
expect(page).to have_content user.postal_address.country
end
it 'does not allow a postal address to be added if required fields are missing' do
expect(user.postal_address).to be_nil
fill_in 'user[postal_address_attributes][address_line_1]', with: address.address_line_1
fill_in 'user[postal_address_attributes][postal_code]', with: address.postal_code
click_on 'Save'
expect(page).to have_content "Postal address city can't be blank"
expect(page).to have_content "Postal address country can't be blank"
end
it 'autofills saved postal address info on edit form if it exists' do
user.update(postal_address: create(:postal_address))
visit edit_user_path(user)
expect(page).to have_selector("input[value='#{user.postal_address.address_line_1}']")
expect(page).to have_selector("input[value='#{user.postal_address.city}']")
expect(page).to have_selector("input[value='#{user.postal_address.state_or_province}']")
expect(page).to have_selector("input[value='#{user.postal_address.postal_code}']")
end
it 'lets you delete an existing postal address' do
user.update(postal_address: address)
visit edit_user_path(user)
accept_alert do
click_on 'Remove Address'
end
expect(current_path).to eq user_path(user)
expect(page).to_not have_content address.address_line_1
expect(page).to_not have_content address.address_line_2
expect(page).to_not have_content address.city
expect(page).to_not have_content address.state_or_province
expect(page).to_not have_content address.postal_code
end
end
end
end