Skip to content

Commit

Permalink
Added spec testing nested objects in collections.
Browse files Browse the repository at this point in the history
  • Loading branch information
zk committed Jun 8, 2012
1 parent 029ee18 commit 1d29a0b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
11 changes: 10 additions & 1 deletion spec/models/post.rb
@@ -1,10 +1,19 @@
class PostMetadata
attr_accessor :posted_at

def initialize(posted_at=Time.new(0))
@posted_at = posted_at
end
end



class Post class Post
attr_accessor :title, :body, :comments attr_accessor :title, :body, :comments, :meta


def initialize(title = nil, body = nil) def initialize(title = nil, body = nil)
@title, @body = title, body @title, @body = title, body
@comments = [] @comments = []
@meta = PostMetadata.new
end end


end end
20 changes: 20 additions & 0 deletions spec/unit/node_spec.rb
Expand Up @@ -488,6 +488,26 @@ def wrap(&block)
} }
end end


it "renders objects nested in collections properly" do
posts = [Post.new("foo")]

nodes = node_wrap do
collection :data => posts do
attributes :title

object :meta => current_object.meta do
attributes :posted_at
end
end
end

nodes.result.should == {
:data => [
{:title => 'foo', :meta => {:posted_at => Time.new(0)}}
]
}
end

it "renders nested collections with dynamic property values correctly" do it "renders nested collections with dynamic property values correctly" do
post1 = Post.new("post 1") post1 = Post.new("post 1")
post2 = Post.new("post 2") post2 = Post.new("post 2")
Expand Down

0 comments on commit 1d29a0b

Please sign in to comment.