Skip to content

Commit

Permalink
Formulated acceptance spec for embeds
Browse files Browse the repository at this point in the history
  • Loading branch information
moonglum committed Oct 23, 2013
1 parent 7e230b7 commit 60ed49e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/guacamole/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ def all
Query.new(connection.query, mapper)
end

def map(&block)
mapper.instance_eval(&block)
end

def add_timestamps_to_model(model)
timestamp = Time.now
model.created_at = timestamp
Expand Down
21 changes: 21 additions & 0 deletions spec/acceptance/basic_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,27 @@
require 'guacamole'
require 'acceptance/spec_helper'

class Comment
include Guacamole::Model

attribute :text, String
end

class Article
include Guacamole::Model

attribute :title, String
attribute :comments, Array[Comment]

validates :title, presence: true
end

class ArticlesCollection
include Guacamole::Collection

map do
embeds :comments
end
end

describe 'ModelBasics' do
Expand Down Expand Up @@ -88,6 +99,16 @@ class ArticlesCollection

expect(result.title).to eq 'Disturbed'
end

it 'should allow to nest models' do
pending 'To be implemented'

article_with_comments = Fabricate(:article_with_two_comments)
found_article = subject.by_key(article_with_comments.key)

expect(found_article.comments.first).to be_a Comment
expect(found_article.comments).to eq article_with_comments.comments
end
end

end
5 changes: 5 additions & 0 deletions spec/fabricators/article_fabricator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@
Fabricator(:article) do
title 'And then there was silence'
end

Fabricator(:article_with_two_comments, from: Article) do
title 'I have two comments'
comments(count: 2) { |attrs, i| Fabricate.build(:comment, text: "I'm comment number #{i}") }
end
5 changes: 5 additions & 0 deletions spec/fabricators/comment_fabricator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- encoding: utf-8 -*-

Fabricator(:comment) do
text 'This article is super awesome'
end

0 comments on commit 60ed49e

Please sign in to comment.