##// END OF EJS Templates
Removes RJS from IssueRelationsController....
Jean-Philippe Lang -
r9862:855310701615
parent child
Show More
@@ -0,0 +1,5
1 Element.update('relations', '<%= escape_javascript(render :partial => 'issues/relations') %>');
2 <% if @relation.errors.empty? %>
3 $('relation_delay').value = ''
4 $('relation_issue_to_id').value = ''
5 <% end %>
@@ -0,0 +1,1
1 Element.remove('<%= "relation-#{@relation.id}" %>');
@@ -1,95 +1,88
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 class IssueRelationsController < ApplicationController
19 19 before_filter :find_issue, :find_project_from_association, :authorize, :only => [:index, :create]
20 20 before_filter :find_relation, :except => [:index, :create]
21 21
22 22 accept_api_auth :index, :show, :create, :destroy
23 23
24 24 def index
25 25 @relations = @issue.relations
26 26
27 27 respond_to do |format|
28 28 format.html { render :nothing => true }
29 29 format.api
30 30 end
31 31 end
32 32
33 33 def show
34 34 raise Unauthorized unless @relation.visible?
35 35
36 36 respond_to do |format|
37 37 format.html { render :nothing => true }
38 38 format.api
39 39 end
40 40 end
41 41
42 42 def create
43 43 @relation = IssueRelation.new(params[:relation])
44 44 @relation.issue_from = @issue
45 45 if params[:relation] && m = params[:relation][:issue_to_id].to_s.strip.match(/^#?(\d+)$/)
46 46 @relation.issue_to = Issue.visible.find_by_id(m[1].to_i)
47 47 end
48 48 saved = @relation.save
49 49
50 50 respond_to do |format|
51 51 format.html { redirect_to :controller => 'issues', :action => 'show', :id => @issue }
52 format.js do
52 format.js {
53 53 @relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? }
54 render :update do |page|
55 page.replace_html "relations", :partial => 'issues/relations'
56 if @relation.errors.empty?
57 page << "$('relation_delay').value = ''"
58 page << "$('relation_issue_to_id').value = ''"
59 end
60 end
61 end
54 }
62 55 format.api {
63 56 if saved
64 57 render :action => 'show', :status => :created, :location => relation_url(@relation)
65 58 else
66 59 render_validation_errors(@relation)
67 60 end
68 61 }
69 62 end
70 63 end
71 64
72 65 def destroy
73 66 raise Unauthorized unless @relation.deletable?
74 67 @relation.destroy
75 68
76 69 respond_to do |format|
77 70 format.html { redirect_to issue_path } # TODO : does this really work since @issue is always nil? What is it useful to?
78 format.js { render(:update) {|page| page.remove "relation-#{@relation.id}"} }
71 format.js
79 72 format.api { render_api_ok }
80 73 end
81 74 end
82 75
83 76 private
84 77 def find_issue
85 78 @issue = @object = Issue.find(params[:issue_id])
86 79 rescue ActiveRecord::RecordNotFound
87 80 render_404
88 81 end
89 82
90 83 def find_relation
91 84 @relation = IssueRelation.find(params[:id])
92 85 rescue ActiveRecord::RecordNotFound
93 86 render_404
94 87 end
95 88 end
@@ -1,135 +1,151
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../test_helper', __FILE__)
19 19 require 'issue_relations_controller'
20 20
21 21 # Re-raise errors caught by the controller.
22 22 class IssueRelationsController; def rescue_action(e) raise e end; end
23 23
24 24
25 25 class IssueRelationsControllerTest < ActionController::TestCase
26 26 fixtures :projects,
27 27 :users,
28 28 :roles,
29 29 :members,
30 30 :member_roles,
31 31 :issues,
32 32 :issue_statuses,
33 33 :issue_relations,
34 34 :enabled_modules,
35 35 :enumerations,
36 36 :trackers
37 37
38 38 def setup
39 39 @controller = IssueRelationsController.new
40 40 @request = ActionController::TestRequest.new
41 41 @response = ActionController::TestResponse.new
42 42 User.current = nil
43 43 end
44 44
45 45 def test_create
46 46 assert_difference 'IssueRelation.count' do
47 47 @request.session[:user_id] = 3
48 48 post :create, :issue_id => 1,
49 49 :relation => {:issue_to_id => '2', :relation_type => 'relates', :delay => ''}
50 50 end
51 51 relation = IssueRelation.first(:order => 'id DESC')
52 52 assert_equal 1, relation.issue_from_id
53 53 assert_equal 2, relation.issue_to_id
54 54 assert_equal 'relates', relation.relation_type
55 55 end
56 56
57 57 def test_create_xhr
58 58 assert_difference 'IssueRelation.count' do
59 59 @request.session[:user_id] = 3
60 xhr :post, :create,
61 :issue_id => 3,
62 :relation => {:issue_to_id => '1', :relation_type => 'relates', :delay => ''}
63 assert_select_rjs 'relations' do
64 assert_select 'table', 1
65 assert_select 'tr', 2 # relations
66 end
60 xhr :post, :create, :issue_id => 3, :relation => {:issue_to_id => '1', :relation_type => 'relates', :delay => ''}
61 assert_response :success
62 assert_template 'create'
63 assert_equal 'text/javascript', response.content_type
67 64 end
68 65 relation = IssueRelation.first(:order => 'id DESC')
69 66 assert_equal 3, relation.issue_from_id
70 67 assert_equal 1, relation.issue_to_id
68
69 assert_match /Bug #1/, response.body
71 70 end
72 71
73 72 def test_create_should_accept_id_with_hash
74 73 assert_difference 'IssueRelation.count' do
75 74 @request.session[:user_id] = 3
76 75 post :create, :issue_id => 1,
77 76 :relation => {:issue_to_id => '#2', :relation_type => 'relates', :delay => ''}
78 77 end
79 78 relation = IssueRelation.first(:order => 'id DESC')
80 79 assert_equal 2, relation.issue_to_id
81 80 end
82 81
83 82 def test_create_should_strip_id
84 83 assert_difference 'IssueRelation.count' do
85 84 @request.session[:user_id] = 3
86 85 post :create, :issue_id => 1,
87 86 :relation => {:issue_to_id => ' 2 ', :relation_type => 'relates', :delay => ''}
88 87 end
89 88 relation = IssueRelation.first(:order => 'id DESC')
90 89 assert_equal 2, relation.issue_to_id
91 90 end
92 91
93 92 def test_create_should_not_break_with_non_numerical_id
94 93 assert_no_difference 'IssueRelation.count' do
95 94 assert_nothing_raised do
96 95 @request.session[:user_id] = 3
97 96 post :create, :issue_id => 1,
98 97 :relation => {:issue_to_id => 'foo', :relation_type => 'relates', :delay => ''}
99 98 end
100 99 end
101 100 end
102 101
103 102 def test_should_create_relations_with_visible_issues_only
104 103 Setting.cross_project_issue_relations = '1'
105 104 assert_nil Issue.visible(User.find(3)).find_by_id(4)
106 105
107 106 assert_no_difference 'IssueRelation.count' do
108 107 @request.session[:user_id] = 3
109 108 post :create, :issue_id => 1,
110 109 :relation => {:issue_to_id => '4', :relation_type => 'relates', :delay => ''}
111 110 end
112 111 end
113 112
114 113 should "prevent relation creation when there's a circular dependency"
115 114
115 def test_create_xhr_with_failure
116 assert_no_difference 'IssueRelation.count' do
117 @request.session[:user_id] = 3
118 xhr :post, :create, :issue_id => 3, :relation => {:issue_to_id => '999', :relation_type => 'relates', :delay => ''}
119
120 assert_response :success
121 assert_template 'create'
122 assert_equal 'text/javascript', response.content_type
123 end
124
125 assert_match /errorExplanation/, response.body
126 end
127
116 128 def test_destroy
117 129 assert_difference 'IssueRelation.count', -1 do
118 130 @request.session[:user_id] = 3
119 131 delete :destroy, :id => '2'
120 132 end
121 133 end
122 134
123 135 def test_destroy_xhr
124 136 IssueRelation.create!(:relation_type => IssueRelation::TYPE_RELATES) do |r|
125 137 r.issue_from_id = 3
126 138 r.issue_to_id = 1
127 139 end
128 140
129 141 assert_difference 'IssueRelation.count', -1 do
130 142 @request.session[:user_id] = 3
131 143 xhr :delete, :destroy, :id => '2'
132 assert_select_rjs :remove, 'relation-2'
144
145 assert_response :success
146 assert_template 'destroy'
147 assert_equal 'text/javascript', response.content_type
148 assert_match /relation-2/, response.body
133 149 end
134 150 end
135 151 end
General Comments 0
You need to be logged in to leave comments. Login now