From 0e90eba37e6bd391cc44ce2ee49b32ab93af353d Mon Sep 17 00:00:00 2001 From: Cyril Mougel Date: Thu, 29 Aug 2013 16:10:48 +0200 Subject: [PATCH] Allow create a Problem without ErrorClass --- app/models/problem.rb | 2 +- spec/models/app_spec.rb | 33 +++++++++++++++++++++++---------- spec/models/problem_spec.rb | 16 ++-------------- 3 files changed, 26 insertions(+), 25 deletions(-) diff --git a/app/models/problem.rb b/app/models/problem.rb index d4755fc..7c67dbb 100644 --- a/app/models/problem.rb +++ b/app/models/problem.rb @@ -39,7 +39,7 @@ class Problem has_many :errs, :inverse_of => :problem, :dependent => :destroy has_many :comments, :inverse_of => :err, :dependent => :destroy - validates_presence_of :error_class, :environment + validates_presence_of :environment before_create :cache_app_attributes diff --git a/spec/models/app_spec.rb b/spec/models/app_spec.rb index 9367e4d..e0bdebf 100644 --- a/spec/models/app_spec.rb +++ b/spec/models/app_spec.rb @@ -158,31 +158,44 @@ describe App do context '#find_or_create_err!' do - before do - @app = Fabricate(:app) - @conditions = { + let(:app) { Fabricate(:app) } + let(:conditions) { { :error_class => 'Whoops', :environment => 'production', :fingerprint => 'some-finger-print' } - end + } it 'returns the correct err if one already exists' do - existing = Fabricate(:err, @conditions.merge(:problem => Fabricate(:problem, :app => @app))) - Err.where(@conditions).first.should == existing - @app.find_or_create_err!(@conditions).should == existing + existing = Fabricate(:err, conditions.merge(:problem => Fabricate(:problem, :app => app))) + Err.where(conditions).first.should == existing + app.find_or_create_err!(conditions).should == existing end it 'assigns the returned err to the given app' do - @app.find_or_create_err!(@conditions).app.should == @app + app.find_or_create_err!(conditions).app.should == app end it 'creates a new problem if a matching one does not already exist' do - Err.where(@conditions).first.should be_nil + Err.where(conditions).first.should be_nil lambda { - @app.find_or_create_err!(@conditions) + app.find_or_create_err!(conditions) }.should change(Problem,:count).by(1) end + + context "without error_class" do + let(:conditions) { { + :environment => 'production', + :fingerprint => 'some-finger-print' + } + } + it 'save the err' do + Err.where(conditions).first.should be_nil + lambda { + app.find_or_create_err!(conditions) + }.should change(Problem,:count).by(1) + end + end end diff --git a/spec/models/problem_spec.rb b/spec/models/problem_spec.rb index 41b713a..08a4f44 100644 --- a/spec/models/problem_spec.rb +++ b/spec/models/problem_spec.rb @@ -1,21 +1,15 @@ 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 + context 'validations' do 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 @@ -70,7 +64,6 @@ describe Problem do end end - context '#message' do it "adding a notice caches its message" do err = Fabricate(:err) @@ -81,7 +74,6 @@ describe Problem do end end - context 'being created' do context 'when the app has err notifications set to false' do it 'should not send an email notification' do @@ -92,7 +84,6 @@ describe Problem do end end - context "#resolved?" do it "should start out as unresolved" do problem = Problem.new @@ -108,7 +99,6 @@ describe Problem do end end - context "resolve!" do it "marks the problem as resolved" do problem = Fabricate(:problem) @@ -198,7 +188,6 @@ describe Problem do end end - context "notice counter cache" do before do @app = Fabricate(:app) @@ -225,7 +214,6 @@ describe Problem do end end - context "#app_name" do let!(:app) { Fabricate(:app) } let!(:problem) { Fabricate(:problem, :app => app) } -- libgit2 0.21.2