Created
January 22, 2010 08:35
-
-
Save morgoth/283620 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: ASCII-8BIT | |
require 'test_helper' | |
class SearchTest < ActiveSupport::TestCase | |
self.use_transactional_fixtures = false | |
def self.startup | |
start_sphinx do | |
us_country = Factory(:us_country) | |
jp_country = Factory(:country, :code => "jp") | |
Factory(:school, :name => "Harward Univ", :country => us_country) | |
Factory(:school, :name => "Princeton Univ", :country => us_country) | |
Factory(:school, :name => "Kyoto Univ", :country => jp_country) | |
Factory(:school, :name => "Politechnika Śląska", :country => Factory(:pl_country), :city => 'Gliwice') | |
Factory(:school, :state => "unverified") | |
Factory(:confirmed_user, :login => 'batman') | |
Factory(:user, :state => 'unconfirmed') | |
@user1 = Factory(:confirmed_user, :login => 'gregor', :first_name => 'Grzegorz', :last_name => "Męczywór") | |
@user2 = Factory(:confirmed_user, :login => 'johndoe', :first_name => 'Johnny', :last_name => 'Doe') | |
@user1.name_privacy = 'public' | |
@user2.name_privacy = 'private' | |
@user1.save! | |
@user2.save! | |
end | |
end | |
def self.shutdown | |
stop_sphinx | |
end | |
context "sphinx search for" do | |
context "user" do | |
should "find batman" do | |
users = User.search "baatman" | |
assert_equal 0, users.size | |
users = User.search 'batman' | |
assert_equal 1, users.size | |
assert_equal 'batman', users.first.login | |
end | |
should "find gregor by name Grzegorz when name privacy is public" do | |
users = User.search "Grzegorz" | |
assert_equal 'gregor', users.first.login | |
assert_equal 1, users.size | |
end | |
should "not find johndoe by name Johnny when name privacy is private" do | |
users = User.search "Johnny" | |
assert_equal 0, users.size | |
end | |
should "find user Męczywór by search word meczywor - ignore polish letters" do | |
users = User.search "meczywor" | |
assert_equal "Męczywór", users.first.last_name | |
assert_equal 1, users.size | |
end | |
should "not find unconfirmed users" do | |
users = User.search "" | |
assert_equal 0, users.count { |u| u.state == "unconfirmed" } | |
end | |
end | |
context "school" do | |
should "find 3 schools by univ" do | |
schools = School.search "univ" | |
assert_equal 3, schools.size | |
end | |
should "find Harward by name ha" do | |
schools = School.search "ha" | |
assert_equal 1, schools.size | |
assert_equal "Harward Univ", schools.first.name | |
end | |
should "find 2 schools by letter p" do | |
schools = School.search "p" | |
assert_equal 2, schools.size | |
assert_equal 1, schools.count { |s| s.name == "Princeton Univ" } | |
end | |
should "find Politechnika Śląska by name slaska" do | |
schools = School.search "slaska" | |
assert_equal 1, schools.size | |
assert_equal "Politechnika Śląska", schools.first.name | |
end | |
should "find Politechnika Śląska by name po sl" do | |
schools = School.search "po sl" | |
assert_equal 1, schools.size | |
assert_equal "Politechnika Śląska", schools.first.name | |
end | |
should "not find unverified school" do | |
schools = School.search "" | |
assert_equal 0, schools.count { |s| s.state == "unverified" } | |
end | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ENV["RAILS_ENV"] = "test" | |
require File.expand_path(File.dirname(__FILE__) + "/../config/environment") | |
require 'test_help' | |
DatabaseCleaner.strategy = :truncation | |
class ActiveSupport::TestCase | |
include RR::Adapters::TestUnit | |
self.use_transactional_fixtures = true | |
self.use_instantiated_fixtures = false | |
def self.start_sphinx | |
DatabaseCleaner.clean | |
yield | |
ThinkingSphinx::Test.init | |
ThinkingSphinx::Test.start | |
end | |
def self.stop_sphinx | |
ThinkingSphinx::Test.stop | |
DatabaseCleaner.clean | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment