Code cleanup.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10179 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2012-08-08 21:28:07 +00:00
parent b907398788
commit 0ce0b52342
3 changed files with 19 additions and 6 deletions

View File

@ -172,12 +172,7 @@ class IssuesController < ApplicationController
rescue ActiveRecord::StaleObjectError rescue ActiveRecord::StaleObjectError
@conflict = true @conflict = true
if params[:last_journal_id] if params[:last_journal_id]
if params[:last_journal_id].present? @conflict_journals = @issue.journals_after(params[:last_journal_id]).all
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
end end
end end

View File

@ -587,6 +587,15 @@ class Issue < ActiveRecord::Base
end end
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 # Return true if the issue is closed, otherwise false
def closed? def closed?
self.status.is_closed? self.status.is_closed?

View File

@ -1530,4 +1530,13 @@ class IssueTest < ActiveSupport::TestCase
def test_last_journal_id_without_journals_should_return_nil def test_last_journal_id_without_journals_should_return_nil
assert_nil Issue.find(3).last_journal_id assert_nil Issue.find(3).last_journal_id
end 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 end