From: Jean-Philippe Lang Date: Sun, 15 Jul 2012 15:33:17 +0000 (+0000) Subject: Adds a sorted scope to IssueStatus model. X-Git-Tag: 2.1.0~327 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=7946f4a69668ac5ce1699b4c5940482497b929ed;p=redmine.git Adds a sorted scope to IssueStatus model. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9989 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/models/issue_status.rb b/app/models/issue_status.rb index 1562d049a..95c7e4d51 100644 --- a/app/models/issue_status.rb +++ b/app/models/issue_status.rb @@ -28,6 +28,7 @@ class IssueStatus < ActiveRecord::Base validates_length_of :name, :maximum => 30 validates_inclusion_of :default_done_ratio, :in => 0..100, :allow_nil => true + scope :sorted, order("#{table_name}.position ASC") scope :named, lambda {|arg| where(["LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip])} def update_default diff --git a/test/unit/issue_status_test.rb b/test/unit/issue_status_test.rb index 5d3b6a112..75c86e39e 100644 --- a/test/unit/issue_status_test.rb +++ b/test/unit/issue_status_test.rb @@ -112,6 +112,10 @@ class IssueStatusTest < ActiveSupport::TestCase end end + def test_sorted_scope + assert_equal IssueStatus.all.sort, IssueStatus.sorted.all + end + def test_named_scope status = IssueStatus.named("resolved").first assert_not_nil status