Skip to content

Instantly share code, notes, and snippets.

@daxadax
Created October 30, 2015 13:54
Show Gist options
  • Select an option

  • Save daxadax/c0e8b6bea0a17c76ef97 to your computer and use it in GitHub Desktop.

Select an option

Save daxadax/c0e8b6bea0a17c76ef97 to your computer and use it in GitHub Desktop.

Revisions

  1. daxadax created this gist Oct 30, 2015.
    13 changes: 13 additions & 0 deletions testing database queries in rails
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    describe 'database performance' do
    before { @sql_calls = 0 }
    after { ActiveSupport::Notifications.unsubscribe(@subscription) }

    it 'makes a minimum of db queries' do
    @subscription = ActiveSupport::Notifications.subscribe('sql.active_record') do |event|
    @sql_calls += 1
    end

    get :index, attributes.merge(format: :json)
    expect(@sql_calls).to be < 25
    end
    end