leanback 0.2.7 → 0.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -214,6 +214,8 @@ Leanback parses the native JSON results to return only the data values.
214
214
  # => [{"_id"=>"Nancy", "_rev"=>"2-4404d0a5a1a3dff103fd46faf1e46c30", "firstname"=>"Nancy", "lastname"=>"Lee",
215
215
  "phone"=>"347-808-3734", "email"=>"nancy@mail.com", "gender"=>"female", "age"=>"36"}]
216
216
 
217
+ The above example will return all contacts with age = 36.
218
+
217
219
  This is similar to sending a
218
220
  GET http://127.0.0.1:5984/[database]/_design/[design_doc]/_view/[view_name]?key="searchterm"
219
221
  For the above example
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.7
1
+ 0.2.8
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{leanback}
8
- s.version = "0.2.7"
8
+ s.version = "0.2.8"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Obi Akubue"]
12
- s.date = %q{2011-08-04}
12
+ s.date = %q{2011-09-14}
13
13
  s.description = %q{lightweight Ruby interface to CouchDB}
14
14
  s.email = %q{obioraakubue@yahoo.com}
15
15
  s.extra_rdoc_files = [
@@ -9,77 +9,85 @@ class TestLeanback < Test::Unit::TestCase
9
9
 
10
10
 
11
11
  should "create a database if it doesn't already exist" do
12
- hash = Couchdb.create 'staff'
13
- #puts hash.inspect
12
+ hash = Couchdb.create 'staff'
13
+ assert_equal '{"ok"=>true}', hash.to_s
14
+ response = RestClient.get 'http://127.0.0.1:5984/_all_dbs', {:content_type => :json}
15
+ assert_equal true,response.include?("staff")
14
16
  end
15
17
 
16
18
  should "create a database if it doesn't already exist, and handle exception if it exists" do
17
19
  begin
18
20
  hash = Couchdb.create 'contacts'
19
- #puts hash.inspect
21
+ assert_equal '{"ok"=>true}', hash.to_s
20
22
  rescue => e
21
- #puts "Error message: " + e.to_s
22
- #puts "Error value: " + e.error
23
+ assert_equal "CouchDB: Error - file_exists. Reason - The database could not be created, the file already exists.", e.to_s
24
+ assert_equal "file_exists", e.error
23
25
  end
24
26
  end
25
27
 
26
- should "delete a database that doesn't exist and handle the exception" do
28
+ should "try to delete a database that doesn't exist and handle the exception" do
27
29
  begin
28
30
  hash = Couchdb.delete 'buildings'
29
31
  #puts hash.inspect
30
32
  rescue CouchdbException => e
31
- #puts "Error message: " + e.to_s
32
- #puts "Error value: " + e.error
33
+ assert_equal "CouchDB: Error - not_found. Reason - missing", e.to_s
34
+ assert_equal "not_found", e.error
33
35
  end
34
36
  end
35
37
 
36
38
  should "add a finder method to the database or handle exception if a finder already exists" do
37
- begin
38
39
  hash = Couchdb.add_finder(:database => 'contacts', :key => 'email')
39
- #puts hash.inspect
40
- rescue CouchdbException => e
41
- #puts e.to_s
42
- #puts e.error
43
- end
40
+ assert_equal true,hash.include?("_design/email_finder")
41
+ assert_equal true,hash.include?("true")
42
+ assert_equal true,hash.include?("rev")
43
+
44
+ doc = {:database => 'contacts', :doc_id => '_design/email_finder'}
45
+ hash = Couchdb.view doc
46
+ assert_equal '_design/email_finder', hash["_id"]
44
47
  end
45
48
 
46
49
  should "find items by key" do
47
50
  #docs = Couchdb.find_by( :database => 'contacts', :email => 'nancy@mail.com')
48
51
  docs = Couchdb.find_by( :database => 'contacts', :lastname => 'smith')
49
52
  #docs = Couchdb.find_by( :database => 'contacts', :country => 'female')
50
- #puts docs.inspect
53
+
54
+ d = docs[0]
55
+ assert_equal "smith", d["lastname"]
51
56
  end
52
57
 
53
- should "view document doc or handle exception" do
58
+ should "create and view document doc" do
59
+
60
+ data = {:firstname => 'John',
61
+ :lastname =>'smith',
62
+ :phone => '202-234-1234',
63
+ :email =>'james@mail.com',
64
+ :age =>'34',
65
+ :gender =>'male'}
66
+
67
+ doc = {:database => 'contacts', :doc_id => 'john', :data => data}
68
+ Document.create doc
54
69
 
55
- doc = {:database => 'monitors', :doc_id => '3-d71c8ee21d6753896f2d08f57a985e94'}
56
- begin
70
+ doc = {:database => 'contacts', :doc_id => 'john'}
57
71
  hash = Couchdb.view doc
58
- #puts hash.inspect
59
- rescue CouchdbException => e
60
- #puts e.inspect
61
- #puts e.error
62
- end
72
+ assert_equal 'john', hash["_id"]
63
73
  end
64
74
 
65
75
  should "Query a permanent view that doesn't exist and handle exception" do
66
76
  begin
67
- #puts 'viewing design doc...'
68
77
  view = { :database => "contacts", :design_doc => 'more_views', :view => 'get_user_email'}
69
- hash = Couchdb.find view
70
- #puts hash.inspect
78
+ Couchdb.find view
71
79
  rescue CouchdbException => e
72
- # puts "Error message: " + e.to_s
73
- # puts "Error value: " + e.error
80
+ assert_equal "CouchDB: Error - not_found. Reason - missing_named_view", e.to_s
81
+ assert_equal "not_found", e.error
74
82
  end
75
83
  end
76
84
 
77
85
 
78
86
  should "Query a permanent view" do
79
87
  view = { :database => "contacts", :design_doc => 'more_views', :view => 'get_email'}
80
- #puts 'viewing design doc...'
81
- hash = Couchdb.find view
82
- #puts hash.inspect
88
+ docs = Couchdb.find view
89
+ assert_equal true,docs[0].include?("Email")
90
+ assert_equal true,docs[0].include?("Lastname")
83
91
  end
84
92
 
85
93
 
@@ -88,9 +96,14 @@ class TestLeanback < Test::Unit::TestCase
88
96
  :design_doc => 'my_views',
89
97
  :view => 'get_emails',
90
98
  :json_doc => '/home/obi/bin/my_views.json'}
