Skip to content

Commit

Permalink
Fix Rails 3.2 compatibility by not using try
Browse files Browse the repository at this point in the history
The ActiveSupport `try` method works differently in different versions of Rails.
In some versions it checks `respond_to?`; others do not. It is safer (and more
compatible) to explicitly use `respond_to?` instead.
  • Loading branch information
mattbrictson committed May 20, 2016
1 parent 237514e commit 597947d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ lesser changes or bug fixes.
## [Unreleased][]

* Your contribution here!
* Fix a regression in 0.1.20 that broke Rails 3.2 apps
[#72](https://github.com/brentd/xray-rails/pull/72)

## [0.1.20][] (2016-05-18)

Expand Down
6 changes: 5 additions & 1 deletion lib/xray/middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def call(env)
# Modifying the original response obj maintains compatibility with other middlewares
if ActionDispatch::Response === response
response.body = [body]
response.header['Content-Length'] = content_length unless response.try(:committed?)
response.header['Content-Length'] = content_length unless committed?(response)
response.to_a
else
headers['Content-Length'] = content_length
Expand All @@ -73,6 +73,10 @@ def call(env)

private

def committed?(response)
response.respond_to?(:committed?) && response.committed?
end

def inject_xray_bar!(html)
html.sub!(/<body[^>]*>/) { "#{$~}\n#{render_xray_bar}" }
end
Expand Down

0 comments on commit 597947d

Please sign in to comment.