Skip to content

Commit

Permalink
Added test for one to one relation graph
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Naiman committed Dec 27, 2017
1 parent a10bace commit 1e3705a
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions spec/collection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,11 @@
it 'Graph' do
1.upto(3) do |i|
db[:users].insert name: "User #{i}"
db[:people].insert document_number: "document_#{i}",
first_name: "John #{i}",
last_name: "Doe #{i}",
birth_date: Time.now - i,
user_id: i
db[:categories].insert name: "Category #{i}"
db[:posts].insert user_id: i, title: "Post #{i}", body: '...'
db[:categories_posts].insert post_id: i, category_id: i
Expand All @@ -379,11 +384,12 @@
end
end

posts_graph = posts.where(id: 1).graph(:user, :categories, 'comments.user.posts.categories').all
posts_graph = posts.where(id: 1).graph('user.person', :categories, 'comments.user.posts.categories').all

posts_graph.count.must_equal 1

posts_graph[0].user.must_equal users.find(1)
posts_graph[0].user.id.must_equal 1
posts_graph[0].user.person.must_equal people.detect(user_id: 1)

posts_graph[0].categories.must_equal [categories.find(1)]

Expand Down

0 comments on commit 1e3705a

Please sign in to comment.