Merge branch 'janl/master'

This commit is contained in:
Chris Anderson 2008-12-31 15:16:32 -08:00
commit c488aab338
16 changed files with 81 additions and 49 deletions

View file

@ -46,48 +46,48 @@ describe CouchRest do
it "should parse just a dbname" do
db = CouchRest.parse "my-db"
db[:database].should == "my-db"
db[:host].should == "localhost:5984"
db[:host].should == "127.0.0.1:5984"
end
it "should parse a host and db" do
db = CouchRest.parse "localhost/my-db"
db = CouchRest.parse "127.0.0.1/my-db"
db[:database].should == "my-db"
db[:host].should == "localhost"
db[:host].should == "127.0.0.1"
end
it "should parse a host and db with http" do
db = CouchRest.parse "http://localhost/my-db"
db = CouchRest.parse "http://127.0.0.1/my-db"
db[:database].should == "my-db"
db[:host].should == "localhost"
db[:host].should == "127.0.0.1"
end
it "should parse a host with a port and db" do
db = CouchRest.parse "localhost:5555/my-db"
db = CouchRest.parse "127.0.0.1:5555/my-db"
db[:database].should == "my-db"
db[:host].should == "localhost:5555"
db[:host].should == "127.0.0.1:5555"
end
it "should parse a host with a port and db with http" do
db = CouchRest.parse "http://localhost:5555/my-db"
db = CouchRest.parse "http://127.0.0.1:5555/my-db"
db[:database].should == "my-db"
db[:host].should == "localhost:5555"
db[:host].should == "127.0.0.1:5555"
end
it "should parse just a host" do
db = CouchRest.parse "http://localhost:5555/"
db = CouchRest.parse "http://127.0.0.1:5555/"
db[:database].should be_nil
db[:host].should == "localhost:5555"
db[:host].should == "127.0.0.1:5555"
end
it "should parse just a host no slash" do
db = CouchRest.parse "http://localhost:5555"
db[:host].should == "localhost:5555"
db = CouchRest.parse "http://127.0.0.1:5555"
db[:host].should == "127.0.0.1:5555"
db[:database].should be_nil
end
it "should get docid" do
db = CouchRest.parse "localhost:5555/my-db/my-doc"
db = CouchRest.parse "127.0.0.1:5555/my-db/my-doc"
db[:database].should == "my-db"
db[:host].should == "localhost:5555"
db[:host].should == "127.0.0.1:5555"
db[:doc].should == "my-doc"
end
it "should get docid with http" do
db = CouchRest.parse "http://localhost:5555/my-db/my-doc"
db = CouchRest.parse "http://127.0.0.1:5555/my-db/my-doc"
db[:database].should == "my-db"
db[:host].should == "localhost:5555"
db[:host].should == "127.0.0.1:5555"
db[:doc].should == "my-doc"
end
@ -137,24 +137,24 @@ describe CouchRest do
describe "easy initializing a database adapter" do
it "should be possible without an explicit CouchRest instantiation" do
db = CouchRest.database "http://localhost:5984/couchrest-test"
db = CouchRest.database "http://127.0.0.1:5984/couchrest-test"
db.should be_an_instance_of(CouchRest::Database)
db.host.should == "localhost:5984"
db.host.should == "127.0.0.1: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"
# db = CouchRest.database "https://127.0.0.1:5984/couchrest-test"
# db.host.should == "https://127.0.0.1:5984"
# end
it "should not create the database automatically" do
db = CouchRest.database "http://localhost:5984/couchrest-test"
db = CouchRest.database "http://127.0.0.1:5984/couchrest-test"
lambda{db.info}.should raise_error(RestClient::ResourceNotFound)
end
end
describe "ensuring the db exists" do
it "should be super easy" do
db = CouchRest.database! "http://localhost:5984/couchrest-test-2"
db = CouchRest.database! "http://127.0.0.1:5984/couchrest-test-2"
db.name.should == 'couchrest-test-2'
db.info["db_name"].should == 'couchrest-test-2'
end

View file

@ -159,7 +159,7 @@ describe CouchRest::Database do
docs = [{'key' => 'value'}, {'_id' => 'totally-uniq'}]
id_docs = [{'key' => 'value', '_id' => 'asdf6sgadkfhgsdfusdf'}, {'_id' => 'totally-uniq'}]
CouchRest.should_receive(:post).with("http://localhost:5984/couchrest-test/_bulk_docs", {:docs => id_docs})
CouchRest.should_receive(:post).with("http://127.0.0.1:5984/couchrest-test/_bulk_docs", {:docs => id_docs})
@db.bulk_save(docs)
end

View file

@ -46,7 +46,7 @@ class Course < CouchRest::Model
end
class Article < CouchRest::Model
use_database CouchRest.database!('http://localhost:5984/couchrest-model-test')
use_database CouchRest.database!('http://127.0.0.1:5984/couchrest-model-test')
unique_id :slug
view_by :date, :descending => true
@ -110,8 +110,8 @@ describe CouchRest::Model do
@db = @cr.create_db(TESTDB) rescue nil
@adb = @cr.database('couchrest-model-test')
@adb.delete! rescue nil
CouchRest.database!('http://localhost:5984/couchrest-model-test')
CouchRest::Model.default_database = CouchRest.database!('http://localhost:5984/couchrest-test')
CouchRest.database!('http://127.0.0.1:5984/couchrest-model-test')
CouchRest::Model.default_database = CouchRest.database!('http://127.0.0.1:5984/couchrest-test')
end
it "should use the default database" do