dohruby 0.1.37 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +9 -0
- data/bin/run_tests.rb +44 -10
- data/lib/doh/app/activate_database.rb +1 -0
- data/lib/doh/app/config.rb +0 -1
- data/lib/doh/app/home.rb +0 -1
- data/lib/doh/app/init.rb +3 -1
- data/lib/doh/app/init_runnable.rb +5 -0
- data/lib/doh/app/init_unit_test.rb +5 -0
- data/lib/doh/app_util.rb +1 -0
- data/lib/doh/core/date.rb +6 -0
- data/lib/doh/data/require_datagen.rb +7 -0
- data/lib/doh/merb/login.rb +90 -0
- data/lib/doh/mysql/cache_connector.rb +5 -3
- data/lib/doh/mysql/load_sql.rb +0 -1
- data/lib/doh/mysql.rb +1 -0
- data/lib/doh/test/clear_on_teardown.rb +11 -0
- data/lib/doh/test/configure_logging.rb +13 -0
- data/lib/doh/test/error_acceptor.rb +27 -0
- data/lib/doh/test/run_tests.rb +82 -0
- data/lib/doh/test/use_test_database.rb +12 -0
- data/lib/doh/util/banking_workday.rb +61 -0
- data/lib/doh/util/internal_ip.rb +9 -0
- data/test/core/tc_date.rb +25 -0
- data/test/util/tc_banking_workday.rb +27 -0
- metadata +18 -7
- data/bin/repeat_test.rb +0 -11
- data/lib/doh/unit_test.rb +0 -2
- data/lib/doh/unit_test_create_db.rb +0 -7
- data/lib/doh/util/run_tests.rb +0 -10
- data/lib/doh/util/unit_test_logging.rb +0 -31
data/CHANGELOG
CHANGED
@@ -110,3 +110,12 @@
|
|
110
110
|
* added reconfigure_connector utility
|
111
111
|
*0.1.37* (Jun 16th, 2008)
|
112
112
|
* nothing new added, just trying to get it to show up on rubyforge again
|
113
|
+
*0.1.38* (Jun 17th, 2008)
|
114
|
+
* added util/internal_ip, and source_ip setting stuff to default app configuration
|
115
|
+
* move all test related stuff into a test library, and DohTest namespace
|
116
|
+
* significant overhaul to test framework
|
117
|
+
*0.2.0* (Jun 19th, 2008)
|
118
|
+
* added Date::short_weekday_to_num
|
119
|
+
* added DohMerb::Login module
|
120
|
+
* added banking_workday methods to Date in util/banking_workday
|
121
|
+
* added create_database.rb to deploy executables list
|
data/bin/run_tests.rb
CHANGED
@@ -1,17 +1,51 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
require 'doh/app/
|
2
|
+
require 'doh/app/options'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
opts = DohApp::Options.new(
|
5
|
+
{'filter' => [nil, "-f", "--filter <name>", "name or partial name of test method(s) to execute."] \
|
6
|
+
,'force_production' => [false, "-p", "--force_production", "override config to run only production (p, q) tests."] \
|
7
|
+
,'force_development' => [false, "-d", "--force_development", "override config to run only dev (d, p, i) tests."] \
|
8
|
+
,'repeat' => [1, "-r", "--repeat <times>", "number of times to repeat the tests."] \
|
9
|
+
}, true, 'Files or directories may be specified to run tests on. Directories will be treated recursively. Defaults to the current directory.')
|
10
|
+
|
11
|
+
def get_args_without_repeat(argv)
|
12
|
+
result = []
|
13
|
+
ignore_next = false
|
14
|
+
argv.each do |arg|
|
15
|
+
if arg == '-r' || arg == '--repeat'
|
16
|
+
ignore_next = true
|
17
|
+
elsif ignore_next || arg =~ /-r.+/
|
18
|
+
ignore_next = false
|
19
|
+
else
|
20
|
+
result.push(arg)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
result
|
24
|
+
end
|
25
|
+
|
26
|
+
args = opts.varargs.size > 0 ? opts.varargs : ['.']
|
27
|
+
if File.directory?(args[0])
|
28
|
+
start_dir = args[0]
|
7
29
|
else
|
8
|
-
start_dir = File.dirname(
|
30
|
+
start_dir = File.dirname(args[0])
|
9
31
|
end
|
10
|
-
DohApp::init_unit_test(start_dir)
|
11
32
|
|
12
|
-
|
13
|
-
|
14
|
-
|
33
|
+
repeat_count = opts.repeat.to_i
|
34
|
+
if repeat_count > 1
|
35
|
+
args_without_repeat = get_args_without_repeat(ARGV).join(' ')
|
36
|
+
while (repeat_count > 0) do
|
37
|
+
puts "running run_tests.rb #{args_without_repeat} #{repeat_count} more times (or until it fails)"
|
38
|
+
repeat_count -= 1
|
39
|
+
system("#{$PROGRAM_NAME} #{args_without_repeat}")
|
40
|
+
exit $?.exitstatus if $?.exitstatus != 0
|
41
|
+
end
|
15
42
|
else
|
16
|
-
require
|
43
|
+
require 'doh/app/init_unit_test'
|
44
|
+
require 'doh/test/run_tests'
|
45
|
+
DohApp::init_unit_test(start_dir)
|
46
|
+
prod_flag = (DohApp::config['include_production_tests'] || opts.force_production) && !opts.force_development
|
47
|
+
args.each do |arg|
|
48
|
+
DohTest::run_tests(arg, prod_flag, opts.filter)
|
49
|
+
end
|
17
50
|
end
|
51
|
+
|
data/lib/doh/app/config.rb
CHANGED
data/lib/doh/app/home.rb
CHANGED
data/lib/doh/app/init.rb
CHANGED
@@ -1,18 +1,20 @@
|
|
1
1
|
require 'doh/app/home'
|
2
2
|
require 'doh/app/config'
|
3
|
+
require 'doh/app_util'
|
3
4
|
|
4
5
|
module DohApp
|
5
6
|
|
6
7
|
def self.init(file_or_directory)
|
8
|
+
@@config = {}
|
7
9
|
if File.directory?(file_or_directory)
|
8
10
|
find_home(file_or_directory)
|
9
11
|
else
|
10
12
|
find_home(File.dirname(file_or_directory))
|
11
13
|
end
|
12
14
|
$LOAD_PATH.push(File.join(DohApp::home, 'lib'))
|
15
|
+
require 'doh'
|
13
16
|
DohApp::load_config_file('system')
|
14
17
|
DohApp::load_config_file('development_environment') unless DohApp::load_config_file('active_environment')
|
15
|
-
require 'doh/app_util'
|
16
18
|
end
|
17
19
|
|
18
20
|
end
|
@@ -12,6 +12,9 @@ def self.use_default_runnable_production_config
|
|
12
12
|
root_cfg['logger'] = logger_cfg
|
13
13
|
root_cfg['enable_logger'] = true
|
14
14
|
root_cfg['host_files_directory'] = '/etc'
|
15
|
+
|
16
|
+
require 'doh/util/internal_ip'
|
17
|
+
Doh::set_source_ip(Doh::internal_ip)
|
15
18
|
end
|
16
19
|
|
17
20
|
def self.use_default_runnable_development_config
|
@@ -24,6 +27,8 @@ def self.use_default_runnable_development_config
|
|
24
27
|
root_cfg['host_files_directory'] = '~/.dohruby'
|
25
28
|
root_cfg['mail_server'] = 'localhost'
|
26
29
|
root_cfg['database'] = {'username' => 'root', 'host' => 'localhost'}
|
30
|
+
|
31
|
+
Doh::set_source_ip('127.0.0.1')
|
27
32
|
end
|
28
33
|
|
29
34
|
def self.init_runnable(file_or_directory, block = nil)
|
@@ -4,6 +4,11 @@ module DohApp
|
|
4
4
|
|
5
5
|
def self.use_default_unit_test_development_config
|
6
6
|
DohApp::config['database'] = {'username' => 'root', 'host' => 'localhost'}
|
7
|
+
DohApp::config['include_production_tests'] = false
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.use_default_unit_test_production_config
|
11
|
+
DohApp::config['include_production_tests'] = true
|
7
12
|
end
|
8
13
|
|
9
14
|
def self.init_unit_test(file_or_directory)
|
data/lib/doh/app_util.rb
CHANGED
data/lib/doh/core/date.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'date'
|
2
|
+
require 'time'
|
2
3
|
|
3
4
|
class Date
|
4
5
|
def self.days_in_month(year, month)
|
@@ -12,6 +13,11 @@ class Date
|
|
12
13
|
def date_only
|
13
14
|
self
|
14
15
|
end
|
16
|
+
|
17
|
+
def self.short_weekday_to_num(weekday)
|
18
|
+
@@short_days_of_week ||= Time::RFC2822_DAY_NAME.collect {|day| day.downcase}
|
19
|
+
@@short_days_of_week.index(weekday.downcase)
|
20
|
+
end
|
15
21
|
end
|
16
22
|
|
17
23
|
class DateTime
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'doh/mysql'
|
2
|
+
require 'digest'
|
3
|
+
|
4
|
+
module DohMerb
|
5
|
+
module Login
|
6
|
+
attr_accessor :username_fieldname, :password_fieldname, :login_table, :login_db_name, :password_db_name, :login_page
|
7
|
+
|
8
|
+
#set the attr_accessors or override them
|
9
|
+
def username_fieldname
|
10
|
+
@username_fieldname || 'username'
|
11
|
+
end
|
12
|
+
|
13
|
+
def password_fieldname
|
14
|
+
@password_fieldname || 'password'
|
15
|
+
end
|
16
|
+
|
17
|
+
def login_table
|
18
|
+
@login_table || 'login'
|
19
|
+
end
|
20
|
+
|
21
|
+
def login_db_name
|
22
|
+
@login_db_name || 'login'
|
23
|
+
end
|
24
|
+
|
25
|
+
def login_page
|
26
|
+
@login_page || 'login'
|
27
|
+
end
|
28
|
+
|
29
|
+
def password_db_name
|
30
|
+
@password_db_name || 'password'
|
31
|
+
end
|
32
|
+
|
33
|
+
def login_required
|
34
|
+
if !authenticated?
|
35
|
+
Doh::log.debug "not authenticated, redirecting to #{login_page}"
|
36
|
+
session[:dohmerb_original_uri] = request.uri
|
37
|
+
Doh::log.debug("storing original uri #{request.uri.inspect}")
|
38
|
+
redirect login_page
|
39
|
+
throw :halt
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def authenticated?
|
44
|
+
Doh::log.debug("authenticated? called -- session[:dohmerb_login_username] = #{session[:dohmerb_login_username]}, session[:dohmerb_login_key] = #{session[:dohmerb_login_key]}")
|
45
|
+
authenticate_username_key(session[:dohmerb_login_username], session[:dohmerb_login_key])
|
46
|
+
end
|
47
|
+
|
48
|
+
# override this to have custom behavior
|
49
|
+
def authenticate_username_key(username, key)
|
50
|
+
begin
|
51
|
+
password = DohDb::select_field("SELECT #{password_db_name} FROM #{login_table} WHERE #{login_db_name} = #{username.to_sql}")
|
52
|
+
key == get_session_key(username, password)
|
53
|
+
rescue
|
54
|
+
return nil
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def get_session_key(username, password)
|
59
|
+
Digest::SHA1.hexdigest("#{username}**#{password}")
|
60
|
+
end
|
61
|
+
|
62
|
+
def logged_in?
|
63
|
+
authenticated?
|
64
|
+
end
|
65
|
+
|
66
|
+
#kjmtodobb: figure out how to make it so login / logout can just exist here instead of having to get called as helpers -- merb doesn't recognize them as actions if they're included via a module in regular fashion...
|
67
|
+
def login_helper
|
68
|
+
if request.post?
|
69
|
+
session[:dohmerb_login_username] = params[username_fieldname]
|
70
|
+
session[:dohmerb_login_key] = get_session_key(params[username_fieldname], params[password_fieldname])
|
71
|
+
if authenticated?
|
72
|
+
Doh::log.debug("redirecting to original uri: #{session[:dohmerb_original_uri].inspect}")
|
73
|
+
redirect session[:dohmerb_original_uri]
|
74
|
+
else
|
75
|
+
Doh::log.debug("login_helper called, not authenticated -- redirecting to login page")
|
76
|
+
redirect login_page
|
77
|
+
end
|
78
|
+
end
|
79
|
+
render
|
80
|
+
end
|
81
|
+
|
82
|
+
def logout_helper
|
83
|
+
session[:dohmerb_login_username] = ''
|
84
|
+
session[:dohmerb_login_key] = ''
|
85
|
+
redirect login_page
|
86
|
+
render
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
end
|
@@ -31,15 +31,17 @@ class CacheConnector
|
|
31
31
|
private
|
32
32
|
def close_handle(msg)
|
33
33
|
return unless @handle
|
34
|
-
Doh::log.debug("
|
34
|
+
Doh::log.debug("DohDb::CacheConnector - closing previous database connection - #{msg}")
|
35
35
|
@handle.close
|
36
36
|
@handle = nil
|
37
37
|
end
|
38
38
|
|
39
39
|
def get_new_handle(database = nil)
|
40
|
-
|
40
|
+
database ||= @database
|
41
|
+
dbmsg = database.to_s.strip.empty? ? 'no default database' : "database #{database}"
|
42
|
+
Doh::log.info("DohDb::CacheConnector - connecting to #@host as username #@username, #{dbmsg}")
|
41
43
|
@last_used = Time.now
|
42
|
-
Handle.new(Mysql.connect(@host, @username, @password, database
|
44
|
+
Handle.new(Mysql.connect(@host, @username, @password, database), @row_builder)
|
43
45
|
end
|
44
46
|
|
45
47
|
def passed_timeout?
|
data/lib/doh/mysql/load_sql.rb
CHANGED
@@ -11,7 +11,6 @@ def self.load_sql(filenames, host, username, password, database)
|
|
11
11
|
mysqlcmd = 'mysql' + mysql_arg(host, 'h') + mysql_arg(username, 'u') + mysql_arg(password, 'p') + ' ' + database
|
12
12
|
io = IO::popen(mysqlcmd, 'r+')
|
13
13
|
filenames.each do |elem|
|
14
|
-
Doh::log.debug("loading file: #{elem}")
|
15
14
|
open(elem) {|file| io << file.read}
|
16
15
|
end
|
17
16
|
io.close
|
data/lib/doh/mysql.rb
CHANGED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'doh/logger/formatter'
|
2
|
+
require 'doh/logger_configure'
|
3
|
+
require 'doh/logger/util'
|
4
|
+
require 'doh/test/error_acceptor'
|
5
|
+
|
6
|
+
DohTest::init_error_acceptor
|
7
|
+
scheduler = DohLogger::DirectScheduler.new
|
8
|
+
file_acceptor = DohLogger::IOStreamAcceptor.new(File.new('doh_tests.log', "wb"))
|
9
|
+
intrfc = DohLogger::StandardInterface.new(scheduler)
|
10
|
+
intrfc.add_acceptor(DohLogger::DEBUG, file_acceptor)
|
11
|
+
intrfc.add_acceptor(DohLogger::ERROR, DohTest::error_acceptor)
|
12
|
+
Doh::set_logger_interface(intrfc)
|
13
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'doh/logger/memory_acceptor'
|
2
|
+
|
3
|
+
module DohTest
|
4
|
+
|
5
|
+
def self.init_error_acceptor
|
6
|
+
@@error_acceptor = DohLogger::MemoryAcceptor.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.error_acceptor
|
10
|
+
@@error_acceptor
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.pop_error
|
14
|
+
@@error_acceptor.events.pop
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.check_for_unhandled_errors
|
18
|
+
errors = DohTest::error_acceptor.events
|
19
|
+
unless errors.empty?
|
20
|
+
STDERR.puts("#{errors.size} unhandled errors were written to the log file:")
|
21
|
+
formatter = DohLogger::Formatter.new("[%severity] : %msg\nexception: %exception\nstack:\n%call_stack")
|
22
|
+
errors.each {|elem| STDERR.puts(formatter.replace(elem))}
|
23
|
+
exit 1
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'doh/test/configure_logging'
|
2
|
+
require 'doh/core/dir'
|
3
|
+
require 'doh/app/activate_database'
|
4
|
+
require 'doh/mysql/database_creator'
|
5
|
+
require 'test/unit'
|
6
|
+
require 'test/unit/collector/dir'
|
7
|
+
require 'test/unit/ui/console/testrunner'
|
8
|
+
require 'doh/test/clear_on_teardown'
|
9
|
+
require 'doh/data/require_datagen'
|
10
|
+
|
11
|
+
module DohTest
|
12
|
+
|
13
|
+
def self.find_tests(directory, match, files_found)
|
14
|
+
Dir.glob(File.join(directory, match)).each {|filename| files_found.push(filename)}
|
15
|
+
Dir.directories(directory).each {|subdir| find_tests(File.join(directory, subdir), match, files_found)}
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.init_test_database
|
19
|
+
dbname = DohApp::config['primary_database']
|
20
|
+
DohDb::DatabaseCreator.new.create_database_copy('doh_test_' + dbname, dbname, true)
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.init_live_database
|
24
|
+
DohDb::connector_instance.reset
|
25
|
+
DohDb::connector_instance.database = DohApp::config['primary_database']
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.execute_test_files(files, method_filter = nil)
|
29
|
+
collector = Test::Unit::Collector::Dir.new
|
30
|
+
collector.filter = [proc {|tstobj| !tstobj.method_name.index(method_filter).nil?}] if method_filter
|
31
|
+
suite = collector.collect(*files)
|
32
|
+
results = Test::Unit::UI::Console::TestRunner.run(suite)
|
33
|
+
exit(1) unless results.passed?
|
34
|
+
DohTest::check_for_unhandled_errors
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.run_tests_directory(directory, include_production_tests, method_filter = nil)
|
38
|
+
if include_production_tests
|
39
|
+
letters = 'pq'
|
40
|
+
run_integration_tests = false
|
41
|
+
else
|
42
|
+
letters = 'dp'
|
43
|
+
run_integration_tests = true
|
44
|
+
end
|
45
|
+
|
46
|
+
files = []; DohTest::find_tests(directory, "*.dt[#{letters}].rb", files)
|
47
|
+
unless files.empty?
|
48
|
+
init_test_database
|
49
|
+
execute_test_files(files, method_filter)
|
50
|
+
end
|
51
|
+
|
52
|
+
return unless run_integration_tests
|
53
|
+
files = []; DohTest::find_tests(directory, "*.dti.rb", files)
|
54
|
+
unless files.empty?
|
55
|
+
init_live_database
|
56
|
+
execute_test_files(files)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.run_tests_file(filename, method_filter = nil)
|
61
|
+
if filename.ends_with('.dti.rb')
|
62
|
+
init_live_database
|
63
|
+
else
|
64
|
+
init_test_database
|
65
|
+
end
|
66
|
+
execute_test_files([filename], method_filter)
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.run_tests(what_to_run, include_production_tests, method_filter = nil)
|
70
|
+
DohApp::activate_database
|
71
|
+
DohData::require_datagen
|
72
|
+
what_to_run.each do |elem|
|
73
|
+
if File.directory?(elem)
|
74
|
+
run_tests_directory(elem, include_production_tests, method_filter)
|
75
|
+
else
|
76
|
+
run_tests_file(elem, method_filter)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
0
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'doh/mysql/database_creator'
|
2
|
+
|
3
|
+
module DohTest
|
4
|
+
|
5
|
+
def self.use_test_database
|
6
|
+
dbcfg = DohApp::config['database']
|
7
|
+
dbname = DohApp::config['primary_database']
|
8
|
+
DohDb::set_connector_instance(DohDb::CacheConnector.new(dbcfg['host'], dbcfg['username'], dbcfg['password'], nil, DohApp::config['row_builder']))
|
9
|
+
DohDb::DatabaseCreator.new.create_database_copy('doh_test_' + dbname, dbname, true)
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'doh/core/date'
|
2
|
+
|
3
|
+
class Date
|
4
|
+
# taken from http://www.federalreserve.gov/releases/k8/default.htm
|
5
|
+
@@banking_holidays = [Date.new(2007, 1, 1), Date.new(2007, 1, 15), Date.new(2007, 2, 19), Date.new(2007, 5, 28), Date.new(2007, 7, 4), Date.new(2007, 9, 3), Date.new(2007, 10, 8), Date.new(2007, 11, 12), Date.new(2007, 11, 22), Date.new(2007, 12, 25),
|
6
|
+
Date.new(2008, 1, 1), Date.new(2008, 1, 21), Date.new(2008, 2, 18), Date.new(2008, 5, 26), Date.new(2008, 7, 4), Date.new(2008, 9, 1), Date.new(2008, 10, 13), Date.new(2008, 11, 11), Date.new(2008, 11, 27), Date.new(2008, 12, 25),
|
7
|
+
Date.new(2009, 1, 1), Date.new(2009, 1, 19), Date.new(2009, 2, 16), Date.new(2009, 5, 25), Date.new(2009, 7, 4), Date.new(2009, 9, 7), Date.new(2009, 10, 12), Date.new(2009, 11, 11), Date.new(2009, 11, 26), Date.new(2009, 12, 25),
|
8
|
+
Date.new(2010, 1, 1), Date.new(2010, 1, 18), Date.new(2010, 2, 15), Date.new(2010, 5, 31), Date.new(2010, 7, 5), Date.new(2010, 9, 6), Date.new(2010, 10, 11), Date.new(2010, 11, 11), Date.new(2010, 11, 25), Date.new(2010, 12, 25),
|
9
|
+
Date.new(2011, 1, 1), Date.new(2011, 1, 17), Date.new(2011, 2, 21), Date.new(2011, 5, 30), Date.new(2011, 7, 4), Date.new(2011, 9, 5), Date.new(2011, 10, 10), Date.new(2011, 11, 11), Date.new(2011, 11, 24), Date.new(2011, 12, 26),
|
10
|
+
]
|
11
|
+
|
12
|
+
def banking_holiday?
|
13
|
+
@@banking_holidays.include?(self)
|
14
|
+
end
|
15
|
+
|
16
|
+
def banking_workday?
|
17
|
+
weekday? && !banking_holiday?
|
18
|
+
end
|
19
|
+
|
20
|
+
def forward_banking_workday(count = 1)
|
21
|
+
retval = self
|
22
|
+
until retval.banking_workday?
|
23
|
+
retval = retval + 1
|
24
|
+
end
|
25
|
+
count.times do
|
26
|
+
begin
|
27
|
+
retval = retval + 1
|
28
|
+
end until retval.banking_workday?
|
29
|
+
end
|
30
|
+
retval
|
31
|
+
end
|
32
|
+
|
33
|
+
def backward_banking_workday(count = 1)
|
34
|
+
retval = self
|
35
|
+
until retval.banking_workday?
|
36
|
+
retval = retval - 1
|
37
|
+
end
|
38
|
+
count.times do
|
39
|
+
begin
|
40
|
+
retval = retval - 1
|
41
|
+
end until retval.banking_workday?
|
42
|
+
end
|
43
|
+
retval
|
44
|
+
end
|
45
|
+
|
46
|
+
def next_weekend_day
|
47
|
+
retval = self + 1
|
48
|
+
until !retval.weekday?
|
49
|
+
retval += 1
|
50
|
+
end
|
51
|
+
retval
|
52
|
+
end
|
53
|
+
|
54
|
+
def previous_weekend_day
|
55
|
+
retval = self - 1
|
56
|
+
until !retval.weekday?
|
57
|
+
retval -= 1
|
58
|
+
end
|
59
|
+
retval
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'doh/core/date'
|
3
|
+
|
4
|
+
module Doh
|
5
|
+
|
6
|
+
class TC_core_date < Test::Unit::TestCase
|
7
|
+
def test_weekday
|
8
|
+
Date.new(2007, 1, 15).upto(Date.new(2007, 1, 19)) { |date| assert(date.weekday?) }
|
9
|
+
assert(!Date.new(2007, 1, 13).weekday?)
|
10
|
+
assert(!Date.new(2007, 1, 14).weekday?)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_short_weekday_to_num
|
14
|
+
assert_equal(0, Date::short_weekday_to_num('SUN'))
|
15
|
+
assert_equal(1, Date::short_weekday_to_num('MON'))
|
16
|
+
assert_equal(2, Date::short_weekday_to_num('tue'))
|
17
|
+
assert_equal(3, Date::short_weekday_to_num('Wed'))
|
18
|
+
assert_equal(4, Date::short_weekday_to_num('Thu'))
|
19
|
+
assert_equal(5, Date::short_weekday_to_num('fRi'))
|
20
|
+
assert_equal(6, Date::short_weekday_to_num('saT'))
|
21
|
+
assert_equal(nil, Date::short_weekday_to_num('saTurday'))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'doh/util/banking_workday'
|
3
|
+
module Doh
|
4
|
+
|
5
|
+
class TC_banking_workday < Test::Unit::TestCase
|
6
|
+
def test_forward_banking_workday
|
7
|
+
assert_equal(Date.new(2007, 2, 2).to_s, Date.new(2007, 2, 1).forward_banking_workday.to_s)
|
8
|
+
assert_equal(Date.new(2007, 2, 5).to_s, Date.new(2007, 2, 2).forward_banking_workday.to_s)
|
9
|
+
assert_equal(Date.new(2007, 2, 6).to_s, Date.new(2007, 2, 3).forward_banking_workday.to_s)
|
10
|
+
assert_equal(Date.new(2007, 2, 6).to_s, Date.new(2007, 2, 4).forward_banking_workday.to_s)
|
11
|
+
assert_equal(Date.new(2007, 2, 6).to_s, Date.new(2007, 2, 5).forward_banking_workday.to_s)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_backward_banking_workday
|
15
|
+
assert_equal(Date.new(2007, 2, 5).to_s, Date.new(2007, 2, 6).backward_banking_workday.to_s)
|
16
|
+
assert_equal(Date.new(2007, 2, 2).to_s, Date.new(2007, 2, 5).backward_banking_workday.to_s)
|
17
|
+
assert_equal(Date.new(2007, 2, 1).to_s, Date.new(2007, 2, 4).backward_banking_workday.to_s)
|
18
|
+
assert_equal(Date.new(2007, 2, 1).to_s, Date.new(2007, 2, 3).backward_banking_workday.to_s)
|
19
|
+
assert_equal(Date.new(2007, 2, 1).to_s, Date.new(2007, 2, 2).backward_banking_workday.to_s)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_banking_holiday
|
23
|
+
assert(Date.new(2007, 2, 19).banking_holiday?)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dohruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Makani & Kem Mason
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-06-
|
12
|
+
date: 2008-06-19 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -26,6 +26,7 @@ email: makani.and.kem.mason@gmail.com
|
|
26
26
|
executables:
|
27
27
|
- run_tests.rb
|
28
28
|
- rcov-preprocess-files.rb
|
29
|
+
- create_database.rb
|
29
30
|
extensions: []
|
30
31
|
|
31
32
|
extra_rdoc_files:
|
@@ -35,7 +36,6 @@ extra_rdoc_files:
|
|
35
36
|
files:
|
36
37
|
- bin/create_database.rb
|
37
38
|
- bin/rcov-preprocess-files.rb
|
38
|
-
- bin/repeat_test.rb
|
39
39
|
- bin/run_tests.rb
|
40
40
|
- lib/doh
|
41
41
|
- lib/doh/app
|
@@ -61,6 +61,7 @@ files:
|
|
61
61
|
- lib/doh/data/basic.rb
|
62
62
|
- lib/doh/data/bulk.rb
|
63
63
|
- lib/doh/data/human.rb
|
64
|
+
- lib/doh/data/require_datagen.rb
|
64
65
|
- lib/doh/data.rb
|
65
66
|
- lib/doh/logger
|
66
67
|
- lib/doh/logger/direct_scheduler.rb
|
@@ -77,6 +78,7 @@ files:
|
|
77
78
|
- lib/doh/logger.rb
|
78
79
|
- lib/doh/logger_configure.rb
|
79
80
|
- lib/doh/merb
|
81
|
+
- lib/doh/merb/login.rb
|
80
82
|
- lib/doh/merb/notify_on_exception.rb
|
81
83
|
- lib/doh/merb/post_hash.rb
|
82
84
|
- lib/doh/merb.rb
|
@@ -101,19 +103,24 @@ files:
|
|
101
103
|
- lib/doh/mysql/typed_row_builder.rb
|
102
104
|
- lib/doh/mysql/unquoted.rb
|
103
105
|
- lib/doh/mysql.rb
|
104
|
-
- lib/doh/
|
105
|
-
- lib/doh/
|
106
|
+
- lib/doh/test
|
107
|
+
- lib/doh/test/clear_on_teardown.rb
|
108
|
+
- lib/doh/test/configure_logging.rb
|
109
|
+
- lib/doh/test/error_acceptor.rb
|
110
|
+
- lib/doh/test/run_tests.rb
|
111
|
+
- lib/doh/test/use_test_database.rb
|
106
112
|
- lib/doh/util
|
113
|
+
- lib/doh/util/banking_workday.rb
|
107
114
|
- lib/doh/util/blank_slate.rb
|
108
115
|
- lib/doh/util/current_date.rb
|
116
|
+
- lib/doh/util/internal_ip.rb
|
109
117
|
- lib/doh/util/num_or_self.rb
|
110
|
-
- lib/doh/util/run_tests.rb
|
111
118
|
- lib/doh/util/source_ip.rb
|
112
119
|
- lib/doh/util/time_util.rb
|
113
|
-
- lib/doh/util/unit_test_logging.rb
|
114
120
|
- lib/doh.rb
|
115
121
|
- test/core
|
116
122
|
- test/core/tc_bigdecimal.rb
|
123
|
+
- test/core/tc_date.rb
|
117
124
|
- test/core/tc_string.rb
|
118
125
|
- test/logger
|
119
126
|
- test/logger/sample.rb
|
@@ -131,6 +138,8 @@ files:
|
|
131
138
|
- test/mysql/tc_parse.rb
|
132
139
|
- test/mysql/tc_readonly_row.rb
|
133
140
|
- test/mysql/tc_unquoted.rb
|
141
|
+
- test/util
|
142
|
+
- test/util/tc_banking_workday.rb
|
134
143
|
- README
|
135
144
|
- MIT-LICENSE
|
136
145
|
- CHANGELOG
|
@@ -162,6 +171,7 @@ specification_version: 2
|
|
162
171
|
summary: DohRuby's purpose is to make your life as a developer easier & make you more efficient in your programming.
|
163
172
|
test_files:
|
164
173
|
- test/core/tc_bigdecimal.rb
|
174
|
+
- test/core/tc_date.rb
|
165
175
|
- test/core/tc_string.rb
|
166
176
|
- test/logger/sample.rb
|
167
177
|
- test/logger/tc_acceptor.rb
|
@@ -176,3 +186,4 @@ test_files:
|
|
176
186
|
- test/mysql/tc_parse.rb
|
177
187
|
- test/mysql/tc_readonly_row.rb
|
178
188
|
- test/mysql/tc_unquoted.rb
|
189
|
+
- test/util/tc_banking_workday.rb
|
data/bin/repeat_test.rb
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
file_to_run = ARGV[0]
|
4
|
-
repeat_count = (ARGV[1] || 10000).to_i
|
5
|
-
|
6
|
-
while (repeat_count > 0) do
|
7
|
-
puts "running #{file_to_run} #{repeat_count} more times (or until it fails)"
|
8
|
-
repeat_count -= 1
|
9
|
-
system("run_tests.rb #{file_to_run}")
|
10
|
-
exit if $?.exitstatus != 0
|
11
|
-
end
|
data/lib/doh/unit_test.rb
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
require 'doh/mysql/database_creator'
|
2
|
-
|
3
|
-
#kjmtodo -- mak possibly combine this with doh/unit_test ??
|
4
|
-
|
5
|
-
dbconfig = DohApp::config['database']
|
6
|
-
DohDb::set_connector_instance(DohDb::CacheConnector.new(dbconfig['host'], dbconfig['username'], dbconfig['password'], nil, DohApp::config['row_builder']))
|
7
|
-
DohDb::DatabaseCreator.new.create_database_copy('dohruby_unit_test_' + DohApp::config['primary_database'], DohApp::config['primary_database'], true)
|
data/lib/doh/util/run_tests.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'doh/logger/formatter'
|
2
|
-
|
3
|
-
at_exit do
|
4
|
-
errors = $doh_unit_test_error_acceptor.events
|
5
|
-
unless errors.empty?
|
6
|
-
STDERR.puts("#{errors.size} unhandled errors were written to the log file:")
|
7
|
-
formatter = DohLogger::Formatter.new("[%severity] : %msg\nexception: %exception\nstack:\n%call_stack")
|
8
|
-
errors.each {|err| STDERR.puts(formatter.replace(err))}
|
9
|
-
exit 1
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
require 'doh/logger_configure'
|
14
|
-
require 'doh/logger/memory_acceptor'
|
15
|
-
require 'doh/logger/util'
|
16
|
-
|
17
|
-
scheduler = DohLogger::DirectScheduler.new
|
18
|
-
file_acceptor = DohLogger::IOStreamAcceptor.new(File.new('doh_unit_tests.log', "wb"))
|
19
|
-
$doh_unit_test_error_acceptor = DohLogger::MemoryAcceptor.new
|
20
|
-
intrfc = DohLogger::StandardInterface.new(scheduler)
|
21
|
-
intrfc.add_acceptor(DohLogger::DEBUG, file_acceptor)
|
22
|
-
intrfc.add_acceptor(DohLogger::ERROR, $doh_unit_test_error_acceptor)
|
23
|
-
Doh::set_logger_interface(intrfc)
|
24
|
-
|
25
|
-
module Doh
|
26
|
-
|
27
|
-
def self.pop_unit_test_error
|
28
|
-
$doh_unit_test_error_acceptor.events.pop
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|