ki 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.rvmrc +1 -1
- data/Gemfile +6 -3
- data/Gemfile.lock +81 -0
- data/Guardfile +9 -0
- data/LICENSE.txt +1 -1
- data/README.rdoc +8 -1
- data/Rakefile +17 -3
- data/VERSION +1 -1
- data/bin/ki +3 -2
- data/examples/base/Gemfile +1 -7
- data/examples/base/Gemfile.lock +24 -0
- data/examples/base/app.rb +1 -2
- data/examples/base/config.ru +4 -0
- data/examples/{example → northpole}/Gemfile +0 -1
- data/examples/northpole/Gemfile.lock +33 -0
- data/examples/northpole/app.rb +19 -0
- data/examples/northpole/config.ru +6 -0
- data/examples/northpole/config.yml +3 -0
- data/examples/northpole/views/index.haml +1 -0
- data/examples/northpole/views/website.haml +1 -0
- data/ki.gemspec +125 -0
- data/lib/db.rb +43 -13
- data/lib/extensions/mail.rb +41 -0
- data/lib/helpers.rb +16 -0
- data/lib/ki.rb +8 -27
- data/lib/ki_cli.rb +63 -0
- data/lib/model.rb +59 -92
- data/lib/modules/callbacks.rb +27 -0
- data/lib/modules/query_interface.rb +29 -0
- data/lib/modules/restrictions.rb +62 -0
- data/lib/req.rb +30 -0
- data/lib/resp.rb +50 -0
- data/lib/static_file.rb +14 -0
- data/lib/util.rb +21 -30
- data/lib/views/404.haml +7 -0
- data/lib/views/406.haml +7 -0
- data/lib/views/index.haml +5 -17
- data/logo.png +0 -0
- data/spec/db_spec.rb +71 -0
- data/spec/ki_spec.rb +2 -2
- data/spec/model_spec.rb +82 -0
- data/spec/modules/callbacks_spec.rb +14 -0
- data/spec/modules/query_interface_spec.rb +63 -0
- data/spec/modules/restrictions_spec.rb +64 -0
- data/spec/req_spec.rb +4 -0
- data/spec/spec_helper.rb +30 -1
- data/spec/util_spec.rb +32 -16
- metadata +89 -36
- data/examples/base/config.yml +0 -3
- data/examples/example/app.rb +0 -15
- data/examples/example/config.ru +0 -2
- data/examples/example/config.yml +0 -3
- data/examples/example/public/custom.css +0 -0
- data/examples/example/public/custom.js +0 -0
- data/lib/cli.rb +0 -51
- data/lib/controller.rb +0 -15
- data/lib/modules.rb +0 -54
- data/lib/public/bootstrap.css +0 -6004
- data/lib/public/bootstrap.js +0 -2036
- data/lib/public/custom.css +0 -0
- data/lib/public/custom.js +0 -0
- data/lib/public/glyphicons-halflings-white.png +0 -0
- data/lib/public/glyphicons-halflings.png +0 -0
- data/lib/public/jquery-1.8.2.min.js +0 -2
- data/lib/public/ki.css +0 -56
- data/lib/request.rb +0 -14
- data/lib/response.rb +0 -51
- data/lib/views/container.haml +0 -6
- data/lib/views/footer.haml +0 -2
- data/lib/views/form.haml +0 -10
- data/lib/views/models.haml +0 -14
- 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
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
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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
|
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:
|
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:
|
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:
|
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:
|
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:
|
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:
|
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
|
-
|
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/
|
196
|
-
- examples/
|
197
|
-
- examples/
|
198
|
-
- examples/
|
199
|
-
- examples/
|
200
|
-
- examples/
|
201
|
-
- examples/
|
202
|
-
-
|
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/
|
209
|
-
- lib/
|
210
|
-
- lib/
|
211
|
-
- lib/
|
212
|
-
- lib/
|
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/
|
220
|
-
- lib/views/
|
221
|
-
- lib/views/form.haml
|
268
|
+
- lib/views/404.haml
|
269
|
+
- lib/views/406.haml
|
222
270
|
- lib/views/index.haml
|
223
|
-
-
|
224
|
-
-
|
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:
|
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:
|
308
|
+
summary: Prototyping noSQL RESTful API cloud database
|
256
309
|
test_files: []
|