这是我的控制器
@business = @current_user.businesses.new(params[:business])
@businesses
是一个business
个对象的数组,我不确定如何模拟这个级联的调用。
答案 0 :(得分:2)
这是一种方法。它的“业务”部分是一个关联代理。所以通常嘲笑它:
business = Business.new
businesses_proxy = mock('business association proxy', :new => business)
@current_user.should_receive(:businesses).and_return(businesses_proxy)
或更明确的
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)