forked from chuyeow/activecouch
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleaning up for v0.2.0 release. Added find_from_url and count_all met…
…hods to ActiveCouch::Base. Moved ActiveCouch::Exporter to be under lib/support
- Loading branch information
Arun Thampi
authored and
Arun Thampi
committed
Oct 22, 2008
1 parent
24c2644
commit 38b50ec
Showing
16 changed files
with
184 additions
and
130 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.1.95 | ||
0.2.0 |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
require 'active_couch/support/inflector' | ||
require 'active_couch/support/extensions' | ||
require 'active_couch/support/extensions' | ||
require 'active_couch/support/exporter' |
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 |
---|---|---|
@@ -1,3 +1,2 @@ | ||
require 'active_couch/views/errors.rb' | ||
require 'active_couch/views/view.rb' | ||
require 'active_couch/views/exporter.rb' | ||
require 'active_couch/views/view.rb' |
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,29 @@ | ||
require File.dirname(__FILE__) + '/../spec_helper.rb' | ||
|
||
describe "ActiveCouch::Base #count_all 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 | ||
|
||
# Create the database first | ||
ActiveCouch::Exporter.create_database('http://localhost:5984', 'people') | ||
# 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::Exporter.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_all | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
require File.dirname(__FILE__) + '/../spec_helper.rb' | ||
|
||
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::View | ||
define :for_db => 'people' do | ||
with_key 'last_name' | ||
end | ||
end | ||
# Create the database first | ||
ActiveCouch::Exporter.create_database('http://localhost:5984', 'people') | ||
# Create a view | ||
ActiveCouch::Exporter.export('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::Exporter.delete_database('http://localhost:5984', 'people') | ||
Object.send(:remove_const, :Person) | ||
end | ||
|
||
it "should find all objects in the database when find_from_url method is used" do | ||
people = Person.find_from_url("/people/_view/by_last_name/by_last_name?key=%22McLovin%22") | ||
# Check if it is an array and if the size is 2 | ||
people.class.should == Array | ||
people.size.should == 2 | ||
# The id's and rev's for all the objects must not be nil | ||
people.each do |p| | ||
p.id.should_not == nil | ||
p.rev.should_not == nil | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require File.dirname(__FILE__) + '/../spec_helper.rb' | ||
|
||
require 'net/http' | ||
require 'uri' | ||
|
||
describe ActiveCouch::Exporter, "#export twice (that actually connects to a CouchDB server)" do | ||
before(:each) do | ||
class ByFace < ActiveCouch::View | ||
define :for_db => 'ac_test_4' do | ||
with_key 'face' | ||
end | ||
end | ||
|
||
ActiveCouch::Exporter.create_database('http://localhost:5984/', 'ac_test_4') | ||
end | ||
|
||
after(:each) do | ||
ActiveCouch::Exporter.delete_database('http://localhost:5984/', 'ac_test_4') | ||
end | ||
|
||
it "should be able to create a permanent view when sent the export method, after the view has already been saved" do | ||
ActiveCouch::Exporter.export('http://localhost:5984', ByFace).should == true | ||
# This is the view document. To actually query this particular view, the URL to be used | ||
# is http://#{host}:#{port}/ac_test_1/_view/by_face/by_face | ||
# A little unwieldy I know, but the point of ActiveCouch is to abstract this unwieldiness | ||
response = Net::HTTP.get_response URI.parse("http://localhost:5984/ac_test_4/_design/by_face") | ||
response.code.should == '200' | ||
|
||
ActiveCouch::Exporter.delete('http://localhost:5984', ByFace).should == true | ||
# This is the view document. To actually query this particular view, the URL to be used | ||
# is http://#{host}:#{port}/ac_test_1/_view/by_face/by_face | ||
# A little unwieldy I know, but the point of ActiveCouch is to abstract this unwieldiness | ||
response = Net::HTTP.get_response URI.parse("http://localhost:5984/ac_test_4/_design/by_face") | ||
response.code.should == '404' | ||
end | ||
end |
Oops, something went wrong.