contact_us 0.1.5 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,32 +2,38 @@ require 'spec_helper'
2
2
 
3
3
  describe 'Contact Us page' do
4
4
 
5
- before do
6
- visit contact_us_path
7
- end
8
-
9
- it 'displays contact form' do
10
- page.should have_selector "form#new_contact_us_contact"
11
- end
12
-
13
- it "displays an input for email" do
14
- page.should have_selector "input#contact_us_contact_email"
5
+ after do
6
+ ActionMailer::Base.deliveries = []
7
+ ContactUs.mailer_from = nil
8
+ ContactUs.mailer_to = nil
9
+ ContactUs.require_name = false
10
+ ContactUs.require_subject = false
15
11
  end
16
12
 
17
- it "displays a textarea for message" do
18
- page.should have_selector "textarea#contact_us_contact_message"
13
+ before do
14
+ ActionMailer::Base.deliveries = []
15
+ ContactUs.mailer_to = 'test@test.com'
19
16
  end
20
17
 
21
- it "displays a submit button" do
22
- page.should have_selector "input#contact_us_contact_submit"
18
+ it 'displays default contact form properly' do
19
+ visit contact_us_path
20
+ within "form#new_contact_us_contact" do
21
+ page.should have_selector "input#contact_us_contact_email"
22
+ page.should have_selector "textarea#contact_us_contact_message"
23
+ page.should_not have_selector "input#contact_us_contact_name"
24
+ page.should_not have_selector "input#contact_us_contact_subject"
25
+ page.should have_selector "input#contact_us_contact_submit"
26
+ end
23
27
  end
24
28
 
25
29
  context "Submitting the form" do
26
- after { ActionMailer::Base.deliveries = [] }
30
+
31
+ before do
32
+ visit contact_us_path
33
+ end
27
34
 
28
35
  context "when valid" do
29
36
  before do
30
- ContactUs.mailer_to = 'test@test.com'
31
37
  fill_in 'Email', :with => 'test@example.com'
32
38
  fill_in 'Message', :with => 'howdy'
33
39
  click_button 'Submit'
@@ -58,8 +64,12 @@ describe 'Contact Us page' do
58
64
  end
59
65
 
60
66
  it "I should see two error messages" do
61
- page.should have_content "is invalid"
62
- page.should have_content "can't be blank"
67
+ within '#contact_us_contact_email_input' do
68
+ page.should have_content "is invalid"
69
+ end
70
+ within '#contact_us_contact_message_input' do
71
+ page.should have_content "can't be blank"
72
+ end
63
73
  end
64
74
 
65
75
  it "An email should not have been sent" do
@@ -68,4 +78,67 @@ describe 'Contact Us page' do
68
78
  end
69
79
  end
70
80
  end
81
+
82
+ context 'with name and subject configuration' do
83
+
84
+ before do
85
+ ContactUs.require_name = true
86
+ ContactUs.require_subject = true
87
+ visit contact_us_path
88
+ end
89
+
90
+ it "displays an input for name and subject" do
91
+ page.should have_selector "input#contact_us_contact_name"
92
+ page.should have_selector "input#contact_us_contact_subject"
93
+ end
94
+
95
+ context "Submitting the form" do
96
+ context "when valid" do
97
+ before do
98
+ fill_in 'Email', :with => 'test@example.com'
99
+ fill_in 'Message', :with => 'howdy'
100
+ fill_in 'contact_us_contact[name]', :with => 'Jeff'
101
+ fill_in 'contact_us_contact[subject]', :with => 'Testing contact form.'
102
+ click_button 'Submit'
103
+ end
104
+
105
+ it "I should be redirected to the homepage" do
106
+ current_path.should == "/"
107
+ end
108
+
109
+ it "An email should have been sent" do
110
+ ActionMailer::Base.deliveries.size.should == 1
111
+ end
112
+
113
+ it "The email should have the correct attributes" do
114
+ mail = ActionMailer::Base.deliveries.last
115
+ mail.body.should match 'howdy'
116
+ mail.body.should match 'Jeff'
117
+ mail.from.should == ['test@example.com']
118
+ mail.subject.should match 'Testing contact form.'
119
+ mail.to.should == ['test@test.com']
120
+ end
121
+ end
122
+
123
+ context "when name and subject are blank" do
124
+ before do
125
+ click_button 'Submit'
126
+ end
127
+
128
+ it "I should see error messages" do
129
+ within '#contact_us_contact_name_input' do
130
+ page.should have_content "can't be blank"
131
+ end
132
+ within '#contact_us_contact_subject_input' do
133
+ page.should have_content "can't be blank"
134
+ end
135
+ end
136
+
137
+ it "An email should not have been sent" do
138
+ ActionMailer::Base.deliveries.size.should == 0
139
+ end
140
+ end
141
+ end
142
+ end
143
+
71
144
  end
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+
3
+ describe ContactUs do
4
+
5
+ after do
6
+ ContactUs.mailer_from = nil
7
+ ContactUs.mailer_to = nil
8
+ ContactUs.require_name = false
9
+ ContactUs.require_subject = false
10
+ end
11
+
12
+ it "should be valid" do
13
+ ContactUs.should be_a(Module)
14
+ end
15
+
16
+ describe 'setup block' do
17
+ it 'should yield self' do
18
+ ContactUs.setup do |config|
19
+ ContactUs.should eql(config)
20
+ end
21
+ end
22
+ end
23
+
24
+ describe 'mailer_from' do
25
+ it 'should be configurable' do
26
+ ContactUs.mailer_from = "contact@please-change-me.com"
27
+ ContactUs.mailer_from.should eql("contact@please-change-me.com")
28
+ end
29
+ end
30
+
31
+ describe 'mailer_to' do
32
+ it 'should be configurable' do
33
+ ContactUs.mailer_to = "contact@please-change-me.com"
34
+ ContactUs.mailer_to.should eql("contact@please-change-me.com")
35
+ end
36
+ end
37
+
38
+ describe 'require_name' do
39
+ it 'should be configurable' do
40
+ ContactUs.require_name = true
41
+ ContactUs.require_name.should eql(true)
42
+ end
43
+ end
44
+
45
+ describe 'require_subject' do
46
+ it 'should be configurable' do
47
+ ContactUs.require_subject = true
48
+ ContactUs.require_subject.should eql(true)
49
+ end
50
+ end
51
+
52
+ end
@@ -4,7 +4,7 @@ describe ContactUs::ContactMailer do
4
4
 
