[rspec-users] Controller spec: testing that scope is set

Michael Schuerig michael at schuerig.de
Tue Apr 21 04:02:29 EDT 2009

On Monday 20 April 2009, Zach Dennis wrote:
> > I don't agress. Both classes have distinct, although related
> > purposes. RequestCondition implements the translation from request
> > parameters to #find-options. QueryScope(Builder) fits it in with
> > ActionController and adds syntactic sugar. The former is easy to
> > spec, for the latter, I've been to lazy to figure out a good way.
> I'm just suggesting that RequestCondition and QueryScopeBuilder are
> encapsulated behind RequestToQueryTranslator, so your controller
> doesn't have to know about both of them. Your controller doesn't
> actually care about request conditioners and query scope builders. It
> only cares that it can translate a request to a query so it can be
> used to set the scope on the model.

That's already the case. Both of these classes are only internally used 
by module QueryScope, which is the only thing a controller sees:

class PeopleController < ApplicationController
  include QueryScope

  query_scope :only => :index do
    # Only allow to filter and order by the
    # virtual name attribute.
    # This attribute is mapped onto the real
    # firstname and lastname attributes.
    allow     :name
    condition :name =>
      "LOWER(firstname || ' ' || lastname) :op LOWER(?)"
    order     :name => "lastname :dir, firstname :dir"


Michael Schuerig
mailto:michael at schuerig.de

More information about the rspec-users mailing list