ki 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.1
1
+ 0.3.2
data/ki.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "ki"
8
- s.version = "0.3.1"
8
+ s.version = "0.3.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Cristian Mircea Messel"]
12
- s.date = "2013-03-31"
12
+ s.date = "2013-06-27"
13
13
  s.description = "Fuck setting up a database for your prototypes. Some call it an ORM with a RESTful interface. Some say its for prototyping."
14
14
  s.email = "mess110@gmail.com"
15
15
  s.executables = ["ki"]
@@ -39,11 +39,13 @@ Gem::Specification.new do |s|
39
39
  "gfx/logo.png",
40
40
  "ki.gemspec",
41
41
  "ki_wrap.rb",
42
+ "lib/conf.rb",
42
43
  "lib/db.rb",
43
44
  "lib/extensions/mail.rb",
44
45
  "lib/helpers.rb",
45
46
  "lib/ki.rb",
46
47
  "lib/ki_cli.rb",
48
+ "lib/mockreq.rb",
47
49
  "lib/model.rb",
48
50
  "lib/modules/callbacks.rb",
49
51
  "lib/modules/model_helpers.rb",
@@ -57,6 +59,7 @@ Gem::Specification.new do |s|
57
59
  "lib/views/406.haml",
58
60
  "lib/views/index.haml",
59
61
  "lib/views/layout.haml",
62
+ "spec/conf_spec.rb",
60
63
  "spec/db_spec.rb",
61
64
  "spec/extensions/mail_spec.rb",
62
65
  "spec/integration/integration_spec.rb",
@@ -0,0 +1,28 @@
1
+ require 'singleton'
2
+
3
+ module Ki
4
+ # named conf because ruby has Config class :(
5
+ # in version 2 Config class will be deprecated and
6
+ # replace with RbConfig
7
+ # When you update to ruby2, think about changing the name
8
+ class Conf
9
+ include Singleton
10
+
11
+ attr_accessor :yaml
12
+
13
+ def initialize
14
+ super
15
+
16
+ config_path = File.join(Dir.pwd, 'config.yml')
17
+ if File.exists? config_path
18
+ @yaml = YAML.load_file(config_path)
19
+ else
20
+ @yaml = YAML.load({
21
+ 'database_host' => '127.0.0.1',
22
+ 'database_port' => 27017,
23
+ 'database_name' => 'ki_default_db'
24
+ }.to_yaml)
25
+ end
26
+ end
27
+ end
28
+ end
data/lib/db.rb CHANGED
@@ -8,6 +8,12 @@ module Ki
8
8
 
9
9
  attr_reader :db
10
10
 
11
+ def initialize
12
+ super
13
+
14
+ config
15
+ end
16
+
11
17
  def collection_names
12
18
  @db.collection_names.delete_if{|name| name =~ /^system/}
13
19
  end
@@ -25,10 +31,6 @@ module Ki
25
31
  end
26
32
 
27
33
  def find_by name, hash
28
- if hash['_id']
29
- hash['_id'] = BSON::ObjectId(hash['_id'])
30
- end
31
-
32
34
  if hash['id']
33
35
  hash['_id'] = BSON::ObjectId(hash['id'])
34
36
  hash.delete('id')
@@ -54,24 +56,18 @@ module Ki
54
56
  @db[name].remove(:_id => BSON::ObjectId(id))
55
57
  end
56
58
 
57
- def config_db
58
- config_path = File.join(Dir.pwd, 'config.yml')
59
- if File.exists? config_path
60
- yaml = YAML.load_file(config_path)
61
- config yaml['database_host'], yaml['database_port'], yaml['database_name']
62
- else
63
- config '127.0.0.1', 27017, 'ki_default_db'
64
- end
59
+ def db_name db_name
60
+ Conf.instance.yaml['database_name'] = db_name
61
+ @db = @con.db(db_name)
65
62
  end
66
63
 
67
- def config host, port, db_name
68
- # puts "Using #{db_name} at #{host}:#{port}"
69
- @con = Mongo::Connection.new(host, port)
70
- @db = @con.db(db_name)
64
+ def config
65
+ yaml = Conf.instance.yaml
66
+ @con = Mongo::Connection.new(yaml['database_host'], yaml['database_port'])
67
+ @db = @con.db(yaml['database_name'])
71
68
  rescue Mongo::ConnectionFailure
72
69
  puts "Could not connect to MongoDB"
73
70
  exit 1
74
71
  end
75
72
  end
76
73
  end
77
-
data/lib/ki.rb CHANGED
@@ -4,7 +4,7 @@ require 'haml'
4
4
  require 'sass'
5
5
  require 'coffee-script'
6
6
 
7
-
7
+ require 'conf'
8
8
  require 'db'
9
9
  require 'model'
10
10
  require 'helpers'
@@ -12,8 +12,12 @@ require 'util'
12
12
  require 'req'
13
13
  require 'resp'
14
14
  require 'static_file'
15
+ require 'mockreq'
15
16
 
16
- Ki::Db.instance.config_db
17
+ Dir['public/**/**'].each do |s|
18
+ Ki::StaticFile.compile_css(s)
19
+ Ki::StaticFile.compile_js(s)
20
+ end
17
21
 
18
22
  module Ki
19
23
  class Ki
@@ -22,8 +26,3 @@ module Ki
22
26
  end
23
27
  end
24
28
  end
25
-
26
- Dir['public/**/**'].each do |s|
27
- Ki::StaticFile.compile_css(s)
28
- Ki::StaticFile.compile_js(s)
29
- end
@@ -0,0 +1,45 @@
1
+ module Ki
2
+ class MockReq
3
+ attr_accessor :request_method
4
+ attr_accessor :params
5
+
6
+ def get?
7
+ request_method == 'GET'
8
+ end
9
+
10
+ def post?
11
+ request_method == 'POST'
12
+ end
13
+
14
+ def put?
15
+ request_method == 'PUT'
16
+ end
17
+
18
+ def delete?
19
+ request_method == 'DELETE'
20
+ end
21
+
22
+ def search?
23
+ request_method == 'SEARCH'
24
+ end
25
+ end
26
+
27
+ class ReqFactory
28
+ def self.new sym, params={}
29
+ case sym
30
+ when :get, :post, :put, :delete, :head, :search
31
+ mr = MockReq.new
32
+ mr.request_method = sym.to_s.upcase
33
+ mr.params = params
34
+ return mr
35
+ when :post_homer
36
+ mr = MockReq.new
37
+ mr.request_method = 'POST'
38
+ mr.params = { 'user' => 'homer' }
39
+ return mr
40
+ else
41
+ raise "not a valid factory"
42
+ end
43
+ end
44
+ end
45
+ end
@@ -46,7 +46,6 @@ module Ki
46
46
 
47
47
  def self.sass_to_css sass_path, css_path
48
48
  if File.exists? sass_path
49
- p "Compiling #{sass_path}"
50
49
  eng = Sass::Engine.new(File.read(sass_path), :syntax => :sass)
51
50
  File.open(css_path, 'w') do |f|
52
51
  f.puts eng.render
@@ -56,7 +55,6 @@ module Ki
56
55
 
57
56
  def self.coffee_to_js coffee_path, js_path
58
57
  if File.exists? coffee_path
59
- p "Compiling #{coffee_path}"
60
58
  cont = CoffeeScript.compile(File.read(coffee_path))
61
59
  File.open(js_path, 'w') do |f|
62
60
  f.puts cont
@@ -0,0 +1,6 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Ki::Conf do
4
+ it "should work" do
5
+ end
6
+ end
@@ -81,4 +81,13 @@ describe Ki::Db do
81
81
  r = @db.find_by 'zoidberg', hash
82
82
  r.length.should == 1
83
83
  end
84
+
85
+ it "should be able to change db name" do
86
+ new_db_name = 'test_ki_change_name'
87
+ @db.db.name.should == DB_NAME
88
+
89
+ @db.db_name new_db_name
90
+
91
+ @db.db.name.should == new_db_name
92
+ end
84
93
  end
@@ -46,67 +46,67 @@ describe 'Integration Tests' do
46
46
  end
47
47
 
48
48
  expect {
49
- User.new(ReqFactory.new(:post, { 'mail' => 'cool@beans.com'})).hash['id']
49
+ User.new(Ki::ReqFactory.new(:post, { 'mail' => 'cool@beans.com'})).hash['id']
50
50
  }.to raise_error 'password missing'
51
51
 
52
52
  expect {
53
- id = User.new(ReqFactory.new(:post, { 'mail' => 'cool@beans.com', 'password' => '123'})).hash['id']
54
- User.new(ReqFactory.new(:get, { 'id' => id })).hash[0]['password'].should == '123!'
53
+ id = User.new(Ki::ReqFactory.new(:post, { 'mail' => 'cool@beans.com', 'password' => '123'})).hash['id']
54
+ User.new(Ki::ReqFactory.new(:get, { 'id' => id })).hash[0]['password'].should == '123!'
55
55
  }.to change(User, :count).by(1)
56
56
 
57
57
  expect {
58
- id = User.new(ReqFactory.new(:post, { 'mail' => 'cool@beans.com', 'password' => '123'})).hash['id']
58
+ id = User.new(Ki::ReqFactory.new(:post, { 'mail' => 'cool@beans.com', 'password' => '123'})).hash['id']
59
59
  }.to raise_error 'mail not unique'
60
60
 
61
61
  expect {
62
- Storage.new(ReqFactory.new(:post, {}))
62
+ Storage.new(Ki::ReqFactory.new(:post, {}))
63
63
  }.to raise_error 'not authorized'
64
64
 
65
65
  expect {
66
- Storage.new(ReqFactory.new(:post, {'mail' => 'cool@beans.com'}))
66
+ Storage.new(Ki::ReqFactory.new(:post, {'mail' => 'cool@beans.com'}))
67
67
  }.to raise_error 'not authorized'
68
68
 
69
69
  # create storage
70
- storage = Storage.new(ReqFactory.new(:post, {'mail' => 'cool@beans.com', 'password' => '123', 'all_my_data' => [1,2,3]}))
70
+ storage = Storage.new(Ki::ReqFactory.new(:post, {'mail' => 'cool@beans.com', 'password' => '123', 'all_my_data' => [1,2,3]}))
71
71
  id = storage.hash['id']
72
- r = Storage.new(ReqFactory.new(:get, { 'mail' => 'cool@beans.com', 'password' => '123'}))
72
+ r = Storage.new(Ki::ReqFactory.new(:get, { 'mail' => 'cool@beans.com', 'password' => '123'}))
73
73
  r.hash[0]['all_my_data'].should == [1,2,3]
74
74
  r.hash[0]['password'].should == nil
75
75
 
76
76
  expect {
77
- Storage.new(ReqFactory.new(:delete, {}))
77
+ Storage.new(Ki::ReqFactory.new(:delete, {}))
78
78
  }.to raise_error 'not authorized'
79
79
 
80
80
  expect {
81
- Storage.new(ReqFactory.new(:delete, {'id' => id}))
81
+ Storage.new(Ki::ReqFactory.new(:delete, {'id' => id}))
82
82
  }.to raise_error 'not authorized'
83
83
 
84
84
  expect {
85
- Storage.new(ReqFactory.new(:delete, {'mail' => 'cool@beans.com', 'password' => '123'}))
85
+ Storage.new(Ki::ReqFactory.new(:delete, {'mail' => 'cool@beans.com', 'password' => '123'}))
86
86
  }.to raise_error 'param id missing'
87
87
 
88
88
  # delete from storage
89
89
  expect {
90
- Storage.new(ReqFactory.new(:delete, {'id' => id, 'mail' => 'cool@beans.com', 'password' => '123'}))
90
+ Storage.new(Ki::ReqFactory.new(:delete, {'id' => id, 'mail' => 'cool@beans.com', 'password' => '123'}))
91
91
  }.to change(Storage, :count).by(-1)
92
92
 
93
93
  # not allowed to delete user
94
94
  expect {
95
- id = User.new(ReqFactory.new(:post, { 'mail' => 'other@beans.com', 'password' => '123'})).hash['id']
96
- p User.new(ReqFactory.new(:delete, { 'id' => id }))
95
+ id = User.new(Ki::ReqFactory.new(:post, { 'mail' => 'other@beans.com', 'password' => '123'})).hash['id']
96
+ p User.new(Ki::ReqFactory.new(:delete, { 'id' => id }))
97
97
  }.to raise_error 'action forbidden'
98
98
 
99
- storage = Storage.new(ReqFactory.new(:post, {'mail' => 'cool@beans.com', 'password' => '123', 'all_my_data' => [4,4,5]}))
99
+ storage = Storage.new(Ki::ReqFactory.new(:post, {'mail' => 'cool@beans.com', 'password' => '123', 'all_my_data' => [4,4,5]}))
100
100
  id = storage.hash['id']
101
101
  expect {
102
- Storage.new(ReqFactory.new(:put, {'mail' => 'cool@beans.com', 'password' => '123', 'all_my_data' => [1]}))
102
+ Storage.new(Ki::ReqFactory.new(:put, {'mail' => 'cool@beans.com', 'password' => '123', 'all_my_data' => [1]}))
103
103
  }.to raise_error 'param id missing'
104
104
 
105
105
  expect {
106
- Storage.new(ReqFactory.new(:put, {'mail' => 'cool@beans.com', 'password' => '1234', 'all_my_data' => [1]}))
106
+ Storage.new(Ki::ReqFactory.new(:put, {'mail' => 'cool@beans.com', 'password' => '1234', 'all_my_data' => [1]}))
107
107
  }.to raise_error 'not authorized'
108
108
 
109
- storage = Storage.new(ReqFactory.new(:put, {'id' => id, 'mail' => 'cool@beans.com', 'password' => '123', 'all_my_data' => [1]}))
109
+ storage = Storage.new(Ki::ReqFactory.new(:put, {'id' => id, 'mail' => 'cool@beans.com', 'password' => '123', 'all_my_data' => [1]}))
110
110
  storage.hash['id'].should == id
111
111
  storage = Storage.find(id)
112
112
  storage['all_my_data'].should == [1]
@@ -13,7 +13,7 @@ describe Ki::Model do
13
13
  end
14
14
 
15
15
  it "should create a new item in the databse" do
16
- post = ReqFactory.new(:post_homer)
16
+ post = Ki::ReqFactory.new(:post_homer)
17
17
  @db.db['zoidberg'].count.should == 0
18
18
  hash = Zoidberg.new(post).hash
19
19
  @db.db['zoidberg'].count.should == 1
@@ -23,7 +23,7 @@ describe Ki::Model do
23
23
  it "should get a model depending on id" do
24
24
  id = @db.create 'zoidberg', { :name => 'homer' }
25
25
 
26
- get = ReqFactory.new(:get, {'id' => id})
26
+ get = Ki::ReqFactory.new(:get, {'id' => id})
27
27
  Zoidberg.new(get).hash[0]['name'].should == 'homer'
28
28
  end
29
29
 
@@ -34,23 +34,23 @@ describe Ki::Model do
34
34
  @db.create 'zoidberg', { :name => 'joker', :valid => false, :cool => true }
35
35
  @db.create 'zoidberg', { :name => 'joker', :valid => false, :cool => false }
36
36
 
37
- r = Zoidberg.new(ReqFactory.new(:get, { :name => 'homer' })).hash
37
+ r = Zoidberg.new(Ki::ReqFactory.new(:get, { :name => 'homer' })).hash
38
38
  r[0]['name'].should == 'homer'
39
39
 
40
- r = Zoidberg.new(ReqFactory.new(:get, { :valid => true })).hash
40
+ r = Zoidberg.new(Ki::ReqFactory.new(:get, { :valid => true })).hash
41
41
  r.length.should == 2
42
42
 
43
43
  r.collect { |z|
44
44
  z['valid'].should be_true
45
45
  }
46
46
 
47
- r = Zoidberg.new(ReqFactory.new(:get, { :valid => false, :cool => true })).hash
47
+ r = Zoidberg.new(Ki::ReqFactory.new(:get, { :valid => false, :cool => true })).hash
48
48
  r.length.should == 2
49
49
  end
50
50
 
51
51
  it "should only accept valid object ids" do
52
52
  expect {
53
- Zoidberg.new(ReqFactory.new(:get_with_params, { :id => 'homer' }))
53
+ Zoidberg.new(Ki::ReqFactory.new(:get_with_params, { :id => 'homer' }))
54
54
  }.to raise_error
55
55
  end
56
56
 
@@ -58,34 +58,34 @@ describe Ki::Model do
58
58
  id = @db.create 'zoidberg', { :name => 'homer' }
59
59
  @db.find('zoidberg', id)['name'].should == 'homer'
60
60
 
61
- Zoidberg.new(ReqFactory.new(:put, {'id' => id, :name => 'bart'}))
61
+ Zoidberg.new(Ki::ReqFactory.new(:put, {'id' => id, :name => 'bart'}))
62
62
  @db.find('zoidberg', id)['name'].should == 'bart'
63
63
  end
64
64
 
65
65
  it "should raise error if id is missing when updating" do
66
66
  expect {
67
- Zoidberg.new(ReqFactory.new(:put, {:name => 'bart'}))
67
+ Zoidberg.new(Ki::ReqFactory.new(:put, {:name => 'bart'}))
68
68
  }.to raise_error
69
69
  end
70
70
 
71
71
  it "should raise error if id is invalid" do
72
72
  expect {
73
- Zoidberg.new(ReqFactory.new(:put, {'id' => 'f*ck', :name => 'bart'}))
73
+ Zoidberg.new(Ki::ReqFactory.new(:put, {'id' => 'f*ck', :name => 'bart'}))
74
74
  }.to raise_error
75
75
  end
76
76
 
77
77
  it "should delete a document" do
78
78
  expect {
79
- Zoidberg.new(ReqFactory.new(:delete))
79
+ Zoidberg.new(Ki::ReqFactory.new(:delete))
80
80
  }.to raise_error
81
81
 
82
82
  expect {
83
- Zoidberg.new(ReqFactory.new(:delete, {'id' => 'f*ck', :name => 'bart'}))
83
+ Zoidberg.new(Ki::ReqFactory.new(:delete, {'id' => 'f*ck', :name => 'bart'}))
84
84
  }.to raise_error
85
85
 
86
86
  id = @db.create 'zoidberg', { :name => 'homer' }
87
87
  expect {
88
- Zoidberg.new(ReqFactory.new(:delete, {'id' => id}))
88
+ Zoidberg.new(Ki::ReqFactory.new(:delete, {'id' => id}))
89
89
  }.to change(@db.db['zoidberg'], :count).by(-1)
90
90
  end
91
91
  end
@@ -8,8 +8,8 @@ describe Ki::Callbacks do
8
8
  end
9
9
  end
10
10
 
11
- id = Foo.new(ReqFactory.new(:post, {:foo => 'bar'})).hash['id']
12
- Foo.new(ReqFactory.new(:get, { 'id' => id })).hash[0]['meaning_of_life'].should == 42
11
+ id = Foo.new(Ki::ReqFactory.new(:post, {:foo => 'bar'})).hash['id']
12
+ Foo.new(Ki::ReqFactory.new(:get, { 'id' => id })).hash[0]['meaning_of_life'].should == 42
13
13
  end
14
14
 
15
15
  it "should handle before and after all" do
@@ -19,7 +19,7 @@ describe Ki::Callbacks do
19
19
  end
20
20
  end
21
21
 
22
- id = Foo.new(ReqFactory.new(:post, {:foo => 'bar'})).hash['id']
23
- Foo.new(ReqFactory.new(:get, { 'id' => id })).hash[0]['cool'].should be_true
22
+ id = Foo.new(Ki::ReqFactory.new(:post, {:foo => 'bar'})).hash['id']
23
+ Foo.new(Ki::ReqFactory.new(:get, { 'id' => id })).hash[0]['cool'].should be_true
24
24
  end
25
25
  end
@@ -10,7 +10,7 @@ describe Ki::Restrictions do
10
10
  class Foo < Ki::Model
11
11
  end
12
12
  expect {
13
- Foo.new(ReqFactory.new(:head))
13
+ Foo.new(Ki::ReqFactory.new(:head))
14
14
  }.to raise_error
15
15
  end
16
16
 
@@ -18,7 +18,7 @@ describe Ki::Restrictions do
18
18
  class Foo < Ki::Model
19
19
  end
20
20
  Foo.forbidden_actions.empty?.should be_true
21
- Foo.new(ReqFactory.new(:post_homer))
21
+ Foo.new(Ki::ReqFactory.new(:post_homer))
22
22
  end
23
23
 
24
24
  it "should restrict search when find is forbidden" do
@@ -26,7 +26,7 @@ describe Ki::Restrictions do
26
26
  forbid :find
27
27
  end
28
28
  expect {
29
- Foo.new(ReqFactory.new(:search, {'foo' => 'bar'} ))
29
+ Foo.new(Ki::ReqFactory.new(:search, {'foo' => 'bar'} ))
30
30
  }.to raise_exception
31
31
  end
32
32
 
@@ -35,9 +35,9 @@ describe Ki::Restrictions do
35
35
  forbid :delete
36
36
  end
37
37
  Foo.forbidden_actions.include?(:delete).should be_true
38
- id = Foo.new(ReqFactory.new(:post_homer)).hash['id']
38
+ id = Foo.new(Ki::ReqFactory.new(:post_homer)).hash['id']
39
39
  expect {
40
- Foo.new(ReqFactory.new(:delete, { 'id' => id } ))
40
+ Foo.new(Ki::ReqFactory.new(:delete, { 'id' => id } ))
41
41
  }.to raise_exception
42
42
  end
43
43
 
@@ -68,11 +68,11 @@ describe Ki::Restrictions do
68
68
  Foo.required_attributes.include?(:name).should be_true
69
69
 
70
70
  expect {
71
- Foo.new(ReqFactory.new(:post_homer))
71
+ Foo.new(Ki::ReqFactory.new(:post_homer))
72
72
  }.to raise_exception
73
73
 
74
74
  expect {
75
- Foo.new(ReqFactory.new(:post, {'name' => 'bart' }))
75
+ Foo.new(Ki::ReqFactory.new(:post, {'name' => 'bart' }))
76
76
  }.to change(Ki::Db.instance.db['foo'], :count).by(1)
77
77
  end
78
78
 
@@ -87,11 +87,11 @@ describe Ki::Restrictions do
87
87
  Bar.unique_attributes.should == [:foo]
88
88
 
89
89
  expect {
90
- Bar.new(ReqFactory.new(:post, { 'foo' => 'bar'}))
90
+ Bar.new(Ki::ReqFactory.new(:post, { 'foo' => 'bar'}))
91
91
  }.to change(Bar, :count).by(1)
92
92
 
93
93
  expect {
94
- Bar.new(ReqFactory.new(:post, { 'foo' => 'bar'}))
94
+ Bar.new(Ki::ReqFactory.new(:post, { 'foo' => 'bar'}))
95
95
  }.to raise_error 'foo not unique'
96
96
  end
97
97
 
@@ -9,21 +9,21 @@ describe Ki::Req do
9
9
  end
10
10
 
11
11
  it "should handle SEARCH verb" do
