Skip to content

Commit

Permalink
more test code + make sure Model.primary_key is set as a string (due …
Browse files Browse the repository at this point in the history
…3.1)
  • Loading branch information
kares committed Oct 11, 2013
1 parent 4f4d152 commit 672d606
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions test/db/postgresql/a_custom_primary_key_test.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
require 'test_helper'
require 'db/postgres'

# NOTE: named to execute before:
# 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:
#
# ActiveRecord::JDBCError: org.postgresql.util.PSQLException: ERROR:
# null value in column "uhash" violates not-null constraint
# Detail: Failing row contains (null, http://url.to).:
# 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|
Expand All @@ -26,7 +26,7 @@ def self.down
drop_table 'some_urls'
end
end

def setup
CreateUrls.up
end
Expand All @@ -36,15 +36,21 @@ def teardown
end

class SomeUrl < ActiveRecord::Base
self.primary_key = :uhash
self.primary_key = 'uhash' # :uhash won't work correctly on 3.1
end

def test_create_url
url = SomeUrl.new
url.uhash = 'uhash1'
url.url = 'http://url.to'
url.save!
assert_equal 'uhash1', url.reload.uhash

url = SomeUrl.create! do |instance|
instance.uhash = 'uhash'
instance.uhash = 'uhash2'
instance.url = 'http://url.to'
end
assert_equal 'uhash', url.reload.uhash
assert_equal 'uhash2', url.reload.uhash
end

end

0 comments on commit 672d606

Please sign in to comment.