Commit e1cf64297acdf19f3ae760734ec1fec9366b3f9a
Committed by
Bob Lail
1 parent
0d890b14
Exists in
master
and in
1 other branch
move the validations for error_class and environment from Err to Problem
Problems are the models rendered in the UI now, not Errs. Errs are functioning as a glorified hash table. It makes more sense to validate problems. Also, this paves the way for the next commit, so that no functionality is lost in the subsequent refactor.
Showing
9 changed files
with
26 additions
and
18 deletions
Show diff stats
app/interactors/problem_updater_cache.rb
| ... | ... | @@ -43,8 +43,6 @@ class ProblemUpdaterCache |
| 43 | 43 | attrs[:last_notice_at] = last_notice.created_at if last_notice |
| 44 | 44 | attrs.merge!( |
| 45 | 45 | :message => notice.message, |
| 46 | - :environment => notice.environment_name, | |
| 47 | - :error_class => notice.error_class, | |
| 48 | 46 | :where => notice.where, |
| 49 | 47 | :messages => attribute_count(:message, messages), |
| 50 | 48 | :hosts => attribute_count(:host, hosts), | ... | ... |
app/models/app.rb
| ... | ... | @@ -46,7 +46,7 @@ class App |
| 46 | 46 | Err.where( |
| 47 | 47 | :fingerprint => attrs[:fingerprint] |
| 48 | 48 | ).first || |
| 49 | - problems.create!.errs.create!(attrs) | |
| 49 | + problems.create!(attrs.slice(:error_class, :environment)).errs.create!(attrs) | |
| 50 | 50 | end |
| 51 | 51 | |
| 52 | 52 | # Mongoid Bug: find(id) on association proxies returns an Enumerator | ... | ... |
app/models/err.rb
app/models/error_report.rb
| ... | ... | @@ -23,7 +23,9 @@ class ErrorReport |
| 23 | 23 | end |
| 24 | 24 | |
| 25 | 25 | def rails_env |
| 26 | - server_environment['environment-name'] || 'development' | |
| 26 | + rails_env = server_environment['environment-name'] | |
| 27 | + rails_env = 'development' if rails_env.blank? | |
| 28 | + rails_env | |
| 27 | 29 | end |
| 28 | 30 | |
| 29 | 31 | def component | ... | ... |
app/models/problem.rb
| ... | ... | @@ -39,6 +39,8 @@ class Problem |
| 39 | 39 | has_many :errs, :inverse_of => :problem, :dependent => :destroy |
| 40 | 40 | has_many :comments, :inverse_of => :err, :dependent => :destroy |
| 41 | 41 | |
| 42 | + validates_presence_of :error_class, :environment | |
| 43 | + | |
| 42 | 44 | before_create :cache_app_attributes |
| 43 | 45 | |
| 44 | 46 | scope :resolved, where(:resolved => true) |
| ... | ... | @@ -91,11 +93,12 @@ class Problem |
| 91 | 93 | end |
| 92 | 94 | |
| 93 | 95 | def unmerge! |
| 96 | + attrs = {:error_class => error_class, :environment => environment} | |
| 94 | 97 | problem_errs = errs.to_a |
| 95 | 98 | problem_errs.shift |
| 96 | 99 | [self] + problem_errs.map(&:id).map do |err_id| |
| 97 | 100 | err = Err.find(err_id) |
| 98 | - app.problems.create.tap do |new_problem| | |
| 101 | + app.problems.create(attrs).tap do |new_problem| | |
| 99 | 102 | err.update_attribute(:problem_id, new_problem.id) |
| 100 | 103 | new_problem.reset_cached_attributes |
| 101 | 104 | end | ... | ... |
spec/fabricators/problem_fabricator.rb
spec/interactors/problem_updater_cache_spec.rb
| ... | ... | @@ -27,8 +27,6 @@ describe ProblemUpdaterCache do |
| 27 | 27 | |
| 28 | 28 | it 'update information about this notice' do |
| 29 | 29 | expect(problem.message).to eq notice.message |
| 30 | - expect(problem.environment).to eq notice.environment_name | |
| 31 | - expect(problem.error_class).to eq notice.error_class | |
| 32 | 30 | expect(problem.where).to eq notice.where |
| 33 | 31 | end |
| 34 | 32 | |
| ... | ... | @@ -68,8 +66,6 @@ describe ProblemUpdaterCache do |
| 68 | 66 | end |
| 69 | 67 | it 'update information about this notice' do |
| 70 | 68 | expect(problem.message).to eq notice.message |
| 71 | - expect(problem.environment).to eq notice.environment_name | |
| 72 | - expect(problem.error_class).to eq notice.error_class | |
| 73 | 69 | expect(problem.where).to eq notice.where |
| 74 | 70 | end |
| 75 | 71 | |
| ... | ... | @@ -118,8 +114,6 @@ describe ProblemUpdaterCache do |
| 118 | 114 | |
| 119 | 115 | it 'update information about this notice' do |
| 120 | 116 | expect(problem.message).to eq notice.message |
| 121 | - expect(problem.environment).to eq notice.environment_name | |
| 122 | - expect(problem.error_class).to eq notice.error_class | |
| 123 | 117 | expect(problem.where).to eq notice.where |
| 124 | 118 | end |
| 125 | 119 | ... | ... |
spec/models/err_spec.rb
spec/models/problem_spec.rb
| 1 | 1 | require 'spec_helper' |
| 2 | 2 | |
| 3 | 3 | describe Problem do |
| 4 | + | |
| 5 | + context 'validations' do | |
| 6 | + it 'requires a error_class' do | |
| 7 | + err = Fabricate.build(:problem, :error_class => nil) | |
| 8 | + err.should_not be_valid | |
| 9 | + err.errors[:error_class].should include("can't be blank") | |
| 10 | + end | |
| 11 | + | |
| 12 | + it 'requires an environment' do | |
| 13 | + err = Fabricate.build(:problem, :environment => nil) | |
| 14 | + err.should_not be_valid | |
| 15 | + err.errors[:environment].should include("can't be blank") | |
| 16 | + end | |
| 17 | + end | |
| 18 | + | |
| 4 | 19 | describe "Fabrication" do |
| 5 | 20 | context "Fabricate(:problem)" do |
| 6 | 21 | it 'should have no comment' do | ... | ... |