[rspec-users] Mocking the dynamic composition of named_scopes.

Juanma Cervera lists at ruby-forum.com
Sat Sep 13 06:24:28 EDT 2008


I am still learning to specify named_scopes, having some troubles and
needing some help.

This is the situation.
I have already spec two or three named_scopes independently.
but now, I want to spec a function that combines somes of these
named_scopes dynamically.
Something like this

 class Thing

  named_scope foo, .....
  named_scope bar, ....
  named_scope baz, ....

  def complex_query(condition1, condition2, condition3)
    scope = Thing.scoped({})
    scope = scope.scoped( Thing.foo.proxy_options ) if condition1
    scope = scope.scoped( Thing.bar.proxy_options ) if condition2
    scope = scope.scoped( Thing.baz.proxy_options ) if condition3

 I don't know if there is a better way to implement it, but it works.
 The problem is with the specification. I don't know how to do it with
 I have already spec and test the named_scopes against the database and
 that this time I have to test only the chaining and not the result.

 Juanma Cervera
Posted via http://www.ruby-forum.com/.

More information about the rspec-users mailing list