aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test
diff options
context:
space:
mode:
Diffstat (limited to 'railties/test')
-rw-r--r--railties/test/generators/mailer_generator_test.rb39
-rw-r--r--railties/test/generators/named_base_test.rb70
2 files changed, 89 insertions, 20 deletions
diff --git a/railties/test/generators/mailer_generator_test.rb b/railties/test/generators/mailer_generator_test.rb
index dfc3130f77..99ce53323e 100644
--- a/railties/test/generators/mailer_generator_test.rb
+++ b/railties/test/generators/mailer_generator_test.rb
@@ -7,7 +7,18 @@ class MailerGeneratorTest < Rails::Generators::TestCase
def test_mailer_skeleton_is_created
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 "from@example.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 +35,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.text.erb" do |view|
+ assert_match /app\/views\/notifier\/foo/, view
+ assert_match /<%= @greeting %>/, view
+ end
+
+ assert_file "app/views/notifier/bar.text.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 +58,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 => "to@example.com"\)/, foo
+ assert_match /@greeting = "Hi"/, foo
+ end
+
+ assert_instance_method :bar, mailer do |bar|
+ assert_match /mail\(:to => "to@example.com"\)/, 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..f327fb1282 100644
--- a/railties/test/generators/named_base_test.rb
+++ b/railties/test/generators/named_base_test.rb
@@ -16,28 +16,68 @@ 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
+ def test_application_name
+ g = generator ['Admin::Foo']
+ Rails.stubs(:application).returns(Object.new)
+ assert_name g, "object", :application_name
+ Rails.stubs(:application).returns(nil)
+ assert_name g, "application", :application_name
+ end
+
+ protected
+
+ def assert_name(generator, value, method)
+ assert_equal value, generator.send(method)
+ end
end