>From a mocking / stubbing perspective, how is this different from
Article.all(:conditions => ['published_at <= ?', Time.now], :include =>
:comments)
?
i.e. in both cases wouldn't you do
class Article
def self.active_published
all :conditions => ['published_at <= ?', Time.now], :include => :comments
# where("published_at <= ?", Time.now).includes(:comments)
end
end
and mock the call to Article.active_published instead?
Pat
On Feb 22, 2010, at 3:07 PM, Rick DeNatale wrote:
> I thought that it might be worth starting a discussion about the best
> approaches to deal with spec'ing what's becoming more and more common
> in apps using active record.
>
> It started with named scopes, now we have arel, and the old find calls
> with parameters are being deprecated.
>
> When I watched Ryan Bate's latest opus
> http://railscasts.com/episodes/202-active-record-queries-in-rails-3
> this morning I decided it might be good to bring my concerns up.
>
> The problem of course is that we're going to get used to writing more
> code like this:
>
> Article.where("published_at <= ?", Time.now).includes(:comments)
>
>> From one aspect, I find all this very nice. It makes writing queries
> easier and much more readable.
>
> On the other hand these are the kind of "train wreck" violations of
> the "strong suggestion of Demeter" which makes mocking and stubbing
> difficult among other things.
>
> Thoughts?
>
> --
> Rick DeNatale
>
> Blog: http://talklikeaduck.denhaven2.com/
> Twitter: http://twitter.com/RickDeNatale
> WWR: http://www.workingwithrails.com/person/9021-rick-denatale
> LinkedIn: http://www.linkedin.com/in/rickdenatale
> _______________________________________________
> rspec-users mailing list
> [email protected]
> http://rubyforge.org/mailman/listinfo/rspec-users
_______________________________________________
rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users