Browse files

Do not create table_name_prefix method on isolated module if the meth…

…od already exists.

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
1 parent 799a6fa commit f821055dc7bead5ab348f63279cd4321d4d9c3c8 @drogus drogus committed with josevalim Nov 21, 2010
Showing with 23 additions and 2 deletions.
  1. +4 −2 railties/lib/rails/engine.rb
  2. +19 −0 railties/test/railties/engine_test.rb
View
6 railties/lib/rails/engine.rb
@@ -363,8 +363,10 @@ def isolate_namespace(mod)
_railtie
end
- define_method(:table_name_prefix) do
- "#{name}_"
+ unless mod.respond_to?(:table_name_prefix)
+ define_method(:table_name_prefix) do
+ "#{name}_"
+ end
end
end
end
View
19 railties/test/railties/engine_test.rb
@@ -683,5 +683,24 @@ class Engine < ::Rails::Engine
app_generators = Rails.application.config.generators.options[:rails]
assert_equal :test_unit , app_generators[:test_framework]
end
+
+ test "do not create table_name_prefix method if it already exists" do
+ @plugin.write "lib/bukkits.rb", <<-RUBY
+ module Bukkits
+ def self.table_name_prefix
+ "foo"
+ end
+
+ class Engine < ::Rails::Engine
+ isolate_namespace(Bukkits)
+ end
+ end
+ RUBY
+
+ boot_rails
+ require "#{rails_root}/config/environment"
+
+ assert_equal "foo", Bukkits.table_name_prefix
+ end
end
end

0 comments on commit f821055

Please sign in to comment.