Removed some shoulda context.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11863 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2013-05-18 08:57:27 +00:00
parent 0d4bb7558f
commit 8f7b69f77e
8 changed files with 683 additions and 870 deletions

View File

@ -27,9 +27,24 @@ class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base
set_tmp_attachments_directory
end
context "GET /projects" do
context ".xml" do
should "return projects" 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")
should_allow_api_authentication(:get, "/projects/2.json")
should_allow_api_authentication(:post,
'/projects.xml',
{:project => {:name => 'API test', :identifier => 'api-test'}},
{:success_code => :created})
should_allow_api_authentication(:put,
'/projects/2.xml',
{:project => {:name => 'API update'}},
{:success_code => :ok})
should_allow_api_authentication(:delete,
'/projects/2.xml',
{},
{:success_code => :ok})
test "GET /projects.xml should return projects" do
get '/projects.xml'
assert_response :success
assert_equal 'application/xml', @response.content_type
@ -37,10 +52,8 @@ class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base
assert_tag :tag => 'projects',
:child => {:tag => 'project', :child => {:tag => 'id', :content => '1'}}
end
end
context ".json" do
should "return projects" do
test "GET /projects.json should return projects" do
get '/projects.json'
assert_response :success
assert_equal 'application/json', @response.content_type
@ -51,16 +64,8 @@ class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base
assert_kind_of Hash, json['projects'].first
assert json['projects'].first.has_key?('id')
end
end
end
context "GET /projects/:id" do
context ".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")
should "return requested project" do
test "GET /projects/:id.xml should return the project" do
get '/projects/1.xml'
assert_response :success
assert_equal 'application/xml', @response.content_type
@ -74,12 +79,18 @@ class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base
assert_no_tag 'issue_categories'
end
context "with hidden custom fields" do
setup do
ProjectCustomField.find_by_name('Development status').update_attribute :visible, false
test "GET /projects/:id.json should return the project" do
get '/projects/1.json'
json = ActiveSupport::JSON.decode(response.body)
assert_kind_of Hash, json
assert_kind_of Hash, json['project']
assert_equal 1, json['project']['id']
end
should "not display hidden custom fields" do
test "GET /projects/:id.xml with hidden custom fields should not display hidden custom fields" do
ProjectCustomField.find_by_name('Development status').update_attribute :visible, false
get '/projects/1.xml'
assert_response :success
assert_equal 'application/xml', @response.content_type
@ -87,9 +98,8 @@ class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base
assert_no_tag 'custom_field',
:attributes => {:name => 'Development status'}
end
end
should "return categories with include=issue_categories" do
test "GET /projects/:id.xml with include=issue_categories should return categories" do
get '/projects/1.xml?include=issue_categories'
assert_response :success
assert_equal 'application/xml', @response.content_type
@ -105,7 +115,7 @@ class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base
}
end
should "return trackers with include=trackers" do
test "GET /projects/:id.xml with include=trackers should return trackers" do
get '/projects/1.xml?include=trackers'
assert_response :success
assert_equal 'application/xml', @response.content_type
@ -120,39 +130,14 @@ class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base
}
}
end
end
context ".json" do
should_allow_api_authentication(:get, "/projects/2.json")
should "return requested project" do
get '/projects/1.json'
json = ActiveSupport::JSON.decode(response.body)
assert_kind_of Hash, json
assert_kind_of Hash, json['project']
assert_equal 1, json['project']['id']
end
end
end
context "POST /projects" do
context "with valid parameters" do
setup do
test "POST /projects.xml with valid parameters should create the project" do
Setting.default_projects_modules = ['issue_tracking', 'repository']
@parameters = {:project => {:name => 'API test', :identifier => 'api-test'}}
end
context ".xml" do
should_allow_api_authentication(:post,
'/projects.xml',
{:project => {:name => 'API test', :identifier => 'api-test'}},
{:success_code => :created})
should "create a project with the attributes" do
assert_difference('Project.count') do
post '/projects.xml', @parameters, credentials('admin')
post '/projects.xml',
{:project => {:name => 'API test', :identifier => 'api-test'}},
credentials('admin')
end
project = Project.first(:order => 'id DESC')
@ -166,64 +151,41 @@ class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base
assert_tag 'project', :child => {:tag => 'id', :content => project.id.to_s}
end
should "accept enabled_module_names attribute" do
@parameters[:project].merge!({:enabled_module_names => ['issue_tracking', 'news', 'time_tracking']})
test "POST /projects.xml should accept enabled_module_names attribute" do
assert_difference('Project.count') do
post '/projects.xml', @parameters, credentials('admin')
post '/projects.xml',
{:project => {:name => 'API test', :identifier => 'api-test', :enabled_module_names => ['issue_tracking', 'news', 'time_tracking']}},
credentials('admin')
end
project = Project.first(:order => 'id DESC')
assert_equal ['issue_tracking', 'news', 'time_tracking'], project.enabled_module_names.sort
end
should "accept tracker_ids attribute" do
@parameters[:project].merge!({:tracker_ids => [1, 3]})
test "POST /projects.xml should accept tracker_ids attribute" do
assert_difference('Project.count') do
post '/projects.xml', @parameters, credentials('admin')
post '/projects.xml',
{:project => {:name => 'API test', :identifier => 'api-test', :tracker_ids => [1, 3]}},
credentials('admin')
end
project = Project.first(:order => 'id DESC')
assert_equal [1, 3], project.trackers.map(&:id).sort
end
end
end
context "with invalid parameters" do
setup do
@parameters = {:project => {:name => 'API test'}}
end
context ".xml" do
should "return errors" do
test "POST /projects.xml with invalid parameters should return errors" do
assert_no_difference('Project.count') do
post '/projects.xml', @parameters, credentials('admin')
post '/projects.xml', {:project => {:name => 'API test'}}, credentials('admin')
end
assert_response :unprocessable_entity
assert_equal 'application/xml', @response.content_type
assert_tag 'errors', :child => {:tag => 'error', :content => "Identifier can't be blank"}
end
end
end
end
context "PUT /projects/:id" do
context "with valid parameters" do
setup do
@parameters = {:project => {:name => 'API update'}}
end
context ".xml" do
should_allow_api_authentication(:put,
'/projects/2.xml',
{:project => {:name => 'API update'}},
{:success_code => :ok})
should "update the project" do
test "PUT /projects/:id.xml with valid parameters should update the project" do
assert_no_difference 'Project.count' do
put '/projects/2.xml', @parameters, credentials('jsmith')
put '/projects/2.xml', {:project => {:name => 'API update'}}, credentials('jsmith')
end
assert_response :ok
assert_equal '', @response.body
@ -232,11 +194,9 @@ class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base
assert_equal 'API update', project.name
end
should "accept enabled_module_names attribute" do
@parameters[:project].merge!({:enabled_module_names => ['issue_tracking', 'news', 'time_tracking']})
test "PUT /projects/:id.xml should accept enabled_module_names attribute" do
assert_no_difference 'Project.count' do
put '/projects/2.xml', @parameters, credentials('admin')
put '/projects/2.xml', {:project => {:name => 'API update', :enabled_module_names => ['issue_tracking', 'news', 'time_tracking']}}, credentials('admin')
end
assert_response :ok
assert_equal '', @response.body
@ -244,47 +204,27 @@ class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base
assert_equal ['issue_tracking', 'news', 'time_tracking'], project.enabled_module_names.sort
end
should "accept tracker_ids attribute" do
@parameters[:project].merge!({:tracker_ids => [1, 3]})
test "PUT /projects/:id.xml should accept tracker_ids attribute" do
assert_no_difference 'Project.count' do
put '/projects/2.xml', @parameters, credentials('admin')
put '/projects/2.xml', {:project => {:name => 'API update', :tracker_ids => [1, 3]}}, credentials('admin')
end
assert_response :ok
assert_equal '', @response.body
project = Project.find(2)
assert_equal [1, 3], project.trackers.map(&:id).sort
end
end
end
context "with invalid parameters" do
setup do
@parameters = {:project => {:name => ''}}
end
context ".xml" do
should "return errors" do
test "PUT /projects/:id.xml with invalid parameters should return errors" do
assert_no_difference('Project.count') do
put '/projects/2.xml', @parameters, credentials('admin')
put '/projects/2.xml', {:project => {:name => ''}}, credentials('admin')
end
assert_response :unprocessable_entity
assert_equal 'application/xml', @response.content_type
assert_tag 'errors', :child => {:tag => 'error', :content => "Name can't be blank"}
end
end
end
end
context "DELETE /projects/:id" do
context ".xml" do
should_allow_api_authentication(:delete,
'/projects/2.xml',
{},
{:success_code => :ok})
should "delete the project" do
test "DELETE /projects/:id.xml should delete the project" do
assert_difference('Project.count',-1) do
delete '/projects/2.xml', {}, credentials('admin')
end
@ -292,6 +232,4 @@ class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base
assert_equal '', @response.body
assert_nil Project.find_by_id(2)
end
end
end
end