5
5
  describe "#contact_email" do
6
6
 
7
- before(:each) do
7
+ before do
8
8
  ContactUs.mailer_to = "contact@please-change-me.com"
9
9
  @contact = ContactUs::Contact.new(:email => 'test@email.com', :message => 'Thanks!')
10
10
  end
@@ -13,9 +13,16 @@ describe ContactUs::ContactMailer do
13
13
  lambda { ContactUs::ContactMailer.contact_email(@contact) }.should_not raise_error
14
14
  end
15
15
 
16
+ it "should use the ContactUs.mailer_from setting when it is set" do
17
+ ContactUs.mailer_from = "contact@please-change-me.com"
18
+ @mailer = ContactUs::ContactMailer.contact_email(@contact)
19
+ @mailer.from.should eql([ContactUs.mailer_from])
20
+ ContactUs.mailer_from = nil
21
+ end
22
+
16
23
  describe "rendered without error" do
17
24
 
18
- before(:each) do
25
+ before do
19
26
  @mailer = ContactUs::ContactMailer.contact_email(@contact)
20
27
  end
21
28
 
@@ -23,7 +30,7 @@ describe ContactUs::ContactMailer do
23
30
  @mailer.to.should eql([ContactUs.mailer_to])
24
31
  end
25
32
 
26
- it "should have users email in the from field" do
33
+ it "should use the users email in the from field when ContactUs.mailer_from is not set" do
27
34
  @mailer.from.should eql([@contact.email])
28
35
  end
29
36
 
@@ -5,25 +5,26 @@ describe ContactUs::Contact do
5
5
 
6
6
  describe "Validations" do
7
7
 
8
- it 'should validate email presence' do
9
- contact = ContactUs::Contact.new(:email => "", :message => "Test")
10
- contact.valid?.should eql(false)
11
- contact = ContactUs::Contact.new(:email => "Valid@Email.com", :message => "Test")
12
- contact.valid?.should eql(true)
13
- end
8
+ it {should validate_presence_of(:email)}
9
+ it {should validate_presence_of(:message)}
10
+ it {should_not validate_presence_of(:name)}
11
+ it {should_not validate_presence_of(:subject)}
14
12
 
15
- it 'should validate email format' do
16
- contact = ContactUs::Contact.new(:email => "Invalid", :message => "Test")
17
- contact.valid?.should eql(false)
18
- contact = ContactUs::Contact.new(:email => "Valid@Email.com", :message => "Test")
19
- contact.valid?.should eql(true)
20
- end
13
+ context 'with name and subject settings' do
14
+
15
+ after do
16
+ ContactUs.require_name = false
17
+ ContactUs.require_subject = false
18
+ end
19
+
20
+ before do
21
+ ContactUs.require_name = true
22
+ ContactUs.require_subject =true
23
+ end
24
+
25
+ it {should validate_presence_of(:name)}
26
+ it {should validate_presence_of(:subject)}
21
27
 
