Skip to content

Commit

Permalink
Merge pull request #827 from iHiD/speed_up_to_key
Browse files Browse the repository at this point in the history
Remove network call to exist? via to_key
  • Loading branch information
subvertallchris committed Jun 8, 2015
2 parents 4c3c564 + 7931c9a commit df793da
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/neo4j/shared/identity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def ==(other)
# Returns an Enumerable of all (primary) key attributes
# or nil if model.persisted? is false
def to_key
persisted? ? [id] : nil
_persisted_obj ? [id] : nil
end

# @return [Integer, nil] the neo4j id of the node if persisted or nil
Expand Down
23 changes: 23 additions & 0 deletions spec/unit/identity_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,27 @@ def id
end
end
end

describe '#to_key' do
let(:node) { clazz.new }
let(:created_node) { clazz.new }

before(:each) do
node.stub(:_persisted_obj).and_return(nil)
end

it 'should be nil before being persisted' do
node.to_key.should be_nil
end

context 'a persisted record' do
before(:each) do
created_node.stub(:_persisted_obj).and_return(double(neo_id: 4387, del: true))
end

it 'should be an array of ids after record is saved' do
created_node.to_key.should == [created_node.id]
end
end
end
end

0 comments on commit df793da

Please sign in to comment.