This project is archived and is in readonly mode.
Let test authors set up controller_path in ActionView::TestCase without using stubs
Reported by David Chelimsky | May 26th, 2010 @ 02:13 AM
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.
Comments and changes to this ticket
-
David Chelimsky May 26th, 2010 @ 02:13 AM
- Assigned user set to Yehuda Katz (wycats)
-
David Chelimsky May 26th, 2010 @ 02:13 AM
- Assigned user changed from Yehuda Katz (wycats) to José Valim
-
David Chelimsky May 26th, 2010 @ 02:17 AM
- Tag set to action_view, patch
-
Repository May 26th, 2010 @ 07:50 AM
- 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 state:resolved]
Signed-off-by: José Valim jose.valim@gmail.com
http://github.com/rails/rails/commit/163152bfd0ea5344472d24b6f89e8c...
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Tags
Referenced by
- 4697 Let test authors set up controller_path in ActionView::TestCase without using stubs [#4697 state:resolved]