2009-06-25 10:21:33 -04:00
|
|
|
require 'abstract_unit'
|
|
|
|
require 'generators/generators_test_helper'
|
2009-09-24 17:01:31 -04:00
|
|
|
require 'rails/generators/rails/mailer/mailer_generator'
|
2009-06-25 10:21:33 -04:00
|
|
|
|
|
|
|
class MailerGeneratorTest < GeneratorsTestCase
|
|
|
|
|
|
|
|
def test_mailer_skeleton_is_created
|
|
|
|
run_generator
|
2009-06-25 10:27:44 -04:00
|
|
|
assert_file "app/models/notifier.rb", /class Notifier < ActionMailer::Base/
|
2009-06-25 10:21:33 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_check_class_collision
|
|
|
|
content = capture(:stderr){ run_generator ["object"] }
|
|
|
|
assert_match /The name 'Object' is either already used in your application or reserved/, content
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_invokes_default_test_framework
|
|
|
|
run_generator
|
2009-06-27 07:03:07 -04:00
|
|
|
assert_file "test/unit/notifier_test.rb", /class NotifierTest < ActionMailer::TestCase/
|
|
|
|
assert_file "test/fixtures/notifier/foo", /app\/views\/notifier\/foo/
|
|
|
|
assert_file "test/fixtures/notifier/bar", /app\/views\/notifier\/bar/
|
2009-06-25 10:21:33 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_invokes_default_template_engine
|
|
|
|
run_generator
|
2009-06-26 05:57:40 -04:00
|
|
|
assert_file "app/views/notifier/foo.erb", /app\/views\/notifier\/foo/
|
|
|
|
assert_file "app/views/notifier/bar.erb", /app\/views\/notifier\/bar/
|
2009-06-25 10:21:33 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_invokes_default_template_engine_even_with_no_action
|
|
|
|
run_generator ["notifier"]
|
|
|
|
assert_file "app/views/notifier"
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_logs_if_the_template_engine_cannot_be_found
|
2009-07-08 06:55:50 -04:00
|
|
|
content = run_generator ["notifier", "foo", "bar", "--template-engine=haml"]
|
|
|
|
assert_match /haml \[not found\]/, content
|
2009-06-25 10:21:33 -04:00
|
|
|
end
|
|
|
|
|
2009-06-25 10:27:44 -04:00
|
|
|
def test_actions_are_turned_into_methods
|
|
|
|
run_generator
|
|
|
|
assert_file "app/models/notifier.rb", /def foo/
|
|
|
|
assert_file "app/models/notifier.rb", /def bar/
|
|
|
|
end
|
|
|
|
|
2009-06-25 10:21:33 -04:00
|
|
|
protected
|
|
|
|
|
|
|
|
def run_generator(args=["notifier", "foo", "bar"])
|
2009-07-14 16:20:43 -04:00
|
|
|
silence(:stdout) { Rails::Generators::MailerGenerator.start args, :destination_root => destination_root }
|
2009-06-25 10:21:33 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|