Removed some shoulda context.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11862 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2013-05-18 08:27:53 +00:00
parent 5b29964512
commit 0d4bb7558f
7 changed files with 403 additions and 527 deletions

View File

@ -24,12 +24,8 @@ class Redmine::ApiTest::EnumerationsTest < Redmine::ApiTest::Base
Setting.rest_api_enabled = '1'
end
context "/enumerations/issue_priorities" do
context "GET" do
should "return priorities" do
test "GET /enumerations/issue_priorities.xml should return priorities" do
get '/enumerations/issue_priorities.xml'
assert_response :success
assert_equal 'application/xml', response.content_type
assert_select 'issue_priorities[type=array]' do
@ -40,5 +36,3 @@ class Redmine::ApiTest::EnumerationsTest < Redmine::ApiTest::Base
end
end
end
end
end

View File

@ -24,14 +24,12 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base
Setting.rest_api_enabled = '1'
end
context "GET /groups" do
context ".xml" do
should "require authentication" do
test "GET /groups.xml should require authentication" do
get '/groups.xml'
assert_response 401
end
should "return groups" do
test "GET /groups.xml should return groups" do
get '/groups.xml', {}, credentials('admin')
assert_response :success
assert_equal 'application/xml', response.content_type
@ -43,15 +41,13 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base
end
end
end
end
context ".json" do
should "require authentication" do
test "GET /groups.json should require authentication" do
get '/groups.json'
assert_response 401
end
should "return groups" do
test "GET /groups.json should return groups" do
get '/groups.json', {}, credentials('admin')
assert_response :success
assert_equal 'application/json', response.content_type
@ -63,12 +59,8 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base
assert_not_nil group
assert_equal({'id' => 10, 'name' => 'A Team'}, group)
end
end
end
context "GET /groups/:id" do
context ".xml" do
should "return the group with its users" do
test "GET /groups/:id.xml should return the group with its users" do
get '/groups/10.xml', {}, credentials('admin')
assert_response :success
assert_equal 'application/xml', response.content_type
@ -79,7 +71,7 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base
end
end
should "include users if requested" do
test "GET /groups/:id.xml should include users if requested" do
get '/groups/10.xml?include=users', {}, credentials('admin')
assert_response :success
assert_equal 'application/xml', response.content_type
@ -92,7 +84,7 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base
end
end
should "include memberships if requested" do
test "GET /groups/:id.xml include memberships if requested" do
get '/groups/10.xml?include=memberships', {}, credentials('admin')
assert_response :success
assert_equal 'application/xml', response.content_type
@ -101,13 +93,8 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base
assert_select 'memberships'
end
end
end
end
context "POST /groups" do
context "with valid parameters" do
context ".xml" do
should "create groups" do
test "POST /groups.xml with valid parameters should create the group" do
assert_difference('Group.count') do
post '/groups.xml', {:group => {:name => 'Test', :user_ids => [2, 3]}}, credentials('admin')
assert_response :created
@ -122,12 +109,8 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base
assert_select 'name', :text => 'Test'
end
end
end
end
context "with invalid parameters" do
context ".xml" do
should "return errors" do
test "POST /groups.xml with invalid parameters should return errors" do
assert_no_difference('Group.count') do
post '/groups.xml', {:group => {:name => ''}}, credentials('admin')
end
@ -138,14 +121,8 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base
assert_select 'error', :text => /Name can't be blank/
end
end
end
end
end
context "PUT /groups/:id" do
context "with valid parameters" do
context ".xml" do
should "update the group" do
test "PUT /groups/:id.xml with valid parameters should update the group" do
put '/groups/10.xml', {:group => {:name => 'New name', :user_ids => [2, 3]}}, credentials('admin')
assert_response :ok
assert_equal '', @response.body
@ -154,12 +131,8 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base
assert_equal 'New name', group.name
assert_equal [2, 3], group.users.map(&:id).sort
end
end
end
context "with invalid parameters" do
context ".xml" do
should "return errors" do
test "PUT /groups/:id.xml with invalid parameters should return errors" do
put '/groups/10.xml', {:group => {:name => ''}}, credentials('admin')
assert_response :unprocessable_entity
assert_equal 'application/xml', response.content_type
@ -168,25 +141,16 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base
assert_select 'error', :text => /Name can't be blank/
end
end
end
end
end
context "DELETE /groups/:id" do
context ".xml" do
should "delete the group" do
test "DELETE /groups/:id.xml should delete the group" do
assert_difference 'Group.count', -1 do
delete '/groups/10.xml', {}, credentials('admin')
assert_response :ok
assert_equal '', @response.body
end
end
end
end
context "POST /groups/:id/users" do
context ".xml" do
should "add user to the group" do
test "POST /groups/:id/users.xml should add user to the group" do
assert_difference 'Group.find(10).users.count' do
post '/groups/10/users.xml', {:user_id => 5}, credentials('admin')
assert_response :ok
@ -194,12 +158,8 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base
end
assert_include User.find(5), Group.find(10).users
end
end
end
context "DELETE /groups/:id/users/:user_id" do
context ".xml" do
should "remove user from the group" do
test "DELETE /groups/:id/users/:user_id.xml should remove user from the group" do
assert_difference 'Group.find(10).users.count', -1 do
delete '/groups/10/users/8.xml', {}, credentials('admin')
assert_response :ok
@ -208,5 +168,3 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base
assert_not_include User.find(8), Group.find(10).users
end
end
end
end

View File

@ -28,28 +28,23 @@ class Redmine::ApiTest::IssueCategoriesTest < Redmine::ApiTest::Base
Setting.rest_api_enabled = '1'
end
context "GET /projects/:project_id/issue_categories.xml" do
should "return issue categories" do
test "GET /projects/:project_id/issue_categories.xml should return the issue categories" do
get '/projects/1/issue_categories.xml', {}, credentials('jsmith')
assert_response :success
assert_equal 'application/xml', @response.content_type
assert_tag :tag => 'issue_categories',
:child => {:tag => 'issue_category', :child => {:tag => 'id', :content => '2'}}
end
end
context "GET /issue_categories/2.xml" do
should "return requested issue category" do
test "GET /issue_categories/:id.xml should return the issue category" do
get '/issue_categories/2.xml', {}, credentials('jsmith')
assert_response :success
assert_equal 'application/xml', @response.content_type
assert_tag :tag => 'issue_category',
:child => {:tag => 'id', :content => '2'}
end
end
context "POST /projects/:project_id/issue_categories.xml" do
should "return create issue category" do
test "POST /projects/:project_id/issue_categories.xml should return create issue category" do
assert_difference 'IssueCategory.count' do
post '/projects/1/issue_categories.xml', {:issue_category => {:name => 'API'}}, credentials('jsmith')
end
@ -61,8 +56,7 @@ class Redmine::ApiTest::IssueCategoriesTest < Redmine::ApiTest::Base
assert_equal 1, category.project_id
end
context "with invalid parameters" do
should "return errors" do
test "POST /projects/:project_id/issue_categories.xml with invalid parameters should return errors" do
assert_no_difference 'IssueCategory.count' do
post '/projects/1/issue_categories.xml', {:issue_category => {:name => ''}}, credentials('jsmith')
end
@ -71,12 +65,8 @@ class Redmine::ApiTest::IssueCategoriesTest < Redmine::ApiTest::Base
assert_tag 'errors', :child => {:tag => 'error', :content => "Name can't be blank"}
end
end
end
context "PUT /issue_categories/2.xml" do
context "with valid parameters" do
should "update issue category" do
test "PUT /issue_categories/:id.xml with valid parameters should update the issue category" do
assert_no_difference 'IssueCategory.count' do
put '/issue_categories/2.xml', {:issue_category => {:name => 'API Update'}}, credentials('jsmith')
end
@ -84,10 +74,8 @@ class Redmine::ApiTest::IssueCategoriesTest < Redmine::ApiTest::Base
assert_equal '', @response.body
assert_equal 'API Update', IssueCategory.find(2).name
end
end
context "with invalid parameters" do
should "return errors" do
test "PUT /issue_categories/:id.xml with invalid parameters should return errors" do
assert_no_difference 'IssueCategory.count' do
put '/issue_categories/2.xml', {:issue_category => {:name => ''}}, credentials('jsmith')
end
@ -96,11 +84,8 @@ class Redmine::ApiTest::IssueCategoriesTest < Redmine::ApiTest::Base
assert_tag 'errors', :child => {:tag => 'error', :content => "Name can't be blank"}
end
end
end
context "DELETE /issue_categories/1.xml" do
should "destroy issue categories" do
test "DELETE /issue_categories/:id.xml should destroy the issue category" do
assert_difference 'IssueCategory.count', -1 do
delete '/issue_categories/1.xml', {}, credentials('jsmith')
end
@ -109,7 +94,7 @@ class Redmine::ApiTest::IssueCategoriesTest < Redmine::ApiTest::Base
assert_nil IssueCategory.find_by_id(1)
end
should "reassign issues with :reassign_to_id param" do
test "DELETE /issue_categories/:id.xml should reassign issues with :reassign_to_id param" do
issue_count = Issue.count(:conditions => {:category_id => 1})
assert issue_count > 0
@ -123,4 +108,3 @@ class Redmine::ApiTest::IssueCategoriesTest < Redmine::ApiTest::Base
assert_nil IssueCategory.find_by_id(1)
end
end
end

