]> source.dussan.org Git - redmine.git/commitdiff
Fixed that settings raises an error if not trackers exist (#11467).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 21 Jul 2012 15:43:44 +0000 (15:43 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 21 Jul 2012 15:43:44 +0000 (15:43 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10067 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/tracker.rb
test/functional/settings_controller_test.rb
test/unit/tracker_test.rb

index 472b94b31a1f23437376043423e7b7d70db39a5a..9b3f6afe673266e0870ab9a0bcf3583b953867db 100644 (file)
@@ -92,12 +92,20 @@ class Tracker < ActiveRecord::Base
 
   # Returns the fields that are disabled for all the given trackers
   def self.disabled_core_fields(trackers)
-    trackers.uniq.map(&:disabled_core_fields).reduce(:&)
+    if trackers.present?
+      trackers.uniq.map(&:disabled_core_fields).reduce(:&)
+    else
+      []
+    end
   end
 
   # Returns the fields that are enabled for one tracker at least
   def self.core_fields(trackers)
-    trackers.uniq.map(&:core_fields).reduce(:|)
+    if trackers.present?
+      trackers.uniq.map(&:core_fields).reduce(:|)
+    else
+      CORE_FIELDS.dup
+    end
   end
 
 private
index deddabea5ea9748729de12c0f2e66167361ffcbe..034b902d03f5718790a3d2c981113b3b15e2805f 100644 (file)
@@ -66,6 +66,13 @@ class SettingsControllerTest < ActionController::TestCase
     end
   end
 
+  def test_get_edit_without_trackers_should_succeed
+    Tracker.delete_all
+
+    get :edit
+    assert_response :success
+  end
+
   def test_post_edit_notifications
     post :edit, :settings => {:mail_from => 'functional@test.foo',
                               :bcc_recipients  => '0',
index e1b1663e813f94cab241233d4cd98a5cf72093ef..64f1078d1e7e5531fc4fe34d453f8e4f74740649 100644 (file)
@@ -83,6 +83,11 @@ class TrackerTest < ActiveSupport::TestCase
     assert_equal Tracker::CORE_FIELDS - %w(assigned_to_id due_date done_ratio), Tracker.disabled_core_fields(trackers)
   end
 
+  def test_core_fields_should_return_all_fields_for_an_empty_argument
+    assert_equal Tracker::CORE_FIELDS, Tracker.core_fields([])
+    assert_equal [], Tracker.disabled_core_fields([])
+  end
+
   def test_sort_should_sort_by_position
     a = Tracker.new(:name => 'Tracker A', :position => 2)
     b = Tracker.new(:name => 'Tracker B', :position => 1)