ki 0.0.2 → 0.1.0

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.
Files changed (72) hide show
  1. data/.rvmrc +1 -1
  2. data/Gemfile +6 -3
  3. data/Gemfile.lock +81 -0
  4. data/Guardfile +9 -0
  5. data/LICENSE.txt +1 -1
  6. data/README.rdoc +8 -1
  7. data/Rakefile +17 -3
  8. data/VERSION +1 -1
  9. data/bin/ki +3 -2
  10. data/examples/base/Gemfile +1 -7
  11. data/examples/base/Gemfile.lock +24 -0
  12. data/examples/base/app.rb +1 -2
  13. data/examples/base/config.ru +4 -0
  14. data/examples/{example → northpole}/Gemfile +0 -1
  15. data/examples/northpole/Gemfile.lock +33 -0
  16. data/examples/northpole/app.rb +19 -0
  17. data/examples/northpole/config.ru +6 -0
  18. data/examples/northpole/config.yml +3 -0
  19. data/examples/northpole/views/index.haml +1 -0
  20. data/examples/northpole/views/website.haml +1 -0
  21. data/ki.gemspec +125 -0
  22. data/lib/db.rb +43 -13
  23. data/lib/extensions/mail.rb +41 -0
  24. data/lib/helpers.rb +16 -0
  25. data/lib/ki.rb +8 -27
  26. data/lib/ki_cli.rb +63 -0
  27. data/lib/model.rb +59 -92
  28. data/lib/modules/callbacks.rb +27 -0
  29. data/lib/modules/query_interface.rb +29 -0
  30. data/lib/modules/restrictions.rb +62 -0
  31. data/lib/req.rb +30 -0
  32. data/lib/resp.rb +50 -0
  33. data/lib/static_file.rb +14 -0
  34. data/lib/util.rb +21 -30
  35. data/lib/views/404.haml +7 -0
  36. data/lib/views/406.haml +7 -0
  37. data/lib/views/index.haml +5 -17
  38. data/logo.png +0 -0
  39. data/spec/db_spec.rb +71 -0
  40. data/spec/ki_spec.rb +2 -2
  41. data/spec/model_spec.rb +82 -0
  42. data/spec/modules/callbacks_spec.rb +14 -0
  43. data/spec/modules/query_interface_spec.rb +63 -0
  44. data/spec/modules/restrictions_spec.rb +64 -0
  45. data/spec/req_spec.rb +4 -0
  46. data/spec/spec_helper.rb +30 -1
  47. data/spec/util_spec.rb +32 -16
  48. metadata +89 -36
  49. data/examples/base/config.yml +0 -3
  50. data/examples/example/app.rb +0 -15
  51. data/examples/example/config.ru +0 -2
  52. data/examples/example/config.yml +0 -3
  53. data/examples/example/public/custom.css +0 -0
  54. data/examples/example/public/custom.js +0 -0
  55. data/lib/cli.rb +0 -51
  56. data/lib/controller.rb +0 -15
  57. data/lib/modules.rb +0 -54
  58. data/lib/public/bootstrap.css +0 -6004
  59. data/lib/public/bootstrap.js +0 -2036
  60. data/lib/public/custom.css +0 -0
  61. data/lib/public/custom.js +0 -0
  62. data/lib/public/glyphicons-halflings-white.png +0 -0
  63. data/lib/public/glyphicons-halflings.png +0 -0
  64. data/lib/public/jquery-1.8.2.min.js +0 -2
  65. data/lib/public/ki.css +0 -56
  66. data/lib/request.rb +0 -14
  67. data/lib/response.rb +0 -51
  68. data/lib/views/container.haml +0 -6
  69. data/lib/views/footer.haml +0 -2
  70. data/lib/views/form.haml +0 -10
  71. data/lib/views/models.haml +0 -14
  72. data/lib/views/navbar.haml +0 -11
@@ -0,0 +1,14 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Ki::Callbacks do
4
+ it "should have before and after find" do
5
+ class Foo < Ki::Model
6
+ def before_create
7
+ @req.params['meaning_of_life'] = 42
8
+ end
9
+ end
10
+
11
+ id = Foo.new(ReqFactory.new(:post, {:foo => 'bar'})).hash['_id']
12
+ Foo.new(ReqFactory.new(:get, { '_id' => id })).hash['meaning_of_life'].should == 42
13
+ end
14
+ end
@@ -0,0 +1,63 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Ki::QueryInterface do
4
+ before :each do
5
+ @db = Ki::Db.instance
6
+ @db.remove_collections
7
+ end
8
+
9
+ it "should find waldo" do
10
+ id = @db.create 'waldo', { :location => 'amsterdam' }
11
+
12
+ class Waldo < Ki::Model
13
+ end
14
+
15
+ waldo = Waldo.find(id)
16
+ waldo['location'].should == 'amsterdam'
17
+ end
18
+
19
+ it "should delete porn" do
20
+ id = @db.create 'porn', { :website => 'youporn.com' }
21
+
22
+ class Porn < Ki::Model
23
+ end
24
+
25
+ expect {
26
+ Porn.delete(id)
27
+ }.to change(@db.db['porn'], :count).by(-1)
28
+ end
29
+
30
+ it "should count sheep" do
31
+ class Sheep < Ki::Model
32
+ end
33
+
34
+ Sheep.count.should == 0
35
+ expect {
36
+ @db.create 'sheep', { :wool => 'green' }
37
+ }.to change(Sheep, :count).by(1)
38
+ Sheep.count.should == 1
39
+ end
40
+
41
+ it "should create the universe in 7 days" do
42
+ class Universe < Ki::Model
43
+ end
44
+
45
+ universe = { :water => true }
46
+ Universe.count.should == 0
47
+ expect {
48
+ id = Universe.create universe
49
+ Universe.find(id)['water'].should be_true
50
+ }.to change(Universe, :count).by(1)
51
+ end
52
+
53
+ it "should update all the software" do
54
+ class Software < Ki::Model
55
+ end
56
+
57
+ id = Software.create({ :version => 1.1 })
58
+ expect {
59
+ Software.update({'_id' => id, :version => 1.2})
60
+ Software.find(id)['version'].should == 1.2
61
+ }.to change(Software, :count).by(0)
62
+ end
63
+ end
@@ -0,0 +1,64 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Ki::Restrictions do
4
+ it "should only allow specified methods" do
5
+ class Foo < Ki::Model
6
+ end
7
+ expect {
8
+ Foo.new(ReqFactory.new(:head))
9
+ }.to raise_error
10
+ end
11
+
12
+ it "should not have any restrictions by default" do
13
+ class Foo < Ki::Model
14
+ end
15
+ Foo.forbidden_actions.empty?.should be_true
16
+ Foo.new(ReqFactory.new(:post_homer))
17
+ end
18
+
19
+ it "should only restrict :delete" do
20
+ class Foo < Ki::Model
21
+ forbid :delete
22
+ end
23
+ Foo.forbidden_actions.include?(:delete).should be_true
24
+ id = Foo.new(ReqFactory.new(:post_homer)).hash['_id']
25
+ expect {
26
+ Foo.new(ReqFactory.new(:delete, { '_id' => id } ))
27
+ }.to raise_exception
28
+ end
29
+
30
+ it "should respond to html and json by default" do
31
+ class Foo < Ki::Model
32
+ end
33
+ Foo.allowed_formats.should == [:json, :html]
34
+ end
35
+
36
+ it "should allow only json" do
37
+ class Foo < Ki::Model
38
+ respond_to :json
39
+ end
40
+ Foo.allowed_formats.include?(:json).should be_true
41
+ Foo.allowed_formats.include?(:html).should be_false
42
+ end
43
+
44
+ it "should not have any required attributes" do
45
+ class Foo < Ki::Model
46
+ end
47
+ Foo.required_attributes.empty?.should be_true
48
+ end
49
+
50
+ it "should require name" do
51
+ class Foo < Ki::Model
52
+ requires :name
53
+ end
54
+ Foo.required_attributes.include?(:name).should be_true
55
+
56
+ expect {
57
+ Foo.new(ReqFactory.new(:post_homer))
58
+ }.to raise_exception
59
+
60
+ expect {
61
+ Foo.new(ReqFactory.new(:post, {'name' => 'bart' }))
62
+ }.to change(Ki::Db.instance.db['foo'], :count).by(1)
63
+ end
64
+ end
data/spec/req_spec.rb ADDED
@@ -0,0 +1,4 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Ki::Req do
4
+ end
data/spec/spec_helper.rb CHANGED
@@ -7,6 +7,35 @@ require 'ki'
7
7
  # in ./support/ and its subdirectories.
8
8
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
9
 
10
+ DB_NAME = 'test_ki_db'
11
+ DB_HOST = '127.0.0.1'
12
+ DB_PORT = 27017
13
+
14
+ Ki::Db.instance.config DB_HOST, DB_PORT, DB_NAME
15
+
16
+ class MockReq
17
+ attr_accessor :request_method
18
+ attr_accessor :params
19
+ end
20
+
21
+ class ReqFactory
22
+ def self.new sym, params={}
23
+ case sym
24
+ when :get, :post, :put, :delete, :head
25
+ mr = MockReq.new
26
+ mr.request_method = sym.to_s.upcase
27
+ mr.params = params
28
+ return mr
29
+ when :post_homer
30
+ mr = MockReq.new
31
+ mr.request_method = 'POST'
32
+ mr.params = { 'user' => 'homer' }
33
+ return mr
34
+ else
35
+ raise "not a valid factory"
36
+ end
37
+ end
38
+ end
39
+
10
40
  RSpec.configure do |config|
11
-
12
41
  end
data/spec/util_spec.rb CHANGED
@@ -1,25 +1,41 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
+ def format s, output
4
+ Ki::Util.format(s).should == output
5
+ end
6
+
7
+ def base s, output
8
+ Ki::Util.base(s).should == output
9
+ end
10
+
3
11
  describe Ki::Util do
4
- it "should extrac the base url correctly" do
5
- Ki::Util.base("/foo").should == "foo"
6
- Ki::Util.base("/foo?bar=dar").should == "foo"
7
- Ki::Util.base("/foo.json").should == "foo"
8
- Ki::Util.base("/foo.json?bar=dar").should == "foo"
12
+ it "should parse format correctly" do
13
+ format '/', :html
14
+ format '/index', :html
15
+ format '/index.html', :html
16
+ format '/index.html?asd=1', :html
17
+ format '/index?asd=1', :html
18
+ format '/john?asd=', :html
19
+ format '/asd?asd=1&bar=2', :html
20
+ format '/welcome.json', :json
21
+ format '/welcome.json?foo', :json
22
+ format '/welcome.json?foo=1&ar=2', :json
9
23
  end
10
24
 
11
- it "should convert string to class" do
12
- class Foo
13
- end
14
-
15
- "Foo".to_class.should == Foo
16
- "foo".to_class.should == Foo
25
+ it "should get the base url correctly" do
26
+ base '/', ''
27
+ base '/index', 'index'
28
+ base '/foo?bar=1', 'foo'
29
+ base '/asd/bar', 'asd'
30
+ base '/asd.json', 'asd'
31
+ base '/foo.html', 'foo'
17
32
  end
18
33
 
19
- it "should extract format correctly" do
20
- Ki::Util.format('/foo').should == :html
21
- Ki::Util.format('/foo.json').should == :json
22
- Ki::Util.format('/foo.html').should == :html
23
- Ki::Util.format('/foo.json?bar=dar').should == :json
34
+ it "should correctly convert to a class" do
35
+ "dog".to_class.should == nil
36
+ class Dog
37
+ end
38
+ "dog".to_class.should == Dog
39
+ "cat".to_class.should == nil
24
40
  end
25
41
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ki
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-31 00:00:00.000000000 Z
12
+ date: 2013-02-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
@@ -28,7 +28,7 @@ dependencies:
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
30
  - !ruby/object:Gem::Dependency
31
- name: thin
31
+ name: mongo
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  none: false
34
34
  requirements:
@@ -44,7 +44,7 @@ dependencies:
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
46
  - !ruby/object:Gem::Dependency
47
- name: mongo
47
+ name: bson_ext
48
48
  requirement: !ruby/object:Gem::Requirement
49
49
  none: false
50
50
  requirements:
@@ -60,7 +60,7 @@ dependencies:
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  - !ruby/object:Gem::Dependency
63
- name: bson_ext
63
+ name: thor
64
64
  requirement: !ruby/object:Gem::Requirement
65
65
  none: false
66
66
  requirements:
@@ -92,7 +92,7 @@ dependencies:
92
92
  - !ruby/object:Gem::Version
93
93
  version: '0'
94
94
  - !ruby/object:Gem::Dependency
95
- name: thor
95
+ name: thin
96
96
  requirement: !ruby/object:Gem::Requirement
97
97
  none: false
98
98
  requirements:
@@ -108,7 +108,7 @@ dependencies:
108
108
  - !ruby/object:Gem::Version
109
109
  version: '0'
110
110
  - !ruby/object:Gem::Dependency
111
- name: shotgun
111
+ name: rspec
112
112
  requirement: !ruby/object:Gem::Requirement
113
113
  none: false
114
114
  requirements:
@@ -124,7 +124,39 @@ dependencies:
124
124
  - !ruby/object:Gem::Version
125
125
  version: '0'
126
126
  - !ruby/object:Gem::Dependency
127
- name: rspec
127
+ name: guard-rspec
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ - !ruby/object:Gem::Dependency
143
+ name: rb-inotify
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ~>
148
+ - !ruby/object:Gem::Version
149
+ version: 0.8.8
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ~>
156
+ - !ruby/object:Gem::Version
157
+ version: 0.8.8
158
+ - !ruby/object:Gem::Dependency
159
+ name: rdoc
128
160
  requirement: !ruby/object:Gem::Requirement
