diff --git a/app/interactors/problem_updater_cache.rb b/app/interactors/problem_updater_cache.rb index 7a53106..e5370ab 100644 --- a/app/interactors/problem_updater_cache.rb +++ b/app/interactors/problem_updater_cache.rb @@ -43,8 +43,6 @@ class ProblemUpdaterCache attrs[:last_notice_at] = last_notice.created_at if last_notice attrs.merge!( :message => notice.message, - :environment => notice.environment_name, - :error_class => notice.error_class, :where => notice.where, :messages => attribute_count(:message, messages), :hosts => attribute_count(:host, hosts), diff --git a/app/models/app.rb b/app/models/app.rb index a979c96..e103e00 100644 --- a/app/models/app.rb +++ b/app/models/app.rb @@ -46,7 +46,7 @@ class App Err.where( :fingerprint => attrs[:fingerprint] ).first || - problems.create!.errs.create!(attrs) + problems.create!(attrs.slice(:error_class, :environment)).errs.create!(attrs) end # Mongoid Bug: find(id) on association proxies returns an Enumerator diff --git a/app/models/err.rb b/app/models/err.rb index da3c436..477cd50 100644 --- a/app/models/err.rb +++ b/app/models/err.rb @@ -22,4 +22,3 @@ class Err delegate :app, :resolved?, :to => :problem end - diff --git a/app/models/error_report.rb b/app/models/error_report.rb index 81bdbe0..dea4174 100644 --- a/app/models/error_report.rb +++ b/app/models/error_report.rb @@ -23,7 +23,9 @@ class ErrorReport end def rails_env - server_environment['environment-name'] || 'development' + rails_env = server_environment['environment-name'] + rails_env = 'development' if rails_env.blank? + rails_env end def component diff --git a/app/models/problem.rb b/app/models/problem.rb index 29fc693..d4755fc 100644 --- a/app/models/problem.rb +++ b/app/models/problem.rb @@ -39,6 +39,8 @@ class Problem has_many :errs, :inverse_of => :problem, :dependent => :destroy has_many :comments, :inverse_of => :err, :dependent => :destroy + validates_presence_of :error_class, :environment + before_create :cache_app_attributes scope :resolved, where(:resolved => true) @@ -91,11 +93,12 @@ class Problem end def unmerge! + attrs = {:error_class => error_class, :environment => environment} problem_errs = errs.to_a problem_errs.shift [self] + problem_errs.map(&:id).map do |err_id| err = Err.find(err_id) - app.problems.create.tap do |new_problem| + app.problems.create(attrs).tap do |new_problem| err.update_attribute(:problem_id, new_problem.id) new_problem.reset_cached_attributes end diff --git a/spec/fabricators/problem_fabricator.rb b/spec/fabricators/problem_fabricator.rb index 2536f6d..6cba738 100644 --- a/spec/fabricators/problem_fabricator.rb +++ b/spec/fabricators/problem_fabricator.rb @@ -1,6 +1,8 @@ Fabricator(:problem) do app! { Fabricate(:app) } comments { [] } + error_class 'FooError' + environment 'production' end Fabricator(:problem_with_comments, :from => :problem) do diff --git a/spec/interactors/problem_updater_cache_spec.rb b/spec/interactors/problem_updater_cache_spec.rb index 5a7a66f..2afbf3f 100644 --- a/spec/interactors/problem_updater_cache_spec.rb +++ b/spec/interactors/problem_updater_cache_spec.rb @@ -27,8 +27,6 @@ describe ProblemUpdaterCache do it 'update information about this notice' do expect(problem.message).to eq notice.message - expect(problem.environment).to eq notice.environment_name - expect(problem.error_class).to eq notice.error_class expect(problem.where).to eq notice.where end @@ -68,8 +66,6 @@ describe ProblemUpdaterCache do end it 'update information about this notice' do expect(problem.message).to eq notice.message - expect(problem.environment).to eq notice.environment_name - expect(problem.error_class).to eq notice.error_class expect(problem.where).to eq notice.where end @@ -118,8 +114,6 @@ describe ProblemUpdaterCache do it 'update information about this notice' do expect(problem.message).to eq notice.message - expect(problem.environment).to eq notice.environment_name - expect(problem.error_class).to eq notice.error_class expect(problem.where).to eq notice.where end diff --git a/spec/models/err_spec.rb b/spec/models/err_spec.rb index c8ca653..6a6599f 100644 --- a/spec/models/err_spec.rb +++ b/spec/models/err_spec.rb @@ -1,10 +1,5 @@ require 'spec_helper' describe Err do - it 'sets a default error_class and environment' do - err = Err.new - err.error_class.should == "UnknownError" - err.environment.should == "unknown" - end -end +end diff --git a/spec/models/problem_spec.rb b/spec/models/problem_spec.rb index b7732dd..9593e92 100644 --- a/spec/models/problem_spec.rb +++ b/spec/models/problem_spec.rb @@ -1,6 +1,21 @@ require 'spec_helper' describe Problem do + + context 'validations' do + it 'requires a error_class' do + err = Fabricate.build(:problem, :error_class => nil) + err.should_not be_valid + err.errors[:error_class].should include("can't be blank") + end + + it 'requires an environment' do + err = Fabricate.build(:problem, :environment => nil) + err.should_not be_valid + err.errors[:environment].should include("can't be blank") + end + end + describe "Fabrication" do context "Fabricate(:problem)" do it 'should have no comment' do -- libgit2 0.21.2