Skip to content

Commit

Permalink
all specs passing, running full tx support spec each time
Browse files Browse the repository at this point in the history
  • Loading branch information
subvertallchris committed Sep 25, 2014
1 parent 43d2976 commit 12614be
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .rspec
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
--color
--tty
--tty
5 changes: 4 additions & 1 deletion lib/neo4j/migration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,17 @@ def add_ids_to(model)

def id_batch_set(label, property, new_ids, to_set)
Benchmark.realtime do
Neo4j::Transaction.run do
begin
tx = Neo4j::Transaction.new
Neo4j::Session.query("MATCH (n:`#{label}`) WHERE NOT has(n.#{property})
with COLLECT(n) as nodes, #{new_ids} as ids
FOREACH(i in range(0,#{to_set - 1})|
FOREACH(node in [nodes[i]]|
SET node.#{property} = ids[i]))
RETURN distinct(true)
LIMIT #{to_set}")
ensure
tx.close
end
end
end
Expand Down
33 changes: 20 additions & 13 deletions spec/e2e/transaction_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
end

#:nocov:
it 'returns hash values inside but outside it has the node value after commit' do
it 'returns a wrapped node inside and outside of transaction' do
i = 0
SecureRandom.stub(:uuid) do
i += 1
Expand All @@ -20,23 +20,30 @@

if Neo4j::Session.current.db_type == :server_db
clazz
tx = Neo4j::Transaction.new
a = clazz.create name: 'a'
b = clazz.create name: 'b'
a.thing = b
expect(a.thing).to eq("name"=>"b", "_classname"=>clazz.to_s, "uuid" => "secure1234_2")
tx.close
begin
tx = Neo4j::Transaction.new
a = clazz.create name: 'a'
b = clazz.create name: 'b'
a.thing = b
# expect(a.thing).to eq("name"=>"b", "_classname"=>clazz.to_s, "uuid" => "secure1234_2")
expect(a.thing).to eq b
ensure
tx.close
end
expect(a.thing).to eq(b)
end

if Neo4j::Session.current.db_type == :embedded_db
clazz
tx = Neo4j::Transaction.new
a = clazz.create name: 'a'
b = clazz.create name: 'b'
a.thing = b
expect(a.thing).to eq(b)
tx.close
begin
tx = Neo4j::Transaction.new
a = clazz.create name: 'a'
b = clazz.create name: 'b'
a.thing = b
expect(a.thing).to eq(b)
ensure
tx.close
end
expect(a.thing).to eq(b)
end

Expand Down
4 changes: 2 additions & 2 deletions spec/unit/wrapper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ module AutoLoadTest
class MyWrapper
include Neo4j::Node::Wrapper
def props
42
{ value: 42 }
end
end
class B
Expand All @@ -118,7 +118,7 @@ class C < D
allow(Neo4j::ActiveNode::Labels).to receive(:_wrapped_labels).and_return(label_mapping)

wrapper.should_receive(:_class_wrappers).and_return(label_mapping.keys)
D.any_instance.should_receive(:init_on_load).with(wrapper, 42)
D.any_instance.should_receive(:init_on_load).with(wrapper, { value: 42 })
wrapper.wrapper
end
end
Expand Down

0 comments on commit 12614be

Please sign in to comment.