Skip to content

Commit

Permalink
fix node load error, additional spec
Browse files Browse the repository at this point in the history
  • Loading branch information
subvertallchris committed Sep 11, 2014
1 parent d09882c commit f0bd58a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/neo4j/active_rel/initialize.rb
Expand Up @@ -10,12 +10,12 @@ module Initialize
# @param [Neo4j::Relationship] start_node the starting node in the relationship.
# @param [Neo4j::Relationship] end_node the ending node in the relationship
# @param [String] type the relationship type
def init_on_load(persisted_rel, start_node_id, end_node_id, type)
def init_on_load(persisted_rel, from_node_id, to_node_id, type)
@_persisted_obj = persisted_rel
@rel_type = type
changed_attributes && changed_attributes.clear
@attributes = attributes.merge(persisted_rel.props.stringify_keys)
load_nodes(start_node_id, end_node_id)
load_nodes(from_node_id, to_node_id)
self.default_properties = persisted_rel.props
@attributes = convert_properties_to :ruby, @attributes
end
Expand Down
2 changes: 1 addition & 1 deletion lib/neo4j/active_rel/persistence.rb
Expand Up @@ -24,7 +24,7 @@ def create_model(*)
set_timestamps
properties = convert_properties_to :db, props
rel = _create_rel(from_node, to_node, properties)
init_on_load(rel, to_node, from_node, @rel_type)
init_on_load(rel, from_node, to_node, @rel_type)
true
end

Expand Down
6 changes: 3 additions & 3 deletions lib/neo4j/active_rel/property.rb
Expand Up @@ -59,9 +59,9 @@ def load_entity(id)

private

def load_nodes(start_node = nil, end_node = nil)
@from_node = RelatedNode.new(end_node)
@to_node = RelatedNode.new(start_node)
def load_nodes(from_node = nil, to_node = nil)
@from_node = RelatedNode.new(from_node)
@to_node = RelatedNode.new(to_node)
end
end
end
6 changes: 6 additions & 0 deletions spec/e2e/active_model_spec.rb
Expand Up @@ -537,6 +537,12 @@ class MyRelClass
expect(MyRelClass.where(score: 99)).to eq [@rel1]
end

it 'has the appropriate from and to nodes' do
rel = MyRelClass.where(score: 99).first
expect(rel.from_node).to eq from_node
expect(rel.to_node).to eq to_node
end

context 'with a string' do
it 'returns the matching rels' do
expect(MyRelClass.where('r1.score > 48')).to eq [@rel1, @rel2]
Expand Down

1 comment on commit f0bd58a

@subvertallchris
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.