Permalink
Browse files

Restore Gem::Version::new behavior from < 2.1

Gem::Version::new used to return the same class as the input object but
now returns a Gem::Version if called with the same input from a
subclass.  This broke backward compatibility.

This broke from #447 which was a performance improvement change.
This commit maintains the same behavior except when Gem::Version was
subclassed and the version cache (which reduces GC) is skipped.

See #447 for the original commits

Fixes #805
  • Loading branch information...
1 parent 6bc4913 commit 77f75f4e5b3e8ac62f611942dd03794f0e2ee7f2 @drbrain drbrain committed Feb 4, 2014
Showing with 14 additions and 0 deletions.
  1. +2 −0 History.txt
  2. +2 −0 lib/rubygems/version.rb
  3. +10 −0 test/rubygems/test_gem_version.rb
View
@@ -24,6 +24,8 @@ Bug fixes:
directory. Pull request #801 by Brian Fletcher.
* RubyGems bin stubs now ignore non-versions. This allows RubyGems bin stubs
to list file names like "_foo_". Issue #799 by Postmodern.
+* Restored behavior of Gem::Version::new when subclassed. Issue #805 by
+ Sergio Rubio.
=== 2.2.1 / 2014-01-06
View
@@ -189,6 +189,8 @@ def self.create input
@@all = {}
def self.new version # :nodoc:
+ return super unless Gem::VERSION == self.class
+
@@all[version] ||= super
end
@@ -3,6 +3,9 @@
class TestGemVersion < Gem::TestCase
+ class V < ::Gem::Version
+ end
+
def test_bump
assert_bumped_version_equal "5.3", "5.2.4"
end
@@ -37,6 +40,13 @@ def test_class_create
assert_equal v('1.1'), Gem::Version.create(ver)
end
+ def test_class_new_subclass
+ v1 = Gem::Version.new '1'
+ v2 = V.new '1'
+
+ refute_same v1, v2
+ end
+
def test_eql_eh
assert_version_eql "1.2", "1.2"
refute_version_eql "1.2", "1.2.0"

0 comments on commit 77f75f4

Please sign in to comment.