| 
									
										
										
										
											2009-02-10 22:03:25 +00:00
										 |  |  | # Redmine - project management software | 
					
						
							| 
									
										
										
										
											2011-03-16 20:31:01 +00:00
										 |  |  | # Copyright (C) 2006-2011  Jean-Philippe Lang | 
					
						
							| 
									
										
										
										
											2009-02-10 22:03:25 +00:00
										 |  |  | # | 
					
						
							|  |  |  | # This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  | # modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  | # as published by the Free Software Foundation; either version 2 | 
					
						
							|  |  |  | # of the License, or (at your option) any later version. | 
					
						
							| 
									
										
										
										
											2011-05-25 04:40:18 +00:00
										 |  |  | # | 
					
						
							| 
									
										
										
										
											2009-02-10 22:03:25 +00:00
										 |  |  | # This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  | # but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  | # GNU General Public License for more details. | 
					
						
							| 
									
										
										
										
											2011-05-25 04:40:18 +00:00
										 |  |  | # | 
					
						
							| 
									
										
										
										
											2009-02-10 22:03:25 +00:00
										 |  |  | # You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  | # along with this program; if not, write to the Free Software | 
					
						
							|  |  |  | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-12 23:24:34 +00:00
										 |  |  | require File.expand_path('../../test_helper', __FILE__) | 
					
						
							| 
									
										
										
										
											2009-02-10 22:03:25 +00:00
										 |  |  | require 'sys_controller' | 
					
						
							| 
									
										
										
										
											2011-03-16 20:31:01 +00:00
										 |  |  | require 'mocha' | 
					
						
							| 
									
										
										
										
											2009-02-10 22:03:25 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | # Re-raise errors caught by the controller. | 
					
						
							|  |  |  | class SysController; def rescue_action(e) raise e end; end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-13 17:14:35 +00:00
										 |  |  | class SysControllerTest < ActionController::TestCase | 
					
						
							| 
									
										
										
										
											2011-03-16 20:31:01 +00:00
										 |  |  |   fixtures :projects, :repositories, :enabled_modules | 
					
						
							| 
									
										
										
										
											2011-05-25 04:40:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-10 22:03:25 +00:00
										 |  |  |   def setup | 
					
						
							|  |  |  |     @controller = SysController.new | 
					
						
							|  |  |  |     @request    = ActionController::TestRequest.new | 
					
						
							|  |  |  |     @response   = ActionController::TestResponse.new | 
					
						
							|  |  |  |     Setting.sys_api_enabled = '1' | 
					
						
							| 
									
										
										
										
											2009-03-01 10:55:01 +00:00
										 |  |  |     Setting.enabled_scm = %w(Subversion Git) | 
					
						
							| 
									
										
										
										
											2009-02-10 22:03:25 +00:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-05-25 04:40:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-10 22:03:25 +00:00
										 |  |  |   def test_projects_with_repository_enabled | 
					
						
							|  |  |  |     get :projects | 
					
						
							|  |  |  |     assert_response :success | 
					
						
							|  |  |  |     assert_equal 'application/xml', @response.content_type | 
					
						
							|  |  |  |     with_options :tag => 'projects' do |test| | 
					
						
							|  |  |  |       test.assert_tag :children => { :count  => Project.active.has_module(:repository).count } | 
					
						
							| 
									
										
										
										
											2011-11-27 17:30:28 +00:00
										 |  |  |       test.assert_tag 'project', :child => {:tag => 'identifier', :sibling => {:tag => 'is-public'}} | 
					
						
							| 
									
										
										
										
											2009-02-10 22:03:25 +00:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2011-11-27 17:30:28 +00:00
										 |  |  |     assert_no_tag 'extra-info' | 
					
						
							|  |  |  |     assert_no_tag 'extra_info' | 
					
						
							| 
									
										
										
										
											2009-02-10 22:03:25 +00:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_create_project_repository | 
					
						
							|  |  |  |     assert_nil Project.find(4).repository | 
					
						
							| 
									
										
										
										
											2011-05-25 04:40:18 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     post :create_project_repository, :id => 4, | 
					
						
							| 
									
										
										
										
											2009-02-10 22:03:25 +00:00
										 |  |  |                                      :vendor => 'Subversion', | 
					
						
							|  |  |  |                                      :repository => { :url => 'file:///create/project/repository/subproject2'} | 
					
						
							|  |  |  |     assert_response :created | 
					
						
							| 
									
										
										
										
											2011-11-27 17:30:28 +00:00
										 |  |  |     assert_equal 'application/xml', @response.content_type | 
					
						
							| 
									
										
										
										
											2011-05-25 04:40:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-10 22:03:25 +00:00
										 |  |  |     r = Project.find(4).repository | 
					
						
							|  |  |  |     assert r.is_a?(Repository::Subversion) | 
					
						
							|  |  |  |     assert_equal 'file:///create/project/repository/subproject2', r.url | 
					
						
							| 
									
										
										
										
											2011-11-27 17:30:28 +00:00
										 |  |  |      | 
					
						
							|  |  |  |     assert_tag 'repository-subversion', | 
					
						
							|  |  |  |       :child => { | 
					
						
							|  |  |  |         :tag => 'id', :content => r.id.to_s, | 
					
						
							|  |  |  |         :sibling => {:tag => 'url', :content => r.url} | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     assert_no_tag 'extra-info' | 
					
						
							|  |  |  |     assert_no_tag 'extra_info' | 
					
						
							| 
									
										
										
										
											2009-02-10 22:03:25 +00:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-05-25 04:40:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-03 13:59:17 +00:00
										 |  |  |   def test_create_already_existing | 
					
						
							|  |  |  |     post :create_project_repository, :id => 1, | 
					
						
							|  |  |  |       :vendor => 'Subversion', | 
					
						
							|  |  |  |       :repository => { :url => 'file:///create/project/repository/subproject2'} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     assert_response :conflict | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_create_with_failure | 
					
						
							|  |  |  |     post :create_project_repository, :id => 4, | 
					
						
							|  |  |  |       :vendor => 'Subversion', | 
					
						
							|  |  |  |       :repository => { :url => 'invalid url'} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     assert_response :unprocessable_entity | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-28 16:50:26 +00:00
										 |  |  |   def test_fetch_changesets | 
					
						
							| 
									
										
										
										
											2012-01-15 14:23:06 +00:00
										 |  |  |     Repository::Subversion.any_instance.expects(:fetch_changesets).twice.returns(true) | 
					
						
							| 
									
										
										
										
											2009-11-28 16:50:26 +00:00
										 |  |  |     get :fetch_changesets | 
					
						
							|  |  |  |     assert_response :success | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-05-25 04:40:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-25 12:57:30 +00:00
										 |  |  |   def test_fetch_changesets_one_project_by_identifier | 
					
						
							| 
									
										
										
										
											2012-01-15 14:23:06 +00:00
										 |  |  |     Repository::Subversion.any_instance.expects(:fetch_changesets).once.returns(true) | 
					
						
							| 
									
										
										
										
											2009-11-28 16:50:26 +00:00
										 |  |  |     get :fetch_changesets, :id => 'ecookbook' | 
					
						
							|  |  |  |     assert_response :success | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-05-25 04:40:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-25 12:57:30 +00:00
										 |  |  |   def test_fetch_changesets_one_project_by_id | 
					
						
							|  |  |  |     Repository::Subversion.any_instance.expects(:fetch_changesets).once.returns(true) | 
					
						
							|  |  |  |     get :fetch_changesets, :id => '1' | 
					
						
							|  |  |  |     assert_response :success | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-28 16:50:26 +00:00
										 |  |  |   def test_fetch_changesets_unknown_project | 
					
						
							|  |  |  |     get :fetch_changesets, :id => 'unknown' | 
					
						
							|  |  |  |     assert_response 404
 | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-05-25 04:40:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-20 09:44:28 +00:00
										 |  |  |   def test_disabled_ws_should_respond_with_403_error | 
					
						
							|  |  |  |     with_settings :sys_api_enabled => '0' do | 
					
						
							|  |  |  |       get :projects | 
					
						
							|  |  |  |       assert_response 403
 | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-05-25 04:40:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-20 09:44:28 +00:00
										 |  |  |   def test_api_key | 
					
						
							|  |  |  |     with_settings :sys_api_key => 'my_secret_key' do | 
					
						
							|  |  |  |       get :projects, :key => 'my_secret_key' | 
					
						
							|  |  |  |       assert_response :success | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-05-25 04:40:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-20 09:44:28 +00:00
										 |  |  |   def test_wrong_key_should_respond_with_403_error | 
					
						
							|  |  |  |     with_settings :sys_api_enabled => 'my_secret_key' do | 
					
						
							|  |  |  |       get :projects, :key => 'wrong_key' | 
					
						
							|  |  |  |       assert_response 403
 | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2009-02-10 22:03:25 +00:00
										 |  |  | end |