Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

#clone_into and #copy_into were reversing edge directions.

Don't know how I never figured this out before! Probably explains lots of past confusion though.
  • Loading branch information...
commit f9b3c7357bfd38acc5ea2531c03354fa43ac38d0 1 parent ee18c1e
@pangloss authored
View
16 lib/pacer/wrappers/edge_wrapper.rb
@@ -131,17 +131,11 @@ def delete!
# @raise [StandardError] If this the associated vertices don't exist and :create_vertices is not set
def clone_into(target_graph, opts = {})
e_idx = target_graph.temp_index("tmp-e-#{graph.graph_id}", :edge, :create => true)
- e = target_graph.edge(element_id)
- unless e
- e = e_idx.first('id', element_id)
- if e
- e = EdgeWrapper.new(graph, e)
- end
- end
+ e = e_idx.first('id', element_id)
unless e
v_idx = target_graph.temp_index("tmp-v-#{graph.graph_id}", :vertex, :create => true)
- iv = target_graph.vertex(in_vertex.element_id) || v_idx.first('id', in_vertex.element_id)
- ov = target_graph.vertex(out_vertex.element_id) || v_idx.first('id', out_vertex.element_id)
+ iv = v_idx.first('id', in_vertex.element_id)
+ ov = v_idx.first('id', out_vertex.element_id)
if opts[:create_vertices]
iv ||= in_vertex.clone_into target_graph
ov ||= out_vertex.clone_into target_graph
@@ -152,7 +146,7 @@ def clone_into(target_graph, opts = {})
raise message unless opts[:ignore_missing_vertices]
return nil
end
- e = target_graph.create_edge(element_id, iv, ov, label, properties)
+ e = target_graph.create_edge(element_id, ov, iv, label, properties)
e_idx.put('id', element_id, e)
yield e if block_given?
end
@@ -173,7 +167,7 @@ def copy_into(target_graph)
ov = v_idx.first('id', out_vertex.element_id) || target_graph.vertex(out_vertex.element_id)
raise 'vertices not found' if not iv or not ov
- e = target_graph.create_edge nil, iv, ov, label, properties
+ e = target_graph.create_edge nil, ov, iv, label, properties
yield e if block_given?
e
end
View
2  lib/pacer/wrappers/vertex_wrapper.rb
@@ -132,7 +132,7 @@ def delete!
# @return [Pacer::Wrappers::VertexWrapper] the new vertex
def clone_into(target_graph, opts = nil)
v_idx = target_graph.temp_index("tmp-v-#{graph.graph_id}", :vertex, :create => true)
- v = target_graph.vertex(element_id) || v_idx.first('id', element_id)
+ v = v_idx.first('id', element_id)
unless v
v = target_graph.create_vertex element_id, properties
v_idx.put('id', element_id, v.element)
View
86 spec/pacer/wrapper/edge_wrapper_spec.rb
@@ -1,9 +1,8 @@
require 'spec_helper'
Run.all :read_only do
- use_pacer_graphml_data :read_only
-
describe Pacer::Wrappers::EdgeWrapper do
+ use_pacer_graphml_data :read_only
let(:e_exts) { [Tackle::SimpleMixin, TP::Wrote] }
let(:e_wrapper_class) { Pacer::Wrappers::EdgeWrapper.wrapper_for e_exts }
@@ -32,9 +31,8 @@
end
end
end
-end
-shared_examples_for Pacer::Wrappers::EdgeWrapper do
+describe Pacer::Wrappers::EdgeWrapper do
use_simple_graph_data
describe '#e' do
@@ -66,6 +64,30 @@
end
end
+ subject { e0 }
+ its(:graph) { should equal(graph) }
+ its(:display_name) { should == "#{ v0.element_id }-links-#{ v1.element_id }" }
+ its(:inspect) { should == "#<E[#{ e0.element_id }]:#{ v0.element_id }-links-#{ v1.element_id }>" }
+ context 'with label proc' do
+ before do
+ graph.edge_name = proc { |e| "some name" }
+ end
+ its(:display_name) { should == "some name" }
+ its(:inspect) { should == "#<E[#{ e0.element_id }]:some name>" }
+ end
+
+ context '', :transactions => true do
+ it { should_not == e1 }
+ it { should == e0 }
+ it { should_not == v0 }
+ end
+end
+end
+
+Run.all :read_write do
+ use_simple_graph_data
+
+describe Pacer::Wrappers::EdgeWrapper do
describe '#delete!' do
before do
@edge_id = e0.element_id
@@ -83,25 +105,32 @@
let(:dest) { Pacer.tg }
},
'into graph2' => proc {
- let(:dest) { graph2 }
+ let(:dest) {
+ c = example.metadata[:graph2_commit]
+ c.call() if c
+ graph2.v.delete!
+ c.call() if c
+ graph2
+ }
}) do
- describe '#clone_into', :transactions => false do
- before { pending 'support temporary hash indices for clone/copy' unless graph.features.supportsIndices }
+ describe '#clone_into' do
context 'including vertices' do
subject { e0.clone_into(dest, :create_vertices => true) }
its('element_id.to_s') { should == e0.element_id.to_s unless graph.features.ignoresSuppliedIds }
its(:label) { should == 'links' }
its(:graph) { should equal(dest) }
- its('in_vertex.properties') { should == { 'name' => 'eliza' } }
- its('out_vertex.properties') { should == { 'name' => 'darrick' } }
+ its('in_vertex.properties') { should == e0.in_vertex.properties }
+ its('out_vertex.properties') { should == e0.out_vertex.properties }
end
context 'without vertices' do
- subject { e0.clone_into(dest) rescue nil }
- it { should be_nil }
+ context 'not existing' do
+ subject { e0.clone_into(dest) rescue nil }
+ it { should be_nil }
+ end
- context 'but already existing' do
+ context 'existing' do
before do
v0.clone_into(dest)
v1.clone_into(dest)
@@ -110,42 +139,19 @@
its('element_id.to_s') { should == e0.element_id.to_s unless graph.features.ignoresSuppliedIds }
its(:label) { should == 'links' }
its(:graph) { should equal(dest) }
- its('in_vertex.properties') { should == { 'name' => 'eliza' } }
- its('out_vertex.properties') { should == { 'name' => 'darrick' } }
+ its('in_vertex.properties') { should == e0.in_vertex.properties }
+ its('out_vertex.properties') { should == e0.out_vertex.properties }
end
end
end
- describe '#copy_into', :transactions => false do
- before { pending unless graph.features.supportsIndices }
+ describe '#copy_into' do
subject { v0.clone_into(dest); v1.clone_into(dest); e0.copy_into(dest) }
its(:label) { should == 'links' }
its(:graph) { should equal(dest) }
- its('in_vertex.properties') { should == { 'name' => 'eliza' } }
- its('out_vertex.properties') { should == { 'name' => 'darrick' } }
- end
-
- end
-
- subject { e0 }
- its(:graph) { should equal(graph) }
- its(:display_name) { should == "#{ v0.element_id }-links-#{ v1.element_id }" }
- its(:inspect) { should == "#<E[#{ e0.element_id }]:#{ v0.element_id }-links-#{ v1.element_id }>" }
- context 'with label proc' do
- before do
- graph.edge_name = proc { |e| "some name" }
+ its('in_vertex.properties') { should == e0.in_vertex.properties }
+ its('out_vertex.properties') { should == e0.out_vertex.properties }
end
- its(:display_name) { should == "some name" }
- its(:inspect) { should == "#<E[#{ e0.element_id }]:some name>" }
- end
-
- context '', :transactions => true do
- it { should_not == e1 }
- it { should == e0 }
- it { should_not == v0 }
end
end
-
-Run.all do
- it_uses Pacer::Wrappers::EdgeWrapper
end
Please sign in to comment.
Something went wrong with that request. Please try again.