Here is my spec:
describe Admin::ProductsController, “A visitor wants to access
@product = mock_model(Product, :traffic_available => 0)
it “should redirect to login path” do
In my application.rb, I have the following before filter:
@site = Site.find_by_domain_name(website_name)
if @site.traffic_available < 0
render :nothing => :true
As the test DB is empty and I don’t use fixtures, it won’t find any
site, therefore nil.traffic_available < 0 returns an error when running
I thought I could stub out the find_by_domain_name method to return a
cooperative object with a traffic_available value, but it didn’t work.
How can I do that correctly?
I have found a dirty workaround:
but I don’t find it acceptable. I am not going to stub out all methods
in my app, that’s nonsense.