Skip to content

Commit

Permalink
Removing test gem. Conditionally loading rescuers to check for specif…
Browse files Browse the repository at this point in the history
…ic loading ORM. Cleanup test code.
  • Loading branch information
David Czarnecki committed Oct 12, 2011
1 parent 959b371 commit dd3d057
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 16 deletions.
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ end
group :test do
gem 'rails', '3.1.0'
gem 'sqlite3-ruby'
gem 'turn'
gem 'mocha', :require => false
gem 'mongoid'
gem 'mongo_mapper'
Expand Down
13 changes: 6 additions & 7 deletions lib/errship.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'rescuers/active_record'
require 'rescuers/mongoid'
require 'rescuers/mongo_mapper'
require 'rescuers/active_record' if defined?(::ActiveRecord)
require 'rescuers/mongoid' if defined?(::Mongoid)
require 'rescuers/mongo_mapper' if defined?(::MongoMapper)

module Errship
class Engine < ::Rails::Engine
Expand All @@ -12,7 +12,6 @@ class Engine < ::Rails::Engine
module Rescuers
def self.included(base)
unless Rails.application.config.consider_all_requests_local
base.rescue_from Exception, :with => :render_error
base.rescue_from ActionController::RoutingError, :with => :render_404_error
base.rescue_from ActionController::UnknownController, :with => :render_404_error
base.rescue_from ActionController::UnknownAction, :with => :render_404_error
Expand All @@ -21,20 +20,20 @@ def self.included(base)

def render_error(exception, errship_scope = false)
airbrake_class.send(:notify, exception) if airbrake_class
render :template => '/errship/standard', :locals => {
render :template => '/errship/standard', :locals => {
:status_code => 500, :errship_scope => errship_scope }
end

def render_404_error(exception = nil, errship_scope = false)
render :template => '/errship/standard', :locals => {
render :template => '/errship/standard', :locals => {
:status_code => 404, :errship_scope => errship_scope }
end

# A blank page with just the layout and flash message, which can be redirected to when
# all else fails.
def errship_standard(errship_scope = false)
flash[:error] ||= 'An unknown error has occurred, or you have reached this page by mistake.'
render :template => '/errship/standard', :locals => {
render :template => '/errship/standard', :locals => {
:status_code => 500, :errship_scope => errship_scope }
end

Expand Down
1 change: 0 additions & 1 deletion test/sandbox/app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

class ApplicationController < ActionController::Base
include Errship::Rescuers
include Errship::ActiveRecord::Rescuers
protect_from_forgery

def try_flashback
Expand Down
2 changes: 1 addition & 1 deletion test/sandbox/app/controllers/brains_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ class BrainsController < ApplicationController
include Errship::ActiveRecord::Rescuers

def index
raise ActiveRecord::RecordNotFound
raise ActiveRecord::RecordNotFound.new
end
end
2 changes: 1 addition & 1 deletion test/sandbox/app/controllers/humans_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ class HumansController < ApplicationController
include Errship::MongoMapper::Rescuers

def index
raise MongoMapper::DocumentNotFound
raise MongoMapper::DocumentNotFound.new
end
end
2 changes: 1 addition & 1 deletion test/sandbox/app/controllers/zombies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ class ZombiesController < ApplicationController
include Errship::Mongoid::Rescuers

def index
raise Mongoid::Errors::DocumentNotFound
raise Mongoid::Errors::DocumentNotFound.new(User, 1)
end
end
2 changes: 1 addition & 1 deletion test/sandbox/config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Sandbox::Application.routes.draw do
match '/try_flashback', :controller => 'application', :action => 'try_flashback'
match '/brains', :controller => 'brains', :action => 'index'
match '/zombies', :controller => 'zombies', :action => 'index'
match '/humans', :controller => 'humans', :action => 'index'
match '/zombies', :controller => 'zombies', :action => 'index'
end
2 changes: 1 addition & 1 deletion test/sandbox/test/functional/brains_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class BrainsControllerTest < ActionController::TestCase
test "/error routes to errship's standard error page with ActiveRecord::RecordNotFound" do
Errship::Rescuers.expects(:render_404_error).with(ActiveRecord::RecordNotFound, anything)
@controller.expects(:render_404_error).with(anything)

get :index
end
Expand Down
2 changes: 1 addition & 1 deletion test/sandbox/test/functional/humans_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class HumansControllerTest < ActionController::TestCase
test "/error routes to errship's standard error page with MongoMapper::DocumentNotFound exception" do
Errship::Rescuers.expects(:render_404_error).with(MongoMapper::DocumentNotFound, anything)
@controller.expects(:render_404_error).with(anything)

get :index
end
Expand Down
2 changes: 1 addition & 1 deletion test/sandbox/test/functional/zombies_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class ZombiesControllerTest < ActionController::TestCase
test "/error routes to errship's standard error page with Mongoid::Errors::DocumentNotFound" do
Errship::Rescuers.expects(:render_404_error).with(Mongoid::Errors::DocumentNotFound, anything)
@controller.expects(:render_404_error).with(anything)

get :index
end
Expand Down
2 changes: 2 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))

require 'mongoid'
require 'mongo_mapper'

# Run the tests for the sandbox (dummy) application
ENV['RAILS_ENV'] = 'test'
Expand Down

0 comments on commit dd3d057

Please sign in to comment.