From 903aa56d7da8d0037d38a5c6f5aeaf3f62b56cb6 Mon Sep 17 00:00:00 2001 From: Roel van Dijk Date: Sat, 8 Sep 2012 21:16:57 +0200 Subject: [PATCH] Add NodeAutoIndexes spec. --- spec/matchers.rb | 20 ++++++++- spec/unit/rest/node_auto_indexes_spec.rb | 57 ++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 spec/unit/rest/node_auto_indexes_spec.rb diff --git a/spec/matchers.rb b/spec/matchers.rb index 6c3cde2..955a23a 100644 --- a/spec/matchers.rb +++ b/spec/matchers.rb @@ -2,11 +2,12 @@ RSpec::Matchers.define :json_match do |field, expected| match do |actual| + p actual[field] expected == JSON.parse(actual[field]) end failure_message_for_should do - "expected JSON in field '#{@field}' to not match '#{@expected}'" + "expected JSON in field '#{field}' to match '#{expected}'" end description do @@ -14,3 +15,20 @@ end end + +# Convenience matcher for matching fields in a hash +RSpec::Matchers.define :hash_match do |field, expected| + + match do |actual| + expected == actual[field] + end + + failure_message_for_should do + "expected field '#{field}' to match '#{expected}'" + end + + description do + "field '#{field}' should match '#{expected.inspect}'" + end + +end diff --git a/spec/unit/rest/node_auto_indexes_spec.rb b/spec/unit/rest/node_auto_indexes_spec.rb new file mode 100644 index 0000000..8bd623e --- /dev/null +++ b/spec/unit/rest/node_auto_indexes_spec.rb @@ -0,0 +1,57 @@ +require 'spec_helper' + +module Neography + class Rest + describe NodeAutoIndexes do + + let(:connection) { stub } + subject { NodeAutoIndexes.new(connection) } + + it "gets a node from an auto index" do + connection.should_receive(:get).with("/index/auto/node/some_key/some_value") + subject.get("some_key", "some_value") + end + + it "returns nil if nothing was found in the auto index" do + connection.stub(:get).and_return(nil) + subject.get("some_key", "some_value").should be_nil + end + + it "finds by key and value" do + connection.should_receive(:get).with("/index/auto/node/some_key/some_value") + subject.find("some_key", "some_value") + end + + it "finds by query" do + connection.should_receive(:get).with("/index/auto/node/?query=some_query") + subject.query("some_query") + end + + it "gets the status" do + connection.should_receive(:get).with("/index/auto/node/status") + subject.status + end + + it "sets the status" do + connection.should_receive(:put).with("/index/auto/node/status", hash_match(:body, '"foo"')) + subject.status = "foo" + end + + it "gets auto index properties" do + connection.should_receive(:get).with("/index/auto/node/properties") + subject.properties + end + + it "adds a property to an auto index" do + connection.should_receive(:post).with("/index/auto/node/properties", hash_match(:body, "foo")) + subject.add_property("foo") + end + + it "removes a property from an auto index" do + connection.should_receive(:delete).with("/index/auto/node/properties/foo") + subject.remove_property("foo") + end + + end + end +end