upgraded couchrest for 080
This commit is contained in:
parent
db20bc4101
commit
915905ca13
|
@ -1,6 +1,6 @@
|
|||
Gem::Specification.new do |s|
|
||||
s.name = "couchrest"
|
||||
s.version = "0.7.99"
|
||||
s.version = "0.8.0"
|
||||
s.date = "2008-06-20"
|
||||
s.summary = "Lean and RESTful interface to CouchDB."
|
||||
s.email = "jchris@grabb.it"
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
require File.dirname(__FILE__) + '/lib/couchrest'
|
||||
require File.dirname(__FILE__) + '/lib/database'
|
||||
require File.dirname(__FILE__) + '/lib/pager'
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ require 'json'
|
|||
require 'rest_client'
|
||||
|
||||
require File.dirname(__FILE__) + '/database'
|
||||
require File.dirname(__FILE__) + '/pager'
|
||||
|
||||
class CouchRest
|
||||
attr_accessor :uri
|
||||
|
|
|
@ -31,6 +31,11 @@ class CouchRest
|
|||
url = CouchRest.paramify_url "#{@root}/_search", params
|
||||
CouchRest.get url
|
||||
end
|
||||
# experimental
|
||||
def action action, params = nil
|
||||
url = CouchRest.paramify_url "#{@root}/_action/#{action}", params
|
||||
CouchRest.get url
|
||||
end
|
||||
|
||||
def get id
|
||||
slug = CGI.escape(id)
|
||||
|
|
|
@ -116,7 +116,11 @@ when "push" # files to views
|
|||
end
|
||||
end
|
||||
# save them to the db
|
||||
control = db.get("#{prefix}/#{cntrl}") rescue nil
|
||||
begin
|
||||
control = db.get("#{prefix}/#{cntrl}")
|
||||
rescue RestClient::Request::RequestFailed
|
||||
control = nil
|
||||
end
|
||||
if (control && control['actions'] == actions)
|
||||
puts "no change to #{prefix}/#{cntrl}. skipping..."
|
||||
else
|
||||
|
|
|
@ -40,7 +40,11 @@ end
|
|||
|
||||
puts attachments.keys.inspect
|
||||
|
||||
doc = @db.get(dirname) rescue nil
|
||||
begin
|
||||
doc = @db.get(dirname)
|
||||
rescue RestClient::Request::RequestFailed
|
||||
doc = nil
|
||||
end
|
||||
|
||||
# puts "get: #{doc.inspect}"
|
||||
|
||||
|
|
|
@ -112,7 +112,11 @@ when "push" # files to views
|
|||
dviews.delete("#{view}-reduce") unless dviews["#{view}-reduce"]["reduce"]
|
||||
end
|
||||
# save them to the db
|
||||
view = db.get("_design/#{design}") rescue nil
|
||||
begin
|
||||
view = db.get("_design/#{design}")
|
||||
rescue RestClient::Request::RequestFailed
|
||||
view = nil
|
||||
end
|
||||
if (view && view['views'] == dviews)
|
||||
puts "no change to _design/#{design}. skipping..."
|
||||
else
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
require File.dirname(__FILE__) + '/../lib/couchrest'
|
||||
require File.dirname(__FILE__) + '/spec_helper'
|
||||
|
||||
describe CouchRest do
|
||||
|
||||
before(:each) do
|
||||
@cr = CouchRest.new("http://localhost:5984")
|
||||
@db = @cr.database('couchrest-test')
|
||||
@cr = CouchRest.new(COUCHHOST)
|
||||
begin
|
||||
@db = @cr.database(TESTDB)
|
||||
@db.delete!
|
||||
|
||||
rescue RestClient::Request::RequestFailed
|
||||
end
|
||||
end
|
||||
|
@ -49,7 +50,7 @@ describe CouchRest do
|
|||
|
||||
describe "initializing a database" do
|
||||
it "should return a db" do
|
||||
db = @cr.database('couchrest-test')
|
||||
db = @cr.database(TESTDB)
|
||||
db.should be_an_instance_of(CouchRest::Database)
|
||||
db.host.should == @cr.uri
|
||||
end
|
||||
|
@ -57,28 +58,28 @@ describe CouchRest do
|
|||
|
||||
describe "successfully creating a database" do
|
||||
it "should start without a database" do
|
||||
@cr.databases.should_not include('couchrest-test')
|
||||
@cr.databases.should_not include(TESTDB)
|
||||
end
|
||||
it "should return the created database" do
|
||||
db = @cr.create_db('couchrest-test')
|
||||
db = @cr.create_db(TESTDB)
|
||||
db.should be_an_instance_of(CouchRest::Database)
|
||||
end
|
||||
it "should create the database" do
|
||||
db = @cr.create_db('couchrest-test')
|
||||
@cr.databases.should include('couchrest-test')
|
||||
db = @cr.create_db(TESTDB)
|
||||
@cr.databases.should include(TESTDB)
|
||||
end
|
||||
end
|
||||
|
||||
describe "failing to create a database because the name is taken" do
|
||||
before(:each) do
|
||||
db = @cr.create_db('couchrest-test')
|
||||
db = @cr.create_db(TESTDB)
|
||||
end
|
||||
it "should start with the test database" do
|
||||
@cr.databases.should include('couchrest-test')
|
||||
@cr.databases.should include(TESTDB)
|
||||
end
|
||||
it "should PUT the database and raise an error" do
|
||||
lambda{
|
||||
@cr.create_db('couchrest-test')
|
||||
@cr.create_db(TESTDB)
|
||||
}.should raise_error(RestClient::Request::RequestFailed)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
require File.dirname(__FILE__) + '/../lib/couchrest'
|
||||
require File.dirname(__FILE__) + '/spec_helper'
|
||||
|
||||
describe CouchRest::Database do
|
||||
before(:each) do
|
||||
@cr = CouchRest.new("http://localhost:5984")
|
||||
@cr = CouchRest.new(COUCHHOST)
|
||||
begin
|
||||
@db = @cr.create_db('couchrest-test')
|
||||
@db = @cr.create_db(TESTDB)
|
||||
rescue RestClient::Request::RequestFailed
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue