leanback 0.2.8 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,52 @@
1
+ require 'spec_base.rb'
2
+
3
+ #a day in the life of the non-admin user
4
+ hash = Couchdb.login(username = 'obiora',password ='trusted')
5
+ @@auth_session = hash["AuthSession"]
6
+
7
+ hash = Couchdb.login(username = 'obi',password ='trusted')
8
+ @@admin_auth_session = hash["AuthSession"]
9
+
10
+ #specs to ensure non-admin users function properly
11
+ describe "non admin user" do
12
+ it "should create a document, view, update and delete it" do
13
+ data = {:firstname => 'Nancy', :lastname =>'Lee', :phone => '347-808-3734',:email =>'nancy@mail.com',:gender => 'female'}
14
+ doc = {:database => 'contacts', :doc_id => 'eeek', :data => data}
15
+ hash = Couchdb.create_doc doc,@@auth_session
16
+
17
+ doc = {:database => 'contacts', :doc_id => 'eeek'}
18
+ hash = Couchdb.view doc,@@auth_session
19
+ hash["_id"].should == 'eeek'
20
+
21
+ data = {:age => "41", :lastname => "Stevens" }
22
+ doc = { :database => 'contacts', :doc_id => 'eeek', :data => data}
23
+ hash = Couchdb.update_doc doc,@@auth_session
24
+ hash["id"].should == 'eeek'
25
+ hash["ok"].should == true
26
+
27
+ Couchdb.delete_doc({:database => 'contacts', :doc_id => 'eeek'},@@auth_session)
28
+
29
+ hash["id"].should == 'eeek'
30
+ hash["ok"].should == true
31
+ doc = { :database => 'contacts', :doc_id => 'eeek'}
32
+ lambda {Couchdb.view(doc,@@auth_session)}.should raise_error(CouchdbException,"CouchDB: Error - not_found. Reason - deleted")
33
+ end
34
+
35
+ it"should query a view" do
36
+ doc = { :database => 'contacts', :design_doc => 'more_views', :json_doc => '/home/obi/bin/leanback/test/my_views.json' }
37
+ hash = Couchdb.create_design doc,@@admin_auth_session
38
+
39
+ doc = {:database => 'contacts', :doc_id => '_design/more_views'}
40
+ hash = Couchdb.view doc,@@auth_session
41
+ hash["_id"].should == '_design/more_views'
42
+
43
+ view = { :database => "contacts", :design_doc => 'more_views', :view => 'get_email'}
44
+ hash = Couchdb.find view,@@auth_session
45
+
46
+ hash[0].has_key?("Firstname").should == true
47
+ hash[0].has_key?("Lastname").should == true
48
+ hash[0].has_key?("Email").should == true
49
+ Couchdb.delete_doc({:database => 'contacts', :doc_id => '_design/more_views'},@@admin_auth_session)
50
+ end
51
+
52
+ end
@@ -0,0 +1,2 @@
1
+ require 'rubygems'
2
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib/leanback'))
@@ -0,0 +1,154 @@
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
+ #Couchdb.set_config data
12
+
13
+ hash = Couchdb.login(username = 'obi',password ='trusted')
14
+ #puts hash.inspect
15
+
16
+ auth_session = hash["AuthSession"]
17
+
18
+ #data = {:section => "httpd",
19
+ # :key => "port"}
20
+
21
+ data = {:section => "couchdb",
22
+ :key => "database_dir"}
23
+
24
+ #hash = Couchdb.get_config(data,auth_session)
25
+ #puts hash.inspect
26
+
27
+ data = { :admins => {"names" => ["david"], "roles" => ["admin"]},
28
+ :readers => {"names" => ["david"],"roles" => ["admin"]}
29
+ }
30
+
31
+ #hash = Couchdb.set_security("contacts",data,auth_session)
32
+ hash = Couchdb.get_security("contacts",auth_session)
33
+ puts hash.inspect
34
+
35
+ data = {:section => "admins",
36
+ :key => "sample_admin",
37
+ :value => "trusted"}
38
+ #Couchdb.set_config data,auth_session
39
+
40
+ data = {:section => "admins",
41
+ :key => "sample_admin"}
42
+
43
+ #hash = Couchdb.delete_config(data,auth_session)
44
+ #puts "EKE" + hash.inspect
45
+
46
+ #hash = Couchdb.create 'contactsabc',auth_session
47
+ #hash = Couchdb.all,auth_session
48
+ #puts hash.inspect
49
+
50
+ data = {:firstname => 'Linda',
51
+ :lastname =>'smith',
52
+ :phone => '212-234-1234',
53
+ :email =>'john@mail.com'}
54
+
55
+ doc = {:database => 'contactsabc', :doc_id => 'Linda', :data => data}
56
+ #hash = Couchdb.create_doc doc,auth_session
57
+ #puts hash.inspect
58
+
59
+ #hash = Couchdb.find_by( {:database => 'contactss', :email => 'john@mail.com'},auth_session)
60
+ #puts hash.inspect
61
+
62
+
63
+
64
+
65
+
66
+ data = {:section => "httpd",
67
+ :key => "port",
68
+ :value => "6980" }
69
+ #Couchdb.set_config(data,auth_session)
70
+
71
+ #Couchdb.port = "6980"
72
+
73
+
74
+ #puts auth_session
75
+ # Couchdb.create('staff',auth_session)
76
+
77
+ #hash = Couchdb.add_finder({:database => 'contacts', :key => 'firstname'}, auth_session)
78
+
79
+ #puts hash.inspect
80
+
81
+ #user = { :username => "Will.i.am", :password => "trusted", :roles => []}
82
+ #hash = Couchdb.add_user(user)
83
+ #puts hash.inspect
84
+
85
+ #user = { :username => "kris", :password => "trusted", :roles => ["drunk"]}
86
+ #hash = Couchdb.add_user(user,auth_session)
87
+ #puts hash.inspect
88
+
89
+ #hash = Couchdb.login(username = 'kris',password ='trusted')
90
+ #auth_session = hash["AuthSession"]
91
+ #puts "session = " + auth_session
92
+
93
+ #user = {:username => "jayz", :password => "trusted", :roles => ["student"], :salt => "whatevathesaltis",:email => 'uzi@aol.com'}
94
+
95
+ #hash = Couchdb.create_user(user)
96
+ #admins can add user roles
97
+ #hash = Couchdb.create_user(user, auth_session)
98
+
99
+ #puts hash.inspect
100
+
101
+ #o = [('a'..'z'),('A'..'Z')].map{|i| i.to_a}.flatten;
102
+ #salt = (0..50).map{ o[rand(o.length)] }.join;
103
+
104
+ #puts salt
105
+ data = { :admins => {"names" => ["nancy"], "roles" => ["admin"]},
106
+ :readers => {"names" => ["nancy"],"roles" => ["admin"]}
107
+ }
108
+ #data = { :admins => {"names" => [], "roles" => []},
109
+ # :readers => {"names" => [],"roles" => []}
110
+ # }
111
+
112
+ #hash = Couchdb.set_security("corn",data,auth_session)
113
+ #puts hash.inspect
114
+
115
+ #hash = Couchdb.get_security("corn",auth_session)
116
+ #puts hash.inspect
117
+
118
+
119
+
120
+ doc = { :database => 'contacts', :design_doc => 'more_views', :json_doc => '/home/obi/bin/leanback/test/my_views.json' }
121
+ #hash = Couchdb.create_design doc, auth_session
122
+ #puts hash.inspect
123
+
124
+ view = {:database => 'contacts',
125
+ :design_doc => 'my_views',
126
+ :view => 'get_emails',
127
+ :json_doc => '/home/obi/bin/my_views.json'}
128
+
129
+ #docs = Couchdb.find_on_fly(view,"",auth_session)
130
+ #puts "docs = " + docs.inspect
131
+
132
+ #view = { :database => "contacts", :design_doc => 'more_views', :view => 'get_email'}
133
+ #Couchdb.find view
134
+
135
+ view = { :database => 'contacts',
136
+ :design_doc => 'the_view',
137
+ :view => 'age',
138
+ :json_doc => '/home/obi/bin/view_age.json'}
139
+
140
+ age = '36'
141
+ #docs = Couchdb.find_on_fly(view,key = age, auth_session)
142
+
143
+ #puts "docs = " + docs.inspect
144
+
145
+ doc = {:database => 'contacts', :doc_id => '_design/the_view'}
146
+ #hash = Couchdb.view doc, auth_session
147
+ #puts hash.inspect
148
+
149
+
150
+ #docs = Couchdb.find_by({:database => 'contacts', :lastname => 'Hanna'}, auth_session)
151
+ #puts "docs = " + docs.inspect
152
+
153
+ #docs = Couchdb.docs_from 'contacts', auth_session
154
+ #puts "docs = " + docs.inspect
@@ -65,7 +65,7 @@ class TestLeanback < Test::Unit::TestCase
65
65
  :gender =>'male'}
