test/database_test.rb in mattly-exegesis-0.2.0 vs test/database_test.rb in mattly-exegesis-0.2.1
- old
+ new
@@ -5,10 +5,20 @@
end
class CustomDesignDirDatabaseTest
include Exegesis::Database
designs_directory 'app/designs'
end
+class NamedDocumentDatabaseTest
+ include Exegesis::Database
+ named_document :settings do
+ expose :things
+ end
+end
+class NamedDocumentWithoutBlockDatabaseTest
+ include Exegesis::Database
+ named_document :blah
+end
class DatabaseTestDocument
include Exegesis::Document
end
class ExegesisDatabaseTest < Test::Unit::TestCase
@@ -79,10 +89,20 @@
expect { @doc.is_a?(Hash).will == true }
expect { @doc['_id'].will == 'test-document' }
expect { @doc['key'].will == 'value' }
expect { @doc['class'].will == 'DatabaseTestDocument' }
end
+
+ context "retrieving multiple documents" do
+ before do
+ docs = [{"_id"=>"a"},{"_id"=>"b"},{"_id"=>"c"}].map{|d| d.update('class' => 'DatabaseTestDocument')}
+ RestClient.post("#{@db.uri}/_bulk_docs", {"docs"=>docs}.to_json)
+ end
+
+ expect { @db.get(%w(a b c)).size.will == 3 }
+ expect { @db.get(%w(a b c)).all?{|doc| doc.is_a?(DatabaseTestDocument)}.will == true }
+ end
end
context "saving docs" do
before do
reset_db
@@ -126,10 +146,11 @@
context "without a valid rev" do
before { @doc.delete('_rev') }
expect { lambda { @db.save(@doc) }.will raise_error }
end
end
+
end
end
context "multiple docs" do
before do
@@ -154,8 +175,44 @@
end
context "setting the designs directory" do
expect { DatabaseTest.designs_directory.will == Pathname.new('designs') }
expect { CustomDesignDirDatabaseTest.designs_directory.will == Pathname.new('app/designs') }
+ end
+
+ context "with a named document" do
+ context "that doesn't exist yet" do
+ before do
+ reset_db
+ @db = NamedDocumentDatabaseTest.new('exegesis-test')
+ end
+
+ expect { @db.settings.kind_of?(NamedDocumentDatabaseTest::Settings).will == true }
+ expect { @db.settings.rev.will =~ /1-\d{7,12}/ }
+ expect { @db.settings.respond_to?(:things).will == true }
+ expect { @db.settings; lambda{ @db.get('settings') }.wont raise_error(RestClient::ResourceNotFound) }
+ end
+
+ context "that does exist" do
+ before do
+ reset_db
+ @db = NamedDocumentDatabaseTest.new('exegesis-test')
+ @doc = @db.save({'_id' => 'settings', 'things' => %w(foo bar baz), 'class' => 'NamedDocumentDatabaseTest::Settings'})
+ end
+
+ expect { lambda { @db.get('settings') }.wont raise_error(RestClient::ResourceNotFound) }
+ expect { @db.settings.rev.will == @doc['_rev'] }
+ expect { @db.settings.rev.will =~ /1-\d{7,12}/ }
+ expect { @db.settings.things.will == %w(foo bar baz) }
+ end
+
+ context "when the declaration does not have a block" do
+ before do
+ reset_db
+ @db = NamedDocumentWithoutBlockDatabaseTest.new('exegesis-test')
+ end
+
+ expect { @db.blah.kind_of?(NamedDocumentWithoutBlockDatabaseTest::Blah).will == true }
+ end
end
end
\ No newline at end of file