Merge pull request #7109 from CodeMonk/pkg_version_fix
Fix for when version is nil
This commit is contained in:
commit
89fd3cc234
@ -36,7 +36,10 @@ class PkgVersion
|
||||
def <=>(other)
|
||||
return unless other.is_a?(PkgVersion)
|
||||
|
||||
(version <=> other.version).nonzero? || revision <=> other.revision
|
||||
version_comparison = (version <=> other.version)
|
||||
return if version_comparison.nil?
|
||||
|
||||
version_comparison.nonzero? || revision <=> other.revision
|
||||
end
|
||||
alias eql? ==
|
||||
|
||||
|
||||
@ -54,6 +54,11 @@ describe PkgVersion do
|
||||
describe "#<=>" do
|
||||
it "returns nil if the comparison fails" do
|
||||
expect(described_class.new(Version.create("1.0"), 0) <=> Object.new).to be nil
|
||||
expect(Object.new <=> described_class.new(Version.create("1.0"), 0)).to be nil
|
||||
expect(Object.new <=> described_class.new(Version.create("1.0"), 0)).to be nil
|
||||
expect(described_class.new(Version.create("1.0"), 0) <=> nil).to be nil
|
||||
# This one used to fail due to dereferencing a null `self`
|
||||
expect(described_class.new(nil, 0) <=> described_class.new(Version.create("1.0"), 0)).to be nil
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user