Permalink
Browse files

Adding tests for the LikeQuery scope

  • Loading branch information...
1 parent 56d0fd2 commit effb60dcc13513c4b3b3e0c37e11cf7453ecdbac @towski towski committed Jul 30, 2008
Showing with 59 additions and 0 deletions.
  1. +59 −0 spec/like_query_scope_spec.rb
@@ -0,0 +1,59 @@
+require File.dirname(__FILE__) + '/spec_helper'
+
+module CanSearch
+ describe "all LikeQuery Scopes", :shared => true do
+ include CanSearchSpecHelper
+
+ it "instantiates like query scope" do
+ Record.search_scopes[@scope.name].should == @scope
+ end
+
+ it "creates named_scope" do
+ Record.scopes[@scope.named_scope].should_not be_nil
+ end
+
+ it "filters records by full name" do
+ compare_records Record.search(:name => "day"), [:day]
+ end
+
+ it "filters records by name that doesn't match" do
+ compare_records Record.search(:name => "aye"), []
+ end
+ end
+
+ describe LikeQueryScope do
+ describe "(LikeQuery Scope with no options)" do
+ before do
+ Record.can_search do
+ scoped_by :name, :scope => :like
+ end
+ @scope = LikeQueryScope.new(Record, :name, :attribute => :name, :scope => :like_query, :named_scope => :like_name)
+ end
+
+ it "filters records by partial name" do
+ compare_records Record.search(:name => "ay"), [:day]
+ end
+
+ it "filters multiple records by partial name" do
+ compare_records Record.search(:name => "biweek"), [:biweek_1, :biweek_2]
+ end
+
+ it_should_behave_like "all LikeQuery Scopes"
+ end
+
+ describe "(LikeQuery Scope with a format option for exact match)" do
+ before do
+ Record.can_search do
+ scoped_by :name, :scope => :like, :format => "%s"
+ end
+ @scope = LikeQueryScope.new(Record, :name, :attribute => :name, :scope => :like_query, :named_scope => :like_name, :format => "%s")
+ end
+
+ it "filters records using the format" do
+ compare_records Record.search(:name => "ay"), []
+ end
+
+ it_should_behave_like "all LikeQuery Scopes"
+ end
+ end
+end

0 comments on commit effb60d

Please sign in to comment.