##// END OF EJS Templates
Accept key auth for ProjectsController#create (#6841)....
Jean-Philippe Lang -
r4327:8458faed1111
parent child
Show More
@@ -24,7 +24,7 class ProjectsController < ApplicationController
24 before_filter :authorize, :except => [ :index, :list, :new, :create, :copy, :archive, :unarchive, :destroy]
24 before_filter :authorize, :except => [ :index, :list, :new, :create, :copy, :archive, :unarchive, :destroy]
25 before_filter :authorize_global, :only => [:new, :create]
25 before_filter :authorize_global, :only => [:new, :create]
26 before_filter :require_admin, :only => [ :copy, :archive, :unarchive, :destroy ]
26 before_filter :require_admin, :only => [ :copy, :archive, :unarchive, :destroy ]
27 accept_key_auth :index
27 accept_key_auth :index, :create
28
28
29 after_filter :only => [:create, :edit, :update, :archive, :unarchive, :destroy] do |controller|
29 after_filter :only => [:create, :edit, :update, :archive, :unarchive, :destroy] do |controller|
30 if controller.request.post?
30 if controller.request.post?
@@ -46,21 +46,26 class ApiTest::ProjectsTest < ActionController::IntegrationTest
46 assert_equal 'application/xml', @response.content_type
46 assert_equal 'application/xml', @response.content_type
47 assert_no_tag 'custom_field', :attributes => {:name => 'Development status'}
47 assert_no_tag 'custom_field', :attributes => {:name => 'Development status'}
48 end
48 end
49
49
50 def test_create
50 context "POST /projects.xml" do
51 attributes = {:name => 'API test', :identifier => 'api-test'}
51 should_allow_api_authentication(:post,
52 assert_difference 'Project.count' do
52 '/projects.xml',
53 post '/projects.xml', {:project => attributes}, :authorization => credentials('admin')
53 {:project => {:name => 'API test', :identifier => 'api-test'}},
54 end
54 {:success_code => :created})
55
56 project = Project.first(:order => 'id DESC')
57 attributes.each do |attribute, value|
58 assert_equal value, project.send(attribute)
59 end
60
55
61 assert_response :created
56 should "create a project with the attributes" do
62 assert_equal 'application/xml', @response.content_type
57 assert_difference('Project.count') do
63 assert_tag 'project', :child => {:tag => 'id', :content => project.id.to_s}
58 post '/projects.xml', {:project => {:name => 'API test', :identifier => 'api-test'}}, :authorization => credentials('admin')
59 end
60
61 project = Project.first(:order => 'id DESC')
62 assert_equal 'API test', project.name
63 assert_equal 'api-test', project.identifier
64
65 assert_response :created
66 assert_equal 'application/xml', @response.content_type
67 assert_tag 'project', :child => {:tag => 'id', :content => project.id.to_s}
68 end
64 end
69 end
65
70
66 def test_create_failure
71 def test_create_failure
General Comments 0
You need to be logged in to leave comments. Login now