Commit 135ea58d authored by jplang's avatar jplang

Use JSON instead of XML for reposman.rb.

git-svn-id: https://svn.redmine.org/redmine/trunk@16591 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent f35fe923
......@@ -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
......
......@@ -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);
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment