refactored error aggregation

This commit is contained in:
Hauke Klement
2015-02-18 17:18:46 +01:00
parent ea44db73ef
commit 28405783a2
3 changed files with 4 additions and 5 deletions

View File

@ -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

View File

@ -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

View File

@ -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)