Skip to content

Instantly share code, notes, and snippets.

@nambrot
Created October 12, 2012 16:31
Show Gist options
  • Save nambrot/3880117 to your computer and use it in GitHub Desktop.
Save nambrot/3880117 to your computer and use it in GitHub Desktop.
it "should have unique connections respective to their context", :debug => true do
TpSubidentity.create!({
:uid => 'test10',
:context_name => 'batchspectpsicontext',
:name => 'ttest',
:image => 'http://graph.facebook.com/523538207/picture',
:url => 'http://graph.facebook.com/523538207/picture',
:objecttype => 'something',
:credentials => {},
:attributes => {}
})
TpSubidentity.create!({
:uid => 'test20',
:context_name => 'batchspectpsicontext',
:name => 'ttest',
:image => 'http://graph.facebook.com/523538207/picture',
:url => 'http://graph.facebook.com/523538207/picture',
:objecttype => 'something',
:credentials => {},
:attributes => {}
})
from = [TpSubidentity.find_by_uid_and_context_name('test10','batchspectpsicontext')]*2
to = [TpSubidentity.find_by_uid_and_context_name('test20','batchspectpsicontext')]*2
provider = Provider.find_by_name 'webcred'
context1 = ConnectionContext.create!({
:name => 'batchspecconnectioncontext1',
:async => true,
:cardinality => '1',
:connection_type => "user-user",
:provider => provider,
:attributes => {}
})
context2 = ConnectionContext.create!({
:name => 'batchspecconnectioncontext2',
:async => true,
:cardinality => '1',
:connection_type => "user-user",
:provider => provider,
:attributes => {}
})
contexts = [context1, context2]
attributes = [{}]*2
connections = Connection.batch_connect!(from, to, contexts, attributes)
# Ensure we have done right
connections.should_not be_nil
# Query the relationships to ensure that they work
relations = NeoModel.neo.get_node_relationships(from.first.neo_id)
relations = relations.delete_if{|item| item['data']['context_name'] != context1.name and item['data']['context_name'] != context2.name }
(relations.size == 2).should be_true
# should be connected in both contexts
Connection.directed_connections(from.first, to.first, context1).size.should == 1
Connection.directed_connections(from.first, to.first, context2).size.should == 1
Connection.connect!(from.first, to.first, context1, {})
Connection.directed_connections(from.first, to.first, context1).size.should == 1
Connection.directed_connections(from.first, to.first, context2).size.should == 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment