Sha256: 491a90aec5cc8fbd1bc00788454bd3094e03fab2d00b2acdea578e9805465a77

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

require 'jdbc_common'

class CreateSchema < ActiveRecord::Migration
  def self.up
    execute "CREATE SCHEMA test"
    execute "CREATE TABLE test.people (id serial, name text)"
    execute "INSERT INTO test.people (name) VALUES ('Alex')"
    execute "CREATE TABLE public.people (id serial, wrongname text)"
  end

  def self.down
    execute "DROP SCHEMA test CASCADE"
    execute "DROP TABLE people"
  end
end

class Person < ActiveRecord::Base
  establish_connection POSTGRES_CONFIG.merge(:schema_search_path => 'test,public')
end

class PostgresSchemaSearchPathTest < Test::Unit::TestCase
  def setup
    CreateSchema.up
  end

  def teardown
    CreateSchema.down
  end

  def test_columns
    assert_equal(%w{id name}, Person.column_names)
  end

  def test_find_right
    assert_not_nil Person.find_by_name("Alex")
  end

  def test_find_wrong
    assert_raise NoMethodError do
      Person.find_by_wrongname("Alex")
    end
  end
  def test_column_information
    assert Person.columns.map{|col| col.name}.include?("name")
    assert !Person.columns.map{|col| col.name}.include?("wrongname")
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
activerecord-jdbc-adapter-1.2.5 test/postgres_schema_search_path_test.rb