Commit 35ae77fedcf104120b101fe5bc161cadb1cf6d3a
Exists in
master
and in
1 other branch
Merge branch 'master' into mongoid-3
Conflicts: spec/models/problem_spec.rb
Showing
4 changed files
with
25 additions
and
24 deletions
Show diff stats
CHANGELOG.md
app/models/problem.rb
| @@ -39,7 +39,7 @@ class Problem | @@ -39,7 +39,7 @@ class Problem | ||
| 39 | has_many :errs, :inverse_of => :problem, :dependent => :destroy | 39 | has_many :errs, :inverse_of => :problem, :dependent => :destroy |
| 40 | has_many :comments, :inverse_of => :err, :dependent => :destroy | 40 | has_many :comments, :inverse_of => :err, :dependent => :destroy |
| 41 | 41 | ||
| 42 | - validates_presence_of :error_class, :environment | 42 | + validates_presence_of :environment |
| 43 | 43 | ||
| 44 | before_create :cache_app_attributes | 44 | before_create :cache_app_attributes |
| 45 | 45 |
spec/models/app_spec.rb
| @@ -165,31 +165,44 @@ describe App do | @@ -165,31 +165,44 @@ describe App do | ||
| 165 | end | 165 | end |
| 166 | 166 | ||
| 167 | context '#find_or_create_err!' do | 167 | context '#find_or_create_err!' do |
| 168 | - before do | ||
| 169 | - @app = Fabricate(:app) | ||
| 170 | - @conditions = { | 168 | + let(:app) { Fabricate(:app) } |
| 169 | + let(:conditions) { { | ||
| 171 | :error_class => 'Whoops', | 170 | :error_class => 'Whoops', |
| 172 | :environment => 'production', | 171 | :environment => 'production', |
| 173 | :fingerprint => 'some-finger-print' | 172 | :fingerprint => 'some-finger-print' |
| 174 | } | 173 | } |
| 175 | - end | 174 | + } |
| 176 | 175 | ||
| 177 | it 'returns the correct err if one already exists' do | 176 | it 'returns the correct err if one already exists' do |
| 178 | - existing = Fabricate(:err, @conditions.merge(:problem => Fabricate(:problem, :app => @app))) | ||
| 179 | - Err.where(@conditions).first.should == existing | ||
| 180 | - @app.find_or_create_err!(@conditions).should == existing | 177 | + existing = Fabricate(:err, conditions.merge(:problem => Fabricate(:problem, :app => app))) |
| 178 | + Err.where(conditions).first.should == existing | ||
| 179 | + app.find_or_create_err!(conditions).should == existing | ||
| 181 | end | 180 | end |
| 182 | 181 | ||
| 183 | it 'assigns the returned err to the given app' do | 182 | it 'assigns the returned err to the given app' do |
| 184 | - @app.find_or_create_err!(@conditions).app.should == @app | 183 | + app.find_or_create_err!(conditions).app.should == app |
| 185 | end | 184 | end |
| 186 | 185 | ||
| 187 | it 'creates a new problem if a matching one does not already exist' do | 186 | it 'creates a new problem if a matching one does not already exist' do |
| 188 | - Err.where(@conditions).first.should be_nil | 187 | + Err.where(conditions).first.should be_nil |
| 189 | lambda { | 188 | lambda { |
| 190 | - @app.find_or_create_err!(@conditions) | 189 | + app.find_or_create_err!(conditions) |
| 191 | }.should change(Problem,:count).by(1) | 190 | }.should change(Problem,:count).by(1) |
| 192 | end | 191 | end |
| 192 | + | ||
| 193 | + context "without error_class" do | ||
| 194 | + let(:conditions) { { | ||
| 195 | + :environment => 'production', | ||
| 196 | + :fingerprint => 'some-finger-print' | ||
| 197 | + } | ||
| 198 | + } | ||
| 199 | + it 'save the err' do | ||
| 200 | + Err.where(conditions).first.should be_nil | ||
| 201 | + lambda { | ||
| 202 | + app.find_or_create_err!(conditions) | ||
| 203 | + }.should change(Problem,:count).by(1) | ||
| 204 | + end | ||
| 205 | + end | ||
| 193 | end | 206 | end |
| 194 | 207 | ||
| 195 | describe ".find_by_api_key!" do | 208 | describe ".find_by_api_key!" do |
spec/models/problem_spec.rb
| @@ -3,12 +3,6 @@ require 'spec_helper' | @@ -3,12 +3,6 @@ require 'spec_helper' | ||
| 3 | describe Problem do | 3 | describe Problem do |
| 4 | 4 | ||
| 5 | context 'validations' do | 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 | 6 | it 'requires an environment' do |
| 13 | err = Fabricate.build(:problem, :environment => nil) | 7 | err = Fabricate.build(:problem, :environment => nil) |
| 14 | err.should_not be_valid | 8 | err.should_not be_valid |
| @@ -70,7 +64,6 @@ describe Problem do | @@ -70,7 +64,6 @@ describe Problem do | ||
| 70 | end | 64 | end |
| 71 | end | 65 | end |
| 72 | 66 | ||
| 73 | - | ||
| 74 | context '#message' do | 67 | context '#message' do |
| 75 | it "adding a notice caches its message" do | 68 | it "adding a notice caches its message" do |
| 76 | err = Fabricate(:err) | 69 | err = Fabricate(:err) |
| @@ -81,7 +74,6 @@ describe Problem do | @@ -81,7 +74,6 @@ describe Problem do | ||
| 81 | end | 74 | end |
| 82 | end | 75 | end |
| 83 | 76 | ||
| 84 | - | ||
| 85 | context 'being created' do | 77 | context 'being created' do |
| 86 | context 'when the app has err notifications set to false' do | 78 | context 'when the app has err notifications set to false' do |
| 87 | it 'should not send an email notification' do | 79 | it 'should not send an email notification' do |
| @@ -92,7 +84,6 @@ describe Problem do | @@ -92,7 +84,6 @@ describe Problem do | ||
| 92 | end | 84 | end |
| 93 | end | 85 | end |
| 94 | 86 | ||
| 95 | - | ||
| 96 | context "#resolved?" do | 87 | context "#resolved?" do |
| 97 | it "should start out as unresolved" do | 88 | it "should start out as unresolved" do |
| 98 | problem = Problem.new | 89 | problem = Problem.new |
| @@ -108,7 +99,6 @@ describe Problem do | @@ -108,7 +99,6 @@ describe Problem do | ||
| 108 | end | 99 | end |
| 109 | end | 100 | end |
| 110 | 101 | ||
| 111 | - | ||
| 112 | context "resolve!" do | 102 | context "resolve!" do |
| 113 | it "marks the problem as resolved" do | 103 | it "marks the problem as resolved" do |
| 114 | problem = Fabricate(:problem) | 104 | problem = Fabricate(:problem) |
| @@ -202,7 +192,6 @@ describe Problem do | @@ -202,7 +192,6 @@ describe Problem do | ||
| 202 | end | 192 | end |
| 203 | end | 193 | end |
| 204 | 194 | ||
| 205 | - | ||
| 206 | context "notice counter cache" do | 195 | context "notice counter cache" do |
| 207 | before do | 196 | before do |
| 208 | @app = Fabricate(:app) | 197 | @app = Fabricate(:app) |
| @@ -229,7 +218,6 @@ describe Problem do | @@ -229,7 +218,6 @@ describe Problem do | ||
| 229 | end | 218 | end |
| 230 | end | 219 | end |
| 231 | 220 | ||
| 232 | - | ||
| 233 | context "#app_name" do | 221 | context "#app_name" do |
| 234 | let!(:app) { Fabricate(:app) } | 222 | let!(:app) { Fabricate(:app) } |
| 235 | let!(:problem) { Fabricate(:problem, :app => app) } | 223 | let!(:problem) { Fabricate(:problem, :app => app) } |