Patch #38772 ยป add_type_check_in_spaceship_operators.patch
| app/models/custom_field.rb | ||
|---|---|---|
|
end
|
||
|
def <=>(field)
|
||
|
return nil unless field.is_a?(CustomField)
|
||
|
position <=> field.position
|
||
|
end
|
||
| app/models/enumeration.rb | ||
|---|---|---|
|
end
|
||
|
def <=>(enumeration)
|
||
|
return nil unless enumeration.is_a?(Enumeration)
|
||
|
position <=> enumeration.position
|
||
|
end
|
||
| app/models/issue.rb | ||
|---|---|---|
|
end
|
||
|
def <=>(issue)
|
||
|
return nil unless issue.is_a?(Issue)
|
||
|
if issue.nil?
|
||
|
-1
|
||
|
elsif root_id != issue.root_id
|
||
| app/models/issue_category.rb | ||
|---|---|---|
|
end
|
||
|
def <=>(category)
|
||
|
return nil unless category.is_a?(IssueCategory)
|
||
|
name <=> category.name
|
||
|
end
|
||
| app/models/issue_relation.rb | ||
|---|---|---|
|
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
|
||
| app/models/issue_status.rb | ||
|---|---|---|
|
end
|
||
|
def <=>(status)
|
||
|
return nil unless status.is_a?(IssueStatus)
|
||
|
position <=> status.position
|
||
|
end
|
||
| app/models/member.rb | ||
|---|---|---|
|
end
|
||
|
def <=>(member)
|
||
|
return nil unless member.is_a?(Member)
|
||
|
a, b = roles.sort, member.roles.sort
|
||
|
if a == b
|
||
|
if principal
|
||
| app/models/principal.rb | ||
|---|---|---|
|
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
|
||
| app/models/project.rb | ||
|---|---|---|
|
end
|
||
|
def <=>(project)
|
||
|
return nil unless project.is_a?(Project)
|
||
|
name.casecmp(project.name)
|
||
|
end
|
||
| app/models/repository.rb | ||
|---|---|---|
|
end
|
||
|
def <=>(repository)
|
||
|
return nil unless repository.is_a?(Repository)
|
||
|
if is_default?
|
||
|
-1
|
||
|
elsif repository.is_default?
|
||
| app/models/role.rb | ||
|---|---|---|
|
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
|
||
| app/models/tracker.rb | ||
|---|---|---|
|
def to_s; name end
|
||
|
def <=>(tracker)
|
||
|
return nil unless tracker.is_a?(Tracker)
|
||
|
position <=> tracker.position
|
||
|
end
|
||
| app/models/version.rb | ||
|---|---|---|
|
# 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
|
||
| lib/redmine/plugin.rb | ||
|---|---|---|
|
end
|
||
|
def <=>(plugin)
|
||
|
return nil unless plugin.is_a?(Plugin)
|
||
|
self.id.to_s <=> plugin.id.to_s
|
||
|
end
|
||
| lib/redmine/themes.rb | ||
|---|---|---|
|
end
|
||
|
def <=>(theme)
|
||
|
return nil unless theme.is_a?(Theme)
|
||
|
name <=> theme.name
|
||
|
end
|
||
| test/unit/enumeration_test.rb | ||
|---|---|---|
|
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
|
||