marjoree 0.0.1
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.
- data/README +50 -0
- data/examples/contains_example.rb +23 -0
- data/examples/count_and_insert_example.rb +20 -0
- data/examples/select_example.rb +27 -0
- data/html/classes/ExpectedResultSet.html +220 -0
- data/html/classes/ExpectedResultSet.src/M000001.html +18 -0
- data/html/classes/ExpectedResultSet.src/M000002.html +18 -0
- data/html/classes/ExpectedResultSet.src/M000003.html +18 -0
- data/html/classes/ExpectedResultSet.src/M000004.html +18 -0
- data/html/classes/Marjoree.html +568 -0
- data/html/classes/Marjoree.src/M000022.html +19 -0
- data/html/classes/Marjoree.src/M000023.html +20 -0
- data/html/classes/Marjoree.src/M000024.html +22 -0
- data/html/classes/Marjoree.src/M000025.html +18 -0
- data/html/classes/Marjoree.src/M000026.html +20 -0
- data/html/classes/Marjoree.src/M000027.html +18 -0
- data/html/classes/Marjoree.src/M000028.html +18 -0
- data/html/classes/Marjoree.src/M000029.html +21 -0
- data/html/classes/Marjoree.src/M000030.html +20 -0
- data/html/classes/Marjoree.src/M000031.html +19 -0
- data/html/classes/Marjoree.src/M000032.html +18 -0
- data/html/classes/Marjoree.src/M000033.html +18 -0
- data/html/classes/Marjoree.src/M000034.html +19 -0
- data/html/classes/Marjoree.src/M000035.html +21 -0
- data/html/classes/Marjoree.src/M000036.html +26 -0
- data/html/classes/Marjoree.src/M000037.html +22 -0
- data/html/classes/Marjoree.src/M000038.html +23 -0
- data/html/classes/Marjoree.src/M000039.html +24 -0
- data/html/classes/Marjoree.src/M000040.html +18 -0
- data/html/classes/Marjoree.src/M000041.html +18 -0
- data/html/classes/Marjoree.src/M000042.html +25 -0
- data/html/classes/ODBC/Error.html +152 -0
- data/html/classes/ODBC/Error.src/M000020.html +21 -0
- data/html/classes/ODBC/Error.src/M000021.html +18 -0
- data/html/classes/ODBC/TimeStamp.html +182 -0
- data/html/classes/ODBC/TimeStamp.src/M000017.html +18 -0
- data/html/classes/ODBC/TimeStamp.src/M000018.html +22 -0
- data/html/classes/ODBC/TimeStamp.src/M000019.html +19 -0
- data/html/classes/ODBC.html +108 -0
- data/html/classes/ResultSetWrapper.html +345 -0
- data/html/classes/ResultSetWrapper.src/M000005.html +27 -0
- data/html/classes/ResultSetWrapper.src/M000006.html +24 -0
- data/html/classes/ResultSetWrapper.src/M000007.html +23 -0
- data/html/classes/ResultSetWrapper.src/M000008.html +18 -0
- data/html/classes/ResultSetWrapper.src/M000009.html +18 -0
- data/html/classes/ResultSetWrapper.src/M000010.html +18 -0
- data/html/classes/ResultSetWrapper.src/M000011.html +18 -0
- data/html/classes/ResultSetWrapper.src/M000012.html +20 -0
- data/html/classes/ResultSetWrapper.src/M000013.html +18 -0
- data/html/classes/ResultSetWrapper.src/M000014.html +22 -0
- data/html/classes/ResultSetWrapper.src/M000015.html +23 -0
- data/html/classes/ResultSetWrapper.src/M000016.html +27 -0
- data/html/created.rid +1 -0
- data/html/files/README.html +159 -0
- data/html/files/lib/expected_result_set_rb.html +116 -0
- data/html/files/lib/marjoree_rb.html +110 -0
- data/html/files/lib/odbc_overrides_rb.html +101 -0
- data/html/files/lib/result_set_wrapper_rb.html +101 -0
- data/html/fr_class_index.html +32 -0
- data/html/fr_file_index.html +31 -0
- data/html/fr_method_index.html +68 -0
- data/html/index.html +24 -0
- data/html/rdoc-style.css +208 -0
- data/lib/expected_result_set.rb +35 -0
- data/lib/marjoree.rb +344 -0
- data/lib/odbc_overrides.rb +33 -0
- data/lib/result_set_wrapper.rb +193 -0
- data/rakefile.rb +38 -0
- data/tests/all_tests.rb +15 -0
- data/tests/sprocs/test_error_sproc.sp +11 -0
- data/tests/sprocs/test_sproc.sp +5 -0
- data/tests/sprocs/test_sproc_with_mixed_params.sp +15 -0
- data/tests/sprocs/test_sproc_with_output_params.sp +10 -0
- data/tests/sprocs/test_sproc_with_params.sp +9 -0
- data/tests/sprocs/test_sproc_with_select_and_ops.sp +12 -0
- data/tests/test_contains.rb +27 -0
- data/tests/test_delete.rb +47 -0
- data/tests/test_expected_result_set.rb +40 -0
- data/tests/test_insert.rb +47 -0
- data/tests/test_marjoree.rb +91 -0
- data/tests/test_num_rows.rb +32 -0
- data/tests/test_result_set_wrapper.rb +162 -0
- data/tests/test_select.rb +30 -0
- data/tests/test_sproc.rb +99 -0
- data/tests/test_time_stamp.rb +52 -0
- data/tests/test_truncate.rb +31 -0
- data/tests/test_update.rb +56 -0
- metadata +137 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
class ODBC::TimeStamp
|
|
2
|
+
alias_method :old_to_s, :to_s
|
|
3
|
+
|
|
4
|
+
def ==( pal )
|
|
5
|
+
return to_s.index( pal.to_s ) == 0
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def to_s
|
|
9
|
+
datetime = old_to_s
|
|
10
|
+
date, time, fraction = datetime.split(" ")
|
|
11
|
+
|
|
12
|
+
fraction_text = (fraction == '0') ? '' : ".#{fraction}"
|
|
13
|
+
return "#{date} #{time}#{fraction_text}"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def self.from_date(date)
|
|
17
|
+
formatted_date = date.strftime '%Y-%m-%d %H:%M:%S.000'
|
|
18
|
+
return ODBC::TimeStamp.new(formatted_date)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
class ODBC::Error
|
|
23
|
+
def error_code
|
|
24
|
+
start_index = to_s =~ /(\()/
|
|
25
|
+
end_index = to_s =~ /(\))/
|
|
26
|
+
end_index -= 1
|
|
27
|
+
return to_s.slice( (start_index + 1 ), (end_index - start_index ) ).to_i
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def error_message
|
|
31
|
+
return to_s.split( /\]/ ).last.rstrip!
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
class ResultSetWrapper
|
|
2
|
+
attr_reader :columns
|
|
3
|
+
attr_reader :hashes
|
|
4
|
+
|
|
5
|
+
def initialize( statement, output_param_names = [] )
|
|
6
|
+
@padding = " "
|
|
7
|
+
@spacer = " "
|
|
8
|
+
@columns = statement.columns
|
|
9
|
+
@hashes = []
|
|
10
|
+
|
|
11
|
+
if output_param_names.length > 0
|
|
12
|
+
apply_output_params( output_param_names, statement )
|
|
13
|
+
else
|
|
14
|
+
extract_results( statement )
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def apply_output_params( output_param_names, statement )
|
|
19
|
+
for i in 0..( output_param_names.length - 1 )
|
|
20
|
+
value = statement.fetch![0]
|
|
21
|
+
statement.more_results
|
|
22
|
+
|
|
23
|
+
var_name = "#{output_param_names[i]}"
|
|
24
|
+
instance_variable_set( var_name, value )
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def method_missing( name )
|
|
29
|
+
member_var = eval( "@#{name}" )
|
|
30
|
+
if !member_var.nil?
|
|
31
|
+
return member_var
|
|
32
|
+
else
|
|
33
|
+
return super.method_missing( name )
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def is_output_param?( name )
|
|
38
|
+
return !eval( "#{name}" ).nil?
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Returns the number of rows in self.
|
|
42
|
+
def count
|
|
43
|
+
return @hashes.size
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Returns the number of rows in self.
|
|
47
|
+
def size
|
|
48
|
+
return count
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Returns true if self contains zero rows.
|
|
52
|
+
def empty?
|
|
53
|
+
return count == 0
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Iterates round each row applying a block.
|
|
57
|
+
def collect
|
|
58
|
+
@hashes.each do |hash|
|
|
59
|
+
yield hash
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# Returns true if the contents of the 'expected_result_set' is held within self.
|
|
64
|
+
def has?( expected_result_set )
|
|
65
|
+
return contains?( expected_result_set.row_hashes )
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# Returns true if the contents of the 'expected_rows' map is held within self.
|
|
69
|
+
def contains?( *expected_rows )
|
|
70
|
+
expected_rows.flatten.each do |expected|
|
|
71
|
+
return false unless contains_row?( expected )
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
return true
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def contains_row?( expected )
|
|
78
|
+
expected_with_symbols = convert_keys_to_symbols( expected )
|
|
79
|
+
@hashes.each do |actual|
|
|
80
|
+
return true if actual == actual.merge(expected_with_symbols)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
return false
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# Provides the contents of self in the form of a table.
|
|
87
|
+
def to_s
|
|
88
|
+
column_widths = widest_value_in_columns
|
|
89
|
+
|
|
90
|
+
result = create_header_row( column_widths )
|
|
91
|
+
result << "\n" + create_separator_row( column_widths )
|
|
92
|
+
|
|
93
|
+
@hashes.each do |row|
|
|
94
|
+
result << "\n" + create_data_row( row, column_widths )
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
return result
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
private
|
|
101
|
+
|
|
102
|
+
def create_separator_row( column_widths )
|
|
103
|
+
result = ""
|
|
104
|
+
|
|
105
|
+
column_widths.each do |width|
|
|
106
|
+
result << " "
|
|
107
|
+
num_bars = width + ( @padding.length * 2 )
|
|
108
|
+
num_bars.times { result << "-" }
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
result << " "
|
|
112
|
+
|
|
113
|
+
return result
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def create_header_row( column_widths )
|
|
117
|
+
result = ""
|
|
118
|
+
|
|
119
|
+
counter = 0
|
|
120
|
+
column_names.each do |header|
|
|
121
|
+
result << "|#{@padding}" + create_entry( header, column_widths[counter] ) + "#{@padding}"
|
|
122
|
+
counter += 1
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
return result + "|"
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def create_data_row( row, column_widths )
|
|
129
|
+
result = ""
|
|
130
|
+
|
|
131
|
+
counter = 0
|
|
132
|
+
column_names.each do |header|
|
|
133
|
+
result << "|#{@padding}" + create_entry( row[header.to_sym].to_s, column_widths[counter] ) + "#{@padding}"
|
|
134
|
+
counter += 1
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
return result + "|"
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def create_entry( header, expected_width )
|
|
141
|
+
if header.length == expected_width
|
|
142
|
+
return header
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
num_prefix_spaces = (expected_width - header.length)/2
|
|
146
|
+
num_postfix_spaces = expected_width - (num_prefix_spaces + header.length )
|
|
147
|
+
pre = ""
|
|
148
|
+
post = ""
|
|
149
|
+
num_prefix_spaces.times{ pre << " " }
|
|
150
|
+
num_postfix_spaces.times{ post << " " }
|
|
151
|
+
|
|
152
|
+
return pre + header + post
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
def widest_value_in_columns
|
|
156
|
+
result = []
|
|
157
|
+
|
|
158
|
+
column_names.each do |header|
|
|
159
|
+
largest = header.length
|
|
160
|
+
@hashes.each do |row|
|
|
161
|
+
if row[header.to_sym].to_s.length > largest
|
|
162
|
+
largest = row[header.to_sym].length
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
result << largest
|
|
167
|
+
puts
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
return result
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
def column_names
|
|
174
|
+
return columns.keys
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
def convert_keys_to_symbols( row )
|
|
178
|
+
result = {}
|
|
179
|
+
|
|
180
|
+
row.each do |key, value|
|
|
181
|
+
result[key.to_sym] = value
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
return result
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
def extract_results( statement )
|
|
188
|
+
statement.each_hash do |row|
|
|
189
|
+
@hashes << convert_keys_to_symbols( row )
|
|
190
|
+
end
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
end
|
data/rakefile.rb
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'rake'
|
|
3
|
+
require 'rake/packagetask'
|
|
4
|
+
require 'rake/testtask'
|
|
5
|
+
require 'rake/gempackagetask'
|
|
6
|
+
require 'rake/rdoctask'
|
|
7
|
+
|
|
8
|
+
task :default => ['test', "rdoc"]
|
|
9
|
+
|
|
10
|
+
spec = Gem::Specification.new do |s|
|
|
11
|
+
s.name = 'marjoree'
|
|
12
|
+
s.version = "0.0.1"
|
|
13
|
+
s.platform = Gem::Platform::RUBY
|
|
14
|
+
s.summary = "Marjoree is the Stored Procedure Testing Library"
|
|
15
|
+
s.homepage = "http://www.jiggypete.com"
|
|
16
|
+
s.files = Dir["./**/*"]
|
|
17
|
+
s.has_rdoc=true
|
|
18
|
+
s.author = "Peter Aitken, Ian Davies, Gus MacCuish"
|
|
19
|
+
s.email = "jiggypete@googlemail.com"
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
Rake::GemPackageTask.new(spec) do |p|
|
|
23
|
+
p.gem_spec = spec
|
|
24
|
+
p.need_tar = true
|
|
25
|
+
p.need_zip = true
|
|
26
|
+
p.gem_file
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
Rake::RDocTask.new do |rd|
|
|
30
|
+
rd.main = "README.rdoc"
|
|
31
|
+
rd.rdoc_files.include("README", "lib/**/*.rb")
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
Rake::TestTask.new do |t|
|
|
35
|
+
t.libs << "lib"
|
|
36
|
+
t.test_files = FileList['tests/all_tests.rb']
|
|
37
|
+
t.verbose = true
|
|
38
|
+
end
|
data/tests/all_tests.rb
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
|
|
2
|
+
|
|
3
|
+
require 'marjoree'
|
|
4
|
+
require 'expected_result_set'
|
|
5
|
+
require 'rake'
|
|
6
|
+
|
|
7
|
+
include Marjoree
|
|
8
|
+
connect('ODBC_DATASOURCE_NAME', 'USERNAME', 'PASSWORD' )
|
|
9
|
+
Kernel.at_exit { disconnect }
|
|
10
|
+
|
|
11
|
+
FileList['**/test_*.rb'].to_a.each do |test_case|
|
|
12
|
+
require test_case
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
CREATE PROCEDURE test_sproc_with_mixed_params
|
|
2
|
+
(
|
|
3
|
+
@input_text varchar(20),
|
|
4
|
+
@output_number int output,
|
|
5
|
+
@input_first_number int,
|
|
6
|
+
@output_text varchar(10) output,
|
|
7
|
+
@input_second_number int
|
|
8
|
+
)
|
|
9
|
+
AS
|
|
10
|
+
BEGIN
|
|
11
|
+
select @output_number = 15
|
|
12
|
+
|
|
13
|
+
select @output_text = 'results'
|
|
14
|
+
END
|
|
15
|
+
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require 'test/unit'
|
|
2
|
+
|
|
3
|
+
class TestContainsMethodOnMarjoree < Test::Unit::TestCase
|
|
4
|
+
include Marjoree
|
|
5
|
+
|
|
6
|
+
def setup
|
|
7
|
+
$db.do( "CREATE TABLE TEST_TABLE( id int NOT NULL, value int NOT NULL )" )
|
|
8
|
+
$db.do( "INSERT INTO TEST_TABLE ( id, value ) VALUES( 0, 10 )" )
|
|
9
|
+
$db.do( "INSERT INTO TEST_TABLE ( id, value ) VALUES( 1, 11 )" )
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def test_contains
|
|
13
|
+
assert( contains?( "TEST_TABLE", :id => 0, :value => 10 ) )
|
|
14
|
+
assert( contains?( "TEST_TABLE", :id => 1, :value => 11 ) )
|
|
15
|
+
assert( contains?( "TEST_TABLE", :id => 1 ) )
|
|
16
|
+
assert( !contains?( "TEST_TABLE", :id => 2, :value => 12 ) )
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def test_contains?_with_bad_column_names
|
|
20
|
+
assert( !contains?( "TEST_TABLE", :wibble => 'wobble' ) )
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def teardown
|
|
24
|
+
$db.do( "TRUNCATE TABLE TEST_TABLE" )
|
|
25
|
+
$db.do( "DROP TABLE TEST_TABLE" )
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
require 'test/unit'
|
|
2
|
+
|
|
3
|
+
class TestDeleteOnMarjoree < Test::Unit::TestCase
|
|
4
|
+
include Marjoree
|
|
5
|
+
|
|
6
|
+
def setup
|
|
7
|
+
$db.do( "CREATE TABLE TEST_TABLE( id int NOT NULL, value int NOT NULL )" )
|
|
8
|
+
$db.do( "INSERT INTO TEST_TABLE ( id, value ) VALUES( 0, 10 )" )
|
|
9
|
+
$db.do( "INSERT INTO TEST_TABLE ( id, value ) VALUES( 1, 11 )" )
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def test_delete
|
|
13
|
+
assert( contains?( "TEST_TABLE", :id => 0, :value => 10 ) )
|
|
14
|
+
|
|
15
|
+
delete( "TEST_TABLE", :id => 0 )
|
|
16
|
+
assert( !contains?( "TEST_TABLE", :id => 0, :value => 10 ) )
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def test_delete_where_table_does_not_exist
|
|
20
|
+
begin
|
|
21
|
+
delete( "DUFF_TABLE", :id => 0 )
|
|
22
|
+
fail
|
|
23
|
+
rescue ODBC::Error
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_delete_where_column_header_does_not_exist
|
|
28
|
+
begin
|
|
29
|
+
delete( "TEST_TABLE", :mince => 0 )
|
|
30
|
+
fail
|
|
31
|
+
rescue ODBC::Error
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def test_delete_where_column_value_is_incorrect_type
|
|
36
|
+
begin
|
|
37
|
+
delete( "TEST_TABLE", :id => 'bad type' )
|
|
38
|
+
fail
|
|
39
|
+
rescue ODBC::Error
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def teardown
|
|
44
|
+
$db.do( "TRUNCATE TABLE TEST_TABLE" )
|
|
45
|
+
$db.do( "DROP TABLE TEST_TABLE" )
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
require 'test/unit'
|
|
2
|
+
|
|
3
|
+
class TestExpectedResultSet < Test::Unit::TestCase
|
|
4
|
+
|
|
5
|
+
def setup
|
|
6
|
+
@testee = ExpectedResultSet.new
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def test_row_hashes_with_one_entry
|
|
10
|
+
@testee.columns = ["firstColumn"]
|
|
11
|
+
@testee.rows << [2]
|
|
12
|
+
|
|
13
|
+
assert_equal( [{"firstColumn"=>2}], @testee.row_hashes )
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def test_columns_are_strings
|
|
17
|
+
@testee.columns = ["firstColumn"]
|
|
18
|
+
assert_equal ['firstColumn'], @testee.columns
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def test_row_hash_with_one_row_and_one_column
|
|
22
|
+
@testee.columns = ["firstColumn"]
|
|
23
|
+
@testee.rows << [2]
|
|
24
|
+
assert_equal( {"firstColumn"=>2}, @testee.row_hash( 0 ) )
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_row_hash_with_one_rows_and_two_columns
|
|
28
|
+
@testee.columns = ["firstColumn", "secondColumn"]
|
|
29
|
+
@testee.rows << [123, 456]
|
|
30
|
+
assert_equal( {"firstColumn"=>123, "secondColumn"=>456}, @testee.row_hash( 0 ) )
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def test_row_hash_with_two_rows_and_two_columns
|
|
34
|
+
@testee.columns = ["firstColumn", "secondColumn"]
|
|
35
|
+
@testee.rows << [123, 234]
|
|
36
|
+
@testee.rows << [345, 567]
|
|
37
|
+
assert_equal( {"firstColumn"=>123, "secondColumn"=>234}, @testee.row_hash( 0 ) )
|
|
38
|
+
assert_equal( {"firstColumn"=>345, "secondColumn"=>567}, @testee.row_hash( 1 ) )
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
require 'test/unit'
|
|
2
|
+
|
|
3
|
+
class TestInsertOnMarjoree < Test::Unit::TestCase
|
|
4
|
+
include Marjoree
|
|
5
|
+
|
|
6
|
+
def setup
|
|
7
|
+
$db.do( "CREATE TABLE TEST_TABLE( id int NOT NULL, value int NOT NULL )" )
|
|
8
|
+
$db.do( "INSERT INTO TEST_TABLE ( id, value ) VALUES( 0, 10 )" )
|
|
9
|
+
$db.do( "INSERT INTO TEST_TABLE ( id, value ) VALUES( 1, 11 )" )
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def test_insert
|
|
13
|
+
assert( !contains?( "TEST_TABLE", :id => 2 ) )
|
|
14
|
+
|
|
15
|
+
insert( "TEST_TABLE", :id => 2, :value => 12 )
|
|
16
|
+
assert( contains?( "TEST_TABLE", :id => 2, :value => 12 ) )
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def test_insert_with_bad_table
|
|
20
|
+
begin
|
|
21
|
+
insert( "TABLE_NOT_INT_DB", :id => 2, :value => 12 )
|
|
22
|
+
fail
|
|
23
|
+
rescue ODBC::Error
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_insert_with_bad_column_names
|
|
28
|
+
begin
|
|
29
|
+
insert( "TEST_TABLE", :fred => 2, :wilma => 12 )
|
|
30
|
+
fail
|
|
31
|
+
rescue ODBC::Error
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def test_insert_with_values_of_incorrect_type
|
|
36
|
+
begin
|
|
37
|
+
insert( "TEST_TABLE", :id => 'text', :value => 12 )
|
|
38
|
+
fail
|
|
39
|
+
rescue ODBC::Error
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def teardown
|
|
44
|
+
$db.do( "TRUNCATE TABLE TEST_TABLE" )
|
|
45
|
+
$db.do( "DROP TABLE TEST_TABLE" )
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
require 'test/unit'
|
|
2
|
+
require 'result_set_wrapper'
|
|
3
|
+
|
|
4
|
+
class TestMarjoree < Test::Unit::TestCase
|
|
5
|
+
include Marjoree
|
|
6
|
+
|
|
7
|
+
def setup
|
|
8
|
+
$db.do( "CREATE TABLE TEST_TABLE( id int NOT NULL, value int NOT NULL )" )
|
|
9
|
+
$db.do( "INSERT INTO TEST_TABLE ( id, value ) VALUES( 0, 10 )" )
|
|
10
|
+
$db.do( "INSERT INTO TEST_TABLE ( id, value ) VALUES( 1, 11 )" )
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def test_select
|
|
14
|
+
result_set = select( "TEST_TABLE" )
|
|
15
|
+
|
|
16
|
+
assert_equal( 2, result_set.count )
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def test_select_with_bad_table
|
|
20
|
+
begin
|
|
21
|
+
resultSet = select( "TABLE_NOT_INT_DB" )
|
|
22
|
+
fail
|
|
23
|
+
rescue ODBC::Error
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_num_rows_for_table
|
|
28
|
+
assert_equal( 2, num_rows( "TEST_TABLE" ) )
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def test_num_rows_with_bad_table
|
|
32
|
+
begin
|
|
33
|
+
num_rows( "TABLE_NOT_INT_DB" )
|
|
34
|
+
fail
|
|
35
|
+
rescue ODBC::Error
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def test_contains?
|
|
40
|
+
assert( contains?( "TEST_TABLE", :id => 0, :value => 10 ) )
|
|
41
|
+
assert( contains?( "TEST_TABLE", :id => 1, :value => 11 ) )
|
|
42
|
+
assert( contains?( "TEST_TABLE", :id => 1 ) )
|
|
43
|
+
assert( !contains?( "TEST_TABLE", :id => 2, :value => 12 ) )
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def test_contains?_with_bad_column_names
|
|
47
|
+
assert( !contains?( "TEST_TABLE", :wibble => 'wobble' ) )
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def test_insert
|
|
51
|
+
assert( !contains?( "TEST_TABLE", :id => 2 ) )
|
|
52
|
+
|
|
53
|
+
insert( "TEST_TABLE", :id => 2, :value => 12 )
|
|
54
|
+
assert( contains?( "TEST_TABLE", :id => 2, :value => 12 ) )
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def test_insert_with_bad_table
|
|
58
|
+
begin
|
|
59
|
+
insert( "TABLE_NOT_INT_DB", :id => 2, :value => 12 )
|
|
60
|
+
fail
|
|
61
|
+
rescue ODBC::Error
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def test_delete
|
|
66
|
+
assert( contains?( "TEST_TABLE", :id => 0, :value => 10 ) )
|
|
67
|
+
|
|
68
|
+
delete( "TEST_TABLE", :id => 0 )
|
|
69
|
+
assert( !contains?( "TEST_TABLE", :id => 0, :value => 10 ) )
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def test_truncate
|
|
73
|
+
assert( num_rows( "TEST_TABLE" ) > 0 )
|
|
74
|
+
|
|
75
|
+
truncate( "TEST_TABLE" )
|
|
76
|
+
assert_equal( 0, num_rows( "TEST_TABLE" ) )
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def test_update
|
|
80
|
+
assert( contains?( "TEST_TABLE", :id => 0, :value => 10 ) )
|
|
81
|
+
|
|
82
|
+
update( "TEST_TABLE", { :id => 0 }, :value => 20 )
|
|
83
|
+
assert( !contains?( "TEST_TABLE", :id => 0, :value => 10 ) )
|
|
84
|
+
assert( contains?( "TEST_TABLE", :id => 0, :value => 20 ) )
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def teardown
|
|
88
|
+
$db.do( "TRUNCATE TABLE TEST_TABLE" )
|
|
89
|
+
$db.do( "DROP TABLE TEST_TABLE" )
|
|
90
|
+
end
|
|
91
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
require 'test/unit'
|
|
2
|
+
|
|
3
|
+
class TestNumRowsOnMarjoree < Test::Unit::TestCase
|
|
4
|
+
include Marjoree
|
|
5
|
+
|
|
6
|
+
def setup
|
|
7
|
+
$db.do( "CREATE TABLE TEST_TABLE( id int NOT NULL, value int NOT NULL )" )
|
|
8
|
+
$db.do( "INSERT INTO TEST_TABLE ( id, value ) VALUES( 0, 10 )" )
|
|
9
|
+
$db.do( "INSERT INTO TEST_TABLE ( id, value ) VALUES( 1, 11 )" )
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def test_num_rows_for_table
|
|
13
|
+
assert_equal( 2, num_rows( "TEST_TABLE" ) )
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def test_num_rows_for_table_using_where
|
|
17
|
+
assert_equal( 1, num_rows( "TEST_TABLE", {:id=>1} ) )
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def test_num_rows_with_bad_table
|
|
21
|
+
begin
|
|
22
|
+
num_rows( "TABLE_NOT_INT_DB" )
|
|
23
|
+
fail
|
|
24
|
+
rescue ODBC::Error
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def teardown
|
|
29
|
+
$db.do( "TRUNCATE TABLE TEST_TABLE" )
|
|
30
|
+
$db.do( "DROP TABLE TEST_TABLE" )
|
|
31
|
+
end
|
|
32
|
+
end
|