shows some unexpected (to me) behavior of DataMapper
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 '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