<commit_before>require_relative './init'
require 'timecop'

RSpec.configure do |config|
  config.include FactoryGirl::Syntax::Methods
end
describe "Helper" do
  before do
    IntegrationSpecHelper.InitializeMongo()
  end
  before(:each) do
    User.destroy_all
    Device.destroy_all
    Request.destroy_all
  end

  def create_device_for_user user
    device = Device.new
    device.device_token = "device_token_#{(Time.now.to_f*100000).to_s}"
    user.devices.push(device)
    device.save!
  end

  describe "available" do
    it "can get available helpers with lanugage" do
      Timecop.freeze(Time.gm(2014,"jul",9,11,30) ) do
        request = build(:request)

        helper = request.helper
        helper.languages = ['ab', 'en']
        helper.first_name = "non-english"
        helper.save!

        blind =request.blind
        blind.languages = ['en', 'da']
        blind.save!

        create_device_for_user helper

        expect(helper.available(request).count).to eq(1)
      end
    end

    it "finds no available helpers when noone speaks blind persons languages" do
      request = build(:request)

      helper = request.helper
      helper.languages = ['ab', 'aa']
      helper.first_name = "non-english"
      helper.save!
<commit_msg>remember to log user in<commit_after>require_relative './init'
require 'timecop'

RSpec.configure do |config|
  config.include FactoryGirl::Syntax::Methods
end
describe "Helper" do
  before do
    IntegrationSpecHelper.InitializeMongo()
  end
  before(:each) do
    User.destroy_all
    Device.destroy_all
    Request.destroy_all
  end

  describe "available" do
    it "can get available helpers with language" do
      Timecop.freeze(Time.gm(2014,"jul",9,11,30) ) do
        request = build(:request)

        helper = request.helper
        helper.languages = ['ab', 'en']
        helper.first_name = "non-english"
        helper.create_or_renew_token
        helper.save!

        blind =request.blind
        blind.languages = ['en', 'da']
        blind.save!

        expect(helper.available(request).count).to eq(1)
      end
    end

    it "finds no available helpers when noone speaks blind persons languages" do
      request = build(:request)

      helper = request.helper
      helper.languages = ['ab', 'aa']
      helper.first_name = "non-english"
      helper.save!

{'fraction_non_alphanumeric': 0.10503842869342442, 'fraction_numerical': 0.011101622544833475, 'mean_word_length': 2.7974068071312805, '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': '2182335', 'n_tokens_mistral': 749, 'n_tokens_neox': 711, 'n_words': 173}