<commit_before>require 'spec_helper'
require 'rack'

describe Parametrizer::Middleware do
  let(:app) { ->(env) { [200, env, "app"] } }
  let(:middleware) { Parametrizer::Middleware.new(app) }

  before do
    Parametrizer.configure do |config|
      config.base_host = 'test.com'
    end
  end

  it 'puts language in params' do
    _, env = middleware.call env_for('http://texaco.test.com', 'HTTP_ACCEPT_LANGUAGE' => 'en-US;q=0.6')
    expect(env['action_dispatch.request.request_parameters']['language']).to eq 'en'
  end

  it 'puts subdomain in params' do
    _, env = middleware.call env_for('http://texaco.test.com')
    expect(env['action_dispatch.request.request_parameters']['oem']).to eq 'texaco'
  end

  def env_for(url, opts = {})
    Rack::MockRequest.env_for(url, opts)
  end
end<commit_msg>EBELP-74 add tests for middleware and country<commit_after>require 'spec_helper'
require 'rack'

describe Parametrizer::Middleware do
  let(:app) { ->(env) { [200, env, "app"] } }
  let(:middleware) { Parametrizer::Middleware.new(app) }

  before do
    Parametrizer.configure do |config|
      config.base_host = 'test.com'
    end
  end

  it 'puts language in params' do
    _, env = middleware.call env_for('http://texaco.test.com', 'HTTP_ACCEPT_LANGUAGE' => 'en-US;q=0.6')
    expect(env['action_dispatch.request.request_parameters']['language']).to eq 'en'
  end

  it 'puts oem in params' do
    _, env = middleware.call env_for('http://texaco.test.com')
    expect(env['action_dispatch.request.request_parameters']['oem']).to eq 'texaco'
  end

  it 'puts country in params' do
    _, env = middleware.call env_for('http://texaco.test.com', 'HTTP_ACCEPT_LANGUAGE' => 'en-US;q=0.6')
    expect(env['action_dispatch.request.request_parameters']['country']).to eq 'US'
  end

  def env_for(url, opts = {})
    Rack::MockRequest.env_for(url, opts)
  end
end
{'fraction_non_alphanumeric': 0.15578158458244112, 'fraction_numerical': 0.007494646680942184, 'mean_word_length': 4.235294117647059, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '4722524', 'n_tokens_mistral': 680, 'n_tokens_neox': 671, 'n_words': 136}