View File

@ -31,10 +31,7 @@ class Redmine::ApiTest::QueriesTest < Redmine::ApiTest::Base
Setting.rest_api_enabled = '1'
end
context "/queries" do
context "GET" do
should "return queries" do
test "GET /queries.xml should return queries" do
get '/queries.xml'
assert_response :success
@ -53,6 +50,4 @@ class Redmine::ApiTest::QueriesTest < Redmine::ApiTest::Base
}
}
end
end
end
end

View File

@ -24,10 +24,7 @@ class Redmine::ApiTest::RolesTest < Redmine::ApiTest::Base
Setting.rest_api_enabled = '1'
end
context "/roles" do
context "GET" do
context "xml" do
should "return the roles" do
test "GET /roles.xml should return the roles" do
get '/roles.xml'
assert_response :success
@ -48,10 +45,8 @@ class Redmine::ApiTest::RolesTest < Redmine::ApiTest::Base
}
}
end
end
context "json" do
should "return the roles" do
test "GET /roles.json should return the roles" do
get '/roles.json'
assert_response :success
@ -63,14 +58,8 @@ class Redmine::ApiTest::RolesTest < Redmine::ApiTest::Base
assert_kind_of Array, json['roles']
assert_include({'id' => 2, 'name' => 'Developer'}, json['roles'])
end
end
end
end
context "/roles/:id" do
context "GET" do
context "xml" do
should "return the role" do
test "GET /roles/:id.xml should return the role" do
get '/roles/1.xml'
assert_response :success
@ -84,7 +73,4 @@ class Redmine::ApiTest::RolesTest < Redmine::ApiTest::Base
end
end
end
end
end
end
end

