Commit 5af09f5a630c39daede8e7baaae95a97199bfbd3
Exists in
master
and in
1 other branch
Merge pull request #265 from concordia-publishing-house/dont-clear-notice-count
Notice counts are all zero when you resolve a problem
Showing
3 changed files
with
12 additions
and
3 deletions
Show diff stats
app/models/notice.rb
@@ -111,7 +111,7 @@ class Notice | @@ -111,7 +111,7 @@ class Notice | ||
111 | end | 111 | end |
112 | 112 | ||
113 | def unresolve_problem | 113 | def unresolve_problem |
114 | - problem.update_attribute(:resolved, false) if problem.resolved? | 114 | + problem.update_attributes!(:resolved => false, :resolved_at => nil, :notices_count => 1) if problem.resolved? |
115 | end | 115 | end |
116 | 116 | ||
117 | def cache_attributes_on_problem | 117 | def cache_attributes_on_problem |
app/models/problem.rb
@@ -58,11 +58,11 @@ class Problem | @@ -58,11 +58,11 @@ class Problem | ||
58 | end | 58 | end |
59 | 59 | ||
60 | def resolve! | 60 | def resolve! |
61 | - self.update_attributes!(:resolved => true, :resolved_at => Time.now, :notices_count => 0) | 61 | + self.update_attributes!(:resolved => true, :resolved_at => Time.now) |
62 | end | 62 | end |
63 | 63 | ||
64 | def unresolve! | 64 | def unresolve! |
65 | - self.update_attributes!(:resolved => false) | 65 | + self.update_attributes!(:resolved => false, :resolved_at => nil) |
66 | end | 66 | end |
67 | 67 | ||
68 | def unresolved? | 68 | def unresolved? |
spec/models/problem_spec.rb
@@ -109,6 +109,15 @@ describe Problem do | @@ -109,6 +109,15 @@ describe Problem do | ||
109 | problem.resolved_at.to_s.should == expected_resolved_at.to_s | 109 | problem.resolved_at.to_s.should == expected_resolved_at.to_s |
110 | end | 110 | end |
111 | 111 | ||
112 | + it "should not reset notice count" do | ||
113 | + problem = Fabricate(:problem, :notices_count => 1) | ||
114 | + original_notices_count = problem.notices_count | ||
115 | + original_notices_count.should > 0 | ||
116 | + | ||
117 | + problem.resolve! | ||
118 | + problem.notices_count.should == original_notices_count | ||
119 | + end | ||
120 | + | ||
112 | it "should throw an err if it's not successful" do | 121 | it "should throw an err if it's not successful" do |
113 | problem = Fabricate(:problem) | 122 | problem = Fabricate(:problem) |
114 | problem.should_not be_resolved | 123 | problem.should_not be_resolved |