Skip to content

Commit

Permalink
Add Relationships specs.
Browse files Browse the repository at this point in the history
  • Loading branch information
rdvdijk committed Sep 8, 2012
1 parent c758b82 commit c7a17c8
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lib/neography/rest/relationship_properties.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ def initialize(connection)
@connection = connection
end

def set(id, properties)
properties.each do |key, value|
options = { :body => value.to_json, :headers => json_content_type }
@connection.put(single_path(:id => get_id(id), :property => key), options)
end
end

def reset(id, properties)
options = { :body => properties.to_json, :headers => json_content_type }
@connection.put(all_path(:id => get_id(id)), options)
Expand Down Expand Up @@ -48,13 +55,6 @@ def remove_each(id, *properties)
end
end

def set(id, properties)
properties.each do |key, value|
options = { :body => value.to_json, :headers => json_content_type }
@connection.put(single_path(:id => get_id(id), :property => key), options)
end
end

end
end
end
80 changes: 80 additions & 0 deletions spec/unit/rest/relationship_properties_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
require 'spec_helper'

module Neography
class Rest
describe RelationshipProperties do

let(:connection) { stub }
subject { RelationshipProperties.new(connection) }

it "sets properties" do
options1 = {
:body => '"bar"',
:headers => json_content_type
}
options2 = {
:body => '"qux"',
:headers => json_content_type
}
connection.should_receive(:put).with("/relationship/42/properties/foo", options1)
connection.should_receive(:put).with("/relationship/42/properties/baz", options2)
subject.set("42", {:foo => "bar", :baz => "qux"})
end

it "resets properties" do
options = {
:body => '{"foo":"bar"}',
:headers => json_content_type
}
connection.should_receive(:put).with("/relationship/42/properties", options)
subject.reset("42", {:foo => "bar"})
end

context "getting properties" do

it "gets all properties" do
connection.should_receive(:get).with("/relationship/42/properties")
subject.get("42")
end

it "gets multiple properties" do
connection.should_receive(:get).with("/relationship/42/properties/foo")
connection.should_receive(:get).with("/relationship/42/properties/bar")
subject.get("42", "foo", "bar")
end

it "returns multiple properties as a hash" do
connection.stub(:get).and_return("baz", "qux")
subject.get("42", "foo", "bar").should == { "foo" => "baz", "bar" => "qux" }
end

it "returns nil if no properties were found" do
connection.stub(:get).and_return(nil, nil)
subject.get("42", "foo", "bar").should be_nil
end

it "returns hash without nil return values" do
connection.stub(:get).and_return("baz", nil)
subject.get("42", "foo", "bar").should == { "foo" => "baz" }
end

end

context "removing properties" do

it "removes all properties" do
connection.should_receive(:delete).with("/relationship/42/properties")
subject.remove("42")
end

it "removes multiple properties" do
connection.should_receive(:delete).with("/relationship/42/properties/foo")
connection.should_receive(:delete).with("/relationship/42/properties/bar")
subject.remove("42", "foo", "bar")
end

end

end
end
end

0 comments on commit c7a17c8

Please sign in to comment.