129
161
  none: false
130
162
  requirements:
@@ -171,7 +203,24 @@ dependencies:
171
203
  - - ! '>='
172
204
  - !ruby/object:Gem::Version
173
205
  version: '0'
174
- description: longer description of your gem
206
+ - !ruby/object:Gem::Dependency
207
+ name: simplecov
208
+ requirement: !ruby/object:Gem::Requirement
209
+ none: false
210
+ requirements:
211
+ - - ! '>='
212
+ - !ruby/object:Gem::Version
213
+ version: '0'
214
+ type: :development
215
+ prerelease: false
216
+ version_requirements: !ruby/object:Gem::Requirement
217
+ none: false
218
+ requirements:
219
+ - - ! '>='
220
+ - !ruby/object:Gem::Version
221
+ version: '0'
222
+ description: Fuck setting up a database for your prototypes. Some call it an ORM with
223
+ a RESTful interface. Some say its for prototyping.
175
224
  email: mess110@gmail.com
176
225
  executables:
177
226
  - ki
@@ -184,45 +233,49 @@ files:
184
233
  - .rspec
185
234
  - .rvmrc
186
235
  - Gemfile
236
+ - Gemfile.lock
237
+ - Guardfile
187
238
  - LICENSE.txt
188
239
  - README.rdoc
189
240
  - Rakefile
190
241
  - VERSION
191
242
  - bin/ki
192
243
  - examples/base/Gemfile
244
+ - examples/base/Gemfile.lock
193
245
  - examples/base/app.rb
194
246
  - examples/base/config.ru
195
- - examples/base/config.yml
196
- - examples/example/Gemfile
197
- - examples/example/app.rb
198
- - examples/example/config.ru
199
- - examples/example/config.yml
200
- - examples/example/public/custom.css
201
- - examples/example/public/custom.js
202
- - lib/cli.rb
203
- - lib/controller.rb
247
+ - examples/northpole/Gemfile
248
+ - examples/northpole/Gemfile.lock
249
+ - examples/northpole/app.rb
250
+ - examples/northpole/config.ru
251
+ - examples/northpole/config.yml
252
+ - examples/northpole/views/index.haml
253
+ - examples/northpole/views/website.haml
254
+ - ki.gemspec
204
255
  - lib/db.rb
256
+ - lib/extensions/mail.rb
257
+ - lib/helpers.rb
205
258
  - lib/ki.rb
259
+ - lib/ki_cli.rb
206
260
  - lib/model.rb
207
- - lib/modules.rb
208
- - lib/public/bootstrap.css
209
- - lib/public/bootstrap.js
210
- - lib/public/custom.css
211
- - lib/public/custom.js
212
- - lib/public/glyphicons-halflings-white.png
213
- - lib/public/glyphicons-halflings.png
214
- - lib/public/jquery-1.8.2.min.js
215
- - lib/public/ki.css
216
- - lib/request.rb
217
- - lib/response.rb
261
+ - lib/modules/callbacks.rb
262
+ - lib/modules/query_interface.rb
263
+ - lib/modules/restrictions.rb
264
+ - lib/req.rb
265
+ - lib/resp.rb
266
+ - lib/static_file.rb
218
267
  - lib/util.rb
219
- - lib/views/container.haml
220
- - lib/views/footer.haml
221
- - lib/views/form.haml
268
+ - lib/views/404.haml
269
+ - lib/views/406.haml
222
270
  - lib/views/index.haml
223
- - lib/views/models.haml
224
- - lib/views/navbar.haml
271
+ - logo.png
272
+ - spec/db_spec.rb
225
273
  - spec/ki_spec.rb
274
+ - spec/model_spec.rb
275
+ - spec/modules/callbacks_spec.rb
276
+ - spec/modules/query_interface_spec.rb
277
+ - spec/modules/restrictions_spec.rb
278
+ - spec/req_spec.rb
226
279
  - spec/spec_helper.rb
227
280
  - spec/util_spec.rb
228
281
  homepage: http://github.com/mess110/ki
@@ -240,7 +293,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
240
293
  version: '0'
241
294
  segments:
242
295
  - 0
243
- hash: 2106213773731717633
296
+ hash: -1834327354065041712
244
297
  required_rubygems_version: !ruby/object:Gem::Requirement
245
298
  none: false
246
299
  requirements:
@@ -252,5 +305,5 @@ rubyforge_project:
252
305
  rubygems_version: 1.8.24
253
306
  signing_key:
254
307
  specification_version: 3
255
- summary: one-line summary of your gem
308
+ summary: Prototyping noSQL RESTful API cloud database
256
309
  test_files: []