Skip to content

Instantly share code, notes, and snippets.

@mmmurf
Created November 13, 2010 02:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmmurf/3569c20a3bf30f269699 to your computer and use it in GitHub Desktop.
Save mmmurf/3569c20a3bf30f269699 to your computer and use it in GitHub Desktop.
shows some unexpected (to me) behavior of DataMapper
require 'dm-core'
require 'dm-migrations'
require 'dm-aggregates'
require 'test/unit'
class Animal
include DataMapper::Resource
property :id, Serial
def self.small
all(:id.lte => 2)
end
end
DataMapper::Logger.new("/tmp/dmtestlog", :debug)
DataMapper.setup(:default, 'sqlite:///tmp/testdb')
DataMapper.auto_migrate!!
DataMapper.finalize
5.times do
Animal.create
end
class CountTest < Test::Unit::TestCase
def test_total_count
assert_equal 5, Animal.count
end
def test_slice_count
a = Animal.all(:id.lte => 5)
b = Animal.all(:id.lte => 4)
assert_equal 1, (a-b).count, "The difference leaves one item"
assert_equal 1, (a-b).small.count, "Adding a the small filter should not make the count larger"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment