mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
create_fixtures() should always return a list
This commit is contained in:
parent
ca938c0fc9
commit
6344246654
2 changed files with 9 additions and 9 deletions
|
@ -471,11 +471,10 @@ class Fixtures
|
||||||
|
|
||||||
def self.cached_fixtures(connection, keys_to_fetch = nil)
|
def self.cached_fixtures(connection, keys_to_fetch = nil)
|
||||||
if keys_to_fetch
|
if keys_to_fetch
|
||||||
fixtures = cache_for_connection(connection).values_at(*keys_to_fetch)
|
cache_for_connection(connection).values_at(*keys_to_fetch)
|
||||||
else
|
else
|
||||||
fixtures = cache_for_connection(connection).values
|
cache_for_connection(connection).values
|
||||||
end
|
end
|
||||||
fixtures.size > 1 ? fixtures : fixtures.first
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.cache_fixtures(connection, fixtures_map)
|
def self.cache_fixtures(connection, fixtures_map)
|
||||||
|
@ -554,13 +553,14 @@ class Fixtures
|
||||||
attr_reader :table_name, :name, :fixtures
|
attr_reader :table_name, :name, :fixtures
|
||||||
|
|
||||||
def initialize(connection, table_name, class_name, fixture_path, file_filter = DEFAULT_FILTER_RE)
|
def initialize(connection, table_name, class_name, fixture_path, file_filter = DEFAULT_FILTER_RE)
|
||||||
@fixtures = ActiveSupport::OrderedHash.new
|
|
||||||
@connection = connection
|
@connection = connection
|
||||||
@table_name = table_name
|
@table_name = table_name
|
||||||
@fixture_path = fixture_path
|
@fixture_path = fixture_path
|
||||||
@file_filter = file_filter
|
@file_filter = file_filter
|
||||||
@name = table_name # preserve fixture base name
|
@name = table_name # preserve fixture base name
|
||||||
@class_name = class_name
|
@class_name = class_name
|
||||||
|
|
||||||
|
@fixtures = ActiveSupport::OrderedHash.new
|
||||||
@table_name = "#{ActiveRecord::Base.table_name_prefix}#{@table_name}#{ActiveRecord::Base.table_name_suffix}"
|
@table_name = "#{ActiveRecord::Base.table_name_prefix}#{@table_name}#{ActiveRecord::Base.table_name_suffix}"
|
||||||
@table_name = class_name.table_name if class_name.respond_to?(:table_name)
|
@table_name = class_name.table_name if class_name.respond_to?(:table_name)
|
||||||
@connection = class_name.connection if class_name.respond_to?(:connection)
|
@connection = class_name.connection if class_name.respond_to?(:connection)
|
||||||
|
|
|
@ -35,7 +35,7 @@ class FixturesTest < ActiveRecord::TestCase
|
||||||
def test_clean_fixtures
|
def test_clean_fixtures
|
||||||
FIXTURES.each do |name|
|
FIXTURES.each do |name|
|
||||||
fixtures = nil
|
fixtures = nil
|
||||||
assert_nothing_raised { fixtures = create_fixtures(name) }
|
assert_nothing_raised { fixtures = create_fixtures(name).first }
|
||||||
assert_kind_of(Fixtures, fixtures)
|
assert_kind_of(Fixtures, fixtures)
|
||||||
fixtures.each { |_name, fixture|
|
fixtures.each { |_name, fixture|
|
||||||
fixture.each { |key, value|
|
fixture.each { |key, value|
|
||||||
|
@ -53,7 +53,7 @@ class FixturesTest < ActiveRecord::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_attributes
|
def test_attributes
|
||||||
topics = create_fixtures("topics")
|
topics = create_fixtures("topics").first
|
||||||
assert_equal("The First Topic", topics["first"]["title"])
|
assert_equal("The First Topic", topics["first"]["title"])
|
||||||
assert_nil(topics["second"]["author_email_address"])
|
assert_nil(topics["second"]["author_email_address"])
|
||||||
end
|
end
|
||||||
|
@ -127,7 +127,7 @@ class FixturesTest < ActiveRecord::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_instantiation
|
def test_instantiation
|
||||||
topics = create_fixtures("topics")
|
topics = create_fixtures("topics").first
|
||||||
assert_kind_of Topic, topics["first"].find
|
assert_kind_of Topic, topics["first"].find
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -245,7 +245,7 @@ if Account.connection.respond_to?(:reset_pk_sequence!)
|
||||||
|
|
||||||
def test_create_fixtures_resets_sequences_when_not_cached
|
def test_create_fixtures_resets_sequences_when_not_cached
|
||||||
@instances.each do |instance|
|
@instances.each do |instance|
|
||||||
max_id = create_fixtures(instance.class.table_name).fixtures.inject(0) do |_max_id, (_, fixture)|
|
max_id = create_fixtures(instance.class.table_name).first.fixtures.inject(0) do |_max_id, (_, fixture)|
|
||||||
fixture_id = fixture['id'].to_i
|
fixture_id = fixture['id'].to_i
|
||||||
fixture_id > _max_id ? fixture_id : _max_id
|
fixture_id > _max_id ? fixture_id : _max_id
|
||||||
end
|
end
|
||||||
|
@ -509,7 +509,7 @@ class FasterFixturesTest < ActiveRecord::TestCase
|
||||||
fixtures :categories, :authors
|
fixtures :categories, :authors
|
||||||
|
|
||||||
def load_extra_fixture(name)
|
def load_extra_fixture(name)
|
||||||
fixture = create_fixtures(name)
|
fixture = create_fixtures(name).first
|
||||||
assert fixture.is_a?(Fixtures)
|
assert fixture.is_a?(Fixtures)
|
||||||
@loaded_fixtures[fixture.table_name] = fixture
|
@loaded_fixtures[fixture.table_name] = fixture
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue