mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Don't pass unused connection
to FixtureSet.new
The `@connection` is no longer used since ee5ab22
.
Originally the `@connection` was useless because it is only used in
`timestamp_column_names`, which is only used if `model_class` is given.
If `model_class` is given, the `@connection` is always
`model_class.connection`.
This commit is contained in:
parent
19f0f14074
commit
1812240f1a
2 changed files with 11 additions and 14 deletions
|
@ -577,9 +577,8 @@ module ActiveRecord
|
||||||
fixtures_map = {}
|
fixtures_map = {}
|
||||||
fixture_sets = fixture_files.map do |fixture_set_name|
|
fixture_sets = fixture_files.map do |fixture_set_name|
|
||||||
klass = class_names[fixture_set_name]
|
klass = class_names[fixture_set_name]
|
||||||
conn = klass&.connection || connection
|
|
||||||
fixtures_map[fixture_set_name] = new( # ActiveRecord::FixtureSet.new
|
fixtures_map[fixture_set_name] = new( # ActiveRecord::FixtureSet.new
|
||||||
conn,
|
nil,
|
||||||
fixture_set_name,
|
fixture_set_name,
|
||||||
klass,
|
klass,
|
||||||
::File.join(fixtures_directory, fixture_set_name)
|
::File.join(fixtures_directory, fixture_set_name)
|
||||||
|
@ -621,7 +620,7 @@ module ActiveRecord
|
||||||
|
|
||||||
attr_reader :table_name, :name, :fixtures, :model_class, :config
|
attr_reader :table_name, :name, :fixtures, :model_class, :config
|
||||||
|
|
||||||
def initialize(connection, name, class_name, path, config = ActiveRecord::Base)
|
def initialize(_, name, class_name, path, config = ActiveRecord::Base)
|
||||||
@name = name
|
@name = name
|
||||||
@path = path
|
@path = path
|
||||||
@config = config
|
@config = config
|
||||||
|
@ -630,8 +629,6 @@ module ActiveRecord
|
||||||
|
|
||||||
@fixtures = read_fixture_files(path)
|
@fixtures = read_fixture_files(path)
|
||||||
|
|
||||||
@connection = connection
|
|
||||||
|
|
||||||
@table_name = (model_class.respond_to?(:table_name) ?
|
@table_name = (model_class.respond_to?(:table_name) ?
|
||||||
model_class.table_name :
|
model_class.table_name :
|
||||||
self.class.default_fixture_table_name(name, config))
|
self.class.default_fixture_table_name(name, config))
|
||||||
|
|
|
@ -473,11 +473,11 @@ class FixturesTest < ActiveRecord::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_empty_yaml_fixture
|
def test_empty_yaml_fixture
|
||||||
assert_not_nil ActiveRecord::FixtureSet.new(Account.connection, "accounts", Account, FIXTURES_ROOT + "/naked/yml/accounts")
|
assert_not_nil ActiveRecord::FixtureSet.new(nil, "accounts", Account, FIXTURES_ROOT + "/naked/yml/accounts")
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_empty_yaml_fixture_with_a_comment_in_it
|
def test_empty_yaml_fixture_with_a_comment_in_it
|
||||||
assert_not_nil ActiveRecord::FixtureSet.new(Account.connection, "companies", Company, FIXTURES_ROOT + "/naked/yml/companies")
|
assert_not_nil ActiveRecord::FixtureSet.new(nil, "companies", Company, FIXTURES_ROOT + "/naked/yml/companies")
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_nonexistent_fixture_file
|
def test_nonexistent_fixture_file
|
||||||
|
@ -487,14 +487,14 @@ class FixturesTest < ActiveRecord::TestCase
|
||||||
assert_empty Dir[nonexistent_fixture_path + "*"]
|
assert_empty Dir[nonexistent_fixture_path + "*"]
|
||||||
|
|
||||||
assert_raise(Errno::ENOENT) do
|
assert_raise(Errno::ENOENT) do
|
||||||
ActiveRecord::FixtureSet.new(Account.connection, "companies", Company, nonexistent_fixture_path)
|
ActiveRecord::FixtureSet.new(nil, "companies", Company, nonexistent_fixture_path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_dirty_dirty_yaml_file
|
def test_dirty_dirty_yaml_file
|
||||||
fixture_path = FIXTURES_ROOT + "/naked/yml/courses"
|
fixture_path = FIXTURES_ROOT + "/naked/yml/courses"
|
||||||
error = assert_raise(ActiveRecord::Fixture::FormatError) do
|
error = assert_raise(ActiveRecord::Fixture::FormatError) do
|
||||||
ActiveRecord::FixtureSet.new(Account.connection, "courses", Course, fixture_path)
|
ActiveRecord::FixtureSet.new(nil, "courses", Course, fixture_path)
|
||||||
end
|
end
|
||||||
assert_equal "fixture is not a hash: #{fixture_path}.yml", error.to_s
|
assert_equal "fixture is not a hash: #{fixture_path}.yml", error.to_s
|
||||||
end
|
end
|
||||||
|
@ -502,7 +502,7 @@ class FixturesTest < ActiveRecord::TestCase
|
||||||
def test_yaml_file_with_one_invalid_fixture
|
def test_yaml_file_with_one_invalid_fixture
|
||||||
fixture_path = FIXTURES_ROOT + "/naked/yml/courses_with_invalid_key"
|
fixture_path = FIXTURES_ROOT + "/naked/yml/courses_with_invalid_key"
|
||||||
error = assert_raise(ActiveRecord::Fixture::FormatError) do
|
error = assert_raise(ActiveRecord::Fixture::FormatError) do
|
||||||
ActiveRecord::FixtureSet.new(Account.connection, "courses", Course, fixture_path)
|
ActiveRecord::FixtureSet.new(nil, "courses", Course, fixture_path)
|
||||||
end
|
end
|
||||||
assert_equal "fixture key is not a hash: #{fixture_path}.yml, keys: [\"two\"]", error.to_s
|
assert_equal "fixture key is not a hash: #{fixture_path}.yml, keys: [\"two\"]", error.to_s
|
||||||
end
|
end
|
||||||
|
@ -525,7 +525,7 @@ class FixturesTest < ActiveRecord::TestCase
|
||||||
|
|
||||||
def test_omap_fixtures
|
def test_omap_fixtures
|
||||||
assert_nothing_raised do
|
assert_nothing_raised do
|
||||||
fixtures = ActiveRecord::FixtureSet.new(Account.connection, "categories", Category, FIXTURES_ROOT + "/categories_ordered")
|
fixtures = ActiveRecord::FixtureSet.new(nil, "categories", Category, FIXTURES_ROOT + "/categories_ordered")
|
||||||
|
|
||||||
fixtures.each.with_index do |(name, fixture), i|
|
fixtures.each.with_index do |(name, fixture), i|
|
||||||
assert_equal "fixture_no_#{i}", name
|
assert_equal "fixture_no_#{i}", name
|
||||||
|
@ -596,7 +596,7 @@ class HasManyThroughFixture < ActiveRecord::TestCase
|
||||||
|
|
||||||
parrots = File.join FIXTURES_ROOT, "parrots"
|
parrots = File.join FIXTURES_ROOT, "parrots"
|
||||||
|
|
||||||
fs = ActiveRecord::FixtureSet.new parrot.connection, "parrots", parrot, parrots
|
fs = ActiveRecord::FixtureSet.new(nil, "parrots", parrot, parrots)
|
||||||
rows = fs.table_rows
|
rows = fs.table_rows
|
||||||
assert_equal load_has_and_belongs_to_many["parrots_treasures"], rows["parrots_treasures"]
|
assert_equal load_has_and_belongs_to_many["parrots_treasures"], rows["parrots_treasures"]
|
||||||
end
|
end
|
||||||
|
@ -614,7 +614,7 @@ class HasManyThroughFixture < ActiveRecord::TestCase
|
||||||
|
|
||||||
parrots = File.join FIXTURES_ROOT, "parrots"
|
parrots = File.join FIXTURES_ROOT, "parrots"
|
||||||
|
|
||||||
fs = ActiveRecord::FixtureSet.new parrot.connection, "parrots", parrot, parrots
|
fs = ActiveRecord::FixtureSet.new(nil, "parrots", parrot, parrots)
|
||||||
rows = fs.table_rows
|
rows = fs.table_rows
|
||||||
assert_equal load_has_and_belongs_to_many["parrots_treasures"], rows["parrot_treasures"]
|
assert_equal load_has_and_belongs_to_many["parrots_treasures"], rows["parrot_treasures"]
|
||||||
end
|
end
|
||||||
|
@ -629,7 +629,7 @@ class HasManyThroughFixture < ActiveRecord::TestCase
|
||||||
|
|
||||||
parrots = File.join FIXTURES_ROOT, "parrots"
|
parrots = File.join FIXTURES_ROOT, "parrots"
|
||||||
|
|
||||||
fs = ActiveRecord::FixtureSet.new parrot.connection, "parrots", parrot, parrots
|
fs = ActiveRecord::FixtureSet.new(nil, "parrots", parrot, parrots)
|
||||||
fs.table_rows
|
fs.table_rows
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue