Patch #29161 ยป 0001-Use-the-id-field-as-project_key-in-ProjectCustomFiel.patch
| app/models/project_custom_field.rb | ||
|---|---|---|
| 19 | 19 |
def type_name |
| 20 | 20 |
:label_project_plural |
| 21 | 21 |
end |
| 22 | ||
| 23 |
def visibility_by_project_condition(project_key=nil, user=User.current, id_column=nil) |
|
| 24 |
project_key ||= "#{Project.table_name}.id"
|
|
| 25 |
super(project_key, user, id_column) |
|
| 26 |
end |
|
| 22 | 27 |
end |
| test/unit/custom_field_test.rb | ||
|---|---|---|
| 340 | 340 |
assert_equal 12.5, field.cast_value('+12.5')
|
| 341 | 341 |
assert_equal -12.5, field.cast_value('-12.5')
|
| 342 | 342 |
end |
| 343 | ||
| 344 |
def test_project_custom_field_visibility |
|
| 345 |
project_field = ProjectCustomField.generate!(:visible => false, :field_format => 'list', :possible_values => %w[a b c]) |
|
| 346 |
project = Project.find(3) |
|
| 347 |
project.custom_field_values = { project_field.id => 'a' }
|
|
| 348 | ||
| 349 |
# Admins can find projects with the field |
|
| 350 |
with_current_user(User.find(1)) do |
|
| 351 |
assert_includes Project.where(project_field.visibility_by_project_condition), project |
|
| 352 |
end |
|
| 353 | ||
| 354 |
# The field is not visible to normal users |
|
| 355 |
with_current_user(User.find(2)) do |
|
| 356 |
refute_includes Project.where(project_field.visibility_by_project_condition), project |
|
| 357 |
end |
|
| 358 |
end |
|
| 343 | 359 |
end |