<commit_before>require File.dirname(__FILE__) + '/spec_helper'

module AccessControllerCreator
  def create_controller(&block)
    Class.new(ApplicationController).tap do |controller|
      controller.class_eval do
        %w(first second third).each do |word|
          class_eval <<-src_code, __FILE__, __LINE__
            def #{word}
              render :text => '#{word.capitalize}!'
            end
            def #{word}?
              action_name == '#{word}'
            end
            def not_#{word}?
              action_name != '#{word}'
            end
          src_code
        end
      end
      controller.class_eval(&block) if block
    end
  end
end

describe Access, :type => :controller do
  extend AccessControllerCreator
  def self.test_access(description, actions, *blocks)
    describe '' do
      controller = blocks.inject(nil) do |parent, block|
        if parent
          Class.new(parent).tap do |sub_controller|
            sub_controller.class_eval(&block) if block
          end
        else
          create_controller(&block)
        end
      end
      tests controller
      it "should get" do
        actions = Array(actions)
        %w(first second third).each do |action|
          get action
          if actions == [:all] || actions.include?(action.to_sym)
            response.should have_text("#{action.camelize}!")
            response.should_not redirect_to('/')
          else
            response.should_not have_text("#{action.camelize}!")
            response.should redirect_to('/')
          end
        end
      end
    end
  end
<commit_msg>refactored specs<commit_after>require File.dirname(__FILE__) + '/spec_helper'

module AccessControllerCreator
  def create_controller(&block)
    Class.new(ApplicationController).tap do |controller|
      controller.class_eval do
        %w(first second third).each do |word|
          class_eval <<-src_code, __FILE__, __LINE__
            def #{word}
              render :text => '#{word.capitalize}!'
            end
            def #{word}?
              action_name == '#{word}'
            end
            def not_#{word}?
              action_name != '#{word}'
            end
          src_code
        end
      end
      controller.class_eval(&block) if block
    end
  end

  def test_controller(description, *blocks, &test_block)
    describe '' do
      controller = blocks.inject(nil) do |parent, block|
        if parent
          Class.new(parent).tap do |sub_controller|
            sub_controller.class_eval(&block) if block
          end
        else
          create_controller(&block)
        end
      end
      tests controller
      it description do
        self.instance_eval(&test_block)
      end
    end
  end
end

describe Access, :type => :controller do
  extend AccessControllerCreator
  def self.test_access(description, actions, *blocks)
    test_controller description, *blocks do
      actions = Array(actions)
      %w(first second third).each do |action|
        get action
        if actions == [:all] || actions.include?(action.to_sym)
          response.should have_text("#{action.camelize}!")
          response.should_not redirect_to('/')
        else
          response.should_not have_text("#{action.camelize}!")
          response.should redirect_to('/')
        end
      end
    end
  end

{'fraction_non_alphanumeric': 0.09760479041916167, 'fraction_numerical': 0.0, 'mean_word_length': 2.00990990990991, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '6395272', 'n_tokens_mistral': 918, 'n_tokens_neox': 907, 'n_words': 231}