-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9d2fee7
commit 7a77fc4
Showing
4 changed files
with
190 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
module Neography | ||
class Rest | ||
class Constraints | ||
extend Neography::Rest::Paths | ||
include Neography::Rest::Helpers | ||
|
||
add_path :base, "/schema/constraint/" | ||
add_path :label, "/schema/constraint/:label" | ||
add_path :uniqueness, "/schema/constraint/:label/uniqueness/" | ||
add_path :unique, "/schema/constraint/:label/uniqueness/:property" | ||
|
||
def initialize(connection) | ||
@connection = connection | ||
end | ||
|
||
def drop(label, property) | ||
@connection.delete(unique_path(:label => label, :property => property)) | ||
end | ||
|
||
def list | ||
@connection.get(base_path) | ||
end | ||
|
||
def get(label) | ||
@connection.get(label_path(:label => label)) | ||
end | ||
|
||
def get_uniqueness(label) | ||
@connection.get(uniqueness_path(:label => label)) | ||
end | ||
|
||
def get_unique(label, property) | ||
@connection.get(unique_path(:label => label, :property => property)) | ||
end | ||
|
||
def create_unique(label, property) | ||
options = { | ||
:body => { | ||
:property_keys => [property] | ||
}.to_json, | ||
:headers => json_content_type | ||
} | ||
@connection.post(uniqueness_path(:label => label), options) | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
require 'spec_helper' | ||
|
||
describe Neography::Rest do | ||
before(:each) do | ||
@neo = Neography::Rest.new | ||
end | ||
|
||
describe "create unique constraint" do | ||
it "can create a unique constraint" do | ||
label = "User" | ||
property = "user_id" | ||
uc = @neo.create_unique_constraint(label, property) | ||
uc.should_not be_nil | ||
uc["label"].should == label | ||
uc["property_keys"].should == [property] | ||
end | ||
end | ||
|
||
describe "get a unique constraint" do | ||
it "can get a unique constraint" do | ||
label = "User" | ||
property = "user_id" | ||
uc = @neo.get_unique_constraint(label, property) | ||
uc.should_not be_nil | ||
uc.first["label"].should == label | ||
uc.first["property_keys"].should == [property] | ||
end | ||
end | ||
|
||
describe "get unique constraints" do | ||
it "can get unique constraints for a label" do | ||
label = "User" | ||
property = "user_id" | ||
uc = @neo.get_uniqueness(label) | ||
uc.should_not be_nil | ||
uc.first["label"].should == label | ||
uc.first["property_keys"].should == [property] | ||
end | ||
end | ||
|
||
describe "list constraints" do | ||
it "can get a list of constraints" do | ||
label = "User" | ||
property = "user_id" | ||
cs = @neo.get_constraints | ||
cs.should_not be_nil | ||
cs.first["label"].should == label | ||
cs.first["property_keys"].should == [property] | ||
end | ||
|
||
it "can get a list of constraints for a specifc label" do | ||
label = "User" | ||
property = "user_id" | ||
cs = @neo.get_constraints(label) | ||
cs.should_not be_nil | ||
cs.first["label"].should == label | ||
cs.first["property_keys"].should == [property] | ||
end | ||
end | ||
|
||
describe "drop a constraint" do | ||
it "can drop a constraint" do | ||
label = "User" | ||
property = "user_id" | ||
uc = @neo.drop_constraint(label, property) | ||
uc.should be_nil | ||
cs = @neo.get_constraints(label) | ||
cs.should be_empty | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
require 'spec_helper' | ||
|
||
module Neography | ||
class Rest | ||
describe Constraints do | ||
|
||
let(:connection) { double } | ||
subject { Constraints.new(connection) } | ||
|
||
it "list constraints" do | ||
connection.should_receive(:get).with("/schema/constraint/") | ||
subject.list | ||
end | ||
|
||
it "get constraints for a label" do | ||
connection.should_receive(:get).with("/schema/constraint/label") | ||
subject.get("label") | ||
end | ||
|
||
it "create a unique constraint for a label" do | ||
options = { | ||
:body => '{"property_keys":["property"]}', | ||
:headers => json_content_type | ||
} | ||
connection.should_receive(:post).with("/schema/constraint/label/uniqueness/", options) | ||
subject.create_unique("label", "property") | ||
end | ||
|
||
it "get unique constraints for a label" do | ||
connection.should_receive(:get).with("/schema/constraint/label/uniqueness/") | ||
subject.get_uniqueness("label") | ||
end | ||
|
||
it "get a specific unique constraint for a label" do | ||
connection.should_receive(:get).with("/schema/constraint/label/uniqueness/property") | ||
subject.get_unique("label", "property") | ||
end | ||
|
||
it "can delete a constraint for a label" do | ||
connection.should_receive(:delete).with("/schema/constraint/label/uniqueness/property") | ||
subject.drop("label","property") | ||
end | ||
|
||
end | ||
end | ||
end |