On Fri, Sep 12, 2008 at 5:20 AM, Juanma Cervera <[EMAIL PROTECTED]> wrote: > Hello, > I am having trouble to mock the chaining of named_scope in the > controller, also I would like to use will_paginate. > > def index > @things = Thing.allowed_for(@current_user).available.paginate :page => > params[:page] > end > > ¿How to do it? > Thanks
You're basically just going to have to chain some stubs. @available = stub("available things", :paginate => [:thing]) @allowed_for = stub("allowed things", :available => @available) Thing.stub!(:allowed_for).and_return @allowed_for I would probably wrap that chain up in a method though, that expresses what you want and makes it easier to stub class Thing def self.available_to(user) allowed_for(user).available end end This makes your test become @available = stub("available things", :paginate => [:thing]) Thing.stub!(:available_to).and_return @available and to mock it, you can do Thing.should_receive(:allowed_for).with(mock_user).and_return @available Pat _______________________________________________ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users