refactored error aggregation
This commit is contained in:
@ -28,7 +28,7 @@ class ErrorsController < ApplicationController
|
||||
|
||||
def index
|
||||
authorize!
|
||||
@errors = Error.for_execution_environment(@execution_environment)
|
||||
@errors = Error.for_execution_environment(@execution_environment).grouped_by_message
|
||||
end
|
||||
|
||||
def set_execution_environment
|
||||
|
@ -1,9 +1,8 @@
|
||||
class Error < ActiveRecord::Base
|
||||
belongs_to :execution_environment
|
||||
|
||||
scope :for_execution_environment, ->(execution_environment) do
|
||||
Error.find_by_sql("SELECT MAX(created_at) AS created_at, MAX(id) AS id, message, COUNT(*) AS count FROM errors WHERE #{sanitize_sql_hash_for_conditions(execution_environment_id: execution_environment.id)} GROUP BY message ORDER BY count DESC")
|
||||
end
|
||||
scope :for_execution_environment, ->(execution_environment) { where(execution_environment_id: execution_environment.id) }
|
||||
scope :grouped_by_message, -> { select('MAX(created_at) AS created_at, MAX(id) AS id, message, COUNT(id) AS count').group(:message).order('count DESC') }
|
||||
|
||||
validates :execution_environment_id, presence: true
|
||||
validates :message, presence: true
|
||||
|
@ -67,7 +67,7 @@ describe ErrorsController do
|
||||
expect_assigns(execution_environment: :execution_environment)
|
||||
|
||||
it 'aggregates errors by message' do
|
||||
expect(assigns(:errors).count).to eq(1)
|
||||
expect(assigns(:errors).length).to eq(1)
|
||||
end
|
||||
|
||||
expect_status(200)
|
||||
|
Reference in New Issue
Block a user