aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/fixtures_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/test/fixtures_test.rb')
-rwxr-xr-xactiverecord/test/fixtures_test.rb54
1 files changed, 22 insertions, 32 deletions
diff --git a/activerecord/test/fixtures_test.rb b/activerecord/test/fixtures_test.rb
index c666005b69..66fc4ed65d 100755
--- a/activerecord/test/fixtures_test.rb
+++ b/activerecord/test/fixtures_test.rb
@@ -49,16 +49,18 @@ class FixturesTest < Test::Unit::TestCase
def test_inserts
topics = create_fixtures("topics")
- firstRow = ActiveRecord::Base.connection.select_one("SELECT * FROM topics WHERE author_name = 'David'")
- assert_equal("The First Topic", firstRow["title"])
+ first_row = ActiveRecord::Base.connection.select_one("SELECT * FROM topics WHERE author_name = 'David'")
+ assert_equal("The First Topic", first_row["title"])
- secondRow = ActiveRecord::Base.connection.select_one("SELECT * FROM topics WHERE author_name = 'Mary'")
- assert_nil(secondRow["author_email_address"])
+ second_row = ActiveRecord::Base.connection.select_one("SELECT * FROM topics WHERE author_name = 'Mary'")
+ assert_nil(second_row["author_email_address"])
end
if ActiveRecord::Base.connection.supports_migrations?
def test_inserts_with_pre_and_suffix
+ # Reset cache to make finds on the new table work
Fixtures.reset_cache
+
ActiveRecord::Base.connection.create_table :prefix_topics_suffix do |t|
t.column :title, :string
t.column :author_name, :string
@@ -83,15 +85,15 @@ class FixturesTest < Test::Unit::TestCase
topics = create_fixtures("topics")
- firstRow = ActiveRecord::Base.connection.select_one("SELECT * FROM prefix_topics_suffix WHERE author_name = 'David'")
- assert_equal("The First Topic", firstRow["title"])
+ first_row = ActiveRecord::Base.connection.select_one("SELECT * FROM prefix_topics_suffix WHERE author_name = 'David'")
+ assert_equal("The First Topic", first_row["title"])
- secondRow = ActiveRecord::Base.connection.select_one("SELECT * FROM prefix_topics_suffix WHERE author_name = 'Mary'")
- assert_nil(secondRow["author_email_address"])
+ second_row = ActiveRecord::Base.connection.select_one("SELECT * FROM prefix_topics_suffix WHERE author_name = 'Mary'")
+ assert_nil(second_row["author_email_address"])
ensure
# Restore prefix/suffix to its previous values
- ActiveRecord::Base.table_name_prefix = old_prefix
- ActiveRecord::Base.table_name_suffix = old_suffix
+ ActiveRecord::Base.table_name_prefix = old_prefix
+ ActiveRecord::Base.table_name_suffix = old_suffix
ActiveRecord::Base.connection.drop_table :prefix_topics_suffix rescue nil
end
@@ -200,6 +202,7 @@ if Account.connection.respond_to?(:reset_pk_sequence!)
def setup
@instances = [Account.new(:credit_limit => 50), Company.new(:name => 'RoR Consulting')]
+ Fixtures.reset_cache # make sure tables get reinitialized
end
def test_resets_to_min_pk_with_specified_pk_and_sequence
@@ -224,7 +227,7 @@ if Account.connection.respond_to?(:reset_pk_sequence!)
end
end
- def test_create_fixtures_resets_sequences
+ def test_create_fixtures_resets_sequences_when_not_cached
@instances.each do |instance|
max_id = create_fixtures(instance.class.table_name).inject(0) do |max_id, (name, fixture)|
fixture_id = fixture['id'].to_i
@@ -239,7 +242,6 @@ if Account.connection.respond_to?(:reset_pk_sequence!)
end
end
-
class FixturesWithoutInstantiationTest < Test::Unit::TestCase
self.use_instantiated_fixtures = false
fixtures :topics, :developers, :accounts
@@ -275,7 +277,6 @@ class FixturesWithoutInstantiationTest < Test::Unit::TestCase
end
end
-
class FixturesWithoutInstanceInstantiationTest < Test::Unit::TestCase
self.use_instantiated_fixtures = true
self.use_instantiated_fixtures = :no_instances
@@ -290,7 +291,6 @@ class FixturesWithoutInstanceInstantiationTest < Test::Unit::TestCase
end
end
-
class TransactionalFixturesTest < Test::Unit::TestCase
self.use_instantiated_fixtures = true
self.use_transactional_fixtures = true
@@ -307,7 +307,6 @@ class TransactionalFixturesTest < Test::Unit::TestCase
end
end
-
class MultipleFixturesTest < Test::Unit::TestCase
fixtures :topics
fixtures :developers, :accounts
@@ -317,7 +316,6 @@ class MultipleFixturesTest < Test::Unit::TestCase
end
end
-
class OverlappingFixturesTest < Test::Unit::TestCase
fixtures :topics, :developers
fixtures :developers, :accounts
@@ -327,7 +325,6 @@ class OverlappingFixturesTest < Test::Unit::TestCase
end
end
-
class ForeignKeyFixturesTest < Test::Unit::TestCase
fixtures :fk_test_has_pk, :fk_test_has_fk
@@ -347,7 +344,7 @@ end
class SetTableNameFixturesTest < Test::Unit::TestCase
set_fixture_class :funny_jokes => 'Joke'
fixtures :funny_jokes
-
+
def test_table_method
assert_kind_of Joke, funny_jokes(:a_joke)
end
@@ -356,7 +353,7 @@ end
class CustomConnectionFixturesTest < Test::Unit::TestCase
set_fixture_class :courses => Course
fixtures :courses
-
+
def test_connection
assert_kind_of Course, courses(:ruby)
assert_equal Course.connection, courses(:ruby).connection
@@ -382,17 +379,15 @@ class CheckEscapedYamlFixturesTest < Test::Unit::TestCase
end
end
-class DevelopersProject; end;
-
+class DevelopersProject; end
class ManyToManyFixturesWithClassDefined < Test::Unit::TestCase
fixtures :developers_projects
-
+
def test_this_should_run_cleanly
assert true
end
end
-
class FixturesBrokenRollbackTest < Test::Unit::TestCase
def blank_setup; end
alias_method :ar_setup_with_fixtures, :setup_with_fixtures
@@ -429,27 +424,22 @@ end
class FasterFixturesTest < Test::Unit::TestCase
fixtures :categories, :authors
-
- def run(*args, &block)
- Fixtures.reset_cache
- super(*args, &block)
- end
-
+
def load_extra_fixture(name)
fixture = create_fixtures(name)
assert fixture.is_a?(Fixtures)
@loaded_fixtures[fixture.table_name] = fixture
end
-
+
def test_cache
assert Fixtures.fixture_is_cached?(ActiveRecord::Base.connection, 'categories')
assert Fixtures.fixture_is_cached?(ActiveRecord::Base.connection, 'authors')
-
+
assert_no_queries do
create_fixtures('categories')
create_fixtures('authors')
end
-
+
load_extra_fixture('posts')
assert Fixtures.fixture_is_cached?(ActiveRecord::Base.connection, 'posts')
self.class.setup_fixture_accessors('posts')