View File

@ -31,8 +31,7 @@ class Redmine::ApiTest::TimeEntriesTest < Redmine::ApiTest::Base
Setting.rest_api_enabled = '1'
end
context "GET /time_entries.xml" do
should "return time entries" do
test "GET /time_entries.xml should return time entries" do
get '/time_entries.xml', {}, credentials('jsmith')
assert_response :success
assert_equal 'application/xml', @response.content_type
@ -40,30 +39,23 @@ class Redmine::ApiTest::TimeEntriesTest < Redmine::ApiTest::Base
:child => {:tag => 'time_entry', :child => {:tag => 'id', :content => '2'}}
end
context "with limit" do
should "return limited results" do
test "GET /time_entries.xml with limit should return limited results" do
get '/time_entries.xml?limit=2', {}, credentials('jsmith')
assert_response :success
assert_equal 'application/xml', @response.content_type
assert_tag :tag => 'time_entries',
:children => {:count => 2}
end
end
end
context "GET /time_entries/2.xml" do
should "return requested time entry" do
test "GET /time_entries/:id.xml should return the time entry" do
get '/time_entries/2.xml', {}, credentials('jsmith')
assert_response :success
assert_equal 'application/xml', @response.content_type
assert_tag :tag => 'time_entry',
:child => {:tag => 'id', :content => '2'}
end
end
context "POST /time_entries.xml" do
context "with issue_id" do
should "return create time entry" do
test "POST /time_entries.xml with issue_id should create time entry" do
assert_difference 'TimeEntry.count' do
post '/time_entries.xml', {:time_entry => {:issue_id => '1', :spent_on => '2010-12-02', :hours => '3.5', :activity_id => '11'}}, credentials('jsmith')
end
@ -79,7 +71,7 @@ class Redmine::ApiTest::TimeEntriesTest < Redmine::ApiTest::Base
assert_equal TimeEntryActivity.find(11), entry.activity
end
should "accept custom fields" do
test "POST /time_entries.xml with issue_id should accept custom fields" do
field = TimeEntryCustomField.create!(:name => 'Test', :field_format => 'string')
assert_difference 'TimeEntry.count' do
@ -93,10 +85,8 @@ class Redmine::ApiTest::TimeEntriesTest < Redmine::ApiTest::Base
entry = TimeEntry.first(:order => 'id DESC')
assert_equal 'accepted', entry.custom_field_value(field)
end
end
context "with project_id" do
should "return create time entry" do
test "POST /time_entries.xml with project_id should create time entry" do
assert_difference 'TimeEntry.count' do
post '/time_entries.xml', {:time_entry => {:project_id => '1', :spent_on => '2010-12-02', :hours => '3.5', :activity_id => '11'}}, credentials('jsmith')
end
@ -111,10 +101,8 @@ class Redmine::ApiTest::TimeEntriesTest < Redmine::ApiTest::Base
assert_equal 3.5, entry.hours
assert_equal TimeEntryActivity.find(11), entry.activity
end
end
context "with invalid parameters" do
should "return errors" do
test "POST /time_entries.xml with invalid parameters should return errors" do
assert_no_difference 'TimeEntry.count' do
post '/time_entries.xml', {:time_entry => {:project_id => '1', :spent_on => '2010-12-02', :activity_id => '11'}}, credentials('jsmith')
end
@ -123,12 +111,8 @@ class Redmine::ApiTest::TimeEntriesTest < Redmine::ApiTest::Base
assert_tag 'errors', :child => {:tag => 'error', :content => "Hours can't be blank"}
end
end
end
context "PUT /time_entries/2.xml" do
context "with valid parameters" do
should "update time entry" do
test "PUT /time_entries/:id.xml with valid parameters should update time entry" do
assert_no_difference 'TimeEntry.count' do
put '/time_entries/2.xml', {:time_entry => {:comments => 'API Update'}}, credentials('jsmith')
end
@ -136,10 +120,8 @@ class Redmine::ApiTest::TimeEntriesTest < Redmine::ApiTest::Base
assert_equal '', @response.body
assert_equal 'API Update', TimeEntry.find(2).comments
end
end
context "with invalid parameters" do
should "return errors" do
test "PUT /time_entries/:id.xml with invalid parameters should return errors" do
assert_no_difference 'TimeEntry.count' do
put '/time_entries/2.xml', {:time_entry => {:hours => '', :comments => 'API Update'}}, credentials('jsmith')
end
@ -148,11 +130,8 @@ class Redmine::ApiTest::TimeEntriesTest < Redmine::ApiTest::Base
assert_tag 'errors', :child => {:tag => 'error', :content => "Hours can't be blank"}
end
end
end
context "DELETE /time_entries/2.xml" do
should "destroy time entry" do
test "DELETE /time_entries/:id.xml should destroy time entry" do
assert_difference 'TimeEntry.count', -1 do
delete '/time_entries/2.xml', {}, credentials('jsmith')
end
@ -160,5 +139,4 @@ class Redmine::ApiTest::TimeEntriesTest < Redmine::ApiTest::Base
assert_equal '', @response.body
assert_nil TimeEntry.find_by_id(2)
end
end
end

