Skip to content

Commit

Permalink
Fix bug in Padrino::Mounter.app_constant (padrino#1595)
Browse files Browse the repository at this point in the history
If the module with the same name as the application class has already been defined,
Padrino::Mounter.app_constant had returned the very module object.

So I intend not to search towards ancestors with second parameter 'false' in 'const_defined?'.
This code is only valid in the Ruby 1.9 or later.
  • Loading branch information
tyabe committed Feb 28, 2014
1 parent 30ec5ff commit da50241
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion padrino-core/lib/padrino-core/mounter.rb
Expand Up @@ -137,7 +137,7 @@ def app_constant
klass = Object
for piece in app_class.split("::")
piece = piece.to_sym
if klass.const_defined?(piece)
if klass.const_defined?(piece, false)
klass = klass.const_get(piece)
else
return
Expand Down
7 changes: 7 additions & 0 deletions padrino-core/test/fixtures/apps/demo_app.rb
@@ -0,0 +1,7 @@
PADRINO_ROOT = File.dirname(__FILE__) unless defined? PADRINO_ROOT

module Demo
class App < Padrino::Application
set :reload, true
end
end
7 changes: 7 additions & 0 deletions padrino-core/test/fixtures/apps/demo_demo.rb
@@ -0,0 +1,7 @@
PADRINO_ROOT = File.dirname(__FILE__) unless defined? PADRINO_ROOT

module Demo
class Demo < Padrino::Application
set :reload, true
end
end
9 changes: 9 additions & 0 deletions padrino-core/test/test_mounter.rb
Expand Up @@ -118,6 +118,15 @@ class ::TwoApp < Padrino::Application; end
assert_equal ["one_app", "two_app"], Padrino.mounted_apps.map(&:name)
end

should 'mount app with the same name as the module' do
Padrino.mount("Demo::App", :app_file => File.expand_path(File.dirname(__FILE__) + '/fixtures/apps/demo_app.rb')).to("/app")
Padrino.mount("Demo::Demo", :app_file => File.expand_path(File.dirname(__FILE__) + '/fixtures/apps/demo_demo.rb')).to("/")

Padrino.mounted_apps.each do |app|
assert_equal app.app_obj.setup_application!, true
end
end

should 'change mounted_root' do
Padrino.mounted_root = "fixtures"
assert_equal Padrino.root("fixtures", "test", "app.rb"), Padrino.mounted_root("test", "app.rb")
Expand Down

0 comments on commit da50241

Please sign in to comment.