obsolete.ChilliProject/test/functional/search_controller_test.rb

163 lines
4.8 KiB
Ruby
Raw Normal View History

2011-10-29 16:19:11 +04:00
#-- encoding: UTF-8
#-- copyright
# ChiliProject is a project management system.
2011-05-30 22:52:25 +04:00
#
# Copyright (C) 2010-2011 the ChiliProject Team
2011-05-30 22:52:25 +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
#
# See doc/COPYRIGHT.rdoc for more details.
#++
require File.expand_path('../../test_helper', __FILE__)
require 'search_controller'
# Re-raise errors caught by the controller.
class SearchController; def rescue_action(e) raise e end; end
class SearchControllerTest < ActionController::TestCase
fixtures :projects, :enabled_modules, :roles, :users, :members, :member_roles,
:issues, :trackers, :issue_statuses,
:custom_fields, :custom_values,
:repositories, :changesets
2011-05-30 22:52:25 +04:00
def setup
@controller = SearchController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
User.current = nil
end
2011-05-30 22:52:25 +04:00
def test_search_for_projects
get :index
assert_response :success
assert_template 'index'
get :index, :q => "cook"
assert_response :success
assert_template 'index'
assert assigns(:results).include?(Project.find(1))
end
2011-05-30 22:52:25 +04:00
def test_search_all_projects
get :index, :q => 'recipe subproject commit', :submit => 'Search'
assert_response :success
assert_template 'index'
2011-05-30 22:52:25 +04:00
assert assigns(:results).include?(Issue.find(2))
assert assigns(:results).include?(Issue.find(5))
assert assigns(:results).include?(Changeset.find(101))
assert_select "dt.issue-edit" do
assert_select "a", :text => /Add ingredients categories/
end
2011-05-30 22:52:25 +04:00
assert assigns(:results_by_type).is_a?(Hash)
assert_equal 5, assigns(:results_by_type)['changesets']
assert_tag :a, :content => 'Changesets (5)'
end
2011-05-30 22:52:25 +04:00
def test_search_issues
get :index, :q => 'issue', :issues => 1
assert_response :success
assert_template 'index'
assert assigns(:results).include?(Issue.find(8))
assert assigns(:results).include?(Issue.find(5))
assert_select "dt.issue" do
assert_select "a", :text => /Closed/
end
end
2011-05-30 22:52:25 +04:00
def test_search_project_and_subprojects
get :index, :id => 1, :q => 'recipe subproject', :scope => 'subprojects', :submit => 'Search'
assert_response :success
assert_template 'index'
assert assigns(:results).include?(Issue.find(1))
assert assigns(:results).include?(Issue.find(5))
end
def test_search_without_searchable_custom_fields
CustomField.update_all "searchable = #{ActiveRecord::Base.connection.quoted_false}"
2011-05-30 22:52:25 +04:00
get :index, :id => 1
assert_response :success
assert_template 'index'
assert_not_nil assigns(:project)
2011-05-30 22:52:25 +04:00
get :index, :id => 1, :q => "can"
assert_response :success
assert_template 'index'
end
2011-05-30 22:52:25 +04:00
def test_search_with_searchable_custom_fields
get :index, :id => 1, :q => "stringforcustomfield"
assert_response :success
results = assigns(:results)
assert_not_nil results
assert_equal 1, results.size
assert results.include?(Issue.find(7))
end
2011-05-30 22:52:25 +04:00
def test_search_all_words
# 'all words' is on by default
get :index, :id => 1, :q => 'recipe updating saving'
results = assigns(:results)
assert_not_nil results
assert_equal 1, results.size
assert results.include?(Issue.find(3))
end
2011-05-30 22:52:25 +04:00
def test_search_one_of_the_words
get :index, :id => 1, :q => 'recipe updating saving', :submit => 'Search'
results = assigns(:results)
assert_not_nil results
assert_equal 3, results.size
assert results.include?(Issue.find(3))
end
def test_search_titles_only_without_result
get :index, :id => 1, :q => 'recipe updating saving', :all_words => '1', :titles_only => '1', :submit => 'Search'
results = assigns(:results)
assert_not_nil results
assert_equal 0, results.size
end
def test_search_titles_only
get :index, :id => 1, :q => 'recipe', :titles_only => '1', :submit => 'Search'
results = assigns(:results)
assert_not_nil results
assert_equal 2, results.size
end
2011-05-30 22:52:25 +04:00
def test_search_with_invalid_project_id
get :index, :id => 195, :q => 'recipe'
assert_response 404
assert_nil assigns(:results)
end
def test_quick_jump_to_issue
# issue of a public project
get :index, :q => "3"
assert_redirected_to '/issues/3'
2011-05-30 22:52:25 +04:00
# issue of a private project
get :index, :q => "4"
assert_response :success
assert_template 'index'
end
def test_large_integer
get :index, :q => '4615713488'
assert_response :success
assert_template 'index'
end
2011-05-30 22:52:25 +04:00
def test_tokens_with_quotes
get :index, :id => 1, :q => '"good bye" hello "bye bye"'
assert_equal ["good bye", "hello", "bye bye"], assigns(:tokens)
end
end