Skip to content

Commit

Permalink
Implement support for DATETIME (odbc, tiny_tds) and DATE (tiny_tds only)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vassil Kovatchev committed Mar 18, 2018
1 parent affc641 commit b019ffe
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
2 changes: 2 additions & 0 deletions lib/slacker/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ def configure
configure_db_odbc
when TINYTDS_DRIVER
configure_db_tiny_tds
else
raise RuntimeError, "Unknown driver \"#{@configuration.db_driver}\" used in database configuration; Supported drivers: \"odbc\", \"tiny_tds\"."
end
configure_rspec
configure_misc
Expand Down
14 changes: 8 additions & 6 deletions lib/slacker/query_result_matcher.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
require 'csv'
require 'time'

module Slacker
DATE_FORMAT = "%m/%d/%Y"
DATETIME_FORMAT = '%Y-%m-%dT%H:%M:%S'


class QueryResultMatcher
def initialize(golden_master)
@golden_master = golden_master
Expand Down Expand Up @@ -100,13 +99,16 @@ def match_values?(master_val, subject_val)
elsif master_val.kind_of?(String)
case subject_val
when ODBC::TimeStamp
(!!Time.strptime(master_val, DATE_FORMAT) rescue false) && Time.strptime(master_val, DATE_FORMAT) == ODBC::to_time(subject_val)
# Convert master string value to date-time and compare.
((subject_val_time = Time.parse(master_val)) rescue false) && subject_val_time == ODBC::to_time(subject_val)
# Time is the class returned by tiny_tds when the resultset includes datetime or time.
when Time
# Convert master string value to date-time and compare.
((subject_val_time = Time.parse(master_val)) rescue false) && subject_val_time == subject_val
when Float
(!!Float(master_val) rescue false) && Float(master_val) == subject_val
when BigDecimal
(!!BigDecimal(master_val) rescue false) && BigDecimal(master_val) == BigDecimal(subject_val)
when Time
(!!DateTime.strptime(DateTime.parse(master_val).to_s, DATETIME_FORMAT) rescue false) && DateTime.strptime(DateTime.parse(master_val).to_s, DATETIME_FORMAT) == DateTime.strptime(DateTime.parse(subject_val.to_s).to_s, DATETIME_FORMAT)
else
subject_val.to_s == master_val.to_s
end
Expand Down
2 changes: 1 addition & 1 deletion lib/slacker/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Slacker
VERSION = "1.0.21"
VERSION = "1.0.22"
end
2 changes: 1 addition & 1 deletion spec/test_files/matcher/test_1.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"Field 1","Field_2","b"
12,,""
"test string",01/30/2011,8.9
"test string",2011-01-30,8.9

0 comments on commit b019ffe

Please sign in to comment.