fixed all the specs so we are back to green

This commit is contained in:
Matt Aimonetti 2009-05-26 18:27:49 -07:00
parent 2d52225a25
commit e48a6c8866
8 changed files with 36 additions and 18 deletions

View file

@ -23,9 +23,7 @@ require 'rest_client'
$:.unshift File.dirname(__FILE__) unless $:.unshift File.dirname(__FILE__) unless
$:.include?(File.dirname(__FILE__)) || $:.include?(File.dirname(__FILE__)) ||
$:.include?(File.expand_path(File.dirname(__FILE__))) $:.include?(File.expand_path(File.dirname(__FILE__)))
$COUCHREST_DEBUG ||= false
require 'couchrest/monkeypatches' require 'couchrest/monkeypatches'
# = CouchDB, close to the metal # = CouchDB, close to the metal
@ -145,7 +143,7 @@ module CouchRest
begin begin
JSON.parse(RestClient.put(uri, payload)) JSON.parse(RestClient.put(uri, payload))
rescue Exception => e rescue Exception => e
if $COUCHREST_DEBUG == true if $DEBUG
raise "Error while sending a PUT request #{uri}\npayload: #{payload.inspect}\n#{e}" raise "Error while sending a PUT request #{uri}\npayload: #{payload.inspect}\n#{e}"
else else
raise e raise e
@ -157,7 +155,7 @@ module CouchRest
begin begin
JSON.parse(RestClient.get(uri), :max_nesting => false) JSON.parse(RestClient.get(uri), :max_nesting => false)
rescue => e rescue => e
if $COUCHREST_DEBUG == true if $DEBUG
raise "Error while sending a GET request #{uri}\n: #{e}" raise "Error while sending a GET request #{uri}\n: #{e}"
else else
raise e raise e
@ -170,7 +168,7 @@ module CouchRest
begin begin
JSON.parse(RestClient.post(uri, payload)) JSON.parse(RestClient.post(uri, payload))
rescue Exception => e rescue Exception => e
if $COUCHREST_DEBUG == true if $DEBUG
raise "Error while sending a POST request #{uri}\npayload: #{payload.inspect}\n#{e}" raise "Error while sending a POST request #{uri}\npayload: #{payload.inspect}\n#{e}"
else else
raise e raise e

View file

@ -142,8 +142,14 @@ module CouchRest
bulk_save bulk_save
end end
result = if doc['_id'] result = if doc['_id']
slug = escape_docid(doc['_id']) slug = escape_docid(doc['_id'])
CouchRest.put "#{@uri}/#{slug}", doc begin
CouchRest.put "#{@uri}/#{slug}", doc
rescue RestClient::ResourceNotFound
p "resource not found when saving even tho an id was passed"
slug = doc['_id'] = @server.next_uuid
CouchRest.put "#{@uri}/#{slug}", doc
end
else else
begin begin
slug = doc['_id'] = @server.next_uuid slug = doc['_id'] = @server.next_uuid

View file

@ -67,9 +67,13 @@ module CouchRest
private private
def reset_design_doc def reset_design_doc
design_doc['_id'] = design_doc_id current = self.database.get(design_doc_id) rescue nil
design_doc.delete('_rev') design_doc['_id'] = design_doc_id
#design_doc.database = nil if current.nil?
design_doc.delete('_rev')
else
design_doc['_rev'] = current['_rev']
end
self.design_doc_fresh = true self.design_doc_fresh = true
end end

View file

@ -92,7 +92,6 @@ module RestClient
# establish_connection(uri) # establish_connection(uri)
# http = Thread.current[:connection] # http = Thread.current[:connection]
# require 'ruby-debug' # require 'ruby-debug'
# debugger
# req.body_stream = nil # req.body_stream = nil
# #
# res = http.request(req, payload) # res = http.request(req, payload)

View file

@ -10,11 +10,11 @@ module CouchRest
def initialize(keys={}) def initialize(keys={})
raise StandardError unless self.is_a? Hash raise StandardError unless self.is_a? Hash
apply_defaults # defined in CouchRest::Mixins::Properties
super() super()
keys.each do |k,v| keys.each do |k,v|
self[k.to_s] = v self[k.to_s] = v
end if keys end if keys
apply_defaults # defined in CouchRest::Mixins::Properties
cast_keys # defined in CouchRest::Mixins::Properties cast_keys # defined in CouchRest::Mixins::Properties
end end

View file

@ -16,8 +16,6 @@ module CouchRest
# # This feature is still not fully ported over, # # This feature is still not fully ported over,
# # test are lacking, so please use with caution # # test are lacking, so please use with caution
# def auto_validate! # def auto_validate!
# require 'ruby-debug'
# debugger
# auto_validation = true # auto_validation = true
# end # end

View file

@ -224,6 +224,7 @@ describe "ExtendedDocument" do
describe "finding all instances of a model" do describe "finding all instances of a model" do
before(:all) do before(:all) do
WithTemplateAndUniqueID.design_doc_fresh = false
WithTemplateAndUniqueID.all.map{|o| o.destroy(true)} WithTemplateAndUniqueID.all.map{|o| o.destroy(true)}
WithTemplateAndUniqueID.database.bulk_delete WithTemplateAndUniqueID.database.bulk_delete
WithTemplateAndUniqueID.new('important-field' => '1').save WithTemplateAndUniqueID.new('important-field' => '1').save
@ -245,6 +246,7 @@ describe "ExtendedDocument" do
describe "counting all instances of a model" do describe "counting all instances of a model" do
before(:each) do before(:each) do
@db = reset_test_db! @db = reset_test_db!
WithTemplateAndUniqueID.design_doc_fresh = false
end end
it ".count should return 0 if there are no docuemtns" do it ".count should return 0 if there are no docuemtns" do
@ -263,6 +265,7 @@ describe "ExtendedDocument" do
describe "finding the first instance of a model" do describe "finding the first instance of a model" do
before(:each) do before(:each) do
@db = reset_test_db! @db = reset_test_db!
WithTemplateAndUniqueID.design_doc_fresh = false
WithTemplateAndUniqueID.new('important-field' => '1').save WithTemplateAndUniqueID.new('important-field' => '1').save
WithTemplateAndUniqueID.new('important-field' => '2').save WithTemplateAndUniqueID.new('important-field' => '2').save
WithTemplateAndUniqueID.new('important-field' => '3').save WithTemplateAndUniqueID.new('important-field' => '3').save

View file

@ -66,6 +66,7 @@ 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')
@ -73,11 +74,13 @@ 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
@ -100,6 +103,7 @@ describe "ExtendedDocument views" do
describe "a ducktype view" do describe "a ducktype view" do
before(:all) do before(:all) do
reset_test_db!
@id = TEST_SERVER.default_database.save_doc({:dept => true})['id'] @id = TEST_SERVER.default_database.save_doc({:dept => true})['id']
end end
it "should setup" do it "should setup" do
@ -107,11 +111,13 @@ describe "ExtendedDocument views" do
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 |variable| 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
@ -207,10 +213,12 @@ 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')
@ -249,7 +257,6 @@ describe "ExtendedDocument views" do
it "should clean up design docs left around on specific database" do it "should clean up design docs left around on specific database" do
@us.by_title @us.by_title
original_id = @us.model_design_doc['_rev'] original_id = @us.model_design_doc['_rev']
debugger
Unattached.view_by :professor Unattached.view_by :professor
@us.by_professor @us.by_professor
@us.model_design_doc['_rev'].should_not == original_id @us.model_design_doc['_rev'].should_not == original_id
@ -302,16 +309,19 @@ 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
@ -321,7 +331,7 @@ 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.database.recreate! 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"