91
-
92
- hash = Couchdb.find_on_fly(view)
93
- #puts hash.inspect
99
+
100
+ docs = Couchdb.find_on_fly(view)
101
+ assert_equal true,docs[0].include?("Email")
102
+ assert_equal true,docs[0].include?("Name")
103
+ #verify that the view was created
104
+ doc = {:database => 'contacts', :doc_id => '_design/my_views'}
105
+ hash = Couchdb.view doc
106
+ assert_equal '_design/my_views', hash["_id"]
94
107
  end
95
108
 
96
109
  should "Query a permanent view by key and create the view on the fly, if it doesn't already exist" do
@@ -100,82 +113,112 @@ class TestLeanback < Test::Unit::TestCase
100
113
  :json_doc => '/home/obi/bin/view_age.json'}
101
114
 
102
115
  age = '36'
103
- hash = Couchdb.find_on_fly(view,key = age)
104
- puts hash.inspect
116
+ docs = Couchdb.find_on_fly(view,key = age)
117
+ assert_equal true,docs[0].include?("age")
118
+ d = docs[0]
119
+ assert_equal '36', d["age"]
120
+ #verify that the view was created
121
+ doc = {:database => 'contacts', :doc_id => '_design/the_view'}
122
+ hash = Couchdb.view doc
123
+ assert_equal '_design/the_view', hash["_id"]
105
124
  end
106
125
 
107
126
  should "Create a design doc/permanent view or handle exception" do
108
127
  doc = { :database => 'contacts', :design_doc => 'more_views', :json_doc => '/home/obi/bin/leanback/test/my_views.json' }
109
- begin
110
128
  hash = Couchdb.create_design doc
111
- #puts hash.inspect
112
- rescue CouchdbException => e
113
- #puts e.to_s
114
- #puts e.error
115
- end
129
+ assert_equal '_design/more_views', hash["id"]
130
+ assert_equal true, hash["ok"]
131
+
132
+ doc = {:database => 'contacts', :doc_id => '_design/more_views'}
133
+ hash = Couchdb.view doc
134
+ assert_equal '_design/more_views', hash["_id"]
116
135
  end
117
136
 
118
137
  should "return a display a list of all databases" do
119
138
  databases = Couchdb.all
120
- databases.each do |db_name|
121
- # puts db_name
122
- end
139
+ assert_equal true,databases.include?("contacts")
123
140
  end
124
141
 
125
142
  should "delete a database" do
126
143
  hash = Couchdb.delete 'staff'
127
- #puts hash.inspect
144
+ assert_equal true, hash["ok"]
145
+ response = RestClient.get 'http://127.0.0.1:5984/_all_dbs', {:content_type => :json}
146
+ assert_equal false,response.include?("staff")
128
147
  end
129
148
 
130
149
  should "create a document and handle exception if one occurs" do
131
- begin
132
150
  data = {:firstname => 'Nancy', :lastname =>'Lee', :phone => '347-808-3734',:email =>'nancy@mail.com',:gender => 'female'}
133
151
  doc = {:database => 'contacts', :doc_id => 'Nancy', :data => data}
134
- hash = Document.create doc
135
- #puts hash.inspect
136
- rescue CouchdbException => e
137
- #puts e.to_s
138
- #puts e.error
139
- end
152
+ hash = Document.create doc
153
+ assert_equal 'Nancy', hash["id"]
154
+ assert_equal true, hash["ok"]
155
+
156
+ doc = {:database => 'contacts', :doc_id => 'Nancy'}
157
+ hash = Couchdb.view doc
158
+ assert_equal 'Nancy', hash["_id"]
159
+ assert_equal 'Nancy', hash["firstname"]
160
+ assert_equal 'Lee', hash["lastname"]
161
+ assert_equal '347-808-3734', hash["phone"]
140
162
  end
141
163
 
