From 48f98df5aa6dc5cc87faa9e8f796fc2ad893e1a3 Mon Sep 17 00:00:00 2001 From: Manfred Stienstra Date: Fri, 25 Feb 2011 12:34:46 +0100 Subject: [PATCH] Add a failing test case for an implicit action with a before filter. --- actionpack/test/controller/filters_test.rb | 22 ++++++++++++++++++++ .../filter_test/implicit_actions/edit.html.erb | 1 + .../filter_test/implicit_actions/show.html.erb | 1 + 3 files changed, 24 insertions(+), 0 deletions(-) create mode 100644 actionpack/test/fixtures/filter_test/implicit_actions/edit.html.erb create mode 100644 actionpack/test/fixtures/filter_test/implicit_actions/show.html.erb diff --git a/actionpack/test/controller/filters_test.rb b/actionpack/test/controller/filters_test.rb index 330fa27..c953322 100644 --- a/actionpack/test/controller/filters_test.rb +++ b/actionpack/test/controller/filters_test.rb @@ -505,6 +505,16 @@ class FilterTest < ActionController::TestCase end end + class ImplicitActionsController < ActionController::Base + before_filter :find_user, :only => :edit + + private + + def find_user + @user = 'Jenny' + end + end + def test_sweeper_should_not_block_rendering response = test_process(SweeperTestController) assert_equal 'hello world', response.body @@ -783,6 +793,18 @@ class FilterTest < ActionController::TestCase assert_equal("I rescued this: #", response.body) end + def test_filter_runs_for_implicitly_defined_action_when_needed + test_process(ImplicitActionsController, 'edit') + assert_equal 'Jenny', assigns(:user) + assert_equal 'edit', response.body + end + + def test_filter_does_not_run_for_implicity_defined_action_when_not_needed + test_process(ImplicitActionsController, 'show') + assert_nil assigns(:user) + assert_equal 'show', response.body + end + private def test_process(controller, action = "show") @controller = controller.is_a?(Class) ? controller.new : controller diff --git a/actionpack/test/fixtures/filter_test/implicit_actions/edit.html.erb b/actionpack/test/fixtures/filter_test/implicit_actions/edit.html.erb new file mode 100644 index 0000000..8491ab9 --- /dev/null +++ b/actionpack/test/fixtures/filter_test/implicit_actions/edit.html.erb @@ -0,0 +1 @@ +edit \ No newline at end of file diff --git a/actionpack/test/fixtures/filter_test/implicit_actions/show.html.erb b/actionpack/test/fixtures/filter_test/implicit_actions/show.html.erb new file mode 100644 index 0000000..0a89cec --- /dev/null +++ b/actionpack/test/fixtures/filter_test/implicit_actions/show.html.erb @@ -0,0 +1 @@ +show \ No newline at end of file -- 1.7.2.3