ruby-plsql 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +8 -6
- data/History.txt +14 -0
- data/README.md +28 -5
- data/Rakefile +4 -3
- data/VERSION +1 -1
- data/lib/plsql/jdbc_connection.rb +6 -4
- data/lib/plsql/oci_connection.rb +10 -1
- data/lib/plsql/procedure.rb +23 -8
- data/lib/plsql/schema.rb +10 -1
- data/ruby-plsql.gemspec +24 -20
- data/spec/plsql/connection_spec.rb +97 -97
- data/spec/plsql/package_spec.rb +9 -9
- data/spec/plsql/procedure_spec.rb +192 -192
- data/spec/plsql/schema_spec.rb +47 -46
- data/spec/plsql/sequence_spec.rb +7 -7
- data/spec/plsql/sql_statements_spec.rb +10 -10
- data/spec/plsql/table_spec.rb +50 -50
- data/spec/plsql/type_spec.rb +40 -39
- data/spec/plsql/variable_spec.rb +52 -52
- data/spec/plsql/version_spec.rb +1 -1
- data/spec/plsql/view_spec.rb +41 -41
- data/spec/spec_helper.rb +40 -17
- metadata +73 -41
data/spec/plsql/schema_spec.rb
CHANGED
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe "Schema" do
|
4
4
|
|
5
5
|
it "should create Schema object" do
|
6
|
-
plsql.class.
|
6
|
+
expect(plsql.class).to eq(PLSQL::Schema)
|
7
7
|
end
|
8
8
|
|
9
9
|
end
|
@@ -24,28 +24,28 @@ describe "Schema connection" do
|
|
24
24
|
|
25
25
|
it "should connect to test database" do
|
26
26
|
plsql.connection = @conn
|
27
|
-
plsql.connection.raw_connection.
|
27
|
+
expect(plsql.connection.raw_connection).to eq(@conn)
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should connect to test database using connection alias" do
|
31
31
|
plsql(:hr).connection = @conn
|
32
|
-
plsql(:hr).connection.raw_connection.
|
32
|
+
expect(plsql(:hr).connection.raw_connection).to eq(@conn)
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should return schema name" do
|
36
36
|
plsql.connection = @conn
|
37
|
-
plsql.schema_name.
|
37
|
+
expect(plsql.schema_name).to eq(DATABASE_USERS_AND_PASSWORDS[0][0].upcase)
|
38
38
|
end
|
39
39
|
|
40
40
|
it "should return new schema name after reconnection" do
|
41
41
|
plsql.connection = @conn
|
42
|
-
plsql.schema_name.
|
42
|
+
expect(plsql.schema_name).to eq(DATABASE_USERS_AND_PASSWORDS[0][0].upcase)
|
43
43
|
plsql.connection = get_connection(1)
|
44
|
-
plsql.schema_name.
|
44
|
+
expect(plsql.schema_name).to eq(DATABASE_USERS_AND_PASSWORDS[1][0].upcase)
|
45
45
|
end
|
46
46
|
|
47
47
|
it "should return nil schema name if not connected" do
|
48
|
-
plsql(:xxx).schema_name.
|
48
|
+
expect(plsql(:xxx).schema_name).to eq(nil)
|
49
49
|
end
|
50
50
|
|
51
51
|
end
|
@@ -55,6 +55,7 @@ describe "Connection with connect!" do
|
|
55
55
|
before(:all) do
|
56
56
|
@username, @password = DATABASE_USERS_AND_PASSWORDS[0]
|
57
57
|
@database = DATABASE_NAME
|
58
|
+
@database_service = DATABASE_SERVICE_NAME
|
58
59
|
@host = DATABASE_HOST
|
59
60
|
@port = DATABASE_PORT
|
60
61
|
end
|
@@ -65,43 +66,43 @@ describe "Connection with connect!" do
|
|
65
66
|
|
66
67
|
it "should connect with username, password and database alias" do
|
67
68
|
plsql.connect! @username, @password, @database
|
68
|
-
plsql.connection.
|
69
|
-
plsql.schema_name.
|
69
|
+
expect(plsql.connection).not_to be_nil
|
70
|
+
expect(plsql.schema_name).to eq(@username.upcase)
|
70
71
|
end
|
71
72
|
|
72
73
|
it "should connect with username, password, host, port and database name" do
|
73
|
-
plsql.connect! @username, @password, :host => @host, :port => @port, :database => @
|
74
|
-
plsql.connection.
|
75
|
-
plsql.schema_name.
|
74
|
+
plsql.connect! @username, @password, :host => @host, :port => @port, :database => @database_service
|
75
|
+
expect(plsql.connection).not_to be_nil
|
76
|
+
expect(plsql.schema_name).to eq(@username.upcase)
|
76
77
|
end
|
77
78
|
|
78
79
|
it "should connect with username, password, host, database name and default port" do
|
79
|
-
|
80
|
-
plsql.connect! @username, @password, :host => @host, :database => @
|
81
|
-
plsql.connection.
|
82
|
-
plsql.schema_name.
|
80
|
+
skip "Non-default port used for test database" unless @port == 1521
|
81
|
+
plsql.connect! @username, @password, :host => @host, :database => @database_service
|
82
|
+
expect(plsql.connection).not_to be_nil
|
83
|
+
expect(plsql.schema_name).to eq(@username.upcase)
|
83
84
|
end
|
84
85
|
|
85
86
|
it "should not connect with wrong port number" do
|
86
|
-
|
87
|
+
expect {
|
87
88
|
plsql.connect! @username, @password, :host => @host, :port => 9999, :database => @database
|
88
|
-
}.
|
89
|
+
}.to raise_error(/no listener|could not establish the connection/)
|
89
90
|
end
|
90
91
|
|
91
92
|
it "should connect with one Hash parameter" do
|
92
93
|
plsql.connect! :username => @username, :password => @password, :database => @database
|
93
|
-
plsql.connection.
|
94
|
-
plsql.schema_name.
|
94
|
+
expect(plsql.connection).not_to be_nil
|
95
|
+
expect(plsql.schema_name).to eq(@username.upcase)
|
95
96
|
end
|
96
97
|
|
97
98
|
it "should set session time zone from TZ environment variable" do
|
98
99
|
plsql.connect! @username, @password, @database
|
99
|
-
plsql.connection.time_zone.
|
100
|
+
expect(plsql.connection.time_zone).to eq(ENV['TZ'])
|
100
101
|
end
|
101
102
|
|
102
103
|
it "should set session time zone from :time_zone parameter" do
|
103
104
|
plsql.connect! :username => @username, :password => @password, :database => @database, :time_zone => 'EET'
|
104
|
-
plsql.connection.time_zone.
|
105
|
+
expect(plsql.connection.time_zone).to eq('EET')
|
105
106
|
end
|
106
107
|
|
107
108
|
end
|
@@ -116,19 +117,19 @@ describe "Named Schema" do
|
|
116
117
|
end
|
117
118
|
|
118
119
|
it "should find existing schema" do
|
119
|
-
plsql.hr.class.
|
120
|
+
expect(plsql.hr.class).to eq(PLSQL::Schema)
|
120
121
|
end
|
121
122
|
|
122
123
|
it "should have the same connection as default schema" do
|
123
|
-
plsql.hr.connection.raw_connection.
|
124
|
+
expect(plsql.hr.connection.raw_connection).to eq(@conn)
|
124
125
|
end
|
125
126
|
|
126
127
|
it "should return schema name" do
|
127
|
-
plsql.hr.schema_name.
|
128
|
+
expect(plsql.hr.schema_name).to eq('HR')
|
128
129
|
end
|
129
130
|
|
130
131
|
it "should not find named schema if specified twice" do
|
131
|
-
|
132
|
+
expect { plsql.hr.hr }.to raise_error(ArgumentError)
|
132
133
|
end
|
133
134
|
|
134
135
|
end
|
@@ -155,22 +156,22 @@ describe "Schema commit and rollback" do
|
|
155
156
|
it "should do commit" do
|
156
157
|
plsql.test_commit.insert @data
|
157
158
|
plsql.commit
|
158
|
-
plsql.test_commit.first.
|
159
|
+
expect(plsql.test_commit.first).to eq(@data)
|
159
160
|
end
|
160
161
|
|
161
162
|
it "should do rollback" do
|
162
163
|
plsql.test_commit.insert @data
|
163
164
|
plsql.rollback
|
164
|
-
plsql.test_commit.first.
|
165
|
+
expect(plsql.test_commit.first).to be_nil
|
165
166
|
end
|
166
167
|
|
167
168
|
it "should create savepoint and rollback to savepoint" do
|
168
169
|
plsql.test_commit.insert @data
|
169
170
|
plsql.savepoint 'test'
|
170
171
|
plsql.test_commit.insert @data2
|
171
|
-
plsql.test_commit.all.
|
172
|
+
expect(plsql.test_commit.all).to eq([@data, @data2])
|
172
173
|
plsql.rollback_to 'test'
|
173
|
-
plsql.test_commit.all.
|
174
|
+
expect(plsql.test_commit.all).to eq([@data])
|
174
175
|
end
|
175
176
|
|
176
177
|
end
|
@@ -191,33 +192,33 @@ describe "ActiveRecord connection" do
|
|
191
192
|
|
192
193
|
it "should connect to test database" do
|
193
194
|
unless defined?(JRUBY_VERSION)
|
194
|
-
plsql.connection.is_a?(PLSQL::OCIConnection).
|
195
|
+
expect(plsql.connection.is_a?(PLSQL::OCIConnection)).to be_truthy
|
195
196
|
else
|
196
|
-
plsql.connection.is_a?(PLSQL::JDBCConnection).
|
197
|
+
expect(plsql.connection.is_a?(PLSQL::JDBCConnection)).to be_truthy
|
197
198
|
end
|
198
199
|
end
|
199
200
|
|
200
201
|
it "should return schema name" do
|
201
|
-
plsql.schema_name.
|
202
|
+
expect(plsql.schema_name).to eq('HR')
|
202
203
|
end
|
203
204
|
|
204
205
|
it "should use ActiveRecord::Base.default_timezone as default" do
|
205
206
|
ActiveRecord::Base.default_timezone = :utc
|
206
|
-
plsql.default_timezone.
|
207
|
+
expect(plsql.default_timezone).to eq(:utc)
|
207
208
|
end
|
208
209
|
|
209
210
|
it "should have the same connection as default schema" do
|
210
|
-
plsql.hr.connection.
|
211
|
+
expect(plsql.hr.connection).to eq(plsql.connection)
|
211
212
|
end
|
212
213
|
|
213
214
|
it "should accept inherited ActiveRecord class" do
|
214
215
|
plsql.activerecord_class = TestBaseModel
|
215
|
-
plsql.schema_name.
|
216
|
+
expect(plsql.schema_name).to eq('HR')
|
216
217
|
end
|
217
218
|
|
218
219
|
it "should accept subclass of inherited ActiveRecord class" do
|
219
220
|
plsql.activerecord_class = TestModel
|
220
|
-
plsql.schema_name.
|
221
|
+
expect(plsql.schema_name).to eq('HR')
|
221
222
|
end
|
222
223
|
end if defined?(ActiveRecord)
|
223
224
|
|
@@ -268,7 +269,7 @@ describe "DBMS_OUTPUT logging" do
|
|
268
269
|
|
269
270
|
it "should log output to specified stream" do
|
270
271
|
plsql.test_dbms_output("test_dbms_output")
|
271
|
-
@buffer.string.
|
272
|
+
expect(@buffer.string).to eq("DBMS_OUTPUT: test_dbms_output\n")
|
272
273
|
end
|
273
274
|
|
274
275
|
it "should not log output to stream when output is disabled" do
|
@@ -277,32 +278,32 @@ describe "DBMS_OUTPUT logging" do
|
|
277
278
|
plsql.test_dbms_output("disabled")
|
278
279
|
plsql.dbms_output_stream = @buffer
|
279
280
|
plsql.test_dbms_output("enabled again")
|
280
|
-
@buffer.string.
|
281
|
+
expect(@buffer.string).to eq("DBMS_OUTPUT: enabled\nDBMS_OUTPUT: enabled again\n")
|
281
282
|
end
|
282
283
|
|
283
284
|
it "should log 20_000 character output with default buffer size" do
|
284
285
|
times = 2_000
|
285
286
|
plsql.test_dbms_output_large("1234567890", times)
|
286
|
-
@buffer.string.
|
287
|
+
expect(@buffer.string).to eq("DBMS_OUTPUT: 1234567890\n" * times)
|
287
288
|
end
|
288
289
|
|
289
290
|
it "should log 100_000 character output with specified buffer size" do
|
290
291
|
times = 10_000
|
291
292
|
plsql.dbms_output_buffer_size = 10 * times
|
292
293
|
plsql.test_dbms_output_large("1234567890", times)
|
293
|
-
@buffer.string.
|
294
|
+
expect(@buffer.string).to eq("DBMS_OUTPUT: 1234567890\n" * times)
|
294
295
|
end
|
295
296
|
|
296
297
|
it "should log output when database version is less than 10.2" do
|
297
|
-
plsql.connection.
|
298
|
+
allow(plsql.connection).to receive(:database_version).and_return([9, 2, 0, 0])
|
298
299
|
times = 2_000
|
299
300
|
plsql.test_dbms_output_large("1234567890", times)
|
300
|
-
@buffer.string.
|
301
|
+
expect(@buffer.string).to eq("DBMS_OUTPUT: 1234567890\n" * times)
|
301
302
|
end
|
302
303
|
|
303
304
|
it "should log output when calling procedure with schema prefix" do
|
304
305
|
plsql.hr.test_dbms_output("test_dbms_output")
|
305
|
-
@buffer.string.
|
306
|
+
expect(@buffer.string).to eq("DBMS_OUTPUT: test_dbms_output\n")
|
306
307
|
end
|
307
308
|
|
308
309
|
end
|
@@ -317,13 +318,13 @@ describe "DBMS_OUTPUT logging" do
|
|
317
318
|
|
318
319
|
it "should log output to specified stream" do
|
319
320
|
plsql(:ar).test_dbms_output("test_dbms_output")
|
320
|
-
@buffer.string.
|
321
|
+
expect(@buffer.string).to eq("DBMS_OUTPUT: test_dbms_output\n")
|
321
322
|
end
|
322
323
|
|
323
324
|
it "should log output after reconnection" do
|
324
325
|
ActiveRecord::Base.connection.reconnect!
|
325
326
|
plsql(:ar).test_dbms_output("after reconnection")
|
326
|
-
@buffer.string.
|
327
|
+
expect(@buffer.string).to eq("DBMS_OUTPUT: after reconnection\n")
|
327
328
|
end
|
328
329
|
|
329
330
|
end if defined?(ActiveRecord)
|
data/spec/plsql/sequence_spec.rb
CHANGED
@@ -19,15 +19,15 @@ describe "Table" do
|
|
19
19
|
describe "find" do
|
20
20
|
|
21
21
|
it "should find existing sequence" do
|
22
|
-
PLSQL::Sequence.find(plsql, :test_employees_seq).
|
22
|
+
expect(PLSQL::Sequence.find(plsql, :test_employees_seq)).not_to be_nil
|
23
23
|
end
|
24
24
|
|
25
25
|
it "should not find nonexisting table" do
|
26
|
-
PLSQL::Sequence.find(plsql, :qwerty123456).
|
26
|
+
expect(PLSQL::Sequence.find(plsql, :qwerty123456)).to be_nil
|
27
27
|
end
|
28
28
|
|
29
29
|
it "should find existing sequence in schema" do
|
30
|
-
plsql.test_employees_seq.
|
30
|
+
expect(plsql.test_employees_seq).to be_a(PLSQL::Sequence)
|
31
31
|
end
|
32
32
|
|
33
33
|
end
|
@@ -43,11 +43,11 @@ describe "Table" do
|
|
43
43
|
end
|
44
44
|
|
45
45
|
it "should find synonym to sequence" do
|
46
|
-
PLSQL::Sequence.find(plsql, :test_employees_seq_synonym).
|
46
|
+
expect(PLSQL::Sequence.find(plsql, :test_employees_seq_synonym)).not_to be_nil
|
47
47
|
end
|
48
48
|
|
49
49
|
it "should find sequence using synonym in schema" do
|
50
|
-
plsql.test_employees_seq_synonym.
|
50
|
+
expect(plsql.test_employees_seq_synonym).to be_a(PLSQL::Sequence)
|
51
51
|
end
|
52
52
|
|
53
53
|
end
|
@@ -55,12 +55,12 @@ describe "Table" do
|
|
55
55
|
describe "values" do
|
56
56
|
it "should get next value from sequence" do
|
57
57
|
next_value = plsql.select_one "SELECT test_employees_seq.NEXTVAL FROM dual"
|
58
|
-
plsql.test_employees_seq.nextval.
|
58
|
+
expect(plsql.test_employees_seq.nextval).to eq(next_value + 1)
|
59
59
|
end
|
60
60
|
|
61
61
|
it "should get current value from sequence" do
|
62
62
|
next_value = plsql.test_employees_seq.nextval
|
63
|
-
plsql.test_employees_seq.currval.
|
63
|
+
expect(plsql.test_employees_seq.currval).to eq(next_value)
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
@@ -57,33 +57,33 @@ describe "SQL statements /" do
|
|
57
57
|
end
|
58
58
|
|
59
59
|
it "should select first result" do
|
60
|
-
plsql.select(:first, "SELECT * FROM test_employees WHERE employee_id = :employee_id",
|
61
|
-
@employees.first[:employee_id]).
|
60
|
+
expect(plsql.select(:first, "SELECT * FROM test_employees WHERE employee_id = :employee_id",
|
61
|
+
@employees.first[:employee_id])).to eq(@employees.first)
|
62
62
|
end
|
63
63
|
|
64
64
|
it "should prefetch only one row when selecting first result" do
|
65
|
-
|
65
|
+
expect {
|
66
66
|
plsql.select(:first, "SELECT 1 FROM dual UNION ALL SELECT 1/0 FROM dual")
|
67
|
-
}.
|
67
|
+
}.not_to raise_error
|
68
68
|
end
|
69
69
|
|
70
70
|
it "should select one value" do
|
71
|
-
plsql.select_one("SELECT count(*) FROM test_employees").
|
71
|
+
expect(plsql.select_one("SELECT count(*) FROM test_employees")).to eq(@employees.size)
|
72
72
|
end
|
73
73
|
|
74
74
|
it "should return nil when selecting non-existing one value" do
|
75
|
-
plsql.select_one("SELECT employee_id FROM test_employees WHERE 1=2").
|
75
|
+
expect(plsql.select_one("SELECT employee_id FROM test_employees WHERE 1=2")).to be_nil
|
76
76
|
end
|
77
77
|
|
78
78
|
it "should prefetch only one row when selecting one value" do
|
79
|
-
|
79
|
+
expect {
|
80
80
|
plsql.select_one("SELECT 1 FROM dual UNION ALL SELECT 1/0 FROM dual")
|
81
|
-
}.
|
81
|
+
}.not_to raise_error
|
82
82
|
end
|
83
83
|
|
84
84
|
it "should select all results" do
|
85
|
-
plsql.select(:all, "SELECT * FROM test_employees ORDER BY employee_id").
|
86
|
-
plsql.select("SELECT * FROM test_employees ORDER BY employee_id").
|
85
|
+
expect(plsql.select(:all, "SELECT * FROM test_employees ORDER BY employee_id")).to eq(@employees)
|
86
|
+
expect(plsql.select("SELECT * FROM test_employees ORDER BY employee_id")).to eq(@employees)
|
87
87
|
end
|
88
88
|
|
89
89
|
end
|
data/spec/plsql/table_spec.rb
CHANGED
@@ -85,15 +85,15 @@ describe "Table" do
|
|
85
85
|
describe "find" do
|
86
86
|
|
87
87
|
it "should find existing table" do
|
88
|
-
PLSQL::Table.find(plsql, :test_employees).
|
88
|
+
expect(PLSQL::Table.find(plsql, :test_employees)).not_to be_nil
|
89
89
|
end
|
90
90
|
|
91
91
|
it "should not find nonexisting table" do
|
92
|
-
PLSQL::Table.find(plsql, :qwerty123456).
|
92
|
+
expect(PLSQL::Table.find(plsql, :qwerty123456)).to be_nil
|
93
93
|
end
|
94
94
|
|
95
95
|
it "should find existing table in schema" do
|
96
|
-
plsql.test_employees.
|
96
|
+
expect(plsql.test_employees).to be_a(PLSQL::Table)
|
97
97
|
end
|
98
98
|
|
99
99
|
end
|
@@ -109,11 +109,11 @@ describe "Table" do
|
|
109
109
|
end
|
110
110
|
|
111
111
|
it "should find synonym to table" do
|
112
|
-
PLSQL::Table.find(plsql, :test_employees_synonym).
|
112
|
+
expect(PLSQL::Table.find(plsql, :test_employees_synonym)).not_to be_nil
|
113
113
|
end
|
114
114
|
|
115
115
|
it "should find table using synonym in schema" do
|
116
|
-
plsql.test_employees_synonym.
|
116
|
+
expect(plsql.test_employees_synonym).to be_a(PLSQL::Table)
|
117
117
|
end
|
118
118
|
|
119
119
|
end
|
@@ -121,11 +121,11 @@ describe "Table" do
|
|
121
121
|
describe "public synonym" do
|
122
122
|
|
123
123
|
it "should find public synonym to table" do
|
124
|
-
PLSQL::Table.find(plsql, :dual).
|
124
|
+
expect(PLSQL::Table.find(plsql, :dual)).not_to be_nil
|
125
125
|
end
|
126
126
|
|
127
127
|
it "should find table using public synonym in schema" do
|
128
|
-
plsql.dual.
|
128
|
+
expect(plsql.dual).to be_a(PLSQL::Table)
|
129
129
|
end
|
130
130
|
|
131
131
|
end
|
@@ -133,11 +133,11 @@ describe "Table" do
|
|
133
133
|
describe "columns" do
|
134
134
|
|
135
135
|
it "should get column names for table" do
|
136
|
-
plsql.test_employees.column_names.
|
136
|
+
expect(plsql.test_employees.column_names).to eq(@employees_all_fields)
|
137
137
|
end
|
138
138
|
|
139
139
|
it "should get columns metadata for table" do
|
140
|
-
plsql.test_employees.columns.
|
140
|
+
expect(plsql.test_employees.columns).to eq({
|
141
141
|
:employee_id => {
|
142
142
|
:position=>1, :data_type=>"NUMBER", :data_length=>22, :data_precision=>15, :data_scale=>0, :char_used=>nil,
|
143
143
|
:type_owner=>nil, :type_name=>nil, :sql_type_name=>nil, :nullable => false, :data_default => nil},
|
@@ -156,11 +156,11 @@ describe "Table" do
|
|
156
156
|
:status => {
|
157
157
|
:position=>6, :data_type=>"VARCHAR2", :data_length=>1, :data_precision=>nil, :data_scale=>nil, :char_used=>"B",
|
158
158
|
:type_owner=>nil, :type_name=>nil, :sql_type_name=>nil, :nullable => true, :data_default => "'N'"}
|
159
|
-
}
|
159
|
+
})
|
160
160
|
end
|
161
161
|
|
162
162
|
it "should get columns metadata for table with object columns" do
|
163
|
-
plsql.test_employees2.columns.
|
163
|
+
expect(plsql.test_employees2.columns).to eq({
|
164
164
|
:employee_id => {
|
165
165
|
:position=>1, :data_type=>"NUMBER", :data_length=>22, :data_precision=>15, :data_scale=>0, :char_used=>nil,
|
166
166
|
:type_owner=>nil, :type_name=>nil, :sql_type_name=>nil, :nullable => false, :data_default => nil},
|
@@ -179,7 +179,7 @@ describe "Table" do
|
|
179
179
|
:phones => {
|
180
180
|
:position=>6, :data_type=>"TABLE", :data_length=>nil, :data_precision=>nil, :data_scale=>nil, :char_used=>nil,
|
181
181
|
:type_owner=>"HR", :type_name=>"T_PHONES", :sql_type_name=>"HR.T_PHONES", :nullable => true, :data_default => nil}
|
182
|
-
}
|
182
|
+
})
|
183
183
|
end
|
184
184
|
|
185
185
|
end
|
@@ -187,32 +187,32 @@ describe "Table" do
|
|
187
187
|
describe "insert" do
|
188
188
|
it "should insert a record in table" do
|
189
189
|
plsql.test_employees.insert @employees.first
|
190
|
-
plsql.test_employees.all.
|
190
|
+
expect(plsql.test_employees.all).to eq([@employees.first])
|
191
191
|
end
|
192
192
|
|
193
193
|
it "should insert a record in table using partial list of columns" do
|
194
194
|
plsql.test_employees.insert @employees.first.except(:hire_date)
|
195
|
-
plsql.test_employees.all.
|
195
|
+
expect(plsql.test_employees.all).to eq([@employees.first.merge(:hire_date => nil)])
|
196
196
|
end
|
197
197
|
|
198
198
|
it "should insert default value from table definition if value not provided" do
|
199
199
|
plsql.test_employees.insert @employees.first.except(:status)
|
200
|
-
plsql.test_employees.all.
|
200
|
+
expect(plsql.test_employees.all).to eq([@employees.first.merge(:status => 'N')])
|
201
201
|
end
|
202
202
|
|
203
203
|
it "should insert array of records in table" do
|
204
204
|
plsql.test_employees.insert @employees
|
205
|
-
plsql.test_employees.all("ORDER BY employee_id").
|
205
|
+
expect(plsql.test_employees.all("ORDER BY employee_id")).to eq(@employees)
|
206
206
|
end
|
207
207
|
|
208
208
|
it "should insert a record in table with object types" do
|
209
209
|
plsql.test_employees2.insert @employees2.first
|
210
|
-
plsql.test_employees2.all.
|
210
|
+
expect(plsql.test_employees2.all).to eq([@employees2.first])
|
211
211
|
end
|
212
212
|
|
213
213
|
it "should insert array of records in table with object types" do
|
214
214
|
plsql.test_employees2.insert @employees2
|
215
|
-
plsql.test_employees2.all("ORDER BY employee_id").
|
215
|
+
expect(plsql.test_employees2.all("ORDER BY employee_id")).to eq(@employees2)
|
216
216
|
end
|
217
217
|
|
218
218
|
end
|
@@ -220,32 +220,32 @@ describe "Table" do
|
|
220
220
|
describe "insert values" do
|
221
221
|
it "should insert a record with array of values" do
|
222
222
|
plsql.test_employees.insert_values @employees_all_values.first
|
223
|
-
plsql.test_employees.all.
|
223
|
+
expect(plsql.test_employees.all).to eq([@employees.first])
|
224
224
|
end
|
225
225
|
|
226
226
|
it "should insert a record with list of all fields and array of values" do
|
227
227
|
plsql.test_employees.insert_values @employees_all_fields, @employees_all_values.first
|
228
|
-
plsql.test_employees.all.
|
228
|
+
expect(plsql.test_employees.all).to eq([@employees.first])
|
229
229
|
end
|
230
230
|
|
231
231
|
it "should insert a record with list of some fields and array of values" do
|
232
232
|
plsql.test_employees.insert_values @employees_some_fields, @employees_some_values.first
|
233
|
-
plsql.test_employees.all.
|
233
|
+
expect(plsql.test_employees.all).to eq([@employees.first.merge(@employee_default_values)])
|
234
234
|
end
|
235
235
|
|
236
236
|
it "should insert many records with array of values" do
|
237
237
|
plsql.test_employees.insert_values *@employees_all_values
|
238
|
-
plsql.test_employees.all.
|
238
|
+
expect(plsql.test_employees.all).to eq(@employees)
|
239
239
|
end
|
240
240
|
|
241
241
|
it "should insert many records with list of all fields and array of values" do
|
242
242
|
plsql.test_employees.insert_values @employees_all_fields, *@employees_all_values
|
243
|
-
plsql.test_employees.all.
|
243
|
+
expect(plsql.test_employees.all).to eq(@employees)
|
244
244
|
end
|
245
245
|
|
246
246
|
it "should insert many records with list of some fields and array of values" do
|
247
247
|
plsql.test_employees.insert_values @employees_some_fields, *@employees_some_values
|
248
|
-
plsql.test_employees.all.
|
248
|
+
expect(plsql.test_employees.all).to eq(@employees.map{|e| e.merge(@employee_default_values)})
|
249
249
|
end
|
250
250
|
|
251
251
|
end
|
@@ -256,24 +256,24 @@ describe "Table" do
|
|
256
256
|
end
|
257
257
|
|
258
258
|
it "should select first record in table" do
|
259
|
-
plsql.test_employees.select(:first, "ORDER BY employee_id").
|
260
|
-
plsql.test_employees.first("ORDER BY employee_id").
|
259
|
+
expect(plsql.test_employees.select(:first, "ORDER BY employee_id")).to eq(@employees.first)
|
260
|
+
expect(plsql.test_employees.first("ORDER BY employee_id")).to eq(@employees.first)
|
261
261
|
end
|
262
262
|
|
263
263
|
it "should select all records in table" do
|
264
|
-
plsql.test_employees.select(:all, "ORDER BY employee_id").
|
265
|
-
plsql.test_employees.all("ORDER BY employee_id").
|
266
|
-
plsql.test_employees.all(:order_by => :employee_id).
|
264
|
+
expect(plsql.test_employees.select(:all, "ORDER BY employee_id")).to eq(@employees)
|
265
|
+
expect(plsql.test_employees.all("ORDER BY employee_id")).to eq(@employees)
|
266
|
+
expect(plsql.test_employees.all(:order_by => :employee_id)).to eq(@employees)
|
267
267
|
end
|
268
268
|
|
269
269
|
it "should select record in table using WHERE condition" do
|
270
|
-
plsql.test_employees.select(:first, "WHERE employee_id = :1", @employees.first[:employee_id]).
|
271
|
-
plsql.test_employees.first("WHERE employee_id = :1", @employees.first[:employee_id]).
|
272
|
-
plsql.test_employees.first(:employee_id => @employees.first[:employee_id]).
|
270
|
+
expect(plsql.test_employees.select(:first, "WHERE employee_id = :1", @employees.first[:employee_id])).to eq(@employees.first)
|
271
|
+
expect(plsql.test_employees.first("WHERE employee_id = :1", @employees.first[:employee_id])).to eq(@employees.first)
|
272
|
+
expect(plsql.test_employees.first(:employee_id => @employees.first[:employee_id])).to eq(@employees.first)
|
273
273
|
end
|
274
274
|
|
275
275
|
it "should select records in table using WHERE condition and ORDER BY sorting" do
|
276
|
-
plsql.test_employees.all(:employee_id => @employees.first[:employee_id], :order_by => :employee_id).
|
276
|
+
expect(plsql.test_employees.all(:employee_id => @employees.first[:employee_id], :order_by => :employee_id)).to eq([@employees.first])
|
277
277
|
end
|
278
278
|
|
279
279
|
it "should select record in table using :column => nil condition" do
|
@@ -281,8 +281,8 @@ describe "Table" do
|
|
281
281
|
employee[:employee_id] = employee[:employee_id] + 1
|
282
282
|
employee[:hire_date] = nil
|
283
283
|
plsql.test_employees.insert employee
|
284
|
-
plsql.test_employees.first("WHERE hire_date IS NULL").
|
285
|
-
plsql.test_employees.first(:hire_date => nil).
|
284
|
+
expect(plsql.test_employees.first("WHERE hire_date IS NULL")).to eq(employee)
|
285
|
+
expect(plsql.test_employees.first(:hire_date => nil)).to eq(employee)
|
286
286
|
end
|
287
287
|
|
288
288
|
it "should select record in table using :column => :is_null condition" do
|
@@ -290,7 +290,7 @@ describe "Table" do
|
|
290
290
|
employee[:employee_id] = employee[:employee_id] + 1
|
291
291
|
employee[:hire_date] = nil
|
292
292
|
plsql.test_employees.insert employee
|
293
|
-
plsql.test_employees.first(:hire_date => :is_null).
|
293
|
+
expect(plsql.test_employees.first(:hire_date => :is_null)).to eq(employee)
|
294
294
|
end
|
295
295
|
|
296
296
|
it "should select record in table using :column => :is_not_null condition" do
|
@@ -298,17 +298,17 @@ describe "Table" do
|
|
298
298
|
employee[:employee_id] = employee[:employee_id] + 1
|
299
299
|
employee[:hire_date] = nil
|
300
300
|
plsql.test_employees.insert employee
|
301
|
-
plsql.test_employees.all(:hire_date => :is_not_null, :order_by => :employee_id).
|
301
|
+
expect(plsql.test_employees.all(:hire_date => :is_not_null, :order_by => :employee_id)).to eq(@employees)
|
302
302
|
end
|
303
303
|
|
304
304
|
it "should count records in table" do
|
305
|
-
plsql.test_employees.select(:count).
|
306
|
-
plsql.test_employees.count.
|
305
|
+
expect(plsql.test_employees.select(:count)).to eq(@employees.size)
|
306
|
+
expect(plsql.test_employees.count).to eq(@employees.size)
|
307
307
|
end
|
308
308
|
|
309
309
|
it "should count records in table using condition" do
|
310
|
-
plsql.test_employees.select(:count, "WHERE employee_id <= :1", @employees[2][:employee_id]).
|
311
|
-
plsql.test_employees.count("WHERE employee_id <= :1", @employees[2][:employee_id]).
|
310
|
+
expect(plsql.test_employees.select(:count, "WHERE employee_id <= :1", @employees[2][:employee_id])).to eq(3)
|
311
|
+
expect(plsql.test_employees.count("WHERE employee_id <= :1", @employees[2][:employee_id])).to eq(3)
|
312
312
|
end
|
313
313
|
|
314
314
|
end
|
@@ -318,17 +318,17 @@ describe "Table" do
|
|
318
318
|
employee_id = @employees.first[:employee_id]
|
319
319
|
plsql.test_employees.insert @employees.first
|
320
320
|
plsql.test_employees.update :first_name => 'Test', :where => {:employee_id => employee_id}
|
321
|
-
plsql.test_employees.first(:employee_id => employee_id)[:first_name].
|
321
|
+
expect(plsql.test_employees.first(:employee_id => employee_id)[:first_name]).to eq('Test')
|
322
322
|
end
|
323
323
|
|
324
324
|
it "should update a record in table using String WHERE condition" do
|
325
325
|
employee_id = @employees.first[:employee_id]
|
326
326
|
plsql.test_employees.insert @employees
|
327
327
|
plsql.test_employees.update :first_name => 'Test', :where => "employee_id = #{employee_id}"
|
328
|
-
plsql.test_employees.first(:employee_id => employee_id)[:first_name].
|
328
|
+
expect(plsql.test_employees.first(:employee_id => employee_id)[:first_name]).to eq('Test')
|
329
329
|
# all other records should not be changed
|
330
330
|
plsql.test_employees.all("WHERE employee_id > :1", employee_id) do |employee|
|
331
|
-
employee[:first_name].
|
331
|
+
expect(employee[:first_name]).not_to eq('Test')
|
332
332
|
end
|
333
333
|
end
|
334
334
|
|
@@ -336,7 +336,7 @@ describe "Table" do
|
|
336
336
|
plsql.test_employees.insert @employees
|
337
337
|
plsql.test_employees.update :first_name => 'Test'
|
338
338
|
plsql.test_employees.all do |employee|
|
339
|
-
employee[:first_name].
|
339
|
+
expect(employee[:first_name]).to eq('Test')
|
340
340
|
end
|
341
341
|
end
|
342
342
|
|
@@ -346,8 +346,8 @@ describe "Table" do
|
|
346
346
|
plsql.test_employees2.insert employee
|
347
347
|
plsql.test_employees2.update :address => employee2[:address], :phones => employee2[:phones], :where => {:employee_id => employee[:employee_id]}
|
348
348
|
updated_employee = plsql.test_employees2.first(:employee_id => employee[:employee_id])
|
349
|
-
updated_employee[:address].
|
350
|
-
updated_employee[:phones].
|
349
|
+
expect(updated_employee[:address]).to eq(employee2[:address])
|
350
|
+
expect(updated_employee[:phones]).to eq(employee2[:phones])
|
351
351
|
end
|
352
352
|
|
353
353
|
end
|
@@ -357,14 +357,14 @@ describe "Table" do
|
|
357
357
|
employee_id = @employees.first[:employee_id]
|
358
358
|
plsql.test_employees.insert @employees
|
359
359
|
plsql.test_employees.delete :employee_id => employee_id
|
360
|
-
plsql.test_employees.first(:employee_id => employee_id).
|
361
|
-
plsql.test_employees.all(:order_by => :employee_id).
|
360
|
+
expect(plsql.test_employees.first(:employee_id => employee_id)).to be_nil
|
361
|
+
expect(plsql.test_employees.all(:order_by => :employee_id)).to eq(@employees[1, @employees.size-1])
|
362
362
|
end
|
363
363
|
|
364
364
|
it "should delete all records from table" do
|
365
365
|
plsql.test_employees.insert @employees
|
366
366
|
plsql.test_employees.delete
|
367
|
-
plsql.test_employees.all.
|
367
|
+
expect(plsql.test_employees.all).to be_empty
|
368
368
|
end
|
369
369
|
end
|
370
370
|
|