From 4f3e44fa03ab8fc47f75fa710b28c72b9b2328b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 28 Jun 2009 12:00:13 +0200 Subject: Move file action only to app generator. --- railties/lib/generators/actions.rb | 6 ------ railties/lib/generators/rails/app/app_generator.rb | 7 +++++++ railties/test/generators/actions_test.rb | 8 ++++---- railties/test/generators/app_generator_test.rb | 9 +++++++++ 4 files changed, 20 insertions(+), 10 deletions(-) (limited to 'railties') diff --git a/railties/lib/generators/actions.rb b/railties/lib/generators/actions.rb index c905f17f61..ee4fe7183f 100644 --- a/railties/lib/generators/actions.rb +++ b/railties/lib/generators/actions.rb @@ -262,12 +262,6 @@ module Rails protected - # Define file as an alias to create_file for backwards compatibility. - # - def file(*args, &block) - create_file(*args, &block) - end - # Define log for backwards compatibility. If just one argument is sent, # invoke say, otherwise invoke say_status. # diff --git a/railties/lib/generators/rails/app/app_generator.rb b/railties/lib/generators/rails/app/app_generator.rb index 45e46aed02..6bd464a16c 100644 --- a/railties/lib/generators/rails/app/app_generator.rb +++ b/railties/lib/generators/rails/app/app_generator.rb @@ -171,6 +171,13 @@ module Rails::Generators protected + # Define file as an alias to create_file for backwards compatibility. + # TODO Add deprecation warning? + # + def file(*args, &block) + create_file(*args, &block) + end + def app_name @app_name ||= File.basename(root) end diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb index a0502e9112..baf687336a 100644 --- a/railties/test/generators/actions_test.rb +++ b/railties/test/generators/actions_test.rb @@ -20,13 +20,13 @@ class ActionsTest < GeneratorsTestCase assert_equal generator.instance_variable_get("@foo"), "FOO" end - def test_file_should_write_data_to_file_path - action :file, 'lib/test_file.rb', 'heres test data' + def test_create_file_should_write_data_to_file_path + action :create_file, 'lib/test_file.rb', 'heres test data' assert_file 'lib/test_file.rb', 'heres test data' end - def test_file_should_write_block_contents_to_file_path - action(:file, 'lib/test_file.rb'){ 'heres block data' } + def test_create_file_should_write_block_contents_to_file_path + action(:create_file, 'lib/test_file.rb'){ 'heres block data' } assert_file 'lib/test_file.rb', 'heres block data' end diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 1e1c7cfb04..6f0bad06b9 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -144,6 +144,11 @@ class AppGeneratorTest < GeneratorsTestCase assert_match "rails:generators:app", Rails::Generators::AppGenerator.namespace end + def test_file_is_added_for_backwards_compatibility + action :file, 'lib/test_file.rb', 'heres test data' + assert_file 'lib/test_file.rb', 'heres test data' + end + protected def run_generator(args=[]) @@ -154,4 +159,8 @@ class AppGeneratorTest < GeneratorsTestCase @generator ||= Rails::Generators::AppGenerator.new([destination_root], options, :root => destination_root) end + def action(*args, &block) + silence(:stdout){ generator.send(*args, &block) } + end + end -- cgit v1.2.3