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
|
require 'test_helper'
require 'rails/generators/mailer/mailer_generator'
require 'generators/haml/mailer/mailer_generator'
class Haml::Generators::MailerGeneratorTest < Rails::Generators::TestCase
destination File.join(Rails.root)
tests Rails::Generators::MailerGenerator
arguments %w(notifier foo bar --template-engine haml)
setup :prepare_destination
setup :copy_routes
test "should invoke template engine" do
run_generator
if ::Rails.version.to_s >= '4.2'
assert_file "app/views/layouts/mailer.text.haml" do |view|
assert_match(/\= yield/, view)
end
assert_file "app/views/layouts/mailer.html.haml" do |view|
assert_match(/\= yield/, view)
end
assert_file "app/views/notifier_mailer/foo.html.haml" do |view|
assert_match %r(app/views/notifier_mailer/foo\.html\.haml), view
assert_match(/\= @greeting/, view)
end
assert_file "app/views/notifier_mailer/bar.html.haml" do |view|
assert_match %r(app/views/notifier_mailer/bar\.html\.haml), view
assert_match(/\= @greeting/, view)
end
assert_file "app/views/notifier_mailer/foo.text.haml" do |view|
assert_match %r(app/views/notifier_mailer/foo\.text\.haml), view
assert_match(/\= @greeting/, view)
end
assert_file "app/views/notifier_mailer/bar.text.haml" do |view|
assert_match %r(app/views/notifier_mailer/bar\.text\.haml), view
assert_match(/\= @greeting/, view)
end
else
if ::Rails.version.to_s >= '4.1'
assert_file "app/views/notifier/foo.html.haml" do |view|
assert_match %r(app/views/notifier/foo\.html\.haml), view
assert_match(/\= @greeting/, view)
end
assert_file "app/views/notifier/bar.html.haml" do |view|
assert_match %r(app/views/notifier/bar\.html\.haml), view
assert_match(/\= @greeting/, view)
end
end
assert_file "app/views/notifier/foo.text.haml" do |view|
assert_match %r(app/views/notifier/foo\.text\.haml), view
assert_match(/\= @greeting/, view)
end
assert_file "app/views/notifier/bar.text.haml" do |view|
assert_match %r(app/views/notifier/bar\.text\.haml), view
assert_match(/\= @greeting/, view)
end
end
end
test 'suffix is not duplicated' do
if ::Rails.version.to_s >= '4.2'
run_generator ['notifier_mailer', 'foo', 'bar', '--template-engine', 'haml']
assert_no_file 'app/views/notifier_mailer_mailer/'
assert_file 'app/views/notifier_mailer/'
assert_no_file 'app/views/notifier_mailer_mailer/foo.text.haml'
assert_file 'app/views/notifier_mailer/foo.text.haml'
assert_no_file 'app/views/notifier_mailer_mailer/foo.html.haml'
assert_file 'app/views/notifier_mailer/foo.html.haml'
assert_no_file 'app/views/notifier_mailer_mailer/bar.text.haml'
assert_file 'app/views/notifier_mailer/bar.text.haml'
assert_no_file 'app/views/notifier_mailer_mailer/bar.html.haml'
assert_file 'app/views/notifier_mailer/bar.html.haml'
end
end
end
|