Rails 2.1

Update to Rails 2.1 final.
This commit is contained in:
Jacques Distler 2008-06-02 01:35:38 -05:00
parent fd554cce90
commit 516d6dfac0
257 changed files with 4058 additions and 1933 deletions

View file

@ -6,6 +6,7 @@ CACHE_DIR = 'test_cache'
FILE_STORE_PATH = File.join(File.dirname(__FILE__), '/../temp/', CACHE_DIR)
ActionController::Base.page_cache_directory = FILE_STORE_PATH
ActionController::Base.cache_store = :file_store, FILE_STORE_PATH
ActionController::Base.view_paths = [ File.dirname(__FILE__) + '/../fixtures/' ]
class PageCachingTestController < ActionController::Base
caches_page :ok, :no_content, :if => Proc.new { |c| !c.request.format.json? }
@ -128,7 +129,7 @@ class PageCachingTest < Test::Unit::TestCase
end
end
end
def test_page_caching_conditional_options
@request.env['HTTP_ACCEPT'] = 'application/json'
get :ok
@ -151,12 +152,15 @@ end
class ActionCachingTestController < ActionController::Base
caches_action :index, :redirected, :forbidden
caches_action :index, :redirected, :forbidden, :if => Proc.new { |c| !c.request.format.json? }
caches_action :show, :cache_path => 'http://test.host/custom/show'
caches_action :edit, :cache_path => Proc.new { |c| c.params[:id] ? "http://test.host/#{c.params[:id]};edit" : "http://test.host/edit" }
caches_action :with_layout
layout 'talk_from_action.erb'
def index
@cache_this = Time.now.to_f.to_s
@cache_this = MockTime.now.to_f.to_s
render :text => @cache_this
end
@ -169,14 +173,26 @@ class ActionCachingTestController < ActionController::Base
headers["Status"] = "403 Forbidden"
end
def with_layout
@cache_this = MockTime.now.to_f.to_s
render :text => @cache_this, :layout => true
end
alias_method :show, :index
alias_method :edit, :index
alias_method :destroy, :index
def expire
expire_action :controller => 'action_caching_test', :action => 'index'
render :nothing => true
end
end
class MockTime < Time
# Let Time spicy to assure that Time.now != Time.now
def to_f
super+rand
end
end
class ActionCachingMockController
@ -216,18 +232,48 @@ class ActionCacheTest < Test::Unit::TestCase
get :index
cached_time = content_to_cache
assert_equal cached_time, @response.body
assert_cache_exists 'hostname.com/action_caching_test'
assert fragment_exist?('hostname.com/action_caching_test')
reset!
get :index
assert_equal cached_time, @response.body
end
def test_simple_action_not_cached
get :destroy
cached_time = content_to_cache
assert_equal cached_time, @response.body
assert !fragment_exist?('hostname.com/action_caching_test/destroy')
reset!
get :destroy
assert_not_equal cached_time, @response.body
end
def test_action_cache_with_layout
get :with_layout
cached_time = content_to_cache
assert_not_equal cached_time, @response.body
assert fragment_exist?('hostname.com/action_caching_test/with_layout')
reset!
get :with_layout
assert_not_equal cached_time, @response.body
assert_equal @response.body, read_fragment('hostname.com/action_caching_test/with_layout')
end
def test_action_cache_conditional_options
@request.env['HTTP_ACCEPT'] = 'application/json'
get :index
assert !fragment_exist?('hostname.com/action_caching_test')
end
def test_action_cache_with_custom_cache_path
get :show
cached_time = content_to_cache
assert_equal cached_time, @response.body
assert_cache_exists 'test.host/custom/show'
assert fragment_exist?('test.host/custom/show')
reset!
get :show
@ -236,11 +282,11 @@ class ActionCacheTest < Test::Unit::TestCase
def test_action_cache_with_custom_cache_path_in_block
get :edit
assert_cache_exists 'test.host/edit'
assert fragment_exist?('test.host/edit')
reset!
get :edit, :id => 1
assert_cache_exists 'test.host/1;edit'
assert fragment_exist?('test.host/1;edit')
end
def test_cache_expiration
@ -349,9 +395,12 @@ class ActionCacheTest < Test::Unit::TestCase
@request.host = 'hostname.com'
end
def assert_cache_exists(path)
full_path = File.join(FILE_STORE_PATH, "views", path + '.cache')
assert File.exist?(full_path), "#{full_path.inspect} does not exist."
def fragment_exist?(path)
@controller.fragment_exist?(path)
end
def read_fragment(path)
@controller.read_fragment(path)
end
end
@ -391,6 +440,19 @@ class FragmentCachingTest < Test::Unit::TestCase
assert_nil @controller.read_fragment('name')
end
def test_fragment_exist__with_caching_enabled
@store.write('views/name', 'value')
assert @controller.fragment_exist?('name')
assert !@controller.fragment_exist?('other_name')
end
def test_fragment_exist__with_caching_disabled
ActionController::Base.perform_caching = false
@store.write('views/name', 'value')
assert !@controller.fragment_exist?('name')
assert !@controller.fragment_exist?('other_name')
end
def test_write_fragment__with_caching_enabled
assert_nil @store.read('views/name')
assert_equal 'value', @controller.write_fragment('name', 'value')
@ -435,7 +497,6 @@ class FragmentCachingTest < Test::Unit::TestCase
assert_equal 'generated till now -> ', buffer
end
def test_fragment_for
@store.write('views/expensive', 'fragment content')
fragment_computed = false
@ -516,7 +577,7 @@ class FunctionalFragmentCachingTest < Test::Unit::TestCase
def setup
ActionController::Base.perform_caching = true
@store = ActiveSupport::Cache::MemoryStore.new
ActionController::Base.cache_store = @store
ActionController::Base.cache_store = @store
@controller = FunctionalCachingController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
@ -529,17 +590,17 @@ Hello
This bit's fragment cached
CACHED
assert_equal expected_body, @response.body
assert_equal "This bit's fragment cached", @store.read('views/test.host/functional_caching/fragment_cached')
end
def test_fragment_caching_in_partials
get :html_fragment_cached_with_partial
assert_response :success
assert_match /Fragment caching in a partial/, @response.body
assert_match "Fragment caching in a partial", @store.read('views/test.host/functional_caching/html_fragment_cached_with_partial')
end
def test_fragment_caching_in_rjs_partials
xhr :get, :js_fragment_cached_with_partial
assert_response :success
@ -547,8 +608,3 @@ CACHED
assert_match "Fragment caching in a partial", @store.read('views/test.host/functional_caching/js_fragment_cached_with_partial')
end
end