find_all_by returning nil with rspec

J

John Mark

The statement
products = find_all_by_category_id(category_id)
in the Product model is returning nil with rspec.
I am expecting it to to return the stub that I provided it with. It does
not also work with fixtures.


Product model

def self.find_all_meeting_some_criteria_for_category(category_id)
products = find_all_by_category_id(category_id)
products.each do |product|
....
end
end

Product spec

it "should find products given a category" do
product = mock_model(Product, :id => 1, :category_id => 1)
Product.stub(!find_all_by_category_id).with(anything()).and_return([product])
Product.should_receive:)find_all_meeting_some_criteria_for_category).with(product.category_id)
end
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top