Fix Rails::Generators::Actions#environment when env is passed. Closes #2110
This commit is contained in:
parent
0aec2e7191
commit
fcdcc87a08
@ -92,14 +92,15 @@ def add_source(source, options={})
|
||||
#
|
||||
def environment(data=nil, options={}, &block)
|
||||
sentinel = /class [a-z_:]+ < Rails::Application/i
|
||||
env_file_sentinel = /::Application\.configure do/
|
||||
data = block.call if !data && block_given?
|
||||
|
||||
in_root do
|
||||
if options[:env].nil?
|
||||
inject_into_file 'config/application.rb', "\n #{data}", :after => sentinel, :verbose => false
|
||||
else
|
||||
Array.wrap(options[:env]).each do|env|
|
||||
append_file "config/environments/#{env}.rb", "\n#{data}", :verbose => false
|
||||
Array.wrap(options[:env]).each do |env|
|
||||
inject_into_file "config/environments/#{env}.rb", "\n #{data}", :after => env_file_sentinel, :verbose => false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -109,6 +109,13 @@ def test_environment_should_include_data_in_environment_initializer_block
|
||||
assert_file 'config/application.rb', /#{Regexp.escape(autoload_paths)}/
|
||||
end
|
||||
|
||||
def test_environment_should_include_data_in_environment_initializer_block_with_env_option
|
||||
run_generator
|
||||
autoload_paths = 'config.autoload_paths += %w["#{Rails.root}/app/extras"]'
|
||||
action :environment, autoload_paths, :env => 'development'
|
||||
assert_file "config/environments/development.rb", /Application\.configure do\n #{Regexp.escape(autoload_paths)}/
|
||||
end
|
||||
|
||||
def test_environment_with_block_should_include_block_contents_in_environment_initializer_block
|
||||
run_generator
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user