diff --git a/config/initializers/connection_specification.rb b/config/initializers/connection_specification.rb index ff172a7e5ea..66d93769741 100644 --- a/config/initializers/connection_specification.rb +++ b/config/initializers/connection_specification.rb @@ -13,7 +13,13 @@ ActiveRecord::Base::ConnectionSpecification.class_eval do if self.class.environment && @config.has_key?(self.class.environment) @current_config.merge!(@config[self.class.environment].symbolize_keys) end + + @current_config.keys.each do |key| + next unless @current_config[key].is_a?(String) + @current_config[key] = I18n.interpolate_hash(@current_config[key], @current_config) + end @current_config[:username] = @current_config[:username].gsub('{schema}', @current_config[:schema_search_path]) if @current_config[:username] && @current_config[:schema_search_path] + if self.class.explicit_user @current_config[:username] = self.class.explicit_user @current_config.delete(:password) diff --git a/spec/lib/connection_specification_with_environment_spec.rb b/spec/lib/connection_specification_with_environment_spec.rb index 93df31a3e43..8ab979b3e9e 100644 --- a/spec/lib/connection_specification_with_environment_spec.rb +++ b/spec/lib/connection_specification_with_environment_spec.rb @@ -48,11 +48,11 @@ describe ActiveRecord::Base::ConnectionSpecification do spec.config[:database].should == 'master' end - it "should allow using {schema} as an insertion into the username" do + it "should allow using hash insertions" do conf = { :adapter => 'postgresql', :database => 'master', - :username => '{schema}', + :username => '%{schema_search_path}', :schema_search_path => 'canvas', :deploy => { :username => 'deploy' @@ -70,7 +70,7 @@ describe ActiveRecord::Base::ConnectionSpecification do conf = { :adapter => 'postgresql', :database => 'master', - :username => '{schema}', + :username => '%{schema_search_path}', :schema_search_path => 'canvas', :deploy => { :username => 'deploy'