View File

@ -37,13 +37,6 @@ class Redmine::ApiTest::TokenAuthenticationTest < Redmine::ApiTest::Base
end
# Using the NewsController because it's a simple API.
context "get /news" do
context "in :xml format" do
should_allow_key_based_auth(:get, "/news.xml")
end
context "in :json format" do
should_allow_key_based_auth(:get, "/news.json")
end
end
end

View File

@ -24,10 +24,7 @@ class Redmine::ApiTest::TrackersTest < Redmine::ApiTest::Base
Setting.rest_api_enabled = '1'
end
context "/trackers" do
context "GET" do
should "return trackers" do
test "GET /trackers.xml should return trackers" do
get '/trackers.xml'
assert_response :success
@ -46,6 +43,4 @@ class Redmine::ApiTest::TrackersTest < Redmine::ApiTest::Base
}
}
end
end
end
end

View File

@ -24,14 +24,46 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base
Setting.rest_api_enabled = '1'
end
context "GET /users" do
should_allow_api_authentication(:get, "/users.xml")
should_allow_api_authentication(:get, "/users.json")
end
should_allow_api_authentication(:post,
'/users.xml',
{:user => {
:login => 'foo', :firstname => 'Firstname', :lastname => 'Lastname',
:mail => 'foo@example.net', :password => 'secret123'
}},
{:success_code => :created})
should_allow_api_authentication(:post,
'/users.json',
{:user => {
:login => 'foo', :firstname => 'Firstname', :lastname => 'Lastname',
:mail => 'foo@example.net'
}},
{:success_code => :created})
should_allow_api_authentication(:put,
'/users/2.xml',
{:user => {
:login => 'jsmith', :firstname => 'John', :lastname => 'Renamed',
:mail => 'jsmith@somenet.foo'
}},
{:success_code => :ok})
should_allow_api_authentication(:put,
'/users/2.json',
{:user => {
:login => 'jsmith', :firstname => 'John', :lastname => 'Renamed',
:mail => 'jsmith@somenet.foo'
}},
{:success_code => :ok})
should_allow_api_authentication(:delete,
'/users/2.xml',
{},
{:success_code => :ok})
should_allow_api_authentication(:delete,
'/users/2.xml',
{},
{:success_code => :ok})
context "GET /users/2" do
context ".xml" do
should "return requested user" do
test "GET /users/:id.xml should return the user" do
get '/users/2.xml'
assert_response :success
@ -39,20 +71,7 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base
:child => {:tag => 'id', :content => '2'}
end
context "with include=memberships" do
should "include memberships" do
get '/users/2.xml?include=memberships'
assert_response :success
assert_tag :tag => 'memberships',
:parent => {:tag => 'user'},
:children => {:count => 1}
end
end
end
context ".json" do
should "return requested user" do
test "GET /users/:id.json should return the user" do
get '/users/2.json'
assert_response :success
@ -62,8 +81,16 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base
assert_equal 2, json['user']['id']
end
context "with include=memberships" do
should "include memberships" do
test "GET /users/:id.xml with include=memberships should include memberships" do
get '/users/2.xml?include=memberships'
assert_response :success
assert_tag :tag => 'memberships',
:parent => {:tag => 'user'},
:children => {:count => 1}
end
test "GET /users/:id.json with include=memberships should include memberships" do
get '/users/2.json?include=memberships'
assert_response :success
@ -75,26 +102,19 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base
"roles"=>[{"name"=>"Manager", "id"=>1}]
}], json['user']['memberships']
end
end
end
end
context "GET /users/current" do
context ".xml" do
should "require authentication" do
test "GET /users/current.xml should require authentication" do
get '/users/current.xml'
assert_response 401
end
should "return current user" do
test "GET /users/current.xml should return current user" do
get '/users/current.xml', {}, credentials('jsmith')
assert_tag :tag => 'user',
:child => {:tag => 'id', :content => '2'}
end
end
end
test "GET /users/:id should not return login for other user" do
get '/users/3.xml', {}, credentials('jsmith')
@ -132,30 +152,15 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base
assert_tag 'user', :child => {:tag => 'status', :content => User.find(1).status.to_s}
end
context "POST /users" do
context "with valid parameters" do
setup do
@parameters = {
test "POST /users.xml with valid parameters should create the user" do
assert_difference('User.count') do
post '/users.xml', {
:user => {
:login => 'foo', :firstname => 'Firstname', :lastname => 'Lastname',
:mail => 'foo@example.net', :password => 'secret123',
:mail_notification => 'only_assigned'
}
}
end
context ".xml" do
should_allow_api_authentication(:post,
'/users.xml',
{:user => {
:login => 'foo', :firstname => 'Firstname', :lastname => 'Lastname',
:mail => 'foo@example.net', :password => 'secret123'
}},
{:success_code => :created})
should "create a user with the attributes" do
assert_difference('User.count') do
post '/users.xml', @parameters, credentials('admin')
:mail_notification => 'only_assigned'}
},
credentials('admin')
end
user = User.first(:order => 'id DESC')
@ -171,20 +176,16 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base
assert_equal 'application/xml', @response.content_type
assert_tag 'user', :child => {:tag => 'id', :content => user.id.to_s}
end
end
context ".json" do
should_allow_api_authentication(:post,
'/users.json',
{:user => {
:login => 'foo', :firstname => 'Firstname', :lastname => 'Lastname',
:mail => 'foo@example.net'
}},
{:success_code => :created})
should "create a user with the attributes" do
test "POST /users.json with valid parameters should create the user" do
assert_difference('User.count') do
post '/users.json', @parameters, credentials('admin')
post '/users.json', {
:user => {
:login => 'foo', :firstname => 'Firstname', :lastname => 'Lastname',
:mail => 'foo@example.net', :password => 'secret123',
:mail_notification => 'only_assigned'}
},
credentials('admin')
end
user = User.first(:order => 'id DESC')
@ -201,18 +202,10 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base
assert_kind_of Hash, json['user']
assert_equal user.id, json['user']['id']
end
end
end
context "with invalid parameters" do
setup do
@parameters = {:user => {:login => 'foo', :lastname => 'Lastname', :mail => 'foo'}}
end
context ".xml" do
should "return errors" do
test "POST /users.xml with with invalid parameters should return errors" do
assert_no_difference('User.count') do
post '/users.xml', @parameters, credentials('admin')
post '/users.xml', {:user => {:login => 'foo', :lastname => 'Lastname', :mail => 'foo'}}, credentials('admin')
end
assert_response :unprocessable_entity
@ -222,12 +215,10 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base
:content => "First name can't be blank"
}
end
end
context ".json" do
should "return errors" do
test "POST /users.json with with invalid parameters should return errors" do
assert_no_difference('User.count') do
post '/users.json', @parameters, credentials('admin')
post '/users.json', {:user => {:login => 'foo', :lastname => 'Lastname', :mail => 'foo'}}, credentials('admin')
end
assert_response :unprocessable_entity
@ -237,33 +228,15 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base
assert json.has_key?('errors')
assert_kind_of Array, json['errors']
end
end
end
end
context "PUT /users/2" do
context "with valid parameters" do
setup do
@parameters = {
test "PUT /users/:id.xml with valid parameters should update the user" do
assert_no_difference('User.count') do
put '/users/2.xml', {
:user => {
:login => 'jsmith', :firstname => 'John', :lastname => 'Renamed',
:mail => 'jsmith@somenet.foo'
}
}
end
context ".xml" do
should_allow_api_authentication(:put,
'/users/2.xml',
{:user => {
:login => 'jsmith', :firstname => 'John', :lastname => 'Renamed',
:mail => 'jsmith@somenet.foo'
}},
{:success_code => :ok})
should "update user with the attributes" do
assert_no_difference('User.count') do
put '/users/2.xml', @parameters, credentials('admin')
:mail => 'jsmith@somenet.foo'}
},
credentials('admin')
end
user = User.find(2)
@ -276,20 +249,15 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base
assert_response :ok
assert_equal '', @response.body
end
end
context ".json" do
should_allow_api_authentication(:put,
'/users/2.json',
{:user => {
:login => 'jsmith', :firstname => 'John', :lastname => 'Renamed',
:mail => 'jsmith@somenet.foo'
}},
{:success_code => :ok})
should "update user with the attributes" do
test "PUT /users/:id.json with valid parameters should update the user" do
assert_no_difference('User.count') do
put '/users/2.json', @parameters, credentials('admin')
put '/users/2.json', {
:user => {
:login => 'jsmith', :firstname => 'John', :lastname => 'Renamed',
:mail => 'jsmith@somenet.foo'}
},
credentials('admin')
end
user = User.find(2)
@ -302,23 +270,15 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base
assert_response :ok
assert_equal '', @response.body
end
end
end
context "with invalid parameters" do
setup do
@parameters = {
test "PUT /users/:id.xml with invalid parameters" do
assert_no_difference('User.count') do
put '/users/2.xml', {
:user => {
:login => 'jsmith', :firstname => '', :lastname => 'Lastname',
:mail => 'foo'
}
}
end
context ".xml" do
should "return errors" do
assert_no_difference('User.count') do
put '/users/2.xml', @parameters, credentials('admin')
:mail => 'foo'}
},
credentials('admin')
end
assert_response :unprocessable_entity
@ -328,12 +288,15 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base
:content => "First name can't be blank"
}
end
end
context ".json" do
should "return errors" do
test "PUT /users/:id.json with invalid parameters" do
assert_no_difference('User.count') do
put '/users/2.json', @parameters, credentials('admin')
put '/users/2.json', {
:user => {
:login => 'jsmith', :firstname => '', :lastname => 'Lastname',
:mail => 'foo'}
},
credentials('admin')
end
assert_response :unprocessable_entity
@ -343,18 +306,8 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base
assert json.has_key?('errors')
assert_kind_of Array, json['errors']
end
end
end
end
context "DELETE /users/2" do
context ".xml" do
should_allow_api_authentication(:delete,
'/users/2.xml',
{},
{:success_code => :ok})
should "delete user" do
test "DELETE /users/:id.xml should delete the user" do
assert_difference('User.count', -1) do
delete '/users/2.xml', {}, credentials('admin')
end
@ -362,15 +315,8 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base
assert_response :ok
assert_equal '', @response.body
end
end
context ".json" do
should_allow_api_authentication(:delete,
'/users/2.xml',
{},
{:success_code => :ok})
should "delete user" do
test "DELETE /users/:id.json should delete the user" do
assert_difference('User.count', -1) do
delete '/users/2.json', {}, credentials('admin')
end
@ -378,6 +324,4 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base
assert_response :ok
assert_equal '', @response.body
end
end
end
end

