spec/util_spec.rb in mongoid_search-0.3.0 vs spec/util_spec.rb in mongoid_search-0.3.1

- old
+ new

@@ -1,12 +1,22 @@ # encoding: utf-8 require File.expand_path(File.dirname(__FILE__) + '/spec_helper') describe Mongoid::Search::Util do + + before(:all) do + @default_proc = Mongoid::Search.stem_proc + end + + after(:all) do + Mongoid::Search.stem_proc = @default_proc + end + before do Mongoid::Search.stem_keywords = false Mongoid::Search.ignore_list = "" + Mongoid::Search.stem_proc = @default_proc end it "should return an empty array if no text is passed" do Mongoid::Search::Util.normalize_keywords("").should == [] end @@ -36,9 +46,16 @@ end it "should stem keywords" do Mongoid::Search.stem_keywords = true Mongoid::Search::Util.normalize_keywords("A runner running and eating").should == ["runner", "run", "and", "eat"] + end + + it "should stem keywords using a custom proc" do + Mongoid::Search.stem_keywords = true + Mongoid::Search.stem_proc = lambda { |word| word.upcase } + + Mongoid::Search::Util.normalize_keywords("A runner running and eating").should == ["RUNNER", "RUNNING", "AND", "EATING"] end it "should ignore keywords from ignore list" do Mongoid::Search.stem_keywords = true Mongoid::Search.ignore_list = YAML.load(File.open(File.dirname(__FILE__) + '/config/ignorelist.yml'))["ignorelist"]