fixed the uuid count for the latest version of couchdb

also avoided CONSTANTS warnings, cleaned up the attachment specs, added missing fixtures
This commit is contained in:
Matt Aimonetti 2009-02-25 00:22:11 -08:00
parent fe489f2d38
commit 80317f31a5
13 changed files with 106 additions and 35 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.15" s.version = "0.16"
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

@ -27,13 +27,13 @@ require 'couchrest/monkeypatches'
# = CouchDB, close to the metal # = CouchDB, close to the metal
module CouchRest module CouchRest
VERSION = '0.15' VERSION = '0.16' 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'
autoload :Response, 'couchrest/core/response' autoload :Response, 'couchrest/core/response'
autoload :Document, 'couchrest/core/document' autoload :Document, 'couchrest/core/document'
autoload :Design, 'couchrest/core/design' autoload :Design, 'couchrest/core/design'
autoload :View, 'couchrest/core/view' autoload :View, 'couchrest/core/view'
autoload :Model, 'couchrest/core/model' autoload :Model, 'couchrest/core/model'
autoload :Pager, 'couchrest/helper/pager' autoload :Pager, 'couchrest/helper/pager'

View file

@ -79,7 +79,7 @@ module CouchRest
def next_uuid(count = @uuid_batch_count) def next_uuid(count = @uuid_batch_count)
@uuids ||= [] @uuids ||= []
if @uuids.empty? if @uuids.empty?
@uuids = CouchRest.post("#{@uri}/_uuids?count=#{count}")["uuids"] @uuids = CouchRest.get("#{@uri}/_uuids?count=#{count}")["uuids"]
end end
@uuids.pop @uuids.pop
end end

View file

@ -325,7 +325,7 @@ module CouchRest
end end
module ClassMethods module ClassMethods
CHAINS = {:before => :before, :around => :before, :after => :after} CHAINS = {:before => :before, :around => :before, :after => :after} unless self.const_defined?("CHAINS")
# Make the _run_save_callbacks method. The generated method takes # Make the _run_save_callbacks method. The generated method takes
# a block that it'll yield to. It'll call the before and around filters # a block that it'll yield to. It'll call the before and around filters

View file

@ -14,7 +14,7 @@ module CouchRest
# reads the data from an attachment # reads the data from an attachment
def read_attachment(attachment_name) def read_attachment(attachment_name)
Base64.decode64(database.fetch_attachment(self.id, attachment_name)) Base64.decode64(database.fetch_attachment(self, attachment_name))
end end
# modifies a file attachment on the current doc # modifies a file attachment on the current doc

View file

@ -1,4 +1,5 @@
begin begin
# still required for Time parsing and pluralization in the validation
require 'extlib' require 'extlib'
rescue rescue
puts "CouchRest::ExtendedDocument still requires extlib (not for much longer). This is left out of the gemspec on purpose." puts "CouchRest::ExtendedDocument still requires extlib (not for much longer). This is left out of the gemspec on purpose."

View file

