diff options
-rw-r--r-- | app/controllers/sys_controller.rb | 7 | ||||
-rwxr-xr-x | extra/svn/reposman.rb | 4 | ||||
-rw-r--r-- | test/functional/sys_controller_test.rb | 39 |
3 files changed, 26 insertions, 24 deletions
diff --git a/app/controllers/sys_controller.rb b/app/controllers/sys_controller.rb index 6ef72a15f..e7f5ebe12 100644 --- a/app/controllers/sys_controller.rb +++ b/app/controllers/sys_controller.rb @@ -22,7 +22,7 @@ class SysController < ActionController::Base p = Project.active.has_module(:repository). order("#{Project.table_name}.identifier").preload(:repository).to_a # extra_info attribute from repository breaks activeresource client - render :xml => p.to_xml( + render :json => p.to_json( :only => [:id, :identifier, :name, :is_public, :status], :include => {:repository => {:only => [:id, :url]}} ) @@ -34,10 +34,11 @@ class SysController < ActionController::Base head 409 else logger.info "Repository for #{project.name} was reported to be created by #{request.remote_ip}." - repository = Repository.factory(params[:vendor], params[:repository]) + repository = Repository.factory(params[:vendor]) + repository.safe_attributes = params[:repository] repository.project = project if repository.save - render :xml => {repository.class.name.underscore.gsub('/', '-') => {:id => repository.id, :url => repository.url}}, :status => 201 + render :json => {repository.class.name.underscore.gsub('/', '-') => {:id => repository.id, :url => repository.url}}, :status => 201 else head 422 end diff --git a/extra/svn/reposman.rb b/extra/svn/reposman.rb index d79ad2695..4e2f53a28 100755 --- a/extra/svn/reposman.rb +++ b/extra/svn/reposman.rb @@ -5,7 +5,7 @@ require 'find' require 'etc' require 'rubygems' -Version = "1.4" +Version = "1.5" SUPPORTED_SCM = %w( Subversion Darcs Mercurial Bazaar Git Filesystem ) $verbose = 0 @@ -160,7 +160,7 @@ end class Project < ActiveResource::Base self.headers["User-agent"] = "Redmine repository manager/#{Version}" - self.format = :xml + self.format = :json end log("querying Redmine for projects...", :level => 1); diff --git a/test/functional/sys_controller_test.rb b/test/functional/sys_controller_test.rb index becd4ec42..8bd1aedf9 100644 --- a/test/functional/sys_controller_test.rb +++ b/test/functional/sys_controller_test.rb @@ -32,17 +32,17 @@ class SysControllerTest < Redmine::ControllerTest def test_projects_with_repository_enabled get :projects assert_response :success - assert_equal 'application/xml', @response.content_type - - assert_select 'projects' do - assert_select 'project', Project.active.has_module(:repository).count - assert_select 'project' do - assert_select 'identifier' - assert_select 'is-public' - end - end - assert_select 'extra-info', 0 - assert_select 'extra_info', 0 + assert_equal 'application/json', @response.content_type + + data = ActiveSupport::JSON.decode(response.body) + + assert_equal Project.active.has_module(:repository).count, data.size + project = data.first + assert project['identifier'] + assert project['is_public'] + + assert_not_include 'extra-info', response.body + assert_not_include 'extra_info', response.body end def test_create_project_repository @@ -54,18 +54,19 @@ class SysControllerTest < Redmine::ControllerTest :repository => { :url => 'file:///create/project/repository/subproject2'} } assert_response :created - assert_equal 'application/xml', @response.content_type + assert_equal 'application/json', @response.content_type r = Project.find(4).repository assert r.is_a?(Repository::Subversion) assert_equal 'file:///create/project/repository/subproject2', r.url - - assert_select 'repository-subversion' do - assert_select 'id', :text => r.id.to_s - assert_select 'url', :text => r.url - end - assert_select 'extra-info', 0 - assert_select 'extra_info', 0 + + data = ActiveSupport::JSON.decode(response.body) + assert data['repository-subversion'] + assert_equal r.id, data['repository-subversion']['id'] + assert_equal r.url, data['repository-subversion']['url'] + + assert_not_include 'extra-info', response.body + assert_not_include 'extra_info', response.body end def test_create_already_existing |