public
Fork of halfbyte/couchobject
Description: Library to access couchdb in ruby
Homepage: http://couchobject.rubyforge.org
Clone URL: git://github.com/jnunemaker/couchobject.git
Search Repo:
added some flexibility to a few methods and fixed some specs
jnunemaker (author)
Wed May 07 19:28:00 -0700 2008
commit  890950623ff813b2ea42879d51da5950b29eb366
tree    5ad6ea3c2696aa319ff0064f0fe3d4016a00bd2f
parent  bbc27f6f205990f1035cb42633ec142404313d01
...
39
40
41
42
 
43
44
45
46
47
 
48
49
50
51
52
 
53
54
55
...
39
40
41
 
42
43
44
45
46
 
47
48
49
50
51
 
52
53
54
55
0
@@ -39,17 +39,17 @@
0
     
0
     # Look up an attribute by +key+
0
     def [](key)
0
- attributes[key]
0
+ attributes[key.to_s]
0
     end
0
     
0
     # Set an attributes by +key+ to +value+
0
     def []=(key, value)
0
- attributes[key] = value
0
+ attributes[key.to_s] = value
0
     end
0
     
0
     # is the attribute +key+ in this document?
0
     def has_key?(key)
0
- attributes.has_key?(key)
0
+ attributes.has_key?(key.to_s)
0
     end
0
 
0
     # is the attribute +key+ in this document?
...
37
38
39
40
 
41
42
43
44
45
 
46
47
48
...
71
72
73
74
 
75
76
77
78
79
80
...
106
107
108
109
 
 
 
 
 
 
110
111
112
113
114
115
116
117
118
119
 
 
 
 
 
 
 
 
 
120
121
122
123
 
 
 
 
 
 
 
 
 
 
 
 
124
125
126
127
 
 
 
 
 
 
128
129
130
...
37
38
39
 
40
41
42
43
44
 
45
46
47
48
...
71
72
73
 
74
75
76
77
78
79
80
...
106
107
108
 
109
110
111
112
113
114
115
116
117
118
119
120
 
 
 
 
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
0
@@ -37,12 +37,12 @@
0
     doc.id.should == "fubar"
0
   end
0
   
0
- it "should should be new? if there's an id attribute" do
0
+ it "should not be new? if there's an id attribute" do
0
     doc = CouchObject::Document.new(@test_data)
0
     doc.new?.should == false
0
   end
0
   
0
- it "should not be new if there's not original id" do
0
+ it "should be new if there's not original id" do
0
     doc = CouchObject::Document.new({"foo" => "bar"})
0
     doc.new?.should == true
0
   end
0
@@ -71,7 +71,7 @@
0
     doc.save(@db)
0
   end
0
   
0
- it "should PUT to the database with create" do
0
+ it "should PUT to the database with update" do
0
     doc = CouchObject::Document.new(@test_data)
0
     doc.should_receive(:to_json).and_return("JSON")
0
     @db.should_receive(:put).with(@test_data["_id"], "JSON").and_return(@response)
0
0
0
0
@@ -106,25 +106,53 @@
0
     doc["foo"].should == "bar"
0
   end
0
   
0
- it "should assign document attributes witih []=" do
0
+ it "should lookup document attributes with [] using a symbol" do
0
+ doc = CouchObject::Document.new({"foo" => "bar"})
0
+ doc[:foo].should == "bar"
0
+ end
0
+
0
+ it "should assign document attributes with []=" do
0
     doc = CouchObject::Document.new
0
     doc["foo"].should == nil
0
     doc["foo"] = "bar"
0
     doc["foo"].should == "bar"
0
   end
0
   
0
- it "should delegate missing methods to attributes" do
0
- doc = CouchObject::Document.new({"foo" => "bar", "stuff" => true })
0
- doc.foo.should == "bar"
0
- doc.stuff?.should == true
0
+ it "should assign document attributes with []= using a symbol" do
0
+ doc = CouchObject::Document.new
0
+ doc[:foo].should == nil
0
+ doc[:foo] = "bar"
0
+ doc[:foo].should == "bar"
0
+ end
0
+
0
+ it "should delegate missing assignment methods to attributes" do
0
+ doc = CouchObject::Document.new({"foo" => "bar"})
0
     proc{ doc.foo = "baz" }.should_not raise_error
0
     doc.foo.should == "baz"
0
   end
0
   
0
+ it "should delegate missing boolean methods to attributes" do
0
+ doc = CouchObject::Document.new({"foo" => true})
0
+ doc.foo?.should == true
0
+ doc.foo = false
0
+ doc.foo?.should == false
0
+ end
0
+
0
+ it "should delegate missing reader methods to attributes" do
0
+ doc = CouchObject::Document.new({"foo" => "bar"})
0
+ doc.foo.should == "bar"
0
+ end
0
+
0
   it "should know if it has a given document key" do
0
     doc = CouchObject::Document.new({"foo" => "bar"})
0
     doc.has_key?("foo").should == true
0
     doc.has_key?("bar").should == false
0
+ end
0
+
0
+ it "should know if it has a given document key using a symbol" do
0
+ doc = CouchObject::Document.new({"foo" => "bar"})
0
+ doc.has_key?(:foo).should == true
0
+ doc.has_key?(:bar).should == false
0
   end
0
   
0
   it "should know if it reponds to a key in the attributes" do

Comments

    No one has commented yet.