aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorRyan T. Hosford <tad.hosford@gmail.com>2016-03-24 12:11:51 -0500
committerRyan T. Hosford <tad.hosford@gmail.com>2016-04-04 08:51:29 -0500
commitf99106805d7275c790466b31514e52544ee1a8d6 (patch)
tree3cf2e494efabdb81716b6b6ade3834faa4ea5747 /actionpack
parent8040e55063abde6eeaac2702ca9961ce34a2d6c7 (diff)
downloadrails-f99106805d7275c790466b31514e52544ee1a8d6.tar.gz
rails-f99106805d7275c790466b31514e52544ee1a8d6.tar.bz2
rails-f99106805d7275c790466b31514e52544ee1a8d6.zip
Fixes #24239
- skip calling helper_method if it's not there: if we don't have helpers, we needn't define one. - tests that an api controller can include and use ActionController::Cookies
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/CHANGELOG.md9
-rw-r--r--actionpack/lib/action_controller/metal/cookies.rb2
-rw-r--r--actionpack/test/controller/api/with_cookies_test.rb21
3 files changed, 31 insertions, 1 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md
index 7d400eaa22..20321eece4 100644
--- a/actionpack/CHANGELOG.md
+++ b/actionpack/CHANGELOG.md
@@ -1,3 +1,12 @@
+* Adds support for including ActionController::Cookies in API controllers.
+ Previously, including the module would raise when trying to define
+ a `cookies` helper method. Skip calling #helper_method if it is not
+ defined -- if we don't have helpers, we needn't define one.
+
+ Fixes #24304
+
+ *Ryan T. Hosford*
+
* ETags: Introduce `Response#strong_etag=` and `#weak_etag=` and analogous
options for `fresh_when` and `stale?`. `Response#etag=` sets a weak ETag.
diff --git a/actionpack/lib/action_controller/metal/cookies.rb b/actionpack/lib/action_controller/metal/cookies.rb
index f8efb2b076..44925641a1 100644
--- a/actionpack/lib/action_controller/metal/cookies.rb
+++ b/actionpack/lib/action_controller/metal/cookies.rb
@@ -3,7 +3,7 @@ module ActionController #:nodoc:
extend ActiveSupport::Concern
included do
- helper_method :cookies
+ helper_method :cookies if defined?(helper_method)
end
private
diff --git a/actionpack/test/controller/api/with_cookies_test.rb b/actionpack/test/controller/api/with_cookies_test.rb
new file mode 100644
index 0000000000..4491dc9002
--- /dev/null
+++ b/actionpack/test/controller/api/with_cookies_test.rb
@@ -0,0 +1,21 @@
+require 'abstract_unit'
+
+class WithCookiesController < ActionController::API
+ include ActionController::Cookies
+
+ def with_cookies
+ render plain: cookies[:foobar]
+ end
+end
+
+class WithCookiesTest < ActionController::TestCase
+ tests WithCookiesController
+
+ def test_with_cookies
+ request.cookies[:foobar] = 'bazbang'
+
+ get :with_cookies
+
+ assert_equal 'bazbang', response.body
+ end
+end