Skip to content

Commit

Permalink
Accept key auth for ProjectsController#create (#6841).
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4441 e93f8b46-1217-0410-a6f0-8f06a7374b81
  • Loading branch information
jplang committed Nov 27, 2010
1 parent d24e663 commit 8458fae
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ProjectsController < ApplicationController
before_filter :authorize, :except => [ :index, :list, :new, :create, :copy, :archive, :unarchive, :destroy]
before_filter :authorize_global, :only => [:new, :create]
before_filter :require_admin, :only => [ :copy, :archive, :unarchive, :destroy ]
accept_key_auth :index
accept_key_auth :index, :create

after_filter :only => [:create, :edit, :update, :archive, :unarchive, :destroy] do |controller|
if controller.request.post?
Expand Down
33 changes: 19 additions & 14 deletions test/integration/api_test/projects_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,26 @@ def test_show_should_not_display_hidden_custom_fields
assert_equal 'application/xml', @response.content_type
assert_no_tag 'custom_field', :attributes => {:name => 'Development status'}
end

def test_create
attributes = {:name => 'API test', :identifier => 'api-test'}
assert_difference 'Project.count' do
post '/projects.xml', {:project => attributes}, :authorization => credentials('admin')
end

project = Project.first(:order => 'id DESC')
attributes.each do |attribute, value|
assert_equal value, project.send(attribute)
end

context "POST /projects.xml" do
should_allow_api_authentication(:post,
'/projects.xml',
{:project => {:name => 'API test', :identifier => 'api-test'}},
{:success_code => :created})

assert_response :created
assert_equal 'application/xml', @response.content_type
assert_tag 'project', :child => {:tag => 'id', :content => project.id.to_s}
should "create a project with the attributes" do
assert_difference('Project.count') do
post '/projects.xml', {:project => {:name => 'API test', :identifier => 'api-test'}}, :authorization => credentials('admin')
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

def test_create_failure
Expand Down

0 comments on commit 8458fae

Please sign in to comment.