##// END OF EJS Templates
Refactor: Start to extract IssuesController#edit into #update (REST)....
Eric Davis -
r3366:d581510af605
parent child
Show More
@@ -19,7 +19,7 class IssuesController < ApplicationController
19 menu_item :new_issue, :only => :new
19 menu_item :new_issue, :only => :new
20 default_search_scope :issues
20 default_search_scope :issues
21
21
22 before_filter :find_issue, :only => [:show, :edit, :reply]
22 before_filter :find_issue, :only => [:show, :edit, :update, :reply]
23 before_filter :find_issues, :only => [:bulk_edit, :move, :destroy]
23 before_filter :find_issues, :only => [:bulk_edit, :move, :destroy]
24 before_filter :find_project, :only => [:new, :update_form, :preview]
24 before_filter :find_project, :only => [:new, :update_form, :preview]
25 before_filter :authorize, :except => [:index, :changes, :gantt, :calendar, :preview, :context_menu]
25 before_filter :authorize, :except => [:index, :changes, :gantt, :calendar, :preview, :context_menu]
@@ -226,7 +226,7 class IssuesController < ApplicationController
226 end
226 end
227 # failure
227 # failure
228 respond_to do |format|
228 respond_to do |format|
229 format.html { }
229 format.html { render :action => 'edit' }
230 format.xml { render :xml => @issue.errors, :status => :unprocessable_entity }
230 format.xml { render :xml => @issue.errors, :status => :unprocessable_entity }
231 end
231 end
232 end
232 end
@@ -237,6 +237,13 class IssuesController < ApplicationController
237 attachments.each(&:destroy)
237 attachments.each(&:destroy)
238 end
238 end
239
239
240 #--
241 # Start converting to the Rails REST controllers
242 #++
243 def update
244 edit
245 end
246
240 def reply
247 def reply
241 journal = Journal.find(params[:journal_id]) if params[:journal_id]
248 journal = Journal.find(params[:journal_id]) if params[:journal_id]
242 if journal
249 if journal
@@ -1,7 +1,8
1 <% labelled_tabular_form_for :issue, @issue,
1 <% labelled_tabular_form_for :issue, @issue,
2 :url => {:action => 'edit', :id => @issue},
2 :url => {:action => 'update', :id => @issue},
3 :html => {:id => 'issue-form',
3 :html => {:id => 'issue-form',
4 :class => nil,
4 :class => nil,
5 :method => :put,
5 :multipart => true} do |f| %>
6 :multipart => true} do |f| %>
6 <%= error_messages_for 'issue' %>
7 <%= error_messages_for 'issue' %>
7 <%= error_messages_for 'time_entry' %>
8 <%= error_messages_for 'time_entry' %>
@@ -52,9 +52,9 Redmine::AccessControl.map do |map|
52 :queries => :index,
52 :queries => :index,
53 :reports => [:issue_report, :issue_report_details]}
53 :reports => [:issue_report, :issue_report_details]}
54 map.permission :add_issues, {:issues => [:new, :update_form]}
54 map.permission :add_issues, {:issues => [:new, :update_form]}
55 map.permission :edit_issues, {:issues => [:edit, :reply, :bulk_edit, :update_form]}
55 map.permission :edit_issues, {:issues => [:edit, :update, :reply, :bulk_edit, :update_form]}
56 map.permission :manage_issue_relations, {:issue_relations => [:new, :destroy]}
56 map.permission :manage_issue_relations, {:issue_relations => [:new, :destroy]}
57 map.permission :add_issue_notes, {:issues => [:edit, :reply]}
57 map.permission :add_issue_notes, {:issues => [:edit, :update, :reply]}
58 map.permission :edit_issue_notes, {:journals => :edit}, :require => :loggedin
58 map.permission :edit_issue_notes, {:journals => :edit}, :require => :loggedin
59 map.permission :edit_own_issue_notes, {:journals => :edit}, :require => :loggedin
59 map.permission :edit_own_issue_notes, {:journals => :edit}, :require => :loggedin
60 map.permission :move_issues, {:issues => :move}, :require => :loggedin
60 map.permission :move_issues, {:issues => :move}, :require => :loggedin
@@ -657,7 +657,7 class IssuesControllerTest < ActionController::TestCase
657 assert_select_rjs :show, "update"
657 assert_select_rjs :show, "update"
658 end
658 end
659
659
660 def test_post_edit_without_custom_fields_param
660 def test_put_update_without_custom_fields_param
661 @request.session[:user_id] = 2
661 @request.session[:user_id] = 2
662 ActionMailer::Base.deliveries.clear
662 ActionMailer::Base.deliveries.clear
663
663
@@ -668,7 +668,7 class IssuesControllerTest < ActionController::TestCase
668
668
669 assert_difference('Journal.count') do
669 assert_difference('Journal.count') do
670 assert_difference('JournalDetail.count', 2) do
670 assert_difference('JournalDetail.count', 2) do
671 post :edit, :id => 1, :issue => {:subject => new_subject,
671 put :update, :id => 1, :issue => {:subject => new_subject,
672 :priority_id => '6',
672 :priority_id => '6',
673 :category_id => '1' # no change
673 :category_id => '1' # no change
674 }
674 }
@@ -686,14 +686,14 class IssuesControllerTest < ActionController::TestCase
686 assert mail.body.include?("Subject changed from #{old_subject} to #{new_subject}")
686 assert mail.body.include?("Subject changed from #{old_subject} to #{new_subject}")
687 end
687 end
688
688
689 def test_post_edit_with_custom_field_change
689 def test_put_update_with_custom_field_change
690 @request.session[:user_id] = 2
690 @request.session[:user_id] = 2
691 issue = Issue.find(1)
691 issue = Issue.find(1)
692 assert_equal '125', issue.custom_value_for(2).value
692 assert_equal '125', issue.custom_value_for(2).value
693
693
694 assert_difference('Journal.count') do
694 assert_difference('Journal.count') do
695 assert_difference('JournalDetail.count', 3) do
695 assert_difference('JournalDetail.count', 3) do
696 post :edit, :id => 1, :issue => {:subject => 'Custom field change',
696 put :update, :id => 1, :issue => {:subject => 'Custom field change',
697 :priority_id => '6',
697 :priority_id => '6',
698 :category_id => '1', # no change
698 :category_id => '1', # no change
699 :custom_field_values => { '2' => 'New custom value' }
699 :custom_field_values => { '2' => 'New custom value' }
@@ -709,12 +709,12 class IssuesControllerTest < ActionController::TestCase
709 assert mail.body.include?("Searchable field changed from 125 to New custom value")
709 assert mail.body.include?("Searchable field changed from 125 to New custom value")
710 end
710 end
711
711
712 def test_post_edit_with_status_and_assignee_change
712 def test_put_update_with_status_and_assignee_change
713 issue = Issue.find(1)
713 issue = Issue.find(1)
714 assert_equal 1, issue.status_id
714 assert_equal 1, issue.status_id
715 @request.session[:user_id] = 2
715 @request.session[:user_id] = 2
716 assert_difference('TimeEntry.count', 0) do
716 assert_difference('TimeEntry.count', 0) do
717 post :edit,
717 put :update,
718 :id => 1,
718 :id => 1,
719 :issue => { :status_id => 2, :assigned_to_id => 3 },
719 :issue => { :status_id => 2, :assigned_to_id => 3 },
720 :notes => 'Assigned to dlopper',
720 :notes => 'Assigned to dlopper',
@@ -733,10 +733,10 class IssuesControllerTest < ActionController::TestCase
733 assert mail.subject.include?("(#{ IssueStatus.find(2).name })")
733 assert mail.subject.include?("(#{ IssueStatus.find(2).name })")
734 end
734 end
735
735
736 def test_post_edit_with_note_only
736 def test_put_update_with_note_only
737 notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
737 notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
738 # anonymous user
738 # anonymous user
739 post :edit,
739 put :update,
740 :id => 1,
740 :id => 1,
741 :notes => notes
741 :notes => notes
742 assert_redirected_to :action => 'show', :id => '1'
742 assert_redirected_to :action => 'show', :id => '1'
@@ -749,11 +749,11 class IssuesControllerTest < ActionController::TestCase
749 assert mail.body.include?(notes)
749 assert mail.body.include?(notes)
750 end
750 end
751
751
752 def test_post_edit_with_note_and_spent_time
752 def test_put_update_with_note_and_spent_time
753 @request.session[:user_id] = 2
753 @request.session[:user_id] = 2
754 spent_hours_before = Issue.find(1).spent_hours
754 spent_hours_before = Issue.find(1).spent_hours
755 assert_difference('TimeEntry.count') do
755 assert_difference('TimeEntry.count') do
756 post :edit,
756 put :update,
757 :id => 1,
757 :id => 1,
758 :notes => '2.5 hours added',
758 :notes => '2.5 hours added',
759 :time_entry => { :hours => '2.5', :comments => '', :activity_id => TimeEntryActivity.first }
759 :time_entry => { :hours => '2.5', :comments => '', :activity_id => TimeEntryActivity.first }
@@ -772,7 +772,7 class IssuesControllerTest < ActionController::TestCase
772 assert_equal spent_hours_before + 2.5, issue.spent_hours
772 assert_equal spent_hours_before + 2.5, issue.spent_hours
773 end
773 end
774
774
775 def test_post_edit_with_attachment_only
775 def test_put_update_with_attachment_only
776 set_tmp_attachments_directory
776 set_tmp_attachments_directory
777
777
778 # Delete all fixtured journals, a race condition can occur causing the wrong
778 # Delete all fixtured journals, a race condition can occur causing the wrong
@@ -780,7 +780,7 class IssuesControllerTest < ActionController::TestCase
780 Journal.delete_all
780 Journal.delete_all
781
781
782 # anonymous user
782 # anonymous user
783 post :edit,
783 put :update,
784 :id => 1,
784 :id => 1,
785 :notes => '',
785 :notes => '',
786 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
786 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
@@ -795,12 +795,12 class IssuesControllerTest < ActionController::TestCase
795 assert mail.body.include?('testfile.txt')
795 assert mail.body.include?('testfile.txt')
796 end
796 end
797
797
798 def test_post_edit_with_no_change
798 def test_put_update_with_no_change
799 issue = Issue.find(1)
799 issue = Issue.find(1)
800 issue.journals.clear
800 issue.journals.clear
801 ActionMailer::Base.deliveries.clear
801 ActionMailer::Base.deliveries.clear
802
802
803 post :edit,
803 put :update,
804 :id => 1,
804 :id => 1,
805 :notes => ''
805 :notes => ''
806 assert_redirected_to :action => 'show', :id => '1'
806 assert_redirected_to :action => 'show', :id => '1'
@@ -811,26 +811,26 class IssuesControllerTest < ActionController::TestCase
811 assert ActionMailer::Base.deliveries.empty?
811 assert ActionMailer::Base.deliveries.empty?
812 end
812 end
813
813
814 def test_post_edit_should_send_a_notification
814 def test_put_update_should_send_a_notification
815 @request.session[:user_id] = 2
815 @request.session[:user_id] = 2
816 ActionMailer::Base.deliveries.clear
816 ActionMailer::Base.deliveries.clear
817 issue = Issue.find(1)
817 issue = Issue.find(1)
818 old_subject = issue.subject
818 old_subject = issue.subject
819 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
819 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
820
820
821 post :edit, :id => 1, :issue => {:subject => new_subject,
821 put :update, :id => 1, :issue => {:subject => new_subject,
822 :priority_id => '6',
822 :priority_id => '6',
823 :category_id => '1' # no change
823 :category_id => '1' # no change
824 }
824 }
825 assert_equal 1, ActionMailer::Base.deliveries.size
825 assert_equal 1, ActionMailer::Base.deliveries.size
826 end
826 end
827
827
828 def test_post_edit_with_invalid_spent_time
828 def test_put_update_with_invalid_spent_time
829 @request.session[:user_id] = 2
829 @request.session[:user_id] = 2
830 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
830 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
831
831
832 assert_no_difference('Journal.count') do
832 assert_no_difference('Journal.count') do
833 post :edit,
833 put :update,
834 :id => 1,
834 :id => 1,
835 :notes => notes,
835 :notes => notes,
836 :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"}
836 :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"}
@@ -843,11 +843,11 class IssuesControllerTest < ActionController::TestCase
843 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => "2z" }
843 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => "2z" }
844 end
844 end
845
845
846 def test_post_edit_should_allow_fixed_version_to_be_set_to_a_subproject
846 def test_put_update_should_allow_fixed_version_to_be_set_to_a_subproject
847 issue = Issue.find(2)
847 issue = Issue.find(2)
848 @request.session[:user_id] = 2
848 @request.session[:user_id] = 2
849
849
850 post :edit,
850 put :update,
851 :id => issue.id,
851 :id => issue.id,
852 :issue => {
852 :issue => {
853 :fixed_version_id => 4
853 :fixed_version_id => 4
@@ -859,11 +859,11 class IssuesControllerTest < ActionController::TestCase
859 assert_not_equal issue.project_id, issue.fixed_version.project_id
859 assert_not_equal issue.project_id, issue.fixed_version.project_id
860 end
860 end
861
861
862 def test_post_edit_should_redirect_back_using_the_back_url_parameter
862 def test_put_update_should_redirect_back_using_the_back_url_parameter
863 issue = Issue.find(2)
863 issue = Issue.find(2)
864 @request.session[:user_id] = 2
864 @request.session[:user_id] = 2
865
865
866 post :edit,
866 put :update,
867 :id => issue.id,
867 :id => issue.id,
868 :issue => {
868 :issue => {
869 :fixed_version_id => 4
869 :fixed_version_id => 4
@@ -874,11 +874,11 class IssuesControllerTest < ActionController::TestCase
874 assert_redirected_to '/issues'
874 assert_redirected_to '/issues'
875 end
875 end
876
876
877 def test_post_edit_should_not_redirect_back_using_the_back_url_parameter_off_the_host
877 def test_put_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
878 issue = Issue.find(2)
878 issue = Issue.find(2)
879 @request.session[:user_id] = 2
879 @request.session[:user_id] = 2
880
880
881 post :edit,
881 put :update,
882 :id => issue.id,
882 :id => issue.id,
883 :issue => {
883 :issue => {
884 :fixed_version_id => 4
884 :fixed_version_id => 4
General Comments 0
You need to be logged in to leave comments. Login now