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]}}
)
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
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
: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