@@ -35,19 +35,19 class Enumeration < ActiveRecord::Base | |||
|
35 | 35 | validates_uniqueness_of :name, :scope => [:type, :project_id] |
|
36 | 36 | validates_length_of :name, :maximum => 30 |
|
37 | 37 | |
|
38 |
scope :shared, |
|
|
39 |
scope :active, |
|
|
40 |
scope :named, lambda {|arg| |
|
|
38 | scope :shared, where(:project_id => nil) | |
|
39 | scope :active, where(:active => true) | |
|
40 | scope :named, lambda {|arg| where("LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip)} | |
|
41 | 41 | |
|
42 | 42 | def self.default |
|
43 | 43 | # Creates a fake default scope so Enumeration.default will check |
|
44 | 44 | # it's type. STI subclasses will automatically add their own |
|
45 | 45 | # types to the finder. |
|
46 | 46 | if self.descends_from_active_record? |
|
47 |
|
|
|
47 | where(:is_default => true, :type => 'Enumeration').first | |
|
48 | 48 | else |
|
49 | 49 | # STI classes are |
|
50 | find(:first, :conditions => { :is_default => true }) | |
|
50 | where(:is_default => true).first | |
|
51 | 51 | end |
|
52 | 52 | end |
|
53 | 53 | |
@@ -58,7 +58,7 class Enumeration < ActiveRecord::Base | |||
|
58 | 58 | |
|
59 | 59 | def check_default |
|
60 | 60 | if is_default? && is_default_changed? |
|
61 |
Enumeration.update_all( |
|
|
61 | Enumeration.update_all({:is_default => false}, {:type => type}) | |
|
62 | 62 | end |
|
63 | 63 | end |
|
64 | 64 |
@@ -20,6 +20,19 require File.expand_path('../../test_helper', __FILE__) | |||
|
20 | 20 | class IssuePriorityTest < ActiveSupport::TestCase |
|
21 | 21 | fixtures :enumerations, :issues |
|
22 | 22 | |
|
23 | def test_named_scope | |
|
24 | assert_equal Enumeration.find_by_name('Normal'), Enumeration.named('normal').first | |
|
25 | end | |
|
26 | ||
|
27 | def test_default_should_return_the_default_priority | |
|
28 | assert_equal Enumeration.find_by_name('Normal'), IssuePriority.default | |
|
29 | end | |
|
30 | ||
|
31 | def test_default_should_return_nil_when_no_default_priority | |
|
32 | IssuePriority.update_all :is_default => false | |
|
33 | assert_nil IssuePriority.default | |
|
34 | end | |
|
35 | ||
|
23 | 36 | def test_should_be_an_enumeration |
|
24 | 37 | assert IssuePriority.ancestors.include?(Enumeration) |
|
25 | 38 | end |
General Comments 0
You need to be logged in to leave comments.
Login now