<commit_before>require 'spec_helper'

describe Travis::Api::App::Endpoint::Authorization::UserManager do
  let(:manager) { described_class.new(data, 'abc123') }

  describe '#info' do
    let(:data) {
      {
        name: '<NAME>', login: 'drogus', gravatar_id: '123', id: 456, foo: 'bar'
      }.stringify_keys
    }

    it 'gets data from github payload' do
      manager.info.should == {
        name: '<NAME>', login: 'drogus', gravatar_id: '123', github_id: 456
      }.stringify_keys
    end

    it 'allows to overwrite existing keys' do
      manager.info({login: 'piotr.sarnacki', bar: 'baz'}.stringify_keys).should == {
        name: '<NAME>', login: 'piotr.sarnacki', gravatar_id: '123',
        github_id: 456, bar: 'baz'
      }.stringify_keys
    end
  end

  describe '#fetch' do
   let(:data) {
      { login: 'drogus', id: 456 }.stringify_keys
    }

    context 'with existing user' do
      it 'updates user data' do
        user = stub('user', login: 'drogus', github_id: 456)
        User.expects(:find_by_github_id).with(456).returns(user)
        attributes = { login: 'drogus', github_id: 456, github_oauth_token: '<PASSWORD>' }.stringify_keys
        user.expects(:update_attributes).with(attributes)

        manager.fetch.should == user
      end
    end<commit_msg>Add missing spec for UserManager (when drop_token is true)<commit_after>require 'spec_helper'

describe Travis::Api::App::Endpoint::Authorization::UserManager do
  let(:manager) { described_class.new(data, 'abc123') }

  describe '#info' do
    let(:data) {
      {
        name: '<NAME>', login: 'drogus', gravatar_id: '123', id: 456, foo: 'bar'
      }.stringify_keys
    }

    it 'gets data from github payload' do
      manager.info.should == {
        name: '<NAME>', login: 'drogus', gravatar_id: '123', github_id: 456
      }.stringify_keys
    end

    it 'allows to overwrite existing keys' do
      manager.info({login: 'piotr.sarnacki', bar: 'baz'}.stringify_keys).should == {
        name: '<NAME>', login: 'piotr.sarnacki', gravatar_id: '123',
        github_id: 456, bar: 'baz'
      }.stringify_keys
    end
  end

  describe '#fetch' do
   let(:data) {
      { login: 'drogus', id: 456 }.stringify_keys
    }

    it 'drops the token when drop_token is set to true' do
      manager = described_class.new(data, 'abc123', true)

      user = stub('user', login: 'drogus', github_id: 456)
      User.expects(:find_by_github_id).with(456).returns(user)

      attributes = { login: 'drogus', github_id: 456 }.stringify_keys

      user.expects(:update_attributes).with(attributes)

      manager.fetch.should == user
    end

    context 'with existing user' do
      it 'updates user data' do
        user = stub('user', login: 'drogus', github_id: 456)
        User.expects(:find_by_github_id).with(456).returns(user)
        attributes = { login: 'drogus', github_id: 456, github_oauth_token: '<PASSWORD>' }.stringify_keys
        user.expects(:update_attributes).with(attributes)

        manager.fetch.should == user
      end
    end
{'fraction_non_alphanumeric': 0.1414041994750656, 'fraction_numerical': 0.025590551181102362, 'mean_word_length': 3.1091644204851754, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '6609596', 'n_tokens_mistral': 1096, 'n_tokens_neox': 975, 'n_words': 247}