Stubbing Chained Queries in Rails 3 and Rspec
I'm trying to test a scope I have that is based upon a chain of other scopes. ("public_stream" below). scope :public, where("entries.privacy = 'public'") scope :completed, where("entries.observation <> '' AND entries.application <> ''") scope :without_user, lambda { |user| where("entries.user_id <> ?", user.id) } scope :public_stream, lambda { |user| public.completed.without_user(user).limit(15) } Using a test like this: it "should use the public, without_user, completed, and limit scopes" do @chain = mock(ActiveRecord::Relation) Entry.should_receive(:public).and_return(@chain) @chain.should