context'when exception is ActiveRecord::StatementInvalid'do
let(:exception){ActiveRecord::StatementInvalid.new(sql:'SELECT "users".* FROM "users" WHERE "users"."id" = 1 AND "users"."foo" = $1')}
it'adds the normalized SQL query to payload'do
described_class.format!(exception,payload)
expect(payload['exception.sql']).toeq('SELECT "users".* FROM "users" WHERE "users"."id" = $2 AND "users"."foo" = $1')
end
end
context'when the ActiveRecord::StatementInvalid is wrapped in another exception'do
beforedo
allow(exception).toreceive(:cause).and_return(ActiveRecord::StatementInvalid.new(sql:'SELECT "users".* FROM "users" WHERE "users"."id" = 1 AND "users"."foo" = $1'))
end
it'adds the normalized SQL query to payload'do
described_class.format!(exception,payload)
expect(payload['exception.sql']).toeq('SELECT "users".* FROM "users" WHERE "users"."id" = $2 AND "users"."foo" = $1')
end
end
context'when the ActiveRecord::StatementInvalid is a bad query'do
let(:exception){ActiveRecord::StatementInvalid.new(sql:'SELECT SELECT FROM SELECT')}
it'adds the query as-is to payload'do
described_class.format!(exception,payload)
expect(payload['exception.sql']).toeq('SELECT SELECT FROM SELECT')