22
- it 'should validate message presence' do
23
- contact = ContactUs::Contact.new(:email => "Valid@Email.com", :message => "")
24
- contact.valid?.should eql(false)
25
- contact = ContactUs::Contact.new(:email => "Valid@Email.com", :message => "Test")
26
- contact.valid?.should eql(true)
27
28
  end
28
29
 
29
30
  end
@@ -3,20 +3,23 @@ require File.dirname(__FILE__) + '/../lib/contact_us/tasks/install'
3
3
  # Configure Rails Envinronment
4
4
  ENV["RAILS_ENV"] = "test"
5
5
 
6
- require 'simplecov'
7
- SimpleCov.start do
8
- add_filter '/config/'
9
- add_group 'Controllers', 'app/controllers'
10
- add_group 'Helpers', 'app/helpers'
11
- add_group 'Mailers', 'app/mailers'
12
- add_group 'Models', 'app/models'
13
- add_group 'Libraries', 'lib'
14
- add_group 'Specs', 'spec'
15
- end
16
-
17
6
  require File.expand_path("../dummy/config/environment.rb", __FILE__)
18
7
  require "rails/test_help"
19
8
  require "rspec/rails"
9
+ require 'shoulda-matchers'
10
+
11
+ unless defined?(Rubinius).present? or RUBY_VERSION == '1.8.7'
12
+ require 'simplecov'
13
+ SimpleCov.start do
14
+ add_filter '/config/'
15
+ add_group 'Controllers', 'app/controllers'
16
+ add_group 'Helpers', 'app/helpers'
17
+ add_group 'Mailers', 'app/mailers'
18
+ add_group 'Models', 'app/models'
19
+ add_group 'Libraries', 'lib'
20
+ add_group 'Specs', 'spec'
21
+ end
22
+ end
20
23
 
21
24
  ActionMailer::Base.delivery_method = :test
22
25
  ActionMailer::Base.perform_deliveries = true
@@ -37,10 +40,5 @@ ActiveRecord::Migrator.migrate File.expand_path("../dummy/db/migrate/", __FILE__
37
40
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
38
41
 
39
42
  RSpec.configure do |config|
40
- # Remove this line if you don't want RSpec's should and should_not methods or matchers
41
- require 'rspec/expectations'
42
43
  config.include RSpec::Matchers
43
-
44
- # == Mock Framework
45
- config.mock_with :rspec
46
44
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: contact_us
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,66 +9,77 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-07 00:00:00.000000000Z
12
+ date: 2012-02-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capybara
16
- requirement: &70229800315020 !ruby/object:Gem::Requirement
16
+ requirement: &70153597745960 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 0.4.1
21
+ version: '1.1'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70229800315020
24
+ version_requirements: *70153597745960
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec-rails
27
- requirement: &70229800313760 !ruby/object:Gem::Requirement
27
+ requirement: &70153597754040 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
31
31
  - !ruby/object:Gem::Version
32
- version: '2.6'
32
+ version: '2.8'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70229800313760
35
+ version_requirements: *70153597754040
36
+ - !ruby/object:Gem::Dependency
37
+ name: shoulda-matchers
38
+ requirement: &70153597748460 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: '1.0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70153597748460
36
47
  - !ruby/object:Gem::Dependency
37
48
  name: simplecov
38
- requirement: &70229800312700 !ruby/object:Gem::Requirement
49
+ requirement: &70153605750260 !ruby/object:Gem::Requirement
39
50
  none: false
40
51
  requirements:
41
52
  - - ~>
42
53
  - !ruby/object:Gem::Version
43
- version: 0.4.2
54
+ version: '0.6'
44
55
  type: :development
45
56
  prerelease: false
46
- version_requirements: *70229800312700
57
+ version_requirements: *70153605750260
47
58
  - !ruby/object:Gem::Dependency
48
59
  name: sqlite3
49
- requirement: &70229800311600 !ruby/object:Gem::Requirement
60
+ requirement: &70153605745840 !ruby/object:Gem::Requirement
50
61
  none: false
51
62
  requirements:
52
63
  - - ~>
53
64
  - !ruby/object:Gem::Version
54
- version: 1.3.3
65
+ version: 1.3.5
55
66
  type: :development
56
67
  prerelease: false
57
- version_requirements: *70229800311600
68
+ version_requirements: *70153605745840
58
69
  - !ruby/object:Gem::Dependency
59
70
  name: formtastic
60
- requirement: &70229800310700 !ruby/object:Gem::Requirement
71
+ requirement: &70153605757220 !ruby/object:Gem::Requirement
61
72
  none: false
62
73
  requirements:
63
74
  - - ! '>='
64
75
  - !ruby/object:Gem::Version
65
- version: 1.2.0
76
+ version: 2.1.0
66
77
  type: :runtime
67
78
  prerelease: false
68
- version_requirements: *70229800310700
79
+ version_requirements: *70153605757220
69
80
  - !ruby/object:Gem::Dependency
70
81
  name: rails
71
- requirement: &70229800309860 !ruby/object:Gem::Requirement
82
+ requirement: &70153605752140 !ruby/object:Gem::Requirement
72
83
  none: false
73
84
  requirements:
74
85
  - - ! '>='
@@ -76,7 +87,7 @@ dependencies:
76
87
  version: 3.0.0
77
88
  type: :runtime
78
89
  prerelease: false
79
- version_requirements: *70229800309860
90
+ version_requirements: *70153605752140
80
91
  description: A Rails 3+ Engine providing a basic contact form. I used Formtastic
81
92
  to keep things simple, and to hook into your apps custom Formtastic stylesheets.
82
93
  email:
@@ -109,7 +120,6 @@ files:
109
120
  - lib/contact_us.rb
110
121
  - lib/tasks/install.rake
111
122
  - lib/templates/contact_us.rb
112
- - spec/contact_us_spec.rb
113
123
  - spec/controllers/contact_us/contact_controller_spec.rb
114
124
  - spec/dummy/app/controllers/application_controller.rb
115
125
  - spec/dummy/app/helpers/application_helper.rb
@@ -130,6 +140,7 @@ files:
130
140
  - spec/dummy/config/locales/contact_us.es.yml
131
141
  - spec/dummy/config/locales/contact_us.it.yml
132
142
  - spec/dummy/config/locales/contact_us.pt-BR.yml
143
+ - spec/dummy/config/locales/contact_us.zh.yml
133
144
  - spec/dummy/config/routes.rb
134
145
  - spec/dummy/config.ru
135
146
  - spec/dummy/Gemfile
@@ -147,6 +158,7 @@ files:
147
158
  - spec/dummy/Rakefile
148
159
  - spec/dummy/script/rails
149
160
  - spec/integration/contact_us_lint_spec.rb
161
+ - spec/lib/contact_us_spec.rb
150
162
  - spec/lib/install_spec.rb
151
163
  - spec/mailers/contact_us/contact_mailer_spec.rb
152
164
  - spec/models/contact_us/contact_spec.rb
@@ -166,7 +178,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
166
178
  version: '0'
167
179
  segments:
168
180
  - 0
169
- hash: 3895995026617364093
181
+ hash: -3617187140453130010
170
182
  required_rubygems_version: !ruby/object:Gem::Requirement
171
183
  none: false
172
184
  requirements:
@@ -175,7 +187,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
175
187
  version: '0'
176
188
  segments:
177
189
  - 0
178
- hash: 3895995026617364093
190
+ hash: -3617187140453130010
179
191
  requirements: []
180
192
  rubyforge_project: contact_us
181
193
  rubygems_version: 1.8.10
@@ -183,7 +195,6 @@ signing_key:
183
195
  specification_version: 3
184
196
  summary: Gem providing simple Contact Us functionality with a Rails 3+ Engine.
185
197
  test_files:
186
- - spec/contact_us_spec.rb
187
198
  - spec/controllers/contact_us/contact_controller_spec.rb
188
199
  - spec/dummy/app/controllers/application_controller.rb
189
200
  - spec/dummy/app/helpers/application_helper.rb
@@ -204,6 +215,7 @@ test_files:
204
215
  - spec/dummy/config/locales/contact_us.es.yml
205
216
  - spec/dummy/config/locales/contact_us.it.yml
206
217
  - spec/dummy/config/locales/contact_us.pt-BR.yml
218
+ - spec/dummy/config/locales/contact_us.zh.yml
207
219
  - spec/dummy/config/routes.rb
208
220
  - spec/dummy/config.ru
209
221
  - spec/dummy/Gemfile
@@ -221,6 +233,7 @@ test_files:
221
233
  - spec/dummy/Rakefile
222
234
  - spec/dummy/script/rails
223
235
  - spec/integration/contact_us_lint_spec.rb
236
+ - spec/lib/contact_us_spec.rb
224
237
  - spec/lib/install_spec.rb
225
238
  - spec/mailers/contact_us/contact_mailer_spec.rb
226
239
  - spec/models/contact_us/contact_spec.rb