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

View file

@ -142,8 +142,14 @@ module CouchRest
bulk_save
end
result = if doc['_id']
slug = escape_docid(doc['_id'])
CouchRest.put "#{@uri}/#{slug}", doc
slug = escape_docid(doc['_id'])
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
begin
slug = doc['_id'] = @server.next_uuid

View file

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

View file

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

View file

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

View file

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

View file

@ -224,6 +224,7 @@ describe "ExtendedDocument" do
describe "finding all instances of a model" do
before(:all) do
WithTemplateAndUniqueID.design_doc_fresh = false
WithTemplateAndUniqueID.all.map{|o| o.destroy(true)}
WithTemplateAndUniqueID.database.bulk_delete
WithTemplateAndUniqueID.new('important-field' => '1').save
@ -245,6 +246,7 @@ describe "ExtendedDocument" do
describe "counting all instances of a model" do
before(:each) do
@db = reset_test_db!
WithTemplateAndUniqueID.design_doc_fresh = false
end
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
before(:each) do
@db = reset_test_db!
WithTemplateAndUniqueID.design_doc_fresh = false
WithTemplateAndUniqueID.new('important-field' => '1').save
WithTemplateAndUniqueID.new('important-field' => '2').save
WithTemplateAndUniqueID.new('important-field' => '3').save

View file

@ -66,6 +66,7 @@ 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')
@ -73,11 +74,13 @@ 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
@ -100,6 +103,7 @@ 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']
end
it "should setup" do
@ -107,11 +111,13 @@ describe "ExtendedDocument views" do
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 |variable|
it "should not look for class" do
Course.design_doc_fresh = false
@as = Course.by_dept
@as[0]['_id'].should == @id
end
@ -207,10 +213,12 @@ 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')
@ -249,7 +257,6 @@ describe "ExtendedDocument views" do
it "should clean up design docs left around on specific database" do
@us.by_title
original_id = @us.model_design_doc['_rev']
debugger
Unattached.view_by :professor
@us.by_professor
@us.model_design_doc['_rev'].should_not == original_id
@ -302,16 +309,19 @@ 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
@ -321,7 +331,7 @@ describe "ExtendedDocument views" do
describe "adding a view" do
before(:each) do
reset_test_db!
Article.database.recreate!
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"