diff --git a/couchrest.gemspec b/couchrest.gemspec
index db09d15..043f1a6 100644
--- a/couchrest.gemspec
+++ b/couchrest.gemspec
@@ -2,7 +2,7 @@
Gem::Specification.new do |s|
s.name = %q{couchrest}
- s.version = "0.27"
+ s.version = "0.28"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["J. Chris Anderson", "Matt Aimonetti"]
diff --git a/lib/couchrest.rb b/lib/couchrest.rb
index af0b83c..a05b1ae 100644
--- a/lib/couchrest.rb
+++ b/lib/couchrest.rb
@@ -28,7 +28,7 @@ require 'couchrest/monkeypatches'
# = CouchDB, close to the metal
module CouchRest
- VERSION = '0.27' unless self.const_defined?("VERSION")
+ VERSION = '0.28' unless self.const_defined?("VERSION")
autoload :Server, 'couchrest/core/server'
autoload :Database, 'couchrest/core/database'
diff --git a/lib/couchrest/core/database.rb b/lib/couchrest/core/database.rb
index ed97127..8c43917 100644
--- a/lib/couchrest/core/database.rb
+++ b/lib/couchrest/core/database.rb
@@ -271,11 +271,16 @@ module CouchRest
# DELETE the database itself. This is not undoable and could be rather
# catastrophic. Use with care!
def delete!
+ clear_extended_doc_fresh_cache
CouchRest.delete @uri
end
private
+ def clear_extended_doc_fresh_cache
+ ::CouchRest::ExtendedDocument.subclasses.each{|klass| klass.design_doc_fresh = false if klass.respond_to?(:design_doc_fresh=) }
+ end
+
def uri_for_attachment(doc, name)
if doc.is_a?(String)
puts "CouchRest::Database#fetch_attachment will eventually require a doc as the first argument, not a doc.id"
diff --git a/lib/couchrest/more/extended_document.rb b/lib/couchrest/more/extended_document.rb
index 661330c..4d08db5 100644
--- a/lib/couchrest/more/extended_document.rb
+++ b/lib/couchrest/more/extended_document.rb
@@ -1,6 +1,7 @@
require 'mime/types'
require File.join(File.dirname(__FILE__), "property")
require File.join(File.dirname(__FILE__), '..', 'mixins', 'extended_document_mixins')
+require "enumerator"
module CouchRest
@@ -12,6 +13,11 @@ module CouchRest
include CouchRest::Mixins::DesignDoc
include CouchRest::Mixins::ExtendedAttachments
include CouchRest::Mixins::ClassProxy
+
+ def self.subclasses
+ @subclasses ||= []
+ # ObjectSpace.enum_for(:each_object, class << self; self; end).to_a.delete_if{|k| k == self}
+ end
def self.inherited(subklass)
subklass.send(:include, CouchRest::Mixins::Properties)
@@ -20,6 +26,7 @@ module CouchRest
subklass.properties = self.properties.dup
end
EOS
+ subclasses << subklass
end
# Accessors
@@ -45,6 +52,8 @@ module CouchRest
end
end
+
+
# Automatically set updated_at and created_at fields
# on the document whenever saving occurs. CouchRest uses a pretty
diff --git a/spec/couchrest/more/extended_doc_view_spec.rb b/spec/couchrest/more/extended_doc_view_spec.rb
index 5b60aeb..4d797e5 100644
--- a/spec/couchrest/more/extended_doc_view_spec.rb
+++ b/spec/couchrest/more/extended_doc_view_spec.rb
@@ -66,7 +66,6 @@ describe "ExtendedDocument views" do
end
end
it "should make the design doc upon first query" do
- Course.design_doc_fresh = false
Course.by_title
doc = Course.design_doc
doc['views']['all']['map'].should include('Course')
@@ -74,13 +73,11 @@ describe "ExtendedDocument views" do
it "should can query via view" do
# register methods with method-missing, for local dispatch. method
# missing lookup table, no heuristics.
- Course.design_doc_fresh = false
view = Course.view :by_title
designed = Course.by_title
view.should == designed
end
it "should get them" do
- Course.design_doc_fresh = false
rs = Course.by_title
rs.length.should == 4
end
@@ -104,20 +101,18 @@ describe "ExtendedDocument views" do
describe "a ducktype view" do
before(:all) do
reset_test_db!
- @id = TEST_SERVER.default_database.save_doc({:dept => true})['id']
+ @id = DB.save_doc({:dept => true})['id']
end
it "should setup" do
duck = Course.get(@id) # from a different db
duck["dept"].should == true
end
it "should make the design doc" do
- Course.design_doc_fresh = false
@as = Course.by_dept
@doc = Course.design_doc
@doc["views"]["by_dept"]["map"].should_not include("couchrest")
end
it "should not look for class" do
- Course.design_doc_fresh = false
@as = Course.by_dept
@as[0]['_id'].should == @id
end
@@ -126,7 +121,7 @@ describe "ExtendedDocument views" do
describe "a model class not tied to a database" do
before(:all) do
reset_test_db!
- @db = TEST_SERVER.default_database
+ @db = DB
%w{aaa bbb ddd eee}.each do |title|
u = Unattached.new(:title => title)
u.database = @db
@@ -191,7 +186,7 @@ describe "ExtendedDocument views" do
end
it "should be able to cleanup the db/bump the revision number" do
# if the previous specs were not run, the model_design_doc will be blank
- Unattached.use_database TEST_SERVER.default_database
+ Unattached.use_database DB
Unattached.view_by :questions
Unattached.by_questions(:database => @db)
original_revision = Unattached.model_design_doc(@db)['_rev']
@@ -204,8 +199,8 @@ describe "ExtendedDocument views" do
before(:all) do
reset_test_db!
# setup the class default doc to save the design doc
- Unattached.use_database TEST_SERVER.default_database
- @us = Unattached.on(TEST_SERVER.default_database)
+ Unattached.use_database DB
+ @us = Unattached.on(DB)
%w{aaa bbb ddd eee}.each do |title|
u = @us.new(:title => title)
u.save
@@ -213,12 +208,10 @@ describe "ExtendedDocument views" do
end
end
it "should query all" do
- Unattached.design_doc_fresh = false
rs = @us.all
rs.length.should == 4
end
it "should make the design doc upon first query" do
- Unattached.design_doc_fresh = false
@us.by_title
doc = @us.design_doc
doc['views']['all']['map'].should include('Unattached')
@@ -265,7 +258,6 @@ describe "ExtendedDocument views" do
describe "a model with a compound key view" do
before(:all) do
- Article.design_doc_fresh = false
Article.by_user_id_and_date.each{|a| a.destroy(true)}
Article.database.bulk_delete
written_at = Time.now - 24 * 3600 * 7
@@ -309,19 +301,16 @@ describe "ExtendedDocument views" do
end
end
it "should be available raw" do
- Article.design_doc_fresh = false
view = Article.by_tags :raw => true
view['rows'].length.should == 5
end
it "should be default to :reduce => false" do
- Article.design_doc_fresh = false
ars = Article.by_tags
ars.first.tags.first.should == 'cool'
end
it "should be raw when reduce is true" do
- Article.design_doc_fresh = false
view = Article.by_tags :reduce => true, :group => true
view['rows'].find{|r|r['key'] == 'cool'}['value'].should == 3
end
@@ -331,7 +320,6 @@ describe "ExtendedDocument views" do
describe "adding a view" do
before(:each) do
reset_test_db!
- Article.design_doc_fresh = false
Article.by_date
@original_doc_rev = Article.model_design_doc['_rev']
@design_docs = Article.database.documents :startkey => "_design/", :endkey => "_design/\u9999"
diff --git a/spec/fixtures/more/article.rb b/spec/fixtures/more/article.rb
index 02b7944..e0a6393 100644
--- a/spec/fixtures/more/article.rb
+++ b/spec/fixtures/more/article.rb
@@ -1,5 +1,5 @@
class Article < CouchRest::ExtendedDocument
- use_database TEST_SERVER.default_database
+ use_database DB
unique_id :slug
view_by :date, :descending => true
diff --git a/spec/fixtures/more/card.rb b/spec/fixtures/more/card.rb
index 46307ad..2562c9d 100644
--- a/spec/fixtures/more/card.rb
+++ b/spec/fixtures/more/card.rb
@@ -5,7 +5,7 @@ class Card < CouchRest::ExtendedDocument
auto_validate!
# Set the default database to use
- use_database TEST_SERVER.default_database
+ use_database DB
# Official Schema
property :first_name
diff --git a/spec/fixtures/more/cat.rb b/spec/fixtures/more/cat.rb
index f53a2a2..54abad5 100644
--- a/spec/fixtures/more/cat.rb
+++ b/spec/fixtures/more/cat.rb
@@ -2,7 +2,7 @@ class Cat < CouchRest::ExtendedDocument
include ::CouchRest::Validation
# Set the default database to use
- use_database TEST_SERVER.default_database
+ use_database DB
property :name
property :toys, :cast_as => ['CatToy'], :default => []
diff --git a/spec/fixtures/more/event.rb b/spec/fixtures/more/event.rb
index c36527a..221865e 100644
--- a/spec/fixtures/more/event.rb
+++ b/spec/fixtures/more/event.rb
@@ -1,5 +1,5 @@
class Event < CouchRest::ExtendedDocument
- use_database TEST_SERVER.default_database
+ use_database DB
property :subject
property :occurs_at, :cast_as => 'Time', :send => 'parse'
diff --git a/spec/fixtures/more/invoice.rb b/spec/fixtures/more/invoice.rb
index f308f7c..273e6f2 100644
--- a/spec/fixtures/more/invoice.rb
+++ b/spec/fixtures/more/invoice.rb
@@ -3,7 +3,7 @@ class Invoice < CouchRest::ExtendedDocument
include CouchRest::Validation
# Set the default database to use
- use_database TEST_SERVER.default_database
+ use_database DB
# Official Schema
property :client_name
diff --git a/spec/fixtures/more/service.rb b/spec/fixtures/more/service.rb
index ea54a7a..6ecf276 100644
--- a/spec/fixtures/more/service.rb
+++ b/spec/fixtures/more/service.rb
@@ -3,7 +3,7 @@ class Service < CouchRest::ExtendedDocument
include CouchRest::Validation
auto_validate!
# Set the default database to use
- use_database TEST_SERVER.default_database
+ use_database DB
# Official Schema
property :name, :length => 4...20
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 7e6800a..cafdcc5 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -12,6 +12,7 @@ unless defined?(FIXTURE_PATH)
TESTDB = 'couchrest-test'
TEST_SERVER = CouchRest.new
TEST_SERVER.default_database = TESTDB
+ DB = TEST_SERVER.database(TESTDB)
end
class Basic < CouchRest::ExtendedDocument
@@ -19,10 +20,8 @@ class Basic < CouchRest::ExtendedDocument
end
def reset_test_db!
- cr = TEST_SERVER
- db = cr.database(TESTDB)
- db.recreate! rescue nil
- db
+ DB.recreate! rescue nil
+ DB
end
Spec::Runner.configure do |config|