Skip to content

Commit

Permalink
Merge pull request maxdemarzi#32 from kamranjon/relations
Browse files Browse the repository at this point in the history
Relations
  • Loading branch information
blizkreeg committed Aug 30, 2013
2 parents f561283 + 022bc99 commit b291249
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/deja/cast.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def sans_initial_node(relation_hash, initial_node)
memo[k] = rel[:rel][k]
memo
end
relationship = rel_class.new(rel[:rel][:type], initial_node, related_node, :out, rel_attributes)
relationship = rel_class.new(rel[:rel][:type], initial_node, related_node, rel_attributes)
last_relationship = relationship
relationship.instance_variable_set('@id', rel[:rel][:id])
[related_node, relationship]
Expand Down
6 changes: 3 additions & 3 deletions lib/deja/relationship.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def valid_direction?(from_type=nil, to_type=nil)
end
end

# initialize(label, start_node, end_node, direction, options = {})
# initialize(label, start_node, end_node, options = {})
# the method below ensures that the relationship configuration is done between before_initialize and after_initialize
def initialize(*args)
super(*args) do |config|
Expand Down Expand Up @@ -67,8 +67,8 @@ def destroy
true
end

def add_to_index(index, key, value, unique = false)
Deja.add_relationship_to_index(index, key, value)
def add_to_index(index, key, value, space = nil)
Deja.add_relationship_to_index(index, key, value, @id)
end

def remove_from_index(*args)
Expand Down
3 changes: 2 additions & 1 deletion lib/deja/schema_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ def attr_accessorize(name, opts)
end
end

def create_index_methods(key, values = nil, unique = nil)
def create_index_methods(key, values = nil, unique = false)

define_attribute_method(key)
@@indexed_attributes[self.name] ||= []
@@indexed_attributes[self.name] << key
Expand Down
2 changes: 1 addition & 1 deletion spec/index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Friends < Relationship
before :each do
@first_node = FactoryGirl.create(:person);
@second_node = FactoryGirl.create(:person);
@relationship = Friends.new(:friends, @first_node, @second_node, :out).create!
@relationship = Friends.new(:friends, @first_node, @second_node).create!
Deja.create_node_index('test_node_index')
Deja.create_relationship_index('test_relationship_index')
end
Expand Down
18 changes: 17 additions & 1 deletion spec/relationship_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

class FriendsWith < Relationship
attribute :uuid, Integer
attribute :name, String
attribute :name, String, :index => true
end

Deja.create_relationship_index('idx_FriendsWith')

describe Node do
before :each do
@first_node = FactoryGirl.create(:person);
Expand All @@ -16,6 +18,10 @@ class FriendsWith < Relationship
@relationship = FriendsWith.new(:friends_with, @first_node, @second_node, :out, @relationship_properties)
end

after :each do
Deja.neo.execute_query("START n=node(*) MATCH n-[r?]->() WHERE ID(n) <> 0 DELETE r DELETE n")
end

describe ".save" do
context "with a relationship that has not yet been saved to the graph" do
it "should create a new relationship in the graph" do
Expand Down Expand Up @@ -55,5 +61,15 @@ class FriendsWith < Relationship
new_rel.end_node.should be_a(Node)
end
end

context "given a relationship index which exists in the graph" do
it "should return a relationship object with related nodes" do
@relationship.save
new_rel = FriendsWith.find({:index => 'idx_FriendsWith', :key => 'name', :value => @relationship.name})
new_rel.should be_a(Relationship)
new_rel.start_node.should be_a(Node)
new_rel.end_node.should be_a(Node)
end
end
end
end

0 comments on commit b291249

Please sign in to comment.