Commit 4e9c6334e8a7ac23bd86fa2b62d4456119a47764
Exists in
master
and in
1 other branch
Merge branch 'master' of http://github.com/jdpace/errbit
Showing
8 changed files
with
36 additions
and
69 deletions
Show diff stats
Gemfile
Gemfile.lock
| ... | ... | @@ -61,7 +61,11 @@ GEM |
| 61 | 61 | haml (3.0.25) |
| 62 | 62 | happymapper (0.3.2) |
| 63 | 63 | libxml-ruby (~> 1.1.3) |
| 64 | + has_scope (0.5.1) | |
| 64 | 65 | i18n (0.5.0) |
| 66 | + inherited_resources (1.2.2) | |
| 67 | + has_scope (~> 0.5.0) | |
| 68 | + responders (~> 0.6.0) | |
| 65 | 69 | libxml-ruby (1.1.4) |
| 66 | 70 | lighthouse-api (2.0) |
| 67 | 71 | activeresource (>= 3.0.0) |
| ... | ... | @@ -110,6 +114,7 @@ GEM |
| 110 | 114 | rake (>= 0.8.7) |
| 111 | 115 | thor (~> 0.14.4) |
| 112 | 116 | rake (0.8.7) |
| 117 | + responders (0.6.4) | |
| 113 | 118 | rest-client (1.5.1) |
| 114 | 119 | mime-types (>= 1.16) |
| 115 | 120 | rspec (2.5.0) |
| ... | ... | @@ -157,6 +162,7 @@ DEPENDENCIES |
| 157 | 162 | email_spec |
| 158 | 163 | factory_girl_rails |
| 159 | 164 | haml |
| 165 | + inherited_resources | |
| 160 | 166 | lighthouse-api |
| 161 | 167 | mongoid (= 2.0.2) |
| 162 | 168 | mongoid_rails_migrations | ... | ... |
app/controllers/apps_controller.rb
| 1 | -class AppsController < ApplicationController | |
| 1 | +class AppsController < InheritedResources::Base | |
| 2 | 2 | |
| 3 | 3 | before_filter :require_admin!, :except => [:index, :show] |
| 4 | - before_filter :find_app, :except => [:index, :new, :create] | |
| 5 | 4 | before_filter :parse_email_at_notices_or_set_default, :only => [:create, :update] |
| 6 | 5 | |
| 7 | - def index | |
| 8 | - @apps = current_user.admin? ? App.all : current_user.apps.all | |
| 9 | - end | |
| 10 | - | |
| 11 | 6 | def show |
| 12 | 7 | where_clause = {} |
| 13 | 8 | respond_to do |format| |
| 14 | 9 | format.html do |
| 15 | 10 | where_clause[:environment] = params[:environment] if(params[:environment].present?) |
| 16 | 11 | if(params[:all_errs]) |
| 17 | - @errs = @app.errs.where(where_clause).ordered.paginate(:page => params[:page], :per_page => current_user.per_page) | |
| 12 | + @errs = resource.errs.where(where_clause).ordered.paginate(:page => params[:page], :per_page => current_user.per_page) | |
| 18 | 13 | @all_errs = true |
| 19 | 14 | else |
| 20 | - @errs = @app.errs.unresolved.where(where_clause).ordered.paginate(:page => params[:page], :per_page => current_user.per_page) | |
| 15 | + @errs = resource.errs.unresolved.where(where_clause).ordered.paginate(:page => params[:page], :per_page => current_user.per_page) | |
| 21 | 16 | @all_errs = false |
| 22 | 17 | end |
| 23 | 18 | @deploys = @app.deploys.order_by(:created_at.desc).limit(5) |
| 24 | 19 | end |
| 25 | 20 | format.atom do |
| 26 | - @errs = @app.errs.unresolved.ordered | |
| 21 | + @errs = resource.errs.unresolved.ordered | |
| 27 | 22 | end |
| 28 | 23 | end |
| 29 | 24 | end |
| 30 | 25 | |
| 31 | 26 | def new |
| 32 | - @app = App.new | |
| 33 | - @app.watchers.build | |
| 27 | + build_resource.watchers.build | |
| 34 | 28 | @app.issue_tracker = IssueTracker.new |
| 29 | + new! | |
| 35 | 30 | end |
| 36 | 31 | |
| 37 | 32 | def edit |
| 38 | - @app.watchers.build if @app.watchers.none? | |
| 39 | - @app.issue_tracker = IssueTracker.new if @app.issue_tracker.nil? | |
| 33 | + resource.watchers.build if resource.watchers.none? | |
| 34 | + resource.issue_tracker = IssueTracker.new if resource.issue_tracker.nil? | |
| 35 | + edit! | |
| 40 | 36 | end |
| 41 | 37 | |
| 42 | 38 | def create |
| 43 | - @app = App.new(params[:app]) | |
| 44 | - | |
| 45 | - if @app.save | |
| 46 | - flash[:success] = 'Great success! Configure your app with the API key below' | |
| 47 | - redirect_to app_path(@app) | |
| 48 | - else | |
| 49 | - render :new | |
| 50 | - end | |
| 39 | + create! :success => 'Great success! Configure your app with the API key below' | |
| 51 | 40 | end |
| 52 | 41 | |
| 53 | 42 | def update |
| 54 | - if @app.update_attributes(params[:app]) | |
| 55 | - flash[:success] = "Good news everyone! '#{@app.name}' was successfully updated." | |
| 56 | - redirect_to app_path(@app) | |
| 57 | - else | |
| 58 | - render :edit | |
| 59 | - end | |
| 43 | + update! :success => "Good news everyone! '#{resource.name}' was successfully updated." | |
| 60 | 44 | end |
| 61 | 45 | |
| 62 | 46 | def destroy |
| 63 | - @app.destroy | |
| 64 | - flash[:success] = "'#{@app.name}' was successfully destroyed." | |
| 65 | - redirect_to apps_path | |
| 47 | + destroy! :success => "'#{resource.name}' was successfully destroyed." | |
| 66 | 48 | end |
| 67 | 49 | |
| 68 | 50 | protected |
| 69 | - | |
| 70 | - def find_app | |
| 71 | - @app = App.find(params[:id]) | |
| 72 | - | |
| 73 | - # Mongoid Bug: could not chain: current_user.apps.find_by_id! | |
| 74 | - # apparently finding by 'watchers.email' and 'id' is broken | |
| 75 | - raise(Mongoid::Errors::DocumentNotFound.new(App,@app.id)) unless current_user.admin? || current_user.watching?(@app) | |
| 51 | + def begin_of_association_chain | |
| 52 | + current_user unless current_user.admin? | |
| 76 | 53 | end |
| 77 | 54 | |
| 78 | 55 | # email_at_notices is edited as a string, and stored as an array. | ... | ... |
app/models/app.rb
| ... | ... | @@ -39,9 +39,8 @@ class App |
| 39 | 39 | accepts_nested_attributes_for :issue_tracker, :allow_destroy => true, |
| 40 | 40 | :reject_if => proc { |attrs| !%w(none lighthouseapp redmine pivotal fogbugz mingle).include?(attrs[:issue_tracker_type]) } |
| 41 | 41 | |
| 42 | - # Mongoid Bug: find(id) on association proxies returns an Enumerator | |
| 43 | 42 | def self.find_by_id!(app_id) |
| 44 | - where(:_id => app_id).first || raise(Mongoid::Errors::DocumentNotFound.new(self,app_id)) | |
| 43 | + find app_id | |
| 45 | 44 | end |
| 46 | 45 | |
| 47 | 46 | def self.find_by_api_key!(key) | ... | ... |
app/models/user.rb
| ... | ... | @@ -19,28 +19,21 @@ class User |
| 19 | 19 | |
| 20 | 20 | attr_protected :admin |
| 21 | 21 | |
| 22 | + has_many :apps, :foreign_key => 'watchers.user_id' | |
| 23 | + | |
| 22 | 24 | if Errbit::Config.user_has_username |
| 23 | 25 | field :username |
| 24 | 26 | validates_presence_of :username |
| 25 | 27 | end |
| 26 | 28 | |
| 27 | - # Mongoid doesn't seem to currently support | |
| 28 | - # referencing embedded documents | |
| 29 | 29 | def watchers |
| 30 | - App.all.map(&:watchers).flatten.select {|w| w.user_id.to_s == id.to_s} | |
| 30 | + apps.map(&:watchers).flatten.select {|w| w.user_id.to_s == id.to_s} | |
| 31 | 31 | end |
| 32 | 32 | |
| 33 | 33 | def per_page |
| 34 | 34 | self[:per_page] || PER_PAGE |
| 35 | 35 | end |
| 36 | 36 | |
| 37 | - def apps | |
| 38 | - # This is completely wasteful but became necessary | |
| 39 | - # due to bugs in Mongoid | |
| 40 | - app_ids = watchers.map {|w| w.app.id} | |
| 41 | - App.any_in(:_id => app_ids) | |
| 42 | - end | |
| 43 | - | |
| 44 | 37 | def watching?(app) |
| 45 | 38 | apps.all.include?(app) |
| 46 | 39 | end | ... | ... |
app/models/watcher.rb
app/views/errs/redmine_body.txt.erb
| 1 | -"See this exception on Errbit":<%= app_err_url err.app, err %> | |
| 2 | 1 | <% if notice = err.notices.first %> |
| 3 | 2 | h1. <%= notice.message %> |
| 4 | 3 | |
| 4 | +h3. "See this exception on Errbit":<%= app_err_url err.app, err %> | |
| 5 | + | |
| 5 | 6 | h2. Summary |
| 6 | 7 | <% if notice.request['url'].present? %> |
| 7 | 8 | h3. URL |
| ... | ... | @@ -30,16 +31,14 @@ h2. Session |
| 30 | 31 | |
| 31 | 32 | h2. Backtrace |
| 32 | 33 | |
| 33 | -<pre> | |
| 34 | -<% for line in notice.backtrace %><%= line['number'] %>: <%= line['file'].sub(/^\[PROJECT_ROOT\]/, '') %> -> *<%= line['method'] %>* | |
| 34 | +| Line | File | Method | | |
| 35 | +<% for line in notice.backtrace %>| <%= line['number'] %> | <%= line['file'].sub(/^\[PROJECT_ROOT\]/, '') %> | *<%= line['method'] %>* | | |
| 35 | 36 | <% end %> |
| 36 | -</pre> | |
| 37 | 37 | |
| 38 | 38 | h2. Environment |
| 39 | 39 | |
| 40 | -<pre> | |
| 41 | -<% for key, val in notice.env_vars %> | |
| 42 | -<%= key %>: <%= val %> | |
| 40 | +<% for key, val in notice.env_vars %>| <%= key %> | <%= val %> | | |
| 43 | 41 | <% end %> |
| 44 | -</pre> | |
| 42 | + | |
| 45 | 43 | <% end %> |
| 44 | + | ... | ... |
spec/controllers/apps_controller_spec.rb
| ... | ... | @@ -201,15 +201,7 @@ describe AppsController do |
| 201 | 201 | |
| 202 | 202 | it "should display a message" do |
| 203 | 203 | post :create, :app => {} |
| 204 | - request.flash[:success].should match(/success/) | |
| 205 | - end | |
| 206 | - end | |
| 207 | - | |
| 208 | - context "when the create is unsuccessful" do | |
| 209 | - it "should render the new page" do | |
| 210 | - @app.should_receive(:save).and_return(false) | |
| 211 | - post :create, :app => {} | |
| 212 | - response.should render_template(:new) | |
| 204 | + request.flash[:notice].should match(/success/) | |
| 213 | 205 | end |
| 214 | 206 | end |
| 215 | 207 | end |
| ... | ... | @@ -227,7 +219,7 @@ describe AppsController do |
| 227 | 219 | |
| 228 | 220 | it "should display a message" do |
| 229 | 221 | put :update, :id => @app.id, :app => {} |
| 230 | - request.flash[:success].should match(/success/) | |
| 222 | + request.flash[:notice].should match(/success/) | |
| 231 | 223 | end |
| 232 | 224 | end |
| 233 | 225 | |
| ... | ... | @@ -432,7 +424,7 @@ describe AppsController do |
| 432 | 424 | |
| 433 | 425 | it "should display a message" do |
| 434 | 426 | delete :destroy, :id => @app.id |
| 435 | - request.flash[:success].should match(/success/) | |
| 427 | + request.flash[:notice].should match(/success/) | |
| 436 | 428 | end |
| 437 | 429 | |
| 438 | 430 | it "should redirect to the apps page" do | ... | ... |