View File

@ -31,9 +31,7 @@ class Redmine::ApiTest::IssueRelationsTest < Redmine::ApiTest::Base
Setting.rest_api_enabled = '1'
end
context "/issues/:issue_id/relations" do
context "GET" do
should "return issue relations" do
test "GET /issues/:issue_id/relations.xml should return issue relations" do
get '/issues/9/relations.xml', {}, credentials('jsmith')
assert_response :success
@ -49,10 +47,8 @@ class Redmine::ApiTest::IssueRelationsTest < Redmine::ApiTest::Base
}
}
end
end
context "POST" do
should "create a relation" do
test "POST /issues/:issue_id/relations.xml should create the relation" do
assert_difference('IssueRelation.count') do
post '/issues/2/relations.xml', {:relation => {:issue_to_id => 7, :relation_type => 'relates'}}, credentials('jsmith')
end
@ -67,8 +63,7 @@ class Redmine::ApiTest::IssueRelationsTest < Redmine::ApiTest::Base
assert_tag 'relation', :child => {:tag => 'id', :content => relation.id.to_s}
end
context "with failure" do
should "return the errors" do
test "POST /issues/:issue_id/relations.xml with failure should return errors" do
assert_no_difference('IssueRelation.count') do
post '/issues/2/relations.xml', {:relation => {:issue_to_id => 7, :relation_type => 'foo'}}, credentials('jsmith')
end
@ -76,23 +71,16 @@ class Redmine::ApiTest::IssueRelationsTest < Redmine::ApiTest::Base
assert_response :unprocessable_entity
assert_tag :errors, :child => {:tag => 'error', :content => /relation_type is not included in the list/}
end
end
end
end
context "/relations/:id" do
context "GET" do
should "return the relation" do
test "GET /relations/:id.xml should return the relation" do
get '/relations/2.xml', {}, credentials('jsmith')
assert_response :success
assert_equal 'application/xml', @response.content_type
assert_tag 'relation', :child => {:tag => 'id', :content => '2'}
end
end
context "DELETE" do
should "delete the relation" do
test "DELETE /relations/:id.xml should delete the relation" do
assert_difference('IssueRelation.count', -1) do
delete '/relations/2.xml', {}, credentials('jsmith')
end
@ -102,5 +90,3 @@ class Redmine::ApiTest::IssueRelationsTest < Redmine::ApiTest::Base
assert_nil IssueRelation.find_by_id(2)
end
end
end
end

View File

@ -24,10 +24,7 @@ class Redmine::ApiTest::IssueStatusesTest < Redmine::ApiTest::Base
Setting.rest_api_enabled = '1'
end
context "/issue_statuses" do
context "GET" do
should "return issue statuses" do
test "GET /issue_statuses.xml should return issue statuses" do
get '/issue_statuses.xml'
assert_response :success
@ -47,5 +44,3 @@ class Redmine::ApiTest::IssueStatusesTest < Redmine::ApiTest::Base
}
end
end
end
end

View File

