Overriding couchrest's database delete method to ensure design cache is deleted
This commit is contained in:
parent
9754f4633c
commit
fba1e53e20
5 changed files with 19 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -108,8 +108,6 @@ module CouchRest
|
|||
}
|
||||
end
|
||||
|
||||
|
||||
|
||||
end # module ClassMethods
|
||||
|
||||
end
|
||||
|
|
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
|
||||
require "couchrest/model/support/couchrest_design"
|
||||
require "couchrest/model/support/couchrest_database"
|
||||
|
||||
# Core Extensions
|
||||
require "couchrest/model/core_extensions/hash"
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue