[activecouch commit] r66 - in trunk: active_couch spec/base

0 views
Skip to first unread message

codesite...@google.com

unread,
Jan 22, 2008, 10:38:46 AM1/22/08
to activ...@googlegroups.com
Author: arun.thampi
Date: Tue Jan 22 07:38:32 2008
New Revision: 66

Modified:
trunk/active_couch/base.rb
trunk/spec/base/before_delete_spec.rb
trunk/spec/base/initialize_spec.rb

Log:
- Fixed bug in ticket 27 (http://code.google.com/p/activecouch/issues/list)
- Added specs for ActiveCouch::Base#new

Modified: trunk/active_couch/base.rb
==============================================================================
--- trunk/active_couch/base.rb (original)
+++ trunk/active_couch/base.rb Tue Jan 22 07:38:32 2008
@@ -450,7 +450,7 @@
elsif v.is_a?(Hash) # This means this is a has_one
association (which we might add later)
# Do nothing for now. More later
else # This means this is a normal attribute
- self.send("#{k}=", v) if @attributes.has_key?(k)
+ self.send("#{k}=", v) if respond_to?("#{k}=") #
@attributes.has_key?(k) || @attributes.has_key?("_#{k}")
end
end
end

Modified: trunk/spec/base/before_delete_spec.rb
==============================================================================
--- trunk/spec/base/before_delete_spec.rb (original)
+++ trunk/spec/base/before_delete_spec.rb Tue Jan 22 07:38:32 2008
@@ -29,8 +29,7 @@

it "should call the method specified as an argument to
before_delete, *before* deleting the object from CouchDB" do
# First save the object
- p = Person.create(:name => 'McLovin')
- p.age = 10
+ p = Person.create(:name => 'McLovin', :age => 10)
# Before deleting, age must be 10
p.age.should == 10
# Delete the object, and...

Modified: trunk/spec/base/initialize_spec.rb
==============================================================================
--- trunk/spec/base/initialize_spec.rb (original)
+++ trunk/spec/base/initialize_spec.rb Tue Jan 22 07:38:32 2008
@@ -0,0 +1,43 @@
+require File.dirname(__FILE__) + '/../spec_helper.rb'
+
+describe "ActiveCouch::Base #new method with a hash containing one
key-value pair" do
+ before(:each) do
+ class Person < ActiveCouch::Base
+ has :name
+ end
+ end
+
+ it "should be able to initialize attributes correctly from a hash" do
+ p = Person.new(:name => 'McLovin')
+ p.name.should == 'McLovin'
+ end
+end
+
+describe "ActiveCouch::Base #new method with a hash containing more
than one key-value pair" do
+ before(:each) do
+ class Person < ActiveCouch::Base
+ has :name
+ has :age, :which_is => :number, :with_default_value => 25
+ end
+ end
+
+ it "should be able to initialize attributes correctly from the hash" do
+ p = Person.new(:name => 'McLovin', :age => 12)
+ p.name.should == 'McLovin'
+ p.age.should == 12
+ end
+end
+
+describe "ActiveCouch::Base #new method with a hash containing a
CouchDB reserved attribute" do
+ before(:each) do
+ class Person < ActiveCouch::Base
+ has :name
+ end
+ end
+
+ it "should be able to initialize attributes correclty from the has,
including CouchDB reserved attributes" do
+ p = Person.new(:name => 'McLovin', :id => '123')
+ p.name.should == 'McLovin'
+ p.id.should == '123'
+ end
+end
\ No newline at end of file

codesite...@google.com

unread,
Jan 22, 2008, 10:38:46 AM1/22/08
to activ...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages