pointless_feedback 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.md +138 -0
- data/Rakefile +40 -0
- data/app/assets/javascripts/pointless_feedback/application.js +15 -0
- data/app/assets/stylesheets/pointless_feedback/application.css +13 -0
- data/app/controllers/pointless_feedback/messages_controller.rb +22 -0
- data/app/helpers/pointless_feedback/application_helper.rb +26 -0
- data/app/mailers/pointless_feedback/feedback_mailer.rb +16 -0
- data/app/models/pointless_feedback/message.rb +26 -0
- data/app/views/layouts/pointless_feedback/application.html.erb +14 -0
- data/app/views/pointless_feedback/feedback_mailer/feedback.html.erb +6 -0
- data/app/views/pointless_feedback/messages/new.html.erb +57 -0
- data/config/locales/en.yml +1 -0
- data/config/routes.rb +5 -0
- data/db/migrate/20130501182659_create_pointless_feedback_messages.rb +12 -0
- data/lib/generators/pointless_feedback/install_generator.rb +13 -0
- data/lib/generators/pointless_feedback/views_generator.rb +16 -0
- data/lib/generators/templates/pointless_feedback.rb +13 -0
- data/lib/pointless_feedback/controllers/helpers.rb +10 -0
- data/lib/pointless_feedback/engine.rb +13 -0
- data/lib/pointless_feedback/version.rb +3 -0
- data/lib/pointless_feedback.rb +32 -0
- data/lib/tasks/pointless_feedback_tasks.rake +4 -0
- data/test/dummy/README.rdoc +261 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +15 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/controllers/home_controller.rb +4 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/home/index.html.erb +1 -0
- data/test/dummy/app/views/layouts/application.html.erb +16 -0
- data/test/dummy/config/application.rb +59 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +67 -0
- data/test/dummy/config/environments/test.rb +37 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +15 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +5 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/schema.rb +25 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +187 -0
- data/test/dummy/log/test.log +9624 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +25 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
- data/test/dummy/tmp/cache/assets/CDA/AF0/sprockets%2F2b009905de1eb97e693a12d62f76c221 +0 -0
- data/test/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/test/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/test/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/test/dummy/tmp/cache/assets/D72/890/sprockets%2F6208de944cfe6b5b3c3c37c89d32f41a +0 -0
- data/test/dummy/tmp/cache/assets/DD9/830/sprockets%2Fc25e8f936dbc8c2b26c7c7b3d7ff6d13 +0 -0
- data/test/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/test/dummy/tmp/cache/assets/E02/8C0/sprockets%2Fdcaacb4effc911c9573def4b74b82590 +0 -0
- data/test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/test/dummy/tmp/capybara/capybara-201306030928415341101962.html +48 -0
- data/test/dummy/tmp/capybara/capybara-201306030937025132981181.html +48 -0
- data/test/dummy/tmp/capybara/capybara-201306030937083494523886.html +48 -0
- data/test/dummy/tmp/capybara/capybara-20130603093722783471600.html +65 -0
- data/test/dummy/tmp/capybara/capybara-20130603094056611257399.html +241 -0
- data/test/dummy/tmp/capybara/capybara-201306030944524823294090.html +14 -0
- data/test/dummy/tmp/capybara/capybara-20130828105343685535937.html +50 -0
- data/test/dummy/tmp/capybara/capybara-201308281055176538066301.html +52 -0
- data/test/dummy/tmp/capybara/capybara-201311071553562925508230.html +58 -0
- data/test/factories/messages.rb +8 -0
- data/test/functional/pointless_feedback/feedback_mailer_test.rb +25 -0
- data/test/functional/pointless_feedback/messages_controller_test.rb +61 -0
- data/test/generators/install_generator_test.rb +14 -0
- data/test/generators/views_generator_test.rb +14 -0
- data/test/integration/pointless_feedback/feedback_submission_test.rb +54 -0
- data/test/integration/pointless_feedback/main_app_root_url_test.rb +9 -0
- data/test/pointless_feedback_test.rb +7 -0
- data/test/test_helper.rb +26 -0
- data/test/tmp/app/views/pointless_feedback/messages/new.html.erb +57 -0
- data/test/unit/helpers/pointless_feedback/application_helper_test.rb +39 -0
- data/test/unit/pointless_feedback/message_test.rb +96 -0
- metadata +280 -0
@@ -0,0 +1,52 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Dummy</title>
|
5
|
+
<link href="/assets/application.css" media="all" rel="stylesheet" type="text/css" />
|
6
|
+
<script src="/assets/application.js" type="text/javascript"></script>
|
7
|
+
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<form accept-charset="UTF-8" action="/pointless_feedback/messages" class="new_message" id="new_message" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /></div>
|
12
|
+
|
13
|
+
<fieldset class="user-fields">
|
14
|
+
<legend>About You</legend>
|
15
|
+
|
16
|
+
<div class="field">
|
17
|
+
<label for="message_name">Name</label>
|
18
|
+
<input id="message_name" name="message[name]" size="30" type="text" />
|
19
|
+
</div>
|
20
|
+
|
21
|
+
<div class="field">
|
22
|
+
<label for="message_email_address">Email address</label>
|
23
|
+
<input id="message_email_address" name="message[email_address]" size="30" type="text" />
|
24
|
+
</div>
|
25
|
+
</fieldset>
|
26
|
+
|
27
|
+
<fieldset class="feedback-fields">
|
28
|
+
<legend>Leave Your Feedback</legend>
|
29
|
+
|
30
|
+
<div class="field">
|
31
|
+
<label for="message_topic">Topic</label>
|
32
|
+
<select id="message_topic" name="message[topic]"><option value="">Please select</option>
|
33
|
+
<option value="Error on page">Error on page</option>
|
34
|
+
<option value="Other">Other</option></select>
|
35
|
+
</div>
|
36
|
+
|
37
|
+
<div class="field">
|
38
|
+
<label for="message_description">Description</label>
|
39
|
+
<textarea cols="40" id="message_description" name="message[description]" rows="20">
|
40
|
+
</textarea>
|
41
|
+
</div>
|
42
|
+
|
43
|
+
<div class="contact-input"></div>
|
44
|
+
<input id="message_contact_info" name="message[contact_info]" size="30" type="text" />
|
45
|
+
</div>
|
46
|
+
</fieldset>
|
47
|
+
|
48
|
+
<input name="commit" type="submit" value="Submit" />
|
49
|
+
</form>
|
50
|
+
|
51
|
+
</body>
|
52
|
+
</html>
|
@@ -0,0 +1,58 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Dummy</title>
|
5
|
+
<link href="/assets/application.css" media="all" rel="stylesheet" type="text/css" />
|
6
|
+
<script src="/assets/application.js" type="text/javascript"></script>
|
7
|
+
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<a href="http://www.example.com/">Homepage</a>
|
12
|
+
|
13
|
+
<form accept-charset="UTF-8" action="/pointless_feedback/messages" class="new_message" id="new_message" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /></div>
|
14
|
+
|
15
|
+
<fieldset class="user-fields">
|
16
|
+
<legend>About You</legend>
|
17
|
+
|
18
|
+
<div class="field">
|
19
|
+
<label for="message_name">Name</label>
|
20
|
+
<input id="message_name" name="message[name]" size="30" type="text" />
|
21
|
+
</div>
|
22
|
+
|
23
|
+
<div class="field">
|
24
|
+
<label for="message_email_address">Email address</label>
|
25
|
+
<input id="message_email_address" name="message[email_address]" size="30" type="text" />
|
26
|
+
</div>
|
27
|
+
</fieldset>
|
28
|
+
|
29
|
+
<fieldset class="feedback-fields">
|
30
|
+
<legend>Leave Your Feedback</legend>
|
31
|
+
|
32
|
+
<div class="field">
|
33
|
+
<label for="message_topic">Topic</label>
|
34
|
+
<select id="message_topic" name="message[topic]"><option value="">Please select</option>
|
35
|
+
<option value="Error on page">Error on page</option>
|
36
|
+
<option value="Other">Other</option></select>
|
37
|
+
</div>
|
38
|
+
|
39
|
+
<div class="field">
|
40
|
+
<label for="message_description">Description</label>
|
41
|
+
<textarea cols="40" id="message_description" name="message[description]" rows="20">
|
42
|
+
</textarea>
|
43
|
+
</div>
|
44
|
+
|
45
|
+
<!-- This is a honeypot field to keep the spammers away. Do not remove. -->
|
46
|
+
<!-- If this field is filled in, feedback will not be emailed -->
|
47
|
+
<div class="contact-input" style="position: absolute; left: -9999px;">
|
48
|
+
<input id="message_contact_info" name="message[contact_info]" size="30" type="text" />
|
49
|
+
</div>
|
50
|
+
<!-- End of honeypot field -->
|
51
|
+
|
52
|
+
</fieldset>
|
53
|
+
|
54
|
+
<input name="commit" type="submit" value="Submit" />
|
55
|
+
</form>
|
56
|
+
|
57
|
+
</body>
|
58
|
+
</html>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module PointlessFeedback
|
4
|
+
class FeedbackMailerTest < ActionMailer::TestCase
|
5
|
+
before do
|
6
|
+
@message = FactoryGirl.create(:message)
|
7
|
+
@mail = FeedbackMailer.feedback('to@example.com', @message)
|
8
|
+
end
|
9
|
+
|
10
|
+
test "feedback email" do
|
11
|
+
assert_equal "Pointless Feedback", @mail.subject
|
12
|
+
assert_equal ["to@example.com"], @mail.to
|
13
|
+
assert_equal ["feedback@pointlesscorp.com"], @mail.from
|
14
|
+
end
|
15
|
+
|
16
|
+
test "feedback email body" do
|
17
|
+
assert_match "You've got feedback!", @mail.body.encoded
|
18
|
+
assert_match "Name: #{@message.name}", @mail.body.encoded
|
19
|
+
assert_match "Email Address: #{@message.email_address}", @mail.body.encoded
|
20
|
+
assert_match "Topic: #{@message.topic}", @mail.body.encoded
|
21
|
+
assert_match "Description: #{@message.description}", @mail.body.encoded
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module PointlessFeedback
|
4
|
+
class MessagesControllerTest < ActionController::TestCase
|
5
|
+
describe "getting new" do
|
6
|
+
setup { get :new, :use_route => :pointless_feedback }
|
7
|
+
|
8
|
+
it { assert_response :success }
|
9
|
+
it { assert_template :new }
|
10
|
+
it { assigns(:message).must_be_instance_of Message }
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "posting to create" do
|
14
|
+
setup do
|
15
|
+
@valid_params = {
|
16
|
+
:message => {
|
17
|
+
:name => 'Some Guy',
|
18
|
+
:email_address => 'some_guy@web.com',
|
19
|
+
:topic => 'Other',
|
20
|
+
:description => 'Yo website bork'
|
21
|
+
},
|
22
|
+
:use_route => :pointless_feedback
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "with invalid params" do
|
27
|
+
setup do
|
28
|
+
post :create, @valid_params.merge(:message => { :name => ''})
|
29
|
+
end
|
30
|
+
|
31
|
+
it { assert_response :success }
|
32
|
+
it { assert_template :new }
|
33
|
+
|
34
|
+
it { assigns(:message).must_be :invalid? }
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "with valid params" do
|
38
|
+
describe "with default after_message_create_path" do
|
39
|
+
setup do
|
40
|
+
post :create, @valid_params
|
41
|
+
end
|
42
|
+
|
43
|
+
it { assert_response :redirect }
|
44
|
+
it { assert_redirected_to '/' }
|
45
|
+
it { flash[:notice].must_equal 'Thanks for your feedback!' }
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "with overridden after_message_create_path" do
|
49
|
+
setup do
|
50
|
+
@controller.instance_eval "def after_message_create_path; '/dashboard'; end"
|
51
|
+
post :create, @valid_params
|
52
|
+
end
|
53
|
+
|
54
|
+
it { assert_response :redirect }
|
55
|
+
it { assert_redirected_to '/dashboard' }
|
56
|
+
it { flash[:notice].must_equal 'Thanks for your feedback!' }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require "rails/generators/test_case"
|
3
|
+
require "generators/pointless_feedback/install_generator"
|
4
|
+
|
5
|
+
class InstallGeneratorTest < Rails::Generators::TestCase
|
6
|
+
tests PointlessFeedback::Generators::InstallGenerator
|
7
|
+
destination File.expand_path("../../tmp", __FILE__)
|
8
|
+
setup :prepare_destination
|
9
|
+
|
10
|
+
test "Assert all files are properly created" do
|
11
|
+
run_generator
|
12
|
+
assert_file "config/initializers/pointless_feedback.rb"
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require "rails/generators/test_case"
|
3
|
+
require "generators/pointless_feedback/views_generator"
|
4
|
+
|
5
|
+
class ViewsGeneratorTest < Rails::Generators::TestCase
|
6
|
+
tests PointlessFeedback::Generators::ViewsGenerator
|
7
|
+
destination File.expand_path("../../tmp", __FILE__)
|
8
|
+
setup :prepare_destination
|
9
|
+
|
10
|
+
test "Assert all views are properly created" do
|
11
|
+
run_generator
|
12
|
+
assert_file 'app/views/pointless_feedback/messages/new.html.erb'
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class FeedbackSubmissionTest < ActionDispatch::IntegrationTest
|
4
|
+
fixtures :all
|
5
|
+
|
6
|
+
describe "submitting feedback" do
|
7
|
+
before do
|
8
|
+
visit "/pointless_feedback"
|
9
|
+
|
10
|
+
fill_in_fields
|
11
|
+
|
12
|
+
click_on "Submit"
|
13
|
+
end
|
14
|
+
|
15
|
+
test "redirects to the root path" do
|
16
|
+
assert_equal current_path, "/"
|
17
|
+
end
|
18
|
+
|
19
|
+
test "thanks message is displayed" do
|
20
|
+
within('body') do
|
21
|
+
assert_match 'Thanks for your feedback!', text
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "submitting feedback with the honeypot field filled in" do
|
27
|
+
before do
|
28
|
+
visit "/pointless_feedback"
|
29
|
+
|
30
|
+
fill_in_fields
|
31
|
+
fill_in "message_contact_info", :with => "I'm a spam bot!"
|
32
|
+
|
33
|
+
click_on "Submit"
|
34
|
+
end
|
35
|
+
|
36
|
+
test "redirects to the root path" do
|
37
|
+
assert_equal current_path, "/"
|
38
|
+
end
|
39
|
+
|
40
|
+
test "thanks message is displayed" do
|
41
|
+
within('body') do
|
42
|
+
assert_match 'Thanks for your feedback!', text
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def fill_in_fields
|
48
|
+
fill_in "Name", :with => "Eli"
|
49
|
+
fill_in "Email address", :with => "eli@example.com"
|
50
|
+
select "Other", :from => "Topic"
|
51
|
+
fill_in "Description", :with => "This site is awful"
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# Configure Rails Environment
|
2
|
+
ENV["RAILS_ENV"] = "test"
|
3
|
+
|
4
|
+
require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
5
|
+
require "rails/test_help"
|
6
|
+
require "capybara/rails"
|
7
|
+
require "factory_girl"
|
8
|
+
require "test/unit"
|
9
|
+
require "mocha/setup"
|
10
|
+
|
11
|
+
require File.expand_path("../factories/messages.rb", __FILE__)
|
12
|
+
|
13
|
+
Rails.backtrace_cleaner.remove_silencers!
|
14
|
+
|
15
|
+
# Load support files
|
16
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
17
|
+
|
18
|
+
# Load fixtures from the engine
|
19
|
+
if ActiveSupport::TestCase.method_defined?(:fixture_path=)
|
20
|
+
ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
|
21
|
+
end
|
22
|
+
|
23
|
+
class ActionDispatch::IntegrationTest
|
24
|
+
# Make the Capybara DSL available in all integration tests
|
25
|
+
include Capybara::DSL
|
26
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
<%= form_for @message do |f| %>
|
2
|
+
<% if @message.errors.any? %>
|
3
|
+
<div class="error_messages">
|
4
|
+
<h2>
|
5
|
+
<%= I18n.t('activerecord.errors.header', :default => 'Invalid Fields') %>
|
6
|
+
</h2>
|
7
|
+
|
8
|
+
<p>
|
9
|
+
<%= I18n.t('activerecord.errors.message', :default => 'Correct the following errors and try again.') %>
|
10
|
+
</p>
|
11
|
+
|
12
|
+
<ul>
|
13
|
+
<% @message.errors.full_messages.each do |message| %>
|
14
|
+
<li><%= message.html_safe %></li>
|
15
|
+
<% end %>
|
16
|
+
</ul>
|
17
|
+
</div>
|
18
|
+
<% end %>
|
19
|
+
|
20
|
+
<fieldset class="user-fields">
|
21
|
+
<legend>About You</legend>
|
22
|
+
|
23
|
+
<div class="field">
|
24
|
+
<%= f.label :name %>
|
25
|
+
<%= f.text_field :name %>
|
26
|
+
</div>
|
27
|
+
|
28
|
+
<div class="field">
|
29
|
+
<%= f.label :email_address %>
|
30
|
+
<%= f.text_field :email_address %>
|
31
|
+
</div>
|
32
|
+
</fieldset>
|
33
|
+
|
34
|
+
<fieldset class="feedback-fields">
|
35
|
+
<legend>Leave Your Feedback</legend>
|
36
|
+
|
37
|
+
<div class="field">
|
38
|
+
<%= f.label :topic %>
|
39
|
+
<%= f.select :topic, PointlessFeedback.message_topics, { :prompt => true } %>
|
40
|
+
</div>
|
41
|
+
|
42
|
+
<div class="field">
|
43
|
+
<%= f.label :description %>
|
44
|
+
<%= f.text_area :description %>
|
45
|
+
</div>
|
46
|
+
|
47
|
+
<!-- This is a honeypot field to keep the spammers away. Do not remove. -->
|
48
|
+
<!-- If this field is filled in, feedback will not be emailed -->
|
49
|
+
<div class="contact-input" style="position: absolute; left: -9999px;">
|
50
|
+
<%= f.text_field :contact_info %>
|
51
|
+
</div>
|
52
|
+
<!-- End of honeypot field -->
|
53
|
+
|
54
|
+
</fieldset>
|
55
|
+
|
56
|
+
<%= f.submit 'Submit' %>
|
57
|
+
<% end %>
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module PointlessFeedback
|
4
|
+
class ApplicationHelperTest < ActionDispatch::IntegrationTest
|
5
|
+
describe "main app's named routes" do
|
6
|
+
class MainAppApplicationHelperMock
|
7
|
+
def foo_path
|
8
|
+
'/foo'
|
9
|
+
end
|
10
|
+
|
11
|
+
def foo_url
|
12
|
+
'http://host/foo'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class PointlessFeedbackApplicationHelperMock
|
17
|
+
include PointlessFeedback::ApplicationHelper
|
18
|
+
|
19
|
+
def main_app
|
20
|
+
MainAppApplicationHelperMock.new
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
let(:raw_helper) { PointlessFeedbackApplicationHelperMock.new }
|
25
|
+
|
26
|
+
it "outputs named path from the main app" do
|
27
|
+
raw_helper.foo_path.must_equal '/foo'
|
28
|
+
end
|
29
|
+
|
30
|
+
it "outputs named url from the main app" do
|
31
|
+
raw_helper.foo_url.must_equal 'http://host/foo'
|
32
|
+
end
|
33
|
+
|
34
|
+
it "raises exception with other routes" do
|
35
|
+
proc{ raw_helper.lolwut_path }.must_raise NoMethodError
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module PointlessFeedback
|
4
|
+
class MessageTest < ActiveSupport::TestCase
|
5
|
+
subject { PointlessFeedback::Message.new }
|
6
|
+
|
7
|
+
%w(name email_address topic description).each do |field|
|
8
|
+
it "requires #{field}" do
|
9
|
+
subject.send("#{field}=", '')
|
10
|
+
subject.save
|
11
|
+
|
12
|
+
subject.errors[field.to_sym].must_include "can't be blank"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "validating topics" do
|
17
|
+
subject { FactoryGirl.build(:message) }
|
18
|
+
|
19
|
+
it "allows valid topic" do
|
20
|
+
subject.topic = 'Other'
|
21
|
+
|
22
|
+
assert subject.valid?
|
23
|
+
end
|
24
|
+
|
25
|
+
it "does not allow invalid topic" do
|
26
|
+
subject.topic = 'lolwut'
|
27
|
+
|
28
|
+
assert subject.invalid?
|
29
|
+
subject.errors[:topic].must_include "is not included in the list"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "validating email" do
|
34
|
+
subject { FactoryGirl.build(:message) }
|
35
|
+
|
36
|
+
it "allows a valid email address" do
|
37
|
+
subject.email_address = 'test@example.com'
|
38
|
+
|
39
|
+
assert subject.valid?
|
40
|
+
end
|
41
|
+
|
42
|
+
it "does not allow invalid emails address" do
|
43
|
+
subject.email_address = 'test@example'
|
44
|
+
assert subject.invalid?
|
45
|
+
|
46
|
+
subject.email_address = 'test.com'
|
47
|
+
assert subject.invalid?
|
48
|
+
|
49
|
+
subject.email_address = 'come on'
|
50
|
+
assert subject.invalid?
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "export_feedback" do
|
55
|
+
describe "when PointlessFeedback.send_emails is true" do
|
56
|
+
before do
|
57
|
+
PointlessFeedback.email_feedback = true
|
58
|
+
PointlessFeedback.to_emails = ['test1@example.com', 'test2@example.com']
|
59
|
+
end
|
60
|
+
|
61
|
+
subject { FactoryGirl.build(:message) }
|
62
|
+
|
63
|
+
it "sends mail after create" do
|
64
|
+
mailer = stub(:deliver => true)
|
65
|
+
['test1@example.com', 'test2@example.com'].each do |email|
|
66
|
+
FeedbackMailer.expects(:feedback).with(email, subject).returns(mailer)
|
67
|
+
end
|
68
|
+
|
69
|
+
subject.save
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "when the honeypot field is not nil" do
|
73
|
+
it "does not send mail after create" do
|
74
|
+
subject.contact_info = "I'm a spam bot!"
|
75
|
+
FeedbackMailer.expects(:feedback).never
|
76
|
+
|
77
|
+
subject.save
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "when PointlessFeedback.send_emails is false" do
|
83
|
+
before do
|
84
|
+
PointlessFeedback.email_feedback = false
|
85
|
+
end
|
86
|
+
subject { FactoryGirl.build(:message) }
|
87
|
+
|
88
|
+
it "does not send any mail" do
|
89
|
+
FeedbackMailer.expects(:feedback).times(0)
|
90
|
+
|
91
|
+
subject.save
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|