Skip to content

Commit

Permalink
Expose view via the view() method in AV::TestCase::Behavior
Browse files Browse the repository at this point in the history
- was exposed as _view, which suggested it was private
- left _view as an alias of view as not to break any extensions that are
  relying on _view

[rails#4932 state:resolved]
  • Loading branch information
dchelimsky committed Jun 23, 2010
1 parent 0e0df4b commit 62f5e35
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
13 changes: 8 additions & 5 deletions actionpack/lib/action_view/test_case.rb
Expand Up @@ -99,8 +99,8 @@ def config
end

def render(options = {}, local_assigns = {}, &block)
_view.assign(_assigns)
@rendered << output = _view.render(options, local_assigns, &block)
view.assign(_assigns)
@rendered << output = view.render(options, local_assigns, &block)
output
end

Expand Down Expand Up @@ -146,8 +146,9 @@ def _render_partial(options)
end
end

def _view
@_view ||= begin
# The instance of ActionView::Base that is used by +render+.
def view
@view ||= begin
view = ActionView::Base.new(ActionController::Base.view_paths, {}, @controller)
view.singleton_class.send :include, _helpers
view.singleton_class.send :include, @controller._router.url_helpers
Expand All @@ -159,10 +160,11 @@ def _view
end
end

alias_method :_view, :view

EXCLUDE_IVARS = %w{
@_assertion_wrapped
@_result
@_view
@controller
@layouts
@locals
Expand All @@ -174,6 +176,7 @@ def _view
@routes
@templates
@test_passed
@view
@view_context_class
}

Expand Down
28 changes: 16 additions & 12 deletions actionpack/test/template/test_case_test.rb
Expand Up @@ -37,8 +37,12 @@ class GeneralViewTest < ActionView::TestCase
include SharedTests
test_case = self

test "memoizes the _view" do
assert_same _view, _view
test "memoizes the view" do
assert_same view, view
end

test "exposes view as _view for backwards compatibility" do
assert_same _view, view
end

test "works without testing a helper module" do
Expand All @@ -61,13 +65,13 @@ class GeneralViewTest < ActionView::TestCase
end

test "delegates notice to request.flash" do
_view.request.flash.expects(:notice).with("this message")
_view.notice("this message")
view.request.flash.expects(:notice).with("this message")
view.notice("this message")
end

test "delegates alert to request.flash" do
_view.request.flash.expects(:alert).with("this message")
_view.alert("this message")
view.request.flash.expects(:alert).with("this message")
view.alert("this message")
end
end

Expand Down Expand Up @@ -136,7 +140,7 @@ def help_me
helper HelperThatInvokesProtectAgainstForgery

test "protect_from_forgery? in any helpers returns false" do
assert !_view.help_me
assert !view.help_me
end

end
Expand Down Expand Up @@ -200,10 +204,10 @@ def render_from_helper
assert_match /Hello: EloyHello: Manfred/, render(:file => 'test/list')
end

test "is able to render partials from templates and also use instance variables after _view has been referenced" do
test "is able to render partials from templates and also use instance variables after view has been referenced" do
@controller.controller_path = "test"

_view
view

@customers = [stub(:name => 'Eloy'), stub(:name => 'Manfred')]
assert_match /Hello: EloyHello: Manfred/, render(:file => 'test/list')
Expand All @@ -229,19 +233,19 @@ def render_from_helper
end

class RenderTemplateTest < ActionView::TestCase
test "render template supports specifying partials" do
test "supports specifying partials" do
controller.controller_path = "test"
render(:template => "test/calling_partial_with_layout")
assert_template :partial => "_partial_for_use_in_layout"
end

test "render template supports specifying locals (passing)" do
test "supports specifying locals (passing)" do
controller.controller_path = "test"
render(:template => "test/calling_partial_with_layout")
assert_template :partial => "_partial_for_use_in_layout", :locals => { :name => "David" }
end

test "render template supports specifying locals (failing)" do
test "supports specifying locals (failing)" do
controller.controller_path = "test"
render(:template => "test/calling_partial_with_layout")
assert_raise Test::Unit::AssertionFailedError, /Somebody else.*David/m do
Expand Down

0 comments on commit 62f5e35

Please sign in to comment.