Permalink
Browse files

extended the active_model tests and added the Document class

  • Loading branch information...
1 parent 81247a9 commit 9c17e997c3bde861280ebdb33201ddfe733ed2f1 Felipe committed Mar 13, 2010
Showing with 50 additions and 5 deletions.
  1. +9 −0 lib/couchrails/core/document.rb
  2. +39 −1 spec/couchrails_active_model_spec.rb
  3. +2 −4 spec/models.rb
@@ -0,0 +1,9 @@
+module CouchRails
+ class Document < CouchRest::ExtendedDocument
+ extend CouchRails::ActiveModel::ClassMethods
+ include CouchRails::ActiveModel::InstanceMethods
+
+ use_database CouchRails::Config.db_for(self.model_name.plural)
+
+ end
+end
@@ -3,9 +3,47 @@
describe 'An active_model compliant CouchRails::ActiveModel' do
before :each do
- @model = ComplianceTest::CouchDocument.new.to_model
+ @model = Models::Doc.new.to_model
end
it_should_behave_like 'an active_model compliant object'
+ describe "persisted?" do
+ it "should not be persisted when created" do
+ @model.persisted?.should be_false
+ end
+
+ it "should be persisted after saved" do
+ @model.save!
+ @model.persisted?.should be_true
+ end
+ end
+
+ describe "to_key" do
+ it "should return nil as the key for new document" do
+ @model.to_key.should be_nil
+ end
+
+ it "should return the _id as key for persisted document" do
+ @model.save!
+ @model.to_key.should == [@model["_id"]]
+ end
+
+ it "should allow user specify which field will be the key"
+ it "should return the value of the specified key when object is persisted"
+ it "should return nil when the oject is new, even when there is a field specified as the key"
+
+ end
+
+ describe "to_param" do
+ it "should resolve to the first item of to_key result when the document is persisted" do
+ @model.save!
+ @model.to_param.should == @model.to_key.first.to_s
+ end
+
+ it "should resolve to nil when the document is new" do
+ @model.to_param.should be_nil
+ end
+ end
+
end
View
@@ -1,6 +1,4 @@
-module ComplianceTest
- class CouchDocument
- extend CouchRails::ActiveModel::ClassMethods
- include CouchRails::ActiveModel::InstanceMethods
+module Models
+ class Doc < CouchRails::Document
end
end

0 comments on commit 9c17e99

Please sign in to comment.