Code cleanup.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9713 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
e7b9a9c6ff
commit
221585c7b5
|
@ -35,19 +35,19 @@ class Enumeration < ActiveRecord::Base
|
||||||
validates_uniqueness_of :name, :scope => [:type, :project_id]
|
validates_uniqueness_of :name, :scope => [:type, :project_id]
|
||||||
validates_length_of :name, :maximum => 30
|
validates_length_of :name, :maximum => 30
|
||||||
|
|
||||||
scope :shared, :conditions => { :project_id => nil }
|
scope :shared, where(:project_id => nil)
|
||||||
scope :active, :conditions => { :active => true }
|
scope :active, where(:active => true)
|
||||||
scope :named, lambda {|arg| { :conditions => ["LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip]}}
|
scope :named, lambda {|arg| where("LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip)}
|
||||||
|
|
||||||
def self.default
|
def self.default
|
||||||
# Creates a fake default scope so Enumeration.default will check
|
# Creates a fake default scope so Enumeration.default will check
|
||||||
# it's type. STI subclasses will automatically add their own
|
# it's type. STI subclasses will automatically add their own
|
||||||
# types to the finder.
|
# types to the finder.
|
||||||
if self.descends_from_active_record?
|
if self.descends_from_active_record?
|
||||||
find(:first, :conditions => { :is_default => true, :type => 'Enumeration' })
|
where(:is_default => true, :type => 'Enumeration').first
|
||||||
else
|
else
|
||||||
# STI classes are
|
# STI classes are
|
||||||
find(:first, :conditions => { :is_default => true })
|
where(:is_default => true).first
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ class Enumeration < ActiveRecord::Base
|
||||||
|
|
||||||
def check_default
|
def check_default
|
||||||
if is_default? && is_default_changed?
|
if is_default? && is_default_changed?
|
||||||
Enumeration.update_all("is_default = #{connection.quoted_false}", {:type => type})
|
Enumeration.update_all({:is_default => false}, {:type => type})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,19 @@ require File.expand_path('../../test_helper', __FILE__)
|
||||||
class IssuePriorityTest < ActiveSupport::TestCase
|
class IssuePriorityTest < ActiveSupport::TestCase
|
||||||
fixtures :enumerations, :issues
|
fixtures :enumerations, :issues
|
||||||
|
|
||||||
|
def test_named_scope
|
||||||
|
assert_equal Enumeration.find_by_name('Normal'), Enumeration.named('normal').first
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_default_should_return_the_default_priority
|
||||||
|
assert_equal Enumeration.find_by_name('Normal'), IssuePriority.default
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_default_should_return_nil_when_no_default_priority
|
||||||
|
IssuePriority.update_all :is_default => false
|
||||||
|
assert_nil IssuePriority.default
|
||||||
|
end
|
||||||
|
|
||||||
def test_should_be_an_enumeration
|
def test_should_be_an_enumeration
|
||||||
assert IssuePriority.ancestors.include?(Enumeration)
|
assert IssuePriority.ancestors.include?(Enumeration)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue