before:
Finished in 6.38 seconds after: Finished in 1.52 seconds
This commit is contained in:
parent
fd035cf777
commit
aea988a447
|
@ -21,63 +21,53 @@ describe UserSearch do
|
||||||
Fabricate :post, user: user6, topic: topic
|
Fabricate :post, user: user6, topic: topic
|
||||||
end
|
end
|
||||||
|
|
||||||
context "all user search" do
|
# this is a seriously expensive integration test, re-creating this entire test db is too expensive
|
||||||
it "searches the user's name" do
|
# reuse
|
||||||
results = UserSearch.search user1.name.split(" ").first
|
it "operates correctly" do
|
||||||
results.size.should == 1
|
# normal search
|
||||||
results.first.should == user1
|
results = UserSearch.search user1.name.split(" ").first
|
||||||
end
|
results.size.should == 1
|
||||||
|
results.first.should == user1
|
||||||
|
|
||||||
it "searches the user's name case insensitive" do
|
# lower case
|
||||||
results = UserSearch.search user1.name.split(" ").first.downcase
|
results = UserSearch.search user1.name.split(" ").first.downcase
|
||||||
results.size.should == 1
|
results.size.should == 1
|
||||||
results.first.should == user1
|
results.first.should == user1
|
||||||
end
|
|
||||||
|
|
||||||
it "searches the user's username" do
|
# username
|
||||||
results = UserSearch.search user4.username
|
results = UserSearch.search user4.username
|
||||||
results.size.should == 1
|
results.size.should == 1
|
||||||
results.first.should == user4
|
results.first.should == user4
|
||||||
end
|
|
||||||
|
|
||||||
it "searches the user's username case insensitive" do
|
# case insensitive
|
||||||
results = UserSearch.search user4.username.upcase
|
results = UserSearch.search user4.username.upcase
|
||||||
results.size.should == 1
|
results.size.should == 1
|
||||||
results.first.should == user4
|
results.first.should == user4
|
||||||
end
|
|
||||||
|
|
||||||
it "searches the user's username substring" do
|
# substrings
|
||||||
results = UserSearch.search "mr"
|
results = UserSearch.search "mr"
|
||||||
results.size.should == 6
|
results.size.should == 6
|
||||||
|
|
||||||
results = UserSearch.search "mrb"
|
results = UserSearch.search "mrb"
|
||||||
results.size.should == 3
|
results.size.should == 3
|
||||||
end
|
|
||||||
|
|
||||||
it "searches the user's username substring upper case" do
|
|
||||||
results = UserSearch.search "MR"
|
|
||||||
results.size.should == 6
|
|
||||||
|
|
||||||
results = UserSearch.search "MRB"
|
results = UserSearch.search "MR"
|
||||||
results.size.should == 3
|
results.size.should == 6
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "sort order respects users with posts on the topic" do
|
results = UserSearch.search "MRB"
|
||||||
it "Mr. Blond is first when searching his topic" do
|
results.size.should == 3
|
||||||
results = UserSearch.search "mrb", topic.id
|
|
||||||
results.first.should == user1
|
|
||||||
end
|
|
||||||
|
|
||||||
it "Mr. Blue is first when searching his topic" do
|
# topic priority
|
||||||
results = UserSearch.search "mrb", topic2.id
|
results = UserSearch.search "mrb", topic.id
|
||||||
results.first.should == user2
|
results.first.should == user1
|
||||||
end
|
|
||||||
|
|
||||||
it "Mr. Brown is first when searching his topic" do
|
|
||||||
results = UserSearch.search "mrb", topic3.id
|
results = UserSearch.search "mrb", topic2.id
|
||||||
results.first.should == user5
|
results.first.should == user2
|
||||||
end
|
|
||||||
|
results = UserSearch.search "mrb", topic3.id
|
||||||
|
results.first.should == user5
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue