From c7a17c8b7f7e6ad7ed3dc45d81f2d847a522bdbf Mon Sep 17 00:00:00 2001 From: Roel van Dijk Date: Sat, 8 Sep 2012 22:22:34 +0200 Subject: [PATCH] Add Relationships specs. --- lib/neography/rest/relationship_properties.rb | 14 ++-- .../unit/rest/relationship_properties_spec.rb | 80 +++++++++++++++++++ 2 files changed, 87 insertions(+), 7 deletions(-) create mode 100644 spec/unit/rest/relationship_properties_spec.rb diff --git a/lib/neography/rest/relationship_properties.rb b/lib/neography/rest/relationship_properties.rb index c8ba4df..8f25d45 100644 --- a/lib/neography/rest/relationship_properties.rb +++ b/lib/neography/rest/relationship_properties.rb @@ -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) @@ -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 diff --git a/spec/unit/rest/relationship_properties_spec.rb b/spec/unit/rest/relationship_properties_spec.rb new file mode 100644 index 0000000..d110210 --- /dev/null +++ b/spec/unit/rest/relationship_properties_spec.rb @@ -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