Skip to content
This repository has been archived by the owner on Sep 2, 2019. It is now read-only.

Commit

Permalink
Adding in spec file for has n :through
Browse files Browse the repository at this point in the history
  • Loading branch information
whoahbot committed Mar 30, 2011
1 parent 103c0ed commit 75a856b
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions spec/dm_redis_associations_spec.rb
Original file line number Diff line number Diff line change
@@ -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.