diff --git a/app/models/issue_status.rb b/app/models/issue_status.rb index 1562d04..95c7e4d 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 5d3b6a1..75c86e3 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