Created
October 4, 2009 03:52
-
-
Save royw/201103 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
require 'mongomapper' | |
require 'spec' | |
MongoMapper.connection = XGen::Mongo::Driver::Connection.new('localhost') | |
MongoMapper.database = 'tmp' | |
class Person | |
include MongoMapper::Document | |
key :title, String | |
key :_keywords, Array | |
before_save do |record| | |
record._keywords = record.title.split(' ').uniq | |
end | |
end | |
describe "testing text search" do | |
before :each do | |
Person.collection.clear | |
person = Person.create :title => 'Something Wicked This Way Comes' | |
end | |
it "should be searchable by whole words" do | |
Person.first(:conditions => {:_keywords => 'Wicked'}).should_not be_nil | |
Person.first(:conditions => {:_keywords => 'Foobar'}).should be_nil | |
end | |
it "should be searchable by array of words" do | |
Person.first(:conditions => {:_keywords => ['Foobar', 'Wicked']}).should_not be_nil | |
Person.first(:conditions => {:_keywords => ['Foo', 'Bar']}).should be_nil | |
end | |
it "should be searchable by regex" do | |
Person.first(:conditions => {:_keywords => /wick/i}).should_not be_nil | |
Person.first(:conditions => {:_keywords => /foo/i}).should be_nil | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment