summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Davis <edavis@littlestreamsoftware.com>2010-08-18 15:01:35 +0000
committerEric Davis <edavis@littlestreamsoftware.com>2010-08-18 15:01:35 +0000
commit1f8d396e3f12ec177fec0dea6a4a7c39c00fe496 (patch)
tree1ddd1116f61d95f4b18a5c6088fb35eb6e5e6dd0
parent3eff27344b0bef7703ba248d0a2312bfca95c182 (diff)
downloadredmine-1f8d396e3f12ec177fec0dea6a4a7c39c00fe496.tar.gz
redmine-1f8d396e3f12ec177fec0dea6a4a7c39c00fe496.zip
Refactor: move IssuesController#preview to a new controller.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3946 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/controllers/issues_controller.rb15
-rw-r--r--app/controllers/previews_controller.rb28
-rw-r--r--app/views/issues/_edit.rhtml2
-rw-r--r--app/views/issues/new.rhtml2
-rw-r--r--app/views/previews/issue.html.erb (renamed from app/views/issues/preview.html.erb)0
-rw-r--r--config/routes.rb2
-rw-r--r--test/functional/issues_controller_test.rb16
-rw-r--r--test/functional/previews_controller_test.rb22
-rw-r--r--test/integration/routing_test.rb3
9 files changed, 57 insertions, 33 deletions
diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb
index 4981f43ee..239c23e71 100644
--- a/app/controllers/issues_controller.rb
+++ b/app/controllers/issues_controller.rb
@@ -301,21 +301,6 @@ class IssuesController < ApplicationController
render :partial => 'attributes'
end
- def preview
- @issue = @project.issues.find_by_id(params[:id]) unless params[:id].blank?
- if @issue
- @attachements = @issue.attachments
- @description = params[:issue] && params[:issue][:description]
- if @description && @description.gsub(/(\r?\n|\n\r?)/, "\n") == @issue.description.to_s.gsub(/(\r?\n|\n\r?)/, "\n")
- @description = nil
- end
- @notes = params[:notes]
- else
- @description = (params[:issue] ? params[:issue][:description] : nil)
- end
- render :layout => false
- end
-
private
def find_issue
@issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
diff --git a/app/controllers/previews_controller.rb b/app/controllers/previews_controller.rb
new file mode 100644
index 000000000..e1c644653
--- /dev/null
+++ b/app/controllers/previews_controller.rb
@@ -0,0 +1,28 @@
+class PreviewsController < ApplicationController
+ before_filter :find_project
+
+ def issue
+ @issue = @project.issues.find_by_id(params[:id]) unless params[:id].blank?
+ if @issue
+ @attachements = @issue.attachments
+ @description = params[:issue] && params[:issue][:description]
+ if @description && @description.gsub(/(\r?\n|\n\r?)/, "\n") == @issue.description.to_s.gsub(/(\r?\n|\n\r?)/, "\n")
+ @description = nil
+ end
+ @notes = params[:notes]
+ else
+ @description = (params[:issue] ? params[:issue][:description] : nil)
+ end
+ render :layout => false
+ end
+
+ private
+
+ def find_project
+ project_id = (params[:issue] && params[:issue][:project_id]) || params[:project_id]
+ @project = Project.find(project_id)
+ rescue ActiveRecord::RecordNotFound
+ render_404
+ end
+
+end
diff --git a/app/views/issues/_edit.rhtml b/app/views/issues/_edit.rhtml
index 0c01f80be..ec36b1459 100644
--- a/app/views/issues/_edit.rhtml
+++ b/app/views/issues/_edit.rhtml
@@ -44,7 +44,7 @@
<%= f.hidden_field :lock_version %>
<%= submit_tag l(:button_submit) %>
<%= link_to_remote l(:label_preview),
- { :url => { :controller => 'issues', :action => 'preview', :project_id => @project, :id => @issue },
+ { :url => preview_issue_path(:project_id => @project, :id => @issue),
:method => 'post',
:update => 'preview',
:with => 'Form.serialize("issue-form")',
diff --git a/app/views/issues/new.rhtml b/app/views/issues/new.rhtml
index 839286bdb..310085d7c 100644
--- a/app/views/issues/new.rhtml
+++ b/app/views/issues/new.rhtml
@@ -9,7 +9,7 @@
<%= submit_tag l(:button_create) %>
<%= submit_tag l(:button_create_and_continue), :name => 'continue' %>
<%= link_to_remote l(:label_preview),
- { :url => { :controller => 'issues', :action => 'preview', :project_id => @project },
+ { :url => preview_issue_path(:project_id => @project),
:method => 'post',
:update => 'preview',
:with => "Form.serialize('issue-form')",
diff --git a/app/views/issues/preview.html.erb b/app/views/previews/issue.html.erb
index 23772859e..23772859e 100644
--- a/app/views/issues/preview.html.erb
+++ b/app/views/previews/issue.html.erb
diff --git a/config/routes.rb b/config/routes.rb
index 910087ab9..956ce054b 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -105,6 +105,8 @@ ActionController::Routing::Routes.draw do |map|
map.resources :issue_moves, :only => [:new, :create], :path_prefix => '/issues', :as => 'move'
map.auto_complete_issues '/issues/auto_complete', :controller => 'auto_completes', :action => 'issues'
+ # TODO: would look nicer as /issues/:id/preview
+ map.preview_issue '/issues/preview/:id', :controller => 'previews', :action => 'issue'
map.with_options :controller => 'issues' do |issues_routes|
issues_routes.with_options :conditions => {:method => :get} do |issues_views|
diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb
index 948cf8598..22f528b7b 100644
--- a/test/functional/issues_controller_test.rb
+++ b/test/functional/issues_controller_test.rb
@@ -1107,22 +1107,6 @@ class IssuesControllerTest < ActionController::TestCase
:class => 'icon-del disabled' }
end
- def test_preview_new_issue
- @request.session[:user_id] = 2
- post :preview, :project_id => '1', :issue => {:description => 'Foo'}
- assert_response :success
- assert_template 'preview'
- assert_not_nil assigns(:description)
- end
-
- def test_preview_notes
- @request.session[:user_id] = 2
- post :preview, :project_id => '1', :id => 1, :issue => {:description => Issue.find(1).description}, :notes => 'Foo'
- assert_response :success
- assert_template 'preview'
- assert_not_nil assigns(:notes)
- end
-
def test_destroy_issue_with_no_time_entries
assert_nil TimeEntry.find_by_issue_id(2)
@request.session[:user_id] = 2
diff --git a/test/functional/previews_controller_test.rb b/test/functional/previews_controller_test.rb
new file mode 100644
index 000000000..63456d1d0
--- /dev/null
+++ b/test/functional/previews_controller_test.rb
@@ -0,0 +1,22 @@
+require File.dirname(__FILE__) + '/../test_helper'
+
+class PreviewsControllerTest < ActionController::TestCase
+ fixtures :all
+
+ def test_preview_new_issue
+ @request.session[:user_id] = 2
+ post :issue, :project_id => '1', :issue => {:description => 'Foo'}
+ assert_response :success
+ assert_template 'preview'
+ assert_not_nil assigns(:description)
+ end
+
+ def test_preview_issue_notes
+ @request.session[:user_id] = 2
+ post :issue, :project_id => '1', :id => 1, :issue => {:description => Issue.find(1).description}, :notes => 'Foo'
+ assert_response :success
+ assert_template 'preview'
+ assert_not_nil assigns(:notes)
+ end
+
+end
diff --git a/test/integration/routing_test.rb b/test/integration/routing_test.rb
index 607df5b06..01a96b7aa 100644
--- a/test/integration/routing_test.rb
+++ b/test/integration/routing_test.rb
@@ -101,6 +101,9 @@ class RoutingTest < ActionController::IntegrationTest
should_route :post, "/projects/project-name/issues/gantt", :controller => 'gantts', :action => 'show', :project_id => 'project-name'
should_route :get, "/issues/auto_complete", :controller => 'auto_completes', :action => 'issues'
+
+ should_route :get, "/issues/preview/123", :controller => 'previews', :action => 'issue', :id => '123'
+ should_route :post, "/issues/preview/123", :controller => 'previews', :action => 'issue', :id => '123'
end
context "issue categories" do