0
@@ -62,4 +62,104 @@ describe "ActiveCouch::Base #find method with just simple attributes" do
0
person = Person.find(:first, :params => {:name => 'Seth'})
0
+describe "ActiveCouch::Base #find method with multiple documents in the CouchDB database" do
0
+ class Person < ActiveCouch::Base
0
+ site 'http://localhost:5984'
0
+ # Define the migration
0
+ class ByLastName < ActiveCouch::Migration
0
+ define :for_db => 'people' do
0
+ # Create the database first
0
+ ActiveCouch::Migrator.create_database('http://localhost:5984', 'people')
0
+ ActiveCouch::Migrator.migrate('http://localhost:5984', ByLastName)
0
+ Person.create(:last_name => 'McLovin', :first_name => 'Seth')
0
+ Person.create(:last_name => 'McLovin', :first_name => 'Bob')
0
+ # Delete the database last
0
+ ActiveCouch::Migrator.delete_database('http://localhost:5984', 'people')
0
+ it "should find all objects in the database when find method is sent the param :all" do
0
+ people = Person.find(:all, :params => {:last_name => 'McLovin'})
0
+ # Check if it is an array and if the size is 2
0
+ people.class.should == Array
0
+ people.size.should == 2
0
+ # The id's and rev's for all the objects must not be nil
0
+ p.id.should_not == nil
0
+ p.rev.should_not == nil
0
+ it "should find only the first object in the database when find method is sent with the param :first" do
0
+ people = Person.find(:first, :params => {:last_name => 'McLovin'})
0
+ # Check if this is a Person and if the size is 1
0
+ people.class.should == Person
0
+describe "ActiveCouch::Base #find method with an object which has associations" do
0
+ class Comment < ActiveCouch::Base
0
+ site 'http://localhost:5984'
0
+ class Blog < ActiveCouch::Base
0
+ site 'http://localhost:5984'
0
+ # Define the migration
0
+ class ByTitle < ActiveCouch::Migration
0
+ define :for_db => 'blogs' do
0
+ # Create the database first
0
+ ActiveCouch::Migrator.create_database('http://localhost:5984', 'blogs')
0
+ ActiveCouch::Migrator.migrate('http://localhost:5984', ByTitle)
0
+ blog = Blog.new(:title => 'iPhone in Singapore')
0
+ blog.add_comment(Comment.new(:body => 'soon plz'))
0
+ blog.add_comment(Comment.new(:body => 'ya rly!'))
0
+ # Create the database first
0
+ ActiveCouch::Migrator.delete_database('http://localhost:5984', 'blogs')
0
+ it "should be able to retrieve the simple attributes" do
0
+ blog = Blog.find(:first, :params => {:title => 'iPhone in Singapore'})
0
+ blog.title.should == 'iPhone in Singapore'
0
+ it "should be able to retrieve associations" do
0
+ blog = Blog.find(:first, :params => {:title => 'iPhone in Singapore'})
0
+ blog.comments.size.should == 2
0
+ # Check whether the bodies of the comments exist
0
+ (blog.comments.inspect =~ /soon plz/).should_not == nil
0
+ (blog.comments.inspect =~ /ya rly!/).should_not == nil
0
\ No newline at end of file
Comments
No one has commented yet.