T开发者_运维问答his is in my controller
@business = @current_user.businesses.new(params[:business])
@businesses
is an array of business
objects and I'm unsure of how to mock this cascade of calls.
Here is one way to do it. The 'businesses' part of it is an association proxy. So usually mock it like this:
business = Business.new
businesses_proxy = mock('business association proxy', :new => business)
@current_user.should_receive(:businesses).and_return(businesses_proxy)
or more explicit
business = Business.new
businesses_proxy = mock('business association proxy')
businesses_proxy.should_recieve(:new).and_return(business)
@current_user.should_receive(:businesses).and_return(businesses_proxy)
精彩评论