OSDN Git Service

Move database.yml to template
[redminele/redminele.git] / redmine / test / functional / repositories_controller_test.rb
1 # redMine - project management software
2 # Copyright (C) 2006-2007  Jean-Philippe Lang
3 #
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.
8
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.
13
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.
17
18 require File.dirname(__FILE__) + '/../test_helper'
19 require 'repositories_controller'
20
21 # Re-raise errors caught by the controller.
22 class RepositoriesController; def rescue_action(e) raise e end; end
23
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
26   
27   def setup
28     @controller = RepositoriesController.new
29     @request    = ActionController::TestRequest.new
30     @response   = ActionController::TestResponse.new
31     User.current = nil
32   end
33   
34   def test_show_routing
35     assert_routing(
36       {:method => :get, :path => '/projects/redmine/repository'},
37       :controller => 'repositories', :action => 'show', :id => 'redmine'
38     )
39   end
40   
41   def test_edit_routing
42     assert_routing(
43       {:method => :get, :path => '/projects/world_domination/repository/edit'},
44       :controller => 'repositories', :action => 'edit', :id => 'world_domination'
45     )
46     assert_routing(
47       {:method => :post, :path => '/projects/world_domination/repository/edit'},
48       :controller => 'repositories', :action => 'edit', :id => 'world_domination'
49     )
50   end
51   
52   def test_revisions_routing
53     assert_routing(
54       {:method => :get, :path => '/projects/redmine/repository/revisions'},
55       :controller => 'repositories', :action => 'revisions', :id => 'redmine'
56     )
57   end
58   
59   def test_revisions_atom_routing
60     assert_routing(
61       {:method => :get, :path => '/projects/redmine/repository/revisions.atom'},
62       :controller => 'repositories', :action => 'revisions', :id => 'redmine', :format => 'atom'
63     )
64   end
65   
66   def test_revisions
67     get :revisions, :id => 1
68     assert_response :success
69     assert_template 'revisions'
70     assert_not_nil assigns(:changesets)
71   end
72
73   def test_revision_routing
74     assert_routing(
75       {:method => :get, :path => '/projects/restmine/repository/revisions/2457'},
76       :controller => 'repositories', :action => 'revision', :id => 'restmine', :rev => '2457'
77     )
78   end
79   
80   def test_revision
81     get :revision, :id => 1, :rev => 1
82     assert_response :success
83     assert_not_nil assigns(:changeset)
84     assert_equal "1", assigns(:changeset).revision
85   end
86   
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'}
93     }
94     assert_tag :tag => "div", :attributes => { :class => "contextual" },
95         :child => { :tag => "a", :attributes => { :href => '/projects/ecookbook/repository/revisions/2'}
96     }
97   end
98   
99   def test_diff_routing
100     assert_routing(
101       {:method => :get, :path => '/projects/restmine/repository/revisions/2457/diff'},
102       :controller => 'repositories', :action => 'diff', :id => 'restmine', :rev => '2457'
103     )
104   end
105   
106   def test_unified_diff_routing
107     assert_routing(
108       {:method => :get, :path => '/projects/restmine/repository/revisions/2457/diff.diff'},
109       :controller => 'repositories', :action => 'diff', :id => 'restmine', :rev => '2457', :format => 'diff'
110     )
111   end
112   
113   def test_diff_path_routing
114     assert_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]
117     )
118   end
119
120   def test_diff_path_routing_with_revision
121     assert_routing(
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'
124     )
125   end
126   
127   def test_browse_routing
128     assert_routing(
129       {:method => :get, :path => '/projects/restmine/repository/browse/path/to/dir'},
130       :controller => 'repositories', :action => 'browse', :id => 'restmine', :path => %w[path to dir]
131     )
132   end
133   
134   def test_entry_routing
135     assert_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]
138     )
139   end
140   
141   def test_entry_routing_with_revision
142     assert_routing(
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'
145     )
146   end
147
148   def test_raw_routing
149     assert_routing(
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'
152     )
153   end
154
155   def test_raw_routing_with_revision
156     assert_routing(
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'
159     )
160   end
161   
162   def test_annotate_routing
163     assert_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]
166     )
167   end
168   
169   def test_changesrouting
170     assert_routing(
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]
173     )
174   end
175   
176   def test_statistics_routing
177     assert_routing(
178       {:method => :get, :path => '/projects/restmine/repository/statistics'},
179       :controller => 'repositories', :action => 'stats', :id => 'restmine'
180     )
181   end
182   
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
187   end
188   
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
193   end
194   
195   def test_committers
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.')
199     
200     get :committers, :id => 1
201     assert_response :success
202     assert_template 'committers'
203     
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' }}}
215   end
216
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.')
221     
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
226     end
227   end
228 end