1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 require File.dirname(__FILE__) + '/../test_helper'
19 require 'repositories_controller'
21 # Re-raise errors caught by the controller.
22 class RepositoriesController; def rescue_action(e) raise e end; end
24 class RepositoriesControllerTest < ActionController::TestCase
25 fixtures :projects, :users, :roles, :members, :member_roles, :repositories, :issues, :issue_statuses, :changesets, :changes, :issue_categories, :enumerations, :custom_fields, :custom_values, :trackers
28 @controller = RepositoriesController.new
29 @request = ActionController::TestRequest.new
30 @response = ActionController::TestResponse.new
36 {:method => :get, :path => '/projects/redmine/repository'},
37 :controller => 'repositories', :action => 'show', :id => 'redmine'
43 {:method => :get, :path => '/projects/world_domination/repository/edit'},
44 :controller => 'repositories', :action => 'edit', :id => 'world_domination'
47 {:method => :post, :path => '/projects/world_domination/repository/edit'},
48 :controller => 'repositories', :action => 'edit', :id => 'world_domination'
52 def test_revisions_routing
54 {:method => :get, :path => '/projects/redmine/repository/revisions'},
55 :controller => 'repositories', :action => 'revisions', :id => 'redmine'
59 def test_revisions_atom_routing
61 {:method => :get, :path => '/projects/redmine/repository/revisions.atom'},
62 :controller => 'repositories', :action => 'revisions', :id => 'redmine', :format => 'atom'
67 get :revisions, :id => 1
68 assert_response :success
69 assert_template 'revisions'
70 assert_not_nil assigns(:changesets)
73 def test_revision_routing
75 {:method => :get, :path => '/projects/restmine/repository/revisions/2457'},
76 :controller => 'repositories', :action => 'revision', :id => 'restmine', :rev => '2457'
81 get :revision, :id => 1, :rev => 1
82 assert_response :success
83 assert_not_nil assigns(:changeset)
84 assert_equal "1", assigns(:changeset).revision
87 def test_revision_with_before_nil_and_afer_normal
88 get :revision, {:id => 1, :rev => 1}
89 assert_response :success
90 assert_template 'revision'
91 assert_no_tag :tag => "div", :attributes => { :class => "contextual" },
92 :child => { :tag => "a", :attributes => { :href => '/projects/ecookbook/repository/revisions/0'}
94 assert_tag :tag => "div", :attributes => { :class => "contextual" },
95 :child => { :tag => "a", :attributes => { :href => '/projects/ecookbook/repository/revisions/2'}
101 {:method => :get, :path => '/projects/restmine/repository/revisions/2457/diff'},
102 :controller => 'repositories', :action => 'diff', :id => 'restmine', :rev => '2457'
106 def test_unified_diff_routing
108 {:method => :get, :path => '/projects/restmine/repository/revisions/2457/diff.diff'},
109 :controller => 'repositories', :action => 'diff', :id => 'restmine', :rev => '2457', :format => 'diff'
113 def test_diff_path_routing
115 {:method => :get, :path => '/projects/restmine/repository/diff/path/to/file.c'},
116 :controller => 'repositories', :action => 'diff', :id => 'restmine', :path => %w[path to file.c]
120 def test_diff_path_routing_with_revision
122 {:method => :get, :path => '/projects/restmine/repository/revisions/2/diff/path/to/file.c'},
123 :controller => 'repositories', :action => 'diff', :id => 'restmine', :path => %w[path to file.c], :rev => '2'
127 def test_browse_routing
129 {:method => :get, :path => '/projects/restmine/repository/browse/path/to/dir'},
130 :controller => 'repositories', :action => 'browse', :id => 'restmine', :path => %w[path to dir]
134 def test_entry_routing
136 {:method => :get, :path => '/projects/restmine/repository/entry/path/to/file.c'},
137 :controller => 'repositories', :action => 'entry', :id => 'restmine', :path => %w[path to file.c]
141 def test_entry_routing_with_revision
143 {:method => :get, :path => '/projects/restmine/repository/revisions/2/entry/path/to/file.c'},
144 :controller => 'repositories', :action => 'entry', :id => 'restmine', :path => %w[path to file.c], :rev => '2'
150 {:method => :get, :path => '/projects/restmine/repository/raw/path/to/file.c'},
151 :controller => 'repositories', :action => 'entry', :id => 'restmine', :path => %w[path to file.c], :format => 'raw'
155 def test_raw_routing_with_revision
157 {:method => :get, :path => '/projects/restmine/repository/revisions/2/raw/path/to/file.c'},
158 :controller => 'repositories', :action => 'entry', :id => 'restmine', :path => %w[path to file.c], :format => 'raw', :rev => '2'
162 def test_annotate_routing
164 {:method => :get, :path => '/projects/restmine/repository/annotate/path/to/file.c'},
165 :controller => 'repositories', :action => 'annotate', :id => 'restmine', :path => %w[path to file.c]
169 def test_changesrouting
171 {:method => :get, :path => '/projects/restmine/repository/changes/path/to/file.c'},
172 :controller => 'repositories', :action => 'changes', :id => 'restmine', :path => %w[path to file.c]
176 def test_statistics_routing
178 {:method => :get, :path => '/projects/restmine/repository/statistics'},
179 :controller => 'repositories', :action => 'stats', :id => 'restmine'
183 def test_graph_commits_per_month
184 get :graph, :id => 1, :graph => 'commits_per_month'
185 assert_response :success
186 assert_equal 'image/svg+xml', @response.content_type
189 def test_graph_commits_per_author
190 get :graph, :id => 1, :graph => 'commits_per_author'
191 assert_response :success
192 assert_equal 'image/svg+xml', @response.content_type
196 @request.session[:user_id] = 2
197 # add a commit with an unknown user
198 Changeset.create!(:repository => Project.find(1).repository, :committer => 'foo', :committed_on => Time.now, :revision => 100, :comments => 'Committed by foo.')
200 get :committers, :id => 1
201 assert_response :success
202 assert_template 'committers'
204 assert_tag :td, :content => 'dlopper',
205 :sibling => { :tag => 'td',
206 :child => { :tag => 'select', :attributes => { :name => %r{^committers\[\d+\]\[\]$} },
207 :child => { :tag => 'option', :content => 'Dave Lopper',
208 :attributes => { :value => '3', :selected => 'selected' }}}}
209 assert_tag :td, :content => 'foo',
210 :sibling => { :tag => 'td',
211 :child => { :tag => 'select', :attributes => { :name => %r{^committers\[\d+\]\[\]$} }}}
212 assert_no_tag :td, :content => 'foo',
213 :sibling => { :tag => 'td',
214 :descendant => { :tag => 'option', :attributes => { :selected => 'selected' }}}
217 def test_map_committers
218 @request.session[:user_id] = 2
219 # add a commit with an unknown user
220 c = Changeset.create!(:repository => Project.find(1).repository, :committer => 'foo', :committed_on => Time.now, :revision => 100, :comments => 'Committed by foo.')
222 assert_no_difference "Changeset.count(:conditions => 'user_id = 3')" do
223 post :committers, :id => 1, :committers => { '0' => ['foo', '2'], '1' => ['dlopper', '3']}
224 assert_redirected_to 'projects/ecookbook/repository/committers'
225 assert_equal User.find(2), c.reload.user