From 0ce0b52342dfb5fd6c444609ef0370f7fdd28230 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Wed, 8 Aug 2012 21:28:07 +0000 Subject: [PATCH] Code cleanup. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10179 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/issues_controller.rb | 7 +------ app/models/issue.rb | 9 +++++++++ test/unit/issue_test.rb | 9 +++++++++ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index e7fdb6886..40a192304 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -172,12 +172,7 @@ class IssuesController < ApplicationController rescue ActiveRecord::StaleObjectError @conflict = true if params[:last_journal_id] - if params[:last_journal_id].present? - last_journal_id = params[:last_journal_id].to_i - @conflict_journals = @issue.journals.all(:conditions => ["#{Journal.table_name}.id > ?", last_journal_id]) - else - @conflict_journals = @issue.journals.all - end + @conflict_journals = @issue.journals_after(params[:last_journal_id]).all end end diff --git a/app/models/issue.rb b/app/models/issue.rb index 6e0f3cc89..97c97e910 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -587,6 +587,15 @@ class Issue < ActiveRecord::Base end end + # Returns a scope for journals that have an id greater than journal_id + def journals_after(journal_id) + scope = journals.reorder("#{Journal.table_name}.id ASC") + if journal_id.present? + scope = scope.where("#{Journal.table_name}.id > ?", journal_id.to_i) + end + scope + end + # Return true if the issue is closed, otherwise false def closed? self.status.is_closed? diff --git a/test/unit/issue_test.rb b/test/unit/issue_test.rb index 97d0a4829..0781c4541 100644 --- a/test/unit/issue_test.rb +++ b/test/unit/issue_test.rb @@ -1530,4 +1530,13 @@ class IssueTest < ActiveSupport::TestCase def test_last_journal_id_without_journals_should_return_nil assert_nil Issue.find(3).last_journal_id end + + def test_journals_after_should_return_journals_with_greater_id + assert_equal [Journal.find(2)], Issue.find(1).journals_after('1') + assert_equal [], Issue.find(1).journals_after('2') + end + + def test_journals_after_with_blank_arg_should_return_all_journals + assert_equal [Journal.find(1), Journal.find(2)], Issue.find(1).journals_after('') + end end -- 2.39.5