Created
February 3, 2012 00:10
-
-
Save tomykaira/1726651 to your computer and use it in GitHub Desktop.
Postgres + DataMapper fails to count :id
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source :rubygems | |
gem 'dm-core', '1.2.0' | |
gem 'dm-migrations', '1.2.0' | |
gem 'dm-timestamps', '1.2.0' | |
gem 'dm-validations', '1.2.0' | |
gem 'dm-types', '1.2.0' | |
gem 'dm-is-tree', '1.2.0' | |
gem 'dm-tags', '1.2.0' | |
gem 'dm-is-searchable', '1.2.0' | |
gem 'dm-postgres-adapter' | |
gem 'dm-mysql-adapter' | |
gem 'dm-sqlite-adapter' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'dm-core' | |
require 'dm-migrations' | |
require 'test/unit' | |
DataMapper.setup(:default, 'postgres://test:test@fileserver/test') | |
# DataMapper.setup(:default, 'mysql://test:test@fileserver/test') | |
# DataMapper.setup(:default, 'sqlite:test.db') | |
class Model | |
include DataMapper::Resource | |
property :id, Serial | |
property :name, String | |
end | |
class TC_Foo < Test::Unit::TestCase | |
def setup | |
Model.auto_migrate! | |
end | |
def test_with_same_id | |
rescued = false | |
Model.create!(:id => 1, :name => "first record") | |
Model.create!(:id => 1, :name => "second record") rescue rescued = true | |
assert_true(rescued) | |
end | |
def test_without_id | |
Model.create!(:name => "first record") | |
Model.create!(:name => "second record") | |
end | |
# I expect success, but fail with postgres | |
def test_with_id_then_without_id | |
Model.create!(:id => 1, :name => "first record") | |
Model.create!(:name => "second record") | |
end | |
def test_with_id_2_then_without_id | |
Model.create!(:id => 2, :name => "first record") | |
Model.create!(:name => "second record") | |
end | |
def test_with_different_ids | |
Model.create!(:id => 1, :name => "first record") | |
Model.create!(:id => 2, :name => "second record") | |
end | |
def test_without_id_then_with_same_id | |
rescued = false | |
Model.create!(:name => "first record") | |
Model.create!(:id => 1, :name => "second record") rescue rescued = true | |
assert_true(rescued) | |
end | |
def assert_true(actual) | |
assert_equal(true, actual) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment