Permalink
Browse files

Adding in spec file for has n :through

  • Loading branch information...
1 parent 103c0ed commit 75a856b967176caaf8a476f8af4d76b8ebbb1296 @whoahbot whoahbot committed Mar 30, 2011
Showing with 54 additions and 0 deletions.
  1. +54 −0 spec/dm_redis_associations_spec.rb
@@ -0,0 +1,54 @@
+require File.expand_path("../spec_helper", __FILE__)
+require 'dm-core'
+require 'dm-redis-adapter/spec/setup'
+
+describe DataMapper::Adapters::RedisAdapter do
+ before(:all) do
+ @adapter = DataMapper.setup(:default, {
+ :adapter => "redis",
+ :db => 15
+ })
+ end
+
+ it "should allow has n :through" do
+ class Book
+ include DataMapper::Resource
+
+ property :id, Serial
+ property :name, String
+
+ has n, :book_tags
+ has n, :tags, :through => :book_tags
+ end
+
+ class Tag
+ include DataMapper::Resource
+
+ property :id, Serial
+ property :name, String
+
+ has n, :book_tags
+ has n, :books, :through => :book_tags
+ end
+
+ class BookTag
+ include DataMapper::Resource
+
+ property :id, Serial
+ # property :book_id, Integer, :index => true
+ # property :tag_id, Integer, :index => true
+
+ belongs_to :book
+ belongs_to :tag
+ end
+
+ b = Book.create(:name => "Harry Potter")
+ t = Tag.create(:name => "fiction")
+
+ b.tags << t
+ b.save
+
+ b2 = Book.get(1)
+ b2.tags.should == [t]
+ end
+end

0 comments on commit 75a856b

Please sign in to comment.