class PostgresqlLtreeTest

Public Instance Methods

setup() click to toggle source
# File activerecord/test/cases/adapters/postgresql/ltree_test.rb, line 12
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
test_column() click to toggle source
# File activerecord/test/cases/adapters/postgresql/ltree_test.rb, line 30
def test_column
  column = Ltree.columns_hash["path"]
  assert_equal :ltree, column.type
  assert_equal "ltree", column.sql_type
  assert_not column.array?

  type = Ltree.type_for_attribute("path")
  assert_not type.binary?
end
test_schema_dump_with_shorthand() click to toggle source
# File activerecord/test/cases/adapters/postgresql/ltree_test.rb, line 51
def test_schema_dump_with_shorthand
  output = dump_table_schema("ltrees")
  assert_match %r[t\.ltree "path"], output
end
test_select() click to toggle source
# File activerecord/test/cases/adapters/postgresql/ltree_test.rb, line 45
def test_select
  @connection.execute "insert into ltrees (path) VALUES ('1.2.3')"
  ltree = Ltree.first
  assert_equal "1.2.3", ltree.path
end
test_write() click to toggle source
# File activerecord/test/cases/adapters/postgresql/ltree_test.rb, line 40
def test_write
  ltree = Ltree.new(path: "1.2.3.4")
  assert ltree.save!
end