Rails 2.1
Update to Rails 2.1 final.
This commit is contained in:
parent
fd554cce90
commit
516d6dfac0
257 changed files with 4058 additions and 1933 deletions
|
@ -131,6 +131,10 @@ class AssertResponseWithUnexpectedErrorController < ActionController::Base
|
|||
def index
|
||||
raise 'FAIL'
|
||||
end
|
||||
|
||||
def show
|
||||
render :text => "Boom", :status => 500
|
||||
end
|
||||
end
|
||||
|
||||
module Admin
|
||||
|
@ -483,6 +487,16 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase
|
|||
rescue Test::Unit::AssertionFailedError => e
|
||||
assert e.message.include?('FAIL')
|
||||
end
|
||||
|
||||
def test_assert_response_failure_response_with_no_exception
|
||||
@controller = AssertResponseWithUnexpectedErrorController.new
|
||||
get :show
|
||||
assert_response :success
|
||||
flunk 'Expected non-success response'
|
||||
rescue Test::Unit::AssertionFailedError
|
||||
rescue
|
||||
flunk "assert_response failed to handle failure response with missing, but optional, exception."
|
||||
end
|
||||
end
|
||||
|
||||
class ActionPackHeaderTest < Test::Unit::TestCase
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -82,6 +82,7 @@ class CookieTest < Test::Unit::TestCase
|
|||
def test_expiring_cookie
|
||||
get :logout
|
||||
assert_equal [ CGI::Cookie::new("name" => "user_name", "value" => "", "expires" => Time.at(0)) ], @response.headers["cookie"]
|
||||
assert_equal CGI::Cookie::new("name" => "user_name", "value" => "", "expires" => Time.at(0)).value, []
|
||||
end
|
||||
|
||||
def test_cookiejar_accessor
|
||||
|
@ -137,4 +138,9 @@ class CookieTest < Test::Unit::TestCase
|
|||
cookies = CGI::Cookie.parse('return_to=http://rubyonrails.org/search?term=api&scope=all&global=true')
|
||||
assert_equal({"return_to" => ["http://rubyonrails.org/search?term=api&scope=all&global=true"]}, cookies)
|
||||
end
|
||||
|
||||
def test_cookies_should_not_be_split_on_values_with_newlines
|
||||
cookies = CGI::Cookie.new("name" => "val", "value" => "this\nis\na\ntest")
|
||||
assert cookies.size == 1
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,14 +7,14 @@ class FilterParamTest < Test::Unit::TestCase
|
|||
def setup
|
||||
@controller = FilterParamController.new
|
||||
end
|
||||
|
||||
|
||||
def test_filter_parameters
|
||||
assert FilterParamController.respond_to?(:filter_parameter_logging)
|
||||
assert !@controller.respond_to?(:filter_parameters)
|
||||
|
||||
|
||||
FilterParamController.filter_parameter_logging
|
||||
assert @controller.respond_to?(:filter_parameters)
|
||||
|
||||
|
||||
test_hashes = [[{},{},[]],
|
||||
[{'foo'=>nil},{'foo'=>nil},[]],
|
||||
[{'foo'=>'bar'},{'foo'=>'bar'},[]],
|
||||
|
@ -24,11 +24,11 @@ class FilterParamTest < Test::Unit::TestCase
|
|||
[{'foo'=>'bar', 'baz'=>'foo'},{'foo'=>'[FILTERED]', 'baz'=>'[FILTERED]'},%w'foo baz'],
|
||||
[{'bar'=>{'foo'=>'bar','bar'=>'foo'}},{'bar'=>{'foo'=>'[FILTERED]','bar'=>'foo'}},%w'fo'],
|
||||
[{'foo'=>{'foo'=>'bar','bar'=>'foo'}},{'foo'=>'[FILTERED]'},%w'f banana']]
|
||||
|
||||
|
||||
test_hashes.each do |before_filter, after_filter, filter_words|
|
||||
FilterParamController.filter_parameter_logging(*filter_words)
|
||||
assert_equal after_filter, @controller.filter_parameters(before_filter)
|
||||
|
||||
assert_equal after_filter, @controller.send!(:filter_parameters, before_filter)
|
||||
|
||||
filter_words.push('blah')
|
||||
FilterParamController.filter_parameter_logging(*filter_words) do |key, value|
|
||||
value.reverse! if key =~ /bargain/
|
||||
|
@ -37,7 +37,13 @@ class FilterParamTest < Test::Unit::TestCase
|
|||
before_filter['barg'] = {'bargain'=>'gain', 'blah'=>'bar', 'bar'=>{'bargain'=>{'blah'=>'foo'}}}
|
||||
after_filter['barg'] = {'bargain'=>'niag', 'blah'=>'[FILTERED]', 'bar'=>{'bargain'=>{'blah'=>'[FILTERED]'}}}
|
||||
|
||||
assert_equal after_filter, @controller.filter_parameters(before_filter)
|
||||
assert_equal after_filter, @controller.send!(:filter_parameters, before_filter)
|
||||
end
|
||||
end
|
||||
|
||||
def test_filter_parameters_is_protected
|
||||
FilterParamController.filter_parameter_logging(:foo)
|
||||
assert !FilterParamController.action_methods.include?('filter_parameters')
|
||||
assert_raise(NoMethodError) { @controller.filter_parameters([{'password' => '[FILTERED]'}]) }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -85,7 +85,7 @@ class HelperTest < Test::Unit::TestCase
|
|||
def test_helper_block_include
|
||||
assert_equal expected_helper_methods, missing_methods
|
||||
assert_nothing_raised {
|
||||
@controller_class.helper { include TestHelper }
|
||||
@controller_class.helper { include HelperTest::TestHelper }
|
||||
}
|
||||
assert [], missing_methods
|
||||
end
|
||||
|
|
|
@ -52,16 +52,33 @@ class MimeTypeTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_type_convenience_methods
|
||||
types = [:html, :xml, :png, :pdf, :yaml, :url_encoded_form]
|
||||
# Don't test Mime::ALL, since it Mime::ALL#html? == true
|
||||
types = Mime::SET.to_a.map(&:to_sym).uniq - [:all]
|
||||
|
||||
# Remove custom Mime::Type instances set in other tests, like Mime::GIF and Mime::IPHONE
|
||||
types.delete_if { |type| !Mime.const_defined?(type.to_s.upcase) }
|
||||
|
||||
types.each do |type|
|
||||
mime = Mime.const_get(type.to_s.upcase)
|
||||
assert mime.send("#{type}?"), "Mime::#{type.to_s.upcase} is not #{type}?"
|
||||
(types - [type]).each { |t| assert !mime.send("#{t}?"), "Mime::#{t.to_s.upcase} is #{t}?" }
|
||||
assert mime.send("#{type}?"), "#{mime.inspect} is not #{type}?"
|
||||
(types - [type]).each { |other_type| assert !mime.send("#{other_type}?"), "#{mime.inspect} is #{other_type}?" }
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def test_mime_all_is_html
|
||||
assert Mime::ALL.all?, "Mime::ALL is not all?"
|
||||
assert Mime::ALL.html?, "Mime::ALL is not html?"
|
||||
end
|
||||
|
||||
def test_verifiable_mime_types
|
||||
unverified_types = Mime::Type.unverifiable_types
|
||||
all_types = Mime::SET.to_a.map(&:to_sym)
|
||||
all_types.uniq!
|
||||
# Remove custom Mime::Type instances set in other tests, like Mime::GIF and Mime::IPHONE
|
||||
all_types.delete_if { |type| !Mime.const_defined?(type.to_s.upcase) }
|
||||
|
||||
unverified, verified = all_types.partition { |type| Mime::Type.unverifiable_types.include? type }
|
||||
assert verified.all? { |type| Mime.const_get(type.to_s.upcase).verify_request? }, "Not all Mime Types are verified: #{verified.inspect}"
|
||||
assert unverified.all? { |type| !Mime.const_get(type.to_s.upcase).verify_request? }, "Some Mime Types are verified: #{unverified.inspect}"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -101,19 +101,79 @@ module RequestForgeryProtectionTests
|
|||
post :unsafe
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
|
||||
def test_should_not_allow_post_without_token
|
||||
assert_raises(ActionController::InvalidAuthenticityToken) { post :index }
|
||||
end
|
||||
|
||||
|
||||
def test_should_not_allow_put_without_token
|
||||
assert_raises(ActionController::InvalidAuthenticityToken) { put :index }
|
||||
end
|
||||
|
||||
|
||||
def test_should_not_allow_delete_without_token
|
||||
assert_raises(ActionController::InvalidAuthenticityToken) { delete :index }
|
||||
end
|
||||
|
||||
|
||||
def test_should_not_allow_api_formatted_post_without_token
|
||||
assert_raises(ActionController::InvalidAuthenticityToken) do
|
||||
post :index, :format => 'xml'
|
||||
end
|
||||
end
|
||||
|
||||
def test_should_not_allow_api_formatted_put_without_token
|
||||
assert_raises(ActionController::InvalidAuthenticityToken) do
|
||||
put :index, :format => 'xml'
|
||||
end
|
||||
end
|
||||
|
||||
def test_should_not_allow_api_formatted_delete_without_token
|
||||
assert_raises(ActionController::InvalidAuthenticityToken) do
|
||||
delete :index, :format => 'xml'
|
||||
end
|
||||
end
|
||||
|
||||
def test_should_not_allow_api_formatted_post_sent_as_url_encoded_form_without_token
|
||||
assert_raises(ActionController::InvalidAuthenticityToken) do
|
||||
@request.env['CONTENT_TYPE'] = Mime::URL_ENCODED_FORM.to_s
|
||||
post :index, :format => 'xml'
|
||||
end
|
||||
end
|
||||
|
||||
def test_should_not_allow_api_formatted_put_sent_as_url_encoded_form_without_token
|
||||
assert_raises(ActionController::InvalidAuthenticityToken) do
|
||||
@request.env['CONTENT_TYPE'] = Mime::URL_ENCODED_FORM.to_s
|
||||
put :index, :format => 'xml'
|
||||
end
|
||||
end
|
||||
|
||||
def test_should_not_allow_api_formatted_delete_sent_as_url_encoded_form_without_token
|
||||
assert_raises(ActionController::InvalidAuthenticityToken) do
|
||||
@request.env['CONTENT_TYPE'] = Mime::URL_ENCODED_FORM.to_s
|
||||
delete :index, :format => 'xml'
|
||||
end
|
||||
end
|
||||
|
||||
def test_should_not_allow_api_formatted_post_sent_as_multipart_form_without_token
|
||||
assert_raises(ActionController::InvalidAuthenticityToken) do
|
||||
@request.env['CONTENT_TYPE'] = Mime::MULTIPART_FORM.to_s
|
||||
post :index, :format => 'xml'
|
||||
end
|
||||
end
|
||||
|
||||
def test_should_not_allow_api_formatted_put_sent_as_multipart_form_without_token
|
||||
assert_raises(ActionController::InvalidAuthenticityToken) do
|
||||
@request.env['CONTENT_TYPE'] = Mime::MULTIPART_FORM.to_s
|
||||
put :index, :format => 'xml'
|
||||
end
|
||||
end
|
||||
|
||||
def test_should_not_allow_api_formatted_delete_sent_as_multipart_form_without_token
|
||||
assert_raises(ActionController::InvalidAuthenticityToken) do
|
||||
@request.env['CONTENT_TYPE'] = Mime::MULTIPART_FORM.to_s
|
||||
delete :index, :format => 'xml'
|
||||
end
|
||||
end
|
||||
|
||||
def test_should_not_allow_xhr_post_without_token
|
||||
assert_raises(ActionController::InvalidAuthenticityToken) { xhr :post, :index }
|
||||
end
|
||||
|
@ -142,16 +202,19 @@ module RequestForgeryProtectionTests
|
|||
end
|
||||
|
||||
def test_should_allow_post_with_xml
|
||||
@request.env['CONTENT_TYPE'] = Mime::XML.to_s
|
||||
post :index, :format => 'xml'
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
def test_should_allow_put_with_xml
|
||||
@request.env['CONTENT_TYPE'] = Mime::XML.to_s
|
||||
put :index, :format => 'xml'
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
def test_should_allow_delete_with_xml
|
||||
@request.env['CONTENT_TYPE'] = Mime::XML.to_s
|
||||
delete :index, :format => 'xml'
|
||||
assert_response :success
|
||||
end
|
||||
|
|
|
@ -50,6 +50,13 @@ class UriReservedCharactersRoutingTest < Test::Unit::TestCase
|
|||
:additional => ["add#{@segment}itional-1", "add#{@segment}itional-2"] }
|
||||
assert_equal options, @set.recognize_path("/controller/act#{@escaped}ion/var#{@escaped}iable/add#{@escaped}itional-1/add#{@escaped}itional-2")
|
||||
end
|
||||
|
||||
def test_route_generation_allows_passing_non_string_values_to_generated_helper
|
||||
assert_equal "/controller/action/variable/1/2", @set.generate(:controller => "controller",
|
||||
:action => "action",
|
||||
:variable => "variable",
|
||||
:additional => [1, 2])
|
||||
end
|
||||
end
|
||||
|
||||
class LegacyRouteSetTests < Test::Unit::TestCase
|
||||
|
|
|
@ -43,7 +43,9 @@ class CookieStoreTest < Test::Unit::TestCase
|
|||
{ :empty => ['BAgw--0686dcaccc01040f4bd4f35fe160afe9bc04c330', {}],
|
||||
:a_one => ['BAh7BiIGYWkG--5689059497d7f122a7119f171aef81dcfd807fec', { 'a' => 1 }],
|
||||
:typical => ['BAh7ByIMdXNlcl9pZGkBeyIKZmxhc2h7BiILbm90aWNlIgxIZXkgbm93--9d20154623b9eeea05c62ab819be0e2483238759', { 'user_id' => 123, 'flash' => { 'notice' => 'Hey now' }}],
|
||||
:flashed => ['BAh7ByIMdXNlcl9pZGkBeyIKZmxhc2h7AA%3D%3D--bf9785a666d3c4ac09f7fe3353496b437546cfbf', { 'user_id' => 123, 'flash' => {} }] }
|
||||
:flashed => ['BAh7ByIMdXNlcl9pZGkBeyIKZmxhc2h7AA==--bf9785a666d3c4ac09f7fe3353496b437546cfbf', { 'user_id' => 123, 'flash' => {} }],
|
||||
:double_escaped => [CGI.escape('BAh7ByIMdXNlcl9pZGkBeyIKZmxhc2h7AA%3D%3D--bf9785a666d3c4ac09f7fe3353496b437546cfbf'), { 'user_id' => 123, 'flash' => {} }] }
|
||||
|
||||
end
|
||||
|
||||
def setup
|
||||
|
@ -101,6 +103,15 @@ class CookieStoreTest < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_restores_double_encoded_cookies
|
||||
set_cookie! cookie_value(:double_escaped)
|
||||
new_session do |session|
|
||||
session.dbman.restore
|
||||
assert_equal session["user_id"], 123
|
||||
assert_equal session["flash"], {}
|
||||
end
|
||||
end
|
||||
|
||||
def test_close_doesnt_write_cookie_if_data_is_blank
|
||||
new_session do |session|
|
||||
assert_no_cookies session
|
||||
|
@ -241,6 +252,7 @@ class CookieStoreWithMD5DigestTest < CookieStoreTest
|
|||
{ :empty => ['BAgw--0415cc0be9579b14afc22ee2d341aa21', {}],
|
||||
:a_one => ['BAh7BiIGYWkG--5a0ed962089cc6600ff44168a5d59bc8', { 'a' => 1 }],
|
||||
:typical => ['BAh7ByIMdXNlcl9pZGkBeyIKZmxhc2h7BiILbm90aWNlIgxIZXkgbm93--f426763f6ef435b3738b493600db8d64', { 'user_id' => 123, 'flash' => { 'notice' => 'Hey now' }}],
|
||||
:flashed => ['BAh7ByIMdXNlcl9pZGkBeyIKZmxhc2h7AA%3D%3D--0af9156650dab044a53a91a4ddec2c51', { 'user_id' => 123, 'flash' => {} }] }
|
||||
:flashed => ['BAh7ByIMdXNlcl9pZGkBeyIKZmxhc2h7AA==--0af9156650dab044a53a91a4ddec2c51', { 'user_id' => 123, 'flash' => {} }],
|
||||
:double_escaped => [CGI.escape('BAh7ByIMdXNlcl9pZGkBeyIKZmxhc2h7AA%3D%3D--0af9156650dab044a53a91a4ddec2c51'), { 'user_id' => 123, 'flash' => {} }] }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -511,16 +511,26 @@ XML
|
|||
|
||||
FILES_DIR = File.dirname(__FILE__) + '/../fixtures/multipart'
|
||||
|
||||
if RUBY_VERSION < '1.9'
|
||||
READ_BINARY = 'rb'
|
||||
READ_PLAIN = 'r'
|
||||
else
|
||||
READ_BINARY = 'rb:binary'
|
||||
READ_PLAIN = 'r:binary'
|
||||
end
|
||||
|
||||
def test_test_uploaded_file
|
||||
filename = 'mona_lisa.jpg'
|
||||
path = "#{FILES_DIR}/#{filename}"
|
||||
content_type = 'image/png'
|
||||
expected = File.read(path)
|
||||
expected.force_encoding(Encoding::BINARY) if expected.respond_to?(:force_encoding)
|
||||
|
||||
file = ActionController::TestUploadedFile.new(path, content_type)
|
||||
assert_equal filename, file.original_filename
|
||||
assert_equal content_type, file.content_type
|
||||
assert_equal file.path, file.local_path
|
||||
assert_equal File.read(path), file.read
|
||||
assert_equal expected, file.read
|
||||
end
|
||||
|
||||
def test_test_uploaded_file_with_binary
|
||||
|
@ -529,10 +539,10 @@ XML
|
|||
content_type = 'image/png'
|
||||
|
||||
binary_uploaded_file = ActionController::TestUploadedFile.new(path, content_type, :binary)
|
||||
assert_equal File.open(path, 'rb').read, binary_uploaded_file.read
|
||||
assert_equal File.open(path, READ_BINARY).read, binary_uploaded_file.read
|
||||
|
||||
plain_uploaded_file = ActionController::TestUploadedFile.new(path, content_type)
|
||||
assert_equal File.open(path, 'r').read, plain_uploaded_file.read
|
||||
assert_equal File.open(path, READ_PLAIN).read, plain_uploaded_file.read
|
||||
end
|
||||
|
||||
def test_fixture_file_upload_with_binary
|
||||
|
@ -541,10 +551,10 @@ XML
|
|||
content_type = 'image/jpg'
|
||||
|
||||
binary_file_upload = fixture_file_upload(path, content_type, :binary)
|
||||
assert_equal File.open(path, 'rb').read, binary_file_upload.read
|
||||
assert_equal File.open(path, READ_BINARY).read, binary_file_upload.read
|
||||
|
||||
plain_file_upload = fixture_file_upload(path, content_type)
|
||||
assert_equal File.open(path, 'r').read, plain_file_upload.read
|
||||
assert_equal File.open(path, READ_PLAIN).read, plain_file_upload.read
|
||||
end
|
||||
|
||||
def test_fixture_file_upload
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue