forked from chuyeow/activecouch
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- ActiveCouch::Base#find supports find by id so Person.find('123') re…
…turns one object (or nil if ID does not exist) - ActiveCouch::Base#count added to count the number of objects which satisfy a given condition (E.g. Person.count(:params => {:name => "McLovin"})
- Loading branch information
1 parent
9e6e7a3
commit 7d1ff41
Showing
20 changed files
with
299 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
require File.dirname(__FILE__) + '/../spec_helper.rb' | ||
|
||
describe "ActiveCouch::Base #count method with just simple attributes" do | ||
before(:each) do | ||
# Define the model | ||
class Person < ActiveCouch::Base | ||
site 'http://localhost:5984' | ||
has :name | ||
end | ||
# Define the migration | ||
class ByName < ActiveCouch::Migration | ||
define :for_db => 'people' do | ||
with_key 'name' | ||
end | ||
end | ||
# Create the database first | ||
ActiveCouch::Migrator.create_database('http://localhost:5984', 'people') | ||
# Create a view | ||
ActiveCouch::Migrator.migrate('http://localhost:5984', ByName) | ||
# Save an object | ||
Person.new(:name => 'McLovin').save | ||
end | ||
|
||
after(:each) do | ||
# Delete the database last | ||
ActiveCouch::Migrator.delete_database('http://localhost:5984', 'people') | ||
Object.send(:remove_const, :Person) | ||
end | ||
|
||
it "should respond to the find method" do | ||
Person.should respond_to(:count) | ||
end | ||
|
||
it "should return an array with one Person object in it, when sent method find with parameter :all" do | ||
count = Person.count(:params => {:name => 'McLovin'}) | ||
count.should == 1 | ||
end | ||
end | ||
|
||
|
||
describe "ActiveCouch::Base #find method with multiple documents in the CouchDB database" do | ||
before(:each) do | ||
class Person < ActiveCouch::Base | ||
site 'http://localhost:5984' | ||
|
||
has :first_name | ||
has :last_name | ||
end | ||
|
||
# Define the migration | ||
class ByLastName < ActiveCouch::Migration | ||
define :for_db => 'people' do | ||
with_key 'last_name' | ||
end | ||
end | ||
# Create the database first | ||
ActiveCouch::Migrator.create_database('http://localhost:5984', 'people') | ||
# Create a view | ||
ActiveCouch::Migrator.migrate('http://localhost:5984', ByLastName) | ||
# Save two objects | ||
Person.create(:last_name => 'McLovin', :first_name => 'Seth') | ||
Person.create(:last_name => 'McLovin', :first_name => 'Bob') | ||
end | ||
|
||
after(:each) do | ||
# Delete the database last | ||
ActiveCouch::Migrator.delete_database('http://localhost:5984', 'people') | ||
Object.send(:remove_const, :Person) | ||
end | ||
|
||
it "should find all objects in the database when find method is sent the param :all" do | ||
count = Person.count(:params => {:last_name => 'McLovin'}) | ||
count.should == 2 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.