forked from radar/rails
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request rails#20384 from kaspth/per-request-cache
Use digest cache in development.
- Loading branch information
Showing
4 changed files
with
82 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
railties/test/application/per_request_digest_cache_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
require 'isolation/abstract_unit' | ||
require 'rack/test' | ||
require 'minitest/mock' | ||
|
||
require 'action_view' | ||
require 'active_support/testing/method_call_assertions' | ||
|
||
class PerRequestDigestCacheTest < ActiveSupport::TestCase | ||
include ActiveSupport::Testing::Isolation | ||
include ActiveSupport::Testing::MethodCallAssertions | ||
include Rack::Test::Methods | ||
|
||
setup do | ||
build_app | ||
add_to_config 'config.consider_all_requests_local = true' | ||
|
||
app_file 'app/models/customer.rb', <<-RUBY | ||
class Customer < Struct.new(:name, :id) | ||
extend ActiveModel::Naming | ||
include ActiveModel::Conversion | ||
end | ||
RUBY | ||
|
||
app_file 'config/routes.rb', <<-RUBY | ||
Rails.application.routes.draw do | ||
resources :customers, only: :index | ||
end | ||
RUBY | ||
|
||
app_file 'app/controllers/customers_controller.rb', <<-RUBY | ||
class CustomersController < ApplicationController | ||
def index | ||
render [ Customer.new('david', 1), Customer.new('dingus', 2) ] | ||
end | ||
end | ||
RUBY | ||
|
||
app_file 'app/views/customers/_customer.html.erb', <<-RUBY | ||
<% cache customer do %> | ||
<%= customer.name %> | ||
<% end %> | ||
RUBY | ||
|
||
require "#{app_path}/config/environment" | ||
end | ||
|
||
teardown :teardown_app | ||
|
||
test "digests are reused when rendering the same template twice" do | ||
get '/customers' | ||
assert_equal 200, last_response.status | ||
|
||
assert_equal [ '8ba099b7749542fe765ff34a6824d548' ], ActionView::Digestor.cache.values | ||
assert_equal %w(david dingus), last_response.body.split.map(&:strip) | ||
end | ||
|
||
test "template digests are cleared before a request" do | ||
assert_called(ActionView::Digestor.cache, :clear) do | ||
get '/customers' | ||
assert_equal 200, last_response.status | ||
end | ||
end | ||
end |