Update `cookies` helper on all HTTP requests #27586

Merged
merged 1 commit into from Jan 6, 2017

Projects

None yet

2 participants

@maclover7
Member
maclover7 commented Jan 5, 2017 edited

Summary

Regression introduced by ae29142 / 8363b87.

Previously, cookies were only updated on GET requests. Now we will
update the helper for all requests, as part of process. Added
regression tests for all available HTTP method helpers in
ActionController::TestCase.

Other Information

@maclover7 maclover7 Update `cookies` helper on all HTTP requests
Regression introduced by ae29142 / 8363b87.

Previously, cookies were only updated on `GET` requests. Now we will
update the helper for all requests, as part of `process`. Added
regression tests for all available HTTP method helpers in
`ActionController::TestCase`.
c5da641
@maclover7 maclover7 added the actionpack label Jan 5, 2017
@rafaelfranca rafaelfranca merged commit 5eff7a9 into rails:master Jan 6, 2017

1 of 2 checks passed

codeclimate Code Climate is analyzing this code.
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@rafaelfranca
Member

Backported in cf51e74

@maclover7 maclover7 deleted the maclover7:jm-fix-27584 branch Jan 6, 2017
@rafaelfranca
Member
rafaelfranca commented Jan 12, 2017 edited

This caused a regression:

begin
  require "bundler/inline"
rescue LoadError => e
  $stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
  raise e
end

gemfile(true) do
  source "https://rubygems.org"
  gem "rails", github: "rails/rails", branch: "5-0-stable"
  gem "pry-byebug"
end

require "action_controller/railtie"

class TestApp < Rails::Application
  config.root = File.dirname(__FILE__)
  config.session_store :cookie_store, key: "cookie_store_key"
  secrets.secret_token    = "secret_token"
  secrets.secret_key_base = "secret_key_base"

  config.logger = Logger.new($stdout)
  Rails.logger  = config.logger

  routes.draw do
    resources :users, only: [:index]
  end
end

class UsersController < ActionController::Base
  def index
    unless cookies[:name].present?
      cookies[:name] = "Alice"
    end
    render plain: "Home"
  end
end

require "minitest/autorun"
require "rack/test"

class UsersControllerTest < ActionController::TestCase
  setup do
    @controller = UsersController.new
    @routes = Rails.application.routes
  end

  test '#index sets a cookie if it is not already present' do
    get :index
    assert_response :ok
    assert_equal "Alice", cookies[:name]

    cookies[:name] = "Bob"

    get :index
    assert_response :ok
    assert_equal "Bob", cookies[:name]
  end
end

@davidcornu was taking a look but I'll revert it for now.

@rafaelfranca rafaelfranca added a commit that referenced this pull request Jan 12, 2017
@rafaelfranca rafaelfranca Revert "Merge pull request #27586 from maclover7/jm-fix-27584"
This reverts commit cf51e74.

Reason: It caused regression and the test case is in the issue.
2abcb99
@rafaelfranca rafaelfranca added a commit that referenced this pull request Jan 12, 2017
@rafaelfranca rafaelfranca Revert "Merge pull request #27586 from maclover7/jm-fix-27584"
This reverts commit 5eff7a9, reversing
changes made to 5f03172.

Reason: It caused a regression. The test case is on the PR.
6902ca5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment