2009-06-25 10:21:33 -04:00
|
|
|
require 'generators/generators_test_helper'
|
2010-01-18 07:44:32 -05:00
|
|
|
require 'generators/rails/mailer/mailer_generator'
|
2009-06-25 10:21:33 -04:00
|
|
|
|
2010-01-18 18:07:11 -05:00
|
|
|
class MailerGeneratorTest < Rails::Generators::TestCase
|
|
|
|
include GeneratorsTestHelper
|
2010-01-03 10:34:32 -05:00
|
|
|
arguments %w(notifier foo bar)
|
2009-06-25 10:21:33 -04:00
|
|
|
|
|
|
|
def test_mailer_skeleton_is_created
|
|
|
|
run_generator
|
2010-01-25 07:13:29 -05:00
|
|
|
assert_file "app/mailers/notifier.rb" do |mailer|
|
|
|
|
assert_match /class Notifier < ActionMailer::Base/, mailer
|
2010-01-27 22:37:47 -05:00
|
|
|
assert_match /default :from => "from@example.com"/, mailer
|
2010-01-25 07:13:29 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_mailer_with_i18n_helper
|
|
|
|
run_generator
|
|
|
|
assert_file "app/mailers/notifier.rb" do |mailer|
|
|
|
|
assert_match /en\.actionmailer\.notifier\.foo\.subject/, mailer
|
|
|
|
assert_match /en\.actionmailer\.notifier\.bar\.subject/, mailer
|
|
|
|
end
|
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
|
2010-01-18 18:49:04 -05:00
|
|
|
assert_file "test/functional/notifier_test.rb", /class NotifierTest < ActionMailer::TestCase/
|
2009-06-27 07:03:07 -04:00
|
|
|
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
|
2010-01-25 19:06:48 -05:00
|
|
|
assert_file "app/views/notifier/foo.text.erb" do |view|
|
2010-01-25 07:13:29 -05:00
|
|
|
assert_match /app\/views\/notifier\/foo/, view
|
|
|
|
assert_match /<%= @greeting %>/, view
|
|
|
|
end
|
|
|
|
|
2010-01-25 19:06:48 -05:00
|
|
|
assert_file "app/views/notifier/bar.text.erb" do |view|
|
2010-01-25 07:13:29 -05:00
|
|
|
assert_match /app\/views\/notifier\/bar/, view
|
|
|
|
assert_match /<%= @greeting %>/, view
|
|
|
|
end
|
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
|
2010-01-25 07:13:29 -05:00
|
|
|
|
|
|
|
assert_file "app/mailers/notifier.rb" do |mailer|
|
|
|
|
assert_instance_method :foo, mailer do |foo|
|
2010-01-27 22:33:26 -05:00
|
|
|
assert_match /mail :to => "to@example.org"/, foo
|
2010-01-25 07:13:29 -05:00
|
|
|
assert_match /@greeting = "Hi"/, foo
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_instance_method :bar, mailer do |bar|
|
2010-01-27 22:33:26 -05:00
|
|
|
assert_match /mail :to => "to@example.org"/, bar
|
2010-01-25 07:13:29 -05:00
|
|
|
assert_match /@greeting = "Hi"/, bar
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-06-25 10:27:44 -04:00
|
|
|
end
|
2009-06-25 10:21:33 -04:00
|
|
|
end
|