diff --git a/lib/couchrest.rb b/lib/couchrest.rb index aeb0dd2..31185e9 100644 --- a/lib/couchrest.rb +++ b/lib/couchrest.rb @@ -76,19 +76,15 @@ module CouchRest # creates it if it isn't already there # returns it after it's been created def database! url - uri = URI.parse url - path = uri.path - uri.path = '' - cr = CouchRest.new(uri.to_s) - cr.database!(path) + parsed = parse url + cr = CouchRest.new(parsed[:host]) + cr.database!(parsed[:database]) end def database url - uri = URI.parse url - path = uri.path - uri.path = '' - cr = CouchRest.new(uri.to_s) - cr.database(path) + parsed = parse url + cr = CouchRest.new(parsed[:host]) + cr.database(parsed[:database]) end def put uri, doc = nil diff --git a/spec/couchrest_spec.rb b/spec/couchrest_spec.rb index 22b67e0..2fa9eff 100644 --- a/spec/couchrest_spec.rb +++ b/spec/couchrest_spec.rb @@ -139,8 +139,13 @@ describe CouchRest do it "should be possible without an explicit CouchRest instantiation" do db = CouchRest.database "http://localhost:5984/couchrest-test" db.should be_an_instance_of(CouchRest::Database) - db.host.should == "http://localhost:5984" + db.host.should == "localhost:5984" 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 db = CouchRest.database "http://localhost:5984/couchrest-test" lambda{db.info}.should raise_error(RestClient::ResourceNotFound) @@ -150,6 +155,7 @@ describe CouchRest do describe "ensuring the db exists" do it "should be super easy" do db = CouchRest.database! "http://localhost:5984/couchrest-test-2" + db.name.should == 'couchrest-test-2' db.info["db_name"].should == 'couchrest-test-2' end end