Skip to content

Commit

Permalink
Add NodeAutoIndexes spec.
Browse files Browse the repository at this point in the history
  • Loading branch information
rdvdijk committed Sep 8, 2012
1 parent bff0665 commit 903aa56
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 1 deletion.
20 changes: 19 additions & 1 deletion spec/matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,33 @@
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
"JSON in field '#{field}' should match '#{expected.inspect}'"
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
57 changes: 57 additions & 0 deletions spec/unit/rest/node_auto_indexes_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 903aa56

Please sign in to comment.