summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/models/enumeration.rb4
-rw-r--r--test/unit/enumeration_test.rb37
2 files changed, 40 insertions, 1 deletions
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})