Don't indent blank lines in named base generators #5902

Merged
merged 1 commit into from Apr 25, 2012

Conversation

Projects
None yet
4 participants
Contributor

avakhov commented Apr 19, 2012

This method is not documented, but I use it in my generators.

code = <<-ROUTES.strip_heredoc
  get "admin/login"

  get "admin/logout"
ROUTES

route indent(code).strip

And this code also used for example here: https://github.com/rails/rails/blob/master/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb#L1

Member

sikachu commented Apr 24, 2012

Do you mind adding a test for this?

Contributor

avakhov commented Apr 25, 2012

I added test which check indented blank lines (It fails on master and passes this PR)

@josevalim josevalim added a commit that referenced this pull request Apr 25, 2012

@josevalim josevalim Merge pull request #5902 from avakhov/generator-no-indent-blank-lines
Don't indent blank lines in named base generators
33d8091

@josevalim josevalim merged commit 33d8091 into rails:master Apr 25, 2012

@carlosantoniodasilva carlosantoniodasilva commented on the diff Apr 25, 2012

railties/test/generators/namespaced_generators_test.rb
@@ -61,6 +61,14 @@ def test_invokes_default_template_engine_even_with_no_action
run_generator ["account"]
assert_file "app/views/test_app/account"
end
+
+ def test_namespaced_controller_dont_indent_blank_lines
+ run_generator
+ assert_file "app/controllers/test_app/account_controller.rb"
+ File.readlines(File.expand_path("app/controllers/test_app/account_controller.rb", destination_root)).each do |line|
+ assert_no_match line.chomp, /^\s+$/, "Don't indent blank lines"
+ end
@carlosantoniodasilva

carlosantoniodasilva Apr 25, 2012

Owner

I think you can give a block to assert_file, to receive it's content as argument, and assert against it (more). Something like:

    assert_file "app/controllers/test_app/account_controller.rb" do |content|
      assert_no_match /^\s+$/, content, "Don't indent blank lines"  
    end

Could you give it a try? Thanks.

Contributor

avakhov commented Apr 26, 2012

@carlosantoniodasilva good point! I didn't think about that. #5997 - Did you mean this?

@avakhov yeah exactly, perfect! Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment