Skip to content

Commit

Permalink
Tweak alias_scope documentation, add a spec for coverage, and allow a…
Browse files Browse the repository at this point in the history
…liasing scopes by symbol that have arguments.
  • Loading branch information
johndouthat committed Mar 23, 2012
1 parent 613a527 commit 0967c91
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/searchlogic/named_scopes/alias_scope.rb
Expand Up @@ -8,7 +8,7 @@ module AliasScope
# or represents a named scope procedure. Ex:
#
# class User
# def teenager
# def self.teenager
# age_gte(13).age_lte(19)
# end
# end
Expand Down Expand Up @@ -37,7 +37,7 @@ def alias_scope(name, options = nil)
define_method name do |*args|
case options
when Symbol
send(options)
send(options, *args)
else
options.call(*args)
end
Expand Down
7 changes: 7 additions & 0 deletions spec/searchlogic/named_scopes/alias_scope_spec.rb
Expand Up @@ -11,6 +11,13 @@
User.username_has("bjohnson").all.should == User.find_all_by_username("bjohnson")
end

it "should allow alias scopes with symbols" do
User.alias_scope :login_has, :username_has
User.create(:username => "bjohnson")
User.create(:username => "thunt")
User.login_has("bjohnson").all.should == User.find_all_by_username("bjohnson")
end

it "should allow alias scopes from the search object" do
search = User.search
search.username_has = "bjohnson"
Expand Down

0 comments on commit 0967c91

Please sign in to comment.