嵌套资源:控制器规范不会调用所需操作

时间:2017-11-01 17:18:53

标签: ruby-on-rails controller nested specifications

我有一个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操作中,但这不会被调用。那么我的规格出了什么问题?

1 个答案:

答案 0 :(得分:2)

问题是我没有登录:

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