aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKen Collins <ken@metaskills.net>2009-05-11 23:22:20 -0400
committerJeremy Kemper <jeremy@bitsweat.net>2009-05-18 13:40:45 -0700
commit87adecfef59577be17a9731245cb201ecb1b477f (patch)
tree222b26f46cf41edbc187e38ecdeecd71d522cfc0
parenta69b28a8b10fdcbb6801051e3086228b56891dbb (diff)
downloadrails-87adecfef59577be17a9731245cb201ecb1b477f.tar.gz
rails-87adecfef59577be17a9731245cb201ecb1b477f.tar.bz2
rails-87adecfef59577be17a9731245cb201ecb1b477f.zip
Reimplement Fixtures.identify so that it consistently generates identities across ruby versions.
[#2633 state:committed] Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
-rw-r--r--activerecord/lib/active_record/fixtures.rb9
-rw-r--r--activerecord/test/cases/fixtures_test.rb5
2 files changed, 10 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/fixtures.rb b/activerecord/lib/active_record/fixtures.rb
index e30fcf9a4f..721114d9d0 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'
require 'active_support/core_ext/logger'
@@ -434,6 +435,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 = {}
@@ -525,11 +527,10 @@ class Fixtures < (RUBY_VERSION < '1.9' ? YAML::Omap : Hash)
cached_fixtures(connection, table_names)
end
- # Returns a consistent identifier for +label+. This will always
- # be a positive integer, and will always be the same for a given
- # label, assuming the same OS, platform, and version of Ruby.
+ # Returns a consistent, platform-independent identifier for +label+.
+ # Identifiers are positive integers less than 2^32.
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 252bf4ff61..b07d4f3521 100644
--- a/activerecord/test/cases/fixtures_test.rb
+++ b/activerecord/test/cases/fixtures_test.rb
@@ -518,6 +518,11 @@ class FoxyFixturesTest < ActiveRecord::TestCase
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)
def test_populates_timestamp_columns