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