actionpack 2.0.5 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of actionpack might be problematic. Click here for more details.
- data/CHANGELOG +149 -7
- data/MIT-LICENSE +1 -1
- data/README +1 -1
- data/Rakefile +5 -6
- data/lib/action_controller.rb +2 -2
- data/lib/action_controller/assertions/model_assertions.rb +2 -1
- data/lib/action_controller/assertions/response_assertions.rb +4 -2
- data/lib/action_controller/assertions/routing_assertions.rb +3 -3
- data/lib/action_controller/assertions/selector_assertions.rb +30 -27
- data/lib/action_controller/assertions/tag_assertions.rb +3 -3
- data/lib/action_controller/base.rb +103 -129
- data/lib/action_controller/benchmarking.rb +3 -3
- data/lib/action_controller/caching.rb +41 -652
- data/lib/action_controller/caching/actions.rb +144 -0
- data/lib/action_controller/caching/fragments.rb +138 -0
- data/lib/action_controller/caching/pages.rb +154 -0
- data/lib/action_controller/caching/sql_cache.rb +18 -0
- data/lib/action_controller/caching/sweeping.rb +97 -0
- data/lib/action_controller/cgi_ext/cookie.rb +27 -23
- data/lib/action_controller/cgi_ext/stdinput.rb +1 -0
- data/lib/action_controller/cgi_process.rb +6 -4
- data/lib/action_controller/components.rb +7 -6
- data/lib/action_controller/cookies.rb +31 -19
- data/lib/action_controller/dispatcher.rb +51 -84
- data/lib/action_controller/filters.rb +295 -421
- data/lib/action_controller/flash.rb +1 -6
- data/lib/action_controller/headers.rb +31 -0
- data/lib/action_controller/helpers.rb +26 -9
- data/lib/action_controller/http_authentication.rb +1 -1
- data/lib/action_controller/integration.rb +65 -13
- data/lib/action_controller/layout.rb +24 -39
- data/lib/action_controller/mime_responds.rb +7 -3
- data/lib/action_controller/mime_type.rb +25 -9
- data/lib/action_controller/mime_types.rb +1 -1
- data/lib/action_controller/polymorphic_routes.rb +32 -17
- data/lib/action_controller/record_identifier.rb +10 -4
- data/lib/action_controller/request.rb +46 -30
- data/lib/action_controller/request_forgery_protection.rb +10 -9
- data/lib/action_controller/request_profiler.rb +29 -8
- data/lib/action_controller/rescue.rb +24 -24
- data/lib/action_controller/resources.rb +66 -23
- data/lib/action_controller/response.rb +2 -2
- data/lib/action_controller/routing.rb +113 -1229
- data/lib/action_controller/routing/builder.rb +204 -0
- data/lib/action_controller/{routing_optimisation.rb → routing/optimisations.rb} +13 -12
- data/lib/action_controller/routing/recognition_optimisation.rb +158 -0
- data/lib/action_controller/routing/route.rb +240 -0
- data/lib/action_controller/routing/route_set.rb +435 -0
- data/lib/action_controller/routing/routing_ext.rb +46 -0
- data/lib/action_controller/routing/segments.rb +283 -0
- data/lib/action_controller/session/active_record_store.rb +13 -8
- data/lib/action_controller/session/cookie_store.rb +20 -17
- data/lib/action_controller/session_management.rb +10 -3
- data/lib/action_controller/streaming.rb +45 -31
- data/lib/action_controller/test_case.rb +33 -23
- data/lib/action_controller/test_process.rb +39 -35
- data/lib/action_controller/url_rewriter.rb +18 -12
- data/lib/action_controller/vendor/html-scanner/html/tokenizer.rb +1 -1
- data/lib/action_pack.rb +1 -1
- data/lib/action_pack/version.rb +2 -2
- data/lib/action_view.rb +11 -3
- data/lib/action_view/base.rb +73 -390
- data/lib/action_view/helpers/active_record_helper.rb +83 -62
- data/lib/action_view/helpers/asset_tag_helper.rb +101 -44
- data/lib/action_view/helpers/atom_feed_helper.rb +35 -7
- data/lib/action_view/helpers/benchmark_helper.rb +5 -3
- data/lib/action_view/helpers/cache_helper.rb +3 -2
- data/lib/action_view/helpers/capture_helper.rb +1 -2
- data/lib/action_view/helpers/date_helper.rb +104 -82
- data/lib/action_view/helpers/form_helper.rb +148 -75
- data/lib/action_view/helpers/form_options_helper.rb +44 -23
- data/lib/action_view/helpers/form_tag_helper.rb +22 -13
- data/lib/action_view/helpers/javascripts/controls.js +1 -1
- data/lib/action_view/helpers/javascripts/dragdrop.js +1 -1
- data/lib/action_view/helpers/javascripts/effects.js +1 -1
- data/lib/action_view/helpers/number_helper.rb +10 -3
- data/lib/action_view/helpers/prototype_helper.rb +61 -29
- data/lib/action_view/helpers/record_tag_helper.rb +3 -3
- data/lib/action_view/helpers/sanitize_helper.rb +23 -17
- data/lib/action_view/helpers/scriptaculous_helper.rb +86 -60
- data/lib/action_view/helpers/text_helper.rb +153 -125
- data/lib/action_view/helpers/url_helper.rb +83 -28
- data/lib/action_view/inline_template.rb +20 -0
- data/lib/action_view/partial_template.rb +70 -0
- data/lib/action_view/partials.rb +31 -73
- data/lib/action_view/template.rb +127 -0
- data/lib/action_view/template_error.rb +8 -7
- data/lib/action_view/template_finder.rb +177 -0
- data/lib/action_view/template_handler.rb +18 -1
- data/lib/action_view/template_handlers/builder.rb +10 -2
- data/lib/action_view/template_handlers/compilable.rb +128 -0
- data/lib/action_view/template_handlers/erb.rb +37 -2
- data/lib/action_view/template_handlers/rjs.rb +14 -1
- data/lib/action_view/test_case.rb +58 -0
- data/test/abstract_unit.rb +1 -1
- data/test/active_record_unit.rb +3 -6
- data/test/activerecord/active_record_store_test.rb +1 -2
- data/test/activerecord/render_partial_with_record_identification_test.rb +158 -41
- data/test/adv_attr_test.rb +20 -0
- data/test/controller/action_pack_assertions_test.rb +16 -19
- data/test/controller/addresses_render_test.rb +1 -1
- data/test/controller/assert_select_test.rb +13 -6
- data/test/controller/base_test.rb +48 -2
- data/test/controller/benchmark_test.rb +1 -2
- data/test/controller/caching_test.rb +282 -21
- data/test/controller/capture_test.rb +1 -1
- data/test/controller/cgi_test.rb +1 -1
- data/test/controller/components_test.rb +1 -1
- data/test/controller/content_type_test.rb +2 -2
- data/test/controller/cookie_test.rb +13 -2
- data/test/controller/custom_handler_test.rb +14 -10
- data/test/controller/deprecation/deprecated_base_methods_test.rb +1 -1
- data/test/controller/dispatcher_test.rb +31 -49
- data/test/controller/fake_controllers.rb +17 -0
- data/test/controller/fake_models.rb +6 -0
- data/test/controller/filter_params_test.rb +14 -8
- data/test/controller/filters_test.rb +44 -16
- data/test/controller/flash_test.rb +2 -2
- data/test/controller/header_test.rb +14 -0
- data/test/controller/helper_test.rb +19 -15
- data/test/controller/html-scanner/document_test.rb +1 -2
- data/test/controller/html-scanner/node_test.rb +1 -2
- data/test/controller/html-scanner/sanitizer_test.rb +8 -5
- data/test/controller/html-scanner/tag_node_test.rb +1 -2
- data/test/controller/html-scanner/text_node_test.rb +2 -3
- data/test/controller/html-scanner/tokenizer_test.rb +8 -2
- data/test/controller/http_authentication_test.rb +1 -1
- data/test/controller/integration_test.rb +14 -16
- data/test/controller/integration_upload_test.rb +43 -0
- data/test/controller/layout_test.rb +26 -6
- data/test/controller/mime_responds_test.rb +39 -7
- data/test/controller/mime_type_test.rb +29 -5
- data/test/controller/new_render_test.rb +105 -34
- data/test/controller/polymorphic_routes_test.rb +32 -20
- data/test/controller/record_identifier_test.rb +38 -2
- data/test/controller/redirect_test.rb +21 -1
- data/test/controller/render_test.rb +59 -15
- data/test/controller/request_forgery_protection_test.rb +92 -5
- data/test/controller/request_test.rb +64 -6
- data/test/controller/rescue_test.rb +22 -6
- data/test/controller/resources_test.rb +102 -14
- data/test/controller/routing_test.rb +231 -19
- data/test/controller/selector_test.rb +2 -2
- data/test/controller/send_file_test.rb +14 -3
- data/test/controller/session/cookie_store_test.rb +16 -4
- data/test/controller/session/mem_cache_store_test.rb +3 -4
- data/test/controller/session_fixation_test.rb +1 -1
- data/test/controller/session_management_test.rb +23 -1
- data/test/controller/test_test.rb +39 -18
- data/test/controller/url_rewriter_test.rb +35 -1
- data/test/controller/verification_test.rb +1 -1
- data/test/controller/view_paths_test.rb +15 -12
- data/test/controller/webservice_test.rb +48 -3
- data/test/fixtures/bad_customers/_bad_customer.html.erb +1 -0
- data/test/fixtures/company.rb +1 -0
- data/test/fixtures/customers/_customer.html.erb +1 -0
- data/test/fixtures/db_definitions/sqlite.sql +6 -0
- data/test/fixtures/functional_caching/_partial.erb +3 -0
- data/test/fixtures/functional_caching/fragment_cached.html.erb +2 -0
- data/test/fixtures/functional_caching/html_fragment_cached_with_partial.html.erb +1 -0
- data/test/fixtures/functional_caching/js_fragment_cached_with_partial.js.rjs +1 -0
- data/test/fixtures/good_customers/_good_customer.html.erb +1 -0
- data/test/fixtures/mascot.rb +3 -0
- data/test/fixtures/mascots.yml +4 -0
- data/test/fixtures/mascots/_mascot.html.erb +1 -0
- data/test/fixtures/multipart/boundary_problem_file +10 -0
- data/test/fixtures/public/javascripts/application.js +1 -0
- data/test/fixtures/public/javascripts/controls.js +1 -0
- data/test/fixtures/public/javascripts/dragdrop.js +1 -0
- data/test/fixtures/public/javascripts/effects.js +1 -0
- data/test/fixtures/public/javascripts/prototype.js +1 -0
- data/test/fixtures/public/javascripts/version.1.0.js +1 -0
- data/test/fixtures/public/stylesheets/version.1.0.css +1 -0
- data/test/fixtures/reply.rb +1 -0
- data/test/fixtures/shared.html.erb +1 -0
- data/test/fixtures/symlink_parent/symlinked_layout.erb +5 -0
- data/test/fixtures/test/_customer_counter.erb +1 -0
- data/test/fixtures/test/_form.erb +1 -0
- data/test/fixtures/test/_labelling_form.erb +1 -0
- data/test/fixtures/test/_raise.html.erb +1 -0
- data/test/fixtures/test/greeting.js.rjs +1 -0
- data/test/fixtures/topics/_topic.html.erb +1 -0
- data/test/template/active_record_helper_test.rb +25 -8
- data/test/template/asset_tag_helper_test.rb +100 -17
- data/test/template/atom_feed_helper_test.rb +29 -1
- data/test/template/benchmark_helper_test.rb +10 -22
- data/test/template/date_helper_test.rb +455 -153
- data/test/template/erb_util_test.rb +10 -42
- data/test/template/form_helper_test.rb +192 -66
- data/test/template/form_options_helper_test.rb +19 -8
- data/test/template/form_tag_helper_test.rb +11 -8
- data/test/template/javascript_helper_test.rb +3 -9
- data/test/template/number_helper_test.rb +6 -3
- data/test/template/prototype_helper_test.rb +27 -40
- data/test/template/record_tag_helper_test.rb +54 -0
- data/test/template/sanitize_helper_test.rb +5 -6
- data/test/template/scriptaculous_helper_test.rb +7 -13
- data/test/template/tag_helper_test.rb +3 -6
- data/test/template/template_finder_test.rb +73 -0
- data/test/template/template_object_test.rb +95 -0
- data/test/template/test_test.rb +56 -0
- data/test/template/text_helper_test.rb +46 -33
- data/test/template/url_helper_test.rb +8 -10
- metadata +65 -12
- data/lib/action_view/compiled_templates.rb +0 -69
- data/test/action_view_test.rb +0 -44
- data/test/activerecord/fixtures_test.rb +0 -24
- data/test/controller/fragment_store_setting_test.rb +0 -47
- data/test/template/compiled_templates_test.rb +0 -197
- data/test/template/deprecate_ivars_test.rb +0 -51
@@ -1,69 +0,0 @@
|
|
1
|
-
module ActionView
|
2
|
-
|
3
|
-
# CompiledTemplates modules hold methods that have been compiled.
|
4
|
-
# Templates are compiled into these methods so that they do not need to be
|
5
|
-
# read and parsed for each request.
|
6
|
-
#
|
7
|
-
# Each template may be compiled into one or more methods. Each method accepts a given
|
8
|
-
# set of parameters which is used to implement local assigns passing.
|
9
|
-
#
|
10
|
-
# To use a compiled template module, create a new instance and include it into the class
|
11
|
-
# in which you want the template to be rendered.
|
12
|
-
class CompiledTemplates < Module
|
13
|
-
attr_reader :method_names
|
14
|
-
|
15
|
-
def initialize
|
16
|
-
@method_names = Hash.new do |hash, key|
|
17
|
-
hash[key] = "__compiled_method_#{(hash.length + 1)}"
|
18
|
-
end
|
19
|
-
@mtimes = {}
|
20
|
-
end
|
21
|
-
|
22
|
-
# Return the full key for the given identifier and argument names
|
23
|
-
def full_key(identifier, arg_names)
|
24
|
-
[identifier, arg_names]
|
25
|
-
end
|
26
|
-
|
27
|
-
# Return the selector for this method or nil if it has not been compiled
|
28
|
-
def selector(identifier, arg_names)
|
29
|
-
key = full_key(identifier, arg_names)
|
30
|
-
method_names.key?(key) ? method_names[key] : nil
|
31
|
-
end
|
32
|
-
alias :compiled? :selector
|
33
|
-
|
34
|
-
# Return the time at which the method for the given identifier and argument names was compiled.
|
35
|
-
def mtime(identifier, arg_names)
|
36
|
-
@mtimes[full_key(identifier, arg_names)]
|
37
|
-
end
|
38
|
-
|
39
|
-
# Compile the provided source code for the given argument names and with the given initial line number.
|
40
|
-
# The identifier should be unique to this source.
|
41
|
-
#
|
42
|
-
# The file_name, if provided will appear in backtraces. If not provided, the file_name defaults
|
43
|
-
# to the identifier.
|
44
|
-
#
|
45
|
-
# This method will return the selector for the compiled version of this method.
|
46
|
-
def compile_source(identifier, arg_names, source, initial_line_number = 0, file_name = nil)
|
47
|
-
file_name ||= identifier
|
48
|
-
name = method_names[full_key(identifier, arg_names)]
|
49
|
-
arg_desc = arg_names.empty? ? '' : "(#{arg_names * ', '})"
|
50
|
-
fake_file_name = "#{file_name}#{arg_desc}" # Include the arguments for this version (for now)
|
51
|
-
|
52
|
-
method_def = wrap_source(name, arg_names, source)
|
53
|
-
|
54
|
-
begin
|
55
|
-
module_eval(method_def, fake_file_name, initial_line_number)
|
56
|
-
@mtimes[full_key(identifier, arg_names)] = Time.now
|
57
|
-
rescue Exception => e # errors from compiled source
|
58
|
-
e.blame_file! identifier
|
59
|
-
raise
|
60
|
-
end
|
61
|
-
name
|
62
|
-
end
|
63
|
-
|
64
|
-
# Wrap the provided source in a def ... end block.
|
65
|
-
def wrap_source(name, arg_names, source)
|
66
|
-
"def #{name}(#{arg_names * ', '})\n#{source}\nend"
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
data/test/action_view_test.rb
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/abstract_unit'
|
2
|
-
require 'test/unit'
|
3
|
-
|
4
|
-
class ActionViewTests < Test::Unit::TestCase
|
5
|
-
def test_find_template_extension_from_first_render
|
6
|
-
base = ActionView::Base.new
|
7
|
-
|
8
|
-
assert_nil base.send(:find_template_extension_from_first_render)
|
9
|
-
|
10
|
-
{
|
11
|
-
nil => nil,
|
12
|
-
'' => nil,
|
13
|
-
'foo' => nil,
|
14
|
-
'/foo' => nil,
|
15
|
-
'foo.rb' => 'rb',
|
16
|
-
'foo.bar.rb' => 'bar.rb',
|
17
|
-
'baz/foo.rb' => 'rb',
|
18
|
-
'baz/foo.bar.rb' => 'bar.rb',
|
19
|
-
'baz/foo.o/foo.rb' => 'rb',
|
20
|
-
'baz/foo.o/foo.bar.rb' => 'bar.rb',
|
21
|
-
}.each do |input,expectation|
|
22
|
-
base.instance_variable_set('@first_render', input)
|
23
|
-
assert_equal expectation, base.send(:find_template_extension_from_first_render)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_should_report_file_exists_correctly
|
28
|
-
base = ActionView::Base.new
|
29
|
-
|
30
|
-
assert_nil base.send(:find_template_extension_from_first_render)
|
31
|
-
|
32
|
-
assert_equal false, base.send(:file_exists?, 'test.rhtml')
|
33
|
-
assert_equal false, base.send(:file_exists?, 'test.rb')
|
34
|
-
|
35
|
-
base.instance_variable_set('@first_render', 'foo.rb')
|
36
|
-
|
37
|
-
assert_equal 'rb', base.send(:find_template_extension_from_first_render)
|
38
|
-
|
39
|
-
assert_equal false, base.send(:file_exists?, 'baz')
|
40
|
-
assert_equal false, base.send(:file_exists?, 'baz.rb')
|
41
|
-
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../active_record_unit'
|
2
|
-
require "action_controller/test_case"
|
3
|
-
|
4
|
-
class ActionController::TestCase
|
5
|
-
self.fixture_path = File.dirname(__FILE__) + '/../fixtures'
|
6
|
-
self.use_transactional_fixtures = false
|
7
|
-
end
|
8
|
-
|
9
|
-
class DeveloperController < ActionController::Base
|
10
|
-
end
|
11
|
-
|
12
|
-
class DeveloperControllerTest < ActionController::TestCase
|
13
|
-
fixtures :developers
|
14
|
-
|
15
|
-
def setup
|
16
|
-
@david = developers(:david)
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_should_have_loaded_fixtures
|
20
|
-
assert_kind_of(Developer, @david)
|
21
|
-
assert_kind_of(Developer, developers(:jamis))
|
22
|
-
assert_equal(@developers.size, Developer.count)
|
23
|
-
end
|
24
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../abstract_unit'
|
2
|
-
|
3
|
-
MemCache = Struct.new(:MemCache, :address) unless Object.const_defined?(:MemCache)
|
4
|
-
|
5
|
-
class FragmentCacheStoreSettingTest < Test::Unit::TestCase
|
6
|
-
def teardown
|
7
|
-
ActionController::Base.fragment_cache_store = ActionController::Caching::Fragments::MemoryStore.new
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_file_fragment_cache_store
|
11
|
-
ActionController::Base.fragment_cache_store = :file_store, "/path/to/cache/directory"
|
12
|
-
assert_kind_of(
|
13
|
-
ActionController::Caching::Fragments::FileStore,
|
14
|
-
ActionController::Base.fragment_cache_store
|
15
|
-
)
|
16
|
-
assert_equal "/path/to/cache/directory", ActionController::Base.fragment_cache_store.cache_path
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_drb_fragment_cache_store
|
20
|
-
ActionController::Base.fragment_cache_store = :drb_store, "druby://localhost:9192"
|
21
|
-
assert_kind_of(
|
22
|
-
ActionController::Caching::Fragments::DRbStore,
|
23
|
-
ActionController::Base.fragment_cache_store
|
24
|
-
)
|
25
|
-
assert_equal "druby://localhost:9192", ActionController::Base.fragment_cache_store.address
|
26
|
-
end
|
27
|
-
|
28
|
-
if defined? CGI::Session::MemCacheStore
|
29
|
-
def test_mem_cache_fragment_cache_store
|
30
|
-
ActionController::Base.fragment_cache_store = :mem_cache_store, "localhost"
|
31
|
-
assert_kind_of(
|
32
|
-
ActionController::Caching::Fragments::MemCacheStore,
|
33
|
-
ActionController::Base.fragment_cache_store
|
34
|
-
)
|
35
|
-
assert_equal %w(localhost), ActionController::Base.fragment_cache_store.addresses
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_object_assigned_fragment_cache_store
|
40
|
-
ActionController::Base.fragment_cache_store = ActionController::Caching::Fragments::FileStore.new("/path/to/cache/directory")
|
41
|
-
assert_kind_of(
|
42
|
-
ActionController::Caching::Fragments::FileStore,
|
43
|
-
ActionController::Base.fragment_cache_store
|
44
|
-
)
|
45
|
-
assert_equal "/path/to/cache/directory", ActionController::Base.fragment_cache_store.cache_path
|
46
|
-
end
|
47
|
-
end
|
@@ -1,197 +0,0 @@
|
|
1
|
-
require "#{File.dirname(__FILE__)}/../abstract_unit"
|
2
|
-
require 'action_view/helpers/date_helper'
|
3
|
-
require 'action_view/compiled_templates'
|
4
|
-
|
5
|
-
class CompiledTemplateTests < Test::Unit::TestCase
|
6
|
-
def setup
|
7
|
-
@ct = ActionView::CompiledTemplates.new
|
8
|
-
@v = Class.new
|
9
|
-
@v.send :include, @ct
|
10
|
-
@a = './test_compile_template_a.rhtml'
|
11
|
-
@b = './test_compile_template_b.rhtml'
|
12
|
-
@s = './test_compile_template_link.rhtml'
|
13
|
-
end
|
14
|
-
def teardown
|
15
|
-
[@a, @b, @s].each do |f|
|
16
|
-
FileUtils.rm(f) if File.exist?(f) || File.symlink?(f)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
attr_reader :ct, :v
|
20
|
-
|
21
|
-
def test_name_allocation
|
22
|
-
hi_world = ct.method_names['hi world']
|
23
|
-
hi_sexy = ct.method_names['hi sexy']
|
24
|
-
wish_upon_a_star = ct.method_names['I love seeing decent error messages']
|
25
|
-
|
26
|
-
assert_equal hi_world, ct.method_names['hi world']
|
27
|
-
assert_equal hi_sexy, ct.method_names['hi sexy']
|
28
|
-
assert_equal wish_upon_a_star, ct.method_names['I love seeing decent error messages']
|
29
|
-
assert_equal 3, [hi_world, hi_sexy, wish_upon_a_star].uniq.length
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_wrap_source
|
33
|
-
assert_equal(
|
34
|
-
"def aliased_assignment(value)\nself.value = value\nend",
|
35
|
-
@ct.wrap_source(:aliased_assignment, [:value], 'self.value = value')
|
36
|
-
)
|
37
|
-
|
38
|
-
assert_equal(
|
39
|
-
"def simple()\nnil\nend",
|
40
|
-
@ct.wrap_source(:simple, [], 'nil')
|
41
|
-
)
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_compile_source_single_method
|
45
|
-
selector = ct.compile_source('doubling method', [:a], 'a + a')
|
46
|
-
assert_equal 2, @v.new.send(selector, 1)
|
47
|
-
assert_equal 4, @v.new.send(selector, 2)
|
48
|
-
assert_equal -4, @v.new.send(selector, -2)
|
49
|
-
assert_equal 0, @v.new.send(selector, 0)
|
50
|
-
selector
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_compile_source_two_method
|
54
|
-
sel1 = test_compile_source_single_method # compile the method in the other test
|
55
|
-
sel2 = ct.compile_source('doubling method', [:a, :b], 'a + b + a + b')
|
56
|
-
assert_not_equal sel1, sel2
|
57
|
-
|
58
|
-
assert_equal 2, @v.new.send(sel1, 1)
|
59
|
-
assert_equal 4, @v.new.send(sel1, 2)
|
60
|
-
|
61
|
-
assert_equal 6, @v.new.send(sel2, 1, 2)
|
62
|
-
assert_equal 32, @v.new.send(sel2, 15, 1)
|
63
|
-
end
|
64
|
-
|
65
|
-
def test_mtime
|
66
|
-
t1 = Time.now
|
67
|
-
|
68
|
-
test_compile_source_single_method
|
69
|
-
mtime = ct.mtime('doubling method', [:a])
|
70
|
-
|
71
|
-
assert mtime < Time.now
|
72
|
-
assert mtime > t1
|
73
|
-
end
|
74
|
-
|
75
|
-
uses_mocha 'test_compile_time' do
|
76
|
-
def test_compile_time
|
77
|
-
t = Time.now
|
78
|
-
|
79
|
-
File.open(@a, "w"){|f| f.puts @a}
|
80
|
-
File.open(@b, "w"){|f| f.puts @b}
|
81
|
-
# windows doesn't support symlinks (even under cygwin)
|
82
|
-
windows = (RUBY_PLATFORM =~ /win32/)
|
83
|
-
`ln -s #{@a} #{@s}` unless windows
|
84
|
-
|
85
|
-
v = ActionView::Base.new
|
86
|
-
v.base_path = '.'
|
87
|
-
v.cache_template_loading = false
|
88
|
-
|
89
|
-
# All templates were created at t+1
|
90
|
-
File::Stat.any_instance.expects(:mtime).times(windows ? 2 : 3).returns(t + 1.second)
|
91
|
-
|
92
|
-
# private methods template_changed_since? and compile_template?
|
93
|
-
# should report true for all since they have not been compiled
|
94
|
-
assert v.send(:template_changed_since?, @a, t)
|
95
|
-
assert v.send(:template_changed_since?, @b, t)
|
96
|
-
assert v.send(:template_changed_since?, @s, t) unless windows
|
97
|
-
|
98
|
-
assert v.send(:compile_template?, nil, @a, {})
|
99
|
-
assert v.send(:compile_template?, nil, @b, {})
|
100
|
-
assert v.send(:compile_template?, nil, @s, {}) unless windows
|
101
|
-
|
102
|
-
@handler = ActionView::Base.handler_for_extension(:rhtml)
|
103
|
-
|
104
|
-
# All templates are rendered at t+2
|
105
|
-
Time.expects(:now).times(windows ? 2 : 3).returns(t + 2.seconds)
|
106
|
-
v.send(:compile_and_render_template, @handler, '', @a)
|
107
|
-
v.send(:compile_and_render_template, @handler, '', @b)
|
108
|
-
v.send(:compile_and_render_template, @handler, '', @s) unless windows
|
109
|
-
a_n = v.method_names[@a]
|
110
|
-
b_n = v.method_names[@b]
|
111
|
-
s_n = v.method_names[@s] unless windows
|
112
|
-
# all of the files have changed since last compile
|
113
|
-
assert v.compile_time[a_n] > t
|
114
|
-
assert v.compile_time[b_n] > t
|
115
|
-
assert v.compile_time[s_n] > t unless windows
|
116
|
-
|
117
|
-
# private methods template_changed_since? and compile_template?
|
118
|
-
# should report false for all since none have changed since compile
|
119
|
-
File::Stat.any_instance.expects(:mtime).times(windows ? 6 : 12).returns(t + 1.second)
|
120
|
-
assert !v.send(:template_changed_since?, @a, v.compile_time[a_n])
|
121
|
-
assert !v.send(:template_changed_since?, @b, v.compile_time[b_n])
|
122
|
-
assert !v.send(:template_changed_since?, @s, v.compile_time[s_n]) unless windows
|
123
|
-
assert !v.send(:compile_template?, nil, @a, {})
|
124
|
-
assert !v.send(:compile_template?, nil, @b, {})
|
125
|
-
assert !v.send(:compile_template?, nil, @s, {}) unless windows
|
126
|
-
v.send(:compile_and_render_template, @handler, '', @a)
|
127
|
-
v.send(:compile_and_render_template, @handler, '', @b)
|
128
|
-
v.send(:compile_and_render_template, @handler, '', @s) unless windows
|
129
|
-
# none of the files have changed since last compile
|
130
|
-
assert v.compile_time[a_n] < t + 3.seconds
|
131
|
-
assert v.compile_time[b_n] < t + 3.seconds
|
132
|
-
assert v.compile_time[s_n] < t + 3.seconds unless windows
|
133
|
-
|
134
|
-
`rm #{@s}; ln -s #{@b} #{@s}` unless windows
|
135
|
-
# private methods template_changed_since? and compile_template?
|
136
|
-
# should report true for symlink since it has changed since compile
|
137
|
-
|
138
|
-
# t + 3.seconds is for the symlink
|
139
|
-
File::Stat.any_instance.expects(:mtime).times(windows ? 6 : 9).returns(
|
140
|
-
*(windows ? [ t + 1.second, t + 1.second ] :
|
141
|
-
[ t + 1.second, t + 1.second, t + 3.second ]) * 3)
|
142
|
-
assert !v.send(:template_changed_since?, @a, v.compile_time[a_n])
|
143
|
-
assert !v.send(:template_changed_since?, @b, v.compile_time[b_n])
|
144
|
-
assert v.send(:template_changed_since?, @s, v.compile_time[s_n]) unless windows
|
145
|
-
assert !v.send(:compile_template?, nil, @a, {})
|
146
|
-
assert !v.send(:compile_template?, nil, @b, {})
|
147
|
-
assert v.send(:compile_template?, nil, @s, {}) unless windows
|
148
|
-
|
149
|
-
# Only the symlink template gets rendered at t+3
|
150
|
-
Time.stubs(:now).returns(t + 3.seconds) unless windows
|
151
|
-
v.send(:compile_and_render_template, @handler, '', @a)
|
152
|
-
v.send(:compile_and_render_template, @handler, '', @b)
|
153
|
-
v.send(:compile_and_render_template, @handler, '', @s) unless windows
|
154
|
-
# the symlink has changed since last compile
|
155
|
-
assert v.compile_time[a_n] < t + 3.seconds
|
156
|
-
assert v.compile_time[b_n] < t + 3.seconds
|
157
|
-
assert_equal v.compile_time[s_n], t + 3.seconds unless windows
|
158
|
-
|
159
|
-
FileUtils.touch @b
|
160
|
-
# private methods template_changed_since? and compile_template?
|
161
|
-
# should report true for symlink and file at end of symlink
|
162
|
-
# since it has changed since last compile
|
163
|
-
#
|
164
|
-
# t+4 is for @b and also for the file that @s points to, which is @b
|
165
|
-
File::Stat.any_instance.expects(:mtime).times(windows ? 6 : 12).returns(
|
166
|
-
*(windows ? [ t + 1.second, t + 4.seconds ] :
|
167
|
-
[ t + 1.second, t + 4.seconds, t + 3.second, t + 4.seconds ]) * 3)
|
168
|
-
assert !v.send(:template_changed_since?, @a, v.compile_time[a_n])
|
169
|
-
assert v.send(:template_changed_since?, @b, v.compile_time[b_n])
|
170
|
-
assert v.send(:template_changed_since?, @s, v.compile_time[s_n]) unless windows
|
171
|
-
assert !v.send(:compile_template?, nil, @a, {})
|
172
|
-
assert v.send(:compile_template?, nil, @b, {})
|
173
|
-
assert v.send(:compile_template?, nil, @s, {}) unless windows
|
174
|
-
|
175
|
-
Time.expects(:now).times(windows ? 1 : 2).returns(t + 5.seconds)
|
176
|
-
v.send(:compile_and_render_template, @handler, '', @a)
|
177
|
-
v.send(:compile_and_render_template, @handler, '', @b)
|
178
|
-
v.send(:compile_and_render_template, @handler, '', @s) unless windows
|
179
|
-
# the file at the end of the symlink has changed since last compile
|
180
|
-
# both the symlink and the file at the end of it should be recompiled
|
181
|
-
assert v.compile_time[a_n] < t + 5.seconds
|
182
|
-
assert_equal v.compile_time[b_n], t + 5.seconds
|
183
|
-
assert_equal v.compile_time[s_n], t + 5.seconds unless windows
|
184
|
-
end
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
module ActionView
|
189
|
-
class Base
|
190
|
-
def compile_time
|
191
|
-
@@compile_time
|
192
|
-
end
|
193
|
-
def method_names
|
194
|
-
@@method_names
|
195
|
-
end
|
196
|
-
end
|
197
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../abstract_unit'
|
2
|
-
|
3
|
-
class DeprecateIvars < ActionController::Base
|
4
|
-
def use_logger
|
5
|
-
render :inline => "<%= logger.class -%>"
|
6
|
-
end
|
7
|
-
|
8
|
-
def use_old_logger
|
9
|
-
render :inline => "<%= @logger.class -%>"
|
10
|
-
end
|
11
|
-
|
12
|
-
def use_action_name
|
13
|
-
render :inline => "<%= action_name -%>"
|
14
|
-
end
|
15
|
-
|
16
|
-
def use_old_action_name
|
17
|
-
render :inline => "<%= @action_name -%>"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
class DeprecateIvarsTest < Test::Unit::TestCase
|
22
|
-
def setup
|
23
|
-
@request = ActionController::TestRequest.new
|
24
|
-
@response = ActionController::TestResponse.new
|
25
|
-
|
26
|
-
@controller = DeprecateIvars.new
|
27
|
-
@controller.logger = Logger.new(nil)
|
28
|
-
|
29
|
-
@request.host = "rubyonrails.com"
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_logger
|
33
|
-
assert_not_deprecated { get :use_logger }
|
34
|
-
assert_equal "Logger", @response.body
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_deprecated_logger
|
38
|
-
assert_deprecated { get :use_old_logger }
|
39
|
-
assert_equal "Logger", @response.body
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_action_name
|
43
|
-
assert_not_deprecated { get :use_action_name }
|
44
|
-
assert_equal "use_action_name", @response.body
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_deprecated_action_name
|
48
|
-
assert_deprecated { get :use_old_action_name }
|
49
|
-
assert_equal "use_old_action_name", @response.body
|
50
|
-
end
|
51
|
-
end
|