[#808] Add JournalsController#diff to diff a single field
This commit is contained in:
parent
e045306a5c
commit
5ad97a4ea3
@ -12,6 +12,8 @@
|
||||
# See doc/COPYRIGHT.rdoc for more details.
|
||||
#++
|
||||
|
||||
require 'diff'
|
||||
|
||||
class JournalsController < ApplicationController
|
||||
before_filter :find_journal, :only => [:edit, :diff]
|
||||
before_filter :find_issue, :only => [:new]
|
||||
@ -84,6 +86,21 @@ class JournalsController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
def diff
|
||||
if valid_field?(params[:field])
|
||||
from = @journal.changes[params[:field]][0]
|
||||
to = @journal.changes[params[:field]][1]
|
||||
|
||||
@diff = Redmine::Helpers::Diff.new(to, from)
|
||||
@issue = @journal.journaled
|
||||
respond_to do |format|
|
||||
format.html { }
|
||||
end
|
||||
else
|
||||
render_404
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_journal
|
||||
@ -100,4 +117,9 @@ class JournalsController < ApplicationController
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
# Is this a valid field for diff'ing?
|
||||
def valid_field?(field)
|
||||
field.to_s.strip == "description"
|
||||
end
|
||||
end
|
||||
|
9
app/views/journals/diff.html.erb
Normal file
9
app/views/journals/diff.html.erb
Normal file
@ -0,0 +1,9 @@
|
||||
<p><%= authoring @journal.created_at, @journal.user, :label => :label_updated_time_by %></p>
|
||||
|
||||
<div class="text-diff">
|
||||
<%= simple_format_without_paragraph @diff.to_html %>
|
||||
</div>
|
||||
|
||||
<p><%= link_to(l(:button_back), issue_path(@issue)) %></p>
|
||||
|
||||
<% html_title "#{@issue.tracker.name} ##{@issue.id}: #{@issue.subject}" %>
|
@ -81,4 +81,68 @@ class JournalsControllerTest < ActionController::TestCase
|
||||
assert_select_rjs :show, "update"
|
||||
end
|
||||
|
||||
context "#diff" do
|
||||
setup do
|
||||
@request.session[:user_id] = 1
|
||||
@issue = Issue.find(6)
|
||||
@previous_description = @issue.description
|
||||
@new_description = "New description"
|
||||
|
||||
assert_difference("Journal.count") do
|
||||
@issue.description = @new_description
|
||||
assert @issue.save
|
||||
end
|
||||
@last_journal = @issue.last_journal
|
||||
end
|
||||
|
||||
context "without a valid journal" do
|
||||
should "return a 404" do
|
||||
get :diff, :id => '0'
|
||||
assert_response :not_found
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
context "with no field parameter" do
|
||||
should "return a 404" do
|
||||
get :diff, :id => @last_journal.id
|
||||
assert_response :not_found
|
||||
end
|
||||
end
|
||||
|
||||
context "for an invalid field" do
|
||||
should "return a 404" do
|
||||
get :diff, :id => @last_journal.id, :field => 'id'
|
||||
assert_response :not_found
|
||||
end
|
||||
end
|
||||
|
||||
context "without permission to view_issues" do
|
||||
should "return a 403" do
|
||||
@request.session[:user_id] = 7
|
||||
get :diff, :id => @last_journal.id, :field => 'description'
|
||||
|
||||
assert_response :forbidden
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context "with permission to view_issues" do
|
||||
setup do
|
||||
get :diff, :id => @last_journal.id, :field => 'description'
|
||||
end
|
||||
|
||||
should "create a diff" do
|
||||
assert_not_nil assigns(:diff)
|
||||
assert assigns(:diff).is_a?(Redmine::Helpers::Diff)
|
||||
end
|
||||
|
||||
should "render an inline diff" do
|
||||
assert_select "#content .text-diff"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user