Added ExtendedDocument.create({}) and #create!({}) so you don't have to do Model.new.create
This commit is contained in:
parent
964526193b
commit
5140899041
|
@ -3,10 +3,11 @@
|
||||||
* Major enhancements
|
* Major enhancements
|
||||||
|
|
||||||
* Created an abstraction HTTP layer to support different http adapters (Matt Aimonetti)
|
* Created an abstraction HTTP layer to support different http adapters (Matt Aimonetti)
|
||||||
|
* Added ExtendedDocument.create({}) and #create!({}) so you don't have to do Model.new.create (Matt Aimonetti)
|
||||||
|
|
||||||
* Minor enhancements
|
* Minor enhancements
|
||||||
|
|
||||||
* Optimized Model.count to run about 3x faster (Matt Aimonetti)
|
* Optimized ExtendedDocument.count to run about 3x faster (Matt Aimonetti)
|
||||||
* Added Float casting (Ryan Felton & Matt Aimonetti)
|
* Added Float casting (Ryan Felton & Matt Aimonetti)
|
||||||
|
|
||||||
== 0.30
|
== 0.30
|
||||||
|
|
|
@ -52,8 +52,25 @@ module CouchRest
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Defines an instance and save it directly to the database
|
||||||
|
#
|
||||||
|
# ==== Returns
|
||||||
|
# returns the reloaded document
|
||||||
|
def self.create(options)
|
||||||
|
instance = new(options)
|
||||||
|
instance.create
|
||||||
|
instance
|
||||||
|
end
|
||||||
|
|
||||||
|
# Defines an instance and save it directly to the database
|
||||||
|
#
|
||||||
|
# ==== Returns
|
||||||
|
# returns the reloaded document or raises an exception
|
||||||
|
def self.create!(options)
|
||||||
|
instance = new(options)
|
||||||
|
instance.create!
|
||||||
|
instance
|
||||||
|
end
|
||||||
|
|
||||||
# Automatically set <tt>updated_at</tt> and <tt>created_at</tt> fields
|
# Automatically set <tt>updated_at</tt> and <tt>created_at</tt> fields
|
||||||
# on the document whenever saving occurs. CouchRest uses a pretty
|
# on the document whenever saving occurs. CouchRest uses a pretty
|
||||||
|
|
|
@ -97,6 +97,22 @@ describe "ExtendedDocument" do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "creating a new document" do
|
||||||
|
it "should instantialize and save a document" do
|
||||||
|
article = Article.create(:title => 'my test')
|
||||||
|
article.title.should == 'my test'
|
||||||
|
article.should_not be_new_document
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should trigger the create callbacks" do
|
||||||
|
doc = WithCallBacks.create(:name => 'my other test')
|
||||||
|
doc.run_before_create.should be_true
|
||||||
|
doc.run_after_create.should be_true
|
||||||
|
doc.run_before_save.should be_true
|
||||||
|
doc.run_after_save.should be_true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "update attributes without saving" do
|
describe "update attributes without saving" do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
a = Article.get "big-bad-danger" rescue nil
|
a = Article.get "big-bad-danger" rescue nil
|
||||||
|
|
Loading…
Reference in a new issue