class FilterTest

Public Instance Methods

test_a_rescuing_around_action() click to toggle source
# File actionpack/test/controller/filters_test.rb, line 816
def test_a_rescuing_around_action
  response = nil
  assert_nothing_raised do
    response = test_process(RescuedController)
  end

  assert response.successful?
  assert_equal("I rescued this: #<FilterTest::ErrorToRescue: Something made the bad noise.>", response.body)
end
test_actions_obey_only_and_except_for_implicit_actions() click to toggle source
# File actionpack/test/controller/filters_test.rb, line 826
def test_actions_obey_only_and_except_for_implicit_actions
  test_process(ImplicitActionsController, "show")
  assert_equal "Except", @controller.instance_variable_get(:@except)
  assert_not @controller.instance_variable_defined?(:@only)
  assert_equal "show", response.body

  test_process(ImplicitActionsController, "edit")
  assert_equal "Only", @controller.instance_variable_get(:@only)
  assert_not @controller.instance_variable_defined?(:@except)
  assert_equal "edit", response.body
end
test_actions_with_mixed_specialization_run_in_order() click to toggle source
# File actionpack/test/controller/filters_test.rb, line 746
def test_actions_with_mixed_specialization_run_in_order
  assert_nothing_raised do
    response = test_process(MixedSpecializationController, "bar")
    assert_equal "bar", response.body
  end

  assert_nothing_raised do
    response = test_process(MixedSpecializationController, "foo")
    assert_equal "foo", response.body
  end
end
test_added_action_to_inheritance_graph() click to toggle source
# File actionpack/test/controller/filters_test.rb, line 556
def test_added_action_to_inheritance_graph
  assert_equal [ :ensure_login ], TestController.before_actions
end
test_after_actions_are_not_run_if_around_action_does_not_yield() click to toggle source
# File actionpack/test/controller/filters_test.rb, line 550
def test_after_actions_are_not_run_if_around_action_does_not_yield
  controller = NonYieldingAroundFilterController.new
  test_process(controller, "index")
  assert_equal ["filter_one", "it didn't yield"], controller.instance_variable_get(:@filters)
end
test_around_action() click to toggle source
# File actionpack/test/controller/filters_test.rb, line 690
def test_around_action
  test_process(AroundFilterController)
  assert @controller.instance_variable_get(:@before_ran)
  assert @controller.instance_variable_get(:@after_ran)
end
test_base_class_in_isolation() click to toggle source
# File actionpack/test/controller/filters_test.rb, line 560
def test_base_class_in_isolation
  assert_equal [ ], ActionController::Base.before_actions
end
test_before_action_redirects_breaks_actioning_chain_for_after_action() click to toggle source
# File actionpack/test/controller/filters_test.rb, line 726
def test_before_action_redirects_breaks_actioning_chain_for_after_action
  test_process(BeforeActionRedirectionController)
  assert_response :redirect
  assert_equal "http://test.host/filter_test/before_action_redirection/target_of_redirection", redirect_to_url
  assert_equal %w( before_action_redirects ), @controller.instance_variable_get(:@ran_filter)
end
test_before_action_redirects_breaks_actioning_chain_for_preprend_after_action() click to toggle source
# File actionpack/test/controller/filters_test.rb, line 739
def test_before_action_redirects_breaks_actioning_chain_for_preprend_after_action
  test_process(BeforeActionRedirectionForPrependAfterActionController)
  assert_response :redirect
  assert_equal "http://test.host/filter_test/before_action_redirection_for_prepend_after_action/target_of_redirection", redirect_to_url
  assert_equal %w( before_action_redirects ), @controller.instance_variable_get(:@ran_filter)
end
test_before_action_rendering_breaks_actioning_chain_for_after_action() click to toggle source
# File actionpack/test/controller/filters_test.rb, line 720
def test_before_action_rendering_breaks_actioning_chain_for_after_action
  test_process(RenderingController)
  assert_equal %w( before_action_rendering ), @controller.instance_variable_get(:@ran_filter)
  assert_not @controller.instance_variable_defined?(:@ran_action)
end
test_before_action_rendering_breaks_actioning_chain_for_preprend_after_action() click to toggle source
# File actionpack/test/controller/filters_test.rb, line 733
def test_before_action_rendering_breaks_actioning_chain_for_preprend_after_action
  test_process(RenderingForPrependAfterActionController)
  assert_equal %w( before_action_rendering ), @controller.instance_variable_get(:@ran_filter)
  assert_not @controller.instance_variable_defined?(:@ran_action)
end
test_before_after_class_action() click to toggle source
# File actionpack/test/controller/filters_test.rb, line 696
def test_before_after_class_action
  test_process(BeforeAfterClassFilterController)
  assert @controller.instance_variable_get(:@before_ran)
  assert @controller.instance_variable_get(:@after_ran)
end
test_changing_the_requirements() click to toggle source
# File actionpack/test/controller/filters_test.rb, line 811
def test_changing_the_requirements
  test_process(ChangingTheRequirementsController, "go_wild")
  assert_not @controller.instance_variable_defined?(:@ran_filter)
end
test_condition_skipping_of_actions_when_siblings_also_have_conditions() click to toggle source
# File actionpack/test/controller/filters_test.rb, line 802
def test_condition_skipping_of_actions_when_siblings_also_have_conditions
  test_process(ChildOfConditionalParentController)
  assert_equal %w( conditional_in_parent_before conditional_in_parent_after ), @controller.instance_variable_get(:@ran_filter)
  test_process(AnotherChildOfConditionalParentController)
  assert_equal %w( conditional_in_parent_after ), @controller.instance_variable_get(:@ran_filter)
  test_process(ChildOfConditionalParentController)
  assert_equal %w( conditional_in_parent_before conditional_in_parent_after ), @controller.instance_variable_get(:@ran_filter)
end
test_conditional_skipping_of_actions() click to toggle source
# File actionpack/test/controller/filters_test.rb, line 783
def test_conditional_skipping_of_actions
  test_process(ConditionalSkippingController, "login")
  assert_not @controller.instance_variable_defined?(:@ran_filter)
  test_process(ConditionalSkippingController, "change_password")
  assert_equal %w( ensure_login find_user ), @controller.instance_variable_get(:@ran_filter)

  test_process(ConditionalSkippingController, "login")
  assert !@controller.instance_variable_defined?("@ran_after_action")
  test_process(ConditionalSkippingController, "change_password")
  assert_equal %w( clean_up ), @controller.instance_variable_get("@ran_after_action")
end
test_conditional_skipping_of_actions_when_parent_action_is_also_conditional() click to toggle source
# File actionpack/test/controller/filters_test.rb, line 795
def test_conditional_skipping_of_actions_when_parent_action_is_also_conditional
  test_process(ChildOfConditionalParentController)
  assert_equal %w( conditional_in_parent_before conditional_in_parent_after ), @controller.instance_variable_get(:@ran_filter)
  test_process(ChildOfConditionalParentController, "another_action")
  assert_not @controller.instance_variable_defined?(:@ran_filter)
end
test_dynamic_dispatch() click to toggle source
# File actionpack/test/controller/filters_test.rb, line 758
def test_dynamic_dispatch
  %w(foo bar baz).each do |action|
    @request.query_parameters[:choose] = action
    response = DynamicDispatchController.action(action).call(@request.env).last
    assert_equal action, response.body
  end
end
test_except_is_ignored_when_used_with_if() click to toggle source
# File actionpack/test/controller/filters_test.rb, line 618
def test_except_is_ignored_when_used_with_if
  test_process(SkipFilterUsingIfAndExcept, "login")
  assert_equal %w(ensure_login), @controller.instance_variable_get(:@ran_filter)
end
test_having_properties_in_around_action() click to toggle source
# File actionpack/test/controller/filters_test.rb, line 702
def test_having_properties_in_around_action
  test_process(AroundFilterController)
  assert_equal "before and after", @controller.instance_variable_get(:@execution_log)
end
test_if_is_ignored_when_used_with_only() click to toggle source
# File actionpack/test/controller/filters_test.rb, line 613
def test_if_is_ignored_when_used_with_only
  test_process(SkipFilterUsingOnlyAndIf, "login")
  assert_not @controller.instance_variable_defined?(:@ran_filter)
end
test_non_yielding_around_actions_do_not_raise() click to toggle source
# File actionpack/test/controller/filters_test.rb, line 543
def test_non_yielding_around_actions_do_not_raise
  controller = NonYieldingAroundFilterController.new
  assert_nothing_raised do
    test_process(controller, "index")
  end
end
test_prepending_action() click to toggle source
# File actionpack/test/controller/filters_test.rb, line 564
def test_prepending_action
  assert_equal [ :wonderful_life, :ensure_login ], PrependingController.before_actions
end
test_prepending_and_appending_around_action() click to toggle source
# File actionpack/test/controller/filters_test.rb, line 707
def test_prepending_and_appending_around_action
  test_process(MixedFilterController)
  assert_equal " before aroundfilter  before procfilter  before appended aroundfilter " \
               " after appended aroundfilter  after procfilter  after aroundfilter ",
               MixedFilterController.execution_log
end
test_rendering_breaks_actioning_chain() click to toggle source
# File actionpack/test/controller/filters_test.rb, line 714
def test_rendering_breaks_actioning_chain
  response = test_process(RenderingController)
  assert_equal "something else", response.body
  assert_not @controller.instance_variable_defined?(:@ran_action)
end
test_running_actions() click to toggle source
# File actionpack/test/controller/filters_test.rb, line 568
def test_running_actions
  test_process(PrependingController)
  assert_equal %w( wonderful_life ensure_login ),
    @controller.instance_variable_get(:@ran_filter)
end
test_running_actions_with_class() click to toggle source
# File actionpack/test/controller/filters_test.rb, line 584
def test_running_actions_with_class
  test_process(AuditController)
  assert @controller.instance_variable_get(:@was_audited)
end
test_running_actions_with_implicit_proc() click to toggle source
# File actionpack/test/controller/filters_test.rb, line 579
def test_running_actions_with_implicit_proc
  test_process(ImplicitProcController)
  assert @controller.instance_variable_get(:@ran_proc_action)
end
test_running_actions_with_proc() click to toggle source
# File actionpack/test/controller/filters_test.rb, line 574
def test_running_actions_with_proc
  test_process(ProcController)
  assert @controller.instance_variable_get(:@ran_proc_action)
end
test_running_anomalous_yet_valid_condition_actions() click to toggle source
# File actionpack/test/controller/filters_test.rb, line 589
def test_running_anomalous_yet_valid_condition_actions
  test_process(AnomolousYetValidConditionController)
  assert_equal %w( ensure_login ), @controller.instance_variable_get(:@ran_filter)
  assert @controller.instance_variable_get(:@ran_class_action)
  assert @controller.instance_variable_get(:@ran_proc_action1)
  assert @controller.instance_variable_get(:@ran_proc_action2)

  test_process(AnomolousYetValidConditionController, "show_without_action")
  assert_not @controller.instance_variable_defined?(:@ran_filter)
  assert_not @controller.instance_variable_defined?(:@ran_class_action)
  assert_not @controller.instance_variable_defined?(:@ran_proc_action1)
  assert_not @controller.instance_variable_defined?(:@ran_proc_action2)
end
test_running_before_and_after_condition_actions() click to toggle source
# File actionpack/test/controller/filters_test.rb, line 683
def test_running_before_and_after_condition_actions
  test_process(BeforeAndAfterConditionController)
  assert_equal %w( ensure_login clean_up_tmp), @controller.instance_variable_get(:@ran_filter)
  test_process(BeforeAndAfterConditionController, "show_without_action")
  assert_not @controller.instance_variable_defined?(:@ran_filter)
end
test_running_collection_condition_actions() click to toggle source
# File actionpack/test/controller/filters_test.rb, line 635
def test_running_collection_condition_actions
  test_process(ConditionalCollectionFilterController)
  assert_equal %w( ensure_login ), @controller.instance_variable_get(:@ran_filter)
  test_process(ConditionalCollectionFilterController, "show_without_action")
  assert_not @controller.instance_variable_defined?(:@ran_filter)
  test_process(ConditionalCollectionFilterController, "another_action")
  assert_not @controller.instance_variable_defined?(:@ran_filter)
end
test_running_conditional_options() click to toggle source
# File actionpack/test/controller/filters_test.rb, line 603
def test_running_conditional_options
  test_process(ConditionalOptionsFilter)
  assert_equal %w( ensure_login ), @controller.instance_variable_get(:@ran_filter)
end
test_running_conditional_skip_options() click to toggle source
# File actionpack/test/controller/filters_test.rb, line 608
def test_running_conditional_skip_options
  test_process(ConditionalOptionsSkipFilter)
  assert_equal %w( ensure_login ), @controller.instance_variable_get(:@ran_filter)
end
test_running_except_condition_actions() click to toggle source
# File actionpack/test/controller/filters_test.rb, line 661
def test_running_except_condition_actions
  test_process(ExceptConditionSymController)
  assert_equal %w( ensure_login ), @controller.instance_variable_get(:@ran_filter)
  test_process(ExceptConditionSymController, "show_without_action")
  assert_not @controller.instance_variable_defined?(:@ran_filter)

  test_process(ExceptConditionProcController)
  assert @controller.instance_variable_get(:@ran_proc_action)
  test_process(ExceptConditionProcController, "show_without_action")
  assert_not @controller.instance_variable_defined?(:@ran_proc_action)

  test_process(ExceptConditionClassController)
  assert @controller.instance_variable_get(:@ran_class_action)
  test_process(ExceptConditionClassController, "show_without_action")
  assert_not @controller.instance_variable_defined?(:@ran_class_action)
end
test_running_only_condition_actions() click to toggle source
# File actionpack/test/controller/filters_test.rb, line 644
def test_running_only_condition_actions
  test_process(OnlyConditionSymController)
  assert_equal %w( ensure_login ), @controller.instance_variable_get(:@ran_filter)
  test_process(OnlyConditionSymController, "show_without_action")
  assert_not @controller.instance_variable_defined?(:@ran_filter)

  test_process(OnlyConditionProcController)
  assert @controller.instance_variable_get(:@ran_proc_action)
  test_process(OnlyConditionProcController, "show_without_action")
  assert_not @controller.instance_variable_defined?(:@ran_proc_action)

  test_process(OnlyConditionClassController)
  assert @controller.instance_variable_get(:@ran_class_action)
  test_process(OnlyConditionClassController, "show_without_action")
  assert_not @controller.instance_variable_defined?(:@ran_class_action)
end
test_running_only_condition_and_conditional_options() click to toggle source
# File actionpack/test/controller/filters_test.rb, line 678
def test_running_only_condition_and_conditional_options
  test_process(OnlyConditionalOptionsFilter, "show")
  assert_not @controller.instance_variable_defined?(:@ran_conditional_index_proc)
end
test_running_prepended_before_and_after_action() click to toggle source
# File actionpack/test/controller/filters_test.rb, line 766
def test_running_prepended_before_and_after_action
  test_process(PrependingBeforeAndAfterController)
  assert_equal %w( before_all between_before_all_and_after_all after_all ), @controller.instance_variable_get(:@ran_filter)
end
test_skipping_and_limiting_controller() click to toggle source
# File actionpack/test/controller/filters_test.rb, line 771
def test_skipping_and_limiting_controller
  test_process(SkippingAndLimitedController, "index")
  assert_equal %w( ensure_login ), @controller.instance_variable_get(:@ran_filter)
  test_process(SkippingAndLimitedController, "public")
  assert_not @controller.instance_variable_defined?(:@ran_filter)
end
test_skipping_and_reordering_controller() click to toggle source
# File actionpack/test/controller/filters_test.rb, line 778
def test_skipping_and_reordering_controller
  test_process(SkippingAndReorderingController, "index")
  assert_equal %w( find_record ensure_login ), @controller.instance_variable_get(:@ran_filter)
end
test_skipping_class_actions() click to toggle source
# File actionpack/test/controller/filters_test.rb, line 623
def test_skipping_class_actions
  test_process(ClassController)
  assert_equal true, @controller.instance_variable_get(:@ran_class_action)

  skipping_class_controller = Class.new(ClassController) do
    skip_before_action ConditionalClassFilter
  end

  test_process(skipping_class_controller)
  assert_not @controller.instance_variable_defined?(:@ran_class_action)
end

Private Instance Methods

test_process(controller, action = "show") click to toggle source
# File actionpack/test/controller/filters_test.rb, line 839
def test_process(controller, action = "show")
  @controller = controller.is_a?(Class) ? controller.new : controller

  process(action)
end