Merge pull request #3756 from johnmdonahue/update-gem-action-linebreaks-and-indentation

Updating newline fix to maintain existing linebreaks and indentation and...
This commit is contained in:
José Valim 2011-11-25 09:44:14 -08:00
commit 2dab493867
2 changed files with 10 additions and 7 deletions

View File

@ -68,8 +68,9 @@ module Rails
end end
in_root do in_root do
str = "\ngem #{parts.join(", ")}\n" str = "gem #{parts.join(", ")}"
str = " " + str if @in_group str = " " + str if @in_group
str = "\n" + str
append_file "Gemfile", str, :verbose => false append_file "Gemfile", str, :verbose => false
end end
end end
@ -87,13 +88,13 @@ module Rails
log :gemfile, "group #{name}" log :gemfile, "group #{name}"
in_root do in_root do
append_file "Gemfile", "\ngroup #{name} do\n", :force => true append_file "Gemfile", "\ngroup #{name} do", :force => true
@in_group = true @in_group = true
instance_eval(&block) instance_eval(&block)
@in_group = false @in_group = false
append_file "Gemfile", "end\n", :force => true append_file "Gemfile", "\nend\n", :force => true
end end
end end

View File

@ -95,11 +95,13 @@ class ActionsTest < Rails::Generators::TestCase
def test_gem_should_insert_on_separate_lines def test_gem_should_insert_on_separate_lines
run_generator run_generator
File.open('Gemfile', 'a') {|f| f.write('# Some content...') }
action :gem, 'rspec' action :gem, 'rspec'
action :gem, 'rspec-rails' action :gem, 'rspec-rails'
assert_file 'Gemfile', /gem "rspec"$/ assert_file 'Gemfile', /^gem "rspec"$/
assert_file 'Gemfile', /gem "rspec-rails"$/ assert_file 'Gemfile', /^gem "rspec-rails"$/
end end
def test_gem_group_should_wrap_gems_in_a_group def test_gem_group_should_wrap_gems_in_a_group
@ -113,7 +115,7 @@ class ActionsTest < Rails::Generators::TestCase
gem 'fakeweb' gem 'fakeweb'
end end
assert_file 'Gemfile', /\ngroup :development, :test do\n \ngem "rspec-rails"\nend\n\ngroup :test do\n \ngem "fakeweb"\nend/ assert_file 'Gemfile', /\ngroup :development, :test do\n gem "rspec-rails"\nend\n\ngroup :test do\n gem "fakeweb"\nend/
end end
def test_environment_should_include_data_in_environment_initializer_block def test_environment_should_include_data_in_environment_initializer_block