Commit ef27f84e5998712996e69c3cc39eec4b76febb4f

Authored by Nick Recobra
1 parent 4d9bc87e
Exists in master and in 1 other branch production

Handle errs without notices. Userful for testing custom clients and different tests.

app/helpers/errs_helper.rb 0 → 100644
@@ -0,0 +1,7 @@ @@ -0,0 +1,7 @@
  1 +module ErrsHelper
  2 +
  3 + def last_notice_at err
  4 + err.last_notice_at || err.created_at
  5 + end
  6 +
  7 +end
0 \ No newline at end of file 8 \ No newline at end of file
app/models/err.rb
@@ -45,7 +45,7 @@ class Err @@ -45,7 +45,7 @@ class Err
45 end 45 end
46 46
47 def message 47 def message
48 - notices.first.message || klass 48 + notices.first.try(:message) || klass
49 end 49 end
50 50
51 end 51 end
52 \ No newline at end of file 52 \ No newline at end of file
app/views/errs/_table.html.haml
@@ -15,11 +15,11 @@ @@ -15,11 +15,11 @@
15 %td.message 15 %td.message
16 = link_to err.message, app_err_path(err.app, err) 16 = link_to err.message, app_err_path(err.app, err)
17 %em= err.where 17 %em= err.where
18 - %td.latest #{time_ago_in_words(err.last_notice_at)} ago 18 + %td.latest #{time_ago_in_words(last_notice_at err)} ago
19 %td.deploy= err.app.last_deploy_at ? err.app.last_deploy_at.to_s(:micro) : 'n/a' 19 %td.deploy= err.app.last_deploy_at ? err.app.last_deploy_at.to_s(:micro) : 'n/a'
20 %td.count= link_to err.notices.count, app_err_path(err.app, err) 20 %td.count= link_to err.notices.count, app_err_path(err.app, err)
21 - if errs.none? 21 - if errs.none?
22 %tr 22 %tr
23 %td{:colspan => (@app ? 5 : 6)} 23 %td{:colspan => (@app ? 5 : 6)}
24 %em No errs here 24 %em No errs here
25 -= will_paginate @errs, :previous_label => '« Previous', :next_label => 'Next »'  
26 \ No newline at end of file 25 \ No newline at end of file
  26 += will_paginate @errs, :previous_label => '« Previous', :next_label => 'Next »'
app/views/errs/show.html.haml
@@ -6,11 +6,11 @@ @@ -6,11 +6,11 @@
6 %strong Environment: 6 %strong Environment:
7 = @err.environment 7 = @err.environment
8 %strong Last Notice: 8 %strong Last Notice:
9 - = @err.last_notice_at.to_s(:micro) 9 + = last_notice_at(@err).to_s(:micro)
10 - content_for :action_bar do 10 - content_for :action_bar do
11 %span= link_to 'resolve', resolve_app_err_path(@app, @err), :method => :put, :confirm => 'Seriously?', :class => 'resolve' if @err.unresolved? 11 %span= link_to 'resolve', resolve_app_err_path(@app, @err), :method => :put, :confirm => 'Seriously?', :class => 'resolve' if @err.unresolved?
12 12
13 -%h4= @notice.message 13 +%h4= @notice.try(:message)
14 14
15 = will_paginate @notices, :param_name => :notice, :page_links => false, :class => 'notice-pagination' 15 = will_paginate @notices, :param_name => :notice, :page_links => false, :class => 'notice-pagination'
16 viewing occurrence #{@notices.current_page} of #{@notices.total_pages} 16 viewing occurrence #{@notices.current_page} of #{@notices.total_pages}
@@ -23,22 +23,23 @@ viewing occurrence #{@notices.current_page} of #{@notices.total_pages} @@ -23,22 +23,23 @@ viewing occurrence #{@notices.current_page} of #{@notices.total_pages}
23 %li= link_to 'Parameters', '#params', :rel => 'params', :class => 'button' 23 %li= link_to 'Parameters', '#params', :rel => 'params', :class => 'button'
24 %li= link_to 'Session', '#session', :rel => 'session', :class => 'button' 24 %li= link_to 'Session', '#session', :rel => 'session', :class => 'button'
25 25
26 -#summary  
27 - %h3 Summary  
28 - = render 'notices/summary', :notice => @notice  
29 -  
30 -#backtrace  
31 - %h3 Backtrace  
32 - = render 'notices/backtrace', :lines => @notice.backtrace 26 +- if @notice
  27 + #summary
  28 + %h3 Summary
  29 + = render 'notices/summary', :notice => @notice
33 30
34 -#environment  
35 - %h3 Environment  
36 - = render 'notices/environment', :notice => @notice  
37 -  
38 -#params  
39 - %h3 Parameters  
40 - = render 'notices/params', :notice => @notice  
41 -  
42 -#session  
43 - %h3 Session  
44 - = render 'notices/session', :notice => @notice  
45 \ No newline at end of file 31 \ No newline at end of file
  32 + #backtrace
  33 + %h3 Backtrace
  34 + = render 'notices/backtrace', :lines => @notice.backtrace
  35 +
  36 + #environment
  37 + %h3 Environment
  38 + = render 'notices/environment', :notice => @notice
  39 +
  40 + #params
  41 + %h3 Parameters
  42 + = render 'notices/params', :notice => @notice
  43 +
  44 + #session
  45 + %h3 Session
  46 + = render 'notices/session', :notice => @notice
spec/controllers/apps_controller_spec.rb
@@ -32,12 +32,21 @@ describe AppsController do @@ -32,12 +32,21 @@ describe AppsController do
32 end 32 end
33 33
34 describe "GET /apps/:id" do 34 describe "GET /apps/:id" do
  35 + render_views
35 context 'logged in as an admin' do 36 context 'logged in as an admin' do
36 - it 'finds the app' do 37 + before(:each) do
37 sign_in Factory(:admin) 38 sign_in Factory(:admin)
38 - app = Factory(:app)  
39 - get :show, :id => app.id  
40 - assigns(:app).should == app 39 + @app = Factory(:app)
  40 + end
  41 +
  42 + it 'finds the app' do
  43 + get :show, :id => @app.id
  44 + assigns(:app).should == @app
  45 + end
  46 +
  47 + it "should not raise errors for app with err without notices" do
  48 + Factory :err, :app => @app
  49 + lambda { get :show, :id => @app.id }.should_not raise_error
41 end 50 end
42 end 51 end
43 52
spec/controllers/errs_controller_spec.rb
@@ -74,6 +74,8 @@ describe ErrsController do @@ -74,6 +74,8 @@ describe ErrsController do
74 end 74 end
75 75
76 describe "GET /apps/:app_id/errs/:id" do 76 describe "GET /apps/:app_id/errs/:id" do
  77 + render_views
  78 +
77 before do 79 before do
78 3.times { Factory(:notice, :err => err)} 80 3.times { Factory(:notice, :err => err)}
79 end 81 end
@@ -93,13 +95,9 @@ describe ErrsController do @@ -93,13 +95,9 @@ describe ErrsController do
93 assigns(:err).should == err 95 assigns(:err).should == err
94 end 96 end
95 97
96 - it "paginates the notices, 1 at a time" do  
97 - App.stub(:find).with(app.id).and_return(app)  
98 - app.errs.stub(:find).with(err.id).and_return(err)  
99 - err.notices.should_receive(:ordered).and_return(proxy = stub('proxy'))  
100 - proxy.should_receive(:paginate).with(:page => 3, :per_page => 1).  
101 - and_return(WillPaginate::Collection.new(1,1) << err.notices.first) 98 + it "successfully render page" do
102 get :show, :app_id => app.id, :id => err.id 99 get :show, :app_id => app.id, :id => err.id
  100 + response.should be_success
103 end 101 end
104 end 102 end
105 103