<commit_before>require "spec_helper"

require 'arrthorizer/rails'

describe Arrthorizer::Rails do
  describe "controller integration" do
    let(:controller_class) { Class.new(ApplicationController) do def index; end end}

    describe "each controller class" do
      it "responds to :prepare_context" do
        controller_class.should respond_to :to_prepare_context
      end

      it "responds to :arrthorizer_configuration" do
        controller_class.should respond_to :arrthorizer_configuration
      end
    end

    describe "each controller" do
      let(:controller) { controller_class.new }

      it "responds to :arrthorizer_context" do
        controller.should respond_to :arrthorizer_context
      end

      context "when it has a proper configuration for context building" do
        let(:injected_params) { { some_param: 1 } }
        let(:current_action) { 'some_action' }

        before :each do
          controller.stub(:params).and_return injected_params

          controller.stub(:action_name).and_return(current_action)
        end

        context "and there is no specific configuration for the current action" do
          before :each do
            controller_class.to_prepare_context do |c|
              c.defaults do
                params # this is an example config which can be easily tested
              end
            end
          end

          it "uses the 'default' config to build an Arrthorizer context" do
            controller.send(:arrthorizer_context).should == Arrthorizer::Context(injected_params)
          end
        end

        context "and there is a specific configuration for the current action" do
          let(:action_specific_config) { { some_extra_key: 'some_value' }}

          before :each do
            controller_class.to_prepare_context do |c|
              c.defaults do
                params
              end

              c.for_action(current_action) do
                arrthorizer_defaults.merge(some_extra_key: 'some_value')
              end
            end
          end

          it "uses the more specific configuration for the current action" do
            context_hash = injected_params.merge(action_specific_config)
            expected_context = Arrthorizer::Context(context_hash)

            controller.send(:arrthorizer_context).should == expected_context
          end
        end
      end
    end
  end
end
<commit_msg>Fix a test in Ruby 2+<commit_after>require "spec_helper"

require 'arrthorizer/rails'

describe Arrthorizer::Rails do
  describe "controller integration" do
    let(:controller_class) { Class.new(ApplicationController) do def index; end end}

    describe "each controller class" do
      it "responds to :prepare_context" do
        controller_class.should respond_to :to_prepare_context
      end

      it "responds to :arrthorizer_configuration" do
        controller_class.should respond_to :arrthorizer_configuration
      end
    end

    describe "each controller" do
      let(:controller) { controller_class.new }

      it "has a protected method called :arrthorizer_context" do
        # this method is protected to prevent exposing it
        # via default or wildcard routes
        controller.protected_methods.should include :arrthorizer_context
      end

      context "when it has a proper configuration for context building" do
        let(:injected_params) { { some_param: 1 } }
        let(:current_action) { 'some_action' }

        before :each do
          controller.stub(:params).and_return injected_params

          controller.stub(:action_name).and_return(current_action)
        end

        context "and there is no specific configuration for the current action" do
          before :each do
            controller_class.to_prepare_context do |c|
              c.defaults do
                params # this is an example config which can be easily tested
              end
            end
          end

          it "uses the 'default' config to build an Arrthorizer context" do
            controller.send(:arrthorizer_context).should == Arrthorizer::Context(injected_params)
          end
        end

        context "and there is a specific configuration for the current action" do
          let(:action_specific_config) { { some_extra_key: 'some_value' }}

          before :each do
            controller_class.to_prepare_context do |c|
              c.defaults do
                params
              end

              c.for_action(current_action) do
                arrthorizer_defaults.merge(some_extra_key: 'some_value')
              end
            end
          end

          it "uses the more specific configuration for the current action" do
            context_hash = injected_params.merge(action_specific_config)
            expected_context = Arrthorizer::Context(context_hash)

            controller.send(:arrthorizer_context).should == expected_context
          end
        end
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.05820955439582497, 'fraction_numerical': 0.0006021678040947411, 'mean_word_length': 2.2675409836065574, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5929780', 'n_tokens_mistral': 1303, 'n_tokens_neox': 1244, 'n_words': 389}