Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add caching_allowed? that was removed from Rails 4 core #1

Merged
merged 2 commits into from

4 participants

@michiels

No description provided.

@frodsan frodsan commented on the diff
lib/action_controller/caching/pages.rb
@@ -185,6 +185,10 @@ def cache_page(content = nil, options = nil, gzip = Zlib::BEST_COMPRESSION)
self.class.cache_page(content || response.body, path, extension, gzip)
end
+
+ def caching_allowed?
+ (request.get? || request.head?) && response.status == 200
@frodsan
frodsan added a note

@carlosantoniodasilva Is it ok to support head?

@rafaelfranca Owner

I guess so.

@frodsan
frodsan added a note

Can you add actionpack-page_caching and actionpack-action_caching to Travis?

@rafaelfranca Owner
@frodsan
frodsan added a note

Thanks :+1:

@rafaelfranca Owner

Done

@frodsan
frodsan added a note

Any plans to push these gems up to Rubygems?

@rafaelfranca Owner

I'll do this week

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@frodsan frodsan merged commit c69dc22 into rails:master
@frodsan

Thanks! :smile:

@michiels

Yay!

@michiels michiels deleted the michiels:add-caching-allowed branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 10 additions and 0 deletions.
  1. +4 −0 lib/action_controller/caching/pages.rb
  2. +6 −0 test/caching_test.rb
View
4 lib/action_controller/caching/pages.rb
@@ -185,6 +185,10 @@ def cache_page(content = nil, options = nil, gzip = Zlib::BEST_COMPRESSION)
self.class.cache_page(content || response.body, path, extension, gzip)
end
+
+ def caching_allowed?
+ (request.get? || request.head?) && response.status == 200
@frodsan
frodsan added a note

@carlosantoniodasilva Is it ok to support head?

@rafaelfranca Owner

I guess so.

@frodsan
frodsan added a note

Can you add actionpack-page_caching and actionpack-action_caching to Travis?

@rafaelfranca Owner
@frodsan
frodsan added a note

Thanks :+1:

@rafaelfranca Owner

Done

@frodsan
frodsan added a note

Any plans to push these gems up to Rubygems?

@rafaelfranca Owner

I'll do this week

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ end
end
end
end
View
6 test/caching_test.rb
@@ -148,6 +148,12 @@ def test_page_caching_resources_saves_to_correct_path_with_extension_even_if_def
end
end
+ def test_should_cache_head_with_ok_status
+ head :ok
+ assert_response :ok
+ assert_page_cached :ok, 'head with ok status should have been cached'
+ end
+
def test_should_cache_get_with_ok_status
get :ok
assert_response :ok
Something went wrong with that request. Please try again.