Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmmurf/1059814 to your computer and use it in GitHub Desktop.
Save mmmurf/1059814 to your computer and use it in GitHub Desktop.
require 'dm-core'
require 'dm-migrations'
class Foo
include DataMapper::Resource
property :id, Serial
has n, :bars
end
class Bar
include DataMapper::Resource
property :id, Serial
belongs_to :foo
belongs_to :baz
end
class Baz
include DataMapper::Resource
property :id, Serial
has n, :bars
end
url = "sqlite3::memory:"
DataMapper.setup(:default, url)
DataMapper.finalize
DataMapper.auto_migrate!
require 'minitest/spec'
require 'minitest/autorun'
describe Foo do
foo = Foo.create()
baz = Baz.create()
bar = Bar.create(:baz => baz , :foo => foo)
describe "chained associations" do
it "should return all results when chaining with all" do
foo.bars.baz.count.must_equal 1
end
it "should return no results when chaining with an empty set" do
foo.bars(:id => []).baz.count.must_equal 0
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment