Nested Resource: Controller Specification Does Not Cause Required Action

I have a ReportsController nested in ProjectsController using the #show method:

 def show # Some stuff do_something(@report) end 

Routes

 resources :projects do resources :reports end 

I need to check that the do_something method is called:

  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 

I placed binding.pry in the #show action, but this is not called. So what about my specification?

+5
source share
1 answer

The problem was that I was not registered:

  before do @user = create :user, :admin sign_in_as @user end 
+2
source

Source: https://habr.com/ru/post/1273062/


All Articles