use url parser to parse database! urls
This commit is contained in:
parent
a6f852943e
commit
ef3055c222
|
@ -76,19 +76,15 @@ module CouchRest
|
||||||
# creates it if it isn't already there
|
# creates it if it isn't already there
|
||||||
# returns it after it's been created
|
# returns it after it's been created
|
||||||
def database! url
|
def database! url
|
||||||
uri = URI.parse url
|
parsed = parse url
|
||||||
path = uri.path
|
cr = CouchRest.new(parsed[:host])
|
||||||
uri.path = ''
|
cr.database!(parsed[:database])
|
||||||
cr = CouchRest.new(uri.to_s)
|
|
||||||
cr.database!(path)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def database url
|
def database url
|
||||||
uri = URI.parse url
|
parsed = parse url
|
||||||
path = uri.path
|
cr = CouchRest.new(parsed[:host])
|
||||||
uri.path = ''
|
cr.database(parsed[:database])
|
||||||
cr = CouchRest.new(uri.to_s)
|
|
||||||
cr.database(path)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def put uri, doc = nil
|
def put uri, doc = nil
|
||||||
|
|
|
@ -139,8 +139,13 @@ describe CouchRest do
|
||||||
it "should be possible without an explicit CouchRest instantiation" do
|
it "should be possible without an explicit CouchRest instantiation" do
|
||||||
db = CouchRest.database "http://localhost:5984/couchrest-test"
|
db = CouchRest.database "http://localhost:5984/couchrest-test"
|
||||||
db.should be_an_instance_of(CouchRest::Database)
|
db.should be_an_instance_of(CouchRest::Database)
|
||||||
db.host.should == "http://localhost:5984"
|
db.host.should == "localhost:5984"
|
||||||
end
|
end
|
||||||
|
# TODO add https support (need test environment...)
|
||||||
|
# it "should work with https" # do
|
||||||
|
# db = CouchRest.database "https://localhost:5984/couchrest-test"
|
||||||
|
# db.host.should == "https://localhost:5984"
|
||||||
|
# end
|
||||||
it "should not create the database automatically" do
|
it "should not create the database automatically" do
|
||||||
db = CouchRest.database "http://localhost:5984/couchrest-test"
|
db = CouchRest.database "http://localhost:5984/couchrest-test"
|
||||||
lambda{db.info}.should raise_error(RestClient::ResourceNotFound)
|
lambda{db.info}.should raise_error(RestClient::ResourceNotFound)
|
||||||
|
@ -150,6 +155,7 @@ describe CouchRest do
|
||||||
describe "ensuring the db exists" do
|
describe "ensuring the db exists" do
|
||||||
it "should be super easy" do
|
it "should be super easy" do
|
||||||
db = CouchRest.database! "http://localhost:5984/couchrest-test-2"
|
db = CouchRest.database! "http://localhost:5984/couchrest-test-2"
|
||||||
|
db.name.should == 'couchrest-test-2'
|
||||||
db.info["db_name"].should == 'couchrest-test-2'
|
db.info["db_name"].should == 'couchrest-test-2'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue