summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2012-07-05 12:20:07 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2012-07-05 12:20:07 +0000
commit4cecc1beeda2337f50090d9fc0fe1d54fb8d54e2 (patch)
treeae525d4ae044a57c48e01462eb76e34e485ed6e3 /test
parent51a1bf90dda6bc22b29b3801fbb7139b891376e5 (diff)
downloadredmine-4cecc1beeda2337f50090d9fc0fe1d54fb8d54e2.tar.gz
redmine-4cecc1beeda2337f50090d9fc0fe1d54fb8d54e2.zip
Ability to disable standard fields on a per tracker basis (#1091).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9912 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test')
-rw-r--r--test/functional/trackers_controller_test.rb35
-rw-r--r--test/unit/issue_test.rb46
-rw-r--r--test/unit/tracker_test.rb24
3 files changed, 105 insertions, 0 deletions
diff --git a/test/functional/trackers_controller_test.rb b/test/functional/trackers_controller_test.rb
index 731d19b52..7393088ae 100644
--- a/test/functional/trackers_controller_test.rb
+++ b/test/functional/trackers_controller_test.rb
@@ -64,10 +64,21 @@ class TrackersControllerTest < ActionController::TestCase
tracker = Tracker.first(:order => 'id DESC')
assert_equal 'New tracker', tracker.name
assert_equal [1], tracker.project_ids.sort
+ assert_equal Tracker::CORE_FIELDS, tracker.core_fields
assert_equal [1, 6], tracker.custom_field_ids.sort
assert_equal 0, tracker.workflows.count
end
+ def create_with_disabled_core_fields
+ assert_difference 'Tracker.count' do
+ post :create, :tracker => { :name => 'New tracker', :core_fields => ['assigned_to_id', 'fixed_version_id', ''] }
+ end
+ assert_redirected_to :action => 'index'
+ tracker = Tracker.first(:order => 'id DESC')
+ assert_equal 'New tracker', tracker.name
+ assert_equal %w(assigned_to_id fixed_version_id), tracker.core_fields
+ end
+
def test_create_new_with_workflow_copy
assert_difference 'Tracker.count' do
post :create, :tracker => { :name => 'New tracker' }, :copy_workflow_from => 1
@@ -107,6 +118,24 @@ class TrackersControllerTest < ActionController::TestCase
:type => 'hidden'}
end
+ def test_edit_should_check_core_fields
+ tracker = Tracker.find(1)
+ tracker.core_fields = %w(assigned_to_id fixed_version_id)
+ tracker.save!
+
+ get :edit, :id => 1
+ assert_response :success
+ assert_template 'edit'
+
+ assert_select 'input[name=?][value=assigned_to_id][checked=checked]', 'tracker[core_fields][]'
+ assert_select 'input[name=?][value=fixed_version_id][checked=checked]', 'tracker[core_fields][]'
+
+ assert_select 'input[name=?][value=category_id]', 'tracker[core_fields][]'
+ assert_select 'input[name=?][value=category_id][checked=checked]', 'tracker[core_fields][]', 0
+
+ assert_select 'input[name=?][value=][type=hidden]', 'tracker[core_fields][]'
+ end
+
def test_update
put :update, :id => 1, :tracker => { :name => 'Renamed',
:project_ids => ['1', '2', ''] }
@@ -121,6 +150,12 @@ class TrackersControllerTest < ActionController::TestCase
assert Tracker.find(1).project_ids.empty?
end
+ def test_update_without_core_fields
+ put :update, :id => 1, :tracker => { :name => 'Renamed', :core_fields => [''] }
+ assert_redirected_to :action => 'index'
+ assert Tracker.find(1).core_fields.empty?
+ end
+
def test_update_with_failure
put :update, :id => 1, :tracker => { :name => '' }
assert_response :success
diff --git a/test/unit/issue_test.rb b/test/unit/issue_test.rb
index b5799f3fc..fe8bdf2ac 100644
--- a/test/unit/issue_test.rb
+++ b/test/unit/issue_test.rb
@@ -403,6 +403,52 @@ class IssueTest < ActiveSupport::TestCase
assert_equal [1, 2], issue.new_statuses_allowed_to(User.find(2)).map(&:id)
end
+ def test_safe_attributes_should_not_include_disabled_field
+ tracker = Tracker.new(:core_fields => %w(assigned_to_id fixed_version_id))
+
+ issue = Issue.new(:tracker => tracker)
+ assert_include 'tracker_id', issue.safe_attribute_names
+ assert_include 'status_id', issue.safe_attribute_names
+ assert_include 'subject', issue.safe_attribute_names
+ assert_include 'description', issue.safe_attribute_names
+ assert_include 'custom_field_values', issue.safe_attribute_names
+ assert_include 'custom_fields', issue.safe_attribute_names
+ assert_include 'lock_version', issue.safe_attribute_names
+
+ tracker.core_fields.each do |field|
+ assert_include field, issue.safe_attribute_names
+ end
+
+ tracker.disabled_core_fields.each do |field|
+ assert_not_include field, issue.safe_attribute_names
+ end
+ end
+
+ def test_safe_attributes_should_ignore_disabled_fields
+ tracker = Tracker.find(1)
+ tracker.core_fields = %w(assigned_to_id due_date)
+ tracker.save!
+
+ issue = Issue.new(:tracker => tracker)
+ issue.safe_attributes = {'start_date' => '2012-07-14', 'due_date' => '2012-07-14'}
+ assert_nil issue.start_date
+ assert_equal Date.parse('2012-07-14'), issue.due_date
+ end
+
+ def test_safe_attributes_should_accept_target_tracker_fields
+ source = Tracker.find(1)
+ source.core_fields = []
+ source.save!
+ target = Tracker.find(2)
+ target.core_fields = %w(assigned_to_id due_date)
+ target.save!
+
+ issue = Issue.new(:tracker => source)
+ issue.safe_attributes = {'tracker_id' => 2, 'due_date' => '2012-07-14'}
+ assert_equal target, issue.tracker
+ assert_equal Date.parse('2012-07-14'), issue.due_date
+ end
+
def test_copy
issue = Issue.new.copy_from(1)
assert issue.copy?
diff --git a/test/unit/tracker_test.rb b/test/unit/tracker_test.rb
index 9cf6866a9..91b259827 100644
--- a/test/unit/tracker_test.rb
+++ b/test/unit/tracker_test.rb
@@ -59,6 +59,30 @@ class TrackerTest < ActiveSupport::TestCase
assert_equal [], Tracker.new.issue_statuses
end
+ def test_core_fields_should_be_enabled_by_default
+ tracker = Tracker.new
+ assert_equal Tracker::CORE_FIELDS, tracker.core_fields
+ assert_equal [], tracker.disabled_core_fields
+ end
+
+ def test_core_fields
+ tracker = Tracker.new
+ tracker.core_fields = %w(assigned_to_id due_date)
+
+ assert_equal %w(assigned_to_id due_date), tracker.core_fields
+ assert_equal Tracker::CORE_FIELDS - %w(assigned_to_id due_date), tracker.disabled_core_fields
+ end
+
+ def test_core_fields_should_return_fields_enabled_for_any_tracker
+ trackers = []
+ trackers << Tracker.new(:core_fields => %w(assigned_to_id due_date))
+ trackers << Tracker.new(:core_fields => %w(assigned_to_id done_ratio))
+ trackers << Tracker.new(:core_fields => [])
+
+ assert_equal %w(assigned_to_id due_date done_ratio), Tracker.core_fields(trackers)
+ assert_equal Tracker::CORE_FIELDS - %w(assigned_to_id due_date done_ratio), Tracker.disabled_core_fields(trackers)
+ end
+
def test_sort_should_sort_by_position
a = Tracker.new(:name => 'Tracker A', :position => 2)
b = Tracker.new(:name => 'Tracker B', :position => 1)