Skip to content

Commit

Permalink
Associations on view WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
yrashk committed Apr 29, 2008
1 parent 5d48e1a commit 40cd239
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
18 changes: 9 additions & 9 deletions lib/strokedb/document/associations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ def view.map(uuid, doc)
reference_slotname = self[:reference_slotname]
through = self[:through]
expected_meta = self[:expected_meta]

begin
through.each {|t| doc = doc.send(t) }
rescue SlotNotFoundError
doc = nil
end

if doc.meta.name == expected_meta &&
reference_slotname_value = doc[reference_slotname]

if doc.meta.name == expected_meta
begin
through.each {|t| doc = doc.send(t) }
rescue SlotNotFoundError
return nil unless doc
end
if reference_slotname_value = doc[reference_slotname]
[
[
reference_slotname_value,
Expand All @@ -24,6 +23,7 @@ def view.map(uuid, doc)
]
end
end
end
end

module HasManyAssociation
Expand Down
6 changes: 5 additions & 1 deletion spec/lib/strokedb/document/associations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,11 @@
playlist = Playlist.create!
rock_song = Song.create!(:playlist => playlist, :genre => 'Rock')
pop_song = Song.create!(:playlist => playlist, :genre => 'Pop')
pending("filtering is not ready") do
playlist.songs.find(:genre => 'Rock').should == [rock_song]
playlist.songs.find(:genre => 'Pop').should == [pop_song]
end
end

it "should be able to instantiate new document with #new" do
playlist = Playlist.create!
Expand Down Expand Up @@ -195,7 +197,9 @@
playlist = Playlist.create!
rock_song = Song.create!(:playlist => playlist, :genre => 'Rock')
pop_song = Song.create!(:playlist => playlist, :genre => 'Pop')
playlist.rock_songs.should == [rock_song]
pending("filtering is not done yet") do
playlist.rock_songs.should == [rock_song]
end
end

end
Expand Down

0 comments on commit 40cd239

Please sign in to comment.