Skip to content

Commit

Permalink
Updating newline fix to maintain existing linebreaks and indentation …
Browse files Browse the repository at this point in the history
…and test for b/eol on inserts
  • Loading branch information
johnmdonahue committed Nov 25, 2011
1 parent 6f5fdf8 commit 95e9b5f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
7 changes: 4 additions & 3 deletions railties/lib/rails/generators/actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ def gem(*args)
end

in_root do
str = "\ngem #{parts.join(", ")}\n"
str = "gem #{parts.join(", ")}"
str = " " + str if @in_group
str = "\n" + str
append_file "Gemfile", str, :verbose => false
end
end
Expand All @@ -87,13 +88,13 @@ def gem_group(*names, &block)
log :gemfile, "group #{name}"

in_root do
append_file "Gemfile", "\ngroup #{name} do\n", :force => true
append_file "Gemfile", "\ngroup #{name} do", :force => true

@in_group = true
instance_eval(&block)
@in_group = false

append_file "Gemfile", "end\n", :force => true
append_file "Gemfile", "\nend\n", :force => true
end
end

Expand Down
10 changes: 6 additions & 4 deletions railties/test/generators/actions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,13 @@ def test_gem_with_version_should_include_version_in_gemfile
def test_gem_should_insert_on_separate_lines
run_generator

File.open('Gemfile', 'a') {|f| f.write('# Some content...') }

action :gem, 'rspec'
action :gem, 'rspec-rails'

assert_file 'Gemfile', /gem "rspec"$/
assert_file 'Gemfile', /gem "rspec-rails"$/
assert_file 'Gemfile', /^gem "rspec"$/
assert_file 'Gemfile', /^gem "rspec-rails"$/
end

def test_gem_group_should_wrap_gems_in_a_group
Expand All @@ -112,8 +114,8 @@ def test_gem_group_should_wrap_gems_in_a_group
action :gem_group, :test do
gem 'fakeweb'
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

def test_environment_should_include_data_in_environment_initializer_block
Expand Down

0 comments on commit 95e9b5f

Please sign in to comment.