Merge branch 'mattetti/master'

This commit is contained in:
Peter Gumeson 2009-05-28 11:30:15 -07:00
commit 4a4cae0d95
12 changed files with 30 additions and 29 deletions

View file

@ -2,7 +2,7 @@
Gem::Specification.new do |s| Gem::Specification.new do |s|
s.name = %q{couchrest} 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.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["J. Chris Anderson", "Matt Aimonetti"] s.authors = ["J. Chris Anderson", "Matt Aimonetti"]

View file

@ -28,7 +28,7 @@ require 'couchrest/monkeypatches'
# = CouchDB, close to the metal # = CouchDB, close to the metal
module CouchRest module CouchRest
VERSION = '0.27' unless self.const_defined?("VERSION") VERSION = '0.28' unless self.const_defined?("VERSION")
autoload :Server, 'couchrest/core/server' autoload :Server, 'couchrest/core/server'
autoload :Database, 'couchrest/core/database' autoload :Database, 'couchrest/core/database'

View file

@ -271,11 +271,16 @@ module CouchRest
# DELETE the database itself. This is not undoable and could be rather # DELETE the database itself. This is not undoable and could be rather
# catastrophic. Use with care! # catastrophic. Use with care!
def delete! def delete!
clear_extended_doc_fresh_cache
CouchRest.delete @uri CouchRest.delete @uri
end end
private 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) def uri_for_attachment(doc, name)
if doc.is_a?(String) if doc.is_a?(String)
puts "CouchRest::Database#fetch_attachment will eventually require a doc as the first argument, not a doc.id" puts "CouchRest::Database#fetch_attachment will eventually require a doc as the first argument, not a doc.id"

View file

@ -1,6 +1,7 @@
require 'mime/types' require 'mime/types'
require File.join(File.dirname(__FILE__), "property") require File.join(File.dirname(__FILE__), "property")
require File.join(File.dirname(__FILE__), '..', 'mixins', 'extended_document_mixins') require File.join(File.dirname(__FILE__), '..', 'mixins', 'extended_document_mixins')
require "enumerator"
module CouchRest module CouchRest
@ -12,6 +13,11 @@ module CouchRest
include CouchRest::Mixins::DesignDoc include CouchRest::Mixins::DesignDoc
include CouchRest::Mixins::ExtendedAttachments include CouchRest::Mixins::ExtendedAttachments
include CouchRest::Mixins::ClassProxy 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) def self.inherited(subklass)
subklass.send(:include, CouchRest::Mixins::Properties) subklass.send(:include, CouchRest::Mixins::Properties)
@ -20,6 +26,7 @@ module CouchRest
subklass.properties = self.properties.dup subklass.properties = self.properties.dup
end end
EOS EOS
subclasses << subklass
end end
# Accessors # Accessors
@ -45,6 +52,8 @@ module CouchRest
end end
end 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

View file

@ -66,7 +66,6 @@ describe "ExtendedDocument views" do
end end
end end
it "should make the design doc upon first query" do it "should make the design doc upon first query" do
Course.design_doc_fresh = false
Course.by_title Course.by_title
doc = Course.design_doc doc = Course.design_doc
doc['views']['all']['map'].should include('Course') doc['views']['all']['map'].should include('Course')
@ -74,13 +73,11 @@ describe "ExtendedDocument views" do
it "should can query via view" do it "should can query via view" do
# register methods with method-missing, for local dispatch. method # register methods with method-missing, for local dispatch. method
# missing lookup table, no heuristics. # missing lookup table, no heuristics.
Course.design_doc_fresh = false
view = Course.view :by_title view = Course.view :by_title
designed = Course.by_title designed = Course.by_title
view.should == designed view.should == designed
end end
it "should get them" do it "should get them" do
Course.design_doc_fresh = false
rs = Course.by_title rs = Course.by_title
rs.length.should == 4 rs.length.should == 4
end end
@ -104,20 +101,18 @@ describe "ExtendedDocument views" do
describe "a ducktype view" do describe "a ducktype view" do
before(:all) do before(:all) do
reset_test_db! reset_test_db!
@id = TEST_SERVER.default_database.save_doc({:dept => true})['id'] @id = DB.save_doc({:dept => true})['id']
end end
it "should setup" do it "should setup" do
duck = Course.get(@id) # from a different db duck = Course.get(@id) # from a different db
duck["dept"].should == true duck["dept"].should == true
end end
it "should make the design doc" do it "should make the design doc" do
Course.design_doc_fresh = false
@as = Course.by_dept @as = Course.by_dept
@doc = Course.design_doc @doc = Course.design_doc
@doc["views"]["by_dept"]["map"].should_not include("couchrest") @doc["views"]["by_dept"]["map"].should_not include("couchrest")
end end
it "should not look for class" do it "should not look for class" do
Course.design_doc_fresh = false
@as = Course.by_dept @as = Course.by_dept
@as[0]['_id'].should == @id @as[0]['_id'].should == @id
end end
@ -126,7 +121,7 @@ describe "ExtendedDocument views" do
describe "a model class not tied to a database" do describe "a model class not tied to a database" do
before(:all) do before(:all) do
reset_test_db! reset_test_db!
@db = TEST_SERVER.default_database @db = DB
%w{aaa bbb ddd eee}.each do |title| %w{aaa bbb ddd eee}.each do |title|
u = Unattached.new(:title => title) u = Unattached.new(:title => title)
u.database = @db u.database = @db
@ -191,7 +186,7 @@ describe "ExtendedDocument views" do
end end
it "should be able to cleanup the db/bump the revision number" do 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 # 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.view_by :questions
Unattached.by_questions(:database => @db) Unattached.by_questions(:database => @db)
original_revision = Unattached.model_design_doc(@db)['_rev'] original_revision = Unattached.model_design_doc(@db)['_rev']
@ -204,8 +199,8 @@ describe "ExtendedDocument views" do
before(:all) do before(:all) do
reset_test_db! reset_test_db!
# setup the class default doc to save the design doc # setup the class default doc to save the design doc
Unattached.use_database TEST_SERVER.default_database Unattached.use_database DB
@us = Unattached.on(TEST_SERVER.default_database) @us = Unattached.on(DB)
%w{aaa bbb ddd eee}.each do |title| %w{aaa bbb ddd eee}.each do |title|
u = @us.new(:title => title) u = @us.new(:title => title)
u.save u.save
@ -213,12 +208,10 @@ describe "ExtendedDocument views" do
end end
end end
it "should query all" do it "should query all" do
Unattached.design_doc_fresh = false
rs = @us.all rs = @us.all
rs.length.should == 4 rs.length.should == 4
end end
it "should make the design doc upon first query" do it "should make the design doc upon first query" do
Unattached.design_doc_fresh = false
@us.by_title @us.by_title
doc = @us.design_doc doc = @us.design_doc
doc['views']['all']['map'].should include('Unattached') doc['views']['all']['map'].should include('Unattached')
@ -265,7 +258,6 @@ describe "ExtendedDocument views" do
describe "a model with a compound key view" do describe "a model with a compound key view" do
before(:all) do before(:all) do
Article.design_doc_fresh = false
Article.by_user_id_and_date.each{|a| a.destroy(true)} Article.by_user_id_and_date.each{|a| a.destroy(true)}
Article.database.bulk_delete Article.database.bulk_delete
written_at = Time.now - 24 * 3600 * 7 written_at = Time.now - 24 * 3600 * 7
@ -309,19 +301,16 @@ describe "ExtendedDocument views" do
end end
end end
it "should be available raw" do it "should be available raw" do
Article.design_doc_fresh = false
view = Article.by_tags :raw => true view = Article.by_tags :raw => true
view['rows'].length.should == 5 view['rows'].length.should == 5
end end
it "should be default to :reduce => false" do it "should be default to :reduce => false" do
Article.design_doc_fresh = false
ars = Article.by_tags ars = Article.by_tags
ars.first.tags.first.should == 'cool' ars.first.tags.first.should == 'cool'
end end
it "should be raw when reduce is true" do it "should be raw when reduce is true" do
Article.design_doc_fresh = false
view = Article.by_tags :reduce => true, :group => true view = Article.by_tags :reduce => true, :group => true
view['rows'].find{|r|r['key'] == 'cool'}['value'].should == 3 view['rows'].find{|r|r['key'] == 'cool'}['value'].should == 3
end end
@ -331,7 +320,6 @@ describe "ExtendedDocument views" do
describe "adding a view" do describe "adding a view" do
before(:each) do before(:each) do
reset_test_db! reset_test_db!
Article.design_doc_fresh = false
Article.by_date Article.by_date
@original_doc_rev = Article.model_design_doc['_rev'] @original_doc_rev = Article.model_design_doc['_rev']
@design_docs = Article.database.documents :startkey => "_design/", :endkey => "_design/\u9999" @design_docs = Article.database.documents :startkey => "_design/", :endkey => "_design/\u9999"

