Created
November 9, 2009 11:31
-
-
Save joahking/229884 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
# this is an AR model class | |
named_scope :privates, :conditions => { :public => false } | |
named_scope :named_like, lambda { |name| { :conditions => "name LIKE '#{name}%'" }} | |
# we want to concatenate named_scopes at later points in code | |
def self.by_privacy_and_name(privates = false, name = nil) | |
# we want a named_scope to concatenate other namescopes afterwards | |
gs = if privates | |
self.privates # with named_scopes everything runs fine | |
else | |
self.all # here we won't get a NamedScope, instead it'll be an Array | |
end | |
if name | |
gs.named_like name # this blows with Array returned by AR.all | |
else | |
gs | |
end | |
end | |
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
NoMethodError in 'Group by_privacy_and_name search method should return all groups starting with letter if no privacy passed' | |
undefined method `named_like' for #<Array:0xb5951d4c> | |
/home/joahking/dev/rails/tucamon/app/models/group.rb:54:in `by_privacy_and_name' | |
./spec/models/group_spec.rb:62: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment