ki 0.4.6 → 0.4.7

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 (54) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +24 -0
  3. data/Gemfile.lock +25 -6
  4. data/Guardfile +11 -5
  5. data/README.md +78 -0
  6. data/Rakefile +4 -4
  7. data/ki.gemspec +24 -23
  8. data/lib/ki.rb +7 -4
  9. data/lib/ki/base_request.rb +2 -2
  10. data/lib/ki/helpers.rb +7 -7
  11. data/lib/ki/ki.rb +12 -18
  12. data/lib/ki/ki_app.rb +16 -0
  13. data/lib/ki/ki_cli.rb +11 -12
  14. data/lib/ki/ki_config.rb +12 -8
  15. data/lib/ki/middleware/admin_interface_generator.rb +1 -1
  16. data/lib/ki/middleware/api_handler.rb +7 -8
  17. data/lib/ki/middleware/base_middleware.rb +1 -1
  18. data/lib/ki/middleware/coffee_compiler.rb +2 -2
  19. data/lib/ki/middleware/doc_generator.rb +5 -4
  20. data/lib/ki/middleware/haml_compiler.rb +4 -22
  21. data/lib/ki/{modules/format_of.rb → middleware/helpers/format_of_helper.rb} +3 -3
  22. data/lib/ki/middleware/helpers/haml_compiler_helper.rb +27 -0
  23. data/lib/ki/{modules → middleware/helpers}/public_file_helper.rb +2 -2
  24. data/lib/ki/{modules → middleware/helpers}/view_helper.rb +3 -3
  25. data/lib/ki/middleware/init_middleware.rb +1 -1
  26. data/lib/ki/middleware/public_file_server.rb +1 -1
  27. data/lib/ki/middleware/sass_compiler.rb +3 -3
  28. data/lib/ki/model.rb +10 -11
  29. data/lib/ki/modules/{model_helpers.rb → model_helper.rb} +1 -1
  30. data/lib/ki/modules/query_interface.rb +7 -7
  31. data/lib/ki/modules/restrictions.rb +4 -5
  32. data/lib/ki/orm.rb +11 -11
  33. data/lib/ki/utils/api_error.rb +4 -4
  34. data/lib/ki/utils/extra_ruby.rb +3 -3
  35. data/lib/ki/utils/indifferent_hash.rb +1 -1
  36. data/lib/ki/version.rb +1 -1
  37. data/lib/ki/views/404.haml +1 -0
  38. data/lib/ki/views/instadmin.haml +47 -4
  39. data/spec/examples/base/app.rb +5 -0
  40. data/spec/examples/json.northpole.ro/Gemfile +1 -1
  41. data/spec/lib/ki/base_request_spec.rb +24 -24
  42. data/spec/lib/ki/helpers_spec.rb +1 -1
  43. data/spec/lib/ki/ki_app_spec.rb +13 -0
  44. data/spec/lib/ki/ki_config_spec.rb +16 -2
  45. data/spec/lib/ki/ki_spec.rb +11 -0
  46. data/spec/lib/ki/middleware/haml_compiler_spec.rb +6 -4
  47. data/spec/lib/ki/{modules/format_of_spec.rb → middleware/helpers/format_of_helper_spec.rb} +4 -1
  48. data/spec/lib/ki/model_spec.rb +14 -14
  49. data/spec/lib/ki/modules/model_helper_spec.rb +4 -0
  50. data/spec/lib/ki/orm_spec.rb +25 -25
  51. data/spec/spec_helper.rb +6 -4
  52. data/spec/util_spec.rb +2 -2
  53. metadata +36 -14
  54. data/spec/lib/ki/modules/model_helpers_spec.rb +0 -4
@@ -1,16 +1,18 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Ki::Middleware::HamlCompiler do
4
+ let(:compiler) { Ki::Middleware::HamlCompiler }
5
+
4
6
  it 'works' do
5
- Ki::Middleware::HamlCompiler.any_instance.stub(:view_exists?).and_return(true)
6
- File.stub(:read).and_return("%p hello")
7
+ compiler.any_instance.stub(:view_exists?).and_return(true)
8
+ File.stub(:read).and_return('%p hello')
7
9
  get '/existing_haml'
8
10
  expect(last_response.body).to eq "<p>hello</p>\n"
9
11
  end
10
12
 
11
13
  it 'passes to next middleware' do
12
- Ki::Middleware::HamlCompiler.any_instance.stub(:view_exists?).and_return(false)
14
+ compiler.any_instance.stub(:view_exists?).and_return(false)
13
15
  get '/inexisting_haml'
14
- expect(last_response.body).to eq "misplaced in space"
16
+ expect(last_response.body).to eq '<h1>404</h1>'
15
17
  end
16
18
  end
@@ -1,7 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Ki::Middleware::Helpers::FormatOf do
4
- let(:obj) { @obj = Object.new; @obj.extend(Ki::Middleware::Helpers::FormatOf) }
4
+ let(:obj) {
5
+ @obj = Object.new
6
+ @obj.extend(Ki::Middleware::Helpers::FormatOf)
7
+ }
5
8
 
6
9
  it 'should parse url format' do
7
10
  [nil, {}, '', '.json'].each do |s|
@@ -6,7 +6,7 @@ describe Ki::Model do
6
6
  class Bar < Ki::Model; end
7
7
  end
8
8
 
9
- it "should know about all descendants" do
9
+ it 'should know about all descendants' do
10
10
  desc = Ki::Model.descendants
11
11
  desc.include?(Foo).should be_true
12
12
  desc.include?(Bar).should be_true
@@ -14,14 +14,14 @@ describe Ki::Model do
14
14
 
15
15
  context Ki::Model::QueryInterface do
16
16
  it 'should have the query interface' do
17
- Foo.class_name.should == 'Foo'
18
- expect {
19
- id = Foo.create({hello: 'world'})['id']
20
- Foo.find(id).first['hello'].should == 'world'
17
+ Foo.class_name.should eq 'Foo'
18
+ expect do
19
+ id = Foo.create({ hello: 'world' })['id']
20
+ Foo.find(id).first['hello'].should eq 'world'
21
21
  Foo.update('id' => id, 'hello' => 'universe')
22
- Foo.find(id).first['hello'].should == 'universe'
22
+ Foo.find(id).first['hello'].should eq 'universe'
23
23
  Foo.delete(id)
24
- }.to change { Foo.count }.by 0
24
+ end.to change { Foo.count }.by 0
25
25
  end
26
26
 
27
27
  it 'should find or create' do
@@ -34,9 +34,9 @@ describe Ki::Model do
34
34
  end
35
35
 
36
36
  it 'should have restrictions configured' do
37
- Bar.unique_attributes.should == []
38
- Bar.required_attributes.should == []
39
- Bar.forbidden_actions.should == []
37
+ Bar.unique_attributes.should eq []
38
+ Bar.required_attributes.should eq []
39
+ Bar.forbidden_actions.should eq []
40
40
 
41
41
  class Bar < Ki::Model
42
42
  unique :foo
@@ -44,9 +44,9 @@ describe Ki::Model do
44
44
  forbid :delete
45
45
  end
46
46
 
47
- Bar.unique_attributes.should == [:foo]
48
- Bar.required_attributes.should == [:foo]
49
- Bar.forbidden_actions.should == [:delete]
47
+ Bar.unique_attributes.should eq [:foo]
48
+ Bar.required_attributes.should eq [:foo]
49
+ Bar.forbidden_actions.should eq [:delete]
50
50
  end
51
51
 
52
52
  context 'default properties' do
@@ -71,7 +71,7 @@ describe Ki::Model do
71
71
  t = Time.now.to_i
72
72
  # keep in mind that delete does not call unique/requires/forbid filters
73
73
  # make sure there are no duplicates
74
- SpecialProperties.delete({'foo' => t})
74
+ SpecialProperties.delete({ 'foo' => t })
75
75
  expect {
76
76
  SpecialProperties.new(:create, { 'name' => 'zim', 'foo' => t })
77
77
  }.to change { SpecialProperties.count }.by 1
@@ -0,0 +1,4 @@
1
+ require 'spec_helper'
2
+
3
+ describe Ki::Model::ModelHelper do
4
+ end
@@ -15,73 +15,73 @@ describe Ki::Orm do
15
15
 
16
16
  it 'should create a db object' do
17
17
  expect {
18
- oid = @db.insert 'foo', {hello: 'world'}
18
+ oid = @db.insert 'foo', { hello: 'world' }
19
19
  oid.class.should == Hash
20
- }.to change{@db.count('foo')}.by(1)
20
+ }.to change { @db.count('foo') }.by(1)
21
21
  end
22
22
 
23
23
  context 'count' do
24
24
  it 'should count' do
25
25
  expect {
26
- @db.insert 'foo', {hello: 'world'}
27
- }.to change{@db.count('foo')}.by(1)
26
+ @db.insert 'foo', { hello: 'world' }
27
+ }.to change { @db.count('foo') }.by(1)
28
28
  end
29
29
 
30
30
  it 'should count by hash' do
31
31
  t = Time.now.to_i.to_s
32
32
  expect {
33
- @db.insert 'foo', {hello: t}
34
- }.to change{@db.count('foo', {hello: t})}.by(1)
33
+ @db.insert 'foo', { hello: t }
34
+ }.to change { @db.count('foo', { hello: t }) }.by(1)
35
35
  end
36
36
  end
37
37
 
38
38
  context 'find' do
39
39
  it 'should find all' do
40
- @db.insert 'foo', {hello: 'world'}
41
- @db.insert 'foo', {hello: 'world'}
42
- @db.find('foo').to_a.count.should >= 2
40
+ @db.insert 'foo', { hello: 'world' }
41
+ @db.insert 'foo', { hello: 'world' }
42
+ @db.find('foo').to_a.size.should >= 2
43
43
  end
44
44
 
45
45
  it 'should find by string id' do
46
- obj_id = @db.insert('foo', {hello: 'world'})['id']
47
- @db.find('foo', obj_id).first['id'].should == obj_id
46
+ obj_id = @db.insert('foo', { hello: 'world' })['id']
47
+ @db.find('foo', obj_id).first['id'].should eq obj_id
48
48
  end
49
49
 
50
50
  it 'should find by hash["id"]' do
51
- obj_id = @db.insert 'foo', {'hello' => 'world'}
52
- @db.find('foo', {'id' => obj_id['id']}).first.should == obj_id
51
+ obj_id = @db.insert 'foo', { 'hello' => 'world' }
52
+ @db.find('foo', { 'id' => obj_id['id'] }).first.should eq obj_id
53
53
  end
54
54
 
55
55
  it 'should find by hash["_id"]' do
56
- obj_id = @db.insert('foo', {hello: 'world'})['id']
57
- @db.find('foo', {'_id' => obj_id}).first['id'].should == obj_id
56
+ obj_id = @db.insert('foo', { hello: 'world' })['id']
57
+ @db.find('foo', { '_id' => obj_id }).first['id'].should eq obj_id
58
58
  end
59
59
 
60
60
  it 'should find by BSON::ObjectId(id)' do
61
- obj_id = @db.insert('foo', {'hello' => 'world'})['id']
62
- @db.find('foo', {'id' => BSON::ObjectId(obj_id)}).first['id'].should == obj_id
63
- @db.find('foo', {'_id' => BSON::ObjectId(obj_id)}).first['id'].should == obj_id
61
+ obj_id = @db.insert('foo', { 'hello' => 'world' })['id']
62
+ @db.find('foo', { 'id' => BSON::ObjectId(obj_id) }).first['id'].should eq obj_id
63
+ @db.find('foo', { '_id' => BSON::ObjectId(obj_id) }).first['id'].should eq obj_id
64
64
  end
65
65
 
66
66
  it 'should return empty array when nothing found' do
67
- r = @db.find('foo', {'it does not exist' => 'sure hope so' + Time.now.to_i.to_s })
68
- r.class.should == Array
69
- r.should be_empty
67
+ r = @db.find('foo', { 'it does not exist' => 'sure hope so' + Time.now.to_i.to_s })
68
+ expect(r.class).to eq Array
69
+ expect(r).to be_empty
70
70
  end
71
71
  end
72
72
 
73
73
  it 'should update' do
74
74
  obj_id = @db.insert('foo', { 'hello' => 'world' })['id']
75
- @db.find('foo', obj_id).first['hello'].should == 'world'
75
+ @db.find('foo', obj_id).first['hello'].should eq 'world'
76
76
  up = @db.update('foo', { 'id' => obj_id, 'hello' => 'universe' })['id']
77
- up.should == obj_id
78
- @db.find('foo', obj_id).first['hello'].should == 'universe'
77
+ up.should eq obj_id
78
+ @db.find('foo', obj_id).first['hello'].should eq 'universe'
79
79
  end
80
80
 
81
81
  it 'should delete by id' do
82
82
  obj_id = @db.insert 'foo', { 'hello' => 'world' }
83
83
  expect {
84
84
  @db.delete('foo', obj_id).should == {}
85
- }.to change { @db.count 'foo' }.by -1
85
+ }.to change { @db.count 'foo' }.by(-1)
86
86
  end
87
87
  end
@@ -1,4 +1,4 @@
1
- require "codeclimate-test-reporter"
1
+ require 'codeclimate-test-reporter'
2
2
  CodeClimate::TestReporter.start
3
3
 
4
4
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
@@ -12,7 +12,9 @@ require 'ki'
12
12
  module Ki
13
13
  class KiConfig
14
14
  def config_file_path
15
- config_yml_path = File.exists?('spec/config.yml') ? 'spec/config.yml' : 'spec/config.yml.example'
15
+ config_yml_path = 'spec/config.yml'
16
+ config_yml_path += '.example' unless File.exist?('spec/config.yml')
17
+
16
18
  if config_yml_path.end_with?('example')
17
19
  puts 'WARNING: spec/config.yml.example used'
18
20
  end
@@ -29,9 +31,9 @@ module Requests
29
31
  module JsonHelpers
30
32
  def json
31
33
  @json = JSON.parse(last_response.body)
32
- # TODO find out if it is needed to convert to a hash with indifferent
34
+ # TODO: find out if it is needed to convert to a hash with indifferent
33
35
  # access
34
- #@json = @json.with_indifferent_access if @json.class == Hash
36
+ # @json = @json.with_indifferent_access if @json.class == Hash
35
37
  @json
36
38
  end
37
39
  end
@@ -8,8 +8,8 @@ describe Ki do
8
8
  it 'should convert string to class corectly' do
9
9
  class Cez; end
10
10
  class CezBar; end
11
- 'cez'.to_class.should == Cez
12
- 'cez_bar'.to_class.should == CezBar
11
+ expect('cez'.to_class).to eq Cez
12
+ expect('cez_bar'.to_class).to eq CezBar
13
13
  end
14
14
 
15
15
  describe Array do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ki
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.6
4
+ version: 0.4.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cristian Mircea Messel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-16 00:00:00.000000000 Z
11
+ date: 2015-04-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -112,16 +112,16 @@ dependencies:
112
112
  name: mongo
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ">="
115
+ - - '='
116
116
  - !ruby/object:Gem::Version
117
- version: '0'
117
+ version: 1.9.2
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ">="
122
+ - - '='
123
123
  - !ruby/object:Gem::Version
124
- version: '0'
124
+ version: 1.9.2
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: bson_ext
127
127
  requirement: !ruby/object:Gem::Requirement
@@ -206,6 +206,20 @@ dependencies:
206
206
  - - ">="
207
207
  - !ruby/object:Gem::Version
208
208
  version: '0'
209
+ - !ruby/object:Gem::Dependency
210
+ name: guard-rubocop
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ">="
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ type: :development
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - ">="
221
+ - !ruby/object:Gem::Version
222
+ version: '0'
209
223
  - !ruby/object:Gem::Dependency
210
224
  name: codeclimate-test-reporter
211
225
  requirement: !ruby/object:Gem::Requirement
@@ -230,6 +244,7 @@ extra_rdoc_files: []
230
244
  files:
231
245
  - ".gitignore"
232
246
  - ".rspec"
247
+ - ".rubocop.yml"
233
248
  - ".ruby-gemset"
234
249
  - ".ruby-version"
235
250
  - ".travis.yml"
@@ -246,6 +261,7 @@ files:
246
261
  - lib/ki/base_request.rb
247
262
  - lib/ki/helpers.rb
248
263
  - lib/ki/ki.rb
264
+ - lib/ki/ki_app.rb
249
265
  - lib/ki/ki_cli.rb
250
266
  - lib/ki/ki_config.rb
251
267
  - lib/ki/middleware/admin_interface_generator.rb
@@ -254,23 +270,25 @@ files:
254
270
  - lib/ki/middleware/coffee_compiler.rb
255
271
  - lib/ki/middleware/doc_generator.rb
256
272
  - lib/ki/middleware/haml_compiler.rb
273
+ - lib/ki/middleware/helpers/format_of_helper.rb
274
+ - lib/ki/middleware/helpers/haml_compiler_helper.rb
275
+ - lib/ki/middleware/helpers/public_file_helper.rb
276
+ - lib/ki/middleware/helpers/view_helper.rb
257
277
  - lib/ki/middleware/init_middleware.rb
258
278
  - lib/ki/middleware/public_file_server.rb
259
279
  - lib/ki/middleware/sass_compiler.rb
260
280
  - lib/ki/model.rb
261
281
  - lib/ki/modules/callbacks.rb
262
- - lib/ki/modules/format_of.rb
263
- - lib/ki/modules/model_helpers.rb
264
- - lib/ki/modules/public_file_helper.rb
282
+ - lib/ki/modules/model_helper.rb
265
283
  - lib/ki/modules/query_interface.rb
266
284
  - lib/ki/modules/restrictions.rb
267
- - lib/ki/modules/view_helper.rb
268
285
  - lib/ki/orm.rb
269
286
  - lib/ki/utils/api_error.rb
270
287
  - lib/ki/utils/extra_irb.rb
271
288
  - lib/ki/utils/extra_ruby.rb
272
289
  - lib/ki/utils/indifferent_hash.rb
273
290
  - lib/ki/version.rb
291
+ - lib/ki/views/404.haml
274
292
  - lib/ki/views/instadmin.haml
275
293
  - lib/ki/views/instadoc.haml
276
294
  - spec/config.yml.example
@@ -396,13 +414,15 @@ files:
396
414
  - spec/lib/ki/base_request_spec.rb
397
415
  - spec/lib/ki/helpers_spec.rb
398
416
  - spec/lib/ki/indifferent_hash_spec.rb
417
+ - spec/lib/ki/ki_app_spec.rb
399
418
  - spec/lib/ki/ki_config_spec.rb
419
+ - spec/lib/ki/ki_spec.rb
400
420
  - spec/lib/ki/middleware/doc_generator_spec.rb
401
421
  - spec/lib/ki/middleware/haml_compiler_spec.rb
422
+ - spec/lib/ki/middleware/helpers/format_of_helper_spec.rb
402
423
  - spec/lib/ki/middleware_spec.rb
403
424
  - spec/lib/ki/model_spec.rb
404
- - spec/lib/ki/modules/format_of_spec.rb
405
- - spec/lib/ki/modules/model_helpers_spec.rb
425
+ - spec/lib/ki/modules/model_helper_spec.rb
406
426
  - spec/lib/ki/orm_spec.rb
407
427
  - spec/spec_helper.rb
408
428
  - spec/util_spec.rb
@@ -555,13 +575,15 @@ test_files:
555
575
  - spec/lib/ki/base_request_spec.rb
556
576
  - spec/lib/ki/helpers_spec.rb
557
577
  - spec/lib/ki/indifferent_hash_spec.rb
578
+ - spec/lib/ki/ki_app_spec.rb
558
579
  - spec/lib/ki/ki_config_spec.rb
580
+ - spec/lib/ki/ki_spec.rb
559
581
  - spec/lib/ki/middleware/doc_generator_spec.rb
560
582
  - spec/lib/ki/middleware/haml_compiler_spec.rb
583
+ - spec/lib/ki/middleware/helpers/format_of_helper_spec.rb
561
584
  - spec/lib/ki/middleware_spec.rb
562
585
  - spec/lib/ki/model_spec.rb
563
- - spec/lib/ki/modules/format_of_spec.rb
564
- - spec/lib/ki/modules/model_helpers_spec.rb
586
+ - spec/lib/ki/modules/model_helper_spec.rb
565
587
  - spec/lib/ki/orm_spec.rb
566
588
  - spec/spec_helper.rb
567
589
  - spec/util_spec.rb
@@ -1,4 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Ki::Model::ModelHelpers do
4
- end