<commit_before>require_relative '../../spec_helper'
require_relative '../../../app/models/carto/user_creation'

describe Carto::UserCreation do

  describe 'autologin?' do

    it 'is false for states other than success' do
      FactoryGirl.build(:autologin_user_creation, state: 'creating_user').autologin?.should == false
      FactoryGirl.build(:autologin_user_creation, state: 'validating_user').autologin?.should == false
      FactoryGirl.build(:autologin_user_creation, state: 'saving_user').autologin?.should == false
      FactoryGirl.build(:autologin_user_creation, state: 'promoting_user').autologin?.should == false
      FactoryGirl.build(:autologin_user_creation, state: 'creating_user_in_central').autologin?.should == false
      FactoryGirl.build(:autologin_user_creation, state: 'load_common_data').autologin?.should == false
      FactoryGirl.build(:autologin_user_creation, state: 'failure').autologin?.should == false

      FactoryGirl.build(:autologin_user_creation, state: 'success').autologin?.should == true
    end

  end

  describe 'validation token' do
    include_context 'organization with users helper'

    it 'assigns an enable_account_token if user has not signed up with Google' do
      User.any_instance.stubs(:create_in_central).returns(true)
      User.any_instance.stubs(:enable_remote_db_user).returns(true)
      user_data = FactoryGirl.build(:valid_user)
      user_data.organization = @organization
      user_data.google_sign_in = false

      user_creation = Carto::UserCreation.new_user_signup(user_data)
      user_creation.next_creation_step until user_creation.finished?

      saved_user = Carto::User.order("created_at desc").limit(1).first
      saved_user.enable_account_token.should_not be_nil<commit_msg>Time constraint autologin test<commit_after>require_relative '../../spec_helper'
require_relative '../../../app/models/carto/user_creation'

describe Carto::UserCreation do

  describe 'autologin?' do

    it 'is true for autologin_user_creation factory' do
      FactoryGirl.build(:autologin_user_creation).autologin?.should == true
    end

    it 'is false for states other than success' do
      FactoryGirl.build(:autologin_user_creation, state: 'creating_user').autologin?.should == false
      FactoryGirl.build(:autologin_user_creation, state: 'validating_user').autologin?.should == false
      FactoryGirl.build(:autologin_user_creation, state: 'saving_user').autologin?.should == false
      FactoryGirl.build(:autologin_user_creation, state: 'promoting_user').autologin?.should == false
      FactoryGirl.build(:autologin_user_creation, state: 'creating_user_in_central').autologin?.should == false
      FactoryGirl.build(:autologin_user_creation, state: 'load_common_data').autologin?.should == false
      FactoryGirl.build(:autologin_user_creation, state: 'failure').autologin?.should == false

      FactoryGirl.build(:autologin_user_creation, state: 'success').autologin?.should == true
    end

    it 'is stops working after one minute' do
      FactoryGirl.build(:autologin_user_creation, created_at: Time.now - 61.seconds).autologin?.should == false
      FactoryGirl.build(:autologin_user_creation, created_at: Time.now - 60.seconds).autologin?.should == false
      FactoryGirl.build(:autologin_user_creation, created_at: Time.now - 59.seconds).autologin?.should == true
    end

  end

  describe 'validation token' do
    include_context 'organization with users helper'

    it 'assigns an enable_account_token if user has not signed up with Google' do
      User.any_instance.stubs(:create_in_central).returns(true)
      User.any_instance.stubs(:enable_remote_db_user).returns(true)
      user_data = FactoryGirl.build(:valid_user)
      user_data.organization = @organization
      user_data.google_sign_in = false

      user_creation = Carto::UserCreation.new_user_signup(user_data)
      user_creation.next_creation_step until user_creation.finished?

      saved_user = Carto::User.order("created_at desc").limit(1).first
      saved_user.enable_account_token.should_not be_nil
{'fraction_non_alphanumeric': 0.10726558664702994, 'fraction_numerical': 0.0019636720667648502, 'mean_word_length': 4.804843304843305, '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': '3091911', 'n_tokens_mistral': 1282, 'n_tokens_neox': 1194, 'n_words': 222}