aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/fixtures_test.rb
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2007-10-26 05:56:46 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2007-10-26 05:56:46 +0000
commit49eafd8c3620bf8e46d21d447fc634a12c8280ab (patch)
tree5e76c1587d3e3db619944091923659846ecede51 /activerecord/test/fixtures_test.rb
parent742694e0eb1abd049aa2a4eadbc7a93591c65db4 (diff)
downloadrails-49eafd8c3620bf8e46d21d447fc634a12c8280ab.tar.gz
rails-49eafd8c3620bf8e46d21d447fc634a12c8280ab.tar.bz2
rails-49eafd8c3620bf8e46d21d447fc634a12c8280ab.zip
Foxy fixtures. Adapter#disable_referential_integrity. Closes #9981.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8036 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test/fixtures_test.rb')
-rwxr-xr-xactiverecord/test/fixtures_test.rb83
1 files changed, 83 insertions, 0 deletions
diff --git a/activerecord/test/fixtures_test.rb b/activerecord/test/fixtures_test.rb
index f35e1ef2c7..2bc72d0b4e 100755
--- a/activerecord/test/fixtures_test.rb
+++ b/activerecord/test/fixtures_test.rb
@@ -7,6 +7,9 @@ require 'fixtures/reply'
require 'fixtures/joke'
require 'fixtures/course'
require 'fixtures/category'
+require 'fixtures/parrot'
+require 'fixtures/pirate'
+require 'fixtures/treasure'
class FixturesTest < Test::Unit::TestCase
self.use_instantiated_fixtures = true
@@ -446,3 +449,83 @@ class FasterFixturesTest < Test::Unit::TestCase
assert_equal 'Welcome to the weblog', posts(:welcome).title
end
end
+
+class FoxyFixturesTest < Test::Unit::TestCase
+ fixtures :parrots, :parrots_pirates, :pirates, :treasures
+
+ def test_identifies_strings
+ assert_equal(Fixtures.identify("foo"), Fixtures.identify("foo"))
+ assert_not_equal(Fixtures.identify("foo"), Fixtures.identify("FOO"))
+ end
+
+ def test_identifies_symbols
+ assert_equal(Fixtures.identify(:foo), Fixtures.identify(:foo))
+ end
+
+ TIMESTAMP_COLUMNS = %w(created_at created_on updated_at updated_on)
+
+ def test_populates_timestamp_columns
+ TIMESTAMP_COLUMNS.each do |property|
+ assert_not_nil(parrots(:george).send(property), "should set #{property}")
+ end
+ end
+
+ def test_populates_all_columns_with_the_same_time
+ last = nil
+
+ TIMESTAMP_COLUMNS.each do |property|
+ current = parrots(:george).send(property)
+ last ||= current
+
+ assert_equal(last, current)
+ last = current
+ end
+ end
+
+ def test_only_populates_columns_that_exist
+ assert_not_nil(pirates(:blackbeard).created_on)
+ assert_not_nil(pirates(:blackbeard).updated_on)
+ end
+
+ def test_preserves_existing_fixture_data
+ assert_equal(2.weeks.ago.to_date, pirates(:redbeard).created_on.to_date)
+ assert_equal(2.weeks.ago.to_date, pirates(:redbeard).updated_on.to_date)
+ end
+
+ def test_generates_unique_ids
+ assert_not_nil(parrots(:george).id)
+ assert_not_equal(parrots(:george).id, parrots(:louis).id)
+ end
+
+ def test_resolves_belongs_to_symbols
+ assert_equal(parrots(:george), pirates(:blackbeard).parrot)
+ end
+
+ def test_supports_join_tables
+ assert(pirates(:blackbeard).parrots.include?(parrots(:george)))
+ assert(pirates(:blackbeard).parrots.include?(parrots(:louis)))
+ assert(parrots(:george).pirates.include?(pirates(:blackbeard)))
+ end
+
+ def test_supports_inline_habtm
+ assert(parrots(:george).treasures.include?(treasures(:diamond)))
+ assert(parrots(:george).treasures.include?(treasures(:sapphire)))
+ assert(!parrots(:george).treasures.include?(treasures(:ruby)))
+ end
+
+ def test_supports_yaml_arrays
+ assert(parrots(:louis).treasures.include?(treasures(:diamond)))
+ assert(parrots(:louis).treasures.include?(treasures(:sapphire)))
+ end
+
+ def test_strips_DEFAULTS_key
+ assert_raise(StandardError) { parrots(:DEFAULTS) }
+
+ # this lets us do YAML defaults and not have an extra fixture entry
+ %w(sapphire ruby).each { |t| assert(parrots(:davey).treasures.include?(treasures(t))) }
+ end
+
+ def test_supports_label_interpolation
+ assert_equal("frederick", parrots(:frederick).name)
+ end
+end