Sha256: 31ae6f59ea25dbce9e10d7daeb7c7a13b34a20c16d6a8814b2a70a52fb902010

Contents?: true

Size: 1.01 KB

Versions: 2

Compression:

Stored size: 1.01 KB

Contents

# encoding: utf-8
require "cases/helper"

class PostgresqlLtreeTest < ActiveRecord::TestCase
  class Ltree < ActiveRecord::Base
    self.table_name = 'ltrees'
  end

  def setup
    @connection = ActiveRecord::Base.connection

    enable_extension!('ltree', @connection)

    @connection.transaction do
      @connection.create_table('ltrees') do |t|
        t.ltree 'path'
      end
    end
  rescue ActiveRecord::StatementInvalid
    skip "do not test on PG without ltree"
  end

  teardown do
    @connection.execute 'drop table if exists ltrees'
  end

  def test_column
    column = Ltree.columns_hash['path']
    assert_equal :ltree, column.type
    assert_equal "ltree", column.sql_type
    assert_not column.number?
    assert_not column.binary?
    assert_not column.array
  end

  def test_write
    ltree = Ltree.new(path: '1.2.3.4')
    assert ltree.save!
  end

  def test_select
    @connection.execute "insert into ltrees (path) VALUES ('1.2.3')"
    ltree = Ltree.first
    assert_equal '1.2.3', ltree.path
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
activejob-lock-0.0.2 rails/activerecord/test/cases/adapters/postgresql/ltree_test.rb
activejob-lock-0.0.1 rails/activerecord/test/cases/adapters/postgresql/ltree_test.rb