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
This commit is contained in:
parent
72d0843c1f
commit
c651184998
|
@ -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
|
||||
|
|
|
@ -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})
|
||||
|
|
Loading…
Reference in New Issue