@ -24,10 +24,7 @@ class Redmine::ApiTest::MembershipsTest < Redmine::ApiTest::Base
Setting.rest_api_enabled = '1'
end
context "/projects/:project_id/memberships" do
context "GET" do
context "xml" do
should "return memberships" do
test "GET /projects/:project_id/memberships.xml should return memberships" do
get '/projects/1/memberships.xml', {}, credentials('jsmith')
assert_response :success
@ -53,10 +50,8 @@ class Redmine::ApiTest::MembershipsTest < Redmine::ApiTest::Base
}
}
end
end
context "json" do
should "return memberships" do
test "GET /projects/:project_id/memberships.json should return memberships" do
get '/projects/1/memberships.json', {}, credentials('jsmith')
assert_response :success
@ -77,12 +72,8 @@ class Redmine::ApiTest::MembershipsTest < Redmine::ApiTest::Base
"offset" => 0},
json)
end
end
end
context "POST" do
context "xml" do
should "create membership" do
test "POST /projects/:project_id/memberships.xml should create the membership" do
assert_difference 'Member.count' do
post '/projects/1/memberships.xml', {:membership => {:user_id => 7, :role_ids => [2,3]}}, credentials('jsmith')
@ -90,7 +81,7 @@ class Redmine::ApiTest::MembershipsTest < Redmine::ApiTest::Base
end
end
should "return errors on failure" do
test "POST /projects/:project_id/memberships.xml with invalid parameters should return errors" do
assert_no_difference 'Member.count' do
post '/projects/1/memberships.xml', {:membership => {:role_ids => [2,3]}}, credentials('jsmith')
@ -99,14 +90,8 @@ class Redmine::ApiTest::MembershipsTest < Redmine::ApiTest::Base
assert_tag 'errors', :child => {:tag => 'error', :content => "Principal can't be blank"}
end
end
end
end
end
context "/memberships/:id" do
context "GET" do
context "xml" do
should "return the membership" do
test "GET /memberships/:id.xml should return the membership" do
get '/memberships/2.xml', {}, credentials('jsmith')
assert_response :success
@ -128,10 +113,8 @@ class Redmine::ApiTest::MembershipsTest < Redmine::ApiTest::Base
}
}
end
end
context "json" do
should "return the membership" do
test "GET /memberships/:id.json should return the membership" do
get '/memberships/2.json', {}, credentials('jsmith')
assert_response :success
@ -146,12 +129,8 @@ class Redmine::ApiTest::MembershipsTest < Redmine::ApiTest::Base
},
json)
end
end
end
context "PUT" do
context "xml" do
should "update membership" do
test "PUT /memberships/:id.xml should update the membership" do
assert_not_equal [1,2], Member.find(2).role_ids.sort
assert_no_difference 'Member.count' do
put '/memberships/2.xml', {:membership => {:user_id => 3, :role_ids => [1,2]}}, credentials('jsmith')
@ -163,19 +142,15 @@ class Redmine::ApiTest::MembershipsTest < Redmine::ApiTest::Base
assert_equal [1,2], member.role_ids.sort
end
should "return errors on failure" do
test "PUT /memberships/:id.xml with invalid parameters should return errors" do
put '/memberships/2.xml', {:membership => {:user_id => 3, :role_ids => [99]}}, credentials('jsmith')
assert_response :unprocessable_entity
assert_equal 'application/xml', @response.content_type
assert_tag 'errors', :child => {:tag => 'error', :content => /member_roles is invalid/}
end
end
end
context "DELETE" do
context "xml" do
should "destroy membership" do
test "DELETE /memberships/:id.xml should destroy the membership" do
assert_difference 'Member.count', -1 do
delete '/memberships/2.xml', {}, credentials('jsmith')
@ -185,7 +160,7 @@ class Redmine::ApiTest::MembershipsTest < Redmine::ApiTest::Base
assert_nil Member.find_by_id(2)
end
should "respond with 422 on failure" do
test "DELETE /memberships/:id.xml should respond with 422 on failure" do
assert_no_difference 'Member.count' do
# A membership with an inherited role can't be deleted
Member.find(2).member_roles.first.update_attribute :inherited_from, 99
@ -195,6 +170,3 @@ class Redmine::ApiTest::MembershipsTest < Redmine::ApiTest::Base
end
end
end
end
end
end

View File

@ -31,9 +31,10 @@ class Redmine::ApiTest::NewsTest < Redmine::ApiTest::Base
Setting.rest_api_enabled = '1'
end
context "GET /news" do
context ".xml" do
should "return news" do
should_allow_api_authentication(:get, "/projects/onlinestore/news.xml")
should_allow_api_authentication(:get, "/projects/onlinestore/news.json")
test "GET /news.xml should return news" do
get '/news.xml'
assert_tag :tag => 'news',
@ -46,10 +47,8 @@ class Redmine::ApiTest::NewsTest < Redmine::ApiTest::Base
}
}
end
end
context ".json" do
should "return news" do
test "GET /news.json should return news" do
get '/news.json'
json = ActiveSupport::JSON.decode(response.body)
@ -58,14 +57,8 @@ class Redmine::ApiTest::NewsTest < Redmine::ApiTest::Base
assert_kind_of Hash, json['news'].first
assert_equal 2, json['news'].first['id']
end
end
end
context "GET /projects/:project_id/news" do
context ".xml" do
should_allow_api_authentication(:get, "/projects/onlinestore/news.xml")
should "return news" do
test "GET /projects/:project_id/news.xml should return news" do
get '/projects/ecookbook/news.xml'
assert_tag :tag => 'news',
@ -78,12 +71,8 @@ class Redmine::ApiTest::NewsTest < Redmine::ApiTest::Base
}
}
end
end
context ".json" do
should_allow_api_authentication(:get, "/projects/onlinestore/news.json")
should "return news" do
test "GET /projects/:project_id/news.json should return news" do
get '/projects/ecookbook/news.json'
json = ActiveSupport::JSON.decode(response.body)
@ -93,5 +82,3 @@ class Redmine::ApiTest::NewsTest < Redmine::ApiTest::Base
assert_equal 2, json['news'].first['id']
end
end
end
end