0
require File.dirname(__FILE__) + '/../spec_helper.rb'
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
+ Object.send(:remove_const, :Blog)
0
+ Object.send(:remove_const, :Comment)
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
+describe "ActiveCouch::Base #find method with no params passed" do
0
+ class Person < ActiveCouch::Base
0
+ site 'http://localhost:5984/'
0
+ # Define the migration
0
+ class ByName < 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', ByName)
0
+ Person.create(:name => 'McLovin')
0
+ Person.create(:name => 'Seth')
0
+ # Delete the database last
0
+ ActiveCouch::Migrator.delete_database('http://localhost:5984', 'people')
0
+ Object.send(:remove_const, :Person)
0
+ it "should return all documents if passed :all, with no params specified"
0
+describe "ActiveCouch::Base #find method with an ID passed" do
0
+ class Person < ActiveCouch::Base
0
+ site 'http://localhost:5984/'
0
+ # Define the migration
0
+ class ByName < 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', ByName)
0
+ p = Person.create(:name => 'McLovin', :id => '123')
0
+ # Delete the database last
0
+ ActiveCouch::Migrator.delete_database('http://localhost:5984', 'people')
0
+ Object.send(:remove_const, :Person)
0
+ it "should return an ActiveCouch::Base object if the ID exists" do
0
+ person = Person.find('123')
0
+ person.name.should == 'McLovin'
0
+ it "should return nil if the ID does not exist" do
0
+ person = Person.find('321')
0
+describe "ActiveCouch::Base #find method with non-String params passed as arguments" do
0
+ class Person < ActiveCouch::Base
0
+ site 'http://localhost:5984/'
0
+ # Define the migration
0
+ class ByAge < 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', ByAge)
0
+ p = Person.create(:age => "21")
0
+ # Delete the database last
0
+ ActiveCouch::Migrator.delete_database('http://localhost:5984', 'people')
0
+ Object.send(:remove_const, :Person)
0
+ it "should return an ActiveCouch::Base object" do
0
+ person = Person.find(:first, :params => {:age => 21})
0
+ person.age.should == "21"
0
describe "ActiveCouch::Base #find method with just simple attributes" do
0
@@ -115,156 +270,107 @@ describe "ActiveCouch::Base #find method with multiple documents in the CouchDB
0
-describe "ActiveCouch::Base #find method
with an object which has associations" do
0
+describe "ActiveCouch::Base #find method
:limit option used" do
0
- class Comment < ActiveCouch::Base
0
- site 'http://localhost:5984'
0
- class Blog < ActiveCouch::Base
0
+ class Person < 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
- Object.send(:remove_const, :Blog)
0
- Object.send(:remove_const, :Comment)
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
-describe "ActiveCouch::Base #find method with no params passed" do
0
- class Person < ActiveCouch::Base
0
- site 'http://localhost:5984/'
0
- class By
Name < ActiveCouch::Migration
0
+ class By
LastName < 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', By
Name)
0
+ ActiveCouch::Migrator.migrate('http://localhost:5984', By
LastName)
0
- Person.create(:name => 'McLovin')
0
- Person.create(:name => 'Seth')
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
Object.send(:remove_const, :Person)
0
- it "should return all documents if passed :all, with no params specified"
0
+ it "should return only one object in the database when find method is sent the param :limit => 1" do
0
+ people = Person.find(:all, :params => {:last_name => 'McLovin'}, :limit => 1)
0
+ # Check if it is an array and if the size is 2
0
+ people.class.should == Array
0
+ people.size.should == 1
0
+ # The id's and rev's for all the objects must not be nil
0
+ person.id.should_not == nil
0
+ person.rev.should_not == nil
0
+ person.first_name == 'Seth'
0
+ person.last_name == 'McLovin'
0
-describe "ActiveCouch::Base #find method with an ID passed" do
0
+describe "ActiveCouch::Base #find method :limit and :offset options used" do
0
class Person < ActiveCouch::Base
0
- site 'http://localhost:5984/'
0
+ site 'http://localhost:5984'
0
- class By
Name < ActiveCouch::Migration
0
+ class By
LastName < 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', ByName)
0
- p = Person.create(:name => 'McLovin', :id => '123')
0
+ ActiveCouch::Migrator.migrate('http://localhost:5984', ByLastName)
0
+ Person.create(:id => 'Seth', :last_name => 'McLovin', :first_name => 'Seth')
0
+ Person.create(:id => 'Bob', :last_name => 'McLovin', :first_name => 'Bob')
0
+ Person.create(:id => 'John', :last_name => 'McLovin', :first_name => 'Bob')
0
# Delete the database last
0
ActiveCouch::Migrator.delete_database('http://localhost:5984', 'people')
0
Object.send(:remove_const, :Person)
0
- it "should return an ActiveCouch::Base object if the ID exists" do
0
- person = Person.find('123')
0
- person.name.should == 'McLovin'
0
+ it "should return two objects in the database when find method is sent the param :offset => 1" do
0
+ people = Person.find(:all, :params => {:last_name => 'McLovin'}, :offset => 1)
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 return nil if the ID does not exist" do
0
- person = Person.find('321')
0
-describe "ActiveCouch::Base #find method with non-String params passed as arguments" do
0
- class Person < ActiveCouch::Base
0
- site 'http://localhost:5984/'
0
- # Define the migration
0
- class ByAge < ActiveCouch::Migration
0
- define :for_db => 'people' do
0
+ it "should return one object in the database when find method is sent the param :offset => 1 and :limit => 1" do
0
+ people = Person.find(:all, :params => {:last_name => 'McLovin'}, :offset => 1, :limit => 1)
0
+ # Check if it is an array and if the size is 2
0
+ people.class.should == Array
0
+ people.size.should == 1
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
- # Create the database first
0
- ActiveCouch::Migrator.create_database('http://localhost:5984', 'people')
0
- ActiveCouch::Migrator.migrate('http://localhost:5984', ByAge)
0
- p = Person.create(:age => "21")
0
- # Delete the database last
0
- ActiveCouch::Migrator.delete_database('http://localhost:5984', 'people')
0
- Object.send(:remove_const, :Person)
0
- it "should return an ActiveCouch::Base object" do
0
- person = Person.find(:first, :params => {:age => 21})
0
- person.age.should == "21"
0
\ No newline at end of file
Comments
No one has commented yet.