-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathedit_page_spec.rb
87 lines (65 loc) · 2.16 KB
/
edit_page_spec.rb
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
require "rails_helper"
describe "customer edit page" do
it "displays the customer's title attribute as the header" do
customer = create(:customer)
visit edit_admin_customer_path(customer)
expect(page).to have_header("Edit #{customer.name}")
end
it "has button to view customer details" do
customer = create(:customer)
visit edit_admin_customer_path(customer)
expect(page).to have_link("Show #{displayed(customer)}")
end
it "has forms for the customer's attributes" do
customer = create(:customer)
visit edit_admin_customer_path(customer)
expect(page).to have_text("Name")
expect(page).to have_text("Email")
end
it "displays boolean values as check boxes" do
customer = create(:customer, email_subscriber: false)
visit edit_admin_customer_path(customer)
check "Email subscriber"
click_on "Update Customer"
expect(page).to have_text("true")
end
it "displays selectable strings as dropdowns", :js do
customer = create(:customer, kind: :standard)
visit edit_admin_customer_path(customer)
select "vip", from: "Kind"
click_on "Update Customer"
expect(page).to have_text("KIND")
expect(page).to have_text("vip")
end
it "displays an error when the submitted form is invalid" do
customer = create(:customer)
visit edit_admin_customer_path(customer)
fill_in "Name", with: ""
click_on "Update Customer"
expect(page).to have_css(
"#error_explanation ul li.flash-error",
text: "Name can't be blank",
)
end
it "displays a success message for successful updates" do
new_name = "Hyper"
new_email = "example@example.com"
customer = create(:customer)
translations = {
activerecord: {
models: {
customer: "Custom name",
},
},
}
with_translations(:en, translations) do
visit edit_admin_customer_path(customer)
fill_in "Name", with: new_name
fill_in "Email", with: new_email
click_on "Update Custom name"
end
expect(page).to have_text(new_name)
expect(page).to have_text(new_email)
expect(page).to have_flash("Custom name was successfully updated.")
end
end