0
在我users_controller_spec.rb我把用rspec保存登錄用戶(current_user) - 如何使其工作?
@u = FactoryGirl.create(:user)
ApplicationController.should_receive(:current_user).at_least(:once).and_return(@u)
controller.stub :current_user => @u
,然後我想寫控制器的規格,顯示我,如果一個物體確實inaccesible對於不應該看到它的用戶 - 有退出require_ownership
功能在application_controller .rb使用var @current_user
來查看誰已登錄,但使用上面的方法我無法找到使用戶「登錄」。
什麼樣的規格?控制器? – apneadiving
yes,controller_specs ..例如測試「1)登錄2)'get:edit' 3)可以訪問它」,或者「1)不登錄2)get:edit,3)不能訪問它」 –
你的第2行應該達到什麼程度?只有'controller.stub'應該足以將'@ u'作爲登錄用戶。 – depa