From d69719a028f26ebb8dfd420da368842cbd05edde Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Wed, 30 May 2012 13:31:56 +1200 Subject: [PATCH] Updated mongoid to 2.4.10, renamed :klass fields to :error_class (including migration) --- Gemfile | 2 +- Gemfile.lock | 6 +++--- app/models/app.rb | 4 ++-- app/models/err.rb | 6 +++--- app/models/error_report.rb | 5 +++-- app/models/notice.rb | 2 +- app/models/problem.rb | 4 ++-- app/views/errs/show.html.haml | 2 +- app/views/notices/_summary.html.haml | 3 +++ db/migrate/20120530005915_rename_klass_to_error_class.rb | 13 +++++++++++++ lib/hoptoad/v2.rb | 2 +- lib/tasks/errbit/demo.rake | 14 +++++++------- spec/fabricators/err_fabricator.rb | 2 +- spec/models/app_spec.rb | 6 +++--- spec/models/err_spec.rb | 6 +++--- 15 files changed, 47 insertions(+), 30 deletions(-) create mode 100644 db/migrate/20120530005915_rename_klass_to_error_class.rb diff --git a/Gemfile b/Gemfile index c326c57..3abdb01 100644 --- a/Gemfile +++ b/Gemfile @@ -3,7 +3,7 @@ source 'http://rubygems.org' gem 'rails', '~> 3.2.0' gem 'nokogiri' -gem 'mongoid', '~> 2.2.2' +gem 'mongoid', '~> 2.4.10' gem 'haml' gem 'htmlentities', "~> 4.3.0" diff --git a/Gemfile.lock b/Gemfile.lock index 9ee71b3..e88cd39 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -105,8 +105,8 @@ GEM mime-types (1.18) mongo (1.3.1) bson (>= 1.3.1) - mongoid (2.2.5) - activemodel (~> 3.0) + mongoid (2.4.10) + activemodel (~> 3.1) mongo (~> 1.3) tzinfo (~> 0.3.22) mongoid_rails_migrations (0.0.14) @@ -242,7 +242,7 @@ DEPENDENCIES kaminari lighthouse-api mongo (= 1.3.1) - mongoid (~> 2.2.2) + mongoid (~> 2.4.10) mongoid_rails_migrations nokogiri octokit (= 0.6.4) diff --git a/app/models/app.rb b/app/models/app.rb index ffd206d..dbcfe73 100644 --- a/app/models/app.rb +++ b/app/models/app.rb @@ -47,7 +47,7 @@ class App # # Accepts either XML or a hash with the following attributes: # - # * :klass - the class of error + # * :error_class - the class of error # * :message - the error message # * :backtrace - an array of stack trace lines # @@ -67,7 +67,7 @@ class App # # Accepts a hash with the following attributes: # - # * :klass - the class of error + # * :error_class - the class of error # * :message - the error message # * :backtrace - an array of stack trace lines # diff --git a/app/models/err.rb b/app/models/err.rb index 1988050..9863fbc 100644 --- a/app/models/err.rb +++ b/app/models/err.rb @@ -6,7 +6,7 @@ class Err include Mongoid::Document include Mongoid::Timestamps - field :klass + field :error_class field :component field :action field :environment @@ -14,11 +14,11 @@ class Err belongs_to :problem index :problem_id - index :klass + index :error_class has_many :notices, :inverse_of => :err, :dependent => :destroy - validates_presence_of :klass, :environment + validates_presence_of :error_class, :environment delegate :app, :resolved?, :to => :problem diff --git a/app/models/error_report.rb b/app/models/error_report.rb index e9d4bd0..68c3aa5 100644 --- a/app/models/error_report.rb +++ b/app/models/error_report.rb @@ -2,7 +2,7 @@ require 'digest/md5' require 'hoptoad_notifier' class ErrorReport - attr_reader :klass, :message, :backtrace, :request, :server_environment, :api_key, :notifier, :user_attributes + attr_reader :error_class, :message, :backtrace, :request, :server_environment, :api_key, :notifier, :user_attributes def initialize(xml_or_attributes) @attributes = (xml_or_attributes.is_a?(String) ? Hoptoad.parse_xml!(xml_or_attributes) : xml_or_attributes).with_indifferent_access @@ -36,6 +36,7 @@ class ErrorReport def generate_notice! notice = Notice.new( :message => message, + :error_class => error_class, :backtrace => backtrace, :request => request, :server_environment => server_environment, @@ -43,7 +44,7 @@ class ErrorReport :user_attributes => user_attributes) err = app.find_or_create_err!( - :klass => klass, + :error_class => error_class, :component => component, :action => action, :environment => rails_env, diff --git a/app/models/notice.rb b/app/models/notice.rb index 4ba9e05..85cafb8 100644 --- a/app/models/notice.rb +++ b/app/models/notice.rb @@ -11,7 +11,7 @@ class Notice field :request, :type => Hash field :notifier, :type => Hash field :user_attributes, :type => Hash - field :klass + field :error_class belongs_to :err index :created_at diff --git a/app/models/problem.rb b/app/models/problem.rb index 43dae4c..4ca333f 100644 --- a/app/models/problem.rb +++ b/app/models/problem.rb @@ -16,7 +16,7 @@ class Problem field :notices_count, :type => Integer, :default => 0 field :message field :environment - field :klass + field :error_class field :where field :user_agents, :type => Hash, :default => {} field :messages, :type => Hash, :default => {} @@ -128,7 +128,7 @@ class Problem attrs.merge!( :message => notice.message, :environment => notice.environment_name, - :klass => notice.klass, + :error_class => notice.error_class, :where => notice.where, :messages => attribute_count_increase(:messages, notice.message), :hosts => attribute_count_increase(:hosts, notice.host), diff --git a/app/views/errs/show.html.haml b/app/views/errs/show.html.haml index 88e20d0..cd8fe5a 100644 --- a/app/views/errs/show.html.haml +++ b/app/views/errs/show.html.haml @@ -1,5 +1,5 @@ - content_for :page_title, @problem.message -- content_for :title, @problem.klass +- content_for :title, @problem.error_class - content_for :meta do %strong App: = link_to @app.name, app_path(@app) diff --git a/app/views/notices/_summary.html.haml b/app/views/notices/_summary.html.haml index e1c7395..2c6136c 100644 --- a/app/views/notices/_summary.html.haml +++ b/app/views/notices/_summary.html.haml @@ -3,6 +3,9 @@ %tr %th Message %td.main.nowrap= message_graph(problem) + %tr + %th Error Class + %td= notice.error_class - if notice.request['url'].present? %tr %th URL diff --git a/db/migrate/20120530005915_rename_klass_to_error_class.rb b/db/migrate/20120530005915_rename_klass_to_error_class.rb new file mode 100644 index 0000000..8644ff2 --- /dev/null +++ b/db/migrate/20120530005915_rename_klass_to_error_class.rb @@ -0,0 +1,13 @@ +class RenameKlassToErrorClass < Mongoid::Migration + def self.up + [Problem, Err, Notice].each do |model| + model.collection.update({}, {'$rename' => {'klass' => 'error_class'}}, multi: true, safe: true) + end + end + + def self.down + [Problem, Err, Notice].each do |model| + model.collection.update({}, {'$rename' => {'error_class' => 'klass'}}, multi: true, safe: true) + end + end +end diff --git a/lib/hoptoad/v2.rb b/lib/hoptoad/v2.rb index 1087360..ea9ed6f 100644 --- a/lib/hoptoad/v2.rb +++ b/lib/hoptoad/v2.rb @@ -50,7 +50,7 @@ module Hoptoad def self.for_errbit_api(notice) { - :klass => notice['error']['class'] || notice['error']['key'], + :error_class => notice['error']['class'] || notice['error']['key'], :message => notice['error']['message'], :backtrace => notice['error']['backtrace']['line'], diff --git a/lib/tasks/errbit/demo.rake b/lib/tasks/errbit/demo.rake index 581ae7a..d7d32d4 100644 --- a/lib/tasks/errbit/demo.rake +++ b/lib/tasks/errbit/demo.rake @@ -9,22 +9,22 @@ namespace :errbit do app.problems.delete_all errors = [{ - :klass => "ArgumentError", + :error_class => "ArgumentError", :message => "wrong number of arguments (3 for 0)" }, { - :klass => "RuntimeError", + :error_class => "RuntimeError", :message => "Could not find Red October" }, { - :klass => "TypeError", + :error_class => "TypeError", :message => "can't convert Symbol into Integer" }, { - :klass => "ActiveRecord::RecordNotFound", + :error_class => "ActiveRecord::RecordNotFound", :message => "could not find a record with the id 5" }, { - :klass => "NameError", + :error_class => "NameError", :message => "uninitialized constant Tag" }, { - :klass => "SyntaxError", + :error_class => "SyntaxError", :message => "unexpected tSTRING_BEG, expecting keyword_do or '{' or '('" }] @@ -44,7 +44,7 @@ namespace :errbit do rand(34).times do error_report = error_template.reverse_merge({ - :klass => "StandardError", + :error_class => "StandardError", :message => "Oops. Something went wrong!", :backtrace => random_backtrace, :request => { diff --git a/spec/fabricators/err_fabricator.rb b/spec/fabricators/err_fabricator.rb index 6d842c2..2b92461 100644 --- a/spec/fabricators/err_fabricator.rb +++ b/spec/fabricators/err_fabricator.rb @@ -1,6 +1,6 @@ Fabricator :err do problem! - klass! { 'FooError' } + error_class! { 'FooError' } component 'foo' action 'bar' environment 'production' diff --git a/spec/models/app_spec.rb b/spec/models/app_spec.rb index 5a4e5ea..466c90c 100644 --- a/spec/models/app_spec.rb +++ b/spec/models/app_spec.rb @@ -117,7 +117,7 @@ describe App do before do @app = Fabricate(:app) @conditions = { - :klass => 'Whoops', + :error_class => 'Whoops', :component => 'Foo', :action => 'bar', :environment => 'production' @@ -158,7 +158,7 @@ describe App do it 'finds the correct err for the notice' do App.should_receive(:find_by_api_key!).and_return(@app) @app.should_receive(:find_or_create_err!).with({ - :klass => 'HoptoadTestingException', + :error_class => 'HoptoadTestingException', :component => 'application', :action => 'verify', :environment => 'development', @@ -171,7 +171,7 @@ describe App do it 'marks the err as unresolved if it was previously resolved' do App.should_receive(:find_by_api_key!).and_return(@app) @app.should_receive(:find_or_create_err!).with({ - :klass => 'HoptoadTestingException', + :error_class => 'HoptoadTestingException', :component => 'application', :action => 'verify', :environment => 'development', diff --git a/spec/models/err_spec.rb b/spec/models/err_spec.rb index b12530c..55c1cf5 100644 --- a/spec/models/err_spec.rb +++ b/spec/models/err_spec.rb @@ -3,10 +3,10 @@ require 'spec_helper' describe Err do context 'validations' do - it 'requires a klass' do - err = Fabricate.build(:err, :klass => nil) + it 'requires a error_class' do + err = Fabricate.build(:err, :error_class => nil) err.should_not be_valid - err.errors[:klass].should include("can't be blank") + err.errors[:error_class].should include("can't be blank") end it 'requires an environment' do -- libgit2 0.21.2