end
def <=>(field)
+ return nil unless field.is_a?(CustomField)
+
position <=> field.position
end
end
def <=>(enumeration)
+ return nil unless enumeration.is_a?(Enumeration)
+
position <=> enumeration.position
end
end
def <=>(issue)
- if issue.nil?
- -1
- elsif root_id != issue.root_id
+ return nil unless issue.is_a?(Issue)
+
+ if root_id != issue.root_id
(root_id || 0) <=> (issue.root_id || 0)
else
(lft || 0) <=> (issue.lft || 0)
end
def <=>(category)
+ return nil unless category.is_a?(IssueCategory)
+
name <=> category.name
end
end
def <=>(relation)
+ return nil unless relation.is_a?(IssueRelation)
+
r = TYPES[self.relation_type][:order] <=> TYPES[relation.relation_type][:order]
r == 0 ? id <=> relation.id : r
end
end
def <=>(status)
+ return nil unless status.is_a?(IssueStatus)
+
position <=> status.position
end
end
def <=>(member)
+ return nil unless member.is_a?(Member)
+
a, b = roles.sort, member.roles.sort
if a == b
if principal
end
def <=>(principal)
- if principal.nil?
- -1
- elsif self.class.name == principal.class.name
+ # avoid an error when sorting members without roles (#10053)
+ return -1 if principal.nil?
+ return nil unless principal.is_a?(Principal)
+
+ if self.class.name == principal.class.name
self.to_s.casecmp(principal.to_s)
else
# groups after users
end
def <=>(project)
+ return nil unless project.is_a?(Project)
+
name.casecmp(project.name)
end
end
def <=>(repository)
+ return nil unless repository.is_a?(Repository)
+
if is_default?
-1
elsif repository.is_default?
end
def <=>(role)
- if role
- if builtin == role.builtin
- position <=> role.position
- else
- builtin <=> role.builtin
- end
+ # returns -1 for nil since r2726
+ return -1 if role.nil?
+ return nil unless role.is_a?(Role)
+
+ if builtin == role.builtin
+ position <=> role.position
else
- -1
+ builtin <=> role.builtin
end
end
def to_s; name end
def <=>(tracker)
+ return nil unless tracker.is_a?(Tracker)
+
position <=> tracker.position
end
# Versions are sorted by effective_date and name
# Those with no effective_date are at the end, sorted by name
def <=>(version)
+ return nil unless version.is_a?(Version)
+
if self.effective_date
if version.effective_date
if self.effective_date == version.effective_date
end
def <=>(plugin)
+ return nil unless plugin.is_a?(Plugin)
+
self.id.to_s <=> plugin.id.to_s
end
end
def <=>(theme)
+ return nil unless theme.is_a?(Theme)
+
name <=> theme.name
end
override.destroy
assert_equal [1, 2, 3], [a, b, c].map(&:reload).map(&:position)
end
+
+ def test_spaceship_operator_with_incomparable_value_should_return_nil
+ e = Enumeration.first
+ assert_nil e <=> nil
+ assert_nil e <=> 'foo'
+ end
end