annotate .svn/pristine/ac/ac7626843625f32674cf1d8a662e9e3a05d37cf1.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

Fix failure to interpret Javascript when autocompleting members for project
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Thu, 11 Sep 2014 10:24:38 +0100
parents dffacf8a6908
children
rev   line source
Chris@1517 1 # Redmine - project management software
Chris@1517 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
Chris@1517 3 #
Chris@1517 4 # This program is free software; you can redistribute it and/or
Chris@1517 5 # modify it under the terms of the GNU General Public License
Chris@1517 6 # as published by the Free Software Foundation; either version 2
Chris@1517 7 # of the License, or (at your option) any later version.
Chris@1517 8 #
Chris@1517 9 # This program is distributed in the hope that it will be useful,
Chris@1517 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1517 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1517 12 # GNU General Public License for more details.
Chris@1517 13 #
Chris@1517 14 # You should have received a copy of the GNU General Public License
Chris@1517 15 # along with this program; if not, write to the Free Software
Chris@1517 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1517 17
Chris@1517 18 require File.expand_path('../../../test_helper', __FILE__)
Chris@1517 19
Chris@1517 20 class Redmine::ApiTest::MembershipsTest < Redmine::ApiTest::Base
Chris@1517 21 fixtures :projects, :users, :roles, :members, :member_roles
Chris@1517 22
Chris@1517 23 def setup
Chris@1517 24 Setting.rest_api_enabled = '1'
Chris@1517 25 end
Chris@1517 26
Chris@1517 27 test "GET /projects/:project_id/memberships.xml should return memberships" do
Chris@1517 28 get '/projects/1/memberships.xml', {}, credentials('jsmith')
Chris@1517 29
Chris@1517 30 assert_response :success
Chris@1517 31 assert_equal 'application/xml', @response.content_type
Chris@1517 32 assert_tag :tag => 'memberships',
Chris@1517 33 :attributes => {:type => 'array'},
Chris@1517 34 :child => {
Chris@1517 35 :tag => 'membership',
Chris@1517 36 :child => {
Chris@1517 37 :tag => 'id',
Chris@1517 38 :content => '2',
Chris@1517 39 :sibling => {
Chris@1517 40 :tag => 'user',
Chris@1517 41 :attributes => {:id => '3', :name => 'Dave Lopper'},
Chris@1517 42 :sibling => {
Chris@1517 43 :tag => 'roles',
Chris@1517 44 :child => {
Chris@1517 45 :tag => 'role',
Chris@1517 46 :attributes => {:id => '2', :name => 'Developer'}
Chris@1517 47 }
Chris@1517 48 }
Chris@1517 49 }
Chris@1517 50 }
Chris@1517 51 }
Chris@1517 52 end
Chris@1517 53
Chris@1517 54 test "GET /projects/:project_id/memberships.json should return memberships" do
Chris@1517 55 get '/projects/1/memberships.json', {}, credentials('jsmith')
Chris@1517 56
Chris@1517 57 assert_response :success
Chris@1517 58 assert_equal 'application/json', @response.content_type
Chris@1517 59 json = ActiveSupport::JSON.decode(response.body)
Chris@1517 60 assert_equal({
Chris@1517 61 "memberships" =>
Chris@1517 62 [{"id"=>1,
Chris@1517 63 "project" => {"name"=>"eCookbook", "id"=>1},
Chris@1517 64 "roles" => [{"name"=>"Manager", "id"=>1}],
Chris@1517 65 "user" => {"name"=>"John Smith", "id"=>2}},
Chris@1517 66 {"id"=>2,
Chris@1517 67 "project" => {"name"=>"eCookbook", "id"=>1},
Chris@1517 68 "roles" => [{"name"=>"Developer", "id"=>2}],
Chris@1517 69 "user" => {"name"=>"Dave Lopper", "id"=>3}}],
Chris@1517 70 "limit" => 25,
Chris@1517 71 "total_count" => 2,
Chris@1517 72 "offset" => 0},
Chris@1517 73 json)
Chris@1517 74 end
Chris@1517 75
Chris@1517 76 test "GET /projects/:project_id/memberships.xml should succeed for closed project" do
Chris@1517 77 project = Project.find(1)
Chris@1517 78 project.close
Chris@1517 79 assert !project.reload.active?
Chris@1517 80 get '/projects/1/memberships.json', {}, credentials('jsmith')
Chris@1517 81 assert_response :success
Chris@1517 82 end
Chris@1517 83
Chris@1517 84 test "POST /projects/:project_id/memberships.xml should create the membership" do
Chris@1517 85 assert_difference 'Member.count' do
Chris@1517 86 post '/projects/1/memberships.xml', {:membership => {:user_id => 7, :role_ids => [2,3]}}, credentials('jsmith')
Chris@1517 87
Chris@1517 88 assert_response :created
Chris@1517 89 end
Chris@1517 90 end
Chris@1517 91
Chris@1517 92 test "POST /projects/:project_id/memberships.xml with invalid parameters should return errors" do
Chris@1517 93 assert_no_difference 'Member.count' do
Chris@1517 94 post '/projects/1/memberships.xml', {:membership => {:role_ids => [2,3]}}, credentials('jsmith')
Chris@1517 95
Chris@1517 96 assert_response :unprocessable_entity
Chris@1517 97 assert_equal 'application/xml', @response.content_type
Chris@1517 98 assert_tag 'errors', :child => {:tag => 'error', :content => "Principal can't be blank"}
Chris@1517 99 end
Chris@1517 100 end
Chris@1517 101
Chris@1517 102 test "GET /memberships/:id.xml should return the membership" do
Chris@1517 103 get '/memberships/2.xml', {}, credentials('jsmith')
Chris@1517 104
Chris@1517 105 assert_response :success
Chris@1517 106 assert_equal 'application/xml', @response.content_type
Chris@1517 107 assert_tag :tag => 'membership',
Chris@1517 108 :child => {
Chris@1517 109 :tag => 'id',
Chris@1517 110 :content => '2',
Chris@1517 111 :sibling => {
Chris@1517 112 :tag => 'user',
Chris@1517 113 :attributes => {:id => '3', :name => 'Dave Lopper'},
Chris@1517 114 :sibling => {
Chris@1517 115 :tag => 'roles',
Chris@1517 116 :child => {
Chris@1517 117 :tag => 'role',
Chris@1517 118 :attributes => {:id => '2', :name => 'Developer'}
Chris@1517 119 }
Chris@1517 120 }
Chris@1517 121 }
Chris@1517 122 }
Chris@1517 123 end
Chris@1517 124
Chris@1517 125 test "GET /memberships/:id.json should return the membership" do
Chris@1517 126 get '/memberships/2.json', {}, credentials('jsmith')
Chris@1517 127
Chris@1517 128 assert_response :success
Chris@1517 129 assert_equal 'application/json', @response.content_type
Chris@1517 130 json = ActiveSupport::JSON.decode(response.body)
Chris@1517 131 assert_equal(
Chris@1517 132 {"membership" => {
Chris@1517 133 "id" => 2,
Chris@1517 134 "project" => {"name"=>"eCookbook", "id"=>1},
Chris@1517 135 "roles" => [{"name"=>"Developer", "id"=>2}],
Chris@1517 136 "user" => {"name"=>"Dave Lopper", "id"=>3}}
Chris@1517 137 },
Chris@1517 138 json)
Chris@1517 139 end
Chris@1517 140
Chris@1517 141 test "PUT /memberships/:id.xml should update the membership" do
Chris@1517 142 assert_not_equal [1,2], Member.find(2).role_ids.sort
Chris@1517 143 assert_no_difference 'Member.count' do
Chris@1517 144 put '/memberships/2.xml', {:membership => {:user_id => 3, :role_ids => [1,2]}}, credentials('jsmith')
Chris@1517 145
Chris@1517 146 assert_response :ok
Chris@1517 147 assert_equal '', @response.body
Chris@1517 148 end
Chris@1517 149 member = Member.find(2)
Chris@1517 150 assert_equal [1,2], member.role_ids.sort
Chris@1517 151 end
Chris@1517 152
Chris@1517 153 test "PUT /memberships/:id.xml with invalid parameters should return errors" do
Chris@1517 154 put '/memberships/2.xml', {:membership => {:user_id => 3, :role_ids => [99]}}, credentials('jsmith')
Chris@1517 155
Chris@1517 156 assert_response :unprocessable_entity
Chris@1517 157 assert_equal 'application/xml', @response.content_type
Chris@1517 158 assert_tag 'errors', :child => {:tag => 'error', :content => /member_roles is invalid/}
Chris@1517 159 end
Chris@1517 160
Chris@1517 161 test "DELETE /memberships/:id.xml should destroy the membership" do
Chris@1517 162 assert_difference 'Member.count', -1 do
Chris@1517 163 delete '/memberships/2.xml', {}, credentials('jsmith')
Chris@1517 164
Chris@1517 165 assert_response :ok
Chris@1517 166 assert_equal '', @response.body
Chris@1517 167 end
Chris@1517 168 assert_nil Member.find_by_id(2)
Chris@1517 169 end
Chris@1517 170
Chris@1517 171 test "DELETE /memberships/:id.xml should respond with 422 on failure" do
Chris@1517 172 assert_no_difference 'Member.count' do
Chris@1517 173 # A membership with an inherited role can't be deleted
Chris@1517 174 Member.find(2).member_roles.first.update_attribute :inherited_from, 99
Chris@1517 175 delete '/memberships/2.xml', {}, credentials('jsmith')
Chris@1517 176
Chris@1517 177 assert_response :unprocessable_entity
Chris@1517 178 end
Chris@1517 179 end
Chris@1517 180 end