2011-10-29 16:19:11 +04:00
|
|
|
#-- encoding: UTF-8
|
2011-05-30 00:11:52 +04:00
|
|
|
#-- copyright
|
|
|
|
# ChiliProject is a project management system.
|
2011-05-30 22:52:25 +04:00
|
|
|
#
|
2013-01-07 02:20:49 +04:00
|
|
|
# Copyright (C) 2010-2013 the ChiliProject Team
|
2011-05-30 22:52:25 +04:00
|
|
|
#
|
2011-05-30 00:11:52 +04:00
|
|
|
# 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.
|
2011-05-30 22:52:25 +04:00
|
|
|
#
|
2011-05-30 00:11:52 +04:00
|
|
|
# See doc/COPYRIGHT.rdoc for more details.
|
|
|
|
#++
|
|
|
|
|
2010-12-13 02:24:34 +03:00
|
|
|
require File.expand_path('../../test_helper', __FILE__)
|
2010-08-17 19:03:58 +04:00
|
|
|
|
|
|
|
class AutoCompletesControllerTest < ActionController::TestCase
|
|
|
|
fixtures :all
|
|
|
|
|
|
|
|
def test_issues_should_not_be_case_sensitive
|
|
|
|
get :issues, :project_id => 'ecookbook', :q => 'ReCiPe'
|
|
|
|
assert_response :success
|
|
|
|
assert_not_nil assigns(:issues)
|
|
|
|
assert assigns(:issues).detect {|issue| issue.subject.match /recipe/}
|
|
|
|
end
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-08-17 19:03:58 +04:00
|
|
|
def test_issues_should_return_issue_with_given_id
|
|
|
|
get :issues, :project_id => 'subproject1', :q => '13'
|
|
|
|
assert_response :success
|
|
|
|
assert_not_nil assigns(:issues)
|
|
|
|
assert assigns(:issues).include?(Issue.find(13))
|
|
|
|
end
|
2011-03-14 03:11:04 +03:00
|
|
|
|
|
|
|
test 'should return issues matching a given id' do
|
|
|
|
@project = Project.find('subproject1')
|
|
|
|
@issue_21 = Issue.generate_for_project!(@project, :id => 21)
|
2011-05-04 21:01:15 +04:00
|
|
|
@issue_2101 = Issue.generate_for_project!(@project, :id => 2101)
|
|
|
|
@issue_2102 = Issue.generate_for_project!(@project, :id => 2102)
|
|
|
|
@issue_with_subject = Issue.generate_for_project!(@project, :subject => 'This has 21 in the subject')
|
2011-03-14 03:11:04 +03:00
|
|
|
|
2011-05-04 21:01:15 +04:00
|
|
|
get :issues, :project_id => @project.id, :q => '21'
|
2011-03-14 03:11:04 +03:00
|
|
|
|
|
|
|
assert_response :success
|
|
|
|
assert_not_nil assigns(:issues)
|
|
|
|
assert assigns(:issues).include?(@issue_21)
|
2011-05-04 21:01:15 +04:00
|
|
|
assert assigns(:issues).include?(@issue_2101)
|
|
|
|
assert assigns(:issues).include?(@issue_2102)
|
2011-03-14 03:11:04 +03:00
|
|
|
assert assigns(:issues).include?(@issue_with_subject)
|
2011-05-04 21:01:15 +04:00
|
|
|
assert_equal assigns(:issues).size, assigns(:issues).uniq.size, "Issues list includes duplicates"
|
2011-03-14 03:11:04 +03:00
|
|
|
end
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-12-12 19:04:28 +03:00
|
|
|
def test_auto_complete_with_scope_all_and_cross_project_relations
|
|
|
|
Setting.cross_project_issue_relations = '1'
|
|
|
|
get :issues, :project_id => 'ecookbook', :q => '13', :scope => 'all'
|
|
|
|
assert_response :success
|
|
|
|
assert_not_nil assigns(:issues)
|
|
|
|
assert assigns(:issues).include?(Issue.find(13))
|
|
|
|
end
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-12-12 19:04:28 +03:00
|
|
|
def test_auto_complete_with_scope_all_without_cross_project_relations
|
|
|
|
Setting.cross_project_issue_relations = '0'
|
|
|
|
get :issues, :project_id => 'ecookbook', :q => '13', :scope => 'all'
|
|
|
|
assert_response :success
|
2010-12-12 19:06:43 +03:00
|
|
|
assert_equal [], assigns(:issues)
|
2010-12-12 19:04:28 +03:00
|
|
|
end
|
2010-12-04 00:59:23 +03:00
|
|
|
|
|
|
|
context "GET :users" do
|
|
|
|
setup do
|
|
|
|
@login = User.generate!(:login => 'Acomplete')
|
|
|
|
@firstname = User.generate!(:firstname => 'Complete')
|
|
|
|
@lastname = User.generate!(:lastname => 'Complete')
|
|
|
|
@none = User.generate!(:login => 'hello', :firstname => 'ABC', :lastname => 'DEF')
|
|
|
|
@inactive = User.generate!(:firstname => 'Complete', :status => User::STATUS_LOCKED)
|
|
|
|
end
|
2010-12-04 01:08:52 +03:00
|
|
|
|
|
|
|
context "with no restrictions" do
|
|
|
|
setup do
|
|
|
|
get :users, :q => 'complete'
|
|
|
|
end
|
2012-01-18 22:26:03 +04:00
|
|
|
|
2010-12-04 01:08:52 +03:00
|
|
|
should_respond_with :success
|
2012-01-18 22:26:03 +04:00
|
|
|
|
2010-12-04 01:08:52 +03:00
|
|
|
should "render a list of matching users in checkboxes" do
|
|
|
|
assert_select "input[type=checkbox][value=?]", @login.id
|
|
|
|
assert_select "input[type=checkbox][value=?]", @firstname.id
|
|
|
|
assert_select "input[type=checkbox][value=?]", @lastname.id
|
|
|
|
assert_select "input[type=checkbox][value=?]", @none.id, :count => 0
|
|
|
|
end
|
2012-01-18 22:26:03 +04:00
|
|
|
|
2010-12-04 01:08:52 +03:00
|
|
|
should "only show active users" do
|
|
|
|
assert_select "input[type=checkbox][value=?]", @inactive.id, :count => 0
|
|
|
|
end
|
2010-12-04 00:59:23 +03:00
|
|
|
end
|
2010-12-04 01:08:52 +03:00
|
|
|
|
2011-04-19 23:03:55 +04:00
|
|
|
context "including groups" do
|
|
|
|
setup do
|
|
|
|
@group = Group.generate(:lastname => 'Complete Group').reload
|
|
|
|
get :users, :q => 'complete', :include_groups => true
|
|
|
|
end
|
2012-01-18 22:26:03 +04:00
|
|
|
|
2011-04-19 23:03:55 +04:00
|
|
|
should_respond_with :success
|
2012-01-18 22:26:03 +04:00
|
|
|
|
2011-04-19 23:03:55 +04:00
|
|
|
should "include matching groups" do
|
|
|
|
assert_select "input[type=checkbox][value=?]", @group.id
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2010-12-04 01:08:52 +03:00
|
|
|
context "restrict by removing group members" do
|
|
|
|
setup do
|
|
|
|
@group = Group.first
|
|
|
|
@group.users << @login
|
|
|
|
@group.users << @firstname
|
|
|
|
get :users, :q => 'complete', :remove_group_members => @group.id
|
|
|
|
end
|
2012-01-18 22:26:03 +04:00
|
|
|
|
2010-12-04 01:08:52 +03:00
|
|
|
should_respond_with :success
|
2012-01-18 22:26:03 +04:00
|
|
|
|
2010-12-04 01:08:52 +03:00
|
|
|
should "not include existing members of the Group" do
|
|
|
|
assert_select "input[type=checkbox][value=?]", @lastname.id
|
|
|
|
|
|
|
|
assert_select "input[type=checkbox][value=?]", @login.id, :count => 0
|
|
|
|
assert_select "input[type=checkbox][value=?]", @firstname.id, :count => 0
|
|
|
|
end
|
2010-12-04 00:59:23 +03:00
|
|
|
end
|
2012-01-18 22:26:03 +04:00
|
|
|
|
2010-12-04 01:56:29 +03:00
|
|
|
context "restrict by removing issue watchers" do
|
|
|
|
setup do
|
|
|
|
@issue = Issue.find(2)
|
|
|
|
@issue.add_watcher(@login)
|
|
|
|
@issue.add_watcher(@firstname)
|
|
|
|
get :users, :q => 'complete', :remove_watchers => @issue.id, :klass => 'Issue'
|
|
|
|
end
|
2012-01-18 22:26:03 +04:00
|
|
|
|
2010-12-04 01:56:29 +03:00
|
|
|
should_respond_with :success
|
2012-01-18 22:26:03 +04:00
|
|
|
|
2010-12-04 01:56:29 +03:00
|
|
|
should "not include existing watchers" do
|
|
|
|
assert_select "input[type=checkbox][value=?]", @lastname.id
|
|
|
|
|
|
|
|
assert_select "input[type=checkbox][value=?]", @login.id, :count => 0
|
|
|
|
assert_select "input[type=checkbox][value=?]", @firstname.id, :count => 0
|
|
|
|
end
|
|
|
|
end
|
2010-12-04 00:59:23 +03:00
|
|
|
end
|
2009-10-20 23:28:07 +04:00
|
|
|
|
|
|
|
context "POST to #projects" do
|
|
|
|
setup do
|
|
|
|
# Clear out some fixtures
|
|
|
|
Project.delete_all
|
|
|
|
ProjectCustomField.delete_all
|
|
|
|
end
|
|
|
|
|
|
|
|
should 'require admin' do
|
|
|
|
@request.session[:user_id] = 2
|
|
|
|
post :projects, {}
|
|
|
|
|
|
|
|
assert_response 403
|
|
|
|
end
|
2012-01-18 22:26:03 +04:00
|
|
|
|
2009-10-20 23:28:07 +04:00
|
|
|
context 'with a valid search' do
|
|
|
|
setup do
|
|
|
|
@user = User.generate_with_protected!
|
|
|
|
@projects = [
|
|
|
|
Project.generate!(:name => "Test"),
|
|
|
|
Project.generate!(:name => "This is a Test")
|
|
|
|
]
|
|
|
|
Project.generate!(:name => "No match")
|
2012-01-18 22:26:03 +04:00
|
|
|
|
2009-10-20 23:28:07 +04:00
|
|
|
@request.session[:user_id] = 1
|
|
|
|
post :projects, {
|
|
|
|
:id => @user.id,
|
|
|
|
:q => 'TeST'
|
|
|
|
}
|
2012-01-18 22:26:03 +04:00
|
|
|
|
2009-10-20 23:28:07 +04:00
|
|
|
end
|
2012-01-18 22:26:03 +04:00
|
|
|
|
2009-10-20 23:28:07 +04:00
|
|
|
should_assign_to(:principal) { @user }
|
|
|
|
should_assign_to(:projects) { @projects }
|
|
|
|
should_render_template :projects
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with an invalid search' do
|
|
|
|
setup do
|
|
|
|
@user = User.generate_with_protected!
|
|
|
|
Project.generate!(:name => "Test")
|
2012-01-18 22:26:03 +04:00
|
|
|
|
2009-10-20 23:28:07 +04:00
|
|
|
@request.session[:user_id] = 1
|
|
|
|
post :projects, {
|
|
|
|
:id => @user.id,
|
|
|
|
:q => 'nothing'
|
|
|
|
}
|
2012-01-18 22:26:03 +04:00
|
|
|
|
2009-10-20 23:28:07 +04:00
|
|
|
end
|
|
|
|
should_assign_to(:principal) { @user }
|
|
|
|
should_assign_to(:projects) { [] }
|
|
|
|
should_render_template :projects
|
2012-01-18 22:26:03 +04:00
|
|
|
|
2009-10-20 23:28:07 +04:00
|
|
|
end
|
|
|
|
end
|
2010-08-17 19:03:58 +04:00
|
|
|
end
|