@ -247,9 +247,11 @@ describe CouchRest::Database do
@db.save_doc(@doc) @db.save_doc(@doc)
end end
it "should get the attachment with the doc's _id" do # Depreacated
@db.fetch_attachment("mydocwithattachment", "test.html").should == @attach # it "should get the attachment with the doc's _id" do
end # @db.fetch_attachment("mydocwithattachment", "test.html").should == @attach
# end
it "should get the attachment with the doc itself" do it "should get the attachment with the doc itself" do
@db.fetch_attachment(@db.get('mydocwithattachment'), 'test.html').should == @attach @db.fetch_attachment(@db.get('mydocwithattachment'), 'test.html').should == @attach
end end
@ -266,7 +268,8 @@ describe CouchRest::Database do
it "should save the attachment to a new doc" do it "should save the attachment to a new doc" do
r = @db.put_attachment({'_id' => 'attach-this'}, 'couchdb.png', image = @file.read, {:content_type => 'image/png'}) r = @db.put_attachment({'_id' => 'attach-this'}, 'couchdb.png', image = @file.read, {:content_type => 'image/png'})
r['ok'].should == true r['ok'].should == true
attachment = @db.fetch_attachment("attach-this","couchdb.png") doc = @db.get("attach-this")
attachment = @db.fetch_attachment(doc,"couchdb.png")
attachment.should == image attachment.should == image
end end
end end
@ -274,7 +277,7 @@ describe CouchRest::Database do
describe "PUT document with attachment" do describe "PUT document with attachment" do
before(:each) do before(:each) do
@attach = "<html><head><title>My Doc</title></head><body><p>Has words.</p></body></html>" @attach = "<html><head><title>My Doc</title></head><body><p>Has words.</p></body></html>"
@doc = { doc = {
"_id" => "mydocwithattachment", "_id" => "mydocwithattachment",
"field" => ["some value"], "field" => ["some value"],
"_attachments" => { "_attachments" => {
@ -284,14 +287,14 @@ describe CouchRest::Database do
} }
} }
} }
@db.save_doc(@doc) @db.save_doc(doc)
@doc = @db.get("mydocwithattachment")
end end
it "should save and be indicated" do it "should save and be indicated" do
doc = @db.get("mydocwithattachment") @doc['_attachments']['test.html']['length'].should == @attach.length
doc['_attachments']['test.html']['length'].should == @attach.length
end end
it "should be there" do it "should be there" do
attachment = @db.fetch_attachment("mydocwithattachment","test.html") attachment = @db.fetch_attachment(@doc,"test.html")
attachment.should == @attach attachment.should == @attach
end end
end end
@ -309,14 +312,14 @@ describe CouchRest::Database do
} }
} }
@db.save_doc(doc) @db.save_doc(doc)
doc = @db.get('mydocwithattachment')
doc['field'] << 'another value' doc['field'] << 'another value'
@db.save_doc(doc) @db.save_doc(doc).should be_true
end end
it 'should be there' do it 'should be there' do
attachment = @db.fetch_attachment('mydocwithattachment', 'test.html') doc = @db.get('mydocwithattachment')
attachment.should == @attach attachment = @db.fetch_attachment(doc, 'test.html')
Base64.decode64(attachment).should == @attach
end end
end end
@ -339,18 +342,18 @@ describe CouchRest::Database do
} }
} }
@db.save_doc(@doc) @db.save_doc(@doc)
@doc = @db.get("mydocwithattachment")
end end
it "should save and be indicated" do it "should save and be indicated" do
doc = @db.get("mydocwithattachment") @doc['_attachments']['test.html']['length'].should == @attach.length
doc['_attachments']['test.html']['length'].should == @attach.length @doc['_attachments']['other.html']['length'].should == @attach2.length
doc['_attachments']['other.html']['length'].should == @attach2.length
end end
it "should be there" do it "should be there" do
attachment = @db.fetch_attachment("mydocwithattachment","test.html") attachment = @db.fetch_attachment(@doc,"test.html")
attachment.should == @attach attachment.should == @attach
end end
it "should be there" do it "should be there" do
attachment = @db.fetch_attachment("mydocwithattachment","other.html") attachment = @db.fetch_attachment(@doc,"other.html")
attachment.should == @attach2 attachment.should == @attach2
end end
end end
@ -370,9 +373,9 @@ describe CouchRest::Database do
@doc = @db.get('mydocwithattachment') @doc = @db.get('mydocwithattachment')
end end
it "should delete the attachment" do it "should delete the attachment" do
lambda { @db.fetch_attachment('mydocwithattachment','test.html') }.should_not raise_error lambda { @db.fetch_attachment(@doc,'test.html') }.should_not raise_error
@db.delete_attachment(@doc, "test.html") @db.delete_attachment(@doc, "test.html")
lambda { @db.fetch_attachment('mydocwithattachment','test.html') }.should raise_error(RestClient::ResourceNotFound) lambda { @db.fetch_attachment(@doc,'test.html') }.should raise_error(RestClient::ResourceNotFound)
end end
end end
@ -395,7 +398,8 @@ describe CouchRest::Database do
doc['_attachments']['http://example.com/stuff.cgi?things=and%20stuff']['length'].should == @attach.length doc['_attachments']['http://example.com/stuff.cgi?things=and%20stuff']['length'].should == @attach.length
end end
it "should be there" do it "should be there" do
attachment = @db.fetch_attachment(@docid,"http://example.com/stuff.cgi?things=and%20stuff") doc = @db.get(@docid)
attachment = @db.fetch_attachment(doc,"http://example.com/stuff.cgi?things=and%20stuff")
attachment.should == @attach attachment.should == @attach
end end
end end
@ -737,4 +741,4 @@ describe CouchRest::Database do
end end
end end

View file

@ -439,12 +439,10 @@ describe "ExtendedDocument" do
result.should == true result.should == true
end end
it "should be resavable" do it "should be resavable" do
pending "TO FIX" do @dobj.destroy
@dobj.destroy @dobj.rev.should be_nil
@dobj.rev.should be_nil @dobj.id.should be_nil
@dobj.id.should be_nil @dobj.save.should == true
@dobj.save.should == true
end
end end
it "should make it go away" do it "should make it go away" do
@dobj.destroy @dobj.destroy

34
spec/fixtures/more/article.rb vendored Normal file
View file

@ -0,0 +1,34 @@
class Article < CouchRest::ExtendedDocument
use_database TEST_SERVER.default_database
unique_id :slug
view_by :date, :descending => true
view_by :user_id, :date
view_by :tags,
:map =>
"function(doc) {
if (doc['couchrest-type'] == 'Article' && doc.tags) {
doc.tags.forEach(function(tag){
emit(tag, 1);
});
}
}",
:reduce =>
"function(keys, values, rereduce) {
return sum(values);
}"
property :date
property :slug, :read_only => true
property :title
property :tags
timestamps!
save_callback :before, :generate_slug_from_title
def generate_slug_from_title
self['slug'] = title.downcase.gsub(/[^a-z0-9]/,'-').squeeze('-').gsub(/^\-|\-$/,'') if new_document?
end
end

14
spec/fixtures/more/course.rb vendored Normal file
View file

@ -0,0 +1,14 @@
require File.join(FIXTURE_PATH, 'more', 'question')
require File.join(FIXTURE_PATH, 'more', 'person')
class Course < CouchRest::ExtendedDocument
use_database TEST_SERVER.default_database
property :title
property :questions, :cast_as => ['Question']
property :professor, :cast_as => 'Person'
property :final_test_at, :cast_as => 'Time'
view_by :title
view_by :dept, :ducktype => true
end

6
spec/fixtures/more/event.rb vendored Normal file
View file

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

8
spec/fixtures/more/person.rb vendored Normal file
View file

@ -0,0 +1,8 @@
class Person < Hash
include ::CouchRest::CastedModel
property :name
def last_name
name.last
end
end

6
spec/fixtures/more/question.rb vendored Normal file
View file

@ -0,0 +1,6 @@
class Question < Hash
include ::CouchRest::CastedModel
property :q
property :a
end