Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #24239 #24304

Merged
merged 1 commit into from
Apr 4, 2016
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions actionpack/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_controller/metal/cookies.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Cookies
extend ActiveSupport::Concern

included do
helper_method :cookies
helper_method :cookies if defined?(helper_method)
end

private
Expand Down
21 changes: 21 additions & 0 deletions actionpack/test/controller/api/with_cookies_test.rb
Original file line number Diff line number Diff line change
@@ -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