annotate test/functional/issue_relations_controller_test.rb @ 1082:997f6d7738f7 bug_531

In repo controller entry action, show the page for the file even if it's binary (so user still has access to history etc links). This makes it possible to use the entry action as the default when a file is clicked on
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Thu, 22 Nov 2012 18:04:17 +0000
parents cbb26bc654de
children 433d4f72a19b
rev   line source
Chris@909 1 # Redmine - project management software
Chris@909 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
Chris@909 3 #
Chris@909 4 # This program is free software; you can redistribute it and/or
Chris@909 5 # modify it under the terms of the GNU General Public License
Chris@909 6 # as published by the Free Software Foundation; either version 2
Chris@909 7 # of the License, or (at your option) any later version.
Chris@909 8 #
Chris@909 9 # This program is distributed in the hope that it will be useful,
Chris@909 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@909 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@909 12 # GNU General Public License for more details.
Chris@909 13 #
Chris@909 14 # You should have received a copy of the GNU General Public License
Chris@909 15 # along with this program; if not, write to the Free Software
Chris@909 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@909 17
Chris@119 18 require File.expand_path('../../test_helper', __FILE__)
Chris@0 19 require 'issue_relations_controller'
Chris@0 20
Chris@0 21 # Re-raise errors caught by the controller.
Chris@0 22 class IssueRelationsController; def rescue_action(e) raise e end; end
Chris@0 23
Chris@0 24
Chris@0 25 class IssueRelationsControllerTest < ActionController::TestCase
Chris@0 26 fixtures :projects,
Chris@0 27 :users,
Chris@0 28 :roles,
Chris@0 29 :members,
Chris@0 30 :member_roles,
Chris@0 31 :issues,
Chris@0 32 :issue_statuses,
Chris@0 33 :issue_relations,
Chris@0 34 :enabled_modules,
Chris@0 35 :enumerations,
Chris@0 36 :trackers
Chris@909 37
Chris@0 38 def setup
Chris@0 39 @controller = IssueRelationsController.new
Chris@0 40 @request = ActionController::TestRequest.new
Chris@0 41 @response = ActionController::TestResponse.new
Chris@0 42 User.current = nil
Chris@0 43 end
Chris@909 44
Chris@909 45 def test_create
Chris@0 46 assert_difference 'IssueRelation.count' do
Chris@0 47 @request.session[:user_id] = 3
Chris@909 48 post :create, :issue_id => 1,
Chris@0 49 :relation => {:issue_to_id => '2', :relation_type => 'relates', :delay => ''}
Chris@0 50 end
Chris@0 51 end
Chris@909 52
Chris@909 53 def test_create_xhr
Chris@210 54 assert_difference 'IssueRelation.count' do
Chris@210 55 @request.session[:user_id] = 3
Chris@909 56 xhr :post, :create,
Chris@909 57 :issue_id => 3,
Chris@210 58 :relation => {:issue_to_id => '1', :relation_type => 'relates', :delay => ''}
Chris@210 59 assert_select_rjs 'relations' do
Chris@210 60 assert_select 'table', 1
Chris@210 61 assert_select 'tr', 2 # relations
Chris@210 62 end
Chris@210 63 end
Chris@210 64 end
Chris@909 65
Chris@909 66 def test_create_should_accept_id_with_hash
Chris@0 67 assert_difference 'IssueRelation.count' do
Chris@0 68 @request.session[:user_id] = 3
Chris@909 69 post :create, :issue_id => 1,
Chris@0 70 :relation => {:issue_to_id => '#2', :relation_type => 'relates', :delay => ''}
Chris@0 71 end
Chris@0 72 end
Chris@909 73
Chris@909 74 def test_create_should_not_break_with_non_numerical_id
Chris@0 75 assert_no_difference 'IssueRelation.count' do
Chris@0 76 assert_nothing_raised do
Chris@0 77 @request.session[:user_id] = 3
Chris@909 78 post :create, :issue_id => 1,
Chris@0 79 :relation => {:issue_to_id => 'foo', :relation_type => 'relates', :delay => ''}
Chris@0 80 end
Chris@0 81 end
Chris@0 82 end
Chris@909 83
Chris@0 84 def test_should_create_relations_with_visible_issues_only
Chris@0 85 Setting.cross_project_issue_relations = '1'
Chris@0 86 assert_nil Issue.visible(User.find(3)).find_by_id(4)
Chris@909 87
Chris@0 88 assert_no_difference 'IssueRelation.count' do
Chris@0 89 @request.session[:user_id] = 3
Chris@909 90 post :create, :issue_id => 1,
Chris@0 91 :relation => {:issue_to_id => '4', :relation_type => 'relates', :delay => ''}
Chris@0 92 end
Chris@0 93 end
Chris@507 94
Chris@507 95 should "prevent relation creation when there's a circular dependency"
Chris@909 96
Chris@0 97 def test_destroy
Chris@0 98 assert_difference 'IssueRelation.count', -1 do
Chris@0 99 @request.session[:user_id] = 3
Chris@909 100 delete :destroy, :id => '2'
Chris@0 101 end
Chris@0 102 end
Chris@909 103
Chris@210 104 def test_destroy_xhr
Chris@210 105 IssueRelation.create!(:relation_type => IssueRelation::TYPE_RELATES) do |r|
Chris@210 106 r.issue_from_id = 3
Chris@210 107 r.issue_to_id = 1
Chris@210 108 end
Chris@909 109
Chris@210 110 assert_difference 'IssueRelation.count', -1 do
Chris@210 111 @request.session[:user_id] = 3
Chris@909 112 xhr :delete, :destroy, :id => '2'
Chris@909 113 assert_select_rjs :remove, 'relation-2'
Chris@210 114 end
Chris@210 115 end
Chris@0 116 end