66
66
 
67
67
  doc = {:database => 'contacts', :doc_id => 'john', :data => data}
68
- Document.create doc
68
+ Couchdb.create_doc doc
69
69
 
70
70
  doc = {:database => 'contacts', :doc_id => 'john'}
71
71
  hash = Couchdb.view doc
@@ -98,12 +98,12 @@ class TestLeanback < Test::Unit::TestCase
98
98
  :json_doc => '/home/obi/bin/my_views.json'}
99
99
 
100
100
  docs = Couchdb.find_on_fly(view)
101
- assert_equal true,docs[0].include?("Email")
102
- assert_equal true,docs[0].include?("Name")
101
+ #assert_equal true,docs[0].include?("Email")
102
+ #assert_equal true,docs[0].include?("Name")
103
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"]
104
+ #doc = {:database => 'contacts', :doc_id => '_design/my_views'}
105
+ #hash = Couchdb.view doc
106
+ #assert_equal '_design/my_views', hash["_id"]
107
107
  end
108
108
 
109
109
  should "Query a permanent view by key and create the view on the fly, if it doesn't already exist" do
@@ -117,7 +117,7 @@ class TestLeanback < Test::Unit::TestCase
117
117
  assert_equal true,docs[0].include?("age")
118
118
  d = docs[0]
119
119
  assert_equal '36', d["age"]
120
- #verify that the view was created
120
+ verify that the view was created
121
121
  doc = {:database => 'contacts', :doc_id => '_design/the_view'}
122
122
  hash = Couchdb.view doc
123
123
  assert_equal '_design/the_view', hash["_id"]
@@ -149,7 +149,7 @@ class TestLeanback < Test::Unit::TestCase
149
149
  should "create a document and handle exception if one occurs" do
150
150
  data = {:firstname => 'Nancy', :lastname =>'Lee', :phone => '347-808-3734',:email =>'nancy@mail.com',:gender => 'female'}
151
151
  doc = {:database => 'contacts', :doc_id => 'Nancy', :data => data}
152
- hash = Document.create doc
152
+ hash = Couchdb.create_doc doc
153
153
  assert_equal 'Nancy', hash["id"]
154
154
  assert_equal true, hash["ok"]
155
155
 
@@ -165,7 +165,7 @@ class TestLeanback < Test::Unit::TestCase
165
165
  #data = {"age" => "42", "lastname" => "arnold", "phone" => "202-456-1234", "hobbies" => "football,running, video gamess" }
166
166
  data = {:age => "41", :lastname => "Stevens" }
167
167
  doc = { :database => 'contacts', :doc_id => 'john', :data => data}
168
- hash = Document.update doc
168
+ hash = Couchdb.update_doc doc
169
169
  assert_equal 'john', hash["id"]
170
170
  assert_equal true, hash["ok"]
171
171
 
@@ -174,15 +174,15 @@ class TestLeanback < Test::Unit::TestCase
174
174
  assert_equal 'john', hash["_id"]
175
175
  assert_equal '41', hash["age"]
176
176
  assert_equal 'Stevens', hash["lastname"]
177
- Document.delete :database => 'contacts', :doc_id => 'john'
177
+ Couchdb.delete_doc :database => 'contacts', :doc_id => 'john'
178
178
  end
179
179
 
180
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'
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
186
  end
187
187
 
188
188
  should "edit a document - handle exceptions" do
@@ -190,7 +190,7 @@ class TestLeanback < Test::Unit::TestCase
190
190
  #see delete without _rev above
191
191
  data = {:firstname => 'john', :lastname =>'smith', :email => 'john@mail.com',:gender=>'male', :_rev=>'2-e813a0e902e3ac114400ff3959a2adde'}
192
192
  doc = {:database => 'contacts', :doc_id => 'john', :data => data}
193
- hash = Document.edit doc
193
+ hash = Couchdb.edit_doc doc
194
194
  #puts hash.inspect
195
195
  rescue CouchdbException => e
196
196
  assert_equal "CouchDB: Error - conflict. Reason - Document update conflict.", e.to_s
@@ -205,10 +205,10 @@ class TestLeanback < Test::Unit::TestCase
205
205
  :email =>'james@mail.com'}
206
206
 
207
207
  doc = {:database => 'contacts', :doc_id => 'Sun', :data => data}
208
- Document.create doc
208
+ Couchdb.create_doc doc
209
209
 
210
210
  doc = {:database => 'contacts', :doc_id => 'Sun'}
211
- hash = Document.delete doc
211
+ hash = Couchdb.delete_doc doc
212
212
 
213
213
  assert_equal 'Sun', hash["id"]
214
214
  assert_equal true, hash["ok"]
@@ -224,7 +224,7 @@ class TestLeanback < Test::Unit::TestCase
224
224
  should "delete a document with revision number - any handle exceptions" do
225
225
  begin
226
226
  doc = {:database => 'contacts', :doc_id => 'james', :rev => '4-4e70528f7400e2e43d6543aec4d8aa2b'}
227
- hash = Document.delete_rev doc
227
+ hash = Couchdb.delete_rev doc
228
228
  #puts hash.inspect
229
229
  rescue CouchdbException => e
230
230
  assert_equal "CouchDB: Error - conflict. Reason - Document update conflict.", e.to_s
@@ -259,7 +259,51 @@ class TestLeanback < Test::Unit::TestCase
259
259
  #end
260
260
  end
261
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
262
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
263
307
 
264
308
  should " switch to default bind address" do
265
309
  Couchdb.address = nil
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: leanback
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 2
8
- - 8
9
- version: 0.2.8
4
+ prerelease:
5
+ version: 0.3.0
10
6
  platform: ruby
11
7
  authors:
12
8
  - Obi Akubue
@@ -14,8 +10,7 @@ autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
12
 
17
- date: 2011-09-14 00:00:00 -04:00
18
- default_executable:
13
+ date: 2011-11-21 00:00:00 Z
19
14
  dependencies:
20
15
  - !ruby/object:Gem::Dependency
21
16
  name: rest-client
@@ -24,8 +19,6 @@ dependencies:
24
19
  requirements:
25
20
  - - ">="
26
21
  - !ruby/object:Gem::Version
27
- segments:
28
- - 0
29
22
  version: "0"
30
23
  type: :runtime
31
24
  prerelease: false
@@ -37,8 +30,6 @@ dependencies:
37
30
  requirements:
38
31
  - - ">="
39
32
  - !ruby/object:Gem::Version
40
- segments:
41
- - 0
42
33
  version: "0"
43
34
  type: :runtime
44
35
  prerelease: false
@@ -50,8 +41,6 @@ dependencies:
50
41
  requirements:
51
42
  - - ">="
52
43
  - !ruby/object:Gem::Version
53
- segments:
54
- - 0
55
44
  version: "0"
56
45
  type: :development
57
46
  prerelease: false
@@ -63,10 +52,6 @@ dependencies:
63
52
  requirements:
64
53
  - - ~>
65
54
  - !ruby/object:Gem::Version
66
- segments:
67
- - 1
68
- - 0
69
- - 0
70
55
  version: 1.0.0
71
56
  type: :development
72
57
  prerelease: false
@@ -78,10 +63,6 @@ dependencies:
78
63
  requirements:
79
64
  - - ~>
80
65
  - !ruby/object:Gem::Version
81
- segments:
82
- - 1
83
- - 5
84
- - 2
85
66
  version: 1.5.2
86
67
  type: :development
87
68
  prerelease: false
@@ -93,12 +74,21 @@ dependencies:
93
74
  requirements:
94
75
  - - ">="
95
76
  - !ruby/object:Gem::Version
96
- segments:
97
- - 0
98
77
  version: "0"
99
78
  type: :development
100
79
  prerelease: false
101
80
  version_requirements: *id006
81
+ - !ruby/object:Gem::Dependency
82
+ name: rspec
83
+ requirement: &id007 !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: "0"
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: *id007
102
92
  description: lightweight Ruby interface to CouchDB
103
93
  email: obioraakubue@yahoo.com
104
94
  executables: []
@@ -107,22 +97,26 @@ extensions: []
107
97
 
108
98
  extra_rdoc_files:
109
99
  - LICENSE.txt
110
- - README.rdoc
100
+ - README.md
111
101
  files:
112
102
  - .document
113
103
  - Changelog.rdoc
114
104
  - Gemfile
115
105
  - Gemfile.lock
116
106
  - LICENSE.txt
117
- - README.rdoc
107
+ - README.md
118
108
  - Rakefile
119
109
  - VERSION
120
110
  - leanback.gemspec
121
111
  - lib/leanback.rb
112
+ - spec/admin_party/database_spec.rb
113
+ - spec/no_admin_party/database_spec.rb
114
+ - spec/no_admin_party/non_admin_user_spec.rb
115
+ - spec/spec_base.rb
122
116
  - test/helper.rb
117
+ - test/main.rb
123
118
  - test/my_views.json
124
119
  - test/test_leanback.rb
125
- has_rdoc: true
126
120
  homepage: http://github.com/obi-a/leanback
127
121
  licenses:
128
122
  - MIT
@@ -136,7 +130,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
136
130
  requirements:
137
131
  - - ">="
138
132
  - !ruby/object:Gem::Version
139
- hash: -211762291
133
+ hash: 154128161
140
134
  segments:
141
135
  - 0
142
136
  version: "0"
@@ -145,16 +139,19 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
139
  requirements:
146
140
  - - ">="
147
141
  - !ruby/object:Gem::Version
148
- segments:
149
- - 0
150
142
  version: "0"
151
143
  requirements: []
152
144
 
153
145
  rubyforge_project:
154
- rubygems_version: 1.3.7
146
+ rubygems_version: 1.8.5
155
147
  signing_key:
156
148
  specification_version: 3
157
149
  summary: lightweight Ruby interface to CouchDB
158
150
  test_files:
151
+ - spec/admin_party/database_spec.rb
152
+ - spec/no_admin_party/database_spec.rb
153
+ - spec/no_admin_party/non_admin_user_spec.rb
154
+ - spec/spec_base.rb
159
155
  - test/helper.rb
156
+ - test/main.rb
160
157
  - test/test_leanback.rb