<commit_before># Test Rack middleware using integration tests because the Spec controller tests
# do not invoke Rack.
require 'spec_helper'
require 'ajax/rspec/helpers'
require 'uri'
require 'rack-ajax'

include Ajax::RSpec::Helpers

# Test the Rack::Ajax::Parser.  See <tt>lib/rack-ajax-parser.rb</tt>
#
# Test Rack middleware using integration tests because the Spec controller tests
# do not invoke Rack.
describe Rack::Ajax::Parser, :type => :integration do
  before :all do
    mock_ajax
    create_app
  end

  it "should recognize robots" do
    call_rack('/', 'GET', { 'HTTP_USER_AGENT' => 'Googlebot' }) do
      rack_response(user_is_robot?)
    end
    should_set_ajax_request_header('robot', true)
  end

  it "should recognize regular users" do
    call_rack('/', { 'HTTP_USER_AGENT' => 'Safari' }) do
      rack_response(user_is_robot?)
    end
    should_set_ajax_request_header('robot', false)
  end

  it "should be able to tell if a url is root" do
    call_rack('/') { rack_response(url_is_root?) }
    should_respond_with('true')

    call_rack('/Beyonce') { rack_response(url_is_root?) }
    should_respond_with('false')

    call_rack('/#/Beyonce?query2') { rack_response(url_is_root?) }
    should_respond_with('true')
  end

  it "should redirect to hashed url from fragment" do
    call_rack('/Beyonce?page=1#/Akon') do
      redirect_to_hashed_url_from_fragment
    end
    should_redirect_to('/#/Akon', 302)
  end

  it "should rewrite to traditional url from fragment" do
    call_rack('/Beyonce?page=1#/Akon?query2') do
      rewrite_to_traditional_url_from_fragment
    end
    should_rewrite_to('/Akon?query2')
  end

  it "should return a valid rack response" do
    call_rack('/') { rack_response('test') }
    should_respond_with('test')
  end

  describe "rewrite", :focus => true do
    before :each do
      @env = {}
    end

    it "should set the HTTP headers correctly" do
      Rack::Ajax::Parser.new(@env).send(:rewrite, 'http://example.com/users?one=two')
      @env['PATH_INFO'].should == '/users'
      @env['REQUEST_URI'].should == 'http://example.com/users?one=two'
      @env['QUERY_STRING'].should == 'one=two'
    end

    it "should ignore the fragment when setting PATH_INFO" do
      Rack::Ajax::Parser.new(@env).send(:rewrite, 'http://example.com/#/users?one=two')
      @env['PATH_INFO'].should == '/'<commit_msg>Remove :focus from spec<commit_after># Test Rack middleware using integration tests because the Spec controller tests
# do not invoke Rack.
require 'spec_helper'
require 'ajax/rspec/helpers'
require 'uri'
require 'rack-ajax'

include Ajax::RSpec::Helpers

# Test the Rack::Ajax::Parser.  See <tt>lib/rack-ajax-parser.rb</tt>
#
# Test Rack middleware using integration tests because the Spec controller tests
# do not invoke Rack.
describe Rack::Ajax::Parser, :type => :integration do
  before :all do
    mock_ajax
    create_app
  end

  it "should recognize robots" do
    call_rack('/', 'GET', { 'HTTP_USER_AGENT' => 'Googlebot' }) do
      rack_response(user_is_robot?)
    end
    should_set_ajax_request_header('robot', true)
  end

  it "should recognize regular users" do
    call_rack('/', { 'HTTP_USER_AGENT' => 'Safari' }) do
      rack_response(user_is_robot?)
    end
    should_set_ajax_request_header('robot', false)
  end

  it "should be able to tell if a url is root" do
    call_rack('/') { rack_response(url_is_root?) }
    should_respond_with('true')

    call_rack('/Beyonce') { rack_response(url_is_root?) }
    should_respond_with('false')

    call_rack('/#/Beyonce?query2') { rack_response(url_is_root?) }
    should_respond_with('true')
  end

  it "should redirect to hashed url from fragment" do
    call_rack('/Beyonce?page=1#/Akon') do
      redirect_to_hashed_url_from_fragment
    end
    should_redirect_to('/#/Akon', 302)
  end

  it "should rewrite to traditional url from fragment" do
    call_rack('/Beyonce?page=1#/Akon?query2') do
      rewrite_to_traditional_url_from_fragment
    end
    should_rewrite_to('/Akon?query2')
  end

  it "should return a valid rack response" do
    call_rack('/') { rack_response('test') }
    should_respond_with('test')
  end

  describe "rewrite" do
    before :each do
      @env = {}
    end

    it "should set the HTTP headers correctly" do
      Rack::Ajax::Parser.new(@env).send(:rewrite, 'http://example.com/users?one=two')
      @env['PATH_INFO'].should == '/users'
      @env['REQUEST_URI'].should == 'http://example.com/users?one=two'
      @env['QUERY_STRING'].should == 'one=two'
    end

    it "should ignore the fragment when setting PATH_INFO" do
      Rack::Ajax::Parser.new(@env).send(:rewrite, 'http://example.com/#/users?one=two')
      @env['PATH_INFO'].should == '/'
{'fraction_non_alphanumeric': 0.13165680473372782, 'fraction_numerical': 0.0033812341504649195, 'mean_word_length': 3.8844169246646025, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 14, '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': '2242539', 'n_tokens_mistral': 1633, 'n_tokens_neox': 1564, 'n_words': 383}