@@ -44,7 +44,9 class Enumeration < ActiveRecord::Base | |||
|
44 | 44 | end |
|
45 | 45 | |
|
46 | 46 | def before_save |
|
47 | Enumeration.update_all("is_default = #{connection.quoted_false}", {:opt => opt}) if is_default? | |
|
47 | if is_default? && is_default_changed? | |
|
48 | Enumeration.update_all("is_default = #{connection.quoted_false}", {:opt => opt}) | |
|
49 | end | |
|
48 | 50 | end |
|
49 | 51 | |
|
50 | 52 | def objects_count |
@@ -37,6 +37,43 class EnumerationTest < Test::Unit::TestCase | |||
|
37 | 37 | assert !Enumeration.find(7).in_use? |
|
38 | 38 | end |
|
39 | 39 | |
|
40 | def test_default | |
|
41 | e = Enumeration.default('IPRI') | |
|
42 | assert e.is_a?(Enumeration) | |
|
43 | assert e.is_default? | |
|
44 | assert_equal 'Normal', e.name | |
|
45 | end | |
|
46 | ||
|
47 | def test_create | |
|
48 | e = Enumeration.new(:opt => 'IPRI', :name => 'Very urgent', :is_default => false) | |
|
49 | assert e.save | |
|
50 | assert_equal 'Normal', Enumeration.default('IPRI').name | |
|
51 | end | |
|
52 | ||
|
53 | def test_create_as_default | |
|
54 | e = Enumeration.new(:opt => 'IPRI', :name => 'Very urgent', :is_default => true) | |
|
55 | assert e.save | |
|
56 | assert_equal e, Enumeration.default('IPRI') | |
|
57 | end | |
|
58 | ||
|
59 | def test_update_default | |
|
60 | e = Enumeration.default('IPRI') | |
|
61 | e.update_attributes(:name => 'Changed', :is_default => true) | |
|
62 | assert_equal e, Enumeration.default('IPRI') | |
|
63 | end | |
|
64 | ||
|
65 | def test_update_default_to_non_default | |
|
66 | e = Enumeration.default('IPRI') | |
|
67 | e.update_attributes(:name => 'Changed', :is_default => false) | |
|
68 | assert_nil Enumeration.default('IPRI') | |
|
69 | end | |
|
70 | ||
|
71 | def test_change_default | |
|
72 | e = Enumeration.find_by_name('Urgent') | |
|
73 | e.update_attributes(:name => 'Urgent', :is_default => true) | |
|
74 | assert_equal e, Enumeration.default('IPRI') | |
|
75 | end | |
|
76 | ||
|
40 | 77 | def test_destroy_with_reassign |
|
41 | 78 | Enumeration.find(4).destroy(Enumeration.find(6)) |
|
42 | 79 | assert_nil Issue.find(:first, :conditions => {:priority_id => 4}) |
General Comments 0
You need to be logged in to leave comments.
Login now