Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions activeresource-response.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Gem::Specification.new do |s|
s.license = 'MIT'

s.add_runtime_dependency('activeresource', ['>= 6.1', '< 6.3'])
s.add_dependency 'activesupport'
s.add_dependency "jruby-openssl" if RUBY_PLATFORM == "java"
s.add_development_dependency "minitest"
s.add_development_dependency 'rake'
Expand Down
20 changes: 14 additions & 6 deletions lib/active_resource_response/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@
#++
module ActiveResourceResponse
module Connection
class Current < ActiveSupport::CurrentAttributes
attribute :http_responses, default: {}

Comment on lines +25 to +27

Copilot AI Mar 5, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ActiveSupport::CurrentAttributes is referenced here, but the gem doesn’t explicitly require it anywhere. Depending on what activeresource loads, this can raise NameError: uninitialized constant ActiveSupport::CurrentAttributes when requiring active_resource_response. Consider adding an explicit require 'active_support/current_attributes' (or require 'active_support') before this class is defined so the dependency is reliably loaded.

Copilot uses AI. Check for mistakes.
def http_response(klass)
http_responses[klass]
end

def set_http_response(klass, response)
http_responses[klass] = response
end
end

def self.included(base)
base.class_eval do
alias_method :origin_handle_response, :handle_response
Expand All @@ -38,15 +50,11 @@ def handle_response(response)
end

def http_response
http_storage[:ActiveResourceResponse]
Current.http_response(self.class)
end

def http_response=(response)
http_storage[:ActiveResourceResponse] = response
end

def http_storage
Thread.current
Current.set_http_response self.class, response
end
end
end
Expand Down
4 changes: 3 additions & 1 deletion test/active_resource_response_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ def setup
mock.get "/streets/1/city.json", {}, @city.to_json, 200, {"X-total"=>'1'}
mock.get "/streets/1.json", {}, @street.to_json, 200, {"X-total"=>'1'}
end

ActiveResourceResponse::Connection::Current.reset
end


Expand Down Expand Up @@ -115,7 +117,7 @@ def test_get_headers_from_find_when_404_custom_get
end

def test_get_headers_from_find_when_404_custom_prefix
Status.all params: { country_id: 1 }
Status.all(params: { country_id: 1 }).to_a
assert_equal Status.http_response.code, 404
end

Expand Down