<commit_before>require 'spec_helper'

describe ROM::Repository do
  before do
    class TestRepository < ROM::Repository
      def self.schemes
        [:test_scheme]
      end
    end
  end

  describe '.setup' do
    it 'sets up connection based on a uri' do
      repository = ROM::Repository.setup("test_scheme::memory")

      expect(repository).to be_instance_of(TestRepository)
    end

    it 'raises an exception if the scheme is not supported' do
      expect {
        ROM::Repository.setup("bogus://any-host")
      }.to raise_error(ArgumentError, '"bogus://any-host" uri is not supported')
    end
  end

  describe '.[]' do
    it "looks up and return the repository class for the given schema" do
      expect(ROM::Repository[:test_scheme]).to eq TestRepository
    end
  end

  describe 'Registration order' do
    it "prefers the last-defined repository" do
      class OrderTestFirst < TestRepository
        def self.schemes
          [:order_test]
        end
      end

      repository = ROM::Repository.setup("order_test::memory")
      expect(repository).to be_instance_of(OrderTestFirst)

      OrderTestSecond = Class.new(OrderTestFirst)

      repository = ROM::Repository.setup("order_test::memory")

      expect(repository).to be_instance_of(OrderTestSecond)
    end
  end

  describe '#disconnect' do
    it 'does nothing' do
      repository_class = Class.new(ROM::Repository) {
        def self.schemes
          [:bazinga]
        end
      }

      repository = repository_class.new('bazinga://localhost')<commit_msg>Ensure ROM::Repository.[] works w/o registered repos<commit_after>require 'spec_helper'

describe ROM::Repository do
  let(:test_repository) do
    Class.new(ROM::Repository) do
      def self.schemes
        [:test_scheme]
      end
    end
  end

  describe '.setup' do
    before { test_repository }

    it 'sets up connection based on a uri' do
      repository = ROM::Repository.setup("test_scheme::memory")

      expect(repository).to be_instance_of(test_repository)
    end

    it 'raises an exception if the scheme is not supported' do
      expect {
        ROM::Repository.setup("bogus://any-host")
      }.to raise_error(ArgumentError, '"bogus://any-host" uri is not supported')
    end
  end

  describe '.[]' do
    it "looks up and return the repository class for the given schema" do
      test_repository

      expect(ROM::Repository[:test_scheme]).to eq test_repository
    end

    it "returns nil w/o registered repositories" do
      expect(ROM::Repository[:test_scheme]).to eq nil
    end
  end

  describe 'Registration order' do
    it "prefers the last-defined repository" do
      order_test_first = Class.new(test_repository) do
        def self.schemes
          [:order_test]
        end
      end

      repository = ROM::Repository.setup("order_test::memory")
      expect(repository).to be_instance_of(order_test_first)

      order_test_second = Class.new(order_test_first)

      repository = ROM::Repository.setup("order_test::memory")

      expect(repository).to be_instance_of(order_test_second)
    end
  end

  describe '#disconnect' do
    it 'does nothing' do
      repository_class = Class.new(ROM::Repository) {
        def self.schemes
          [:bazinga]
        end
      }

      repository = repository_class.new('bazinga://localhost')
{'fraction_non_alphanumeric': 0.09550898203592814, 'fraction_numerical': 0.0, 'mean_word_length': 2.9076023391812864, 'pattern_counts': {'":': 0, '<': 5, '<?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': '5194897', 'n_tokens_mistral': 994, 'n_tokens_neox': 940, 'n_words': 257}