Chris@0
|
1 # redMine - project management software
|
Chris@0
|
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
|
Chris@0
|
3 #
|
Chris@0
|
4 # This program is free software; you can redistribute it and/or
|
Chris@0
|
5 # modify it under the terms of the GNU General Public License
|
Chris@0
|
6 # as published by the Free Software Foundation; either version 2
|
Chris@0
|
7 # of the License, or (at your option) any later version.
|
Chris@0
|
8 #
|
Chris@0
|
9 # This program is distributed in the hope that it will be useful,
|
Chris@0
|
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Chris@0
|
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Chris@0
|
12 # GNU General Public License for more details.
|
Chris@0
|
13 #
|
Chris@0
|
14 # You should have received a copy of the GNU General Public License
|
Chris@0
|
15 # along with this program; if not, write to the Free Software
|
Chris@0
|
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Chris@0
|
17
|
Chris@0
|
18 require File.dirname(__FILE__) + '/../test_helper'
|
Chris@0
|
19 require 'repositories_controller'
|
Chris@0
|
20
|
Chris@0
|
21 # Re-raise errors caught by the controller.
|
Chris@0
|
22 class RepositoriesController; def rescue_action(e) raise e end; end
|
Chris@0
|
23
|
Chris@0
|
24 class RepositoriesControllerTest < ActionController::TestCase
|
Chris@0
|
25 fixtures :projects, :users, :roles, :members, :member_roles, :repositories, :issues, :issue_statuses, :changesets, :changes, :issue_categories, :enumerations, :custom_fields, :custom_values, :trackers
|
Chris@0
|
26
|
Chris@0
|
27 def setup
|
Chris@0
|
28 @controller = RepositoriesController.new
|
Chris@0
|
29 @request = ActionController::TestRequest.new
|
Chris@0
|
30 @response = ActionController::TestResponse.new
|
Chris@0
|
31 User.current = nil
|
Chris@0
|
32 end
|
Chris@0
|
33
|
Chris@0
|
34 def test_revisions
|
Chris@0
|
35 get :revisions, :id => 1
|
Chris@0
|
36 assert_response :success
|
Chris@0
|
37 assert_template 'revisions'
|
Chris@0
|
38 assert_not_nil assigns(:changesets)
|
Chris@0
|
39 end
|
Chris@0
|
40
|
Chris@0
|
41 def test_revision
|
Chris@0
|
42 get :revision, :id => 1, :rev => 1
|
Chris@0
|
43 assert_response :success
|
Chris@0
|
44 assert_not_nil assigns(:changeset)
|
Chris@0
|
45 assert_equal "1", assigns(:changeset).revision
|
Chris@0
|
46 end
|
Chris@0
|
47
|
Chris@0
|
48 def test_revision_with_before_nil_and_afer_normal
|
Chris@0
|
49 get :revision, {:id => 1, :rev => 1}
|
Chris@0
|
50 assert_response :success
|
Chris@0
|
51 assert_template 'revision'
|
Chris@0
|
52 assert_no_tag :tag => "div", :attributes => { :class => "contextual" },
|
Chris@0
|
53 :child => { :tag => "a", :attributes => { :href => '/projects/ecookbook/repository/revisions/0'}
|
Chris@0
|
54 }
|
Chris@0
|
55 assert_tag :tag => "div", :attributes => { :class => "contextual" },
|
Chris@0
|
56 :child => { :tag => "a", :attributes => { :href => '/projects/ecookbook/repository/revisions/2'}
|
Chris@0
|
57 }
|
Chris@0
|
58 end
|
Chris@0
|
59
|
Chris@0
|
60 def test_graph_commits_per_month
|
Chris@0
|
61 get :graph, :id => 1, :graph => 'commits_per_month'
|
Chris@0
|
62 assert_response :success
|
Chris@0
|
63 assert_equal 'image/svg+xml', @response.content_type
|
Chris@0
|
64 end
|
Chris@0
|
65
|
Chris@0
|
66 def test_graph_commits_per_author
|
Chris@0
|
67 get :graph, :id => 1, :graph => 'commits_per_author'
|
Chris@0
|
68 assert_response :success
|
Chris@0
|
69 assert_equal 'image/svg+xml', @response.content_type
|
Chris@0
|
70 end
|
Chris@0
|
71
|
Chris@0
|
72 def test_committers
|
Chris@0
|
73 @request.session[:user_id] = 2
|
Chris@0
|
74 # add a commit with an unknown user
|
Chris@0
|
75 Changeset.create!(:repository => Project.find(1).repository, :committer => 'foo', :committed_on => Time.now, :revision => 100, :comments => 'Committed by foo.')
|
Chris@0
|
76
|
Chris@0
|
77 get :committers, :id => 1
|
Chris@0
|
78 assert_response :success
|
Chris@0
|
79 assert_template 'committers'
|
Chris@0
|
80
|
Chris@0
|
81 assert_tag :td, :content => 'dlopper',
|
Chris@0
|
82 :sibling => { :tag => 'td',
|
Chris@0
|
83 :child => { :tag => 'select', :attributes => { :name => %r{^committers\[\d+\]\[\]$} },
|
Chris@0
|
84 :child => { :tag => 'option', :content => 'Dave Lopper',
|
Chris@0
|
85 :attributes => { :value => '3', :selected => 'selected' }}}}
|
Chris@0
|
86 assert_tag :td, :content => 'foo',
|
Chris@0
|
87 :sibling => { :tag => 'td',
|
Chris@0
|
88 :child => { :tag => 'select', :attributes => { :name => %r{^committers\[\d+\]\[\]$} }}}
|
Chris@0
|
89 assert_no_tag :td, :content => 'foo',
|
Chris@0
|
90 :sibling => { :tag => 'td',
|
Chris@0
|
91 :descendant => { :tag => 'option', :attributes => { :selected => 'selected' }}}
|
Chris@0
|
92 end
|
Chris@0
|
93
|
Chris@0
|
94 def test_map_committers
|
Chris@0
|
95 @request.session[:user_id] = 2
|
Chris@0
|
96 # add a commit with an unknown user
|
Chris@0
|
97 c = Changeset.create!(:repository => Project.find(1).repository, :committer => 'foo', :committed_on => Time.now, :revision => 100, :comments => 'Committed by foo.')
|
Chris@0
|
98
|
Chris@0
|
99 assert_no_difference "Changeset.count(:conditions => 'user_id = 3')" do
|
Chris@0
|
100 post :committers, :id => 1, :committers => { '0' => ['foo', '2'], '1' => ['dlopper', '3']}
|
chris@37
|
101 assert_redirected_to '/projects/ecookbook/repository/committers'
|
Chris@0
|
102 assert_equal User.find(2), c.reload.user
|
Chris@0
|
103 end
|
Chris@0
|
104 end
|
Chris@0
|
105 end
|