I seem to have all the CR::Model specs passing

This commit is contained in:
Chris Anderson 2008-11-22 14:15:07 -08:00
parent 19a70ffd7d
commit 78534f8ec9
4 changed files with 127 additions and 93 deletions

View file

@ -1,5 +1,5 @@
require File.dirname(__FILE__) + '/../../spec_helper'
__END__
class Basic < CouchRest::Model
end
@ -34,8 +34,6 @@ class Course < CouchRest::Model
view_by :dept, :ducktype => true
end
class Article < CouchRest::Model
use_database CouchRest.database!('http://localhost:5984/couchrest-model-test')
unique_id :slug
@ -216,24 +214,24 @@ describe CouchRest::Model do
@course["questions"][0].a[0].should == "beast"
end
end
#
# describe "finding all instances of a model" do
# before(:all) do
# WithTemplate.new('important-field' => '1').save
# WithTemplate.new('important-field' => '2').save
# WithTemplate.new('important-field' => '3').save
# WithTemplate.new('important-field' => '4').save
# end
# it "should make the design doc" do
# WithTemplate.all
# d = WithTemplate.design_doc
# d['views']['all']['map'].should include('WithTemplate')
# end
# it "should find all" do
# rs = WithTemplate.all
# rs.length.should == 4
# end
# end
describe "finding all instances of a model" do
before(:all) do
WithTemplate.new('important-field' => '1').save
WithTemplate.new('important-field' => '2').save
WithTemplate.new('important-field' => '3').save
WithTemplate.new('important-field' => '4').save
end
it "should make the design doc" do
WithTemplate.all
d = WithTemplate.design_doc
d['views']['all']['map'].should include('WithTemplate')
end
it "should find all" do
rs = WithTemplate.all
rs.length.should == 4
end
end
describe "getting a model with a subobject field" do
before(:all) do
@ -288,6 +286,11 @@ describe CouchRest::Model do
Article.database.delete(@old) if @old
end
it "should be a new document" do
@art.should be_a_new_document
@art.title.should be_nil
end
it "should require the title" do
lambda{@art.save}.should raise_error
@art.title = 'This is the title'
@ -409,10 +412,10 @@ describe CouchRest::Model do
view['rows'].length.should == 4
end
# it "should return the matching objects (with default argument :descending => true)" do
# articles = Article.by_date
# articles.collect{|a|a.title}.should == @titles.reverse
# end
it "should return the matching objects (with default argument :descending => true)" do
articles = Article.by_date
articles.collect{|a|a.title}.should == @titles.reverse
end
it "should allow you to override default args" do
articles = Article.by_date :descending => false
@ -433,25 +436,25 @@ describe CouchRest::Model do
doc = Course.design_doc
doc['views']['all']['map'].should include('Course')
end
# it "should can query via view" do
# # register methods with method-missing, for local dispatch. method
# # missing lookup table, no heuristics.
# view = Course.view :by_title
# designed = Course.by_title
# view.should == designed
# end
# it "should get them" do
# rs = Course.by_title
# rs.length.should == 4
# end
# it "should yield" do
# courses = []
# rs = Course.by_title # remove me
# Course.view(:by_title) do |course|
# courses << course
# end
# courses[0]["doc"]["title"].should =='aaa'
# end
it "should can query via view" do
# register methods with method-missing, for local dispatch. method
# missing lookup table, no heuristics.
view = Course.view :by_title
designed = Course.by_title
view.should == designed
end
it "should get them" do
rs = Course.by_title
rs.length.should == 4
end
it "should yield" do
courses = []
rs = Course.by_title # remove me
Course.view(:by_title) do |course|
courses << course
end
courses[0]["doc"]["title"].should =='aaa'
end
end
@ -473,9 +476,6 @@ describe CouchRest::Model do
@as[0]['_id'].should == @id
end
end
end
__END__
describe "a model with a compound key view" do
before(:all) do
@ -553,6 +553,8 @@ __END__
Article.by_updated_at
newdocs = Article.database.documents :startkey => "_design/",
:endkey => "_design/\u9999"
# puts @design_docs.inspect
# puts newdocs.inspect
newdocs["rows"].length.should == @design_docs["rows"].length + 1
end
end