From 2aeb90721e27fc6e7a42fcdc2bb4714c17733b8f Mon Sep 17 00:00:00 2001 From: Matt Date: Sun, 8 Mar 2009 14:27:30 +0000 Subject: [PATCH 1/7] corrected some spec dependencies --- spec/couchrest/more/casted_model_spec.rb | 3 ++- spec/couchrest/more/extended_doc_attachment_spec.rb | 3 ++- spec/couchrest/more/extended_doc_view_spec.rb | 3 ++- spec/couchrest/more/property_spec.rb | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/spec/couchrest/more/casted_model_spec.rb b/spec/couchrest/more/casted_model_spec.rb index 880e0ee..a2b9216 100644 --- a/spec/couchrest/more/casted_model_spec.rb +++ b/spec/couchrest/more/casted_model_spec.rb @@ -70,6 +70,7 @@ describe CouchRest::CastedModel do describe "saved document with casted models" do before(:each) do + reset_test_db! @obj = DummyModel.new(:casted_attribute => {:name => 'whatever'}) @obj.save.should be_true @obj = DummyModel.get(@obj.id) @@ -94,4 +95,4 @@ describe CouchRest::CastedModel do end -end \ No newline at end of file +end diff --git a/spec/couchrest/more/extended_doc_attachment_spec.rb b/spec/couchrest/more/extended_doc_attachment_spec.rb index c75fc0c..a0213a6 100644 --- a/spec/couchrest/more/extended_doc_attachment_spec.rb +++ b/spec/couchrest/more/extended_doc_attachment_spec.rb @@ -4,6 +4,7 @@ describe "ExtendedDocument attachments" do describe "#has_attachment?" do before(:each) do + reset_test_db! @obj = Basic.new @obj.save.should == true @file = File.open(FIXTURE_PATH + '/attachments/test.html') @@ -126,4 +127,4 @@ describe "ExtendedDocument attachments" do @obj.attachment_url(@attachment_name).should == "#{Basic.database}/#{@obj.id}/#{@attachment_name}" end end -end \ No newline at end of file +end diff --git a/spec/couchrest/more/extended_doc_view_spec.rb b/spec/couchrest/more/extended_doc_view_spec.rb index 9045021..4a3e6ee 100644 --- a/spec/couchrest/more/extended_doc_view_spec.rb +++ b/spec/couchrest/more/extended_doc_view_spec.rb @@ -190,6 +190,7 @@ describe "ExtendedDocument views" do describe "with a lot of designs left around" do before(:each) do + reset_test_db! Article.by_date Article.view_by :field Article.by_field @@ -203,4 +204,4 @@ describe "ExtendedDocument views" do ddocs["rows"].length.should == 1 end end -end \ No newline at end of file +end diff --git a/spec/couchrest/more/property_spec.rb b/spec/couchrest/more/property_spec.rb index ec81d50..723c9ac 100644 --- a/spec/couchrest/more/property_spec.rb +++ b/spec/couchrest/more/property_spec.rb @@ -8,6 +8,7 @@ require File.join(FIXTURE_PATH, 'more', 'event') describe "ExtendedDocument properties" do before(:each) do + reset_test_db! @card = Card.new(:first_name => "matt") end @@ -126,4 +127,4 @@ describe "ExtendedDocument properties" do end end -end \ No newline at end of file +end From 7b03c7ba25856f0103bc4fe6a1c061cd6f4999cb Mon Sep 17 00:00:00 2001 From: Chris Anderson Date: Mon, 9 Mar 2009 13:12:28 -0700 Subject: [PATCH 2/7] fix for design doc url changes --- lib/couchrest/core/database.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/couchrest/core/database.rb b/lib/couchrest/core/database.rb index 067e885..f7bbfcc 100644 --- a/lib/couchrest/core/database.rb +++ b/lib/couchrest/core/database.rb @@ -61,12 +61,15 @@ module CouchRest # paramaters as described in http://wiki.apache.org/couchdb/HttpViewApi def view(name, params = {}, &block) keys = params.delete(:keys) - url = CouchRest.paramify_url "#{@uri}/_view/#{name}", params + name = name.split('/') # I think this will always be length == 2, but maybe not... + dname = name.shift + vname = name.join('/') + url = CouchRest.paramify_url "#{@uri}/_design/#{dname}/_view/#{vname}", params if keys CouchRest.post(url, {:keys => keys}) else if block_given? - @streamer.view(name, params, &block) + @streamer.view("_design/#{dname}/_view/#{vname}", params, &block) else CouchRest.get url end From 8964a9b28264a091008c94f71ef5a7b37845347a Mon Sep 17 00:00:00 2001 From: Chris Anderson Date: Sat, 14 Mar 2009 18:42:34 -0700 Subject: [PATCH 3/7] created upgrade helper --- lib/couchrest.rb | 1 + lib/couchrest/core/database.rb | 6 ++- lib/couchrest/helper/upgrade.rb | 72 +++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 lib/couchrest/helper/upgrade.rb diff --git a/lib/couchrest.rb b/lib/couchrest.rb index ae0c946..8524cb3 100644 --- a/lib/couchrest.rb +++ b/lib/couchrest.rb @@ -40,6 +40,7 @@ module CouchRest autoload :Pager, 'couchrest/helper/pager' autoload :FileManager, 'couchrest/helper/file_manager' autoload :Streamer, 'couchrest/helper/streamer' + autoload :Upgrade, 'couchrest/helper/upgrade' autoload :ExtendedDocument, 'couchrest/more/extended_document' autoload :CastedModel, 'couchrest/more/casted_model' diff --git a/lib/couchrest/core/database.rb b/lib/couchrest/core/database.rb index f7bbfcc..e2ffcd0 100644 --- a/lib/couchrest/core/database.rb +++ b/lib/couchrest/core/database.rb @@ -77,9 +77,11 @@ module CouchRest end # GET a document from CouchDB, by id. Returns a Ruby Hash. - def get(id) + def get(id, params = {}) slug = escape_docid(id) - hash = CouchRest.get("#{@uri}/#{slug}") + url = CouchRest.paramify_url("#{@uri}/#{slug}", params) + puts url + hash = CouchRest.get(url) doc = if /^_design/ =~ hash["_id"] Design.new(hash) else diff --git a/lib/couchrest/helper/upgrade.rb b/lib/couchrest/helper/upgrade.rb new file mode 100644 index 0000000..436e514 --- /dev/null +++ b/lib/couchrest/helper/upgrade.rb @@ -0,0 +1,72 @@ +module CouchRest + class Upgrade + attr_accessor :olddb, :newdb, :dbname + def initialize dbname, old_couch, new_couch + @dbname = dbname + @olddb = old_couch.database dbname + @newdb = new_couch.database!(dbname) + @bulk_docs = [] + end + def clone! + puts "#{dbname} - #{olddb.info['doc_count']} docs" + streamer = CouchRest::Streamer.new(olddb) + streamer.view("_all_docs_by_seq") do |row| + load_doc_for_row(row) if row + maybe_flush_bulks + end + flush_bulks! + end + + private + + def maybe_flush_bulks + flush_bulks! if (@bulk_docs.length > 1000) + end + + def flush_bulks! + url = CouchRest.paramify_url "#{@newdb.uri}/_bulk_docs", {:all_or_nothing => true} + puts "posting bulk to #{url}" + puts @bulk_docs.collect{|b|b.id} + begin + CouchRest.post url, {:docs => @bulk_docs} + rescue Exception => e + puts e.response + end + end + + def load_doc_for_row(row) + if row["value"]["conflicts"] + puts "doc #{row["id"]} has conflicts #{row.inspect}" + # load the doc, and it's conflicts + load_conflicts_doc(row) + elsif row["value"]["deleted_conflicts"] + puts "doc #{row["id"]} has deleted conflicts" + elsif row["value"]["deleted"] + # puts "doc #{row["id"]} is deleted" + @bulk_docs << {"_id" => row["id"], "_deleted" => true} + else + load_normal_doc(row) + end + end + + def load_conflicts_doc(row) + results = @olddb.get(row["id"], {:open_revs => "all", :attachments => true}) + results.select{|r|r["ok"]}.each do |r| + doc = r["ok"] + doc.delete('_rev') + @bulk_docs << doc + end + end + + def load_normal_doc(row) + # puts row["id"] + doc = @olddb.get(row["id"], :attachments => true) + if /^_/.match(doc.id) && !/^_design/.match(doc.id) + puts "trimming invalid docid #{doc.id}" + doc["_id"] = doc.id.sub('_','') + end + doc.delete("_rev"); + @bulk_docs << doc + end + end +end From fbc21aacd96e91562d62c28d74b0e418df4a85e5 Mon Sep 17 00:00:00 2001 From: Chris Anderson Date: Sat, 14 Mar 2009 19:00:26 -0700 Subject: [PATCH 4/7] updater is simpler now that I learned about open_revs=all --- lib/couchrest/core/database.rb | 10 ++++---- lib/couchrest/helper/upgrade.rb | 41 ++++++++------------------------- 2 files changed, 15 insertions(+), 36 deletions(-) diff --git a/lib/couchrest/core/database.rb b/lib/couchrest/core/database.rb index e2ffcd0..82fba7d 100644 --- a/lib/couchrest/core/database.rb +++ b/lib/couchrest/core/database.rb @@ -80,12 +80,12 @@ module CouchRest def get(id, params = {}) slug = escape_docid(id) url = CouchRest.paramify_url("#{@uri}/#{slug}", params) - puts url - hash = CouchRest.get(url) - doc = if /^_design/ =~ hash["_id"] - Design.new(hash) + result = CouchRest.get(url) + return result unless result.is_a?(Hash) + doc = if /^_design/ =~ result["_id"] + Design.new(result) else - Document.new(hash) + Document.new(result) end doc.database = self doc diff --git a/lib/couchrest/helper/upgrade.rb b/lib/couchrest/helper/upgrade.rb index 436e514..3f8126f 100644 --- a/lib/couchrest/helper/upgrade.rb +++ b/lib/couchrest/helper/upgrade.rb @@ -11,7 +11,7 @@ module CouchRest puts "#{dbname} - #{olddb.info['doc_count']} docs" streamer = CouchRest::Streamer.new(olddb) streamer.view("_all_docs_by_seq") do |row| - load_doc_for_row(row) if row + load_row_docs(row) if row maybe_flush_bulks end flush_bulks! @@ -20,53 +20,32 @@ module CouchRest private def maybe_flush_bulks - flush_bulks! if (@bulk_docs.length > 1000) + flush_bulks! if (@bulk_docs.length > 99) end def flush_bulks! url = CouchRest.paramify_url "#{@newdb.uri}/_bulk_docs", {:all_or_nothing => true} - puts "posting bulk to #{url}" - puts @bulk_docs.collect{|b|b.id} + puts "posting #{@bulk_docs.length} bulk docs to #{url}" begin CouchRest.post url, {:docs => @bulk_docs} + @bulk_docs = [] rescue Exception => e puts e.response + raise e end end - def load_doc_for_row(row) - if row["value"]["conflicts"] - puts "doc #{row["id"]} has conflicts #{row.inspect}" - # load the doc, and it's conflicts - load_conflicts_doc(row) - elsif row["value"]["deleted_conflicts"] - puts "doc #{row["id"]} has deleted conflicts" - elsif row["value"]["deleted"] - # puts "doc #{row["id"]} is deleted" - @bulk_docs << {"_id" => row["id"], "_deleted" => true} - else - load_normal_doc(row) - end - end - - def load_conflicts_doc(row) + def load_row_docs(row) results = @olddb.get(row["id"], {:open_revs => "all", :attachments => true}) results.select{|r|r["ok"]}.each do |r| doc = r["ok"] + if /^_/.match(doc["_id"]) && !/^_design/.match(doc["_id"]) + puts "invalid docid #{doc["_id"]} -- trimming" + doc["_id"] = doc["_id"].sub('_','') + end doc.delete('_rev') @bulk_docs << doc end end - - def load_normal_doc(row) - # puts row["id"] - doc = @olddb.get(row["id"], :attachments => true) - if /^_/.match(doc.id) && !/^_design/.match(doc.id) - puts "trimming invalid docid #{doc.id}" - doc["_id"] = doc.id.sub('_','') - end - doc.delete("_rev"); - @bulk_docs << doc - end end end From 917157a0e7c1fa6e3279cb2dbfa87d3190523986 Mon Sep 17 00:00:00 2001 From: Chris Anderson Date: Sat, 14 Mar 2009 19:03:17 -0700 Subject: [PATCH 5/7] rev version and new gemspec --- couchrest.gemspec | 10 ++++------ lib/couchrest.rb | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/couchrest.gemspec b/couchrest.gemspec index 935c543..9e0384b 100644 --- a/couchrest.gemspec +++ b/couchrest.gemspec @@ -1,8 +1,6 @@ -# -*- encoding: utf-8 -*- - Gem::Specification.new do |s| s.name = %q{couchrest} - s.version = "0.2.1" + s.version = "0.2.2" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["J. Chris Anderson", "Matt Aimonetti"] @@ -10,18 +8,18 @@ Gem::Specification.new do |s| s.description = %q{CouchRest provides a simple interface on top of CouchDB's RESTful HTTP API, as well as including some utility scripts for managing views and attachments.} s.email = %q{jchris@apache.org} s.extra_rdoc_files = ["README.md", "LICENSE", "THANKS.md"] - s.files = ["LICENSE", "README.md", "Rakefile", "THANKS.md", "examples/model", "examples/model/example.rb", "examples/word_count", "examples/word_count/markov", "examples/word_count/views", "examples/word_count/views/books", "examples/word_count/views/books/chunked-map.js", "examples/word_count/views/books/united-map.js", "examples/word_count/views/markov", "examples/word_count/views/markov/chain-map.js", "examples/word_count/views/markov/chain-reduce.js", "examples/word_count/views/word_count", "examples/word_count/views/word_count/count-map.js", "examples/word_count/views/word_count/count-reduce.js", "examples/word_count/word_count.rb", "examples/word_count/word_count_query.rb", "examples/word_count/word_count_views.rb", "lib/couchrest", "lib/couchrest/commands", "lib/couchrest/commands/generate.rb", "lib/couchrest/commands/push.rb", "lib/couchrest/core", "lib/couchrest/core/database.rb", "lib/couchrest/core/design.rb", "lib/couchrest/core/document.rb", "lib/couchrest/core/response.rb", "lib/couchrest/core/server.rb", "lib/couchrest/core/view.rb", "lib/couchrest/helper", "lib/couchrest/helper/pager.rb", "lib/couchrest/helper/streamer.rb", "lib/couchrest/mixins", "lib/couchrest/mixins/attachments.rb", "lib/couchrest/mixins/callbacks.rb", "lib/couchrest/mixins/design_doc.rb", "lib/couchrest/mixins/document_queries.rb", "lib/couchrest/mixins/extended_attachments.rb", "lib/couchrest/mixins/extended_document_mixins.rb", "lib/couchrest/mixins/properties.rb", "lib/couchrest/mixins/validation.rb", "lib/couchrest/mixins/views.rb", "lib/couchrest/mixins.rb", "lib/couchrest/monkeypatches.rb", "lib/couchrest/more", "lib/couchrest/more/casted_model.rb", "lib/couchrest/more/extended_document.rb", "lib/couchrest/more/property.rb", "lib/couchrest/support", "lib/couchrest/support/blank.rb", "lib/couchrest/support/class.rb", "lib/couchrest/validation", "lib/couchrest/validation/auto_validate.rb", "lib/couchrest/validation/contextual_validators.rb", "lib/couchrest/validation/validation_errors.rb", "lib/couchrest/validation/validators", "lib/couchrest/validation/validators/absent_field_validator.rb", "lib/couchrest/validation/validators/confirmation_validator.rb", "lib/couchrest/validation/validators/format_validator.rb", "lib/couchrest/validation/validators/formats", "lib/couchrest/validation/validators/formats/email.rb", "lib/couchrest/validation/validators/formats/url.rb", "lib/couchrest/validation/validators/generic_validator.rb", "lib/couchrest/validation/validators/length_validator.rb", "lib/couchrest/validation/validators/method_validator.rb", "lib/couchrest/validation/validators/numeric_validator.rb", "lib/couchrest/validation/validators/required_field_validator.rb", "lib/couchrest.rb", "spec/couchrest", "spec/couchrest/core", "spec/couchrest/core/couchrest_spec.rb", "spec/couchrest/core/database_spec.rb", "spec/couchrest/core/design_spec.rb", "spec/couchrest/core/document_spec.rb", "spec/couchrest/core/server_spec.rb", "spec/couchrest/helpers", "spec/couchrest/helpers/pager_spec.rb", "spec/couchrest/helpers/streamer_spec.rb", "spec/couchrest/more", "spec/couchrest/more/casted_extended_doc_spec.rb", "spec/couchrest/more/casted_model_spec.rb", "spec/couchrest/more/extended_doc_attachment_spec.rb", "spec/couchrest/more/extended_doc_spec.rb", "spec/couchrest/more/extended_doc_view_spec.rb", "spec/couchrest/more/property_spec.rb", "spec/couchrest/support", "spec/couchrest/support/class_spec.rb", "spec/fixtures", "spec/fixtures/attachments", "spec/fixtures/attachments/couchdb.png", "spec/fixtures/attachments/README", "spec/fixtures/attachments/test.html", "spec/fixtures/couchapp", "spec/fixtures/couchapp/_attachments", "spec/fixtures/couchapp/_attachments/index.html", "spec/fixtures/couchapp/doc.json", "spec/fixtures/couchapp/foo", "spec/fixtures/couchapp/foo/bar.txt", "spec/fixtures/couchapp/foo/test.json", "spec/fixtures/couchapp/test.json", "spec/fixtures/couchapp/views", "spec/fixtures/couchapp/views/example-map.js", "spec/fixtures/couchapp/views/example-reduce.js", "spec/fixtures/couchapp-test", "spec/fixtures/couchapp-test/my-app", "spec/fixtures/couchapp-test/my-app/_attachments", "spec/fixtures/couchapp-test/my-app/_attachments/index.html", "spec/fixtures/couchapp-test/my-app/foo", "spec/fixtures/couchapp-test/my-app/foo/bar.txt", "spec/fixtures/couchapp-test/my-app/views", "spec/fixtures/couchapp-test/my-app/views/example-map.js", "spec/fixtures/couchapp-test/my-app/views/example-reduce.js", "spec/fixtures/more", "spec/fixtures/more/article.rb", "spec/fixtures/more/card.rb", "spec/fixtures/more/course.rb", "spec/fixtures/more/event.rb", "spec/fixtures/more/invoice.rb", "spec/fixtures/more/person.rb", "spec/fixtures/more/question.rb", "spec/fixtures/more/service.rb", "spec/fixtures/views", "spec/fixtures/views/lib.js", "spec/fixtures/views/test_view", "spec/fixtures/views/test_view/lib.js", "spec/fixtures/views/test_view/only-map.js", "spec/fixtures/views/test_view/test-map.js", "spec/fixtures/views/test_view/test-reduce.js", "spec/spec.opts", "spec/spec_helper.rb", "utils/remap.rb", "utils/subset.rb"] + s.files = ["LICENSE", "README.md", "Rakefile", "THANKS.md", "examples/model", "examples/model/example.rb", "examples/word_count", "examples/word_count/markov", "examples/word_count/views", "examples/word_count/views/books", "examples/word_count/views/books/chunked-map.js", "examples/word_count/views/books/united-map.js", "examples/word_count/views/markov", "examples/word_count/views/markov/chain-map.js", "examples/word_count/views/markov/chain-reduce.js", "examples/word_count/views/word_count", "examples/word_count/views/word_count/count-map.js", "examples/word_count/views/word_count/count-reduce.js", "examples/word_count/word_count.rb", "examples/word_count/word_count_query.rb", "examples/word_count/word_count_views.rb", "lib/couchrest", "lib/couchrest/commands", "lib/couchrest/commands/generate.rb", "lib/couchrest/commands/push.rb", "lib/couchrest/core", "lib/couchrest/core/database.rb", "lib/couchrest/core/design.rb", "lib/couchrest/core/document.rb", "lib/couchrest/core/response.rb", "lib/couchrest/core/server.rb", "lib/couchrest/core/view.rb", "lib/couchrest/helper", "lib/couchrest/helper/pager.rb", "lib/couchrest/helper/streamer.rb", "lib/couchrest/helper/upgrade.rb", "lib/couchrest/mixins", "lib/couchrest/mixins/attachments.rb", "lib/couchrest/mixins/callbacks.rb", "lib/couchrest/mixins/design_doc.rb", "lib/couchrest/mixins/document_queries.rb", "lib/couchrest/mixins/extended_attachments.rb", "lib/couchrest/mixins/extended_document_mixins.rb", "lib/couchrest/mixins/properties.rb", "lib/couchrest/mixins/validation.rb", "lib/couchrest/mixins/views.rb", "lib/couchrest/mixins.rb", "lib/couchrest/monkeypatches.rb", "lib/couchrest/more", "lib/couchrest/more/casted_model.rb", "lib/couchrest/more/extended_document.rb", "lib/couchrest/more/property.rb", "lib/couchrest/support", "lib/couchrest/support/blank.rb", "lib/couchrest/support/class.rb", "lib/couchrest/validation", "lib/couchrest/validation/auto_validate.rb", "lib/couchrest/validation/contextual_validators.rb", "lib/couchrest/validation/validation_errors.rb", "lib/couchrest/validation/validators", "lib/couchrest/validation/validators/absent_field_validator.rb", "lib/couchrest/validation/validators/confirmation_validator.rb", "lib/couchrest/validation/validators/format_validator.rb", "lib/couchrest/validation/validators/formats", "lib/couchrest/validation/validators/formats/email.rb", "lib/couchrest/validation/validators/formats/url.rb", "lib/couchrest/validation/validators/generic_validator.rb", "lib/couchrest/validation/validators/length_validator.rb", "lib/couchrest/validation/validators/method_validator.rb", "lib/couchrest/validation/validators/numeric_validator.rb", "lib/couchrest/validation/validators/required_field_validator.rb", "lib/couchrest.rb", "spec/couchrest", "spec/couchrest/core", "spec/couchrest/core/couchrest_spec.rb", "spec/couchrest/core/database_spec.rb", "spec/couchrest/core/design_spec.rb", "spec/couchrest/core/document_spec.rb", "spec/couchrest/core/server_spec.rb", "spec/couchrest/helpers", "spec/couchrest/helpers/pager_spec.rb", "spec/couchrest/helpers/streamer_spec.rb", "spec/couchrest/more", "spec/couchrest/more/casted_extended_doc_spec.rb", "spec/couchrest/more/casted_model_spec.rb", "spec/couchrest/more/extended_doc_attachment_spec.rb", "spec/couchrest/more/extended_doc_spec.rb", "spec/couchrest/more/extended_doc_view_spec.rb", "spec/couchrest/more/property_spec.rb", "spec/couchrest/support", "spec/couchrest/support/class_spec.rb", "spec/fixtures", "spec/fixtures/attachments", "spec/fixtures/attachments/couchdb.png", "spec/fixtures/attachments/README", "spec/fixtures/attachments/test.html", "spec/fixtures/more", "spec/fixtures/more/article.rb", "spec/fixtures/more/card.rb", "spec/fixtures/more/course.rb", "spec/fixtures/more/event.rb", "spec/fixtures/more/invoice.rb", "spec/fixtures/more/person.rb", "spec/fixtures/more/question.rb", "spec/fixtures/more/service.rb", "spec/fixtures/views", "spec/fixtures/views/lib.js", "spec/fixtures/views/test_view", "spec/fixtures/views/test_view/lib.js", "spec/fixtures/views/test_view/only-map.js", "spec/fixtures/views/test_view/test-map.js", "spec/fixtures/views/test_view/test-reduce.js", "spec/spec.opts", "spec/spec_helper.rb", "utils/remap.rb", "utils/subset.rb"] s.has_rdoc = true s.homepage = %q{http://github.com/jchris/couchrest} s.require_paths = ["lib"] - s.rubygems_version = %q{1.3.1} + s.rubygems_version = %q{1.2.0} s.summary = %q{Lean and RESTful interface to CouchDB.} if s.respond_to? :specification_version then current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION s.specification_version = 2 - if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then + if current_version >= 3 then s.add_runtime_dependency(%q, [">= 1.1.2"]) s.add_runtime_dependency(%q, [">= 0.5"]) s.add_runtime_dependency(%q, [">= 1.15"]) diff --git a/lib/couchrest.rb b/lib/couchrest.rb index 8524cb3..c52ced4 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.2.1' unless self.const_defined?("VERSION") + VERSION = '0.2.2' unless self.const_defined?("VERSION") autoload :Server, 'couchrest/core/server' autoload :Database, 'couchrest/core/database' From 36c8bea4535ebb58689e9c968dbdf0f0d242836e Mon Sep 17 00:00:00 2001 From: Chris Anderson Date: Sun, 15 Mar 2009 13:00:47 -0700 Subject: [PATCH 6/7] all specs pass against couchdb trunk --- lib/couchrest/more/extended_document.rb | 4 ++-- spec/couchrest/core/database_spec.rb | 27 ++++++------------------ spec/couchrest/core/document_spec.rb | 3 ++- spec/couchrest/more/extended_doc_spec.rb | 2 +- 4 files changed, 11 insertions(+), 25 deletions(-) diff --git a/lib/couchrest/more/extended_document.rb b/lib/couchrest/more/extended_document.rb index 826b286..acb6b83 100644 --- a/lib/couchrest/more/extended_document.rb +++ b/lib/couchrest/more/extended_document.rb @@ -205,8 +205,8 @@ module CouchRest _run_destroy_callbacks do result = database.delete_doc(self, bulk) if result['ok'] - self['_rev'] = nil - self['_id'] = nil + self.delete('_rev') + self.delete('_id') end result['ok'] end diff --git a/spec/couchrest/core/database_spec.rb b/spec/couchrest/core/database_spec.rb index dd8c3df..e7f03cc 100644 --- a/spec/couchrest/core/database_spec.rb +++ b/spec/couchrest/core/database_spec.rb @@ -149,8 +149,8 @@ describe CouchRest::Database do {"mild" => "yet local"}, {"another" => ["set","of","keys"]} ]) - rs['new_revs'].each do |r| - @db.get(r['id']) + rs.each do |r| + @db.get(r['id']).rev.should == r["rev"] end end @@ -170,26 +170,10 @@ describe CouchRest::Database do {"_id" => "twoB", "mild" => "yet local"}, {"another" => ["set","of","keys"]} ]) - rs['new_revs'].each do |r| - @db.get(r['id']) + rs.each do |r| + @db.get(r['id']).rev.should == r["rev"] end end - - it "in the case of an id conflict should not insert anything" do - @r = @db.save_doc({'lemons' => 'from texas', 'and' => 'how', "_id" => "oneB"}) - - lambda do - rs = @db.bulk_save([ - {"_id" => "oneB", "wild" => "and random"}, - {"_id" => "twoB", "mild" => "yet local"}, - {"another" => ["set","of","keys"]} - ]) - end.should raise_error(RestClient::RequestFailed) - - lambda do - @db.get('twoB') - end.should raise_error(RestClient::ResourceNotFound) - end it "should empty the bulk save cache if no documents are given" do @db.save_doc({"_id" => "bulk_cache_1", "val" => "test"}, true) @@ -593,7 +577,8 @@ describe CouchRest::Database do @db.save_doc({'_id' => @docid, 'will-exist' => 'here'}) end it "should fail without a rev" do - lambda{@db.move_doc @doc, @docid}.should raise_error(RestClient::RequestFailed) + @doc.delete("_rev") + lambda{@db.move_doc @doc, @docid}.should raise_error(ArgumentError) lambda{@db.get(@r['id'])}.should_not raise_error end it "should succeed with a rev" do diff --git a/spec/couchrest/core/document_spec.rb b/spec/couchrest/core/document_spec.rb index dfb2ab9..da76714 100644 --- a/spec/couchrest/core/document_spec.rb +++ b/spec/couchrest/core/document_spec.rb @@ -224,7 +224,8 @@ describe CouchRest::Document do @db.save_doc({'_id' => @docid, 'will-exist' => 'here'}) end it "should fail without a rev" do - lambda{@doc.move @docid}.should raise_error(RestClient::RequestFailed) + @doc.delete("_rev") + lambda{@doc.move @docid}.should raise_error(ArgumentError) lambda{@db.get(@resp['id'])}.should_not raise_error end it "should succeed with a rev" do diff --git a/spec/couchrest/more/extended_doc_spec.rb b/spec/couchrest/more/extended_doc_spec.rb index f36394a..190baba 100644 --- a/spec/couchrest/more/extended_doc_spec.rb +++ b/spec/couchrest/more/extended_doc_spec.rb @@ -442,7 +442,7 @@ describe "ExtendedDocument" do @dobj.destroy @dobj.rev.should be_nil @dobj.id.should be_nil - @dobj.save.should == true + @dobj.save.should == true end it "should make it go away" do @dobj.destroy From 76ef427862a749487838ad5d15b66c283e2abb29 Mon Sep 17 00:00:00 2001 From: Chris Anderson Date: Sun, 15 Mar 2009 13:01:39 -0700 Subject: [PATCH 7/7] rev gem to version 0.17.0 --- couchrest.gemspec | 2 +- lib/couchrest.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/couchrest.gemspec b/couchrest.gemspec index 9e0384b..59d7be3 100644 --- a/couchrest.gemspec +++ b/couchrest.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = %q{couchrest} - s.version = "0.2.2" + s.version = "0.17.0" 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 c52ced4..a32e17b 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.2.2' unless self.const_defined?("VERSION") + VERSION = '0.17.0' unless self.const_defined?("VERSION") autoload :Server, 'couchrest/core/server' autoload :Database, 'couchrest/core/database'