Commit a55223faa1c8c2f9c6385b0300db4b91fc75eeb5
1 parent
85891ca6
Exists in
master
and in
1 other branch
Dealing with broken problem counters. fixes #151.
Showing
2 changed files
with
8 additions
and
1 deletions
Show diff stats
app/models/problem.rb
| @@ -158,7 +158,7 @@ class Problem | @@ -158,7 +158,7 @@ class Problem | ||
| 158 | 158 | ||
| 159 | def attribute_count_descrease(name, value) | 159 | def attribute_count_descrease(name, value) |
| 160 | counter, index = send(name), attribute_index(value) | 160 | counter, index = send(name), attribute_index(value) |
| 161 | - if counter[index]['count'] > 1 | 161 | + if counter[index] && counter[index]['count'] > 1 |
| 162 | counter[index]['count'] -= 1 | 162 | counter[index]['count'] -= 1 |
| 163 | else | 163 | else |
| 164 | counter.delete(index) | 164 | counter.delete(index) |
spec/models/problem_spec.rb
| @@ -248,6 +248,13 @@ describe Problem do | @@ -248,6 +248,13 @@ describe Problem do | ||
| 248 | @problem.reload | 248 | @problem.reload |
| 249 | }.should change(@problem, :messages).from({Digest::MD5.hexdigest('ERR 1') => {'value' => 'ERR 1', 'count' => 1}}).to({}) | 249 | }.should change(@problem, :messages).from({Digest::MD5.hexdigest('ERR 1') => {'value' => 'ERR 1', 'count' => 1}}).to({}) |
| 250 | end | 250 | end |
| 251 | + | ||
| 252 | + it "removing a notice from the problem with broken counter should not raise an error" do | ||
| 253 | + notice1 = Fabricate(:notice, :err => @err, :message => 'ERR 1') | ||
| 254 | + @problem.messages = {} | ||
| 255 | + @problem.save! | ||
| 256 | + expect {@err.notices.first.destroy}.not_to raise_error | ||
| 257 | + end | ||
| 251 | end | 258 | end |
| 252 | 259 | ||
| 253 | context "notice hosts cache" do | 260 | context "notice hosts cache" do |