@@ -804,17 +804,24 module Redmine | |||
|
804 | 804 | projects.map {|project| possible_values_options(custom_field, project)}.reduce(:&) || [] |
|
805 | 805 | elsif object.respond_to?(:project) && object.project |
|
806 | 806 | scope = object.project.shared_versions |
|
807 | if !all_statuses && custom_field.version_status.is_a?(Array) | |
|
808 | statuses = custom_field.version_status.map(&:to_s).reject(&:blank?) | |
|
809 | if statuses.any? | |
|
810 | scope = scope.where(:status => statuses.map(&:to_s)) | |
|
811 | end | |
|
812 | end | |
|
813 | scope.sort.collect {|u| [u.to_s, u.id.to_s]} | |
|
807 | filtered_versions_options(custom_field, scope, all_statuses) | |
|
808 | elsif object.nil? | |
|
809 | scope = Version.visible.where(:sharing => 'system') | |
|
810 | filtered_versions_options(custom_field, scope, all_statuses) | |
|
814 | 811 | else |
|
815 | 812 | [] |
|
816 | 813 | end |
|
817 | 814 | end |
|
815 | ||
|
816 | def filtered_versions_options(custom_field, scope, all_statuses=false) | |
|
817 | if !all_statuses && custom_field.version_status.is_a?(Array) | |
|
818 | statuses = custom_field.version_status.map(&:to_s).reject(&:blank?) | |
|
819 | if statuses.any? | |
|
820 | scope = scope.where(:status => statuses.map(&:to_s)) | |
|
821 | end | |
|
822 | end | |
|
823 | scope.sort.collect{|u| [u.to_s, u.id.to_s] } | |
|
824 | end | |
|
818 | 825 | end |
|
819 | 826 | end |
|
820 | 827 | end |
@@ -25,6 +25,7 class CustomFieldVersionFormatTest < ActiveSupport::TestCase | |||
|
25 | 25 | end |
|
26 | 26 | |
|
27 | 27 | def test_possible_values_options_with_no_arguments |
|
28 | Version.delete_all | |
|
28 | 29 | assert_equal [], @field.possible_values_options |
|
29 | 30 | assert_equal [], @field.possible_values_options(nil) |
|
30 | 31 | end |
@@ -51,6 +51,15 class Redmine::VersionFieldFormatTest < ActionView::TestCase | |||
|
51 | 51 | |
|
52 | 52 | assert_equal expected, field.possible_values_options(project).map(&:first) |
|
53 | 53 | end |
|
54 | ||
|
55 | def test_possible_values_options_should_return_system_shared_versions_without_project | |
|
56 | field = IssueCustomField.new(:field_format => 'version') | |
|
57 | version = Version.generate!(:project => Project.find(1), :status => 'open', :sharing => 'system') | |
|
58 | ||
|
59 | expected = Version.visible.where(:sharing => 'system').sort.map(&:name) | |
|
60 | assert_include version.name, expected | |
|
61 | assert_equal expected, field.possible_values_options.map(&:first) | |
|
62 | end | |
|
54 | 63 | |
|
55 | 64 | def test_possible_values_options_should_return_project_versions_with_selected_status |
|
56 | 65 | field = IssueCustomField.new(:field_format => 'version', :version_status => ["open"]) |
General Comments 0
You need to be logged in to leave comments.
Login now