Sha256: c5c6cacb5e08d676047eaa11ccf42c4136290ab6e513dcde09ebdb0933879e1e

Contents?: true

Size: 999 Bytes

Versions: 6

Compression:

Stored size: 999 Bytes

Contents

require 'rubygems'
require 'active_record'
require 'jdbc_common'
require 'db/postgres'

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')
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
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
kb-activerecord-jdbc-adapter-0.9.7.1-java test/postgres_schema_search_path_test.rb
activerecord-jdbc-adapter-0.9.7-java test/postgres_schema_search_path_test.rb
activerecord-jdbc-adapter-0.9.6-java test/postgres_schema_search_path_test.rb
activerecord-jdbc-adapter-0.9.5-java test/postgres_schema_search_path_test.rb
activerecord-jdbc-adapter-0.9.4-java test/postgres_schema_search_path_test.rb
activerecord-jdbc-adapter-0.9.3-java test/postgres_schema_search_path_test.rb