12
- post = ReqFactory.new(:post, { :title => 'Foundation' })
12
+ post = Ki::ReqFactory.new(:post, { :title => 'Foundation' })
13
13
  hash = Book.new(post).hash
14
14
 
15
- search = ReqFactory.new(:search, { :title => 'Foundation' })
15
+ search = Ki::ReqFactory.new(:search, { :title => 'Foundation' })
16
16
  hash = Book.new(search).hash
17
17
  hash[0]['title'].should == 'Foundation'
18
18
  end
19
19
 
20
20
  it "should format the id properly" do
21
- post = ReqFactory.new(:post, { :title => 'Foundation' })
21
+ post = Ki::ReqFactory.new(:post, { :title => 'Foundation' })
22
22
  id = Book.new(post).hash['id']
23
23
 
24
- get = ReqFactory.new(:get, { :title => 'Foundation' })
24
+ get = Ki::ReqFactory.new(:get, { :title => 'Foundation' })
25
25
  Book.new(get).hash[0]['id'].should == id
26
26
 
27
- update = ReqFactory.new(:put, { 'id' => id, :title => 'Foundation' })
27
+ update = Ki::ReqFactory.new(:put, { 'id' => id, :title => 'Foundation' })
28
28
  end
29
29
  end
@@ -3,59 +3,9 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
3
  require 'rspec'
4
4
  require 'ki'
5
5
 
6
- # Requires supporting files with custom matchers and macros, etc,
7
- # in ./support/ and its subdirectories.
8
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
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
-
20
- def get?
21
- request_method == 'GET'
22
- end
23
-
24
- def post?
25
- request_method == 'POST'
26
- end
27
-
28
- def put?
29
- request_method == 'PUT'
30
- end
31
-
32
- def delete?
33
- request_method == 'DELETE'
34
- end
35
-
36
- def search?
37
- request_method == 'SEARCH'
38
- end
39
- end
40
-
41
- class ReqFactory
42
- def self.new sym, params={}
43
- case sym
44
- when :get, :post, :put, :delete, :head, :search
45
- mr = MockReq.new
46
- mr.request_method = sym.to_s.upcase
47
- mr.params = params
48
- return mr
49
- when :post_homer
50
- mr = MockReq.new
51
- mr.request_method = 'POST'
52
- mr.params = { 'user' => 'homer' }
53
- return mr
54
- else
55
- raise "not a valid factory"
56
- end
57
- end
58
- end
6
+ DB_NAME = 'ki_test_db'
7
+ Ki::Conf.instance.yaml['database_name'] = DB_NAME
8
+ Ki::Db.instance.config
59
9
 
60
10
  RSpec.configure do |config|
61
11
  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.3.1
4
+ version: 0.3.2
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: 2013-03-31 00:00:00.000000000 Z
12
+ date: 2013-06-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
@@ -298,11 +298,13 @@ files:
298
298
  - gfx/logo.png
299
299
  - ki.gemspec
300
300
  - ki_wrap.rb
301
+ - lib/conf.rb
301
302
  - lib/db.rb
302
303
  - lib/extensions/mail.rb
303
304
  - lib/helpers.rb
304
305
  - lib/ki.rb
305
306
  - lib/ki_cli.rb
307
+ - lib/mockreq.rb
306
308
  - lib/model.rb
307
309
  - lib/modules/callbacks.rb
308
310
  - lib/modules/model_helpers.rb
@@ -316,6 +318,7 @@ files:
316
318
  - lib/views/406.haml
317
319
  - lib/views/index.haml
318
320
  - lib/views/layout.haml
321
+ - spec/conf_spec.rb
319
322
  - spec/db_spec.rb
320
323
  - spec/extensions/mail_spec.rb
321
324
  - spec/integration/integration_spec.rb
@@ -343,7 +346,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
343
346
  version: '0'
344
347
  segments:
345
348
  - 0
346
- hash: -1443684808405340499
349
+ hash: -4593100471811426201
347
350
  required_rubygems_version: !ruby/object:Gem::Requirement
348
351
  none: false
349
352
  requirements: