Permalink
Browse files

re-arrange postgres tests - mainly trying to track out artificial fai…

…lure on 3.1

but gave up for now - renamed failing test to execute before the ones affecting it ... it's worth nothing that the failure only happened on AR-3.1
  • Loading branch information...
1 parent c41ebd8 commit 8c783d610c4b660c0821361a5ea355c425ee0cf5 @kares kares committed Apr 4, 2013
@@ -22,15 +22,15 @@ def self.included(base)
end
def setup
- @prevapp = Rake.application
+ @prev_app = Rake.application
Rake.application = Rake::Application.new
verbose(true)
do_setup
end
def do_setup(env = 'unittest', db = 'test_rake_db_create')
@env = env
- @prevconfigs = ActiveRecord::Base.configurations
+ @prev_configs = ActiveRecord::Base.configurations
ActiveRecord::Base.connection.disconnect!
@db_name = db
setup_rails
@@ -48,9 +48,9 @@ def do_setup(env = 'unittest', db = 'test_rake_db_create')
def teardown
Rake::Task["db:drop"].invoke
- Rake.application = @prevapp
+ Rake.application = @prev_app
restore_rails
- ActiveRecord::Base.configurations = @prevconfigs
+ ActiveRecord::Base.configurations = @prev_configs
ActiveRecord::Base.establish_connection(db_config)
@rails_env_set = nil
@full_env_loaded = nil
@@ -135,4 +135,5 @@ def silence_warnings
ensure
$VERBOSE = prev
end
+
end
@@ -0,0 +1,50 @@
+require 'test_helper'
+require 'db/postgres'
+
+# NOTE: named to execute before:
+# - PostgresConnectionTest
+# - PostgresDbCreateTest
+# - PostgresDbDropTest
+# since on 3.1 otherwise starts weirdly failing (when full suite is run) :
+#
+# ActiveRecord::JDBCError: org.postgresql.util.PSQLException: ERROR:
+# null value in column "uhash" violates not-null constraint
+# Detail: Failing row contains (null, http://url.to).:
+# INSERT INTO "some_urls" ("url") VALUES ('http://url.to') RETURNING "uhash"
+#
+class PostgresACustomPrimaryKeyTest < Test::Unit::TestCase
+
+ class CreateUrls < ActiveRecord::Migration
+ def self.up
+ create_table 'some_urls', :id => false do |t|
+ t.string :uhash, :null => false
+ t.text :url, :null => false
+ end
+ execute "ALTER TABLE some_urls ADD PRIMARY KEY (uhash)"
+ end
+ def self.down
+ drop_table 'some_urls'
+ end
+ end
+
+ def setup
+ CreateUrls.up
+ end
+
+ def teardown
+ CreateUrls.down
+ end
+
+ class SomeUrl < ActiveRecord::Base
+ self.primary_key = :uhash
+ end
+
+ def test_create_url
+ url = SomeUrl.create! do |instance|
+ instance.uhash = 'uhash'
+ instance.url = 'http://url.to'
+ end
+ assert_equal 'uhash', url.reload.uhash
+ end
+
+end
@@ -4,15 +4,15 @@ class PostgresConnectionTest < Test::Unit::TestCase
def test_set_session_variable_true
run_without_connection do |orig_connection|
- ActiveRecord::Base.establish_connection(orig_connection.deep_merge({:variables => {:debug_print_plan => true}}))
+ ActiveRecord::Base.establish_connection(orig_connection.merge({:variables => {:debug_print_plan => true}}))
set_true_rows = select_rows "SHOW DEBUG_PRINT_PLAN"
assert_equal set_true_rows, [["on"]]
end
end
def test_set_session_variable_false
run_without_connection do |orig_connection|
- ActiveRecord::Base.establish_connection(orig_connection.deep_merge({:variables => {:debug_print_plan => false}}))
+ ActiveRecord::Base.establish_connection(orig_connection.merge({:variables => {:debug_print_plan => false}}))
set_false_rows = select_rows "SHOW DEBUG_PRINT_PLAN"
assert_equal set_false_rows, [["off"]]
end
@@ -21,14 +21,16 @@ def test_set_session_variable_false
def test_set_session_variable_nil
run_without_connection do |orig_connection|
# This should be a no-op that does not raise an error
- ActiveRecord::Base.establish_connection(orig_connection.deep_merge({:variables => {:debug_print_plan => nil}}))
+ ActiveRecord::Base.establish_connection(orig_connection.merge({:variables => {:debug_print_plan => nil}}))
+ select_rows "SHOW DEBUG_PRINT_PLAN"
end
end
def test_set_session_variable_default
run_without_connection do |orig_connection|
# This should execute a query that does not raise an error
- ActiveRecord::Base.establish_connection(orig_connection.deep_merge({:variables => {:debug_print_plan => :default}}))
+ ActiveRecord::Base.establish_connection(orig_connection.merge({:variables => {:debug_print_plan => :default}}))
+ select_rows "SHOW DEBUG_PRINT_PLAN"
end
end
@@ -46,7 +48,7 @@ def run_without_connection
begin
yield original_connection
ensure
- ActiveRecord::Base.establish_connection(original_connection)
+ ActiveRecord::Base.establish_connection POSTGRES_CONFIG
end
end
@@ -1,5 +1,5 @@
-require 'abstract_db_create'
require 'db/postgres'
+require 'abstract_db_create'
class PostgresDbCreateTest < Test::Unit::TestCase
include AbstractDbCreate
@@ -1,3 +1,4 @@
+require 'db/postgres'
require 'abstract_db_create'
class PostgresDbDropTest < Test::Unit::TestCase
@@ -12,4 +13,5 @@ def test_dropping_nonexistent_database_does_not_raise_exception
Rake::Task["db:drop"].invoke
end
end
+
end
@@ -1,19 +1,20 @@
-require 'jdbc_common'
+require 'db/postgres'
-class CreateISLSchema < ActiveRecord::Migration
- def self.up
- execute "CREATE TABLE domains (id int, name varchar(16))"
- end
+class PostgresInformationSchemaLeakTest < Test::Unit::TestCase
+
+ class CreateISLSchema < ActiveRecord::Migration
+ def self.up
+ execute "CREATE TABLE domains (id int, name varchar(16))"
+ end
- def self.down
- execute "DROP TABLE domains"
+ def self.down
+ execute "DROP TABLE domains"
+ end
end
-end
-
-class Domain < ActiveRecord::Base
-end
-class PostgresInformationSchemaLeakTest < Test::Unit::TestCase
+ class Domain < ActiveRecord::Base
+ end
+
def setup
CreateISLSchema.up
end
@@ -22,7 +23,8 @@ def teardown
CreateISLSchema.down
end
- def test_columns
+ def test_domain_columns
assert_equal(%w{id name}, Domain.column_names)
end
-end
+
+end
@@ -2,7 +2,7 @@
require 'test_helper'
require 'db/postgres'
-class PostgresqlJSONTest < Test::Unit::TestCase
+class PostgresqlJSONTypeTest < Test::Unit::TestCase
class JsonDataType < ActiveRecord::Base
self.table_name = 'json_data_type'
@@ -1,4 +1,3 @@
-require 'jdbc_common'
require 'db/postgres'
class PostgresNativeTypesTest < Test::Unit::TestCase
@@ -1,40 +0,0 @@
-require 'test_helper'
-require 'db/postgres'
-
-class PostgresNonSeqPKeyTest < Test::Unit::TestCase
-
- class CreateUrls < ActiveRecord::Migration
- def self.up
- create_table 'urls', :id => false do |t|
- t.text :uhash, :null => false
- t.text :url, :null => false
- end
- execute "ALTER TABLE urls ADD PRIMARY KEY (uhash)"
- end
- def self.down
- drop_table 'urls'
- end
- end
-
- class Url < ActiveRecord::Base
- self.primary_key = :uhash
- # shouldn't be needed: set_sequence_name nil
- end
-
- def setup
- CreateUrls.up
- end
-
- def teardown
- CreateUrls.down
- end
-
- def test_create_url
- url = Url.create! do |url|
- url.uhash = 'uhash'
- url.url = 'http://url.to'
- end
- assert_equal 'uhash', url.uhash
- end
-
-end
@@ -85,4 +85,4 @@ def dump_with_data_types(io = StringIO.new)
io.string
end
-end
+end
@@ -110,5 +110,4 @@ def test_column_information
end
-end
-
+end
@@ -2,6 +2,7 @@
require 'db/postgres'
class PostgresTableAliasLengthTest < Test::Unit::TestCase
+
def test_table_alias_length
result = ActiveRecord::Base.connection.select_one("SELECT 1 AS " + "a" * 2048)
@@ -11,5 +12,5 @@ def test_table_alias_length
assert_equal(actual_table_alias_length,
ActiveRecord::Base.connection.table_alias_length)
end
+
end
-
View
@@ -11,5 +11,5 @@ def self.down
end
class AutoId < ActiveRecord::Base
- def self.table_name () "auto_ids" end
+ def self.table_name() "auto_ids" end
end

0 comments on commit 8c783d6

Please sign in to comment.