Skip to content

Commit 6f80987

Browse files
committed
[LOCATION] Request eu checks if helper method defined
1 parent 1dc8f24 commit 6f80987

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

lib/action_pack/cloudfront/location_headers.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ module LocationHeaders
99
|RS|SK|SI|ES|SE|CH|UA|GB|VA|RS)$/ix
1010

1111
included do
12-
helper_method :request_eu?
12+
if respond_to?(:helper_method)
13+
helper_method :request_eu?
14+
end
1315
end
1416

1517
private

lib/action_pack/cloudfront/railtie.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class Railtie < ::Rails::Railtie
66

77
config.action_pack_cloudfront = ActiveSupport::OrderedOptions.new
88
config.action_pack_cloudfront.load_proxies = !::Rails.env.test? && !::Rails.env.development?
9+
config.action_pack_cloudfront.include_location_headers = true
910

1011
config.before_initialize do |app|
1112
if app.config.action_pack_cloudfront.load_proxies
@@ -17,9 +18,10 @@ class Railtie < ::Rails::Railtie
1718
end
1819

1920
config.to_prepare do
20-
::ApplicationController.send :include, ActionPack::Cloudfront::LocationHeaders
21+
if app.config.action_pack_cloudfront.include_location_headers
22+
::ApplicationController.send :include, ActionPack::Cloudfront::LocationHeaders
23+
end
2124
end
22-
2325
end
2426
end
2527
end
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
require 'test_helper'
2+
3+
class LocationHeadersTest < ActiveSupport::TestCase
4+
class ApplicationController < ActionController::Base
5+
include ActionPack::Cloudfront::LocationHeaders
6+
end
7+
8+
class ApiController < ActionController::API
9+
include ActionPack::Cloudfront::LocationHeaders
10+
end
11+
12+
test '#request_eu? - includes when has helper method' do
13+
assert_includes ApplicationController._helper_methods, :request_eu?
14+
assert_nil ApiController.try(:_helper_methods)
15+
end
16+
end

0 commit comments

Comments
 (0)