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|
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"]

View file

@ -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'

View file

@ -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"

View file

@ -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
@ -13,6 +14,11 @@ module CouchRest
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)
subklass.class_eval <<-EOS, __FILE__, __LINE__
@ -20,6 +26,7 @@ module CouchRest
subklass.properties = self.properties.dup
end
EOS
subclasses << subklass
end
# Accessors
@ -46,6 +53,8 @@ module CouchRest
end
# Automatically set <tt>updated_at</tt> and <tt>created_at</tt> fields
# on the document whenever saving occurs. CouchRest uses a pretty
# decent time format by default. See Time#to_json

View file

@ -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"

View file

@ -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

View file

@ -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

View file

@ -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 => []

View file

@ -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'

View file

@ -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

View file

@ -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

View file

@ -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|