##// END OF EJS Templates
Adds tracker name to Redmine issue link titles (#13946)....
Adds tracker name to Redmine issue link titles (#13946). git-svn-id: http://svn.redmine.org/redmine/trunk@14620 e93f8b46-1217-0410-a6f0-8f06a7374b81

File last commit:

r13535:0bc87002d297
r14238:a7b6ad9bb5ba
Show More
groups_test.rb
209 lines | 6.8 KiB | text/x-ruby | RubyLexer
Jean-Philippe Lang
REST Api for Groups (#8981)....
r9575 # Redmine - project management software
Jean-Philippe Lang
Copyright update....
r13490 # Copyright (C) 2006-2015 Jean-Philippe Lang
Jean-Philippe Lang
REST Api for Groups (#8981)....
r9575 #
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require File.expand_path('../../../test_helper', __FILE__)
Jean-Philippe Lang
Adds a subclass of ActionDispatch::IntegrationTest for API tests....
r11023 class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base
Toshi MARUYAMA
add missing fixture to test/integration/api_test/groups_test.rb...
r13535 fixtures :users, :groups_users, :email_addresses
Jean-Philippe Lang
REST Api for Groups (#8981)....
r9575
Jean-Philippe Lang
Removed some shoulda context....
r11632 test "GET /groups.xml should require authentication" do
get '/groups.xml'
assert_response 401
end
Jean-Philippe Lang
REST Api for Groups (#8981)....
r9575
Jean-Philippe Lang
Adds buit-in groups to give specific permissions to anonymous and non members users per project (#17976)....
r13053 test "GET /groups.xml should return givable groups" do
Jean-Philippe Lang
Removed some shoulda context....
r11632 get '/groups.xml', {}, credentials('admin')
assert_response :success
assert_equal 'application/xml', response.content_type
assert_select 'groups' do
Jean-Philippe Lang
Adds buit-in groups to give specific permissions to anonymous and non members users per project (#17976)....
r13053 assert_select 'group', Group.givable.count
Jean-Philippe Lang
Removed some shoulda context....
r11632 assert_select 'group' do
assert_select 'name', :text => 'A Team'
assert_select 'id', :text => '10'
Jean-Philippe Lang
REST Api for Groups (#8981)....
r9575 end
end
Jean-Philippe Lang
Removed some shoulda context....
r11632 end
Jean-Philippe Lang
REST Api for Groups (#8981)....
r9575
Jean-Philippe Lang
Adds buit-in groups to give specific permissions to anonymous and non members users per project (#17976)....
r13053 test "GET /groups.xml?builtin=1 should return all groups" do
get '/groups.xml?builtin=1', {}, credentials('admin')
assert_response :success
assert_equal 'application/xml', response.content_type
assert_select 'groups' do
assert_select 'group', Group.givable.count + 2
assert_select 'group' do
assert_select 'builtin', :text => 'non_member'
assert_select 'id', :text => '12'
end
assert_select 'group' do
assert_select 'builtin', :text => 'anonymous'
assert_select 'id', :text => '13'
end
end
end
Jean-Philippe Lang
Removed some shoulda context....
r11632 test "GET /groups.json should require authentication" do
get '/groups.json'
assert_response 401
end
Jean-Philippe Lang
REST Api for Groups (#8981)....
r9575
Jean-Philippe Lang
Removed some shoulda context....
r11632 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
Jean-Philippe Lang
Adds buit-in groups to give specific permissions to anonymous and non members users per project (#17976)....
r13053 test "GET /groups/:id.xml should return the group" do
Jean-Philippe Lang
Removed some shoulda context....
r11632 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'
Jean-Philippe Lang
REST Api for Groups (#8981)....
r9575 end
end
Jean-Philippe Lang
Adds buit-in groups to give specific permissions to anonymous and non members users per project (#17976)....
r13053 test "GET /groups/:id.xml should return the builtin group" do
get '/groups/12.xml', {}, credentials('admin')
assert_response :success
assert_equal 'application/xml', response.content_type
assert_select 'group' do
assert_select 'builtin', :text => 'non_member'
assert_select 'id', :text => '12'
end
end
Jean-Philippe Lang
Removed some shoulda context....
r11632 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
Jean-Philippe Lang
Makes users optional in GET /groups/:id (#8981)....
r9582
Jean-Philippe Lang
Removed some shoulda context....
r11632 assert_select 'group' do
assert_select 'users' do
assert_select 'user', Group.find(10).users.count
Jean-Philippe Lang
Upgrade to Rails 4.2.0 (#14534)....
r13510 assert_select 'user[id="8"]'
Jean-Philippe Lang
REST Api for Groups (#8981)....
r9575 end
Jean-Philippe Lang
Removed some shoulda context....
r11632 end
end
Jean-Philippe Lang
REST Api for Groups (#8981)....
r9575
Jean-Philippe Lang
Removed some shoulda context....
r11632 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
Jean-Philippe Lang
REST Api for Groups (#8981)....
r9575
Jean-Philippe Lang
Removed some shoulda context....
r11632 assert_select 'group' do
assert_select 'memberships'
Jean-Philippe Lang
REST Api for Groups (#8981)....
r9575 end
end
Jean-Philippe Lang
Removed some shoulda context....
r11632 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
Jean-Philippe Lang
REST Api for Groups (#8981)....
r9575 end
Jean-Philippe Lang
Removed some shoulda context....
r11632 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'
Jean-Philippe Lang
REST Api for Groups (#8981)....
r9575 end
end
Jean-Philippe Lang
Removed some shoulda context....
r11632 test "POST /groups.xml with invalid parameters should return errors" do
assert_no_difference('Group.count') do
post '/groups.xml', {:group => {:name => ''}}, credentials('admin')
Jean-Philippe Lang
REST Api for Groups (#8981)....
r9575 end
Jean-Philippe Lang
Removed some shoulda context....
r11632 assert_response :unprocessable_entity
assert_equal 'application/xml', response.content_type
Jean-Philippe Lang
REST Api for Groups (#8981)....
r9575
Jean-Philippe Lang
Removed some shoulda context....
r11632 assert_select 'errors' do
Jean-Philippe Lang
Replaced "can't" with "cannot" in error messages....
r13399 assert_select 'error', :text => /Name cannot be blank/
Jean-Philippe Lang
REST Api for Groups (#8981)....
r9575 end
end
Jean-Philippe Lang
Removed some shoulda context....
r11632 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
Jean-Philippe Lang
Replaced "can't" with "cannot" in error messages....
r13399 assert_select 'error', :text => /Name cannot be blank/
Jean-Philippe Lang
REST Api for Groups (#8981)....
r9575 end
end
Jean-Philippe Lang
Removed some shoulda context....
r11632 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
Jean-Philippe Lang
REST Api for Groups (#8981)....
r9575 end
end
Jean-Philippe Lang
Removed some shoulda context....
r11632 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
Jean-Philippe Lang
Error when adding user to group where he is already assigned (#18665)....
r13403 test "POST /groups/:id/users.xml should not add the user if already added" do
Group.find(10).users << User.find(5)
assert_no_difference 'Group.find(10).users.count' do
post '/groups/10/users.xml', {:user_id => 5}, credentials('admin')
assert_response :unprocessable_entity
end
assert_select 'errors' do
assert_select 'error', :text => /User is invalid/
end
end
Jean-Philippe Lang
Removed some shoulda context....
r11632 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
Jean-Philippe Lang
REST Api for Groups (#8981)....
r9575 end
Jean-Philippe Lang
Removed some shoulda context....
r11632 assert_not_include User.find(8), Group.find(10).users
Jean-Philippe Lang
REST Api for Groups (#8981)....
r9575 end
end