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)
|
||||
if keys_to_fetch
|
||||
fixtures = cache_for_connection(connection).values_at(*keys_to_fetch)
|
||||
cache_for_connection(connection).values_at(*keys_to_fetch)
|
||||
else
|
||||
fixtures = cache_for_connection(connection).values
|
||||
cache_for_connection(connection).values
|
||||
end
|
||||
fixtures.size > 1 ? fixtures : fixtures.first
|
||||
end
|
||||
|
||||
def self.cache_fixtures(connection, fixtures_map)
|
||||
|
@ -554,13 +553,14 @@ class Fixtures
|
|||
attr_reader :table_name, :name, :fixtures
|
||||
|
||||
def initialize(connection, table_name, class_name, fixture_path, file_filter = DEFAULT_FILTER_RE)
|
||||
@fixtures = ActiveSupport::OrderedHash.new
|
||||
@connection = connection
|
||||
@table_name = table_name
|
||||
@fixture_path = fixture_path
|
||||
@file_filter = file_filter
|
||||
@name = table_name # preserve fixture base 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 = class_name.table_name if class_name.respond_to?(:table_name)
|
||||
@connection = class_name.connection if class_name.respond_to?(:connection)
|
||||
|
|
|
@ -35,7 +35,7 @@ class FixturesTest < ActiveRecord::TestCase
|
|||
def test_clean_fixtures
|
||||
FIXTURES.each do |name|
|
||||
fixtures = nil
|
||||
assert_nothing_raised { fixtures = create_fixtures(name) }
|
||||
assert_nothing_raised { fixtures = create_fixtures(name).first }
|
||||
assert_kind_of(Fixtures, fixtures)
|
||||
fixtures.each { |_name, fixture|
|
||||
fixture.each { |key, value|
|
||||
|
@ -53,7 +53,7 @@ class FixturesTest < ActiveRecord::TestCase
|
|||
end
|
||||
|
||||
def test_attributes
|
||||
topics = create_fixtures("topics")
|
||||
topics = create_fixtures("topics").first
|
||||
assert_equal("The First Topic", topics["first"]["title"])
|
||||
assert_nil(topics["second"]["author_email_address"])
|
||||
end
|
||||
|
@ -127,7 +127,7 @@ class FixturesTest < ActiveRecord::TestCase
|
|||
end
|
||||
|
||||
def test_instantiation
|
||||
topics = create_fixtures("topics")
|
||||
topics = create_fixtures("topics").first
|
||||
assert_kind_of Topic, topics["first"].find
|
||||
end
|
||||
|
||||
|
@ -245,7 +245,7 @@ if Account.connection.respond_to?(:reset_pk_sequence!)
|
|||
|
||||
def test_create_fixtures_resets_sequences_when_not_cached
|
||||
@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 > _max_id ? fixture_id : _max_id
|
||||
end
|
||||
|
@ -509,7 +509,7 @@ class FasterFixturesTest < ActiveRecord::TestCase
|
|||
fixtures :categories, :authors
|
||||
|
||||
def load_extra_fixture(name)
|
||||
fixture = create_fixtures(name)
|
||||
fixture = create_fixtures(name).first
|
||||
assert fixture.is_a?(Fixtures)
|
||||
@loaded_fixtures[fixture.table_name] = fixture
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue