leanback 0.4.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.travis.yml +10 -0
- data/Gemfile +5 -6
- data/Gemfile.lock +65 -14
- data/README.md +465 -33
- data/Rakefile +8 -17
- data/VERSION +1 -1
- data/leanback.gemspec +26 -85
- data/lib/leanback.rb +129 -587
- data/spec/leanback_spec.rb +356 -0
- metadata +40 -117
- data/Changelog.rdoc +0 -146
- data/documentation/static/2011/11/20/i-moved-leanback-documentation/index.html +0 -180
- data/documentation/static/2011/11/20/index.html +0 -146
- data/documentation/static/2011/11/index.html +0 -146
- data/documentation/static/2011/index.html +0 -146
- data/documentation/static/2013/06/02/index.html +0 -146
- data/documentation/static/2013/06/02/released-leanback-v0-3-4/index.html +0 -180
- data/documentation/static/2013/06/09/index.html +0 -146
- data/documentation/static/2013/06/09/released-leanback-v0-4-0/index.html +0 -179
- data/documentation/static/2013/06/index.html +0 -158
- data/documentation/static/2013/index.html +0 -158
- data/documentation/static/author/admin/index.html +0 -175
- data/documentation/static/basic-couchdb-operations/index.html +0 -259
- data/documentation/static/category/uncategorized/index.html +0 -170
- data/documentation/static/couchdb-configuration/index.html +0 -189
- data/documentation/static/couchdb-security/index.html +0 -218
- data/documentation/static/count-by-multiple-documents/index.html +0 -221
- data/documentation/static/count-documents-by-key/index.html +0 -177
- data/documentation/static/css/2c-l-fixed.css +0 -1
- data/documentation/static/css/2c-l-fixed.dev.css +0 -62
- data/documentation/static/css/2c-r-fixed.css +0 -1
- data/documentation/static/css/2c-r-fixed.dev.css +0 -60
- data/documentation/static/css/3c-c-fixed.css +0 -1
- data/documentation/static/css/3c-c-fixed.dev.css +0 -84
- data/documentation/static/css/3c-l-fixed.css +0 -1
- data/documentation/static/css/3c-l-fixed.dev.css +0 -61
- data/documentation/static/css/3c-r-fixed.css +0 -1
- data/documentation/static/css/3c-r-fixed.dev.css +0 -62
- data/documentation/static/css/holy-grail-fluid.css +0 -5
- data/documentation/static/css/plugins.css +0 -5
- data/documentation/static/css/print.css +0 -5
- data/documentation/static/css/screen.css +0 -1
- data/documentation/static/design-documents-and-permanent-views/index.html +0 -454
- data/documentation/static/error-handling/index.html +0 -157
- data/documentation/static/find-document-by-multiple-keys/index.html +0 -269
- data/documentation/static/find-documents-by-key/index.html +0 -243
- data/documentation/static/index.html +0 -161
- data/documentation/static/leanback/index.html +0 -130
- data/documentation/static/leanback/installation/index.html +0 -119
- data/documentation/static/setting-the-bind_address-port/index.html +0 -151
- data/documentation/static/style.css +0 -16
- data/spec/admin_party/database_spec.rb +0 -400
- data/spec/no_admin_party/cloudant_spec.rb +0 -365
- data/spec/no_admin_party/database_spec.rb +0 -491
- data/spec/no_admin_party/non_admin_user_spec.rb +0 -67
- data/test/helper.rb +0 -18
- data/test/main.rb +0 -295
- data/test/my_view.json +0 -8
- data/test/my_views.json +0 -8
- data/test/start.json +0 -8
- data/test/test_leanback.rb +0 -319
- data/test/view_age.json +0 -8
@@ -1,67 +0,0 @@
|
|
1
|
-
require 'spec_base.rb'
|
2
|
-
|
3
|
-
hash = Couchdb.login(username = 'obi',password ='trusted')
|
4
|
-
@@admin_auth_session = hash["AuthSession"]
|
5
|
-
|
6
|
-
user = { :username => "david", :password => "trusted", :roles => []}
|
7
|
-
Couchdb.add_user(user, @@admin_auth_session)
|
8
|
-
|
9
|
-
#a day in the life of the non-admin user
|
10
|
-
hash = Couchdb.login(username = 'david',password ='trusted')
|
11
|
-
@@auth_session = hash["AuthSession"]
|
12
|
-
|
13
|
-
#specs to ensure non-admin users function properly
|
14
|
-
describe "non admin user" do
|
15
|
-
it "should create a document, view, update it" do
|
16
|
-
Couchdb.create('contacts',@@admin_auth_session)
|
17
|
-
|
18
|
-
data = {:firstname => 'Nancy', :lastname =>'Lee', :phone => '347-808-3734',:email =>'nancy@mail.com',:gender => 'female'}
|
19
|
-
doc = {:database => 'contacts', :doc_id => 'eeek', :data => data}
|
20
|
-
hash = Couchdb.create_doc doc,@@auth_session
|
21
|
-
|
22
|
-
doc = {:database => 'contacts', :doc_id => 'eeek'}
|
23
|
-
hash = Couchdb.view doc,@@auth_session
|
24
|
-
hash["_id"].should == 'eeek'
|
25
|
-
|
26
|
-
data = {:age => "41", :lastname => "Stevens" }
|
27
|
-
doc = { :database => 'contacts', :doc_id => 'eeek', :data => data}
|
28
|
-
hash = Couchdb.update_doc doc,@@auth_session
|
29
|
-
hash["id"].should == 'eeek'
|
30
|
-
hash["ok"].should == true
|
31
|
-
end
|
32
|
-
|
33
|
-
it"should query a view" do
|
34
|
-
|
35
|
-
doc = { :database => 'contacts', :design_doc => 'more_views', :json_doc => '/home/obi/bin/leanback/test/my_views.json' }
|
36
|
-
hash = Couchdb.create_design doc,@@admin_auth_session
|
37
|
-
|
38
|
-
doc = {:database => 'contacts', :doc_id => '_design/more_views'}
|
39
|
-
hash = Couchdb.view doc,@@auth_session
|
40
|
-
hash["_id"].should == '_design/more_views'
|
41
|
-
|
42
|
-
view = { :database => "contacts", :design_doc => 'more_views', :view => 'get_email'}
|
43
|
-
hash = Couchdb.find view,@@auth_session
|
44
|
-
hash[0].has_key?("Firstname").should == true
|
45
|
-
hash[0].has_key?("Lastname").should == true
|
46
|
-
hash[0].has_key?("Email").should == true
|
47
|
-
Couchdb.delete_doc({:database => 'contacts', :doc_id => '_design/more_views'},@@admin_auth_session)
|
48
|
-
|
49
|
-
|
50
|
-
end
|
51
|
-
|
52
|
-
|
53
|
-
it "should delete document" do
|
54
|
-
hash = Couchdb.delete_doc({:database => 'contacts', :doc_id => 'eeek'},@@auth_session)
|
55
|
-
hash["id"].should == 'eeek'
|
56
|
-
hash["ok"].should == true
|
57
|
-
doc = { :database => 'contacts', :doc_id => 'eeek'}
|
58
|
-
lambda {Couchdb.view(doc,@@auth_session)}.should raise_error(CouchdbException,"CouchDB: Error - not_found. Reason - deleted")
|
59
|
-
end
|
60
|
-
|
61
|
-
it "should delete the database and user" do
|
62
|
-
doc = {:database => '_users', :doc_id => 'org.couchdb.user:david'}
|
63
|
-
Couchdb.delete_doc doc,@@admin_auth_session
|
64
|
-
Couchdb.delete 'contacts',@@admin_auth_session
|
65
|
-
end
|
66
|
-
|
67
|
-
end
|
data/test/helper.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'bundler'
|
3
|
-
begin
|
4
|
-
Bundler.setup(:default, :development)
|
5
|
-
rescue Bundler::BundlerError => e
|
6
|
-
$stderr.puts e.message
|
7
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
-
exit e.status_code
|
9
|
-
end
|
10
|
-
require 'test/unit'
|
11
|
-
require 'shoulda'
|
12
|
-
|
13
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
-
require 'leanback'
|
16
|
-
|
17
|
-
class Test::Unit::TestCase
|
18
|
-
end
|
data/test/main.rb
DELETED
@@ -1,295 +0,0 @@
|
|
1
|
-
path = File.expand_path(File.dirname(__FILE__))
|
2
|
-
|
3
|
-
require path + "/helper.rb"
|
4
|
-
|
5
|
-
#auth_session = "b2JpOjRFQzE5QThGOl1vWmoCx68CKvF2eJKrZnkCFv1c"
|
6
|
-
|
7
|
-
|
8
|
-
data = {:section => "admins",
|
9
|
-
:key => "obi",
|
10
|
-
:value => "trusted"}
|
11
|
-
|
12
|
-
#hash = Couchdb.delete 'staff'
|
13
|
-
|
14
|
-
#puts hash.inspect
|
15
|
-
|
16
|
-
hash = Couchdb.login(username = 'obi',password ='trusted')
|
17
|
-
auth_session = hash["AuthSession"]
|
18
|
-
|
19
|
-
|
20
|
-
view = { :database => "monitors",
|
21
|
-
:design_doc => 'tag_finder',
|
22
|
-
:view => 'find_by_tag'}
|
23
|
-
|
24
|
-
#hash = Couchdb.find view,auth_session,key='ralph', options = {:limit => 5, :skip => 1}
|
25
|
-
|
26
|
-
#hash = Couchdb.find view,auth_session,key='ralph', options = {:limit => 5}
|
27
|
-
|
28
|
-
|
29
|
-
#Couchdb.find_by({:database => 'zralph1369728249zeb1292e18b998352', :timestamp => 'Smith'},auth_session)
|
30
|
-
|
31
|
-
#Couchdb.find_by({:database => 'monitors', :test => 'Smith'},auth_session)
|
32
|
-
|
33
|
-
view = { :database => "zralph1369728249zeb1292e18b998352",
|
34
|
-
:design_doc => 'timestamp_finder',
|
35
|
-
:view => 'find_by_timestamp'}
|
36
|
-
|
37
|
-
#hash = Couchdb.find view,auth_session,key=nil, options = {:startkey => "100", :endkey => "1369728370"}
|
38
|
-
|
39
|
-
#hash = Couchdb.find view,auth_session,key="1369728370"
|
40
|
-
|
41
|
-
#start 2013-05-29 20:22:07 -0400 1369873327
|
42
|
-
#end 2013-05-29 20:19:07 -0400 1369873147
|
43
|
-
|
44
|
-
view = { :database => "monitors",
|
45
|
-
:design_doc => 'test_finder',
|
46
|
-
:view => 'find_by_test'}
|
47
|
-
#hash = Couchdb.find view,auth_session,key=nil, options = {:startkey => ["1000","UP"], :endkey => ["6000","UP"]}
|
48
|
-
|
49
|
-
#hash = Couchdb.find view,auth_session,key=nil, options = {:startkey => ["3300","UP"],:descending => true}
|
50
|
-
|
51
|
-
#hash = Couchdb.find view,auth_session,key=nil, options = {:descending => true}
|
52
|
-
|
53
|
-
#hash = Couchdb.find view,auth_session,key= {:keys => ['3300','UP']}
|
54
|
-
|
55
|
-
#hash = Couchdb.find view,auth_session,key= '?keys=%5B%228800%22,%22UP%22%5D'
|
56
|
-
|
57
|
-
keys = {:tag =>'ralph', :via => 'ses' }
|
58
|
-
hash = Couchdb.find_by_keys({:database => 'monitors', :keys => keys},auth_session)
|
59
|
-
|
60
|
-
#keys = {:tag =>'ralph', :via => 'ses' }
|
61
|
-
#num = Couchdb.count_by_keys({:database => 'monitors', :keys => keys},auth_session)
|
62
|
-
|
63
|
-
#keys = {:tag =>'ralph', :via => 'ses', :every => '1m'}
|
64
|
-
#hash = Couchdb.find_by_keys({:database => 'monitors', :keys => keys},auth_session, options = {:limit => 1, :skip => 1})
|
65
|
-
|
66
|
-
#keys = {:tag =>'ralph', :via => 'ses', :every => '5m'}
|
67
|
-
#num = Couchdb.count_by_keys({:database => 'monitors', :keys => keys},auth_session)
|
68
|
-
|
69
|
-
#keys = {:tag => 'ralph'}
|
70
|
-
#hash = Couchdb.find_by_keys({:database => 'monitors', :keys => keys},auth_session)
|
71
|
-
|
72
|
-
#keys = {:tag => 'ralph'}
|
73
|
-
#num = Couchdb.count_by_keys({:database => 'monitors', :keys => keys},auth_session)
|
74
|
-
|
75
|
-
|
76
|
-
#Couchdb.add_multiple_finder({:database => "monitors", :keys => ["tag","via"]},auth_session)
|
77
|
-
|
78
|
-
#Couchdb.add_multiple_finder({:database => "monitors", :keys => ["tag","via","state"]},auth_session)
|
79
|
-
|
80
|
-
#Couchdb.add_multiple_finder({:database => "monitors", :keys => ["tag"]},auth_session)
|
81
|
-
|
82
|
-
#puts num.to_s
|
83
|
-
|
84
|
-
puts hash.inspect
|
85
|
-
|
86
|
-
|
87
|
-
###END OF KEYS TESTING########
|
88
|
-
|
89
|
-
#user = { :username => "david", :password => "trusted", :roles => []}
|
90
|
-
#Couchdb.add_user(user, auth_session )
|
91
|
-
|
92
|
-
#hash = Couchdb.delete 'staff',auth_session
|
93
|
-
|
94
|
-
#puts auth_session
|
95
|
-
|
96
|
-
#Couchdb.create 'contacts',auth_session
|
97
|
-
|
98
|
-
data = {:firstname => 'Linda',
|
99
|
-
:lastname =>'smith',
|
100
|
-
:phone => '212-234-1234',
|
101
|
-
:email =>'john@mail.com'}
|
102
|
-
|
103
|
-
doc = {:database => 'contacts', :doc_id => 'Linda', :data => data}
|
104
|
-
#Couchdb.create_doc doc,auth_session
|
105
|
-
|
106
|
-
data = {:email => "linda@mail.com" }
|
107
|
-
doc = { :database => 'contacts', :doc_id => 'Linda', :data => data}
|
108
|
-
#Couchdb.update_doc doc,auth_session
|
109
|
-
|
110
|
-
|
111
|
-
doc = {:database => 'contacts', :doc_id => 'Linda'}
|
112
|
-
#x= Couchdb.view doc,auth_session
|
113
|
-
|
114
|
-
#puts x.inspect
|
115
|
-
|
116
|
-
data = {:firstname => 'Linda',
|
117
|
-
:lastname =>'smith',
|
118
|
-
:email => 'linda@mail.com',
|
119
|
-
:gender=>'female',
|
120
|
-
:phone =>'718-245-5611',
|
121
|
-
:_rev=>'2-d663618eda3268b83f96140b8250bc9e'}
|
122
|
-
|
123
|
-
doc = {:database => 'contacts', :doc_id => 'Linda', :data => data}
|
124
|
-
#Couchdb.edit_doc doc,auth_session
|
125
|
-
|
126
|
-
doc = {:database => 'contacts', :doc_id => 'Linda'}
|
127
|
-
#x= Couchdb.view doc,auth_session
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
#puts x.inspect
|
132
|
-
|
133
|
-
#x = Couchdb.find_by({:database => 'contacts', :email => 'linda@mail.com'} , auth_session)
|
134
|
-
|
135
|
-
#puts x.inspect
|
136
|
-
|
137
|
-
|
138
|
-
#Couchdb.delete 'contacts',auth_session
|
139
|
-
|
140
|
-
#Couchdb.set_config data
|
141
|
-
|
142
|
-
#hash = Couchdb.login(username = 'obi',password ='trusted')
|
143
|
-
#puts hash.inspect
|
144
|
-
|
145
|
-
#auth_session = hash["AuthSession"]
|
146
|
-
|
147
|
-
|
148
|
-
#hash = Couchdb.add_finder({:database => 'mobsters', :key => 'email'})
|
149
|
-
|
150
|
-
new_password = 'ninja'
|
151
|
-
#puts new_password
|
152
|
-
#puts Couchdb.change_password(username = 'kent', new_password, auth_session)
|
153
|
-
|
154
|
-
#hash = Couchdb.login(username ,new_password)
|
155
|
-
#user_auth_session = hash["AuthSession"]
|
156
|
-
|
157
|
-
#puts user_auth_session
|
158
|
-
|
159
|
-
#data = {:section => "httpd",
|
160
|
-
# :key => "port"}
|
161
|
-
|
162
|
-
data = {:section => "couchdb",
|
163
|
-
:key => "database_dir"}
|
164
|
-
|
165
|
-
#hash = Couchdb.get_config(data,auth_session)
|
166
|
-
#puts hash.inspect
|
167
|
-
|
168
|
-
data = { :admins => {"names" => ["david"], "roles" => ["admin"]},
|
169
|
-
:readers => {"names" => ["david"],"roles" => ["admin"]}
|
170
|
-
}
|
171
|
-
|
172
|
-
#hash = Couchdb.set_security("contacts",data,auth_session)
|
173
|
-
# hash = Couchdb.get_security("contacts",auth_session)
|
174
|
-
# puts hash.inspect
|
175
|
-
|
176
|
-
data = {:section => "admins",
|
177
|
-
:key => "sample_admin",
|
178
|
-
:value => "trusted"}
|
179
|
-
#Couchdb.set_config data,auth_session
|
180
|
-
|
181
|
-
data = {:section => "admins",
|
182
|
-
:key => "sample_admin"}
|
183
|
-
|
184
|
-
#hash = Couchdb.delete_config(data,auth_session)
|
185
|
-
#puts "EKE" + hash.inspect
|
186
|
-
|
187
|
-
#hash = Couchdb.create 'contactsabc',auth_session
|
188
|
-
#hash = Couchdb.all,auth_session
|
189
|
-
#puts hash.inspect
|
190
|
-
|
191
|
-
data = {:firstname => 'Linda',
|
192
|
-
:lastname =>'smith',
|
193
|
-
:phone => '212-234-1234',
|
194
|
-
:email =>'john@mail.com'}
|
195
|
-
|
196
|
-
doc = {:database => 'contactsabc', :doc_id => 'Linda', :data => data}
|
197
|
-
#hash = Couchdb.create_doc doc,auth_session
|
198
|
-
#puts hash.inspect
|
199
|
-
|
200
|
-
#hash = Couchdb.find_by( {:database => 'contactss', :email => 'john@mail.com'},auth_session)
|
201
|
-
#puts hash.inspect
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
data = {:section => "httpd",
|
208
|
-
:key => "port",
|
209
|
-
:value => "6980" }
|
210
|
-
#Couchdb.set_config(data,auth_session)
|
211
|
-
|
212
|
-
#Couchdb.port = "6980"
|
213
|
-
|
214
|
-
|
215
|
-
#puts auth_session
|
216
|
-
# Couchdb.create('staff',auth_session)
|
217
|
-
|
218
|
-
#hash = Couchdb.add_finder({:database => 'contacts', :key => 'firstname'}, auth_session)
|
219
|
-
|
220
|
-
#puts hash.inspect
|
221
|
-
|
222
|
-
#user = { :username => "Will.i.am", :password => "trusted", :roles => []}
|
223
|
-
#hash = Couchdb.add_user(user)
|
224
|
-
#puts hash.inspect
|
225
|
-
|
226
|
-
#user = { :username => "kris", :password => "trusted", :roles => ["drunk"]}
|
227
|
-
#hash = Couchdb.add_user(user,auth_session)
|
228
|
-
#puts hash.inspect
|
229
|
-
|
230
|
-
#hash = Couchdb.login(username = 'kris',password ='trusted')
|
231
|
-
#auth_session = hash["AuthSession"]
|
232
|
-
#puts "session = " + auth_session
|
233
|
-
|
234
|
-
#user = {:username => "jayz", :password => "trusted", :roles => ["student"], :salt => "whatevathesaltis",:email => 'uzi@aol.com'}
|
235
|
-
|
236
|
-
#hash = Couchdb.create_user(user)
|
237
|
-
#admins can add user roles
|
238
|
-
#hash = Couchdb.create_user(user, auth_session)
|
239
|
-
|
240
|
-
#puts hash.inspect
|
241
|
-
|
242
|
-
#o = [('a'..'z'),('A'..'Z')].map{|i| i.to_a}.flatten;
|
243
|
-
#salt = (0..50).map{ o[rand(o.length)] }.join;
|
244
|
-
|
245
|
-
#puts salt
|
246
|
-
data = { :admins => {"names" => ["nancy"], "roles" => ["admin"]},
|
247
|
-
:readers => {"names" => ["nancy"],"roles" => ["admin"]}
|
248
|
-
}
|
249
|
-
#data = { :admins => {"names" => [], "roles" => []},
|
250
|
-
# :readers => {"names" => [],"roles" => []}
|
251
|
-
# }
|
252
|
-
|
253
|
-
#hash = Couchdb.set_security("corn",data,auth_session)
|
254
|
-
#puts hash.inspect
|
255
|
-
|
256
|
-
#hash = Couchdb.get_security("corn",auth_session)
|
257
|
-
#puts hash.inspect
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
doc = { :database => 'contacts', :design_doc => 'more_views', :json_doc => '/home/obi/bin/leanback/test/my_views.json' }
|
262
|
-
#hash = Couchdb.create_design doc, auth_session
|
263
|
-
#puts hash.inspect
|
264
|
-
|
265
|
-
view = {:database => 'contacts',
|
266
|
-
:design_doc => 'my_views',
|
267
|
-
:view => 'get_emails',
|
268
|
-
:json_doc => '/home/obi/bin/my_views.json'}
|
269
|
-
|
270
|
-
#docs = Couchdb.find_on_fly(view,"",auth_session)
|
271
|
-
#puts "docs = " + docs.inspect
|
272
|
-
|
273
|
-
#view = { :database => "contacts", :design_doc => 'more_views', :view => 'get_email'}
|
274
|
-
#Couchdb.find view
|
275
|
-
|
276
|
-
view = { :database => 'contacts',
|
277
|
-
:design_doc => 'the_view',
|
278
|
-
:view => 'age',
|
279
|
-
:json_doc => '/home/obi/bin/view_age.json'}
|
280
|
-
|
281
|
-
age = '36'
|
282
|
-
#docs = Couchdb.find_on_fly(view,key = age, auth_session)
|
283
|
-
|
284
|
-
#puts "docs = " + docs.inspect
|
285
|
-
|
286
|
-
doc = {:database => 'contacts', :doc_id => '_design/the_view'}
|
287
|
-
#hash = Couchdb.view doc, auth_session
|
288
|
-
#puts hash.inspect
|
289
|
-
|
290
|
-
|
291
|
-
#docs = Couchdb.find_by({:database => 'contacts', :lastname => 'Hanna'}, auth_session)
|
292
|
-
#puts "docs = " + docs.inspect
|
293
|
-
|
294
|
-
#docs = Couchdb.docs_from 'contacts', auth_session
|
295
|
-
#puts "docs = " + docs.inspect
|
data/test/my_view.json
DELETED
data/test/my_views.json
DELETED
data/test/start.json
DELETED
data/test/test_leanback.rb
DELETED
@@ -1,319 +0,0 @@
|
|
1
|
-
path = File.expand_path(File.dirname(__FILE__))
|
2
|
-
|
3
|
-
require path + "/helper.rb"
|
4
|
-
|
5
|
-
class TestLeanback < Test::Unit::TestCase
|
6
|
-
#should "probably rename this file and start testing for real" do
|
7
|
-
# flunk "hey buddy, you should probably rename this file and start testing for real"
|
8
|
-
#end
|
9
|
-
|
10
|
-
|
11
|
-
should "create a database if it doesn't already exist" do
|
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")
|
16
|
-
end
|
17
|
-
|
18
|
-
should "create a database if it doesn't already exist, and handle exception if it exists" do
|
19
|
-
begin
|
20
|
-
hash = Couchdb.create 'contacts'
|
21
|
-
assert_equal '{"ok"=>true}', hash.to_s
|
22
|
-
rescue => e
|
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
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
should "try to delete a database that doesn't exist and handle the exception" do
|
29
|
-
begin
|
30
|
-
hash = Couchdb.delete 'buildings'
|
31
|
-
#puts hash.inspect
|
32
|
-
rescue CouchdbException => e
|
33
|
-
assert_equal "CouchDB: Error - not_found. Reason - missing", e.to_s
|
34
|
-
assert_equal "not_found", e.error
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
should "add a finder method to the database or handle exception if a finder already exists" do
|
39
|
-
hash = Couchdb.add_finder(:database => 'contacts', :key => 'email')
|
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"]
|
47
|
-
end
|
48
|
-
|
49
|
-
should "find items by key" do
|
50
|
-
#docs = Couchdb.find_by( :database => 'contacts', :email => 'nancy@mail.com')
|
51
|
-
docs = Couchdb.find_by( :database => 'contacts', :lastname => 'smith')
|
52
|
-
#docs = Couchdb.find_by( :database => 'contacts', :country => 'female')
|
53
|
-
|
54
|
-
d = docs[0]
|
55
|
-
assert_equal "smith", d["lastname"]
|
56
|
-
end
|
57
|
-
|
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
|
-
Couchdb.create_doc doc
|
69
|
-
|
70
|
-
doc = {:database => 'contacts', :doc_id => 'john'}
|
71
|
-
hash = Couchdb.view doc
|
72
|
-
assert_equal 'john', hash["_id"]
|
73
|
-
end
|
74
|
-
|
75
|
-
should "Query a permanent view that doesn't exist and handle exception" do
|
76
|
-
begin
|
77
|
-
view = { :database => "contacts", :design_doc => 'more_views', :view => 'get_user_email'}
|
78
|
-
Couchdb.find view
|
79
|
-
rescue CouchdbException => e
|
80
|
-
assert_equal "CouchDB: Error - not_found. Reason - missing_named_view", e.to_s
|
81
|
-
assert_equal "not_found", e.error
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
|
86
|
-
should "Query a permanent view" do
|
87
|
-
view = { :database => "contacts", :design_doc => 'more_views', :view => 'get_email'}
|
88
|
-
docs = Couchdb.find view
|
89
|
-
assert_equal true,docs[0].include?("Email")
|
90
|
-
assert_equal true,docs[0].include?("Lastname")
|
91
|
-
end
|
92
|
-
|
93
|
-
|
94
|
-
should "Query a permanent view and create the view on the fly, if it doesn't already exist" do
|
95
|
-
view = {:database => 'contacts',
|
96
|
-
:design_doc => 'my_views',
|
97
|
-
:view => 'get_emails',
|
98
|
-
:json_doc => '/home/obi/bin/my_views.json'}
|
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"]
|
107
|
-
end
|
108
|
-
|
109
|
-
should "Query a permanent view by key and create the view on the fly, if it doesn't already exist" do
|
110
|
-
view = { :database => 'contacts',
|
111
|
-
:design_doc => 'the_view',
|
112
|
-
:view => 'age',
|
113
|
-
:json_doc => '/home/obi/bin/view_age.json'}
|
114
|
-
|
115
|
-
age = '36'
|
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"]
|
124
|
-
end
|
125
|
-
|
126
|
-
should "Create a design doc/permanent view or handle exception" do
|
127
|
-
doc = { :database => 'contacts', :design_doc => 'more_views', :json_doc => '/home/obi/bin/leanback/test/my_views.json' }
|
128
|
-
hash = Couchdb.create_design doc
|
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"]
|
135
|
-
end
|
136
|
-
|
137
|
-
should "return a display a list of all databases" do
|
138
|
-
databases = Couchdb.all
|
139
|
-
assert_equal true,databases.include?("contacts")
|
140
|
-
end
|
141
|
-
|
142
|
-
should "delete a database" do
|
143
|
-
hash = Couchdb.delete 'staff'
|
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")
|
147
|
-
end
|
148
|
-
|
149
|
-
should "create a document and handle exception if one occurs" do
|
150
|
-
data = {:firstname => 'Nancy', :lastname =>'Lee', :phone => '347-808-3734',:email =>'nancy@mail.com',:gender => 'female'}
|
151
|
-
doc = {:database => 'contacts', :doc_id => 'Nancy', :data => data}
|
152
|
-
hash = Couchdb.create_doc 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"]
|
162
|
-
end
|
163
|
-
|
164
|
-
should "update the document" do
|
165
|
-
#data = {"age" => "42", "lastname" => "arnold", "phone" => "202-456-1234", "hobbies" => "football,running, video gamess" }
|
166
|
-
data = {:age => "41", :lastname => "Stevens" }
|
167
|
-
doc = { :database => 'contacts', :doc_id => 'john', :data => data}
|
168
|
-
hash = Couchdb.update_doc 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
|
-
Couchdb.delete_doc :database => 'contacts', :doc_id => 'john'
|
178
|
-
end
|
179
|
-
|
180
|
-
should "delete sample documents - ready for next test run" do
|
181
|
-
Couchdb.delete_doc :database => 'contacts', :doc_id => 'Nancy'
|
182
|
-
Couchdb.delete_doc :database => 'contacts', :doc_id => '_design/more_views'
|
183
|
-
#Couchdb.delete_doc :database => 'contacts', :doc_id => '_design/the_view'
|
184
|
-
Couchdb.delete_doc :database => 'contacts', :doc_id => '_design/my_views'
|
185
|
-
Couchdb.delete_doc :database => 'contacts', :doc_id => '_design/email_finder'
|
186
|
-
end
|
187
|
-
|
188
|
-
should "edit a document - handle exceptions" do
|
189
|
-
begin
|
190
|
-
#see delete without _rev above
|
191
|
-
data = {:firstname => 'john', :lastname =>'smith', :email => 'john@mail.com',:gender=>'male', :_rev=>'2-e813a0e902e3ac114400ff3959a2adde'}
|
192
|
-
doc = {:database => 'contacts', :doc_id => 'john', :data => data}
|
193
|
-
hash = Couchdb.edit_doc doc
|
194
|
-
#puts hash.inspect
|
195
|
-
rescue CouchdbException => e
|
196
|
-
assert_equal "CouchDB: Error - conflict. Reason - Document update conflict.", e.to_s
|
197
|
-
assert_equal "conflict", e.error
|
198
|
-
end
|
199
|
-
end
|
200
|
-
|
201
|
-
should "create and delete a document" do
|
202
|
-
data = {:firstname => 'Sun',
|
203
|
-
:lastname =>'Nova',
|
204
|
-
:phone => '212-234-1234',
|
205
|
-
:email =>'james@mail.com'}
|
206
|
-
|
207
|
-
doc = {:database => 'contacts', :doc_id => 'Sun', :data => data}
|
208
|
-
Couchdb.create_doc doc
|
209
|
-
|
210
|
-
doc = {:database => 'contacts', :doc_id => 'Sun'}
|
211
|
-
hash = Couchdb.delete_doc doc
|
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
|
222
|
-
end
|
223
|
-
|
224
|
-
should "delete a document with revision number - any handle exceptions" do
|
225
|
-
begin
|
226
|
-
doc = {:database => 'contacts', :doc_id => 'james', :rev => '4-4e70528f7400e2e43d6543aec4d8aa2b'}
|
227
|
-
hash = Couchdb.delete_rev doc
|
228
|
-
#puts hash.inspect
|
229
|
-
rescue CouchdbException => e
|
230
|
-
assert_equal "CouchDB: Error - conflict. Reason - Document update conflict.", e.to_s
|
231
|
-
assert_equal "conflict", e.error
|
232
|
-
end
|
233
|
-
end
|
234
|
-
|
235
|
-
should "attempt to display all documents in the database that doesn't exist and handle exception" do
|
236
|
-
begin
|
237
|
-
docs = Couchdb.docs_from 'buildings'
|
238
|
-
rescue CouchdbException => e
|
239
|
-
assert_equal "CouchDB: Error - not_found. Reason - no_db_file", e.to_s
|
240
|
-
assert_equal "not_found", e.error
|
241
|
-
end
|
242
|
-
end
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
should "display all documents in the database" do
|
247
|
-
#docs = Couchdb.docs_from 'monitors'
|
248
|
-
#puts 'docs = Couchdb.docs_from monitors'
|
249
|
-
#docs.each do |d|
|
250
|
-
# puts "_rev: " + d["_rev"]
|
251
|
-
#puts "_id: " + d["_id"]
|
252
|
-
#puts "every: " + d["every"]
|
253
|
-
#puts "monitor: " + d["monitor"]
|
254
|
-
#puts "url: " + d["url"]
|
255
|
-
#puts "test: " + d["test"]
|
256
|
-
#puts "contact: " + d["contact"]
|
257
|
-
#puts "via: " + d["via"]
|
258
|
-
#puts "notify_interval: " + d["notify_interval"]
|
259
|
-
#end
|
260
|
-
end
|
261
|
-
|
262
|
-
#TODO: add better tests with validations for couchDB configuration methods later
|
263
|
-
|
264
|
-
should "change the timeout key to 78787 " do
|
265
|
-
data = {:section => "couch_httpd_auth",
|
266
|
-
:key => "timeout",
|
267
|
-
:value => "78787"}
|
268
|
-
Couchdb.set_config data
|
269
|
-
end
|
270
|
-
|
271
|
-
should "return the configuration values" do
|
272
|
-
data = {:section => "httpd",
|
273
|
-
:key => "port"}
|
274
|
-
puts "port = " + Couchdb.get_config(data)
|
275
|
-
|
276
|
-
data = {:section => "couch_httpd_auth",
|
277
|
-
:key => "timeout"}
|
278
|
-
puts "timeout = " + Couchdb.get_config(data)
|
279
|
-
end
|
280
|
-
|
281
|
-
should "set sample key values to couchDB configuration" do
|
282
|
-
data = {:section => "sample_config_section",
|
283
|
-
:key => "sample_key",
|
284
|
-
:value => "sample_value"}
|
285
|
-
Couchdb.set_config data
|
286
|
-
end
|
287
|
-
|
288
|
-
should "delete couchDB sample configuration" do
|
289
|
-
data = {:section => "sample_config_section",
|
290
|
-
:key => "sample_key"}
|
291
|
-
hash = Couchdb.delete_config data
|
292
|
-
puts hash.inspect
|
293
|
-
end
|
294
|
-
|
295
|
-
should "add an admin user" do
|
296
|
-
# data = {:section => "admins",
|
297
|
-
# :key => "obi",
|
298
|
-
# :value => "trusted"}
|
299
|
-
#Couchdb.set_config data
|
300
|
-
end
|
301
|
-
|
302
|
-
should "login a user" do
|
303
|
-
#hash = Couchdb.login(username = 'obi',password ='trusted')
|
304
|
-
#puts hash.inspect
|
305
|
-
#sleep
|
306
|
-
end
|
307
|
-
|
308
|
-
should " switch to default bind address" do
|
309
|
-
Couchdb.address = nil
|
310
|
-
Couchdb.port = nil
|
311
|
-
#Couchdb.all
|
312
|
-
end
|
313
|
-
|
314
|
-
end
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|