Matt
Matt

Reputation: 6320

No SQL logs from ActiveRecord with byebug in test mode

Byebug with ActiveRecord in Rails 6 is not logging as expected in my test environment.

When I run a test and use byebug to pause execution ActiveRecord is not logging queries to the console. For example, if I type Candidate.second I see no SQL output:

no output showing when I run Candidate.second

What I would like to see, and what I do see if I run the same query in my development environment within the rails console:

enter image description here

I've looked through documentation on both ActiveRecord and ByeBug but can't seem to solve this. Any help is appreciated!

Steps to reproduce

Throw a debugger statement into a controller, and run a test:

ActiveRecord is not logging queries into the console when using byebug. For example, if a run a test that hits a controller action:

class JobsController < ApplicationController
  # ...

  def show
    debugger
    Candidate.first # arbitrary query
    render json: @job
  end
end

From the terminal:

rails test test/controllers/jobs_controller.rb

Upvotes: 2

Views: 600

Answers (1)

Harsh Kumar
Harsh Kumar

Reputation: 366

ActiveRecord::Base.logger = Logger.new(STDOUT)

Not sure why it doesn't come by default or how to make it permanent. You have to enable rails logger in the byebug console as well.

Upvotes: 4

Related Questions