public
Description: <b>Please go to <a href="http://github.com/arunthampi/activecouch/">http://github.com/arunthampi/activecouch/</a> for the master repos.</b> ActiveCouch is a simple, convenient, Ruby-idiomatic wrapper for CouchDB
Homepage: http://code.google.com/p/activecouch/
Clone URL: git://github.com/chuyeow/activecouch.git
Search Repo:
- ActiveCouch::Base#find supports find by id so Person.find('123') returns 
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"})
arunthampi (author)
Sun Jan 27 20:40:26 -0800 2008
commit  7d1ff41e419741fe31050f9080c405b314753045
tree    f2b7379a21a22bac2b20827c45414ea2e1ab7fc0
parent  9e6e7a363b02c8ec9bf35d7acbfe201fc467b37f
...
1
2
3
 
4
5
6
...
26
27
28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
30
31
...
1
2
3
4
5
6
7
...
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
0
@@ -1,6 +1,7 @@
0
 require 'rubygems'
0
 require 'rake/gempackagetask'
0
 
0
+PKG_NAME = 'activecouch'
0
 PKG_VERSION = File.read('VERSION').chomp
0
 PKG_FILES = FileList[
0
   '[A-Z]*',
0
@@ -26,6 +27,30 @@
0
 Rake::GemPackageTask.new(spec) do |pkg|
0
   pkg.need_zip = true
0
   pkg.need_tar = true
0
+end
0
+
0
+task :lines do
0
+ lines, codelines, total_lines, total_codelines = 0, 0, 0, 0
0
+
0
+ for file_name in FileList["lib/active_couch/**/*.rb"]
0
+ next if file_name =~ /vendor/
0
+ f = File.open(file_name)
0
+
0
+ while line = f.gets
0
+ lines += 1
0
+ next if line =~ /^\s*$/
0
+ next if line =~ /^\s*#/
0
+ codelines += 1
0
+ end
0
+ puts "L: #{sprintf("%4d", lines)}, LOC #{sprintf("%4d", codelines)} | #{file_name}"
0
+
0
+ total_lines += lines
0
+ total_codelines += codelines
0
+
0
+ lines, codelines = 0, 0
0
+ end
0
+
0
+ puts "Total: Lines #{total_lines}, LOC #{total_codelines}"
0
 end
0
 
0
 task :default => [:package]
...
289
290
291
292
 
293
294
295
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
296
297
298
...
407
408
409
 
 
 
 
 
 
 
 
 
410
411
412
...
429
430
431
 
 
 
 
 
 
 
 
432
433
434
...
289
290
291
 
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
...
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
...
453
454
455
456
457
458
459
460
461
462
463
464
465
466
0
@@ -289,10 +289,25 @@
0
         case scope
0
           when :all then find_every(options)
0
           when :first then find_every(options).first
0
- else raise ArgumentError("find must have the first parameter as either :all or :first")
0
+ else find_one(scope) #raise ArgumentError("find must have the first parameter as either :all or :first")
0
         end
0
       end
0
 
0
+ # Retrieves the count of the number of objects in the CouchDB database, based on the
0
+ # search parameters given.
0
+ #
0
+ # Example:
0
+ # class Person < ActiveCouch::Base
0
+ # has :name
0
+ # end
0
+ #
0
+ # # This returns the count of the number of objects
0
+ # people_count = Person.count(:params => {:name => "McLovin"})
0
+ def count(params = {})
0
+ result_set = find(:all, params)
0
+ result_set.size
0
+ end
0
+
0
       # Initializes a new subclass of ActiveCouch::Base and saves in the CouchDB database
0
       # as a new document
0
       #
0
@@ -407,6 +422,15 @@
0
           instantiate_collection(connection.get(path))
0
         end
0
         
0
+ def find_one(id)
0
+ path = "/#{database_name}/#{id}"
0
+ begin
0
+ instantiate_object(connection.get(path))
0
+ rescue ResourceNotFound
0
+ nil
0
+ end
0
+ end
0
+
0
         # Generates a query string by using the ActiveCouch convention, which is to
0
         # have the view defined by pre-pending the attribute to be queried with 'by_'
0
         # So for example, if the params hash is :name => 'McLovin',
0
@@ -429,6 +453,14 @@
0
         def instantiate_collection(result)
0
           hash = JSON.parse(result)
0
           hash['rows'].collect { |row| self.new(row['value']) }
0
+ end
0
+
0
+ # Instantiates an ActiveCouch::Base object, based on the result obtained from
0
+ # the GET URL
0
+ def instantiate_object(result)
0
+ puts result
0
+ hash = JSON.parse(result)
0
+ self.new(hash)
0
         end
0
     end # End class methods
0
     
...
21
22
23
 
24
25
26
...
55
56
57
 
58
59
60
...
92
93
94
 
95
96
97
...
21
22
23
24
25
26
27
...
56
57
58
59
60
61
62
...
94
95
96
97
98
99
100
0
@@ -21,6 +21,7 @@
0
   after(:each) do
0
     # Migration needed for this spec
0
     ActiveCouch::Migrator.delete_database('http://localhost:5984/', 'people')
0
+ Object.send(:remove_const, :Person)
0
   end
0
   
0
   it "should have a class method called after_delete" do
0
@@ -55,6 +56,7 @@
0
   after(:each) do
0
     # Migration needed for this spec
0
     ActiveCouch::Migrator.delete_database('http://localhost:5984/', 'people')
0
+ Object.send(:remove_const, :Person)
0
   end
0
   
0
   it "should execute the block as a param to after_delete" do
0
@@ -92,6 +94,7 @@
0
   after(:each) do
0
     # Migration needed for this spec
0
     ActiveCouch::Migrator.delete_database('http://localhost:5984/', 'people')
0
+ Object.send(:remove_const, :Person)
0
   end
0
   
0
   it "should call before_save in the object passed as a param to after_delete" do
...
23
24
25
 
26
27
28
...
54
55
56
 
57
58
59
...
87
88
89
 
90
91
92
...
23
24
25
26
27
28
29
...
55
56
57
58
59
60
61
...
89
90
91
92
93
94
95
0
@@ -23,6 +23,7 @@
0
   after(:each) do
0
     # Migration needed for this spec
0
     ActiveCouch::Migrator.delete_database('http://localhost:5984/', 'people')
0
+ Object.send(:remove_const, :Person)
0
   end
0
   
0
   it "should have a class method called after_save" do
0
@@ -54,6 +55,7 @@
0
   after(:each) do
0
     # Migration needed for this spec
0
     ActiveCouch::Migrator.delete_database('http://localhost:5984/', 'people')
0
+ Object.send(:remove_const, :Person)
0
   end
0
   
0
   it "should execute the block as a param to after_save" do
0
@@ -87,6 +89,7 @@
0
   after(:each) do
0
     # Migration needed for this spec
0
     ActiveCouch::Migrator.delete_database('http://localhost:5984/', 'people')
0
+ Object.send(:remove_const, :Person)
0
   end
0
   
0
   it "should call before_save in the object passed as a param to after_save" do
...
21
22
23
 
24
25
26
...
55
56
57
 
58
59
60
...
91
92
93
 
94
95
96
...
21
22
23
24
25
26
27
...
56
57
58
59
60
61
62
...
93
94
95
96
97
98
99
0
@@ -21,6 +21,7 @@
0
   after(:each) do
0
     # Migration needed for this spec
0
     ActiveCouch::Migrator.delete_database('http://localhost:5984/', 'people')
0
+ Object.send(:remove_const, :Person)
0
   end
0
   
0
   it "should have a class method called before_save" do
0
@@ -55,6 +56,7 @@
0
   after(:each) do
0
     # Migration needed for this spec
0
     ActiveCouch::Migrator.delete_database('http://localhost:5984/', 'people')
0
+ Object.send(:remove_const, :Person)
0
   end
0
   
0
   it "should execute the block as a param to before_save" do
0
@@ -91,6 +93,7 @@
0
   after(:each) do
0
     # Migration needed for this spec
0
     ActiveCouch::Migrator.delete_database('http://localhost:5984/', 'people')
0
+ Object.send(:remove_const, :Person)
0
   end
0
   
0
   it "should call before_save in the object passed as a param to before_delete" do
...
21
22
23
 
24
25
26
...
52
53
54
 
55
56
57
...
85
86
87
 
88
89
90
...
21
22
23
24
25
26
27
...
53
54
55
56
57
58
59
...
87
88
89
90
91
92
93
0
@@ -21,6 +21,7 @@
0
   after(:each) do
0
     # Migration needed for this spec
0
     ActiveCouch::Migrator.delete_database('http://localhost:5984/', 'people')
0
+ Object.send(:remove_const, :Person)
0
   end
0
   
0
   it "should have a class method called before_save" do
0
@@ -52,6 +53,7 @@
0
   after(:each) do
0
     # Migration needed for this spec
0
     ActiveCouch::Migrator.delete_database('http://localhost:5984/', 'people')
0
+ Object.send(:remove_const, :Person)
0
   end
0
   
0
   it "should execute the block as a param to before_save" do
0
@@ -85,6 +87,7 @@
0
   after(:each) do
0
     # Migration needed for this spec
0
     ActiveCouch::Migrator.delete_database('http://localhost:5984/', 'people')
0
+ Object.send(:remove_const, :Person)
0
   end
0
   
0
   it "should call before_save in the object passed as a param to before_save" do
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
0
@@ -1 +1,76 @@
0
+require File.dirname(__FILE__) + '/../spec_helper.rb'
0
+
0
+describe "ActiveCouch::Base #count method with just simple attributes" do
0
+ before(:each) do
0
+ # Define the model
0
+ class Person < ActiveCouch::Base
0
+ site 'http://localhost:5984'
0
+ has :name
0
+ end
0
+ # Define the migration
0
+ class ByName < ActiveCouch::Migration
0
+ define :for_db => 'people' do
0
+ with_key 'name'
0
+ end
0
+ end
0
+ # Create the database first
0
+ ActiveCouch::Migrator.create_database('http://localhost:5984', 'people')
0
+ # Create a view
0
+ ActiveCouch::Migrator.migrate('http://localhost:5984', ByName)
0
+ # Save an object
0
+ Person.new(:name => 'McLovin').save
0
+ end
0
+
0
+ after(:each) do
0
+ # Delete the database last
0
+ ActiveCouch::Migrator.delete_database('http://localhost:5984', 'people')
0
+ Object.send(:remove_const, :Person)
0
+ end
0
+
0
+ it "should respond to the find method" do
0
+ Person.should respond_to(:count)
0
+ end
0
+
0
+ it "should return an array with one Person object in it, when sent method find with parameter :all" do
0
+ count = Person.count(:params => {:name => 'McLovin'})
0
+ count.should == 1
0
+ end
0
+end
0
+
0
+
0
+describe "ActiveCouch::Base #find method with multiple documents in the CouchDB database" do
0
+ before(:each) do
0
+ class Person < ActiveCouch::Base
0
+ site 'http://localhost:5984'
0
+
0
+ has :first_name
0
+ has :last_name
0
+ end
0
+
0
+ # Define the migration
0
+ class ByLastName < ActiveCouch::Migration
0
+ define :for_db => 'people' do
0
+ with_key 'last_name'
0
+ end
0
+ end
0
+ # Create the database first
0
+ ActiveCouch::Migrator.create_database('http://localhost:5984', 'people')
0
+ # Create a view
0
+ ActiveCouch::Migrator.migrate('http://localhost:5984', ByLastName)
0
+ # Save two objects
0
+ Person.create(:last_name => 'McLovin', :first_name => 'Seth')
0
+ Person.create(:last_name => 'McLovin', :first_name => 'Bob')
0
+ end
0
+
0
+ after(:each) do
0
+ # Delete the database last
0
+ ActiveCouch::Migrator.delete_database('http://localhost:5984', 'people')
0
+ Object.send(:remove_const, :Person)
0
+ end
0
+
0
+ it "should find all objects in the database when find method is sent the param :all" do
0
+ count = Person.count(:params => {:last_name => 'McLovin'})
0
+ count.should == 2
0
+ end
0
+end
...
11
12
13
 
14
15
16
...
11
12
13
14
15
16
17
0
@@ -11,6 +11,7 @@
0
   
0
   after(:each) do
0
     ActiveCouch::Migrator.delete_database('http://localhost:5984/', 'people')
0
+ Object.send(:remove_const, :Person)
0
   end
0
   
0
   it "should have a class method called create" do
...
55
56
57
 
 
 
 
 
58
59
60
...
55
56
57
58
59
60
61
62
63
64
65
0
@@ -55,6 +55,11 @@
0
     end
0
   end
0
 
0
+ after(:all) do
0
+ Object.send(:remove_const, :Parent)
0
+ Object.send(:remove_const, :Child)
0
+ end
0
+
0
   it "should have a base_class of the parent" do
0
     Child.base_class.should == Parent
0
   end
...
12
13
14
 
15
16
17
...
51
52
53
 
54
55
56
...
12
13
14
15
16
17
18
...
52
53
54
55
56
57
58
0
@@ -12,6 +12,7 @@
0
   
0
   after(:each) do
0
     ActiveCouch::Migrator.delete_database('http://localhost:5984/', 'people')
0
+ Object.send(:remove_const, :Person)
0
   end
0
   
0
   it "should have an instance method called delete" do
0
@@ -51,6 +52,7 @@
0
 
0
   after(:each) do
0
     ActiveCouch::Migrator.delete_database('http://localhost:5984/', 'people')
0
+ Object.send(:remove_const, :Person)
0
   end
0
   
0
   it "should have a class method called delete" do
...
24
25
26
 
27
28
29
...
64
65
66
 
67
68
69
...
90
91
92
93
 
 
94
95
96
...
147
148
149
 
 
150
151
152
...
162
163
164
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
165
...
24
25
26
27
28
29
30
...
65
66
67
68
69
70
71
...
92
93
94
 
95
96
97
98
99
...
150
151
152
153
154
155
156
157
...
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
0
@@ -24,6 +24,7 @@
0
   after(:each) do
0
     # Delete the database last
0
     ActiveCouch::Migrator.delete_database('http://localhost:5984', 'people')
0
+ Object.send(:remove_const, :Person)
0
   end
0
 
0
   it "should respond to the find method" do
0
@@ -64,6 +65,7 @@
0
   end
0
 end
0
 
0
+
0
 describe "ActiveCouch::Base #find method with multiple documents in the CouchDB database" do
0
   before(:each) do
0
     class Person < ActiveCouch::Base
0
@@ -90,7 +92,8 @@
0
   
0
   after(:each) do
0
     # Delete the database last
0
- ActiveCouch::Migrator.delete_database('http://localhost:5984', 'people')
0
+ ActiveCouch::Migrator.delete_database('http://localhost:5984', 'people')
0
+ Object.send(:remove_const, :Person)
0
   end
0
   
0
   it "should find all objects in the database when find method is sent the param :all" do
0
@@ -147,6 +150,8 @@
0
   after(:each) do
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
   end
0
   
0
   it "should be able to retrieve the simple attributes" do
0
@@ -162,5 +167,73 @@
0
     (blog.comments.inspect =~ /ya rly!/).should_not == nil
0
   end
0
   
0
+end
0
+
0
+describe "ActiveCouch::Base #find method with no params passed" do
0
+ before(:each) do
0
+ class Person < ActiveCouch::Base
0
+ site 'http://localhost:5984/'
0
+ has :name
0
+ end
0
+ # Define the migration
0
+ class ByName < ActiveCouch::Migration
0
+ define :for_db => 'people' do
0
+ with_key 'name'
0
+ end
0
+ end
0
+ # Create the database first
0
+ ActiveCouch::Migrator.create_database('http://localhost:5984', 'people')
0
+ # Create a view
0
+ ActiveCouch::Migrator.migrate('http://localhost:5984', ByName)
0
+ # Save two objects
0
+ Person.create(:name => 'McLovin')
0
+ Person.create(:name => 'Seth')
0
+ end
0
+
0
+ after(:each) do
0
+ # Delete the database last
0
+ ActiveCouch::Migrator.delete_database('http://localhost:5984', 'people')
0
+ Object.send(:remove_const, :Person)
0
+ end
0
+
0
+ it "should return all documents if passed :all, with no params specified"
0
+end
0
+
0
+
0
+describe "ActiveCouch::Base #find method with an ID passed" do
0
+ before(:each) do
0
+ class Person < ActiveCouch::Base
0
+ site 'http://localhost:5984/'
0
+ has :name
0
+ end
0
+ # Define the migration
0
+ class ByName < ActiveCouch::Migration
0
+ define :for_db => 'people' do
0
+ with_key 'name'
0
+ end
0
+ end
0
+ # Create the database first
0
+ ActiveCouch::Migrator.create_database('http://localhost:5984', 'people')
0
+ # Create a view
0
+ ActiveCouch::Migrator.migrate('http://localhost:5984', ByName)
0
+ # Save two objects
0
+ Person.create(:name => 'McLovin', :id => '123')
0
+ end
0
+
0
+ after(:each) do
0
+ # Delete the database last
0
+ ActiveCouch::Migrator.delete_database('http://localhost:5984', 'people')
0
+ Object.send(:remove_const, :Person)
0
+ end
0
+
0
+ it "should return an ActiveCouch::Base object if the ID exists" do
0
+ person = Person.find('123')
0
+ person.name.should == 'McLovin'
0
+ end
0
+
0
+ it "should return nil if the ID does not exist" do
0
+ person = Person.find('321')
0
+ person.should == nil
0
+ end
0
 end
...
1
2
3
4
 
5
6
7
...
17
18
19
 
 
 
 
 
 
20
21
22
...
1
2
3
 
4
5
6
7
...
17
18
19
20
21
22
23
24
25
26
27
28
0
@@ -1,7 +1,7 @@
0
 require File.dirname(__FILE__) + '/../spec_helper.rb'
0
 
0
 describe "ActiveCouch::Base #from_json method, with many attributes" do
0
- before(:each) do
0
+ before(:all) do
0
     class Hotel < ActiveCouch::Base
0
       has :name, :which_is => :text, :with_default_value => "Swissotel The Stamford"
0
       has :star_rating, :which_is => :decimal, :with_default_value => 5.0
0
@@ -17,6 +17,12 @@
0
       has_many :hospitals
0
     end
0
   end
0
+
0
+ after(:all) do
0
+ Object.send(:remove_const, :Hotel)
0
+ Object.send(:remove_const, :Hospital)
0
+ Object.send(:remove_const, :CrazyPerson)
0
+ end
0
   
0
   it "should have the from_json method" do
0
     Hotel.should respond_to(:from_json)
...
20
21
22
 
 
 
 
 
 
23
24
25
...
60
61
62
 
 
 
 
 
63
64
65
...
20
21
22
23
24
25
26
27
28
29
30
31
...
66
67
68
69
70
71
72
73
74
75
76
0
@@ -20,6 +20,12 @@
0
     @a1 = AgedPerson.new
0
   end
0
   
0
+ after(:each) do
0
+ Object.send(:remove_const, :Person)
0
+ Object.send(:remove_const, :AgedPerson)
0
+ Object.send(:remove_const, :Contact)
0
+ end
0
+
0
   it "should have an instance variable called associations which is a Hash with the key being :people" do
0
     Contact.associations.class.should == Hash
0
     Contact.associations.keys.should == [:people]
0
@@ -60,6 +66,11 @@
0
     @blog = Blog.new(:title => 'Lolcats Primer', :comments => [@comment1, @comment2])
0
     @blog1 = Blog.new(:title => 'Lolcats Primer The Sequel', :comments => [{:body => 'can'}, {:body => 'haz'}])
0
   end
0
+
0
+ after(:each) do
0
+ Object.send(:remove_const, :Comment)
0
+ Object.send(:remove_const, :Blog)
0
+ end
0
   
0
   it "should be able to initialize with a hash which contains descendents of ActiveCouch::Base" do
0
     @comment1.body.should == "I can haz redbull?"
...
5
6
7
8
 
9
10
11
 
 
 
 
12
13
14
...
30
31
32
 
 
 
 
33
34
35
...
51
52
53
 
 
 
 
54
55
56
...
5
6
7
 
8
9
10
11
12
13
14
15
16
17
18
...
34
35
36
37
38
39
40
41
42
43
...
59
60
61
62
63
64
65
66
67
68
0
@@ -5,10 +5,14 @@
0
     class Person < ActiveCouch::Base
0
       has :name, :which_is => :text
0
     end
0
-
0
+ # Initialize a new Person object
0
     @p = Person.new
0
   end
0
   
0
+ after(:each) do
0
+ Object.send(:remove_const, :Person)
0
+ end
0
+
0
   it "should have a method called name which returns the value of the variable name" do
0
     @p.should respond_to(:name)
0
     @p.name.should == ""
0
@@ -30,6 +34,10 @@
0
     @n = NamedPerson.new
0
   end
0
   
0
+ after(:each) do
0
+ Object.send(:remove_const, :NamedPerson)
0
+ end
0
+
0
   it "should have a method called name which returns the value of the variable name" do
0
     @n.should respond_to(:name)
0
     @n.name.should == "McLovin"
0
@@ -51,6 +59,10 @@
0
     
0
     @a = AgedPerson.new
0
   end
0
+
0
+ after(:each) do
0
+ Object.send(:remove_const, :AgedPerson)
0
+ end
0
 
0
   it "should have an instance variable called attributes which is a Hash with the keys being :name, :age" do
0
     AgedPerson.attributes.class.should == Hash
...
1
2
3
4
 
5
6
7
8
9
10
 
 
 
 
11
12
13
...
1
2
3
 
4
5
6
7
 
8
9
10
11
12
13
14
15
16
0
@@ -1,13 +1,16 @@
0
 require File.dirname(__FILE__) + '/../spec_helper.rb'
0
 
0
 describe "An object instantiated from the subclass of ActiveCouch::Base" do
0
- before(:each) do
0
+ before(:all) do
0
     class Person < ActiveCouch::Base
0
       has :name, :which_is => :text
0
     end
0
-
0
     @person = Person.new
0
   end
0
+
0
+ after(:all) do
0
+ Object.send(:remove_const, :Person)
0
+ end
0
 
0
   it "should have accessors for the id attribute" do
0
     @person.should respond_to(:id)
...
1
2
3
4
 
5
6
7
8
9
 
 
 
 
10
11
12
13
...
14
15
16
17
 
18
19
20
21
22
23
 
 
 
 
24
25
26
27
...
29
30
31
32
 
33
34
35
36
 
 
 
 
37
38
39
...
1
2
3
 
4
5
6
7
8
9
10
11
12
13
14
15
16
17
...
18
19
20
 
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
...
37
38
39
 
40
41
42
43
44
45
46
47
48
49
50
51
0
@@ -1,12 +1,16 @@
0
 require File.dirname(__FILE__) + '/../spec_helper.rb'
0
 
0
 describe "ActiveCouch::Base #new method with a hash containing one key-value pair" do
0
- before(:each) do
0
+ before(:all) do
0
     class Person < ActiveCouch::Base
0
       has :name
0
     end
0
   end
0
 
0
+ after(:all) do
0
+ Object.send(:remove_const, :Person)
0
+ end
0
+
0
   it "should be able to initialize attributes correctly from a hash" do
0
     p = Person.new(:name => 'McLovin')
0
     p.name.should == 'McLovin'
0
0
@@ -14,13 +18,17 @@
0
 end
0
 
0
 describe "ActiveCouch::Base #new method with a hash containing more than one key-value pair" do
0
- before(:each) do
0
+ before(:all) do
0
     class Person < ActiveCouch::Base
0
       has :name
0
       has :age, :which_is => :number, :with_default_value => 25
0
     end
0
   end
0
   
0
+ after(:all) do
0
+ Object.send(:remove_const, :Person)
0
+ end
0
+
0
   it "should be able to initialize attributes correctly from the hash" do
0
     p = Person.new(:name => 'McLovin', :age => 12)
0
     p.name.should == 'McLovin'
0
0
@@ -29,11 +37,15 @@
0
 end
0
 
0
 describe "ActiveCouch::Base #new method with a hash containing a CouchDB reserved attribute" do
0
- before(:each) do
0
+ before(:all) do
0
     class Person < ActiveCouch::Base
0
       has :name
0
     end
0
   end
0
+
0
+ after(:all) do
0
+ Object.send(:remove_const, :Person)
0
+ end
0
   
0
   it "should be able to initialize attributes correclty from the has, including CouchDB reserved attributes" do
0
     p = Person.new(:name => 'McLovin', :id => '123')
...
1
2
3
4
 
5
6
7
8
9
10
 
 
 
 
11
12
13
...
1
2
3
 
4
5
6
7
8
9
10
11
12
13
14
15
16
17
0
@@ -1,13 +1,17 @@
0
 require File.dirname(__FILE__) + '/../spec_helper.rb'
0
 
0
 describe "An object instantiated from the subclass of ActiveCouch::Base" do
0
- before(:each) do
0
+ before(:all) do
0
     class Person < ActiveCouch::Base
0
       has :name, :which_is => :text
0
     end
0
     
0
     @person = Person.new
0
   end
0
+
0
+ after(:all) do
0
+ Object.send(:remove_const, :Person)
0
+ end
0
 
0
   it "should have reader/writer for the rev attribute" do
0
     @person.should respond_to(:rev)