View File

@ -31,9 +31,7 @@ class Redmine::ApiTest::VersionsTest < Redmine::ApiTest::Base
Setting.rest_api_enabled = '1'
end
context "/projects/:project_id/versions" do
context "GET" do
should "return project versions" do
test "GET /projects/:project_id/versions.xml should return project versions" do
get '/projects/1/versions.xml'
assert_response :success
@ -52,10 +50,8 @@ class Redmine::ApiTest::VersionsTest < Redmine::ApiTest::Base
}
}
end
end
context "POST" do
should "create the version" do
test "POST /projects/:project_id/versions.xml should create the version" do
assert_difference 'Version.count' do
post '/projects/1/versions.xml', {:version => {:name => 'API test'}}, credentials('jsmith')
end
@ -68,7 +64,7 @@ class Redmine::ApiTest::VersionsTest < Redmine::ApiTest::Base
assert_tag 'version', :child => {:tag => 'id', :content => version.id.to_s}
end
should "create the version with due date" do
test "POST /projects/:project_id/versions.xml should create the version with due date" do
assert_difference 'Version.count' do
post '/projects/1/versions.xml', {:version => {:name => 'API test', :due_date => '2012-01-24'}}, credentials('jsmith')
end
@ -82,7 +78,7 @@ class Redmine::ApiTest::VersionsTest < Redmine::ApiTest::Base
assert_tag 'version', :child => {:tag => 'id', :content => version.id.to_s}
end
should "create the version with custom fields" do
test "POST /projects/:project_id/versions.xml should create the version with custom fields" do
field = VersionCustomField.generate!
assert_difference 'Version.count' do
@ -105,8 +101,7 @@ class Redmine::ApiTest::VersionsTest < Redmine::ApiTest::Base
assert_select 'version>custom_fields>custom_field[id=?]>value', field.id.to_s, 'Some value'
end
context "with failure" do
should "return the errors" do
test "POST /projects/:project_id/versions.xml with failure should return the errors" do
assert_no_difference('Version.count') do
post '/projects/1/versions.xml', {:version => {:name => ''}}, credentials('jsmith')
end
@ -114,13 +109,8 @@ class Redmine::ApiTest::VersionsTest < Redmine::ApiTest::Base
assert_response :unprocessable_entity
assert_tag :errors, :child => {:tag => 'error', :content => "Name can't be blank"}
end
end
end
end
context "/versions/:id" do
context "GET" do
should "return the version" do
test "GET /versions/:id.xml should return the version" do
get '/versions/2.xml'
assert_response :success
@ -131,20 +121,16 @@ class Redmine::ApiTest::VersionsTest < Redmine::ApiTest::Base
assert_select 'sharing', :text => 'none'
end
end
end
context "PUT" do
should "update the version" do
test "PUT /versions/:id.xml should update the version" do
put '/versions/2.xml', {:version => {:name => 'API update'}}, credentials('jsmith')
assert_response :ok
assert_equal '', @response.body
assert_equal 'API update', Version.find(2).name
end
end
context "DELETE" do
should "destroy the version" do
test "DELETE /versions/:id.xml should destroy the version" do
assert_difference 'Version.count', -1 do
delete '/versions/3.xml', {}, credentials('jsmith')
end
@ -153,6 +139,4 @@ class Redmine::ApiTest::VersionsTest < Redmine::ApiTest::Base
assert_equal '', @response.body
assert_nil Version.find_by_id(3)
end
end
end
end