gpt4 book ai didi

ruby-on-rails - 嵌套资源 : controller spec doesn't call the wanted action

转载 作者:行者123 更新时间:2023-12-04 21:05:36 24 4
gpt4 key购买 nike

我有一个 ReportsController ,嵌套在 ProjectsController ,带有 #show方法:

def show
# Some stuff

do_something(@report)
end

路线:
resources :projects do
resources :reports
end

我需要测试 do_something方法被称为:
  it 'calls do_something' do
expect(controller).to receive(:do_something)

project = create :project
report = create :report, project: project

get :show, params: {project_id: project.id, id: report.id}
end

我放置了 binding.pry#show行动,但这不会被调用。那么我的规范有什么问题?

最佳答案

问题是我没有登录:

  before do
@user = create :user, :admin
sign_in_as @user
end

关于ruby-on-rails - 嵌套资源 : controller spec doesn't call the wanted action,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47060323/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com