Permalink
Browse files

Added spec testing nested objects in collections.

  • Loading branch information...
1 parent 029ee18 commit 1d29a0b86c23ed765c9bae6acd6b9bb27acc2aac @zk zk committed Jun 8, 2012
Showing with 30 additions and 1 deletion.
  1. +10 −1 spec/models/post.rb
  2. +20 −0 spec/unit/node_spec.rb
View
@@ -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
- attr_accessor :title, :body, :comments
+ attr_accessor :title, :body, :comments, :meta
def initialize(title = nil, body = nil)
@title, @body = title, body
@comments = []
+ @meta = PostMetadata.new
end
end
View
@@ -488,6 +488,26 @@ def wrap(&block)
}
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
post1 = Post.new("post 1")
post2 = Post.new("post 2")

0 comments on commit 1d29a0b

Please sign in to comment.