142
164
  should "update the document" do
143
165
  #data = {"age" => "42", "lastname" => "arnold", "phone" => "202-456-1234", "hobbies" => "football,running, video gamess" }
144
166
  data = {:age => "41", :lastname => "Stevens" }
145
167
  doc = { :database => 'contacts', :doc_id => 'john', :data => data}
146
- Document.update doc
168
+ hash = Document.update doc
169
+ assert_equal 'john', hash["id"]
170
+ assert_equal true, hash["ok"]
171
+
172
+ doc = {:database => 'contacts', :doc_id => 'john'}
173
+ hash = Couchdb.view doc
174
+ assert_equal 'john', hash["_id"]
175
+ assert_equal '41', hash["age"]
176
+ assert_equal 'Stevens', hash["lastname"]
177
+ Document.delete :database => 'contacts', :doc_id => 'john'
178
+ end
179
+
180
+ should "delete sample documents - ready for next test run" do
181
+ Document.delete :database => 'contacts', :doc_id => 'Nancy'
182
+ Document.delete :database => 'contacts', :doc_id => '_design/more_views'
183
+ Document.delete :database => 'contacts', :doc_id => '_design/the_view'
184
+ Document.delete :database => 'contacts', :doc_id => '_design/my_views'
185
+ Document.delete :database => 'contacts', :doc_id => '_design/email_finder'
147
186
  end
148
187
 
149
188
  should "edit a document - handle exceptions" do
150
189
  begin
190
+ #see delete without _rev above
151
191
  data = {:firstname => 'john', :lastname =>'smith', :email => 'john@mail.com',:gender=>'male', :_rev=>'2-e813a0e902e3ac114400ff3959a2adde'}
152
192
  doc = {:database => 'contacts', :doc_id => 'john', :data => data}
153
193
  hash = Document.edit doc
154
194
  #puts hash.inspect
155
195
  rescue CouchdbException => e
156
- #puts e.to_s
157
- #puts e.error
196
+ assert_equal "CouchDB: Error - conflict. Reason - Document update conflict.", e.to_s
197
+ assert_equal "conflict", e.error
158
198
  end
159
199
  end
160
200
 
161
- should "create and delete a document -- any handle exceptions" do
162
- begin
163
-
164
- data = {:firstname => 'James',
201
+ should "create and delete a document" do
202
+ data = {:firstname => 'Sun',
165
203
  :lastname =>'Nova',
166
204
  :phone => '212-234-1234',
167
205
  :email =>'james@mail.com'}
168
206
 
169
- doc = {:database => 'contacts', :doc_id => 'james', :data => data}
170
- #Document.create doc
207
+ doc = {:database => 'contacts', :doc_id => 'Sun', :data => data}
208
+ Document.create doc
171
209
 
172
- doc = {:database => 'contacts', :doc_id => 'James'}
210
+ doc = {:database => 'contacts', :doc_id => 'Sun'}
173
211
  hash = Document.delete doc
174
- #puts hash.inspect
175
- rescue CouchdbException => e
176
- #puts e.to_s
177
- #puts e.error
178
- end
212
+
213
+ assert_equal 'Sun', hash["id"]
214
+ assert_equal true, hash["ok"]
215
+ begin
216
+ doc = {:database => 'contacts', :doc_id => 'Sun'}
217
+ Couchdb.view doc
218
+ rescue CouchdbException => e
219
+ assert_equal "CouchDB: Error - not_found. Reason - deleted", e.to_s
220
+ assert_equal "not_found", e.error
221
+ end
179
222
  end
180
223
 
181
224
  should "delete a document with revision number - any handle exceptions" do
@@ -184,17 +227,17 @@ class TestLeanback < Test::Unit::TestCase
184
227
  hash = Document.delete_rev doc
185
228
  #puts hash.inspect
186
229
  rescue CouchdbException => e
187
- #puts e.to_s
188
- #puts e.error
230
+ assert_equal "CouchDB: Error - conflict. Reason - Document update conflict.", e.to_s
231
+ assert_equal "conflict", e.error
189
232
  end
190
233
  end
191
234
 
192
- should "display all documents in the database that doesn't exist and handle exception" do
235
+ should "attempt to display all documents in the database that doesn't exist and handle exception" do
193
236
  begin
194
237
  docs = Couchdb.docs_from 'buildings'
195
238
  rescue CouchdbException => e
196
- #puts e.to_s
197
- #puts e.error
239
+ assert_equal "CouchDB: Error - not_found. Reason - no_db_file", e.to_s
240
+ assert_equal "not_found", e.error
198
241
  end
199
242
  end
200
243
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 7
9
- version: 0.2.7
8
+ - 8
9
+ version: 0.2.8
10
10
  platform: ruby
11
11
  authors:
12
12
  - Obi Akubue
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-08-04 00:00:00 -04:00
17
+ date: 2011-09-14 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -136,7 +136,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
136
136
  requirements:
137
137
  - - ">="
138
138
  - !ruby/object:Gem::Version
139
- hash: -441250723
139
+ hash: -211762291
140
140
  segments:
141
141
  - 0
142
142
  version: "0"