spec/hari/node_spec.rb in hari-0.0.4 vs spec/hari/node_spec.rb in hari-0.0.5
- old
+ new
@@ -43,10 +43,14 @@
end
it 'can chain queries' do
followers_following = joao.out(:follow).out(:follow).to_a
followers_following.map(&:id).sort.should eq [raimundo, maria, joaquim].map(&:id).sort
+
+ joao.out(:follow).out(:follow).count.should eq(4)
+
+ joao.out(:follow).out(:follow).first.name.should eq('Joaquim')
end
end
describe 'queries with pagination' do
before do
@@ -83,10 +87,16 @@
following = teresa.out(:follow).out(:follow).from(15.minutes.ago.to_f, 'down')
following.to_a.map(&:id).sort.should eq [maria, joaquim, lili].map(&:id).sort
following = teresa.out(:follow).out(:follow).limit(1).from(15.minutes.ago.to_f, 'down')
following.to_a.map(&:id).sort.should eq [maria.id]
+
+ following = teresa.out(:follow).out(:follow).limit(2)
+ following.to_a.map(&:id).sort.should eq [teresa.id, raimundo.id]
+
+ following = teresa.out(:follow).out(:follow).limit(3)
+ following.to_a.map(&:id).sort.should eq [teresa.id, raimundo.id, maria.id]
end
end
describe 'queries by type' do
before do
@@ -117,8 +127,82 @@
fans.intersect(friends, 1, 3).should eq %w(6 5 4)
fans.sort_by(friends).take(5).should eq %w(7 6 5 4 1)
end
+
+ it 'has count' do
+ 14.times { Hari.relation! :follow, 'user#2', "user##{SecureRandom.hex(2)}" }
+ 3.times { Hari.relation! :follow, 'user#2', "celeb##{SecureRandom.hex(2)}"}
+
+ Hari('user#2').out(:follow).type(:user).count.should eq(15)
+ Hari('user#1').in(:follow).type(:user).count.should eq(1)
+ end
+
+ it 'can list nodes ids' do
+ Hari.relation! :follow, 'user#1', 'celeb#y'
+ Hari.relation! :follow, 'user#1', 'celeb#z'
+ Hari.relation! :follow, 'user#1', 'celeb#w'
+
+ Hari(user: 1).out(:follow) << 'celeb#k'
+ Hari(user: 1).out(:follow) << %w(celeb#a celeb#b)
+
+ user_celebs = Hari('user#1').out(:follow).type(:celeb)
+
+ celebs = user_celebs.nodes_ids
+ celebs.should eq %w(celeb#b celeb#a celeb#k celeb#w celeb#z celeb#y celeb#x)
+ end
+
+ it 'can list relations ids' do
+ Hari.relation! :follow, 'user#1', 'celeb#y'
+ Hari.relation! :follow, 'user#1', 'celeb#z'
+ Hari.relation! :follow, 'user#1', 'celeb#w'
+
+ relations = Hari('user#1').out(:follow).type(:celeb).relations_ids
+ relations.should eq %w(user#1:follow:celeb#w
+ user#1:follow:celeb#z
+ user#1:follow:celeb#y
+ user#1:follow:celeb#x)
+ end
+
+ it 'can list nodes' do
+ followings = [teresa, raimundo, maria, joaquim, lili]
+ x = 5
+
+ followings.each do |following|
+ Delorean.time_travel_to x.minutes.ago do
+ Hari.relation! :follow, joao, following
+ end
+
+ x += 5
+ end
+
+ people = joao.out(:follow).type(:test_node).nodes
+ people[0].name.should eq('Teresa')
+ people[1].name.should eq('Raimundo')
+ people[2].name.should eq('Maria')
+ people[3].name.should eq('Joaquim')
+ people[4].name.should eq('Lili')
+ end
+
+ it 'paginates' do
+ 30.times do |i|
+ Hari.relation! :follow, 'user#42', "celeb##{i + 1}"
+ end
+
+ query = Hari('user#42').out(:follow).type(:celeb).limit(13, 16)
+ query.ids.should eq %w(17 16 15 14)
+ end
+
+ it 'creates new relations by type' do
+ followers = Hari(user: 2).out(:follow)
+ followers.type(:user) << '13'
+ followers.nodes_ids!.include?('user#13').should be_true
+
+ followers.type(:user) << ['15', '16']
+ followers.nodes_ids!.include?('user#15').should be_true
+ followers.nodes_ids!.include?('user#16').should be_true
+ end
+
end
end