From c6511849987c695057c395f10736b54e565461ee Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Fri, 12 Dec 2008 13:32:39 +0000 Subject: [PATCH] Fixed: default flag removed when editing a default enumeration (#2327). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2123 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/enumeration.rb | 4 +++- test/unit/enumeration_test.rb | 37 +++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/app/models/enumeration.rb b/app/models/enumeration.rb index d32a0c049..e4b080be1 100644 --- a/app/models/enumeration.rb +++ b/app/models/enumeration.rb @@ -44,7 +44,9 @@ class Enumeration < ActiveRecord::Base end def before_save - Enumeration.update_all("is_default = #{connection.quoted_false}", {:opt => opt}) if is_default? + if is_default? && is_default_changed? + Enumeration.update_all("is_default = #{connection.quoted_false}", {:opt => opt}) + end end def objects_count diff --git a/test/unit/enumeration_test.rb b/test/unit/enumeration_test.rb index 9b7bfd174..4da3f094b 100644 --- a/test/unit/enumeration_test.rb +++ b/test/unit/enumeration_test.rb @@ -37,6 +37,43 @@ class EnumerationTest < Test::Unit::TestCase assert !Enumeration.find(7).in_use? end + def test_default + e = Enumeration.default('IPRI') + assert e.is_a?(Enumeration) + assert e.is_default? + assert_equal 'Normal', e.name + end + + def test_create + e = Enumeration.new(:opt => 'IPRI', :name => 'Very urgent', :is_default => false) + assert e.save + assert_equal 'Normal', Enumeration.default('IPRI').name + end + + def test_create_as_default + e = Enumeration.new(:opt => 'IPRI', :name => 'Very urgent', :is_default => true) + assert e.save + assert_equal e, Enumeration.default('IPRI') + end + + def test_update_default + e = Enumeration.default('IPRI') + e.update_attributes(:name => 'Changed', :is_default => true) + assert_equal e, Enumeration.default('IPRI') + end + + def test_update_default_to_non_default + e = Enumeration.default('IPRI') + e.update_attributes(:name => 'Changed', :is_default => false) + assert_nil Enumeration.default('IPRI') + end + + def test_change_default + e = Enumeration.find_by_name('Urgent') + e.update_attributes(:name => 'Urgent', :is_default => true) + assert_equal e, Enumeration.default('IPRI') + end + def test_destroy_with_reassign Enumeration.find(4).destroy(Enumeration.find(6)) assert_nil Issue.find(:first, :conditions => {:priority_id => 4}) -- 2.39.5