提交 bb0f4a12 编写于 作者: Y Yves Senn 提交者: Yves Senn

prefix TemplateAssertions ivars (#7459)

上级 d0ad97b9
## Rails 4.0.0 (unreleased) ## ## Rails 4.0.0 (unreleased) ##
* Rename internal variables on ActionController::TemplateAssertions to prevent
naming collisions. @partials, @templates and @layouts are now prefixed with an underscore.
Fix #7459
*Yves Senn*
* `resource` and `resources` don't modify the passed options hash * `resource` and `resources` don't modify the passed options hash
Fix #7777 Fix #7777
......
...@@ -12,16 +12,16 @@ module TemplateAssertions ...@@ -12,16 +12,16 @@ module TemplateAssertions
end end
def setup_subscriptions def setup_subscriptions
@partials = Hash.new(0) @_partials = Hash.new(0)
@templates = Hash.new(0) @_templates = Hash.new(0)
@layouts = Hash.new(0) @_layouts = Hash.new(0)
ActiveSupport::Notifications.subscribe("render_template.action_view") do |name, start, finish, id, payload| ActiveSupport::Notifications.subscribe("render_template.action_view") do |name, start, finish, id, payload|
path = payload[:layout] path = payload[:layout]
if path if path
@layouts[path] += 1 @_layouts[path] += 1
if path =~ /^layouts\/(.*)/ if path =~ /^layouts\/(.*)/
@layouts[$1] += 1 @_layouts[$1] += 1
end end
end end
end end
...@@ -32,11 +32,11 @@ def setup_subscriptions ...@@ -32,11 +32,11 @@ def setup_subscriptions
partial = path =~ /^.*\/_[^\/]*$/ partial = path =~ /^.*\/_[^\/]*$/
if partial if partial
@partials[path] += 1 @_partials[path] += 1
@partials[path.split("/").last] += 1 @_partials[path.split("/").last] += 1
end end
@templates[path] += 1 @_templates[path] += 1
end end
end end
...@@ -46,9 +46,9 @@ def teardown_subscriptions ...@@ -46,9 +46,9 @@ def teardown_subscriptions
end end
def process(*args) def process(*args)
@partials = Hash.new(0) @_partials = Hash.new(0)
@templates = Hash.new(0) @_templates = Hash.new(0)
@layouts = Hash.new(0) @_layouts = Hash.new(0)
super super
end end
...@@ -88,7 +88,7 @@ def assert_template(options = {}, message = nil) ...@@ -88,7 +88,7 @@ def assert_template(options = {}, message = nil)
case options case options
when NilClass, Regexp, String, Symbol when NilClass, Regexp, String, Symbol
options = options.to_s if Symbol === options options = options.to_s if Symbol === options
rendered = @templates rendered = @_templates
msg = message || sprintf("expecting <%s> but rendering with <%s>", msg = message || sprintf("expecting <%s> but rendering with <%s>",
options.inspect, rendered.keys) options.inspect, rendered.keys)
matches_template = matches_template =
...@@ -109,15 +109,15 @@ def assert_template(options = {}, message = nil) ...@@ -109,15 +109,15 @@ def assert_template(options = {}, message = nil)
if options.key?(:layout) if options.key?(:layout)
expected_layout = options[:layout] expected_layout = options[:layout]
msg = message || sprintf("expecting layout <%s> but action rendered <%s>", msg = message || sprintf("expecting layout <%s> but action rendered <%s>",
expected_layout, @layouts.keys) expected_layout, @_layouts.keys)
case expected_layout case expected_layout
when String, Symbol when String, Symbol
assert_includes @layouts.keys, expected_layout.to_s, msg assert_includes @_layouts.keys, expected_layout.to_s, msg
when Regexp when Regexp
assert(@layouts.keys.any? {|l| l =~ expected_layout }, msg) assert(@_layouts.keys.any? {|l| l =~ expected_layout }, msg)
when nil, false when nil, false
assert(@layouts.empty?, msg) assert(@_layouts.empty?, msg)
end end
end end
...@@ -128,17 +128,17 @@ def assert_template(options = {}, message = nil) ...@@ -128,17 +128,17 @@ def assert_template(options = {}, message = nil)
assert_equal(v, actual_locals[k]) assert_equal(v, actual_locals[k])
end end
elsif expected_count = options[:count] elsif expected_count = options[:count]
actual_count = @partials[expected_partial] actual_count = @_partials[expected_partial]
msg = message || sprintf("expecting %s to be rendered %s time(s) but rendered %s time(s)", msg = message || sprintf("expecting %s to be rendered %s time(s) but rendered %s time(s)",
expected_partial, expected_count, actual_count) expected_partial, expected_count, actual_count)
assert(actual_count == expected_count.to_i, msg) assert(actual_count == expected_count.to_i, msg)
else else
msg = message || sprintf("expecting partial <%s> but action rendered <%s>", msg = message || sprintf("expecting partial <%s> but action rendered <%s>",
options[:partial], @partials.keys) options[:partial], @_partials.keys)
assert_includes @partials, expected_partial, msg assert_includes @_partials, expected_partial, msg
end end
elsif options.key?(:partial) elsif options.key?(:partial)
assert @partials.empty?, assert @_partials.empty?,
"Expected no partials to be rendered" "Expected no partials to be rendered"
end end
else else
......
...@@ -196,17 +196,17 @@ def view ...@@ -196,17 +196,17 @@ def view
:@_result, :@_result,
:@_routes, :@_routes,
:@controller, :@controller,
:@layouts, :@_layouts,
:@locals, :@locals,
:@method_name, :@method_name,
:@output_buffer, :@output_buffer,
:@partials, :@_partials,
:@passed, :@passed,
:@rendered, :@rendered,
:@request, :@request,
:@routes, :@routes,
:@tagged_logger, :@tagged_logger,
:@templates, :@_templates,
:@options, :@options,
:@test_passed, :@test_passed,
:@view, :@view,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册