<commit_before>require 'spec_helper'

describe User do

  context "find_for_github_oauth" do

    before(:each) do
      @auth = {
        "provider" => "github",
        "uid" => "1213232",
        "info" => {
          "nickname" => "user-mcuser",
          "email" => "<EMAIL>"
        },
        "credentials" => {
          "token" => "21312313233"
        }
      }
    end

    it "creates a user from Github oauth" do
      user = User.find_for_github_oauth(@auth)

      expect(user.name).to eq("user-mcuser")
      expect(user.email).to eq("<EMAIL>")
      expect(user.token).to eq("21312313233")
      expect(user.api_key).to match /[a-z0-9]{20}/
    end

    it "finds a user from Github oauth" do
      user = create(:user, provider: "github", uid: "1213232")

      found_user = User.find_for_github_oauth(@auth)

      expect(found_user).to eq(user)
    end

    it "lists a user's organizations" do
      user = User.find_for_github_oauth(@auth)

      expect(user.octokit_client).to receive(:org_memberships) {
        [
          {
            name: "org1",
            role: "admin"
          },
          {
            name: "org2",
            role: "member"
          },
        ]
      }.once

      orgs = user.organizations
      user.organizations

      expect(orgs.count).to eq(1)
      expect(orgs.first[:name]).to eq("org1")
    end

    it "gets a user's github user details" do
      user = User.find_for_github_oauth(@auth)

      expect(user.octokit_client).to receive(:user).with('user-mcuser') {
        {}
      }.once

      user.github_user
      user.github_user
    end

  end

end<commit_msg>Fix tests<commit_after>require 'spec_helper'

describe User do

  context "find_for_github_oauth" do

    before(:each) do
      @auth = {
        "provider" => "github",
        "uid" => "1213232",
        "info" => {
          "nickname" => "user-mcuser",
          "email" => "<EMAIL>"
        },
        "credentials" => {
          "token" => "<PASSWORD>"
        }
      }
    end

    it "creates a user from Github oauth" do
      user = User.find_for_github_oauth(@auth)

      expect(user.name).to eq("user-mcuser")
      expect(user.email).to eq("<EMAIL>")
      expect(user.token).to eq("<PASSWORD>")
      expect(user.api_key).to match /[a-z0-9]{20}/
    end

    it "finds a user from Github oauth" do
      user = create(:user, provider: "github", uid: "1213232")

      found_user = User.find_for_github_oauth(@auth)

      expect(found_user).to eq(user)
    end

    it "lists a user's organizations" do
      user = User.find_for_github_oauth(@auth)

      expect(user.octokit_client).to receive(:org_memberships) {
        [
          {
            name: "org1",
            role: "admin"
          },
          {
            name: "org2",
            role: "member"
          },
        ]
      }.once

      orgs = user.organizations
      user.organizations

      expect(orgs.count).to eq(1)
      expect(orgs.first[:name]).to eq("org1")
    end

    it "gets a user's github user details" do
      user = User.find_for_github_oauth(@auth)

      expect(Rails.configuration.octopub_admin).to receive(:user).with('user-mcuser') {
        {}
      }.once

      user.github_user
      user.github_user
    end

  end

end
{'fraction_non_alphanumeric': 0.13644688644688643, 'fraction_numerical': 0.020146520146520148, 'mean_word_length': 1.9495949594959496, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 23, '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': '85526', 'n_tokens_mistral': 1151, 'n_tokens_neox': 1077, 'n_words': 216}