<commit_before>require 'test_helper'

describe Hanami::Model::Adapters::RethinkdbAdapter do
  before do
    # rubocop:disable Documentation
    class TestUser
      include Hanami::Entity
      attributes :id, :name, :age
    end

    class TestUserRepository
      include Hanami::Repository
    end

    class TestDevice
      include Hanami::Entity
      attributes :id
    end

    class TestDeviceRepository
      include Hanami::Repository
    end
    # rubocop:enable Documentation

    @mapper = Hanami::Model::Mapper.new do
      collection :test_users do
        entity TestUser

        attribute :id,   String
        attribute :name, String
        attribute :age,  Integer
      end

      collection :test_devices do
        entity TestDevice

        attribute :id, String
      end
    end.load!

    @adapter = Hanami::Model::Adapters::RethinkdbAdapter.new(
      @mapper, RETHINKDB_TEST_URI
    )
  end

  after do
    Object.send(:remove_const, :TestUser)
    Object.send(:remove_const, :TestUserRepository)
    Object.send(:remove_const, :TestDevice)
    Object.send(:remove_const, :TestDeviceRepository)
  end

  let(:collection) { :test_users }

  describe 'multiple collections' do
    before do
      @adapter.clear(:test_users)
      @adapter.clear(:test_devices)
    end<commit_msg>RethinkdbAdapter: test: create new test adapter for datetime<commit_after>require 'test_helper'

describe Hanami::Model::Adapters::RethinkdbAdapter do
  before do
    # rubocop:disable Documentation
    class TestUser
      include Hanami::Entity
      attributes :id, :name, :age
    end

    class TestUserRepository
      include Hanami::Repository
    end

    class TestUserWithDateTime
      include Hanami::Entity
      attributes :id, :name, :age, :created_at
    end

    class TestUserWithDateTimeRepository
      include Hanami::Repository
    end

    class TestDevice
      include Hanami::Entity
      attributes :id
    end

    class TestDeviceRepository
      include Hanami::Repository
    end
    # rubocop:enable Documentation

    @mapper = Hanami::Model::Mapper.new do
      collection :test_users do
        entity TestUser

        attribute :id,   String
        attribute :name, String
        attribute :age,  Integer
      end

      collection :test_devices do
        entity TestDevice

        attribute :id, String
      end
    end.load!

    @adapter = Hanami::Model::Adapters::RethinkdbAdapter.new(@mapper,
                                                             RETHINKDB_TEST_URI)

    @mapper_datetime = Hanami::Model::Mapper.new do
      collection :test_users_datetime do
        entity TestUserWithDateTime

        attribute :id,   String
        attribute :name, String
        attribute :age,  Integer
        attribute :created_at, Hanami::Model::Adapters::Rethinkdb::Now
      end
    end.load!
    @adapter_datetime = Hanami::Model::Adapters::RethinkdbAdapter.new(@mapper_datetime,
                                                                      RETHINKDB_TEST_URI)
  end

  after do
    Object.send(:remove_const, :TestUser)
    Object.send(:remove_const, :TestUserRepository)
    Object.send(:remove_const, :TestUserWithDateTime)
    Object.send(:remove_const, :TestUserWithDateTimeRepository)
    Object.send(:remove_const, :TestDevice)
    Object.send(:remove_const, :TestDeviceRepository)
  end

  let(:collection) { :test_users }

  describe Hanami::Model::Adapters::Rethinkdb::Now do
    before do
      @adapter_date = Hanami::Model::Adapters::RethinkdbAdapter.new(@mapper_datetime,
                                                                    RETHINKDB_TEST_URI)
      @created_at = DateTime.now
      @user       = TestUserWithDateTime.new(created_at: @created_at)

      before_ids  = @adapter_date.all(:test_users_datetime).map(&:id).sort
      @user       = @adapter_date.create(:test_users_datetime, @user)
      @after_ids  = @adapter_date.all(:test_users_datetime).map(&:id).sort

      @rvalue     = Array.new(before_ids << @user.id).sort
    end

    after do
      @adapter_date.clear(:test_users_datetime)
    end

    it 'must do not break @adapter instance' do
      @after_ids.must_equal @rvalue
    end

    it 'store the created_at attribute' do
      user = @adapter_date.find(:test_users_datetime, @user.id)
      user.created_at.to_s.must_equal @created_at.to_s
    end
  end

  describe 'multiple collections' do
    before do
      @adapter.clear(:test_users)
      @adapter.clear(:test_devices)
    end
{'fraction_non_alphanumeric': 0.08253827379631684, 'fraction_numerical': 0.0, 'mean_word_length': 2.615076182838813, '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': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2131630', 'n_tokens_mistral': 1309, 'n_tokens_neox': 1266, 'n_words': 285}