Skip to content

Commit

Permalink
Add spec for REST node properties.
Browse files Browse the repository at this point in the history
  • Loading branch information
rdvdijk committed Sep 8, 2012
1 parent d1b50e8 commit 5f88ebd
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 14 deletions.
14 changes: 7 additions & 7 deletions lib/neography/rest/node_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 |property, value|
options = { :body => value.to_json, :headers => json_content_type }
@connection.put(single_path(:id => get_id(id), :property => property), 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 |property, value|
options = { :body => value.to_json, :headers => json_content_type }
@connection.put(single_path(:id => get_id(id), :property => property), options)
end
end

end
end
end
7 changes: 6 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@ def generate_text(length=8)

RSpec.configure do |c|
c.filter_run_excluding :slow => true, :break_gremlin => true
end
end

def json_content_type
{"Content-Type"=>"application/json"}
end

80 changes: 80 additions & 0 deletions spec/unit/rest/node_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 NodeProperties do

let(:connection) { stub }
subject { NodeProperties.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("/node/42/properties/foo", options1)
connection.should_receive(:put).with("/node/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("/node/42/properties", options)
subject.reset("42", {:foo => "bar"})
end

context "getting properties" do

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

it "gets multiple properties" do
connection.should_receive(:get).with("/node/42/properties/foo")
connection.should_receive(:get).with("/node/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("/node/42/properties")
subject.remove("42")
end

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

end

end
end
end
6 changes: 0 additions & 6 deletions spec/unit/rest/nodes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,6 @@ class Rest

end

private

def json_content_type
{"Content-Type"=>"application/json"}
end

end
end
end

0 comments on commit 5f88ebd

Please sign in to comment.