Skip to content

Support for Rails 5 #41

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

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ rvm:
- 1.9.3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why those ruby versions are being removed?

- 2.0.0
- 2.1
- 2.2.5
- 2.3.1
gemfile:
- Gemfile
Expand All @@ -13,8 +14,20 @@ gemfile:
- gemfiles/Gemfile-4-2-stable
- gemfiles/Gemfile-edge
matrix:
exclude:
- rvm: 1.9.3
gemfile: Gemfile
- rvm: 1.9.3
gemfile: gemfiles/Gemfile-edge
- rvm: 2.0.0
gemfile: Gemfile
- rvm: 2.0.0
gemfile: gemfiles/Gemfile-edge
- rvm: 2.1
gemfile: Gemfile
- rvm: 2.1
gemfile: gemfiles/Gemfile-edge
allow_failures:
- gemfile: gemfiles/Gemfile-edge
notifications:
email: false
irc:
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.0.3

* Add support for Rails 5.0.x

# 1.0.2

* Fix load order problem with other gems.
Expand Down
4 changes: 2 additions & 2 deletions actionpack-page_caching.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Gem::Specification.new do |gem|
gem.name = 'actionpack-page_caching'
gem.version = '1.0.2'
gem.version = '1.0.3'
gem.author = 'David Heinemeier Hansson'
gem.email = 'david@loudthinking.com'
gem.description = 'Static page caching for Action Pack (removed from core in Rails 4.0)'
Expand All @@ -15,7 +15,7 @@ Gem::Specification.new do |gem|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
gem.require_paths = ['lib']

gem.add_dependency 'actionpack', '>= 4.0.0', '< 5'
gem.add_dependency 'actionpack', '>= 4.0.0', '< 5.1'

gem.add_development_dependency 'mocha'
end
2 changes: 1 addition & 1 deletion lib/action_controller/caching/pages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def caches_page(*actions)
Zlib::BEST_COMPRESSION
end

after_filter({only: actions}.merge(options)) do |c|
after_action({only: actions}.merge(options)) do |c|
c.cache_page(nil, nil, gzip_level)
end
end
Expand Down
14 changes: 13 additions & 1 deletion test/abstract_unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,19 @@ def setup
@routes = SharedTestRoutes

@routes.draw do
get ':controller(/:action)'
get 'page_caching_metal_test/ok' => 'page_caching_metal_test#ok'
scope controller: :page_caching_test, path: 'page_caching_test' do
get :about_me
get :custom_path
get :default_gzip
get :expire_custom_path
get :found
get :gzip_level
get :no_content
get :no_gzip
get :not_found
get :ok
end
end
end
end
Expand Down
36 changes: 27 additions & 9 deletions test/caching_test.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'abstract_unit'
require 'mocha/setup'
require 'rails/version'

CACHE_DIR = 'test_cache'
# Don't change '/../temp/' cavalierly or you might hose something you don't want hosed
Expand All @@ -8,6 +9,7 @@
class CachingMetalController < ActionController::Metal
abstract!

include AbstractController::Callbacks
include ActionController::Caching

self.page_cache_directory = FILE_STORE_PATH
Expand Down Expand Up @@ -78,20 +80,20 @@ def not_found
end

def custom_path
render text: 'Super soaker'
render_text 'Super soaker'
cache_page('Super soaker', '/index.html')
end

def default_gzip
render text: 'Text'
render_text 'Text'
end

def no_gzip
render text: 'PNG'
render_text 'PNG'
end

def gzip_level
render text: 'Big text'
render_text 'Big text'
end

def expire_custom_path
Expand All @@ -100,30 +102,46 @@ def expire_custom_path
end

def trailing_slash
render text: 'Sneak attack'
render_text 'Sneak attack'
end

def about_me
respond_to do |format|
format.html { render text: 'I am html' }
format.xml { render text: 'I am xml' }
format.html { render_text 'I am html' }
format.xml { render xml: 'I am xml' }
end
end

def render_text(str)
if Rails::VERSION::MAJOR >= 5
render html: str
else
render text: str
end
end
end

class PageCachingTest < ActionController::TestCase
def setup
super
@request = if Rails::VERSION::MAJOR >= 5
ActionDispatch::TestRequest.create
else
ActionController::TestRequest.new
end

@request = ActionController::TestRequest.new
@request.host = 'hostname.com'
@request.env.delete('PATH_INFO')

@controller = PageCachingTestController.new
@controller.perform_caching = true
@controller.cache_store = :file_store, FILE_STORE_PATH

@response = ActionController::TestResponse.new
@response = if Rails::VERSION::MAJOR >= 5
ActionDispatch::TestResponse.new
else
ActionController::TestResponse.new
end

@params = { controller: 'posts', action: 'index', only_path: true }

Expand Down
8 changes: 6 additions & 2 deletions test/log_subscriber_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class LogSubscribersController < ActionController::Base

def with_page_cache
cache_page('Super soaker', '/index.html')
render nothing: true
head :ok
end
end
end
Expand All @@ -24,11 +24,15 @@ def setup

@routes = SharedTestRoutes
@routes.draw do
get ':controller(/:action)'
get 'another/log_subscribers/with_page_cache' =>
'another/log_subscribers#with_page_cache'
end

@cache_path = File.expand_path('../temp/test_cache', File.dirname(__FILE__))
ActionController::Base.page_cache_directory = @cache_path
if ActionController::Base.respond_to?(:enable_fragment_cache_logging=)
ActionController::Base.enable_fragment_cache_logging = true
end
@controller.cache_store = :file_store, @cache_path
ActionController::LogSubscriber.attach_to :action_controller
end
Expand Down