1
当我测试控制器我有这样的代码:惨惨,RSpec的+成株没有PARAMS
describe "GET 'show'" do
let!(:comment) { build_stubbed(:comment) }
before(:each) { Project.stubs(:find).returns(project) }
it "render show template" do
get 'show', id: project.id
should render_template('show')
end
it "create a new comment" do
Comment.expects(:new).returns(comment)
get 'show', id: project.id
end
end
我的问题是这样的:我要传递一个ID使用方法load_and_authorize_resource原因德拉ligne 139 dans ce code: https://github.com/ryanb/cancan/blob/2.0/lib/cancan/controller_resource.rb它检查参数中是否有ID。
如何解决这个问题?
谢谢!
编辑: 换句话说:变量@project不是由方法load_and_authorize_resource调用,因为没有ID并且可以检查是否有id来查找模型。
没有抱歉,问题是变量@project不是由load_and_authorize_resource方法调用,它应该是这样。 – Dougui
你现在变得更没有意义了。什么'@ project'变量,你没有参考你的文章中的任何内容?你也不会在任何地方声明'project'变量。 – sevenseacat
对不起,这只是一个摘录。 'code'project'code'由let声明,'@project'变量用在我的视图中。 – Dougui