diff --git a/lib/couchrest.rb b/lib/couchrest.rb index b1bdb80..1f666fd 100644 --- a/lib/couchrest.rb +++ b/lib/couchrest.rb @@ -22,12 +22,13 @@ $:.unshift File.dirname(__FILE__) unless $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__))) +$COUCHREST_DEBUG ||= false require 'couchrest/monkeypatches' # = CouchDB, close to the metal module CouchRest - VERSION = '0.17' unless self.const_defined?("VERSION") + VERSION = '0.17' unless self.const_defined?("VERSION") autoload :Server, 'couchrest/core/server' autoload :Database, 'couchrest/core/database' @@ -129,7 +130,11 @@ module CouchRest begin JSON.parse(RestClient.put(uri, payload)) rescue Exception => e - raise "Error while sending a PUT request #{uri}\npayload: #{payload.inspect}\n#{e}" + if $COUCHREST_DEBUG == true + raise "Error while sending a PUT request #{uri}\npayload: #{payload.inspect}\n#{e}" + else + raise e + end end end @@ -137,7 +142,11 @@ module CouchRest begin JSON.parse(RestClient.get(uri), :max_nesting => false) rescue => e - raise "Error while sending a GET request #{uri}\n: #{e}" + if $COUCHREST_DEBUG == true + raise "Error while sending a GET request #{uri}\n: #{e}" + else + raise e + end end end @@ -146,7 +155,11 @@ module CouchRest begin JSON.parse(RestClient.post(uri, payload)) rescue Exception => e - raise "Error while sending a POST request #{uri}\npayload: #{payload.inspect}\n#{e}" + if $COUCHREST_DEBUG == true + raise "Error while sending a POST request #{uri}\npayload: #{payload.inspect}\n#{e}" + else + raise e + end end end diff --git a/lib/couchrest/mixins/views.rb b/lib/couchrest/mixins/views.rb index fb9269c..b1bcd1d 100644 --- a/lib/couchrest/mixins/views.rb +++ b/lib/couchrest/mixins/views.rb @@ -133,9 +133,8 @@ module CouchRest fetch_view(name, opts, &block) else begin - # auto load mentioned documents unless asked differently - opts.merge({:include_docs => true}) unless opts.has_key?(:include_docs) - view = fetch_view name, opts, &block + # auto load mentioned documents unless asked differently (didn't use merge! on a previous line to avoid duping the object) + view = fetch_view name, (opts.has_key?(:include_docs) ? opts : opts.merge({:include_docs => true})), &block view['rows'].collect{|r|new(r['doc'])} if view['rows'] rescue # fallback for old versions of couchdb that don't diff --git a/spec/couchrest/more/extended_doc_view_spec.rb b/spec/couchrest/more/extended_doc_view_spec.rb index 2e47442..46e8534 100644 --- a/spec/couchrest/more/extended_doc_view_spec.rb +++ b/spec/couchrest/more/extended_doc_view_spec.rb @@ -105,6 +105,9 @@ 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 @titles = ["uniq one", "even more interesting", "less fun", "not junk"] @user_ids = ["quentin", "aaron"]