From 561fe09b5103cbf88f394e7b06676e62c5741f3a Mon Sep 17 00:00:00 2001 From: eileencodes Date: Sun, 10 Jan 2016 16:50:09 -0500 Subject: [PATCH 1/9] Upgrade gem to Rails 5 This sets the dependency to allow Rails 5. In upgrading to Rails 5 we require Ruby 2 and changes that are made here will not work on older versions of Rails. Because of that I'm bumping the version to 2.0.0. --- Gemfile | 2 +- actionpack-action_caching.gemspec | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index ef52326..2d9fcfb 100644 --- a/Gemfile +++ b/Gemfile @@ -2,4 +2,4 @@ source 'https://rubygems.org' gemspec -gem 'rails' +gem 'rails', github: 'rails/rails' diff --git a/actionpack-action_caching.gemspec b/actionpack-action_caching.gemspec index 58367c5..5d3e0f6 100644 --- a/actionpack-action_caching.gemspec +++ b/actionpack-action_caching.gemspec @@ -2,7 +2,7 @@ Gem::Specification.new do |gem| gem.name = 'actionpack-action_caching' - gem.version = '1.1.0' + gem.version = '2.0.0' gem.author = 'David Heinemeier Hansson' gem.email = 'david@loudthinking.com' gem.description = 'Action caching for Action Pack (removed from core in Rails 4.0)' @@ -15,8 +15,8 @@ Gem::Specification.new do |gem| gem.require_paths = ['lib'] gem.license = 'MIT' - gem.add_dependency 'actionpack', '>= 4.0.0', '< 5.0' + gem.add_dependency 'actionpack', '~> 5.x' gem.add_development_dependency 'mocha' - gem.add_development_dependency 'activerecord', '>= 4.0.0.beta', '< 5' + gem.add_development_dependency 'activerecord', '~> 5.x' end From 7debe89a71f2f87191772afa45be0b4f9b2b897f Mon Sep 17 00:00:00 2001 From: eileencodes Date: Sun, 10 Jan 2016 16:52:38 -0500 Subject: [PATCH 2/9] Change `*_filter` to `*_action` `before_filter` is now `before_action`. I've changed this to remove the deprecation warning. --- README.md | 4 ++-- lib/action_controller/caching/actions.rb | 6 +++--- test/caching_test.rb | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index ec694a7..371a394 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ authentication and other restrictions on whether someone is allowed to execute such action. class ListsController < ApplicationController - before_filter :authenticate, except: :public + before_action :authenticate, except: :public caches_page :public caches_action :index, :show @@ -72,7 +72,7 @@ interval (in seconds) to schedule expiration of the cached item. The following example depicts some of the points made above: class ListsController < ApplicationController - before_filter :authenticate, except: :public + before_action :authenticate, except: :public caches_page :public diff --git a/lib/action_controller/caching/actions.rb b/lib/action_controller/caching/actions.rb index 18e5909..1a062c7 100644 --- a/lib/action_controller/caching/actions.rb +++ b/lib/action_controller/caching/actions.rb @@ -10,7 +10,7 @@ module Caching # to execute such action. # # class ListsController < ApplicationController - # before_filter :authenticate, except: :public + # before_action :authenticate, except: :public # # caches_page :public # caches_action :index, :show @@ -66,7 +66,7 @@ module Caching # # # class ListsController < ApplicationController - # before_filter :authenticate, except: :public + # before_action :authenticate, except: :public # # caches_page :public # @@ -113,7 +113,7 @@ def caches_action(*actions) filter_options = options.extract!(:if, :unless).merge(only: actions) cache_options = options.extract!(:layout, :cache_path).merge(store_options: options) - around_filter ActionCacheFilter.new(cache_options), filter_options + around_action ActionCacheFilter.new(cache_options), filter_options end end diff --git a/test/caching_test.rb b/test/caching_test.rb index 53f99ab..af229f5 100644 --- a/test/caching_test.rb +++ b/test/caching_test.rb @@ -25,9 +25,9 @@ class ActionCachingTestController < CachingController end # Eliminate uninitialized ivar warning - before_filter { @title = nil } + before_action { @title = nil } - before_filter only: :with_symbol_format do + before_action only: :with_symbol_format do request.params[:format] = :json end From e2c015dceef8386d93314b1c7b0507d612cf5c10 Mon Sep 17 00:00:00 2001 From: eileencodes Date: Sun, 10 Jan 2016 16:53:31 -0500 Subject: [PATCH 3/9] Fix render text deprecation warning `render text:` is no longer a valid way to render just text content. The correct way is to use `render plain:`. `render text:` is deprecated. --- lib/action_controller/caching/actions.rb | 2 +- test/caching_test.rb | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/action_controller/caching/actions.rb b/lib/action_controller/caching/actions.rb index 1a062c7..bde10e7 100644 --- a/lib/action_controller/caching/actions.rb +++ b/lib/action_controller/caching/actions.rb @@ -173,7 +173,7 @@ def around(controller) body = controller._save_fragment(cache_path.path, @store_options) end - body = controller.render_to_string(text: body, layout: true) unless cache_layout + body = controller.render_to_string(plain: body, layout: true) unless cache_layout controller.response_body = body controller.content_type = Mime[cache_path.extension || :html] diff --git a/test/caching_test.rb b/test/caching_test.rb index af229f5..2b21f98 100644 --- a/test/caching_test.rb +++ b/test/caching_test.rb @@ -48,7 +48,7 @@ class ActionCachingTestController < CachingController def index @cache_this = MockTime.now.to_f.to_s - render text: @cache_this + render plain: @cache_this end def redirected @@ -56,19 +56,19 @@ def redirected end def forbidden - render text: 'Forbidden' + render plain: 'Forbidden' response.status = '403 Forbidden' end def with_layout @cache_this = MockTime.now.to_f.to_s @title = nil - render text: @cache_this, layout: true + render plain: @cache_this, layout: true end def with_format_and_http_param @cache_this = MockTime.now.to_f.to_s - render text: @cache_this + render plain: @cache_this end def with_symbol_format @@ -81,7 +81,7 @@ def record_not_found end def four_oh_four - render text: "404'd!", status: 404 + render plain: "404'd!", status: 404 end def simple_runtime_error @@ -111,7 +111,7 @@ def expire_with_url_string end def streaming - render text: 'streaming', stream: true + render plain: 'streaming', stream: true end def invalid From f7d0e5468178941f96d25c9f624ebe6b92a781d4 Mon Sep 17 00:00:00 2001 From: eileencodes Date: Sun, 10 Jan 2016 16:53:55 -0500 Subject: [PATCH 4/9] Fix keyword args dep notice Rails now requires kwargs in test requests. This sets `params`, `format`, and `headers` accordingly to fix the deprecation warning. --- test/caching_test.rb | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/test/caching_test.rb b/test/caching_test.rb index 2b21f98..7dc5d34 100644 --- a/test/caching_test.rb +++ b/test/caching_test.rb @@ -239,13 +239,13 @@ def test_action_cache_with_layout_and_layout_cache_false end def test_action_cache_with_layout_and_layout_cache_false_via_proc - get :with_layout_proc_param, layout: false + get :with_layout_proc_param, params: { layout: false } assert_response :success cached_time = content_to_cache assert_not_equal cached_time, @response.body assert fragment_exist?('hostname.com/action_caching_test/with_layout_proc_param') - get :with_layout_proc_param, layout: false + get :with_layout_proc_param, params: { layout: false } assert_response :success assert_not_equal cached_time, @response.body body = body_to_string(read_fragment('hostname.com/action_caching_test/with_layout_proc_param')) @@ -253,13 +253,13 @@ def test_action_cache_with_layout_and_layout_cache_false_via_proc end def test_action_cache_with_layout_and_layout_cache_true_via_proc - get :with_layout_proc_param, layout: true + get :with_layout_proc_param, params: { layout: true } assert_response :success cached_time = content_to_cache assert_not_equal cached_time, @response.body assert fragment_exist?('hostname.com/action_caching_test/with_layout_proc_param') - get :with_layout_proc_param, layout: true + get :with_layout_proc_param, params: { layout: true } assert_response :success assert_not_equal cached_time, @response.body body = body_to_string(read_fragment('hostname.com/action_caching_test/with_layout_proc_param')) @@ -312,7 +312,7 @@ def test_action_cache_with_custom_cache_path_in_block assert_response :success assert fragment_exist?('test.host/edit') - get :edit, id: 1 + get :edit, params: { id: 1 } assert_response :success assert fragment_exist?('test.host/1;edit') end @@ -322,7 +322,7 @@ def test_action_cache_with_custom_cache_path_with_custom_object assert_response :success assert fragment_exist?('controller') - get :custom_cache_path, id: 1 + get :custom_cache_path, params: { id: 1 } assert_response :success assert fragment_exist?('controller-1') end @@ -440,8 +440,8 @@ def test_xml_version_of_resource_is_treated_as_different_cache def test_correct_content_type_is_returned_for_cache_hit # run it twice to cache it the first time - get :index, id: 'content-type', format: 'xml' - get :index, id: 'content-type', format: 'xml' + get :index, params: { id: 'content-type' }, format: 'xml' + get :index, params: { id: 'content-type' }, format: 'xml' assert_response :success assert_equal 'application/xml', @response.content_type end @@ -456,8 +456,8 @@ def test_correct_content_type_is_returned_for_cache_hit_on_action_with_string_ke def test_correct_content_type_is_returned_for_cache_hit_on_action_with_string_key_from_proc # run it twice to cache it the first time - get :edit, id: 1, format: 'xml' - get :edit, id: 1, format: 'xml' + get :edit, params: { id: 1 }, format: 'xml' + get :edit, params: { id: 1 }, format: 'xml' assert_response :success assert_equal 'application/xml', @response.content_type end @@ -470,8 +470,8 @@ def test_empty_path_is_normalized end def test_file_extensions - get :index, id: 'kitten.jpg' - get :index, id: 'kitten.jpg' + get :index, params: { id: 'kitten.jpg' } + get :index, params: { id: 'kitten.jpg' } assert_response :success end From a16f8310036635b10ab7706db8df57ecedb2649a Mon Sep 17 00:00:00 2001 From: eileencodes Date: Sun, 10 Jan 2016 17:29:07 -0500 Subject: [PATCH 5/9] Fix render nothing deprecation warning `render nothing:` is deprecated. If you want nothing rendered you should use `head :ok`. --- test/caching_test.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/caching_test.rb b/test/caching_test.rb index 7dc5d34..d2ad4ea 100644 --- a/test/caching_test.rb +++ b/test/caching_test.rb @@ -97,17 +97,17 @@ def simple_runtime_error def expire expire_action controller: 'action_caching_test', action: 'index' - render nothing: true + head :ok end def expire_xml expire_action controller: 'action_caching_test', action: 'index', format: 'xml' - render nothing: true + head :ok end def expire_with_url_string expire_action url_for(controller: 'action_caching_test', action: 'index') - render nothing: true + head :ok end def streaming From 061d61c2fbfa785ad65cfc4fd5d5df15abf1ec74 Mon Sep 17 00:00:00 2001 From: eileencodes Date: Sat, 30 Jan 2016 09:51:03 -0500 Subject: [PATCH 6/9] Check for false in proc In rails/rails@394b7be parameters set were changed to query strings to behave more like a real browser. In a browser the parameters `false` will never get sent as `false` and will always be `"false"`. Because of this change the test for passing `false` into this `Proc` was failing. We need to change it to check if the layout is not false rather than relying on the value in the parameters. --- test/caching_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/caching_test.rb b/test/caching_test.rb index d2ad4ea..5c985ea 100644 --- a/test/caching_test.rb +++ b/test/caching_test.rb @@ -39,7 +39,7 @@ class ActionCachingTestController < CachingController caches_action :with_format_and_http_param, cache_path: Proc.new { |c| { key: 'value' } } caches_action :with_symbol_format, cache_path: 'http://test.host/action_caching_test/with_symbol_format' caches_action :layout_false, layout: false - caches_action :with_layout_proc_param, layout: Proc.new { |c| c.params[:layout] } + caches_action :with_layout_proc_param, layout: Proc.new { |c| c.params[:layout] != "false" } caches_action :record_not_found, :four_oh_four, :simple_runtime_error caches_action :streaming caches_action :invalid From 38935afce2bbd8fd5bbbc5d769fb9631e433ca43 Mon Sep 17 00:00:00 2001 From: eileencodes Date: Sat, 30 Jan 2016 09:51:11 -0500 Subject: [PATCH 7/9] Replace use of assigns in test `assigns` was removed from Rails and using `instance_variable_get` is the new correct way to assign an instance variable in tests. --- test/caching_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/caching_test.rb b/test/caching_test.rb index 5c985ea..db9ac0e 100644 --- a/test/caching_test.rb +++ b/test/caching_test.rb @@ -533,7 +533,7 @@ def test_invalid_format_returns_not_acceptable private def content_to_cache - assigns(:cache_this) + @controller.instance_variable_get(:@cache_this) end def fragment_exist?(path) From 12d1f6e8c60fadf1ada5c249ae7f6b178294c3e7 Mon Sep 17 00:00:00 2001 From: eileencodes Date: Sat, 30 Jan 2016 10:08:36 -0500 Subject: [PATCH 8/9] Set Ruby version to 2.2.2 Rack and Rails require Ruby 2.2.2 so we need to upgrade travis to use only Ruby 2.2.2 and set the minimum version in the gemspec. This means we'll have to split this peripheral gem into 2 releases. One for the 4 apps and one for the 5 apps because the changes required by Rails 5 won't work on older version. --- .travis.yml | 4 +--- actionpack-action_caching.gemspec | 1 + gemfiles/Gemfile-4-0-stable | 5 ----- 3 files changed, 2 insertions(+), 8 deletions(-) delete mode 100644 gemfiles/Gemfile-4-0-stable diff --git a/.travis.yml b/.travis.yml index 5e74365..7995db4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,12 +2,10 @@ language: ruby before_install: - gem install bundler rvm: - - 1.9.3 - - 2.0.0 + - 2.2.2 gemfile: - Gemfile - gemfiles/Gemfile-edge - - gemfiles/Gemfile-4-0-stable matrix: allow_failures: - gemfile: gemfiles/Gemfile-edge diff --git a/actionpack-action_caching.gemspec b/actionpack-action_caching.gemspec index 5d3e0f6..6f95f59 100644 --- a/actionpack-action_caching.gemspec +++ b/actionpack-action_caching.gemspec @@ -9,6 +9,7 @@ Gem::Specification.new do |gem| gem.summary = 'Action caching for Action Pack (removed from core in Rails 4.0)' gem.homepage = 'https://github.com/rails/actionpack-action_caching' + gem.required_ruby_version = '>= 2.2.2' gem.files = `git ls-files`.split($/) gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) } gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) diff --git a/gemfiles/Gemfile-4-0-stable b/gemfiles/Gemfile-4-0-stable deleted file mode 100644 index c0cb216..0000000 --- a/gemfiles/Gemfile-4-0-stable +++ /dev/null @@ -1,5 +0,0 @@ -source 'https://rubygems.org' - -gemspec path: '..' - -gem 'rails', github: 'rails/rails', branch: '4-0-stable' From 20c50ad5203de3e2767e727c9a1f729e78238aae Mon Sep 17 00:00:00 2001 From: eileencodes Date: Sat, 30 Jan 2016 10:10:25 -0500 Subject: [PATCH 9/9] Upgrade travis to run on new infrastructure More info here: https://docs.travis-ci.com/user/migrating-from-legacy/ --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 7995db4..ab23734 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,5 @@ language: ruby +sudo: false before_install: - gem install bundler rvm: