mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
commit
0f51dda718
3 changed files with 31 additions and 1 deletions
|
@ -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.
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ module ActionController #:nodoc:
|
|||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
helper_method :cookies
|
||||
helper_method :cookies if defined?(helper_method)
|
||||
end
|
||||
|
||||
private
|
||||
|
|
21
actionpack/test/controller/api/with_cookies_test.rb
Normal file
21
actionpack/test/controller/api/with_cookies_test.rb
Normal file
|
@ -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
|
Loading…
Reference in a new issue