mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Don't use AR::Base.connection for fixture column quoting. Use the connection given to Fixtures.new
[#3104 state:committed] Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
This commit is contained in:
parent
0821941598
commit
8c05ca96f8
1 changed files with 9 additions and 7 deletions
|
@ -622,7 +622,8 @@ class Fixtures < (RUBY_VERSION < '1.9' ? YAML::Omap : Hash)
|
||||||
targets.each do |target|
|
targets.each do |target|
|
||||||
join_fixtures["#{label}_#{target}"] = Fixture.new(
|
join_fixtures["#{label}_#{target}"] = Fixture.new(
|
||||||
{ association.primary_key_name => row[primary_key_name],
|
{ association.primary_key_name => row[primary_key_name],
|
||||||
association.association_foreign_key => Fixtures.identify(target) }, nil)
|
association.association_foreign_key => Fixtures.identify(target) },
|
||||||
|
nil, @connection)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -711,7 +712,7 @@ class Fixtures < (RUBY_VERSION < '1.9' ? YAML::Omap : Hash)
|
||||||
raise Fixture::FormatError, "Bad data for #{@class_name} fixture named #{name} (nil)"
|
raise Fixture::FormatError, "Bad data for #{@class_name} fixture named #{name} (nil)"
|
||||||
end
|
end
|
||||||
|
|
||||||
self[name] = Fixture.new(data, model_class)
|
self[name] = Fixture.new(data, model_class, @connection)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -724,7 +725,7 @@ class Fixtures < (RUBY_VERSION < '1.9' ? YAML::Omap : Hash)
|
||||||
reader.each do |row|
|
reader.each do |row|
|
||||||
data = {}
|
data = {}
|
||||||
row.each_with_index { |cell, j| data[header[j].to_s.strip] = cell.to_s.strip }
|
row.each_with_index { |cell, j| data[header[j].to_s.strip] = cell.to_s.strip }
|
||||||
self["#{@class_name.to_s.underscore}_#{i+=1}"] = Fixture.new(data, model_class)
|
self["#{@class_name.to_s.underscore}_#{i+=1}"] = Fixture.new(data, model_class, @connection)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -762,7 +763,8 @@ class Fixture #:nodoc:
|
||||||
|
|
||||||
attr_reader :model_class
|
attr_reader :model_class
|
||||||
|
|
||||||
def initialize(fixture, model_class)
|
def initialize(fixture, model_class, connection = ActiveRecord::Base.connection)
|
||||||
|
@connection = connection
|
||||||
@fixture = fixture
|
@fixture = fixture
|
||||||
@model_class = model_class.is_a?(Class) ? model_class : model_class.constantize rescue nil
|
@model_class = model_class.is_a?(Class) ? model_class : model_class.constantize rescue nil
|
||||||
end
|
end
|
||||||
|
@ -784,14 +786,14 @@ class Fixture #:nodoc:
|
||||||
end
|
end
|
||||||
|
|
||||||
def key_list
|
def key_list
|
||||||
columns = @fixture.keys.collect{ |column_name| ActiveRecord::Base.connection.quote_column_name(column_name) }
|
columns = @fixture.keys.collect{ |column_name| @connection.quote_column_name(column_name) }
|
||||||
columns.join(", ")
|
columns.join(", ")
|
||||||
end
|
end
|
||||||
|
|
||||||
def value_list
|
def value_list
|
||||||
list = @fixture.inject([]) do |fixtures, (key, value)|
|
list = @fixture.inject([]) do |fixtures, (key, value)|
|
||||||
col = model_class.columns_hash[key] if model_class.respond_to?(:ancestors) && model_class.ancestors.include?(ActiveRecord::Base)
|
col = model_class.columns_hash[key] if model_class.respond_to?(:ancestors) && model_class.ancestors.include?(ActiveRecord::Base)
|
||||||
fixtures << ActiveRecord::Base.connection.quote(value, col).gsub('[^\]\\n', "\n").gsub('[^\]\\r', "\r")
|
fixtures << @connection.quote(value, col).gsub('[^\]\\n', "\n").gsub('[^\]\\r', "\r")
|
||||||
end
|
end
|
||||||
list * ', '
|
list * ', '
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue