<commit_before>require 'abstract_unit'

module AbstractController
  module Testing
  
    class ControllerWithCallbacks < AbstractController::Base
      include AbstractController::Callbacks
    end
    
    class Callback1 < ControllerWithCallbacks
      set_callback :process_action, :before, :first
      
      def first
        @text = "Hello world"
      end
      
      def index
        self.response_body = @text
      end
    end
    
    class TestCallbacks1 < ActiveSupport::TestCase
      test "basic callbacks work" do
        controller = Callback1.new
        result = controller.process(:index)
        assert_equal "Hello world", controller.response_body
      end
    end

    class Callback2 < ControllerWithCallbacks
      before_filter :first
      after_filter :second
      around_filter :aroundz
      
      def first
        @text = "Hello world"
      end
      
      def second
        @second = "Goodbye"
      end
      
      def aroundz
        @aroundz = "FIRST"
        yield
        @aroundz << "SECOND"
      end
      
      def index
        self.response_body = @text
      end      
    end
    
    class TestCallbacks2 < ActiveSupport::TestCase
      def setup
        @controller = Callback2.new
      end

      test "before_filter works" do
        result = @controller.process(:index)
        assert_equal "Hello world", @controller.response_body
      end
      
      test "after_filter works" do
        @controller.process(:index)
        assert_equal "Goodbye", @controller.instance_variable_get("@second")
      end
      
      test "around_filter works" do
        @controller.process(:index)
        assert_equal "FIRSTSECOND", @controller.instance_variable_get("@aroundz")
      end
    end
    
    class Callback3 < ControllerWithCallbacks
      before_filter do |c|
        c.instance_variable_set("@text", "Hello world")
      end
      <commit_msg>Ensure overwritten callbacks conditions in controllers work [#4761 state:resolved] [#3913 state:resolved]<commit_after>require 'abstract_unit'

module AbstractController
  module Testing
  
    class ControllerWithCallbacks < AbstractController::Base
      include AbstractController::Callbacks
    end
    
    class Callback1 < ControllerWithCallbacks
      set_callback :process_action, :before, :first
      
      def first
        @text = "Hello world"
      end
      
      def index
        self.response_body = @text
      end
    end
    
    class TestCallbacks1 < ActiveSupport::TestCase
      test "basic callbacks work" do
        controller = Callback1.new
        result = controller.process(:index)
        assert_equal "Hello world", controller.response_body
      end
    end

    class Callback2 < ControllerWithCallbacks
      before_filter :first
      after_filter :second
      around_filter :aroundz
      
      def first
        @text = "Hello world"
      end
      
      def second
        @second = "Goodbye"
      end
      
      def aroundz
        @aroundz = "FIRST"
        yield
        @aroundz << "SECOND"
      end
      
      def index
        self.response_body = @text.to_s
      end
    end

    class Callback2Overwrite < Callback2
      before_filter :first, :except => :index
    end
    
    class TestCallbacks2 < ActiveSupport::TestCase
      def setup
        @controller = Callback2.new
      end

      test "before_filter works" do
        result = @controller.process(:index)
        assert_equal "Hello world", @controller.response_body
      end
      
      test "after_filter works" do
        @controller.process(:index)
        assert_equal "Goodbye", @controller.instance_variable_get("@second")
      end
      
      test "around_filter works" do
        @controller.process(:index)
        assert_equal "FIRSTSECOND", @controller.instance_variable_get("@aroundz")
      end

      test "before_filter with overwritten condition" do
        @controller = Callback2Overwrite.new
        result = @controller.process(:index)
        assert_equal "", @controller.response_body
      end
    end
    
    class Callback3 < ControllerWithCallbacks
      before_filter do |c|
        c.instance_variable_set("@text", "Hello world")
      end
      
{'fraction_non_alphanumeric': 0.06824644549763033, 'fraction_numerical': 0.005924170616113744, 'mean_word_length': 2.1476510067114094, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5096184', 'n_tokens_mistral': 1148, 'n_tokens_neox': 1133, 'n_words': 293}