From 6e6aa3f422d6a3400525f9438166f5dd3674b9c5 Mon Sep 17 00:00:00 2001 From: Ken Collins Date: Mon, 11 May 2009 23:22:20 -0400 Subject: [PATCH] Reimplement Fixtures.identify so that it consistently generates identities across ruby versions. --- activerecord/lib/active_record/fixtures.rb | 4 +++- activerecord/test/cases/fixtures_test.rb | 5 +++++ 2 files changed, 8 insertions(+), 1 deletions(-) diff --git a/activerecord/lib/active_record/fixtures.rb b/activerecord/lib/active_record/fixtures.rb index c650111..8f68f40 100644 --- a/activerecord/lib/active_record/fixtures.rb +++ b/activerecord/lib/active_record/fixtures.rb @@ -1,6 +1,7 @@ require 'erb' require 'yaml' require 'csv' +require 'zlib' require 'active_support/dependencies' require 'active_support/test_case' @@ -433,6 +434,7 @@ end # Any fixture labeled "DEFAULTS" is safely ignored. class Fixtures < (RUBY_VERSION < '1.9' ? YAML::Omap : Hash) + MAX_ID = 2 ** 31 - 1 DEFAULT_FILTER_RE = /\.ya?ml$/ @@all_cached_fixtures = {} @@ -528,7 +530,7 @@ class Fixtures < (RUBY_VERSION < '1.9' ? YAML::Omap : Hash) # be a positive integer, and will always be the same for a given # label, assuming the same OS, platform, and version of Ruby. def self.identify(label) - label.to_s.hash.abs + Zlib.crc32(label.to_s) % MAX_ID end attr_reader :table_name, :name diff --git a/activerecord/test/cases/fixtures_test.rb b/activerecord/test/cases/fixtures_test.rb index 252bf4f..5ea76e9 100644 --- a/activerecord/test/cases/fixtures_test.rb +++ b/activerecord/test/cases/fixtures_test.rb @@ -517,6 +517,11 @@ class FoxyFixturesTest < ActiveRecord::TestCase def test_identifies_symbols assert_equal(Fixtures.identify(:foo), Fixtures.identify(:foo)) end + + def test_identifies_consistently + assert_equal 1281023246, Fixtures.identify(:ruby) + assert_equal 2140105598, Fixtures.identify(:sapphire_2) + end TIMESTAMP_COLUMNS = %w(created_at created_on updated_at updated_on) -- 1.6.1