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