From: Jean-Philippe Lang Date: Sat, 18 May 2013 08:27:53 +0000 (+0000) Subject: Removed some shoulda context. X-Git-Tag: 2.4.0~341 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=0d4bb7558fdc955e07b69cd4015f2ecb3b5803c7;p=redmine.git Removed some shoulda context. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11862 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/test/integration/api_test/enumerations_test.rb b/test/integration/api_test/enumerations_test.rb index f1000ffe4..62f64de8c 100644 --- a/test/integration/api_test/enumerations_test.rb +++ b/test/integration/api_test/enumerations_test.rb @@ -24,20 +24,14 @@ 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 - get '/enumerations/issue_priorities.xml' - - assert_response :success - assert_equal 'application/xml', response.content_type - assert_select 'issue_priorities[type=array]' do - assert_select 'issue_priority' do - assert_select 'id', :text => '6' - assert_select 'name', :text => 'High' - end - end + 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 + assert_select 'issue_priority' do + assert_select 'id', :text => '6' + assert_select 'name', :text => 'High' end end end diff --git a/test/integration/api_test/groups_test.rb b/test/integration/api_test/groups_test.rb index e155b8d7c..f300d2cb6 100644 --- a/test/integration/api_test/groups_test.rb +++ b/test/integration/api_test/groups_test.rb @@ -24,189 +24,147 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base Setting.rest_api_enabled = '1' end - context "GET /groups" do - context ".xml" do - should "require authentication" do - get '/groups.xml' - assert_response 401 - end + test "GET /groups.xml should require authentication" do + get '/groups.xml' + assert_response 401 + end - should "return groups" do - get '/groups.xml', {}, credentials('admin') - assert_response :success - assert_equal 'application/xml', response.content_type - - assert_select 'groups' do - assert_select 'group' do - assert_select 'name', :text => 'A Team' - assert_select 'id', :text => '10' - end - end + test "GET /groups.xml should return groups" do + get '/groups.xml', {}, credentials('admin') + assert_response :success + assert_equal 'application/xml', response.content_type + + assert_select 'groups' do + assert_select 'group' do + assert_select 'name', :text => 'A Team' + assert_select 'id', :text => '10' end end + end - context ".json" do - should "require authentication" do - get '/groups.json' - assert_response 401 - end + test "GET /groups.json should require authentication" do + get '/groups.json' + assert_response 401 + end - should "return groups" do - get '/groups.json', {}, credentials('admin') - assert_response :success - assert_equal 'application/json', response.content_type - - json = MultiJson.load(response.body) - groups = json['groups'] - assert_kind_of Array, groups - group = groups.detect {|g| g['name'] == 'A Team'} - assert_not_nil group - assert_equal({'id' => 10, 'name' => 'A Team'}, group) - end + test "GET /groups.json should return groups" do + get '/groups.json', {}, credentials('admin') + assert_response :success + assert_equal 'application/json', response.content_type + + json = MultiJson.load(response.body) + groups = json['groups'] + assert_kind_of Array, groups + group = groups.detect {|g| g['name'] == 'A Team'} + assert_not_nil group + assert_equal({'id' => 10, 'name' => 'A Team'}, group) + end + + 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 + + assert_select 'group' do + assert_select 'name', :text => 'A Team' + assert_select 'id', :text => '10' end end - context "GET /groups/:id" do - context ".xml" do - should "return the group with its users" do - get '/groups/10.xml', {}, credentials('admin') - assert_response :success - assert_equal 'application/xml', response.content_type - - assert_select 'group' do - assert_select 'name', :text => 'A Team' - assert_select 'id', :text => '10' - end - end + 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 - should "include users if requested" do - get '/groups/10.xml?include=users', {}, credentials('admin') - assert_response :success - assert_equal 'application/xml', response.content_type - - assert_select 'group' do - assert_select 'users' do - assert_select 'user', Group.find(10).users.count - assert_select 'user[id=8]' - end - end + assert_select 'group' do + assert_select 'users' do + assert_select 'user', Group.find(10).users.count + assert_select 'user[id=8]' end + end + end - should "include memberships if requested" do - get '/groups/10.xml?include=memberships', {}, credentials('admin') - assert_response :success - assert_equal 'application/xml', response.content_type + 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 - assert_select 'group' do - assert_select 'memberships' - end - end + assert_select 'group' do + assert_select 'memberships' end end - context "POST /groups" do - context "with valid parameters" do - context ".xml" do - should "create groups" do - assert_difference('Group.count') do - post '/groups.xml', {:group => {:name => 'Test', :user_ids => [2, 3]}}, credentials('admin') - assert_response :created - assert_equal 'application/xml', response.content_type - end - - group = Group.order('id DESC').first - assert_equal 'Test', group.name - assert_equal [2, 3], group.users.map(&:id).sort - - assert_select 'group' do - assert_select 'name', :text => 'Test' - end - end - end + 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 + assert_equal 'application/xml', response.content_type end - context "with invalid parameters" do - context ".xml" do - should "return errors" do - assert_no_difference('Group.count') do - post '/groups.xml', {:group => {:name => ''}}, credentials('admin') - end - assert_response :unprocessable_entity - assert_equal 'application/xml', response.content_type - - assert_select 'errors' do - assert_select 'error', :text => /Name can't be blank/ - end - end - end + group = Group.order('id DESC').first + assert_equal 'Test', group.name + assert_equal [2, 3], group.users.map(&:id).sort + + assert_select 'group' do + assert_select 'name', :text => 'Test' end end - context "PUT /groups/:id" do - context "with valid parameters" do - context ".xml" do - 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 - - group = Group.find(10) - assert_equal 'New name', group.name - assert_equal [2, 3], group.users.map(&:id).sort - end - end + 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 + assert_response :unprocessable_entity + assert_equal 'application/xml', response.content_type - context "with invalid parameters" do - context ".xml" do - should "return errors" do - put '/groups/10.xml', {:group => {:name => ''}}, credentials('admin') - assert_response :unprocessable_entity - assert_equal 'application/xml', response.content_type - - assert_select 'errors' do - assert_select 'error', :text => /Name can't be blank/ - end - end - end + assert_select 'errors' do + assert_select 'error', :text => /Name can't be blank/ end end - context "DELETE /groups/:id" do - context ".xml" do - 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 + 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 + + group = Group.find(10) + assert_equal 'New name', group.name + assert_equal [2, 3], group.users.map(&:id).sort + end + + 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 + + assert_select 'errors' do + assert_select 'error', :text => /Name can't be blank/ end end - context "POST /groups/:id/users" do - context ".xml" do - 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 - assert_equal '', @response.body - end - assert_include User.find(5), Group.find(10).users - end + 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 - context "DELETE /groups/:id/users/:user_id" do - context ".xml" do - 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 - assert_equal '', @response.body - end - assert_not_include User.find(8), Group.find(10).users - end + 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 + assert_equal '', @response.body + end + assert_include User.find(5), Group.find(10).users + end + + 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 + assert_equal '', @response.body end + assert_not_include User.find(8), Group.find(10).users end end diff --git a/test/integration/api_test/issue_categories_test.rb b/test/integration/api_test/issue_categories_test.rb index 9e5448414..dc970a65a 100644 --- a/test/integration/api_test/issue_categories_test.rb +++ b/test/integration/api_test/issue_categories_test.rb @@ -28,99 +28,83 @@ 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 - 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 + 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 - context "GET /issue_categories/2.xml" do - should "return requested 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 + 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 - context "POST /projects/:project_id/issue_categories.xml" do - should "return create issue category" do - assert_difference 'IssueCategory.count' do - post '/projects/1/issue_categories.xml', {:issue_category => {:name => 'API'}}, credentials('jsmith') - end - assert_response :created - assert_equal 'application/xml', @response.content_type - - category = IssueCategory.first(:order => 'id DESC') - assert_equal 'API', category.name - assert_equal 1, category.project_id + 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 + assert_response :created + assert_equal 'application/xml', @response.content_type - context "with invalid parameters" do - should "return errors" do - assert_no_difference 'IssueCategory.count' do - post '/projects/1/issue_categories.xml', {:issue_category => {:name => ''}}, credentials('jsmith') - end - assert_response :unprocessable_entity - assert_equal 'application/xml', @response.content_type + category = IssueCategory.first(:order => 'id DESC') + assert_equal 'API', category.name + assert_equal 1, category.project_id + end - assert_tag 'errors', :child => {:tag => 'error', :content => "Name can't be blank"} - end + 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 + assert_response :unprocessable_entity + assert_equal 'application/xml', @response.content_type + + assert_tag 'errors', :child => {:tag => 'error', :content => "Name can't be blank"} end - context "PUT /issue_categories/2.xml" do - context "with valid parameters" do - should "update issue category" do - assert_no_difference 'IssueCategory.count' do - put '/issue_categories/2.xml', {:issue_category => {:name => 'API Update'}}, credentials('jsmith') - end - assert_response :ok - assert_equal '', @response.body - assert_equal 'API Update', IssueCategory.find(2).name - end + 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 + assert_response :ok + assert_equal '', @response.body + assert_equal 'API Update', IssueCategory.find(2).name + end - context "with invalid parameters" do - should "return errors" do - assert_no_difference 'IssueCategory.count' do - put '/issue_categories/2.xml', {:issue_category => {:name => ''}}, credentials('jsmith') - 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 + 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 + assert_response :unprocessable_entity + assert_equal 'application/xml', @response.content_type + + assert_tag 'errors', :child => {:tag => 'error', :content => "Name can't be blank"} end - context "DELETE /issue_categories/1.xml" do - should "destroy issue categories" do - assert_difference 'IssueCategory.count', -1 do - delete '/issue_categories/1.xml', {}, credentials('jsmith') - end - assert_response :ok - assert_equal '', @response.body - assert_nil IssueCategory.find_by_id(1) + 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 + assert_response :ok + assert_equal '', @response.body + assert_nil IssueCategory.find_by_id(1) + end - should "reassign issues with :reassign_to_id param" do - issue_count = Issue.count(:conditions => {:category_id => 1}) - assert issue_count > 0 + 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 - assert_difference 'IssueCategory.count', -1 do - assert_difference 'Issue.count(:conditions => {:category_id => 2})', 3 do - delete '/issue_categories/1.xml', {:reassign_to_id => 2}, credentials('jsmith') - end + assert_difference 'IssueCategory.count', -1 do + assert_difference 'Issue.count(:conditions => {:category_id => 2})', 3 do + delete '/issue_categories/1.xml', {:reassign_to_id => 2}, credentials('jsmith') end - assert_response :ok - assert_equal '', @response.body - assert_nil IssueCategory.find_by_id(1) end + assert_response :ok + assert_equal '', @response.body + assert_nil IssueCategory.find_by_id(1) end end diff --git a/test/integration/api_test/issue_relations_test.rb b/test/integration/api_test/issue_relations_test.rb index 72c690e6a..e11010330 100644 --- a/test/integration/api_test/issue_relations_test.rb +++ b/test/integration/api_test/issue_relations_test.rb @@ -31,76 +31,62 @@ 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 - get '/issues/9/relations.xml', {}, credentials('jsmith') + test "GET /issues/:issue_id/relations.xml should return issue relations" do + get '/issues/9/relations.xml', {}, credentials('jsmith') - assert_response :success - assert_equal 'application/xml', @response.content_type + assert_response :success + assert_equal 'application/xml', @response.content_type - assert_tag :tag => 'relations', - :attributes => { :type => 'array' }, - :child => { - :tag => 'relation', - :child => { - :tag => 'id', - :content => '1' - } - } - end - end - - context "POST" do - should "create a relation" do - assert_difference('IssueRelation.count') do - post '/issues/2/relations.xml', {:relation => {:issue_to_id => 7, :relation_type => 'relates'}}, credentials('jsmith') - end + assert_tag :tag => 'relations', + :attributes => { :type => 'array' }, + :child => { + :tag => 'relation', + :child => { + :tag => 'id', + :content => '1' + } + } + end - relation = IssueRelation.first(:order => 'id DESC') - assert_equal 2, relation.issue_from_id - assert_equal 7, relation.issue_to_id - assert_equal 'relates', relation.relation_type + 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 - assert_response :created - assert_equal 'application/xml', @response.content_type - assert_tag 'relation', :child => {:tag => 'id', :content => relation.id.to_s} - end + relation = IssueRelation.first(:order => 'id DESC') + assert_equal 2, relation.issue_from_id + assert_equal 7, relation.issue_to_id + assert_equal 'relates', relation.relation_type - context "with failure" do - should "return the errors" do - assert_no_difference('IssueRelation.count') do - post '/issues/2/relations.xml', {:relation => {:issue_to_id => 7, :relation_type => 'foo'}}, credentials('jsmith') - end + assert_response :created + assert_equal 'application/xml', @response.content_type + assert_tag 'relation', :child => {:tag => 'id', :content => relation.id.to_s} + end - assert_response :unprocessable_entity - assert_tag :errors, :child => {:tag => 'error', :content => /relation_type is not included in the list/} - end - end + 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 - end - context "/relations/:id" do - context "GET" do - should "return the relation" do - get '/relations/2.xml', {}, credentials('jsmith') + assert_response :unprocessable_entity + assert_tag :errors, :child => {:tag => 'error', :content => /relation_type is not included in the list/} + end - assert_response :success - assert_equal 'application/xml', @response.content_type - assert_tag 'relation', :child => {:tag => 'id', :content => '2'} - end - end + test "GET /relations/:id.xml should return the relation" do + get '/relations/2.xml', {}, credentials('jsmith') - context "DELETE" do - should "delete the relation" do - assert_difference('IssueRelation.count', -1) do - delete '/relations/2.xml', {}, credentials('jsmith') - end + assert_response :success + assert_equal 'application/xml', @response.content_type + assert_tag 'relation', :child => {:tag => 'id', :content => '2'} + end - assert_response :ok - assert_equal '', @response.body - assert_nil IssueRelation.find_by_id(2) - end + test "DELETE /relations/:id.xml should delete the relation" do + assert_difference('IssueRelation.count', -1) do + delete '/relations/2.xml', {}, credentials('jsmith') end + + assert_response :ok + assert_equal '', @response.body + assert_nil IssueRelation.find_by_id(2) end end diff --git a/test/integration/api_test/issue_statuses_test.rb b/test/integration/api_test/issue_statuses_test.rb index db8859b13..f53577ae5 100644 --- a/test/integration/api_test/issue_statuses_test.rb +++ b/test/integration/api_test/issue_statuses_test.rb @@ -24,28 +24,23 @@ class Redmine::ApiTest::IssueStatusesTest < Redmine::ApiTest::Base Setting.rest_api_enabled = '1' end - context "/issue_statuses" do - context "GET" do + test "GET /issue_statuses.xml should return issue statuses" do + get '/issue_statuses.xml' - should "return issue statuses" do - get '/issue_statuses.xml' - - assert_response :success - assert_equal 'application/xml', @response.content_type - assert_tag :tag => 'issue_statuses', - :attributes => {:type => 'array'}, - :child => { - :tag => 'issue_status', - :child => { - :tag => 'id', - :content => '2', - :sibling => { - :tag => 'name', - :content => 'Assigned' - } - } + assert_response :success + assert_equal 'application/xml', @response.content_type + assert_tag :tag => 'issue_statuses', + :attributes => {:type => 'array'}, + :child => { + :tag => 'issue_status', + :child => { + :tag => 'id', + :content => '2', + :sibling => { + :tag => 'name', + :content => 'Assigned' } - end - end + } + } end end diff --git a/test/integration/api_test/memberships_test.rb b/test/integration/api_test/memberships_test.rb index 12b7de7ef..626282054 100644 --- a/test/integration/api_test/memberships_test.rb +++ b/test/integration/api_test/memberships_test.rb @@ -24,177 +24,149 @@ 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 - get '/projects/1/memberships.xml', {}, credentials('jsmith') - - assert_response :success - assert_equal 'application/xml', @response.content_type - assert_tag :tag => 'memberships', - :attributes => {:type => 'array'}, - :child => { - :tag => 'membership', + test "GET /projects/:project_id/memberships.xml should return memberships" do + get '/projects/1/memberships.xml', {}, credentials('jsmith') + + assert_response :success + assert_equal 'application/xml', @response.content_type + assert_tag :tag => 'memberships', + :attributes => {:type => 'array'}, + :child => { + :tag => 'membership', + :child => { + :tag => 'id', + :content => '2', + :sibling => { + :tag => 'user', + :attributes => {:id => '3', :name => 'Dave Lopper'}, + :sibling => { + :tag => 'roles', :child => { - :tag => 'id', - :content => '2', - :sibling => { - :tag => 'user', - :attributes => {:id => '3', :name => 'Dave Lopper'}, - :sibling => { - :tag => 'roles', - :child => { - :tag => 'role', - :attributes => {:id => '2', :name => 'Developer'} - } - } - } + :tag => 'role', + :attributes => {:id => '2', :name => 'Developer'} } } - end - end - - context "json" do - should "return memberships" do - get '/projects/1/memberships.json', {}, credentials('jsmith') - - assert_response :success - assert_equal 'application/json', @response.content_type - json = ActiveSupport::JSON.decode(response.body) - assert_equal({ - "memberships" => - [{"id"=>1, - "project" => {"name"=>"eCookbook", "id"=>1}, - "roles" => [{"name"=>"Manager", "id"=>1}], - "user" => {"name"=>"John Smith", "id"=>2}}, - {"id"=>2, - "project" => {"name"=>"eCookbook", "id"=>1}, - "roles" => [{"name"=>"Developer", "id"=>2}], - "user" => {"name"=>"Dave Lopper", "id"=>3}}], - "limit" => 25, - "total_count" => 2, - "offset" => 0}, - json) - end - end - end + } + } + } + end + + test "GET /projects/:project_id/memberships.json should return memberships" do + get '/projects/1/memberships.json', {}, credentials('jsmith') + + assert_response :success + assert_equal 'application/json', @response.content_type + json = ActiveSupport::JSON.decode(response.body) + assert_equal({ + "memberships" => + [{"id"=>1, + "project" => {"name"=>"eCookbook", "id"=>1}, + "roles" => [{"name"=>"Manager", "id"=>1}], + "user" => {"name"=>"John Smith", "id"=>2}}, + {"id"=>2, + "project" => {"name"=>"eCookbook", "id"=>1}, + "roles" => [{"name"=>"Developer", "id"=>2}], + "user" => {"name"=>"Dave Lopper", "id"=>3}}], + "limit" => 25, + "total_count" => 2, + "offset" => 0}, + json) + end + + 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') - context "POST" do - context "xml" do - should "create membership" do - assert_difference 'Member.count' do - post '/projects/1/memberships.xml', {:membership => {:user_id => 7, :role_ids => [2,3]}}, credentials('jsmith') - - assert_response :created - end - end - - should "return errors on failure" do - assert_no_difference 'Member.count' do - post '/projects/1/memberships.xml', {:membership => {:role_ids => [2,3]}}, credentials('jsmith') - - assert_response :unprocessable_entity - assert_equal 'application/xml', @response.content_type - assert_tag 'errors', :child => {:tag => 'error', :content => "Principal can't be blank"} - end - end - end + assert_response :created end end - context "/memberships/:id" do - context "GET" do - context "xml" do - should "return the membership" do - get '/memberships/2.xml', {}, credentials('jsmith') + 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') - assert_response :success - assert_equal 'application/xml', @response.content_type - assert_tag :tag => 'membership', + assert_response :unprocessable_entity + assert_equal 'application/xml', @response.content_type + assert_tag 'errors', :child => {:tag => 'error', :content => "Principal can't be blank"} + end + end + + test "GET /memberships/:id.xml should return the membership" do + get '/memberships/2.xml', {}, credentials('jsmith') + + assert_response :success + assert_equal 'application/xml', @response.content_type + assert_tag :tag => 'membership', + :child => { + :tag => 'id', + :content => '2', + :sibling => { + :tag => 'user', + :attributes => {:id => '3', :name => 'Dave Lopper'}, + :sibling => { + :tag => 'roles', :child => { - :tag => 'id', - :content => '2', - :sibling => { - :tag => 'user', - :attributes => {:id => '3', :name => 'Dave Lopper'}, - :sibling => { - :tag => 'roles', - :child => { - :tag => 'role', - :attributes => {:id => '2', :name => 'Developer'} - } - } - } + :tag => 'role', + :attributes => {:id => '2', :name => 'Developer'} } - end - end - - context "json" do - should "return the membership" do - get '/memberships/2.json', {}, credentials('jsmith') - - assert_response :success - assert_equal 'application/json', @response.content_type - json = ActiveSupport::JSON.decode(response.body) - assert_equal( - {"membership" => { - "id" => 2, - "project" => {"name"=>"eCookbook", "id"=>1}, - "roles" => [{"name"=>"Developer", "id"=>2}], - "user" => {"name"=>"Dave Lopper", "id"=>3}} - }, - json) - end - end + } + } + } + end + + test "GET /memberships/:id.json should return the membership" do + get '/memberships/2.json', {}, credentials('jsmith') + + assert_response :success + assert_equal 'application/json', @response.content_type + json = ActiveSupport::JSON.decode(response.body) + assert_equal( + {"membership" => { + "id" => 2, + "project" => {"name"=>"eCookbook", "id"=>1}, + "roles" => [{"name"=>"Developer", "id"=>2}], + "user" => {"name"=>"Dave Lopper", "id"=>3}} + }, + json) + end + + 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') + + assert_response :ok + assert_equal '', @response.body end + member = Member.find(2) + assert_equal [1,2], member.role_ids.sort + end + + 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') - context "PUT" do - context "xml" do - should "update 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') - - assert_response :ok - assert_equal '', @response.body - end - member = Member.find(2) - assert_equal [1,2], member.role_ids.sort - end - - should "return errors on failure" 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 + assert_response :unprocessable_entity + assert_equal 'application/xml', @response.content_type + assert_tag 'errors', :child => {:tag => 'error', :content => /member_roles is invalid/} + end + + test "DELETE /memberships/:id.xml should destroy the membership" do + assert_difference 'Member.count', -1 do + delete '/memberships/2.xml', {}, credentials('jsmith') + + assert_response :ok + assert_equal '', @response.body end + assert_nil Member.find_by_id(2) + end + + 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 + delete '/memberships/2.xml', {}, credentials('jsmith') - context "DELETE" do - context "xml" do - should "destroy membership" do - assert_difference 'Member.count', -1 do - delete '/memberships/2.xml', {}, credentials('jsmith') - - assert_response :ok - assert_equal '', @response.body - end - assert_nil Member.find_by_id(2) - end - - 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 - delete '/memberships/2.xml', {}, credentials('jsmith') - - assert_response :unprocessable_entity - end - end - end + assert_response :unprocessable_entity end end end diff --git a/test/integration/api_test/news_test.rb b/test/integration/api_test/news_test.rb index 41be26260..e5a31885c 100644 --- a/test/integration/api_test/news_test.rb +++ b/test/integration/api_test/news_test.rb @@ -31,67 +31,54 @@ class Redmine::ApiTest::NewsTest < Redmine::ApiTest::Base Setting.rest_api_enabled = '1' end - context "GET /news" do - context ".xml" do - should "return news" do - get '/news.xml' + should_allow_api_authentication(:get, "/projects/onlinestore/news.xml") + should_allow_api_authentication(:get, "/projects/onlinestore/news.json") - assert_tag :tag => 'news', - :attributes => {:type => 'array'}, - :child => { - :tag => 'news', - :child => { - :tag => 'id', - :content => '2' - } - } - end - end + test "GET /news.xml should return news" do + get '/news.xml' - context ".json" do - should "return news" do - get '/news.json' - - json = ActiveSupport::JSON.decode(response.body) - assert_kind_of Hash, json - assert_kind_of Array, json['news'] - assert_kind_of Hash, json['news'].first - assert_equal 2, json['news'].first['id'] - end - end + assert_tag :tag => 'news', + :attributes => {:type => 'array'}, + :child => { + :tag => 'news', + :child => { + :tag => 'id', + :content => '2' + } + } end - context "GET /projects/:project_id/news" do - context ".xml" do - should_allow_api_authentication(:get, "/projects/onlinestore/news.xml") + test "GET /news.json should return news" do + get '/news.json' - should "return news" do - get '/projects/ecookbook/news.xml' + json = ActiveSupport::JSON.decode(response.body) + assert_kind_of Hash, json + assert_kind_of Array, json['news'] + assert_kind_of Hash, json['news'].first + assert_equal 2, json['news'].first['id'] + end - assert_tag :tag => 'news', - :attributes => {:type => 'array'}, - :child => { - :tag => 'news', - :child => { - :tag => 'id', - :content => '2' - } - } - end - end + test "GET /projects/:project_id/news.xml should return news" do + get '/projects/ecookbook/news.xml' - context ".json" do - should_allow_api_authentication(:get, "/projects/onlinestore/news.json") + assert_tag :tag => 'news', + :attributes => {:type => 'array'}, + :child => { + :tag => 'news', + :child => { + :tag => 'id', + :content => '2' + } + } + end - should "return news" do - get '/projects/ecookbook/news.json' + test "GET /projects/:project_id/news.json should return news" do + get '/projects/ecookbook/news.json' - json = ActiveSupport::JSON.decode(response.body) - assert_kind_of Hash, json - assert_kind_of Array, json['news'] - assert_kind_of Hash, json['news'].first - assert_equal 2, json['news'].first['id'] - end - end + json = ActiveSupport::JSON.decode(response.body) + assert_kind_of Hash, json + assert_kind_of Array, json['news'] + assert_kind_of Hash, json['news'].first + assert_equal 2, json['news'].first['id'] end end