diff options
Diffstat (limited to 'railties/test/generators')
-rw-r--r-- | railties/test/generators/mailer_generator_test.rb | 40 | ||||
-rw-r--r-- | railties/test/generators/named_base_test.rb | 62 |
2 files changed, 82 insertions, 20 deletions
diff --git a/railties/test/generators/mailer_generator_test.rb b/railties/test/generators/mailer_generator_test.rb index dfc3130f77..0203eb314c 100644 --- a/railties/test/generators/mailer_generator_test.rb +++ b/railties/test/generators/mailer_generator_test.rb @@ -6,8 +6,20 @@ class MailerGeneratorTest < Rails::Generators::TestCase arguments %w(notifier foo bar) def test_mailer_skeleton_is_created + Rails.stubs(:application).returns(Object.new) run_generator - assert_file "app/mailers/notifier.rb", /class Notifier < ActionMailer::Base/ + assert_file "app/mailers/notifier.rb" do |mailer| + assert_match /class Notifier < ActionMailer::Base/, mailer + assert_match /delivers_from "mail@object.com"/, mailer + 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 end def test_check_class_collision @@ -24,8 +36,15 @@ class MailerGeneratorTest < Rails::Generators::TestCase def test_invokes_default_template_engine run_generator - assert_file "app/views/notifier/foo.erb", /app\/views\/notifier\/foo/ - assert_file "app/views/notifier/bar.erb", /app\/views\/notifier\/bar/ + assert_file "app/views/notifier/foo.erb" do |view| + assert_match /app\/views\/notifier\/foo/, view + assert_match /<%= @greeting %>/, view + end + + assert_file "app/views/notifier/bar.erb" do |view| + assert_match /app\/views\/notifier\/bar/, view + assert_match /<%= @greeting %>/, view + end end def test_invokes_default_template_engine_even_with_no_action @@ -40,7 +59,18 @@ class MailerGeneratorTest < Rails::Generators::TestCase def test_actions_are_turned_into_methods run_generator - assert_file "app/mailers/notifier.rb", /def foo/ - assert_file "app/mailers/notifier.rb", /def bar/ + + assert_file "app/mailers/notifier.rb" do |mailer| + assert_instance_method :foo, mailer do |foo| + assert_match /mail\(:to => ""\)/, foo + assert_match /@greeting = "Hi"/, foo + end + + assert_instance_method :bar, mailer do |bar| + assert_match /mail\(:to => ""\)/, bar + assert_match /@greeting = "Hi"/, bar + end + end + end end diff --git a/railties/test/generators/named_base_test.rb b/railties/test/generators/named_base_test.rb index 99eb431a49..7514bc32bd 100644 --- a/railties/test/generators/named_base_test.rb +++ b/railties/test/generators/named_base_test.rb @@ -16,28 +16,60 @@ class NamedBaseTest < Rails::Generators::TestCase tests Rails::Generators::ScaffoldControllerGenerator def test_named_generator_attributes - g = generator ["admin/foo"] - assert_equal 'admin/foo', g.name - assert_equal %w(admin), g.class_path - assert_equal 1, g.class_nesting_depth - assert_equal 'Admin::Foo', g.class_name - assert_equal 'foo', g.singular_name - assert_equal 'foos', g.plural_name - assert_equal g.singular_name, g.file_name - assert_equal "admin_#{g.plural_name}", g.table_name + g = generator ['admin/foo'] + assert_name g, 'admin/foo', :name + assert_name g, %w(admin), :class_path + assert_name g, 'Admin::Foo', :class_name + assert_name g, 'admin/foo', :file_path + assert_name g, 'foo', :file_name + assert_name g, 'foo', :singular_name + assert_name g, 'foos', :plural_name + assert_name g, 'admin.foo', :i18n_scope + assert_name g, 'admin_foos', :table_name + end + + def test_named_generator_attributes_as_ruby + g = generator ['Admin::Foo'] + assert_name g, 'Admin::Foo', :name + assert_name g, %w(admin), :class_path + assert_name g, 'Admin::Foo', :class_name + assert_name g, 'admin/foo', :file_path + assert_name g, 'foo', :file_name + assert_name g, 'foo', :singular_name + assert_name g, 'foos', :plural_name + assert_name g, 'admin.foo', :i18n_scope + assert_name g, 'admin_foos', :table_name end def test_named_generator_attributes_without_pluralized ActiveRecord::Base.pluralize_table_names = false - g = generator ["admin/foo"] - assert_equal "admin_#{g.singular_name}", g.table_name + g = generator ['admin/foo'] + assert_name g, 'admin_foo', :table_name end def test_scaffold_plural_names - g = generator ["ProductLine"] - assert_equal "ProductLines", g.controller_name - assert_equal "ProductLines", g.controller_class_name - assert_equal "product_lines", g.controller_file_name + g = generator ['admin/foo'] + assert_name g, 'admin/foos', :controller_name + assert_name g, %w(admin), :controller_class_path + assert_name g, 'Admin::Foos', :controller_class_name + assert_name g, 'admin/foos', :controller_file_path + assert_name g, 'foos', :controller_file_name + assert_name g, 'admin.foos', :controller_i18n_scope + end + + def test_scaffold_plural_names_as_ruby + g = generator ['Admin::Foo'] + assert_name g, 'Admin::Foos', :controller_name + assert_name g, %w(admin), :controller_class_path + assert_name g, 'Admin::Foos', :controller_class_name + assert_name g, 'admin/foos', :controller_file_path + assert_name g, 'foos', :controller_file_name + assert_name g, 'admin.foos', :controller_i18n_scope end + protected + + def assert_name(generator, value, method) + assert_equal value, generator.send(method) + end end |