Chris@909: # Redmine - project management software Chris@909: # Copyright (C) 2006-2011 Jean-Philippe Lang Chris@0: # Chris@0: # This program is free software; you can redistribute it and/or Chris@0: # modify it under the terms of the GNU General Public License Chris@0: # as published by the Free Software Foundation; either version 2 Chris@0: # of the License, or (at your option) any later version. Chris@909: # Chris@0: # This program is distributed in the hope that it will be useful, Chris@0: # but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@0: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@0: # GNU General Public License for more details. Chris@909: # Chris@0: # You should have received a copy of the GNU General Public License Chris@0: # along with this program; if not, write to the Free Software Chris@0: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Chris@0: Chris@119: require File.expand_path('../../test_helper', __FILE__) Chris@0: require 'repositories_controller' Chris@0: Chris@0: # Re-raise errors caught by the controller. Chris@0: class RepositoriesController; def rescue_action(e) raise e end; end Chris@0: Chris@0: class RepositoriesControllerTest < ActionController::TestCase Chris@441: fixtures :projects, :users, :roles, :members, :member_roles, Chris@441: :repositories, :issues, :issue_statuses, :changesets, :changes, Chris@441: :issue_categories, :enumerations, :custom_fields, :custom_values, :trackers Chris@441: Chris@0: def setup Chris@0: @controller = RepositoriesController.new Chris@0: @request = ActionController::TestRequest.new Chris@0: @response = ActionController::TestResponse.new Chris@0: User.current = nil Chris@0: end Chris@441: Chris@0: def test_revisions Chris@0: get :revisions, :id => 1 Chris@0: assert_response :success Chris@0: assert_template 'revisions' Chris@0: assert_not_nil assigns(:changesets) Chris@0: end Chris@0: Chris@0: def test_revision Chris@0: get :revision, :id => 1, :rev => 1 Chris@0: assert_response :success Chris@0: assert_not_nil assigns(:changeset) Chris@0: assert_equal "1", assigns(:changeset).revision Chris@0: end Chris@441: Chris@0: def test_revision_with_before_nil_and_afer_normal Chris@0: get :revision, {:id => 1, :rev => 1} Chris@0: assert_response :success Chris@0: assert_template 'revision' Chris@0: assert_no_tag :tag => "div", :attributes => { :class => "contextual" }, Chris@0: :child => { :tag => "a", :attributes => { :href => '/projects/ecookbook/repository/revisions/0'} Chris@0: } Chris@0: assert_tag :tag => "div", :attributes => { :class => "contextual" }, Chris@0: :child => { :tag => "a", :attributes => { :href => '/projects/ecookbook/repository/revisions/2'} Chris@0: } Chris@0: end Chris@441: Chris@0: def test_graph_commits_per_month Chris@0: get :graph, :id => 1, :graph => 'commits_per_month' Chris@0: assert_response :success Chris@0: assert_equal 'image/svg+xml', @response.content_type Chris@0: end Chris@441: Chris@0: def test_graph_commits_per_author Chris@0: get :graph, :id => 1, :graph => 'commits_per_author' Chris@0: assert_response :success Chris@0: assert_equal 'image/svg+xml', @response.content_type Chris@0: end Chris@441: Chris@0: def test_committers Chris@0: @request.session[:user_id] = 2 Chris@0: # add a commit with an unknown user Chris@441: Changeset.create!( Chris@441: :repository => Project.find(1).repository, Chris@441: :committer => 'foo', Chris@441: :committed_on => Time.now, Chris@441: :revision => 100, Chris@441: :comments => 'Committed by foo.' Chris@441: ) Chris@441: Chris@0: get :committers, :id => 1 Chris@0: assert_response :success Chris@0: assert_template 'committers' Chris@909: Chris@0: assert_tag :td, :content => 'dlopper', Chris@0: :sibling => { :tag => 'td', Chris@0: :child => { :tag => 'select', :attributes => { :name => %r{^committers\[\d+\]\[\]$} }, Chris@0: :child => { :tag => 'option', :content => 'Dave Lopper', Chris@0: :attributes => { :value => '3', :selected => 'selected' }}}} Chris@0: assert_tag :td, :content => 'foo', Chris@0: :sibling => { :tag => 'td', Chris@0: :child => { :tag => 'select', :attributes => { :name => %r{^committers\[\d+\]\[\]$} }}} Chris@0: assert_no_tag :td, :content => 'foo', Chris@0: :sibling => { :tag => 'td', Chris@0: :descendant => { :tag => 'option', :attributes => { :selected => 'selected' }}} Chris@0: end Chris@0: Chris@0: def test_map_committers Chris@0: @request.session[:user_id] = 2 Chris@0: # add a commit with an unknown user Chris@441: c = Changeset.create!( Chris@441: :repository => Project.find(1).repository, Chris@441: :committer => 'foo', Chris@441: :committed_on => Time.now, Chris@441: :revision => 100, Chris@441: :comments => 'Committed by foo.' Chris@441: ) Chris@0: assert_no_difference "Changeset.count(:conditions => 'user_id = 3')" do Chris@0: post :committers, :id => 1, :committers => { '0' => ['foo', '2'], '1' => ['dlopper', '3']} chris@37: assert_redirected_to '/projects/ecookbook/repository/committers' Chris@0: assert_equal User.find(2), c.reload.user Chris@0: end Chris@0: end Chris@0: end