Overriding couchrest's database delete method to ensure design cache is deleted

This commit is contained in:
Sam Lown 2011-05-19 00:37:17 +02:00
parent 9754f4633c
commit fba1e53e20
5 changed files with 19 additions and 2 deletions

View file

@ -8,6 +8,7 @@
* 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

View file

@ -108,8 +108,6 @@ module CouchRest
}
end
end # module ClassMethods
end

View 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

View file

@ -51,6 +51,7 @@ require "couchrest/model/designs/view"
# Monkey patches applied to couchrest
require "couchrest/model/support/couchrest_design"
require "couchrest/model/support/couchrest_database"
# Core Extensions
require "couchrest/model/core_extensions/hash"

View file

@ -155,6 +155,10 @@ describe "Design Documents" do
Article.by_date
Article.stored_design_doc['_rev'].should eql(orig)
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
describe "when auto_update_design_doc false" do