Merge branch 'master' of git://github.com/couchrest/couchrest_model
This commit is contained in:
commit
a400d46333
11
history.md
11
history.md
|
@ -1,5 +1,16 @@
|
||||||
# CouchRest Model Change History
|
# CouchRest Model Change History
|
||||||
|
|
||||||
|
## 1.1.0 - 2011-05-XX
|
||||||
|
|
||||||
|
* Minor fixes
|
||||||
|
* #as_json now correctly uses ActiveSupports methods.
|
||||||
|
* nil properties are now no longer sent in the document body.
|
||||||
|
* Rails 3.1 support (Peter Williams)
|
||||||
|
* Initialization blocks when creating new models (Peter Williams)
|
||||||
|
* Removed railties dependency (DAddYE)
|
||||||
|
* DesignDoc cache refreshed if a database is deleted.
|
||||||
|
|
||||||
|
|
||||||
## 1.1.0.beta5 - 2011-04-30
|
## 1.1.0.beta5 - 2011-04-30
|
||||||
|
|
||||||
* Major changes:
|
* Major changes:
|
||||||
|
|
|
@ -108,8 +108,6 @@ module CouchRest
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
end # module ClassMethods
|
end # module ClassMethods
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -12,6 +12,9 @@ module CouchRest
|
||||||
raise "You can only mixin Properties in a class responding to [] and []=, if you tried to mixin CastedModel, make sure your class inherits from Hash or responds to the proper methods" unless (method_defined?(:[]) && method_defined?(:[]=))
|
raise "You can only mixin Properties in a class responding to [] and []=, if you tried to mixin CastedModel, make sure your class inherits from Hash or responds to the proper methods" unless (method_defined?(:[]) && method_defined?(:[]=))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def as_json(options = nil)
|
||||||
|
Hash[self].reject{|k,v| v.nil?}.as_json(options)
|
||||||
|
end
|
||||||
|
|
||||||
# Returns the Class properties with their values
|
# Returns the Class properties with their values
|
||||||
#
|
#
|
||||||
|
|
13
lib/couchrest/model/support/couchrest_database.rb
Normal file
13
lib/couchrest/model/support/couchrest_database.rb
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
#
|
||||||
|
# Extend CouchRest's normal database delete! method to ensure any caches are
|
||||||
|
# also emptied. Given that this is a rare event, and the consequences are not
|
||||||
|
# very severe, we just completely empty the cache.
|
||||||
|
#
|
||||||
|
CouchRest::Database.class_eval do
|
||||||
|
|
||||||
|
def delete!
|
||||||
|
Thread.current[:couchrest_design_cache] = { }
|
||||||
|
CouchRest.delete @root
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -51,6 +51,7 @@ require "couchrest/model/designs/view"
|
||||||
|
|
||||||
# Monkey patches applied to couchrest
|
# Monkey patches applied to couchrest
|
||||||
require "couchrest/model/support/couchrest_design"
|
require "couchrest/model/support/couchrest_design"
|
||||||
|
require "couchrest/model/support/couchrest_database"
|
||||||
|
|
||||||
# Core Extensions
|
# Core Extensions
|
||||||
require "couchrest/model/core_extensions/hash"
|
require "couchrest/model/core_extensions/hash"
|
||||||
|
|
|
@ -155,6 +155,10 @@ describe "Design Documents" do
|
||||||
Article.by_date
|
Article.by_date
|
||||||
Article.stored_design_doc['_rev'].should eql(orig)
|
Article.stored_design_doc['_rev'].should eql(orig)
|
||||||
end
|
end
|
||||||
|
it "should recreate the design doc if database deleted" do
|
||||||
|
Article.database.recreate!
|
||||||
|
lambda { Article.by_date }.should_not raise_error(RestClient::ResourceNotFound)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "when auto_update_design_doc false" do
|
describe "when auto_update_design_doc false" do
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
require File.expand_path('../../spec_helper', __FILE__)
|
require File.expand_path('../../spec_helper', __FILE__)
|
||||||
|
require File.join(FIXTURE_PATH, 'more', 'article')
|
||||||
require File.join(FIXTURE_PATH, 'more', 'cat')
|
require File.join(FIXTURE_PATH, 'more', 'cat')
|
||||||
require File.join(FIXTURE_PATH, 'more', 'person')
|
require File.join(FIXTURE_PATH, 'more', 'person')
|
||||||
require File.join(FIXTURE_PATH, 'more', 'card')
|
require File.join(FIXTURE_PATH, 'more', 'card')
|
||||||
|
@ -71,6 +72,24 @@ describe "Model properties" do
|
||||||
@card.updated_at.should_not be_nil
|
@card.updated_at.should_not be_nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#as_json" do
|
||||||
|
|
||||||
|
it "should provide a simple hash from model" do
|
||||||
|
@card.as_json.class.should eql(Hash)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should remove properties from Hash if value is nil" do
|
||||||
|
@card.last_name = nil
|
||||||
|
@card.as_json.keys.include?('last_name').should be_false
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should pass options to Active Support's as_json" do
|
||||||
|
@card.last_name = "Aimonetti"
|
||||||
|
@card.as_json(:only => 'last_name').should eql('last_name' => 'Aimonetti')
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
describe '#read_attribute' do
|
describe '#read_attribute' do
|
||||||
it "should let you use read_attribute method" do
|
it "should let you use read_attribute method" do
|
||||||
@card.last_name = "Aimonetti"
|
@card.last_name = "Aimonetti"
|
||||||
|
|
Loading…
Reference in a new issue