Patch #38772 ยป add_type_check_in_spaceship_operators.patch
app/models/custom_field.rb | ||
---|---|---|
263 | 263 |
end |
264 | 264 | |
265 | 265 |
def <=>(field) |
266 |
return nil unless field.is_a?(CustomField) |
|
267 | ||
266 | 268 |
position <=> field.position |
267 | 269 |
end |
268 | 270 |
app/models/enumeration.rb | ||
---|---|---|
91 | 91 |
end |
92 | 92 | |
93 | 93 |
def <=>(enumeration) |
94 |
return nil unless enumeration.is_a?(Enumeration) |
|
95 | ||
94 | 96 |
position <=> enumeration.position |
95 | 97 |
end |
96 | 98 |
app/models/issue.rb | ||
---|---|---|
1435 | 1435 |
end |
1436 | 1436 | |
1437 | 1437 |
def <=>(issue) |
1438 |
return nil unless issue.is_a?(Issue) |
|
1439 | ||
1438 | 1440 |
if issue.nil? |
1439 | 1441 |
-1 |
1440 | 1442 |
elsif root_id != issue.root_id |
app/models/issue_category.rb | ||
---|---|---|
43 | 43 |
end |
44 | 44 | |
45 | 45 |
def <=>(category) |
46 |
return nil unless category.is_a?(IssueCategory) |
|
47 | ||
46 | 48 |
name <=> category.name |
47 | 49 |
end |
48 | 50 |
app/models/issue_relation.rb | ||
---|---|---|
198 | 198 |
end |
199 | 199 | |
200 | 200 |
def <=>(relation) |
201 |
return nil unless relation.is_a?(IssueRelation) |
|
202 | ||
201 | 203 |
r = TYPES[self.relation_type][:order] <=> TYPES[relation.relation_type][:order] |
202 | 204 |
r == 0 ? id <=> relation.id : r |
203 | 205 |
end |
app/models/issue_status.rb | ||
---|---|---|
82 | 82 |
end |
83 | 83 | |
84 | 84 |
def <=>(status) |
85 |
return nil unless status.is_a?(IssueStatus) |
|
86 | ||
85 | 87 |
position <=> status.position |
86 | 88 |
end |
87 | 89 |
app/models/member.rb | ||
---|---|---|
81 | 81 |
end |
82 | 82 | |
83 | 83 |
def <=>(member) |
84 |
return nil unless member.is_a?(Member) |
|
85 | ||
84 | 86 |
a, b = roles.sort, member.roles.sort |
85 | 87 |
if a == b |
86 | 88 |
if principal |
app/models/principal.rb | ||
---|---|---|
151 | 151 |
end |
152 | 152 | |
153 | 153 |
def <=>(principal) |
154 |
if principal.nil? |
|
155 |
-1 |
|
156 |
elsif self.class.name == principal.class.name |
|
154 |
# avoid an error when sorting members without roles (#10053) |
|
155 |
return -1 if principal.nil? |
|
156 |
return nil unless principal.is_a?(Principal) |
|
157 | ||
158 |
if self.class.name == principal.class.name |
|
157 | 159 |
self.to_s.casecmp(principal.to_s) |
158 | 160 |
else |
159 | 161 |
# groups after users |
app/models/project.rb | ||
---|---|---|
671 | 671 |
end |
672 | 672 | |
673 | 673 |
def <=>(project) |
674 |
return nil unless project.is_a?(Project) |
|
675 | ||
674 | 676 |
name.casecmp(project.name) |
675 | 677 |
end |
676 | 678 |
app/models/repository.rb | ||
---|---|---|
141 | 141 |
end |
142 | 142 | |
143 | 143 |
def <=>(repository) |
144 |
return nil unless repository.is_a?(Repository) |
|
145 | ||
144 | 146 |
if is_default? |
145 | 147 |
-1 |
146 | 148 |
elsif repository.is_default? |
app/models/role.rb | ||
---|---|---|
155 | 155 |
end |
156 | 156 | |
157 | 157 |
def <=>(role) |
158 |
if role
|
|
159 |
if builtin == role.builtin
|
|
160 |
position <=> role.position
|
|
161 |
else |
|
162 |
builtin <=> role.builtin
|
|
163 |
end
|
|
158 |
# returns -1 for nil since r2726
|
|
159 |
return -1 if role.nil?
|
|
160 |
return nil unless role.is_a?(Role)
|
|
161 | ||
162 |
if builtin == role.builtin
|
|
163 |
position <=> role.position
|
|
164 | 164 |
else |
165 |
-1
|
|
165 |
builtin <=> role.builtin
|
|
166 | 166 |
end |
167 | 167 |
end |
168 | 168 |
app/models/tracker.rb | ||
---|---|---|
93 | 93 |
def to_s; name end |
94 | 94 | |
95 | 95 |
def <=>(tracker) |
96 |
return nil unless tracker.is_a?(Tracker) |
|
97 | ||
96 | 98 |
position <=> tracker.position |
97 | 99 |
end |
98 | 100 |
app/models/version.rb | ||
---|---|---|
316 | 316 |
# Versions are sorted by effective_date and name |
317 | 317 |
# Those with no effective_date are at the end, sorted by name |
318 | 318 |
def <=>(version) |
319 |
return nil unless version.is_a?(Version) |
|
320 | ||
319 | 321 |
if self.effective_date |
320 | 322 |
if version.effective_date |
321 | 323 |
if self.effective_date == version.effective_date |
lib/redmine/plugin.rb | ||
---|---|---|
187 | 187 |
end |
188 | 188 | |
189 | 189 |
def <=>(plugin) |
190 |
return nil unless plugin.is_a?(Plugin) |
|
191 | ||
190 | 192 |
self.id.to_s <=> plugin.id.to_s |
191 | 193 |
end |
192 | 194 |
lib/redmine/themes.rb | ||
---|---|---|
61 | 61 |
end |
62 | 62 | |
63 | 63 |
def <=>(theme) |
64 |
return nil unless theme.is_a?(Theme) |
|
65 | ||
64 | 66 |
name <=> theme.name |
65 | 67 |
end |
66 | 68 |
test/unit/enumeration_test.rb | ||
---|---|---|
179 | 179 |
override.destroy |
180 | 180 |
assert_equal [1, 2, 3], [a, b, c].map(&:reload).map(&:position) |
181 | 181 |
end |
182 | ||
183 |
def test_spaceship_operator_with_incomparable_value_should_return_nil |
|
184 |
e = Enumeration.first |
|
185 |
assert_nil e <=> nil |
|
186 |
assert_nil e <=> 'foo' |
|
187 |
end |
|
182 | 188 |
end |