spec/hari/node_spec.rb in hari-0.0.3 vs spec/hari/node_spec.rb in hari-0.0.4

- old
+ new

@@ -63,17 +63,62 @@ end it 'paginates queries' do following = joao.out(:follow).from(15.minutes.ago.to_f).to_a following.map(&:id).sort.should eq [teresa, raimundo].map(&:id).sort + + following = joao.out(:follow).from(15.minutes.ago.to_f, 'down').to_a + following.map(&:id).sort.should eq [maria, joaquim, lili].map(&:id).sort + + following = joao.out(:follow).limit(1).from(15.minutes.ago.to_f, 'down').to_a + following.map(&:id).sort.should eq [maria.id] end it 'paginates chained queries' do Hari.relation! :follow, teresa, joao following = teresa.out(:follow).out(:follow).from(15.minutes.ago.to_f) following.to_a.map(&:id).sort.should eq [teresa, raimundo].map(&:id).sort following.nodes!.map(&:id).sort.should eq [teresa, raimundo].map(&:id).sort + + 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] + end + end + + describe 'queries by type' do + before do + Hari.relation! :follow, 'user#1', 'celeb#x' + Hari.relation! :follow, 'user#2', 'user#1' + end + + it 'can intersect type queries' do + friends = Hari('user#2').out(:follow).type(:user) + fans = Hari('celeb#x').in(:follow).type(:user) + + fans.intersect_count(friends).should eq(1) + friends.intersect_count(fans).should eq(1) + + fans.intersect(friends).should eq %w(1) + + Hari.relation! :follow, 'user#3', 'celeb#x' + Hari.relation! :follow, 'user#4', 'celeb#x' + Hari.relation! :follow, 'user#5', 'celeb#x' + Hari.relation! :follow, 'user#6', 'celeb#x' + Hari.relation! :follow, 'user#7', 'celeb#x' + Hari.relation! :follow, 'user#8', 'celeb#x' + + Hari.relation! :follow, 'user#2', 'user#4' + Hari.relation! :follow, 'user#2', 'user#5' + Hari.relation! :follow, 'user#2', 'user#6' + Hari.relation! :follow, 'user#2', 'user#7' + + 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 end end