Skip to content

Commit

Permalink
fix app generate naming to handle underscores correctly closes #924
Browse files Browse the repository at this point in the history
  • Loading branch information
achiurizo committed Jan 12, 2013
1 parent 87f032e commit 33cf159
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
11 changes: 5 additions & 6 deletions padrino-gen/lib/padrino-gen/generators/app.rb
Expand Up @@ -32,12 +32,13 @@ def self.banner; "padrino-gen project [name]"; end
# @api private
def create_app
self.destination_root = options[:root]
@app_name = name.gsub(/\W/, '_').underscore.camelize
@app_folder = name.gsub(/\W/, '_').underscore
@app_name = name.gsub(/\W/, '_').underscore.camelize
if in_app_root?
self.behavior = :revoke if options[:destroy]
app_skeleton(@app_name.downcase, options[:tiny])
empty_directory destination_root("public/#{@app_name.downcase}")
append_file destination_root('config/apps.rb'), "\nPadrino.mount('#{@app_name}').to('/#{@app_name.downcase}')"
app_skeleton(@app_folder.downcase, options[:tiny])
empty_directory destination_root("public/#{@app_folder.downcase}")
append_file destination_root('config/apps.rb'), "\nPadrino.mount('#{@app_name}').to('/#{@app_folder.downcase}')"

return if self.behavior == :revoke
say
Expand All @@ -46,8 +47,6 @@ def create_app
say '='*65, :green
say "This application has been mounted to /#{@app_name.downcase}"
say "You can configure a different path by editing 'config/apps.rb'"
say '=' * 65, :green
say
else
say 'You are not at the root of a Padrino application! (config/boot.rb not found)'
end
Expand Down
19 changes: 18 additions & 1 deletion padrino-gen/test/test_app_generator.rb
Expand Up @@ -34,6 +34,23 @@ def teardown
assert_match_in_file(/set :session_secret, '[0-9A-z]*'/, "#{@apptmp}/sample_project/config/apps.rb")
end

should "create correctly a new padrino application with an underscore name" do
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}") }
capture_io { generate(:app, 'demo_app', "--root=#{@apptmp}/sample_project") }
assert_file_exists("#{@apptmp}/sample_project")
assert_file_exists("#{@apptmp}/sample_project/demo_app")
assert_file_exists("#{@apptmp}/sample_project/demo_app/app.rb")
assert_file_exists("#{@apptmp}/sample_project/demo_app/controllers")
assert_file_exists("#{@apptmp}/sample_project/demo_app/helpers")
assert_file_exists("#{@apptmp}/sample_project/demo_app/views")
assert_file_exists("#{@apptmp}/sample_project/demo_app/views/layouts")
assert_dir_exists("#{@apptmp}/sample_project/public/demo_app")
assert_match_in_file("Padrino.mount('DemoApp').to('/demo_app')", "#{@apptmp}/sample_project/config/apps.rb")
assert_match_in_file('class DemoApp < Padrino::Application', "#{@apptmp}/sample_project/demo_app/app.rb")
assert_match_in_file(/Padrino.configure_apps do/, "#{@apptmp}/sample_project/config/apps.rb")
assert_match_in_file(/set :session_secret, '[0-9A-z]*'/, "#{@apptmp}/sample_project/config/apps.rb")
end

should "generate tiny app skeleton" do
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}") }
capture_io { generate(:app, 'demo','--tiny',"--root=#{@apptmp}/sample_project") }
Expand All @@ -60,7 +77,7 @@ def teardown
should "correctly create a new mailer inside a padrino application" do
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
capture_io { generate(:app, 'demo_app', "--root=#{@apptmp}/sample_project") }
capture_io { generate(:mailer, 'demo', "-r=#{@apptmp}/sample_project", '-a=demoapp') }
capture_io { generate(:mailer, 'demo', "-r=#{@apptmp}/sample_project", '-a=demo_app') }
end

# only destroys what it generated.
Expand Down
6 changes: 3 additions & 3 deletions padrino-gen/test/test_project_generator.rb
Expand Up @@ -33,9 +33,9 @@ def teardown
assert_match_in_file(/class ProjectCom < Padrino::Application/, "#{@apptmp}/project.com/app/app.rb")
assert_match_in_file(/Padrino.mount\('ProjectCom'\).to\('\/'\)/, "#{@apptmp}/project.com/config/apps.rb")
capture_io { generate(:app, 'ws-dci-2011', "--root=#{@apptmp}/project.com") }
assert_file_exists("#{@apptmp}/project.com/wsdci2011")
assert_match_in_file(/class WsDci2011 < Padrino::Application/, "#{@apptmp}/project.com/wsdci2011/app.rb")
assert_match_in_file(/Padrino.mount\('WsDci2011'\).to\('\/wsdci2011'\)/, "#{@apptmp}/project.com/config/apps.rb")
assert_file_exists("#{@apptmp}/project.com/ws_dci_2011")
assert_match_in_file(/class WsDci2011 < Padrino::Application/, "#{@apptmp}/project.com/ws_dci_2011/app.rb")
assert_match_in_file(/Padrino.mount\('WsDci2011'\).to\('\/ws_dci_2011'\)/, "#{@apptmp}/project.com/config/apps.rb")
end

should "raise an Error when given invalid constant names" do
Expand Down

0 comments on commit 33cf159

Please sign in to comment.