Sha256: 956f9fed066abc5891d123dc75cf5a18fae0b71d74cdb55daf80e69f1fab3d1c

Contents?: true

Size: 1.89 KB

Versions: 3

Compression:

Stored size: 1.89 KB

Contents

RSpec.shared_context :sequel do
  def mysql_uri database=nil
    database ||= mysql_database1
    if defined?(JRUBY_VERSION)
      uri = "jdbc:mysql://#{mysql_host}:#{mysql_port}/#{database}?user=#{mysql_username}&useSSL=false"
      uri += "&password=#{mysql_password}" if mysql_password
      uri
    else
      "mysql2://#{mysql_username}:#{mysql_password}@#{mysql_host}:#{mysql_port}/#{database}"
    end
  end

  def sqlite_uri file_name
    "#{defined?(JRUBY_VERSION) && 'jdbc:'}sqlite://" + File.join(tempdir, file_name)
  end

  def postgres_options database=nil
    database ||= postgres_database1
    if defined?(JRUBY_VERSION)
      uri = "jdbc:postgresql://localhost/#{database}?user=#{postgres_username}"
      uri += "&password=#{postgres_password}" if postgres_password
      {db: uri}
    else
      {
        db: "postgres://localhost/#{database}",
        user: postgres_username,
        password: postgres_password
      }
    end
  end

  def postgres_hstore_options database=nil
    postgres_options(database).merge \
      table: 'hstore_table1',
      hstore: 'row'
  end

  def h2_uri
    "jdbc:h2:" + tempdir
  end
end

RSpec.shared_examples :adapter_sequel do |specs, optimize: true|
  shared_examples :each_key_server do
    context "with each_key server" do
      let(:opts) do
        base_opts.merge(
          servers: {each_key: {}},
          each_key_server: :each_key
        )
      end

      moneta_specs specs
    end

    context "without each_key server" do
      let(:opts) { base_opts }
      moneta_specs specs
    end
  end

  if optimize
    context 'with backend optimizations' do
      let(:base_opts) { {table: "adapter_sequel"} }

      include_examples :each_key_server
    end
  end

  context 'without backend optimizations' do
    let(:base_opts) do
      {
        table: "adapter_sequel",
        optimize: false
      }
    end

    include_examples :each_key_server
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
moneta-1.5.1 spec/moneta/adapters/sequel/helper.rb
moneta-1.5.0 spec/moneta/adapters/sequel/helper.rb
moneta-1.4.2 spec/moneta/adapters/sequel/helper.rb