Skip to content
This repository has been archived by the owner on Dec 1, 2020. It is now read-only.

Commit

Permalink
Added ExceptionManager dependency. Added example of how bindings of a…
Browse files Browse the repository at this point in the history
…ll exceptions can be persisted.
  • Loading branch information
iliabylich committed Nov 20, 2015
1 parent 8b32ed8 commit 770ec23
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 22 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ rvm:
- 2.1.7
- 2.1.6
- 2.0.0
- ruby-1.9.3-p551
before_script:
- bin/dummy_rake db:create db:migrate
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ gem 'rails-dummy'
gem 'sqlite3'
gem 'pry'
gem 'rspec-rails'
gem 'exception_manager'
gem 'binding_of_caller'
5 changes: 4 additions & 1 deletion lib/binding_dumper/core_ext/binding_ext.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'uri'

# Module with patches for Binding class
#
# @example
Expand Down Expand Up @@ -45,6 +47,7 @@ def data_to_dump
#
def dump(&block)
dumped = UniversalDumper.dump(data_to_dump)
dumped = URI.encode(dumped)
block.call(dumped) if block_given?
dumped
end
Expand All @@ -55,7 +58,7 @@ module ClassMethods
# @return [Binding]
#
def load(dumped)
undumped = UniversalDumper.load(dumped)
undumped = UniversalDumper.load(URI.decode(dumped))

mod = MagicContextPatchBuilder.new(undumped).patch

Expand Down
1 change: 1 addition & 0 deletions lib/binding_dumper/load_support/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ def column_with_binding
end

def stored_binding
require 'rails/backtrace_cleaner'
BindingDumper::UniversalDumper.flush_memories!
data = read_attribute(column_with_binding)
Binding.load(data)
Expand Down
15 changes: 0 additions & 15 deletions spec/binding_dumper/functional/users_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,5 @@
expect(params[:limit]).to eq('10')
end
end

context 'response' do
before do
User.create(email: 'test@email.com')
get :index
end

let(:raw_response) { stored_binding.eval('response') }
subject(:response) { JSON.parse(raw_response.body) }

it 'returns existing users' do
expect(response).to be_an(Array)
expect(response.length).to eq(1)
end
end
end
end
7 changes: 7 additions & 0 deletions spec/dummy/app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,11 @@ class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception

rescue_from Exception, with: :log_binding

def log_binding(e)
StoredBinding.create(data: e._binding.dump)
render json: {}
end
end
11 changes: 6 additions & 5 deletions spec/dummy/app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
class UsersController < ApplicationController
def index
render json: some_helper_method
end

def some_helper_method
@users = User.all.to_a
some_proc = proc { 1 + 1 }
render json: @users

binding.dump do |data|
StoredBinding.create(data: data.force_encoding('utf-8'))
end
raise 'oh'
[]
end
end
1 change: 1 addition & 0 deletions spec/dummy/config/initializers/binding_dumper.rb
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
BindingDumper::MagicObjects.register(Rails)
ExceptionManager.enable!

0 comments on commit 770ec23

Please sign in to comment.