sinatra-dm 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +169 -3
- data/Rakefile +18 -0
- data/VERSION +1 -1
- data/lib/sinatra/dm.rb +214 -71
- data/sinatra-dm.gemspec +15 -9
- data/spec/dm_bootstrap.rb +14 -0
- data/spec/sinatra/dm_mysql_spec.rb +148 -0
- data/spec/sinatra/dm_sqlite3_spec.rb +308 -0
- data/spec/spec_helper.rb +16 -40
- metadata +19 -7
- data/lib/sinatra/dm/rake.rb +0 -128
- data/spec/dm_model.rb +0 -14
- data/spec/sinatra/dm_spec.rb +0 -84
data/sinatra-dm.gemspec
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{sinatra-dm}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["kematzy"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2010-02-22}
|
13
13
|
s.description = %q{Sinatra Extension for working with DataMapper (another Sinatra-Sequel Rip-off)}
|
14
14
|
s.email = %q{kematzy@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -24,12 +24,13 @@ Gem::Specification.new do |s|
|
|
24
24
|
"Rakefile",
|
25
25
|
"VERSION",
|
26
26
|
"lib/sinatra/dm.rb",
|
27
|
-
"lib/sinatra/dm/rake.rb",
|
28
27
|
"sinatra-dm.gemspec",
|
29
|
-
"spec/
|
28
|
+
"spec/dm_bootstrap.rb",
|
30
29
|
"spec/fixtures/db/.gitignore",
|
30
|
+
"spec/fixtures/db/custom/.gitignore",
|
31
31
|
"spec/fixtures/log/.gitignore",
|
32
|
-
"spec/sinatra/
|
32
|
+
"spec/sinatra/dm_mysql_spec.rb",
|
33
|
+
"spec/sinatra/dm_sqlite3_spec.rb",
|
33
34
|
"spec/spec_helper.rb"
|
34
35
|
]
|
35
36
|
s.homepage = %q{http://github.com/kematzy/sinatra-dm}
|
@@ -38,8 +39,9 @@ Gem::Specification.new do |s|
|
|
38
39
|
s.rubygems_version = %q{1.3.5}
|
39
40
|
s.summary = %q{Sinatra Extension for working with DataMapper}
|
40
41
|
s.test_files = [
|
41
|
-
"spec/
|
42
|
-
"spec/sinatra/
|
42
|
+
"spec/dm_bootstrap.rb",
|
43
|
+
"spec/sinatra/dm_mysql_spec.rb",
|
44
|
+
"spec/sinatra/dm_sqlite3_spec.rb",
|
43
45
|
"spec/spec_helper.rb"
|
44
46
|
]
|
45
47
|
|
@@ -50,15 +52,19 @@ Gem::Specification.new do |s|
|
|
50
52
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
51
53
|
s.add_runtime_dependency(%q<sinatra>, [">= 0.10.1"])
|
52
54
|
s.add_runtime_dependency(%q<dm-core>, [">= 0.10.1"])
|
55
|
+
s.add_runtime_dependency(%q<kematzy-tasks>, [">= 0.1.0"])
|
53
56
|
s.add_development_dependency(%q<sinatra-tests>, [">= 0.1.5"])
|
54
57
|
else
|
55
58
|
s.add_dependency(%q<sinatra>, [">= 0.10.1"])
|
56
59
|
s.add_dependency(%q<dm-core>, [">= 0.10.1"])
|
60
|
+
s.add_dependency(%q<kematzy-tasks>, [">= 0.1.0"])
|
57
61
|
s.add_dependency(%q<sinatra-tests>, [">= 0.1.5"])
|
58
62
|
end
|
59
63
|
else
|
60
64
|
s.add_dependency(%q<sinatra>, [">= 0.10.1"])
|
61
65
|
s.add_dependency(%q<dm-core>, [">= 0.10.1"])
|
66
|
+
s.add_dependency(%q<kematzy-tasks>, [">= 0.1.0"])
|
62
67
|
s.add_dependency(%q<sinatra-tests>, [">= 0.1.5"])
|
63
68
|
end
|
64
69
|
end
|
70
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class ::Post
|
2
|
+
include DataMapper::Resource
|
3
|
+
property :id, Serial
|
4
|
+
property :name, String
|
5
|
+
end
|
6
|
+
|
7
|
+
def dm_bootstrap(identifier='')
|
8
|
+
|
9
|
+
DataMapper.auto_migrate!
|
10
|
+
|
11
|
+
Post.create!(:name => "#{identifier}Post1" )
|
12
|
+
Post.create!(:name => "#{identifier}Post2" )
|
13
|
+
Post.create!(:name => "#{identifier}Post3" )
|
14
|
+
end
|
@@ -0,0 +1,148 @@
|
|
1
|
+
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '../../spec_helper')
|
3
|
+
|
4
|
+
describe "Sinatra" do
|
5
|
+
|
6
|
+
describe "DM" do
|
7
|
+
|
8
|
+
describe "when using a MySQL db" do
|
9
|
+
|
10
|
+
class MySQLTestApp < Sinatra::Base
|
11
|
+
register(Sinatra::DataMapperExtension)
|
12
|
+
|
13
|
+
# NOTE:: :dm_logger_level & :dm_logger_path must be set before :database
|
14
|
+
# in order to use custom settings
|
15
|
+
set :dm_logger_level, :debug
|
16
|
+
set :dm_logger_path, "#{fixtures_path}/log/dm.mysql_test_app.log"
|
17
|
+
|
18
|
+
# NB!! sets the connection to an existing db [sinatra_dm_tests]
|
19
|
+
# in a standard install MySQL db (ie: unsecured) without a password
|
20
|
+
set :database, 'mysql://root:@localhost/sinatra_dm_tests'
|
21
|
+
|
22
|
+
## ROUTES TEST (IF DATA COMES THROUGH)
|
23
|
+
get '/db-mysql' do
|
24
|
+
Post.all.map(&:name).join(', ') # Post1, Post2,...
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
before(:each) do
|
30
|
+
class ::Test::Unit::TestCase
|
31
|
+
def app; ::MySQLTestApp.new ; end
|
32
|
+
end
|
33
|
+
@app = app
|
34
|
+
|
35
|
+
dm_bootstrap('MySQL-Test') ## INIT THE TABLES AND LOAD THE DATA
|
36
|
+
end
|
37
|
+
|
38
|
+
after(:each) do
|
39
|
+
class ::Test::Unit::TestCase
|
40
|
+
def app; nil ; end
|
41
|
+
end
|
42
|
+
@app = nil
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "Configurations" do
|
46
|
+
|
47
|
+
it "should set :db_dir to [../db] (NB! unused value when using MySQL)" do
|
48
|
+
MySQLTestApp.db_dir.should == "#{fixtures_path}/db"
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should set :dm_logger_level to :debug" do
|
52
|
+
MySQLTestApp.dm_logger_level.should == :debug
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should set :dm_logger_path to [../log/dm.mysql_test_app.log]" do
|
56
|
+
MySQLTestApp.dm_logger_path.should == "#{fixtures_path}/log/dm.mysql_test_app.log"
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should set :dm_setup_context to :default" do
|
60
|
+
MySQLTestApp.dm_setup_context.should == :default
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should set :dm_database_url to [mysql://]" do
|
64
|
+
MySQLTestApp.dm_database_url.should == "mysql://root:@localhost/sinatra_dm_tests"
|
65
|
+
end
|
66
|
+
|
67
|
+
end #/ Configurations
|
68
|
+
|
69
|
+
|
70
|
+
describe "Helper method " do
|
71
|
+
|
72
|
+
describe "#database" do
|
73
|
+
|
74
|
+
it "should return an MySQL Adapter" do
|
75
|
+
app.database.should be_a_kind_of(DataMapper::Adapters::MysqlAdapter)
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "and the MySQL Adapter " do
|
79
|
+
|
80
|
+
it "should be configured with the correct DB host [localhost]" do
|
81
|
+
app.database.options['host'].should == "localhost"
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should be configured with the correct DB path [/sinatra_dm_tests]" do
|
85
|
+
app.database.options['path'].should == "/sinatra_dm_tests"
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should be configured with the correct DB user [root]" do
|
89
|
+
app.database.options['user'].should == "root"
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should be configured with the correct DB password [ (empty)]" do
|
93
|
+
app.database.options['password'].should == ""
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should be configured with the correct setup [:default]" do
|
97
|
+
app.database.name.should == :default
|
98
|
+
end
|
99
|
+
|
100
|
+
end #/ and the MySQL Adapter
|
101
|
+
|
102
|
+
|
103
|
+
end #/ #database
|
104
|
+
|
105
|
+
describe "#db_logger" do
|
106
|
+
|
107
|
+
it "should be a DataMapper::Logger Object" do
|
108
|
+
app.db_logger.should be_a_kind_of(DataMapper::Logger)
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should have the correct log path [../log/dm.mysql_test_app.log]" do
|
112
|
+
app.db_logger.init_args[0].should == "#{fixtures_path}/log/dm.mysql_test_app.log"
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should have the correct log level [:debug]" do
|
116
|
+
app.db_logger.init_args[1].should == :debug
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should write log messages to the log file" do
|
120
|
+
custom_message = "__INFO_MYSQL_MESSAGE__ written at [#{Time.now.strftime("%Y-%m-%d %H:%M:%S")}]"
|
121
|
+
app.db_logger.info(custom_message)
|
122
|
+
IO.read(app.db_logger.init_args[0]).should match(/#{Regexp.escape(custom_message)}/)
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should write debug log messages to the log file" do
|
126
|
+
custom_message = "__DEBUG_MYSQL_MESSAGE__ written at [#{Time.now.strftime("%Y-%m-%d %H:%M:%S")}]"
|
127
|
+
app.db_logger.debug(custom_message)
|
128
|
+
IO.read(app.db_logger.init_args[0]).should match(/#{Regexp.escape(custom_message)}/)
|
129
|
+
end
|
130
|
+
|
131
|
+
end #/ #db_logger
|
132
|
+
|
133
|
+
end #/ Helper method
|
134
|
+
|
135
|
+
|
136
|
+
describe "DB Queries" do
|
137
|
+
|
138
|
+
it "should return the data from the database" do
|
139
|
+
get("/db-mysql")
|
140
|
+
body.should == "MySQL-TestPost1, MySQL-TestPost2, MySQL-TestPost3"
|
141
|
+
end
|
142
|
+
|
143
|
+
end #/ DB Queries
|
144
|
+
|
145
|
+
|
146
|
+
end #/ when using a MySQL
|
147
|
+
end #/ DM
|
148
|
+
end #/ Sinatra
|
@@ -0,0 +1,308 @@
|
|
1
|
+
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '../../spec_helper')
|
3
|
+
|
4
|
+
describe "Sinatra" do
|
5
|
+
|
6
|
+
describe "DM" do
|
7
|
+
|
8
|
+
describe "when using a SQLite3 db" do
|
9
|
+
|
10
|
+
describe "and using Default Settings" do
|
11
|
+
|
12
|
+
class MyTestApp < Sinatra::Base
|
13
|
+
register(Sinatra::DataMapperExtension)
|
14
|
+
|
15
|
+
# NOTE:: need to set this for the logger to function
|
16
|
+
set :environment, ENV['RACK_ENV'].to_sym || :test
|
17
|
+
|
18
|
+
# NOTE:: The database configuration must be set
|
19
|
+
# in order for the DataMapper.auto_migrate! /auto_upgrade! migrations work
|
20
|
+
set :database, dm_database_url
|
21
|
+
|
22
|
+
## ROUTES TEST (IF DATA COMES THROUGH)
|
23
|
+
get '/db-default' do
|
24
|
+
Post.all.map(&:name).join(', ') # Post1, Post2,...
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
before(:each) do
|
30
|
+
class ::Test::Unit::TestCase
|
31
|
+
def app; ::MyTestApp.new ; end
|
32
|
+
end
|
33
|
+
@app = app
|
34
|
+
|
35
|
+
dm_bootstrap('SQLite3-Default') ## INIT THE TABLES AND LOAD THE DATA
|
36
|
+
end
|
37
|
+
|
38
|
+
after(:each) do
|
39
|
+
class ::Test::Unit::TestCase
|
40
|
+
def app; nil ; end
|
41
|
+
end
|
42
|
+
@app = nil
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "Configuration" do
|
46
|
+
|
47
|
+
it "should set :db_dir to ../db" do
|
48
|
+
MyTestApp.db_dir.should == "#{fixtures_path}/db"
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should set :dm_logger_level to :debug" do
|
52
|
+
MyTestApp.dm_logger_level.should == :debug
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should set :dm_logger_path to [../log/dm.< environment >.log]" do
|
56
|
+
MyTestApp.dm_logger_path.should == "#{fixtures_path}/log/dm.test.log"
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should set :dm_setup_context to :default" do
|
60
|
+
MyTestApp.dm_setup_context.should == :default
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should set :dm_database_url to [../db/db.< environment >.db]" do
|
64
|
+
MyTestApp.dm_database_url.should == "sqlite3://#{fixtures_path}/db/db.test.db"
|
65
|
+
end
|
66
|
+
|
67
|
+
end #/ Configuration
|
68
|
+
|
69
|
+
describe "Helpers" do
|
70
|
+
|
71
|
+
describe "#database" do
|
72
|
+
|
73
|
+
it "should return an SQLite3 Adapter" do
|
74
|
+
app.database.should be_a_kind_of(DataMapper::Adapters::Sqlite3Adapter)
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should be configured with the correct DB path [../db/db.< environment >.db]" do
|
78
|
+
app.database.options['path'].should == "#{fixtures_path}/db/db.test.db"
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should be configured with the correct setup [:default]" do
|
82
|
+
app.database.name.should == :default
|
83
|
+
end
|
84
|
+
|
85
|
+
end #/ #database
|
86
|
+
|
87
|
+
describe "#db_logger" do
|
88
|
+
|
89
|
+
it "should be a DataMapper::Logger Object" do
|
90
|
+
app.db_logger.should be_a_kind_of(DataMapper::Logger)
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should have the correct log path [../log/dm.< environment >.log]" do
|
94
|
+
app.db_logger.init_args[0].should == "#{fixtures_path}/log/dm.test.log"
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should have the correct log level [:debug]" do
|
98
|
+
app.db_logger.init_args[1].should == :debug
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should write log messages to the log file" do
|
102
|
+
custom_message = "__DEBUG_DEFAULT_MESSAGE__ written at [#{Time.now.strftime("%Y-%m-%d %H:%M:%S")}]"
|
103
|
+
app.db_logger.debug(custom_message)
|
104
|
+
IO.read(app.db_logger.init_args[0]).should match(/#{Regexp.escape(custom_message)}/)
|
105
|
+
end
|
106
|
+
|
107
|
+
end #/ #db_logger
|
108
|
+
|
109
|
+
end #/ Helpers
|
110
|
+
|
111
|
+
|
112
|
+
describe "Class Methods" do
|
113
|
+
|
114
|
+
describe "#database_logger" do
|
115
|
+
|
116
|
+
it "should be a DataMapper::Logger Object" do
|
117
|
+
MyTestApp.database_logger.should be_a_kind_of(DataMapper::Logger)
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should have the correct log path [../log/dm.< environment >.log]" do
|
121
|
+
MyTestApp.database_logger.init_args[0].should == "#{fixtures_path}/log/dm.test.log"
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should write log messages to the log file" do
|
125
|
+
custom_message = "__DEBUG_CLASS_METHOD_DEFAULT_MESSAGE__ written at [#{Time.now.strftime("%Y-%m-%d %H:%M:%S")}]"
|
126
|
+
MyTestApp.database_logger.debug(custom_message)
|
127
|
+
IO.read(MyTestApp.database_logger.init_args[0]).should match(/#{Regexp.escape(custom_message)}/)
|
128
|
+
end
|
129
|
+
|
130
|
+
end #/ #database_logger
|
131
|
+
|
132
|
+
describe "#database" do
|
133
|
+
|
134
|
+
it "should return an SQLite3 Adapter" do
|
135
|
+
MyTestApp.database.should be_a_kind_of(DataMapper::Adapters::Sqlite3Adapter)
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should be configured with the correct DB path [../db/db.< environment >.db]" do
|
139
|
+
MyTestApp.database.options['path'].should == "#{fixtures_path}/db/db.test.db"
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should be configured with the correct setup [:default]" do
|
143
|
+
MyTestApp.database.name.should == :default
|
144
|
+
end
|
145
|
+
|
146
|
+
end #/ #database
|
147
|
+
|
148
|
+
describe "#database=" do
|
149
|
+
|
150
|
+
it "should allow changing the DB settings" do
|
151
|
+
lambda {
|
152
|
+
MyTestApp.database = "sqlite3://#{fixtures_path}/db/db.class_method.db", :class_method
|
153
|
+
}.should_not raise_error(Exception)
|
154
|
+
MyTestApp.database.options['path'].should == "#{fixtures_path}/db/db.class_method.db"
|
155
|
+
MyTestApp.database.name.should == :class_method
|
156
|
+
end
|
157
|
+
|
158
|
+
it "should throw ArgumentError when using the wrong syntax ..App.database(vars, vars)" do
|
159
|
+
lambda {
|
160
|
+
MyTestApp.database("sqlite3://#{fixtures_path}/db/db.class_method.db", :class_method)
|
161
|
+
}.should raise_error(ArgumentError)
|
162
|
+
end
|
163
|
+
|
164
|
+
end #/ #database=
|
165
|
+
|
166
|
+
end #/ Class Methods
|
167
|
+
|
168
|
+
|
169
|
+
describe "DB Queries" do
|
170
|
+
|
171
|
+
it "should return the data from the database" do
|
172
|
+
get("/db-default")
|
173
|
+
body.should == "SQLite3-DefaultPost1, SQLite3-DefaultPost2, SQLite3-DefaultPost3"
|
174
|
+
end
|
175
|
+
|
176
|
+
end #/ DB Queries
|
177
|
+
|
178
|
+
end #/ and using Default Settings
|
179
|
+
|
180
|
+
|
181
|
+
describe "and using Custom Settings" do
|
182
|
+
|
183
|
+
class MyCustomTestApp < Sinatra::Base
|
184
|
+
register(Sinatra::DataMapperExtension)
|
185
|
+
|
186
|
+
# NOTE:: :dm_logger_level & :dm_logger_path must be set before :database
|
187
|
+
# in order to use custom settings
|
188
|
+
set :db_dir, "#{fixtures_path}/db/custom"
|
189
|
+
set :dm_logger_level, :info
|
190
|
+
set :dm_logger_path, "#{fixtures_path}/log/dm.my_custom_test_app.log"
|
191
|
+
set :dm_setup_context, :custom
|
192
|
+
set :dm_database_url, lambda { "sqlite3://#{db_dir}/db.my_custom_test_app.db" }
|
193
|
+
|
194
|
+
# NOTE:: The database configuration must be set
|
195
|
+
# in order for the DataMapper.auto_migrate! /auto_upgrade! migrations work
|
196
|
+
set :database, dm_database_url
|
197
|
+
|
198
|
+
## ROUTES TEST (IF DATA COMES THROUGH)
|
199
|
+
get '/db-custom' do
|
200
|
+
Post.all.map(&:name).join(', ') # Post1, Post2,...
|
201
|
+
end
|
202
|
+
|
203
|
+
end
|
204
|
+
|
205
|
+
before(:each) do
|
206
|
+
class ::Test::Unit::TestCase
|
207
|
+
def app; ::MyCustomTestApp.new ; end
|
208
|
+
end
|
209
|
+
@app = app
|
210
|
+
|
211
|
+
dm_bootstrap('SQLite3-Custom') ## INIT THE TABLES AND LOAD THE DATA
|
212
|
+
end
|
213
|
+
|
214
|
+
after(:each) do
|
215
|
+
class ::Test::Unit::TestCase
|
216
|
+
def app; nil ; end
|
217
|
+
end
|
218
|
+
@app = nil
|
219
|
+
end
|
220
|
+
|
221
|
+
describe "Configurations" do
|
222
|
+
|
223
|
+
it "should set :db_dir to ../db/custom" do
|
224
|
+
MyCustomTestApp.db_dir.should == "#{fixtures_path}/db/custom"
|
225
|
+
end
|
226
|
+
|
227
|
+
it "should set :dm_logger_level to :info" do
|
228
|
+
MyCustomTestApp.dm_logger_level.should == :info
|
229
|
+
end
|
230
|
+
|
231
|
+
it "should set :dm_logger_path to [../log/dm.my_custom_test_app.log]" do
|
232
|
+
MyCustomTestApp.dm_logger_path.should == "#{fixtures_path}/log/dm.my_custom_test_app.log"
|
233
|
+
end
|
234
|
+
|
235
|
+
it "should set :dm_setup_context to :custom" do
|
236
|
+
MyCustomTestApp.dm_setup_context.should == :custom
|
237
|
+
end
|
238
|
+
|
239
|
+
it "should set :dm_database_url to [../db/db.my_custom_test_app.db]" do
|
240
|
+
MyCustomTestApp.dm_database_url.should == "sqlite3://#{fixtures_path}/db/custom/db.my_custom_test_app.db"
|
241
|
+
end
|
242
|
+
|
243
|
+
end #/ Configurations
|
244
|
+
|
245
|
+
|
246
|
+
describe "Helper method " do
|
247
|
+
|
248
|
+
describe "#database" do
|
249
|
+
|
250
|
+
it "should return an SQLite3 Adapter" do
|
251
|
+
app.database.should be_a_kind_of(DataMapper::Adapters::Sqlite3Adapter)
|
252
|
+
end
|
253
|
+
|
254
|
+
it "should be configured with the correct DB path [../db/db.my_custom_test_app.db]" do
|
255
|
+
app.database.options['path'].should == "#{fixtures_path}/db/custom/db.my_custom_test_app.db"
|
256
|
+
end
|
257
|
+
|
258
|
+
it "should be configured with the correct setup [:custom]" do
|
259
|
+
app.database.name.should == :custom
|
260
|
+
end
|
261
|
+
|
262
|
+
end #/ #database
|
263
|
+
|
264
|
+
describe "#db_logger" do
|
265
|
+
|
266
|
+
it "should be a DataMapper::Logger Object" do
|
267
|
+
app.db_logger.should be_a_kind_of(DataMapper::Logger)
|
268
|
+
end
|
269
|
+
|
270
|
+
it "should have the correct log path [../log/dm.my_custom_test_app.log]" do
|
271
|
+
app.db_logger.init_args[0].should == "#{fixtures_path}/log/dm.my_custom_test_app.log"
|
272
|
+
end
|
273
|
+
|
274
|
+
it "should have the correct log level [:info]" do
|
275
|
+
app.db_logger.init_args[1].should == :info
|
276
|
+
end
|
277
|
+
|
278
|
+
it "should write log messages to the log file" do
|
279
|
+
custom_message = "__INFO_CUSTOM_MESSAGE__ written at [#{Time.now.strftime("%Y-%m-%d %H:%M:%S")}]"
|
280
|
+
app.db_logger.info(custom_message)
|
281
|
+
IO.read(app.db_logger.init_args[0]).should match(/#{Regexp.escape(custom_message)}/)
|
282
|
+
end
|
283
|
+
|
284
|
+
it "should NOT write debug log messages to the log file" do
|
285
|
+
custom_message = "__DEBUG_CUSTOM_MESSAGE__ written at [#{Time.now.strftime("%Y-%m-%d %H:%M:%S")}]"
|
286
|
+
app.db_logger.debug(custom_message)
|
287
|
+
IO.read(app.db_logger.init_args[0]).should_not match(/#{Regexp.escape(custom_message)}/)
|
288
|
+
end
|
289
|
+
|
290
|
+
end #/ #db_logger
|
291
|
+
|
292
|
+
end #/ Helper method
|
293
|
+
|
294
|
+
|
295
|
+
describe "DB Queries" do
|
296
|
+
|
297
|
+
it "should return the data from the database" do
|
298
|
+
get("/db-custom")
|
299
|
+
body.should == "SQLite3-CustomPost1, SQLite3-CustomPost2, SQLite3-CustomPost3"
|
300
|
+
end
|
301
|
+
|
302
|
+
end #/ DB Queries
|
303
|
+
|
304
|
+
end #/ and using Custom Settings
|
305
|
+
|
306
|
+
end #/ when using a SQLite3 db
|
307
|
+
end #/ DM
|
308
|
+
end #/ Sinatra
|