Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Let test authors set up controller_path in ActionView::TestCase without using stubs

#4697

AV::TestCase requires test authors to stub TestController.controller_path if the template being rendered in the test renders any partials. This is evidenced in rails' own tests:

# in actionpack/test/template/test_case_test.rb
test "is able to render partials from templates and also use instance variables" do
  TestController.stubs(:controller_path).returns('test')

  @customers = [stub(:name => 'Eloy'), stub(:name => 'Manfred')]
  assert_match /Hello: EloyHello: Manfred/, render(:file => 'test/list')
end

This patch makes it so you can just assign controller_path directly on the controller instance, and it handles setting it on the class.

http://github.com/dchelimsky/rails/commit/c725d23a535d2a3dd27c8c979...

The result is a test method like this:

# in actionpack/test/template/test_case_test.rb
test "is able to render partials from templates and also use instance variables" do
  controller.controller_path = 'test'

  @customers = [stub(:name => 'Eloy'), stub(:name => 'Manfred')]
  assert_match /Hello: EloyHello: Manfred/, render(:file => 'test/list')
end

This removes the dependency on a stub framework, and makes it easier for extension libraries (like rspec-rails) to set it implicitly without having to clean up after each test.

Reported by David Chelimsky · May 26th, 2010 @ 02:13 AM

State: resolved
Milestone: none
Assigned to: José Valim José Valim
Importance: none

Activity

  1. David Chelimsky
    David Chelimsky
    • Assigned user set to Yehuda Katz (wycats)

    May 26th, 2010 @ 02:13 AM

  2. David Chelimsky
    David Chelimsky
    • Assigned user changed from Yehuda Katz (wycats) to José Valim

    May 26th, 2010 @ 02:13 AM

  3. David Chelimsky
    David Chelimsky
    • Tag set to action_view, patch

    May 26th, 2010 @ 02:17 AM

  4. Repository
    Repository
    • State changed from new to resolved

    (from [163152bfd0ea5344472d24b6f89e8c957dbd66f5]) Support configuration of controller.controller_path on instances of ActionView::TestCase::TestController without stubs. Just say:

    @controller.controller_path = "path/i/need/for/this/test"

    [#4697 Let test authors set up controller_path in ActionView::TestCase without using... state:resolved]

    Signed-off-by: José Valim jose.valim@gmail.com
    http://github.com/rails/rails/commit/163152bfd0ea5344472d24b6f89e8c...

    May 26th, 2010 @ 07:50 AM