View file

@ -1,5 +1,5 @@
class Article < CouchRest::ExtendedDocument class Article < CouchRest::ExtendedDocument
use_database TEST_SERVER.default_database use_database DB
unique_id :slug unique_id :slug
view_by :date, :descending => true view_by :date, :descending => true

View file

@ -5,7 +5,7 @@ class Card < CouchRest::ExtendedDocument
auto_validate! auto_validate!
# Set the default database to use # Set the default database to use
use_database TEST_SERVER.default_database use_database DB
# Official Schema # Official Schema
property :first_name property :first_name

View file

@ -2,7 +2,7 @@ class Cat < CouchRest::ExtendedDocument
include ::CouchRest::Validation include ::CouchRest::Validation
# Set the default database to use # Set the default database to use
use_database TEST_SERVER.default_database use_database DB
property :name property :name
property :toys, :cast_as => ['CatToy'], :default => [] property :toys, :cast_as => ['CatToy'], :default => []

View file

@ -1,5 +1,5 @@
class Event < CouchRest::ExtendedDocument class Event < CouchRest::ExtendedDocument
use_database TEST_SERVER.default_database use_database DB
property :subject property :subject
property :occurs_at, :cast_as => 'Time', :send => 'parse' property :occurs_at, :cast_as => 'Time', :send => 'parse'

View file

@ -3,7 +3,7 @@ class Invoice < CouchRest::ExtendedDocument
include CouchRest::Validation include CouchRest::Validation
# Set the default database to use # Set the default database to use
use_database TEST_SERVER.default_database use_database DB
# Official Schema # Official Schema
property :client_name property :client_name

View file

@ -3,7 +3,7 @@ class Service < CouchRest::ExtendedDocument
include CouchRest::Validation include CouchRest::Validation
auto_validate! auto_validate!
# Set the default database to use # Set the default database to use
use_database TEST_SERVER.default_database use_database DB
# Official Schema # Official Schema
property :name, :length => 4...20 property :name, :length => 4...20

View file

@ -12,6 +12,7 @@ unless defined?(FIXTURE_PATH)
TESTDB = 'couchrest-test' TESTDB = 'couchrest-test'
TEST_SERVER = CouchRest.new TEST_SERVER = CouchRest.new
TEST_SERVER.default_database = TESTDB TEST_SERVER.default_database = TESTDB
DB = TEST_SERVER.database(TESTDB)
end end
class Basic < CouchRest::ExtendedDocument class Basic < CouchRest::ExtendedDocument
@ -19,10 +20,8 @@ class Basic < CouchRest::ExtendedDocument
end end
def reset_test_db! def reset_test_db!
cr = TEST_SERVER DB.recreate! rescue nil
db = cr.database(TESTDB) DB
db.recreate! rescue nil
db
end end
Spec::Runner.configure do |config| Spec::Runner.configure do |config|