mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Move file action only to app generator.
This commit is contained in:
@@ -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.
|
||||
#
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user