On Monday 20 April 2009, Zach Dennis wrote: > On Sun, Apr 19, 2009 at 6:41 PM, Michael Schuerig <[email protected]> wrote: [big snip]
> I think I am starting to understand what you're after. You want to
> ensure the scope defined in your query_scope configuration block in
> the controller is used to set the scope on the controller's model.
> Right?
Exactly.
> With the assumption that that is correct, I would probably refactor
> how your #query_scope method works. Right now you're implicitly going
> through a QueryScopeBuilder to get a RequestConditioner, in order to
> access the #find_options and #offset_limit behaviour on that
> RequestConditioner. I would make your controller deal with one
> object, perhaps a RequestToQueryTranslator. Your #query_scope method
> would come out looking like:
>
> def query_scope(options = {}, &config_block)
> model_class = extract_resource!(options)
> query = RequestToQueryTranslator.translate(controller.request,
> &config_block)
> around_filter(options) do |controller, action|
> controller.instance_variable_set(:@offset_limit,
> query.offset_limit) model_class.send(:with_scope, :find =>
> query.find_options, &action) end
> end
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.
> WDYT?
I've attached the involved files. I try to avoid doing that on mailing
lists, but we're going in circles otherwise.
In the meantime I've looked into rspec's message expectation in order to
add an expectation for a particular scope being set on an ActiveRecord
class. What I'd need to implement this is a way to get hold of the
partially mocked class. There may not be one.
Michael
--
Michael Schuerig
mailto:[email protected]
http://www.schuerig.de/michael/
query_scope.rb
Description: application/ruby
request_conditioner.rb
Description: application/ruby
request_conditioner_spec.rb
Description: application/ruby
_______________________________________________ rspec-users mailing list [email protected] http://rubyforge.org/mailman/listinfo/rspec-users
