mirror of
https://github.com/redmine/redmine.git
synced 2026-05-06 08:37:35 +02:00
Merged custom fields format refactoring.
git-svn-id: http://svn.redmine.org/redmine/trunk@12400 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -63,12 +63,12 @@ class CustomFieldTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
def test_field_format_validation_should_accept_formats_added_at_runtime
|
||||
Redmine::CustomFieldFormat.register 'foobar'
|
||||
Redmine::FieldFormat.add 'foobar', Class.new(Redmine::FieldFormat::Base)
|
||||
|
||||
field = CustomField.new(:name => 'Some Custom Field', :field_format => 'foobar')
|
||||
assert field.valid?, 'field should be valid'
|
||||
ensure
|
||||
Redmine::CustomFieldFormat.delete 'foobar'
|
||||
Redmine::FieldFormat.delete 'foobar'
|
||||
end
|
||||
|
||||
def test_should_not_change_field_format_of_existing_custom_field
|
||||
@@ -293,4 +293,18 @@ class CustomFieldTest < ActiveSupport::TestCase
|
||||
|
||||
assert_equal [fields[0]], CustomField.visible(User.anonymous).order("id").to_a
|
||||
end
|
||||
|
||||
def test_float_cast_blank_value_should_return_nil
|
||||
field = CustomField.new(:field_format => 'float')
|
||||
assert_equal nil, field.cast_value(nil)
|
||||
assert_equal nil, field.cast_value('')
|
||||
end
|
||||
|
||||
def test_float_cast_valid_value_should_return_float
|
||||
field = CustomField.new(:field_format => 'float')
|
||||
assert_equal 12.0, field.cast_value('12')
|
||||
assert_equal 12.5, field.cast_value('12.5')
|
||||
assert_equal 12.5, field.cast_value('+12.5')
|
||||
assert_equal -12.5, field.cast_value('-12.5')
|
||||
end
|
||||
end
|
||||
|
||||
@@ -24,23 +24,6 @@ class CustomFieldUserFormatTest < ActiveSupport::TestCase
|
||||
@field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user')
|
||||
end
|
||||
|
||||
def test_possible_values_with_no_arguments
|
||||
assert_equal [], @field.possible_values
|
||||
assert_equal [], @field.possible_values(nil)
|
||||
end
|
||||
|
||||
def test_possible_values_with_project_resource
|
||||
project = Project.find(1)
|
||||
possible_values = @field.possible_values(project.issues.first)
|
||||
assert possible_values.any?
|
||||
assert_equal project.users.sort.collect(&:id).map(&:to_s), possible_values
|
||||
end
|
||||
|
||||
def test_possible_values_with_nil_project_resource
|
||||
project = Project.find(1)
|
||||
assert_equal [], @field.possible_values(Issue.new)
|
||||
end
|
||||
|
||||
def test_possible_values_options_with_no_arguments
|
||||
assert_equal [], @field.possible_values_options
|
||||
assert_equal [], @field.possible_values_options(nil)
|
||||
|
||||
@@ -24,22 +24,6 @@ class CustomFieldVersionFormatTest < ActiveSupport::TestCase
|
||||
@field = IssueCustomField.create!(:name => 'Tester', :field_format => 'version')
|
||||
end
|
||||
|
||||
def test_possible_values_with_no_arguments
|
||||
assert_equal [], @field.possible_values
|
||||
assert_equal [], @field.possible_values(nil)
|
||||
end
|
||||
|
||||
def test_possible_values_with_project_resource
|
||||
project = Project.find(1)
|
||||
possible_values = @field.possible_values(project.issues.first)
|
||||
assert possible_values.any?
|
||||
assert_equal project.shared_versions.sort.collect(&:id).map(&:to_s), possible_values
|
||||
end
|
||||
|
||||
def test_possible_values_with_nil_project_resource
|
||||
assert_equal [], @field.possible_values(Issue.new)
|
||||
end
|
||||
|
||||
def test_possible_values_options_with_no_arguments
|
||||
assert_equal [], @field.possible_values_options
|
||||
assert_equal [], @field.possible_values_options(nil)
|
||||
|
||||
@@ -18,14 +18,15 @@
|
||||
require File.expand_path('../../../test_helper', __FILE__)
|
||||
|
||||
class CustomFieldsHelperTest < ActionView::TestCase
|
||||
include ApplicationHelper
|
||||
include CustomFieldsHelper
|
||||
include Redmine::I18n
|
||||
include ERB::Util
|
||||
|
||||
def test_format_boolean_value
|
||||
I18n.locale = 'en'
|
||||
assert_equal 'Yes', format_value('1', 'bool')
|
||||
assert_equal 'No', format_value('0', 'bool')
|
||||
assert_equal 'Yes', format_value('1', CustomField.new(:field_format => 'bool'))
|
||||
assert_equal 'No', format_value('0', CustomField.new(:field_format => 'bool'))
|
||||
end
|
||||
|
||||
def test_unknow_field_format_should_be_edited_as_string
|
||||
|
||||
55
test/unit/lib/redmine/field_format/field_format_test.rb
Normal file
55
test/unit/lib/redmine/field_format/field_format_test.rb
Normal file
@@ -0,0 +1,55 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.expand_path('../../../../../test_helper', __FILE__)
|
||||
require 'redmine/field_format'
|
||||
|
||||
class Redmine::FieldFormatTest < ActionView::TestCase
|
||||
include ApplicationHelper
|
||||
|
||||
def test_string_field_with_text_formatting_disabled_should_not_format_text
|
||||
field = IssueCustomField.new(:field_format => 'string')
|
||||
custom_value = CustomValue.new(:custom_field => field, :customized => Issue.new, :value => "*foo*")
|
||||
|
||||
assert_equal "*foo*", field.format.formatted_custom_value(self, custom_value, false)
|
||||
assert_equal "*foo*", field.format.formatted_custom_value(self, custom_value, true)
|
||||
end
|
||||
|
||||
def test_string_field_with_text_formatting_enabled_should_format_text
|
||||
field = IssueCustomField.new(:field_format => 'string', :text_formatting => 'full')
|
||||
custom_value = CustomValue.new(:custom_field => field, :customized => Issue.new, :value => "*foo*")
|
||||
|
||||
assert_equal "*foo*", field.format.formatted_custom_value(self, custom_value, false)
|
||||
assert_include "<strong>foo</strong>", field.format.formatted_custom_value(self, custom_value, true)
|
||||
end
|
||||
|
||||
def test_text_field_with_text_formatting_disabled_should_not_format_text
|
||||
field = IssueCustomField.new(:field_format => 'text')
|
||||
custom_value = CustomValue.new(:custom_field => field, :customized => Issue.new, :value => "*foo*\nbar")
|
||||
|
||||
assert_equal "*foo*\nbar", field.format.formatted_custom_value(self, custom_value, false)
|
||||
assert_include "*foo*\n<br />bar", field.format.formatted_custom_value(self, custom_value, true)
|
||||
end
|
||||
|
||||
def test_text_field_with_text_formatting_enabled_should_format_text
|
||||
field = IssueCustomField.new(:field_format => 'text', :text_formatting => 'full')
|
||||
custom_value = CustomValue.new(:custom_field => field, :customized => Issue.new, :value => "*foo*\nbar")
|
||||
|
||||
assert_equal "*foo*\nbar", field.format.formatted_custom_value(self, custom_value, false)
|
||||
assert_include "<strong>foo</strong>", field.format.formatted_custom_value(self, custom_value, true)
|
||||
end
|
||||
end
|
||||
79
test/unit/lib/redmine/field_format/link_format_test.rb
Normal file
79
test/unit/lib/redmine/field_format/link_format_test.rb
Normal file
@@ -0,0 +1,79 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.expand_path('../../../../../test_helper', __FILE__)
|
||||
require 'redmine/field_format'
|
||||
|
||||
class Redmine::LinkFieldFormatTest < ActionView::TestCase
|
||||
include ApplicationHelper
|
||||
|
||||
def test_link_field_should_substitute_value
|
||||
field = IssueCustomField.new(:field_format => 'link', :url_pattern => 'http://foo/%value%')
|
||||
custom_value = CustomValue.new(:custom_field => field, :customized => Issue.new, :value => "bar")
|
||||
|
||||
assert_equal "bar", field.format.formatted_custom_value(self, custom_value, false)
|
||||
assert_equal '<a href="http://foo/bar">bar</a>', field.format.formatted_custom_value(self, custom_value, true)
|
||||
end
|
||||
|
||||
def test_link_field_should_substitue_object_id_in_url
|
||||
object = Issue.new
|
||||
object.stubs(:id).returns(10)
|
||||
|
||||
field = IssueCustomField.new(:field_format => 'link', :url_pattern => 'http://foo/%id%')
|
||||
custom_value = CustomValue.new(:custom_field => field, :customized => object, :value => "bar")
|
||||
|
||||
assert_equal "bar", field.format.formatted_custom_value(self, custom_value, false)
|
||||
assert_equal '<a href="http://foo/10">bar</a>', field.format.formatted_custom_value(self, custom_value, true)
|
||||
end
|
||||
|
||||
def test_link_field_should_substitue_project_id_in_url
|
||||
project = Project.new
|
||||
project.stubs(:id).returns(52)
|
||||
object = Issue.new
|
||||
object.stubs(:project).returns(project)
|
||||
|
||||
field = IssueCustomField.new(:field_format => 'link', :url_pattern => 'http://foo/%project_id%')
|
||||
custom_value = CustomValue.new(:custom_field => field, :customized => object, :value => "bar")
|
||||
|
||||
assert_equal "bar", field.format.formatted_custom_value(self, custom_value, false)
|
||||
assert_equal '<a href="http://foo/52">bar</a>', field.format.formatted_custom_value(self, custom_value, true)
|
||||
end
|
||||
|
||||
def test_link_field_should_substitue_regexp_groups
|
||||
field = IssueCustomField.new(:field_format => 'link', :regexp => /^(.+)-(.+)$/, :url_pattern => 'http://foo/%m2%/%m1%')
|
||||
custom_value = CustomValue.new(:custom_field => field, :customized => Issue.new, :value => "56-142")
|
||||
|
||||
assert_equal "56-142", field.format.formatted_custom_value(self, custom_value, false)
|
||||
assert_equal '<a href="http://foo/142/56">56-142</a>', field.format.formatted_custom_value(self, custom_value, true)
|
||||
end
|
||||
|
||||
def test_link_field_without_url_pattern_should_link_to_value
|
||||
field = IssueCustomField.new(:field_format => 'link')
|
||||
custom_value = CustomValue.new(:custom_field => field, :customized => Issue.new, :value => "http://foo/bar")
|
||||
|
||||
assert_equal "http://foo/bar", field.format.formatted_custom_value(self, custom_value, false)
|
||||
assert_equal '<a href="http://foo/bar">http://foo/bar</a>', field.format.formatted_custom_value(self, custom_value, true)
|
||||
end
|
||||
|
||||
def test_link_field_without_url_pattern_should_link_to_value_with_http_by_default
|
||||
field = IssueCustomField.new(:field_format => 'link')
|
||||
custom_value = CustomValue.new(:custom_field => field, :customized => Issue.new, :value => "foo.bar")
|
||||
|
||||
assert_equal "foo.bar", field.format.formatted_custom_value(self, custom_value, false)
|
||||
assert_equal '<a href="http://foo.bar">foo.bar</a>', field.format.formatted_custom_value(self, custom_value, true)
|
||||
end
|
||||
end
|
||||
135
test/unit/lib/redmine/field_format/list_format_test.rb
Normal file
135
test/unit/lib/redmine/field_format/list_format_test.rb
Normal file
@@ -0,0 +1,135 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.expand_path('../../../../../test_helper', __FILE__)
|
||||
require 'redmine/field_format'
|
||||
|
||||
class Redmine::ListFieldFormatTest < ActionView::TestCase
|
||||
include ApplicationHelper
|
||||
include Redmine::I18n
|
||||
|
||||
def setup
|
||||
set_language_if_valid 'en'
|
||||
end
|
||||
|
||||
def test_possible_existing_value_should_be_valid
|
||||
field = GroupCustomField.create!(:name => 'List', :field_format => 'list', :possible_values => ['Foo', 'Bar'])
|
||||
group = Group.new(:name => 'Group')
|
||||
group.custom_field_values = {field.id => 'Baz'}
|
||||
assert group.save(:validate => false)
|
||||
|
||||
group = Group.order('id DESC').first
|
||||
assert_equal ['Foo', 'Bar', 'Baz'], field.possible_custom_value_options(group.custom_value_for(field))
|
||||
assert group.valid?
|
||||
end
|
||||
|
||||
def test_edit_tag_should_have_id_and_name
|
||||
field = IssueCustomField.new(:field_format => 'list', :possible_values => ['Foo', 'Bar'], :is_required => false)
|
||||
value = CustomFieldValue.new(:custom_field => field, :customized => Issue.new)
|
||||
|
||||
tag = field.format.edit_tag(self, 'abc', 'xyz', value)
|
||||
assert_select_in tag, 'select[id=abc][name=xyz]'
|
||||
end
|
||||
|
||||
def test_edit_tag_should_contain_possible_values
|
||||
field = IssueCustomField.new(:field_format => 'list', :possible_values => ['Foo', 'Bar'], :is_required => false)
|
||||
value = CustomFieldValue.new(:custom_field => field, :customized => Issue.new)
|
||||
|
||||
tag = field.format.edit_tag(self, 'id', 'name', value)
|
||||
assert_select_in tag, 'select' do
|
||||
assert_select 'option', 3
|
||||
assert_select 'option[value=]'
|
||||
assert_select 'option[value=Foo]', :text => 'Foo'
|
||||
assert_select 'option[value=Bar]', :text => 'Bar'
|
||||
end
|
||||
end
|
||||
|
||||
def test_edit_tag_should_select_current_value
|
||||
field = IssueCustomField.new(:field_format => 'list', :possible_values => ['Foo', 'Bar'], :is_required => false)
|
||||
value = CustomFieldValue.new(:custom_field => field, :customized => Issue.new, :value => 'Bar')
|
||||
|
||||
tag = field.format.edit_tag(self, 'id', 'name', value)
|
||||
assert_select_in tag, 'select' do
|
||||
assert_select 'option[selected=selected]', 1
|
||||
assert_select 'option[value=Bar][selected=selected]', :text => 'Bar'
|
||||
end
|
||||
end
|
||||
|
||||
def test_edit_tag_with_multiple_should_select_current_values
|
||||
field = IssueCustomField.new(:field_format => 'list', :possible_values => ['Foo', 'Bar', 'Baz'], :is_required => false,
|
||||
:multiple => true)
|
||||
value = CustomFieldValue.new(:custom_field => field, :customized => Issue.new, :value => ['Bar', 'Baz'])
|
||||
|
||||
tag = field.format.edit_tag(self, 'id', 'name', value)
|
||||
assert_select_in tag, 'select[multiple=multiple]' do
|
||||
assert_select 'option[selected=selected]', 2
|
||||
assert_select 'option[value=Bar][selected=selected]', :text => 'Bar'
|
||||
assert_select 'option[value=Baz][selected=selected]', :text => 'Baz'
|
||||
end
|
||||
end
|
||||
|
||||
def test_edit_tag_with_check_box_style_should_contain_possible_values
|
||||
field = IssueCustomField.new(:field_format => 'list', :possible_values => ['Foo', 'Bar'], :is_required => false,
|
||||
:edit_tag_style => 'check_box')
|
||||
value = CustomFieldValue.new(:custom_field => field, :customized => Issue.new)
|
||||
|
||||
tag = field.format.edit_tag(self, 'id', 'name', value)
|
||||
assert_select_in tag, 'span' do
|
||||
assert_select 'input[type=radio]', 3
|
||||
assert_select 'label', :text => '(none)' do
|
||||
assert_select 'input[value=]'
|
||||
end
|
||||
assert_select 'label', :text => 'Foo' do
|
||||
assert_select 'input[value=Foo]'
|
||||
end
|
||||
assert_select 'label', :text => 'Bar' do
|
||||
assert_select 'input[value=Bar]'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_edit_tag_with_check_box_style_should_select_current_value
|
||||
field = IssueCustomField.new(:field_format => 'list', :possible_values => ['Foo', 'Bar'], :is_required => false,
|
||||
:edit_tag_style => 'check_box')
|
||||
value = CustomFieldValue.new(:custom_field => field, :customized => Issue.new, :value => 'Bar')
|
||||
|
||||
tag = field.format.edit_tag(self, 'id', 'name', value)
|
||||
assert_select_in tag, 'span' do
|
||||
assert_select 'input[type=radio][checked=checked]', 1
|
||||
assert_select 'label', :text => 'Bar' do
|
||||
assert_select 'input[value=Bar][checked=checked]'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_edit_tag_with_check_box_style_and_multiple_should_select_current_values
|
||||
field = IssueCustomField.new(:field_format => 'list', :possible_values => ['Foo', 'Bar', 'Baz'], :is_required => false,
|
||||
:multiple => true, :edit_tag_style => 'check_box')
|
||||
value = CustomFieldValue.new(:custom_field => field, :customized => Issue.new, :value => ['Bar', 'Baz'])
|
||||
|
||||
tag = field.format.edit_tag(self, 'id', 'name', value)
|
||||
assert_select_in tag, 'span' do
|
||||
assert_select 'input[type=checkbox][checked=checked]', 2
|
||||
assert_select 'label', :text => 'Bar' do
|
||||
assert_select 'input[value=Bar][checked=checked]'
|
||||
end
|
||||
assert_select 'label', :text => 'Baz' do
|
||||
assert_select 'input[value=Baz][checked=checked]'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
60
test/unit/lib/redmine/field_format/user_field_format_test.rb
Normal file
60
test/unit/lib/redmine/field_format/user_field_format_test.rb
Normal file
@@ -0,0 +1,60 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.expand_path('../../../../../test_helper', __FILE__)
|
||||
require 'redmine/field_format'
|
||||
|
||||
class Redmine::UserFieldFormatTest < ActionView::TestCase
|
||||
include ApplicationHelper
|
||||
|
||||
fixtures :projects, :roles, :users, :members, :member_roles
|
||||
|
||||
def test_user_role_should_reject_blank_values
|
||||
field = IssueCustomField.new(:name => 'Foo', :field_format => 'user', :user_role => ["1", ""])
|
||||
field.save!
|
||||
assert_equal ["1"], field.user_role
|
||||
end
|
||||
|
||||
def test_existing_values_should_be_valid
|
||||
field = IssueCustomField.create!(:name => 'Foo', :field_format => 'user', :is_for_all => true, :trackers => Tracker.all)
|
||||
project = Project.generate!
|
||||
user = User.generate!
|
||||
User.add_to_project(user, project, Role.find_by_name('Manager'))
|
||||
issue = Issue.generate!(:project_id => project.id, :tracker_id => 1, :custom_field_values => {field.id => user.id})
|
||||
|
||||
field.user_role = [Role.find_by_name('Developer').id]
|
||||
field.save!
|
||||
|
||||
issue = Issue.order('id DESC').first
|
||||
assert_include [user.name, user.id.to_s], field.possible_custom_value_options(issue.custom_value_for(field))
|
||||
assert issue.valid?
|
||||
end
|
||||
|
||||
def test_possible_values_options_should_return_project_members
|
||||
field = IssueCustomField.new(:field_format => 'user')
|
||||
project = Project.find(1)
|
||||
|
||||
assert_equal ['Dave Lopper', 'John Smith'], field.possible_values_options(project).map(&:first)
|
||||
end
|
||||
|
||||
def test_possible_values_options_should_return_project_members_with_selected_role
|
||||
field = IssueCustomField.new(:field_format => 'user', :user_role => ["2"])
|
||||
project = Project.find(1)
|
||||
|
||||
assert_equal ['Dave Lopper'], field.possible_values_options(project).map(&:first)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,61 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.expand_path('../../../../../test_helper', __FILE__)
|
||||
require 'redmine/field_format'
|
||||
|
||||
class Redmine::VersionFieldFormatTest < ActionView::TestCase
|
||||
include ApplicationHelper
|
||||
|
||||
fixtures :projects, :versions, :trackers
|
||||
|
||||
def test_version_status_should_reject_blank_values
|
||||
field = IssueCustomField.new(:name => 'Foo', :field_format => 'version', :version_status => ["open", ""])
|
||||
field.save!
|
||||
assert_equal ["open"], field.version_status
|
||||
end
|
||||
|
||||
def test_existing_values_should_be_valid
|
||||
field = IssueCustomField.create!(:name => 'Foo', :field_format => 'version', :is_for_all => true, :trackers => Tracker.all)
|
||||
project = Project.generate!
|
||||
version = Version.generate!(:project => project, :status => 'open')
|
||||
issue = Issue.generate!(:project_id => project.id, :tracker_id => 1, :custom_field_values => {field.id => version.id})
|
||||
|
||||
field.version_status = ["open"]
|
||||
field.save!
|
||||
|
||||
issue = Issue.order('id DESC').first
|
||||
assert_include [version.name, version.id.to_s], field.possible_custom_value_options(issue.custom_value_for(field))
|
||||
assert issue.valid?
|
||||
end
|
||||
|
||||
def test_possible_values_options_should_return_project_versions
|
||||
field = IssueCustomField.new(:field_format => 'version')
|
||||
project = Project.find(1)
|
||||
expected = project.shared_versions.sort.map(&:name)
|
||||
|
||||
assert_equal expected, field.possible_values_options(project).map(&:first)
|
||||
end
|
||||
|
||||
def test_possible_values_options_should_return_project_versions_with_selected_status
|
||||
field = IssueCustomField.new(:field_format => 'version', :version_status => ["open"])
|
||||
project = Project.find(1)
|
||||
expected = project.shared_versions.sort.select {|v| v.status == "open"}.map(&:name)
|
||||
|
||||
assert_equal expected, field.possible_values_options(project).map(&:first)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user