Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nested resource: controller spec doesn't call the wanted action

I have a ReportsController, nested in ProjectsController, with a #show method:

def show
  # Some stuff

  do_something(@report)
end

Routes:

resources :projects do
  resources :reports
end

I need to test 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 within the #show action, but this doesn't get called. So what's wrong with my spec?

like image 728
Joshua Muheim Avatar asked Oct 29 '22 23:10

Joshua Muheim


1 Answers

The problem was that I wasn't logged in:

  before do
    @user = create :user, :admin
    sign_in_as @user
  end
like image 120
Joshua Muheim Avatar answered Nov 15 '22 13:11

Joshua Muheim