diff --git a/app/models/notice.rb b/app/models/notice.rb index 7ad3e51..dd9d03d 100644 --- a/app/models/notice.rb +++ b/app/models/notice.rb @@ -57,7 +57,7 @@ class Notice end def self.in_app_backtrace_line? line - line['file'] =~ %r{^\[PROJECT_ROOT\]/(?!(vendor))} + !!(line['file'] =~ %r{^\[PROJECT_ROOT\]/(?!(vendor))}) end def request @@ -84,10 +84,6 @@ class Notice err.update_attributes(:last_notice_at => created_at) end - def top_in_app_backtrace_line - @top_in_app_backtrace_line ||= self.backtrace.find {|line| Notice.in_app_backtrace_line?(line) } - end - protected def should_notify? diff --git a/spec/models/notice_spec.rb b/spec/models/notice_spec.rb index d0352da..4942520 100644 --- a/spec/models/notice_spec.rb +++ b/spec/models/notice_spec.rb @@ -22,9 +22,8 @@ describe Notice do end end - context '#top_in_app_backtrace_line' do - before do - backtrace = [{ + context '.in_app_backtrace_line?' do + let(:backtrace) do [{ 'number' => rand(999), 'file' => '[GEM_ROOT]/gems/actionpack-3.0.4/lib/action_controller/metal/rescue.rb', 'method' => ActiveSupport.methods.shuffle.first @@ -36,18 +35,19 @@ describe Notice do 'number' => rand(999), 'file' => '[PROJECT_ROOT]/lib/set_headers.rb', 'method' => ActiveSupport.methods.shuffle.first - }, { - 'number' => rand(999), - 'file' => '[PROJECT_ROOT]/lib/detect_api.rb', - 'method' => ActiveSupport.methods.shuffle.first }] + end - @notice = Factory(:notice, :backtrace => backtrace) + it "should be false for line not starting with PROJECT_ROOT" do + Notice.in_app_backtrace_line?(backtrace[0]).should == false end - - it 'finds the correct line' do - line = @notice.top_in_app_backtrace_line - line['file'].should == '[PROJECT_ROOT]/lib/set_headers.rb' + + it "should be false for file in vendor dir" do + Notice.in_app_backtrace_line?(backtrace[1]).should == false + end + + it "should be true for application file" do + Notice.in_app_backtrace_line?(backtrace[2]).should == true end end -- libgit2 0.21.2