1
0
mirror of https://github.com/meineerde/redmine.git synced 2025-12-19 23:11:12 +00:00

Backported r4441 to r4444 from trunk.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/1.0-stable@4445 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2010-11-27 16:45:07 +00:00
parent b58382ef2e
commit bac64c9ab4
2 changed files with 54 additions and 30 deletions

View File

@ -24,7 +24,7 @@ class ProjectsController < ApplicationController
before_filter :authorize, :except => [ :index, :list, :new, :create, :copy, :archive, :unarchive, :destroy] before_filter :authorize, :except => [ :index, :list, :new, :create, :copy, :archive, :unarchive, :destroy]
before_filter :authorize_global, :only => [:new, :create] before_filter :authorize_global, :only => [:new, :create]
before_filter :require_admin, :only => [ :copy, :archive, :unarchive, :destroy ] before_filter :require_admin, :only => [ :copy, :archive, :unarchive, :destroy ]
accept_key_auth :index accept_key_auth :index, :show, :create, :update, :destroy
after_filter :only => [:create, :edit, :update, :archive, :unarchive, :destroy] do |controller| after_filter :only => [:create, :edit, :update, :archive, :unarchive, :destroy] do |controller|
if controller.request.post? if controller.request.post?

View File

@ -32,22 +32,36 @@ class ApiTest::ProjectsTest < ActionController::IntegrationTest
assert_equal 'application/xml', @response.content_type assert_equal 'application/xml', @response.content_type
end end
context "GET /projects/2.xml" do
# TODO: A private project is needed because should_allow_api_authentication
# actually tests that authentication is *required*, not just allowed
should_allow_api_authentication(:get, "/projects/2.xml")
end
def test_show def test_show
get '/projects/1.xml' get '/projects/1.xml'
assert_response :success assert_response :success
assert_equal 'application/xml', @response.content_type assert_equal 'application/xml', @response.content_type
end end
def test_create context "POST /projects.xml" do
attributes = {:name => 'API test', :identifier => 'api-test'} should_allow_api_authentication(:post,
assert_difference 'Project.count' do '/projects.xml',
post '/projects.xml', {:project => attributes}, :authorization => credentials('admin') {:project => {:name => 'API test', :identifier => 'api-test'}},
end {:success_code => :created})
assert_response :created
assert_equal 'application/xml', @response.content_type should "create a project with the attributes" do
project = Project.first(:order => 'id DESC') assert_difference('Project.count') do
attributes.each do |attribute, value| post '/projects.xml', {:project => {:name => 'API test', :identifier => 'api-test'}}, :authorization => credentials('admin')
assert_equal value, project.send(attribute) end
project = Project.first(:order => 'id DESC')
assert_equal 'API test', project.name
assert_equal 'api-test', project.identifier
assert_response :created
assert_equal 'application/xml', @response.content_type
assert_tag 'project', :child => {:tag => 'id', :content => project.id.to_s}
end end
end end
@ -61,16 +75,20 @@ class ApiTest::ProjectsTest < ActionController::IntegrationTest
assert_tag :errors, :child => {:tag => 'error', :content => "Identifier can't be blank"} assert_tag :errors, :child => {:tag => 'error', :content => "Identifier can't be blank"}
end end
def test_update context "PUT /projects/2.xml" do
attributes = {:name => 'API update'} should_allow_api_authentication(:put,
assert_no_difference 'Project.count' do '/projects/2.xml',
put '/projects/1.xml', {:project => attributes}, :authorization => credentials('jsmith') {:project => {:name => 'API test'}},
end {:success_code => :ok})
assert_response :ok
assert_equal 'application/xml', @response.content_type should "update the project" do
project = Project.find(1) assert_no_difference 'Project.count' do
attributes.each do |attribute, value| put '/projects/2.xml', {:project => {:name => 'API update'}}, :authorization => credentials('jsmith')
assert_equal value, project.send(attribute) end
assert_response :ok
assert_equal 'application/xml', @response.content_type
project = Project.find(2)
assert_equal 'API update', project.name
end end
end end
@ -84,13 +102,19 @@ class ApiTest::ProjectsTest < ActionController::IntegrationTest
assert_tag :errors, :child => {:tag => 'error', :content => "Name can't be blank"} assert_tag :errors, :child => {:tag => 'error', :content => "Name can't be blank"}
end end
def test_destroy context "DELETE /projects/2.xml" do
assert_difference 'Project.count', -1 do should_allow_api_authentication(:delete,
delete '/projects/2.xml', {}, :authorization => credentials('admin') '/projects/2.xml',
{},
{:success_code => :ok})
should "delete the project" do
assert_difference('Project.count',-1) do
delete '/projects/2.xml', {}, :authorization => credentials('admin')
end
assert_response :ok
assert_nil Project.find_by_id(2)
end end
assert_response :ok
assert_equal 'application/xml', @response.content_type
assert_nil Project.find_by_id(2)
end end
def credentials(user, password=nil) def credentials(user, password=nil)