Patch #29674 » 29674_test_added.patch
lib/redmine/field_format.rb | ||
---|---|---|
740 | 740 |
options |
741 | 741 |
end |
742 | 742 | |
743 |
def validate_custom_value(custom_value) |
|
744 |
values = Array.wrap(custom_value.value).reject {|value| value.to_s == ''} |
|
745 |
invalid_values = values - possible_custom_value_options(custom_value).map(&:last) |
|
746 |
if invalid_values.any? |
|
747 |
[::I18n.t('activerecord.errors.messages.inclusion')] |
|
748 |
else |
|
749 |
[] |
|
750 |
end |
|
751 |
end |
|
752 | ||
743 | 753 |
def order_statement(custom_field) |
744 | 754 |
if target_class.respond_to?(:fields_for_order_statement) |
745 | 755 |
target_class.fields_for_order_statement(value_join_alias(custom_field)) |
test/unit/lib/redmine/field_format/list_format_test.rb | ||
---|---|---|
37 | 37 |
assert group.valid? |
38 | 38 |
end |
39 | 39 | |
40 |
def test_non_existing_value_should_be_invalid |
|
41 |
field = GroupCustomField.create!(:name => 'List', :field_format => 'list', :possible_values => ['Foo', 'Bar']) |
|
42 |
group = Group.new(:name => 'Group') |
|
43 |
group.custom_field_values = {field.id => 'Baz'} |
|
44 | ||
45 |
assert_not_include 'Baz', field.possible_custom_value_options(group.custom_value_for(field)) |
|
46 |
assert_equal false, group.valid? |
|
47 |
assert_include "List #{::I18n.t('activerecord.errors.messages.inclusion')}", group.errors.full_messages.first |
|
48 |
end |
|
49 | ||
40 | 50 |
def test_edit_tag_should_have_id_and_name |
41 | 51 |
field = IssueCustomField.new(:field_format => 'list', :possible_values => ['Foo', 'Bar'], :is_required => false) |
42 | 52 |
value = CustomFieldValue.new(:custom_field => field, :customized => Issue.new) |
test/unit/lib/redmine/field_format/user_field_format_test.rb | ||
---|---|---|
45 | 45 |
assert issue.valid? |
46 | 46 |
end |
47 | 47 | |
48 |
def test_non_existing_values_should_be_invalid |
|
49 |
field = IssueCustomField.create!(:name => 'Foo', :field_format => 'user', :is_for_all => true, :trackers => Tracker.all) |
|
50 |
project = Project.generate! |
|
51 |
user = User.generate! |
|
52 |
User.add_to_project(user, project, Role.find_by_name('Developer')) |
|
53 | ||
54 |
field.user_role = [Role.find_by_name('Manager').id] |
|
55 |
field.save! |
|
56 | ||
57 |
issue = Issue.new(:project_id => project.id, :tracker_id => 1, :custom_field_values => {field.id => user.id}) |
|
58 |
assert_not_include [user.name, user.id.to_s], field.possible_custom_value_options(issue.custom_value_for(field)) |
|
59 |
assert_equal false, issue.valid? |
|
60 |
assert_include "Foo #{::I18n.t('activerecord.errors.messages.inclusion')}", issue.errors.full_messages.first |
|
61 |
end |
|
62 | ||
48 | 63 |
def test_possible_values_options_should_return_project_members |
49 | 64 |
field = IssueCustomField.new(:field_format => 'user') |
50 | 65 |
project = Project.find(1) |
test/unit/lib/redmine/field_format/version_field_format_test.rb | ||
---|---|---|
49 | 49 |
assert issue.valid? |
50 | 50 |
end |
51 | 51 | |
52 |
def test_not_existing_values_should_be_invalid |
|
53 |
field = IssueCustomField.create!(:name => 'Foo', :field_format => 'version', :is_for_all => true, :trackers => Tracker.all) |
|
54 |
project = Project.generate! |
|
55 |
version = Version.generate!(:project => project, :status => 'closed') |
|
56 | ||
57 |
field.version_status = ["open"] |
|
58 |
field.save! |
|
59 | ||
60 |
issue = Issue.new(:project_id => project.id, :tracker_id => 1, :custom_field_values => {field.id => version.id}) |
|
61 |
assert_not_include [version.name, version.id.to_s], field.possible_custom_value_options(issue.custom_value_for(field)) |
|
62 |
assert_equal false, issue.valid? |
|
63 |
assert_include "Foo #{::I18n.t('activerecord.errors.messages.inclusion')}", issue.errors.full_messages.first |
|
64 |
end |
|
65 | ||
52 | 66 |
def test_possible_values_options_should_return_project_versions |
53 | 67 |
field = IssueCustomField.new(:field_format => 'version') |
54 | 68 |
project = Project.find(1) |
- « Previous
- 1
- 2
- Next »