ki 0.4.11 → 0.4.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +9 -0
- data/.ruby-gemset +1 -1
- data/.ruby-version +1 -1
- data/.travis.yml +10 -2
- data/Gemfile +2 -0
- data/Gemfile.lock +95 -85
- data/Guardfile +20 -14
- data/MIDDLEWARE.md +2 -2
- data/README.md +29 -1
- data/Rakefile +3 -1
- data/bin/ki +1 -0
- data/ki.gemspec +15 -14
- data/lib/ki.rb +8 -1
- data/lib/ki/base_request.rb +7 -5
- data/lib/ki/channel_manager.rb +2 -0
- data/lib/ki/helpers.rb +4 -5
- data/lib/ki/ki.rb +11 -2
- data/lib/ki/ki_app.rb +2 -0
- data/lib/ki/ki_cli.rb +9 -2
- data/lib/ki/ki_config.rb +5 -2
- data/lib/ki/ki_logger.rb +15 -0
- data/lib/ki/middleware/admin_interface_generator.rb +3 -1
- data/lib/ki/middleware/api_handler.rb +3 -1
- data/lib/ki/middleware/base_middleware.rb +2 -0
- data/lib/ki/middleware/coffee_compiler.rb +2 -0
- data/lib/ki/middleware/haml_compiler.rb +2 -0
- data/lib/ki/middleware/helpers/format_of_helper.rb +3 -1
- data/lib/ki/middleware/helpers/haml_compiler_helper.rb +7 -5
- data/lib/ki/middleware/helpers/public_file_helper.rb +2 -0
- data/lib/ki/middleware/helpers/redirect_to_helper.rb +2 -0
- data/lib/ki/middleware/helpers/view_helper.rb +2 -0
- data/lib/ki/middleware/init_middleware.rb +2 -0
- data/lib/ki/middleware/{doc_generator.rb → insta_doc.rb} +8 -6
- data/lib/ki/middleware/public_file_server.rb +2 -0
- data/lib/ki/middleware/realtime.rb +3 -1
- data/lib/ki/middleware/sass_compiler.rb +2 -0
- data/lib/ki/model.rb +8 -7
- data/lib/ki/modules/callbacks.rb +12 -20
- data/lib/ki/modules/model_helper.rb +2 -0
- data/lib/ki/modules/query_interface.rb +2 -0
- data/lib/ki/modules/restrictions.rb +5 -2
- data/lib/ki/orm.rb +20 -13
- data/lib/ki/utils/annotations.rb +33 -0
- data/lib/ki/utils/api_error.rb +14 -4
- data/lib/ki/utils/descendants.rb +9 -0
- data/lib/ki/utils/extra_irb.rb +3 -1
- data/lib/ki/utils/extra_ruby.rb +12 -0
- data/lib/ki/utils/indifferent_hash.rb +2 -0
- data/lib/ki/utils/logger.rb +5 -0
- data/lib/ki/version.rb +3 -1
- data/lib/ki/views/instadoc.haml +49 -9
- data/spec/config.yml.example +1 -1
- data/spec/examples/base/client.rb +20 -0
- data/spec/examples/base/logs/.keep +0 -0
- data/spec/examples/base/public/javascripts/app.js +12 -0
- data/spec/examples/json.northpole.ro/.ruby-version +1 -1
- data/spec/examples/json.northpole.ro/public/javascripts/app.coffee +1 -0
- data/spec/functional_spec.rb +2 -0
- data/spec/lib/ki/base_request_spec.rb +25 -23
- data/spec/lib/ki/channel_manager_spec.rb +2 -0
- data/spec/lib/ki/helpers_spec.rb +4 -2
- data/spec/lib/ki/indifferent_hash_spec.rb +2 -0
- data/spec/lib/ki/ki_app_spec.rb +2 -0
- data/spec/lib/ki/ki_config_spec.rb +5 -3
- data/spec/lib/ki/ki_spec.rb +2 -0
- data/spec/lib/ki/middleware/admin_generator_spec.rb +2 -0
- data/spec/lib/ki/middleware/haml_compiler_spec.rb +6 -3
- data/spec/lib/ki/middleware/helpers/format_of_helper_spec.rb +4 -2
- data/spec/lib/ki/middleware/init_middleware_spec.rb +3 -1
- data/spec/lib/ki/middleware/{doc_generator_spec.rb → insta_doc_spec.rb} +3 -1
- data/spec/lib/ki/middleware/realtime_spec.rb +12 -6
- data/spec/lib/ki/middleware_spec.rb +3 -1
- data/spec/lib/ki/model_spec.rb +26 -22
- data/spec/lib/ki/modules/model_helper_spec.rb +5 -3
- data/spec/lib/ki/modules/restrictions_spec.rb +16 -0
- data/spec/lib/ki/orm_spec.rb +18 -15
- data/spec/lib/ki/utils/api_error_spec.rb +9 -0
- data/spec/spec_helper.rb +13 -7
- data/spec/util_spec.rb +3 -1
- metadata +44 -30
data/spec/lib/ki/helpers_spec.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Ki::Helpers do
|
4
6
|
include Ki::Helpers
|
5
7
|
|
6
8
|
it 'should render_haml' do
|
7
|
-
haml('%div.foo').
|
9
|
+
expect(haml('%div.foo')).to eq "<div class='foo'></div>\n"
|
8
10
|
end
|
9
11
|
|
10
12
|
it 'renders css tag' do
|
@@ -22,7 +24,7 @@ describe Ki::Helpers do
|
|
22
24
|
end
|
23
25
|
|
24
26
|
it 'renders haml' do
|
25
|
-
File.
|
27
|
+
expect(File).to receive(:join).and_return('lib/ki/views/404.haml')
|
26
28
|
expect(partial('404')).to include('h1')
|
27
29
|
end
|
28
30
|
end
|
data/spec/lib/ki/ki_app_spec.rb
CHANGED
@@ -1,15 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Ki::KiConfig do
|
4
6
|
let(:config) { Ki::KiConfig.instance }
|
5
7
|
|
6
8
|
it 'should know db name in test env' do
|
7
|
-
config.environment.
|
9
|
+
expect(config.environment).to eq 'test'
|
8
10
|
end
|
9
11
|
|
10
12
|
it 'is overwritten for testing. see spec_helper' do
|
11
13
|
path = config.config_file_path
|
12
|
-
path.
|
14
|
+
expect(path).to be_start_with('spec/config.yml')
|
13
15
|
end
|
14
16
|
|
15
17
|
it 'defaults cors to true' do
|
@@ -48,7 +50,7 @@ describe Ki::KiConfig do
|
|
48
50
|
end
|
49
51
|
|
50
52
|
it 'does not add duplicate middleware' do
|
51
|
-
config.config['add_middleware'] = %w
|
53
|
+
config.config['add_middleware'] = %w[Realtime Realtime]
|
52
54
|
expect(config.middleware.to_s.scan(/Realtime/).count).to eq 1
|
53
55
|
end
|
54
56
|
end
|
data/spec/lib/ki/ki_spec.rb
CHANGED
@@ -1,17 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Ki::Middleware::HamlCompiler do
|
4
6
|
let(:compiler) { Ki::Middleware::HamlCompiler }
|
5
7
|
|
6
8
|
it 'works' do
|
7
|
-
|
8
|
-
|
9
|
+
# TODO: find out why twice
|
10
|
+
expect_any_instance_of(compiler).to receive(:view_exists?).twice.and_return(true)
|
11
|
+
expect(File).to receive(:read).twice.and_return('%p hello')
|
9
12
|
get '/existing_haml'
|
10
13
|
expect(last_response.body).to eq "<p>hello</p>\n"
|
11
14
|
end
|
12
15
|
|
13
16
|
it 'passes to next middleware' do
|
14
|
-
compiler.
|
17
|
+
expect_any_instance_of(compiler).to receive(:view_exists?).and_return(false)
|
15
18
|
get '/inexisting_haml'
|
16
19
|
expect(last_response.body).to eq '<h1>404</h1>'
|
17
20
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Ki::Middleware::Helpers::FormatOf do
|
@@ -8,11 +10,11 @@ describe Ki::Middleware::Helpers::FormatOf do
|
|
8
10
|
|
9
11
|
it 'should parse url format' do
|
10
12
|
[nil, {}, '', '.json'].each do |s|
|
11
|
-
obj.format_of(s).
|
13
|
+
expect(obj.format_of(s)).to eq ''
|
12
14
|
end
|
13
15
|
|
14
16
|
['asd.json', 'asd.json?asd=1'].each do |s|
|
15
|
-
obj.format_of(s).
|
17
|
+
expect(obj.format_of(s)).to eq 'json'
|
16
18
|
end
|
17
19
|
end
|
18
20
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Ki::Middleware::InitMiddleware do
|
@@ -14,7 +16,7 @@ describe Ki::Middleware::InitMiddleware do
|
|
14
16
|
it 'renders index.html if it exists' do
|
15
17
|
env = Rack::MockRequest.env_for('/', { 'REQUEST_METHOD' => 'GET' })
|
16
18
|
|
17
|
-
Ki::Middleware::InitMiddleware.
|
19
|
+
expect_any_instance_of(Ki::Middleware::InitMiddleware).to receive(:public_file_exists?).and_return(true)
|
18
20
|
resp = init.call env
|
19
21
|
expect(resp[0]).to eq 404 # not found because index.html doesn't exist
|
20
22
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
# TODO: find a way to test
|
@@ -18,8 +20,10 @@ describe Ki::Middleware::Realtime do
|
|
18
20
|
it 'handle_websocket' do
|
19
21
|
env = Rack::MockRequest.env_for('/realtime', { 'REQUEST_METHOD' => 'GET' })
|
20
22
|
|
21
|
-
Ki::Middleware::Realtime.any_instance.stub(:handle_websocket).and_return('handle_websocket')
|
22
|
-
Faye::WebSocket.stub(:websocket?).and_return(true)
|
23
|
+
# Ki::Middleware::Realtime.any_instance.stub(:handle_websocket).and_return('handle_websocket')
|
24
|
+
# Faye::WebSocket.stub(:websocket?).and_return(true)
|
25
|
+
expect_any_instance_of(Ki::Middleware::Realtime).to receive(:handle_websocket).and_return('handle_websocket')
|
26
|
+
expect(Faye::WebSocket).to receive(:websocket?).and_return(true)
|
23
27
|
|
24
28
|
resp = realtime.call env
|
25
29
|
expect(resp).to eq 'handle_websocket'
|
@@ -27,15 +31,17 @@ describe Ki::Middleware::Realtime do
|
|
27
31
|
|
28
32
|
it 'continues call' do
|
29
33
|
env = Rack::MockRequest.env_for('/bazinga', { 'REQUEST_METHOD' => 'GET' })
|
30
|
-
Hash.
|
34
|
+
expect_any_instance_of(Hash).to receive(:call).and_return('continue')
|
35
|
+
# Hash.any_instance.stub(:call).and_return('continue')
|
31
36
|
resp = realtime.call env
|
32
37
|
expect(resp).to eq 'continue'
|
33
38
|
end
|
34
39
|
|
35
40
|
it 'has ws_send' do
|
36
41
|
ws = {}
|
37
|
-
ws.
|
38
|
-
|
42
|
+
expect(ws).to receive(:send).and_return(true)
|
43
|
+
# ws.stub(:send).and_return true
|
44
|
+
expect(realtime.ws_send(ws, {})).to be true
|
39
45
|
end
|
40
46
|
|
41
47
|
describe 'on_message' do
|
@@ -43,7 +49,7 @@ describe Ki::Middleware::Realtime do
|
|
43
49
|
let(:db) { Ki::Orm::Db.instance }
|
44
50
|
|
45
51
|
before :each do
|
46
|
-
realtime.
|
52
|
+
allow(realtime).to receive(:ws_send) do |_arg1, arg2|
|
47
53
|
arg2
|
48
54
|
end
|
49
55
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Ki::Middleware do
|
@@ -5,7 +7,7 @@ describe Ki::Middleware do
|
|
5
7
|
it 'should only handle urls maped from objects that extend Ki::Model' do
|
6
8
|
get '/asd.json'
|
7
9
|
json
|
8
|
-
last_response.status.
|
10
|
+
expect(last_response.status).to eq 404
|
9
11
|
end
|
10
12
|
end
|
11
13
|
end
|
data/spec/lib/ki/model_spec.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Ki::Model do
|
@@ -6,20 +8,20 @@ describe Ki::Model do
|
|
6
8
|
class Bar < Ki::Model; end
|
7
9
|
end
|
8
10
|
|
9
|
-
it '
|
11
|
+
it 'knows about descendants' do
|
10
12
|
desc = Ki::Model.descendants
|
11
|
-
desc.include
|
12
|
-
desc.include
|
13
|
+
expect(desc).to include(Foo)
|
14
|
+
expect(desc).to include(Bar)
|
13
15
|
end
|
14
16
|
|
15
17
|
context Ki::Model::QueryInterface do
|
16
18
|
it 'should have the query interface' do
|
17
|
-
Foo.class_name.
|
19
|
+
expect(Foo.class_name).to eq 'Foo'
|
18
20
|
expect do
|
19
21
|
id = Foo.create({ hello: 'world' })['id']
|
20
|
-
Foo.find(id).first['hello'].
|
22
|
+
expect(Foo.find(id).first['hello']).to eq 'world'
|
21
23
|
Foo.update('id' => id, 'hello' => 'universe')
|
22
|
-
Foo.find(id).first['hello'].
|
24
|
+
expect(Foo.find(id).first['hello']).to eq 'universe'
|
23
25
|
Foo.delete(id)
|
24
26
|
end.to change { Foo.count }.by 0
|
25
27
|
end
|
@@ -34,9 +36,9 @@ describe Ki::Model do
|
|
34
36
|
end
|
35
37
|
|
36
38
|
it 'should have restrictions configured' do
|
37
|
-
Bar.unique_attributes.
|
38
|
-
Bar.required_attributes.
|
39
|
-
Bar.forbidden_actions.
|
39
|
+
expect(Bar.unique_attributes).to eq []
|
40
|
+
expect(Bar.required_attributes).to eq []
|
41
|
+
expect(Bar.forbidden_actions).to eq []
|
40
42
|
|
41
43
|
class Bar < Ki::Model
|
42
44
|
unique :foo
|
@@ -44,9 +46,9 @@ describe Ki::Model do
|
|
44
46
|
forbid :delete
|
45
47
|
end
|
46
48
|
|
47
|
-
Bar.unique_attributes.
|
48
|
-
Bar.required_attributes.
|
49
|
-
Bar.forbidden_actions.
|
49
|
+
expect(Bar.unique_attributes).to eq [:foo]
|
50
|
+
expect(Bar.required_attributes).to eq [:foo]
|
51
|
+
expect(Bar.forbidden_actions).to eq [:delete]
|
50
52
|
end
|
51
53
|
|
52
54
|
context 'default properties' do
|
@@ -55,8 +57,10 @@ describe Ki::Model do
|
|
55
57
|
|
56
58
|
it 'should create object' do
|
57
59
|
mock_req = {}
|
58
|
-
mock_req.
|
59
|
-
mock_req.stub(:
|
60
|
+
expect(mock_req).to receive(:to_action).and_return(:create)
|
61
|
+
# mock_req.stub(:to_action).and_return(:create)
|
62
|
+
# mock_req.stub(:params).and_return({})
|
63
|
+
expect(mock_req).to receive(:params).and_return({})
|
60
64
|
|
61
65
|
expect {
|
62
66
|
DefaultProperties.new(mock_req)
|
@@ -78,8 +82,8 @@ describe Ki::Model do
|
|
78
82
|
SpecialProperties.delete({ 'foo' => t })
|
79
83
|
|
80
84
|
mock_req = {}
|
81
|
-
mock_req.
|
82
|
-
mock_req.
|
85
|
+
expect(mock_req).to receive(:to_action).and_return(:create)
|
86
|
+
expect(mock_req).to receive(:params).and_return('name' => 'zim', 'foo' => t)
|
83
87
|
|
84
88
|
expect {
|
85
89
|
SpecialProperties.new(mock_req)
|
@@ -88,8 +92,8 @@ describe Ki::Model do
|
|
88
92
|
|
89
93
|
it 'should check for required attributes' do
|
90
94
|
mock_req = {}
|
91
|
-
mock_req.
|
92
|
-
mock_req.
|
95
|
+
expect(mock_req).to receive(:to_action).and_return(:create)
|
96
|
+
expect(mock_req).to receive(:params).and_return({})
|
93
97
|
|
94
98
|
expect {
|
95
99
|
SpecialProperties.new(mock_req)
|
@@ -99,8 +103,8 @@ describe Ki::Model do
|
|
99
103
|
it 'should check for unique attributes' do
|
100
104
|
t = Time.now.to_i
|
101
105
|
mock_req = {}
|
102
|
-
mock_req.
|
103
|
-
mock_req.
|
106
|
+
expect(mock_req).to receive(:to_action).and_return(:create)
|
107
|
+
expect(mock_req).to receive(:params).and_return({ 'name' => 'zim', 'foo' => t })
|
104
108
|
|
105
109
|
expect {
|
106
110
|
SpecialProperties.new(mock_req)
|
@@ -110,8 +114,8 @@ describe Ki::Model do
|
|
110
114
|
|
111
115
|
it 'should not allow forbidden actions' do
|
112
116
|
mock_req = {}
|
113
|
-
mock_req.
|
114
|
-
mock_req.
|
117
|
+
expect(mock_req).to receive(:to_action).and_return(:delete)
|
118
|
+
expect(mock_req).to receive(:params).and_return({})
|
115
119
|
|
116
120
|
expect {
|
117
121
|
SpecialProperties.new(mock_req)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Ki::Model::ModelHelper do
|
@@ -28,8 +30,8 @@ describe Ki::Model::ModelHelper do
|
|
28
30
|
end
|
29
31
|
|
30
32
|
@req = TmpClassModelHelper.new
|
31
|
-
expect(post?).to
|
32
|
-
expect(put?).to
|
33
|
-
expect(delete?).to
|
33
|
+
expect(post?).to be true
|
34
|
+
expect(put?).to be true
|
35
|
+
expect(delete?).to be true
|
34
36
|
end
|
35
37
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Ki::Model::Restrictions do
|
6
|
+
before :all do
|
7
|
+
class DoubleRestricted < Ki::Model
|
8
|
+
requires :foo, :cez
|
9
|
+
requires :bar
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'merges multiple generic_restrictions' do
|
14
|
+
expect(DoubleRestricted.required_attributes).to eq %i[foo bar cez].sort
|
15
|
+
end
|
16
|
+
end
|
data/spec/lib/ki/orm_spec.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Ki::Orm do
|
@@ -6,7 +8,7 @@ describe Ki::Orm do
|
|
6
8
|
end
|
7
9
|
|
8
10
|
it 'should know db name in test env' do
|
9
|
-
@db.config['name'].
|
11
|
+
expect(@db.config['name']).to eq 'np_test'
|
10
12
|
end
|
11
13
|
|
12
14
|
it 'has a connection string' do
|
@@ -16,7 +18,7 @@ describe Ki::Orm do
|
|
16
18
|
it 'should create a db object' do
|
17
19
|
expect {
|
18
20
|
oid = @db.insert 'foo', { hello: 'world' }
|
19
|
-
oid.
|
21
|
+
expect(oid).to be_a(Hash)
|
20
22
|
}.to change { @db.count('foo') }.by(1)
|
21
23
|
end
|
22
24
|
|
@@ -39,28 +41,29 @@ describe Ki::Orm do
|
|
39
41
|
it 'should find all' do
|
40
42
|
@db.insert 'foo', { hello: 'world' }
|
41
43
|
@db.insert 'foo', { hello: 'world' }
|
42
|
-
@db.find('foo').to_a.size.
|
44
|
+
expect(@db.find('foo').to_a.size).to be >= 2
|
43
45
|
end
|
44
46
|
|
45
47
|
it 'should find by string id' do
|
46
48
|
obj_id = @db.insert('foo', { hello: 'world' })['id']
|
47
|
-
@db.find('foo', obj_id).first['id'].
|
49
|
+
expect(@db.find('foo', obj_id).first['id']).to eq obj_id
|
48
50
|
end
|
49
51
|
|
50
52
|
it 'should find by hash["id"]' do
|
51
|
-
obj_id = @db.insert
|
52
|
-
@db.find('foo', { 'id' => obj_id
|
53
|
+
obj_id = @db.insert('foo', { 'hello' => 'world' })['id']
|
54
|
+
find_query = @db.find('foo', { 'id' => obj_id })
|
55
|
+
expect(find_query.first['id']).to eq obj_id
|
53
56
|
end
|
54
57
|
|
55
58
|
it 'should find by hash["_id"]' do
|
56
59
|
obj_id = @db.insert('foo', { hello: 'world' })['id']
|
57
|
-
@db.find('foo', { '_id' => obj_id }).first['id'].
|
60
|
+
expect(@db.find('foo', { '_id' => obj_id }).first['id']).to eq obj_id
|
58
61
|
end
|
59
62
|
|
60
63
|
it 'should find by BSON::ObjectId(id)' do
|
61
64
|
obj_id = @db.insert('foo', { 'hello' => 'world' })['id']
|
62
|
-
@db.find('foo', { 'id' => BSON::ObjectId(obj_id) }).first['id'].
|
63
|
-
@db.find('foo', { '_id' => BSON::ObjectId(obj_id) }).first['id'].
|
65
|
+
expect(@db.find('foo', { 'id' => BSON::ObjectId(obj_id) }).first['id']).to eq obj_id
|
66
|
+
expect(@db.find('foo', { '_id' => BSON::ObjectId(obj_id) }).first['id']).to eq obj_id
|
64
67
|
end
|
65
68
|
|
66
69
|
it 'should return empty array when nothing found' do
|
@@ -75,12 +78,12 @@ describe Ki::Orm do
|
|
75
78
|
@db.insert('sort_tests', { 'value' => 1 })
|
76
79
|
@db.insert('sort_tests', { 'value' => 2 })
|
77
80
|
|
78
|
-
r = @db.find('sort_tests', { '__sort' => { 'value' =>
|
81
|
+
r = @db.find('sort_tests', { '__sort' => { 'value' => -1 } })
|
79
82
|
expect(r.size).to eq 2
|
80
83
|
expect(r[0]['value']).to eq 2
|
81
84
|
expect(r[1]['value']).to eq 1
|
82
85
|
|
83
|
-
r = @db.find('sort_tests', { '__sort' => { 'value' =>
|
86
|
+
r = @db.find('sort_tests', { '__sort' => { 'value' => 1 } })
|
84
87
|
expect(r.size).to eq 2
|
85
88
|
expect(r[0]['value']).to eq 1
|
86
89
|
expect(r[1]['value']).to eq 2
|
@@ -98,16 +101,16 @@ describe Ki::Orm do
|
|
98
101
|
|
99
102
|
it 'should update' do
|
100
103
|
obj_id = @db.insert('foo', { 'hello' => 'world' })['id']
|
101
|
-
@db.find('foo', obj_id).first['hello'].
|
104
|
+
expect(@db.find('foo', obj_id).first['hello']).to eq 'world'
|
102
105
|
up = @db.update('foo', { 'id' => obj_id, 'hello' => 'universe' })['id']
|
103
|
-
up.
|
104
|
-
@db.find('foo', obj_id).first['hello'].
|
106
|
+
expect(up).to eq obj_id
|
107
|
+
expect(@db.find('foo', obj_id).first['hello']).to eq 'universe'
|
105
108
|
end
|
106
109
|
|
107
110
|
it 'should delete by id' do
|
108
111
|
obj_id = @db.insert 'foo', { 'hello' => 'world' }
|
109
112
|
expect {
|
110
|
-
@db.delete('foo', obj_id).
|
113
|
+
expect(@db.delete('foo', obj_id)).to eq({ deleted_item_count: 1 })
|
111
114
|
}.to change { @db.count 'foo' }.by(-1)
|
112
115
|
end
|
113
116
|
end
|