Skip to content

Commit

Permalink
Delete nodes via REST; added specs
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Kleppmann committed Jun 17, 2009
1 parent 4399a28 commit 98ff17a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
17 changes: 16 additions & 1 deletion lib/rest/rest.rb
Expand Up @@ -140,6 +140,13 @@ def self.included(c)
response
end

Sinatra::Application.delete("/nodes/#{classname}/:id") do
node = Neo4j.load(params[:id])
return 404, "Can't find node with id #{params[:id]}" if node.nil?
node.delete
""
end

Sinatra::Application.post("/nodes/#{classname}") do
p = c.new
data = JSON.parse(request.body.read)
Expand All @@ -149,7 +156,15 @@ def self.included(c)

Sinatra::Application.get("/nodes/#{classname}") do
content_type :json
c.all.map{|rel| rel.end_node.props}.to_json
Neo4j::Transaction.run {
resources = if params[:search].nil?
c.all.map{|rel| rel.end_node}
else
puts "Search string: #{params[:search]}"
c.find(params[:search])
end
resources.map{|res| res.props}.to_json
}
end
end
end
Expand Down
30 changes: 29 additions & 1 deletion test/rest/rest_spec.rb
Expand Up @@ -170,6 +170,35 @@ class Foo
status.should == 404
end

it "should be possible to set all properties on PUT nodes/Person/<node_id>" do
# given
p = Person.new
p.name = 'sune123'

# when
data = {:name => 'blah', :dynamic_property => 'cool stuff'}
put "/nodes/Person/#{p.neo_node_id}", data.to_json

# then
status.should == 200
p.name.should == 'blah'
p.props['dynamic_property'].should == 'cool stuff'
end

it "should be possible to delete a node on DELETE nodes/Person/<node_id>" do
# given
p = Person.new
p.name = 'asdf'
id = p.neo_node_id

# when
delete "/nodes/Person/#{id}"

# then
status.should == 200
Neo4j.load(id).should be_nil
end

it "should be possible to get a property on GET nodes/Person/<node_id>/<property_name>" do
# given
p = Person.new
Expand Down Expand Up @@ -197,5 +226,4 @@ class Foo
status.should == 200
p.name.should == 'new-name'
end

end

0 comments on commit 98ff17a

Please sign in to comment.