/
contact_us_lint_spec.rb
144 lines (120 loc) · 4.02 KB
/
contact_us_lint_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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
require 'spec_helper'
describe 'Contact Us page' do
after do
ActionMailer::Base.deliveries = []
ContactUs.mailer_from = nil
ContactUs.mailer_to = nil
ContactUs.require_name = false
ContactUs.require_subject = false
end
before do
ActionMailer::Base.deliveries = []
ContactUs.mailer_to = 'test@test.com'
end
it 'displays default contact form properly' do
visit contact_us_path
within "form#new_contact_us_contact" do
page.should have_selector "input#contact_us_contact_email"
page.should have_selector "textarea#contact_us_contact_message"
page.should_not have_selector "input#contact_us_contact_name"
page.should_not have_selector "input#contact_us_contact_subject"
page.should have_selector "input.submit"
end
end
context "Submitting the form" do
before do
visit contact_us_path
end
context "when valid" do
before do
fill_in 'Email', :with => 'test@example.com'
fill_in 'Message', :with => 'howdy'
click_button 'Submit'
end
it "I should be redirected to the homepage" do
current_path.should == "/"
end
it "An email should have been sent" do
ActionMailer::Base.deliveries.size.should == 1
end
it "The email should have the correct attributes" do
mail = ActionMailer::Base.deliveries.last
mail.to.should == ['test@test.com']
mail.from.should == ['test@example.com']
mail.body.should match 'howdy'
end
end
context "when invalid" do
context "Email and message are invalid" do
before do
fill_in 'Email', :with => 'a'
fill_in 'Message', :with => ''
click_button 'Submit'
end
it "I should see two error messages" do
within '#contact_us_contact_email_input' do
page.should have_content "is invalid"
end
within '#contact_us_contact_message_input' do
page.should have_content "can't be blank"
end
end
it "An email should not have been sent" do
ActionMailer::Base.deliveries.size.should == 0
end
end
end
end
context 'with name and subject configuration' do
before do
ContactUs.require_name = true
ContactUs.require_subject = true
visit contact_us_path
end
it "displays an input for name and subject" do
page.should have_selector "input#contact_us_contact_name"
page.should have_selector "input#contact_us_contact_subject"
end
context "Submitting the form" do
context "when valid" do
before do
fill_in 'Email', :with => 'test@example.com'
fill_in 'Message', :with => 'howdy'
fill_in 'contact_us_contact[name]', :with => 'Jeff'
fill_in 'contact_us_contact[subject]', :with => 'Testing contact form.'
click_button 'Submit'
end
it "I should be redirected to the homepage" do
current_path.should == "/"
end
it "An email should have been sent" do
ActionMailer::Base.deliveries.size.should == 1
end
it "The email should have the correct attributes" do
mail = ActionMailer::Base.deliveries.last
mail.body.should match 'howdy'
mail.body.should match 'Jeff'
mail.from.should == ['test@example.com']
mail.subject.should match 'Testing contact form.'
mail.to.should == ['test@test.com']
end
end
context "when name and subject are blank" do
before do
click_button 'Submit'
end
it "I should see error messages" do
within '#contact_us_contact_name_input' do
page.should have_content "can't be blank"
end
within '#contact_us_contact_subject_input' do
page.should have_content "can't be blank"
end
end
it "An email should not have been sent" do
ActionMailer::Base.deliveries.size.should == 0
end
end
end
end
end