ruby-plsql 0.8.0 → 0.9.0

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.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/History.txt +2 -0
  3. data/VERSION +1 -1
  4. data/lib/plsql/connection.rb +14 -14
  5. data/lib/plsql/helpers.rb +3 -3
  6. data/lib/plsql/jdbc_connection.rb +3 -3
  7. data/lib/plsql/oci_connection.rb +8 -4
  8. data/lib/plsql/package.rb +3 -3
  9. data/lib/plsql/procedure.rb +32 -17
  10. data/lib/plsql/procedure_call.rb +15 -15
  11. data/lib/plsql/schema.rb +13 -9
  12. data/lib/plsql/sequence.rb +2 -2
  13. data/lib/plsql/table.rb +6 -6
  14. data/lib/plsql/type.rb +7 -7
  15. data/lib/plsql/variable.rb +4 -4
  16. data/lib/plsql/version.rb +1 -1
  17. data/lib/plsql/view.rb +2 -2
  18. metadata +13 -138
  19. data/.github/stale.yml +0 -37
  20. data/.github/workflows/rubocop.yml +0 -37
  21. data/.github/workflows/test.yml +0 -69
  22. data/.rubocop.yml +0 -147
  23. data/.travis/oracle/download.sh +0 -15
  24. data/.travis/oracle/install.sh +0 -32
  25. data/.travis/setup_accounts.sh +0 -9
  26. data/.travis.yml +0 -88
  27. data/Gemfile +0 -24
  28. data/Rakefile +0 -53
  29. data/Vagrantfile +0 -38
  30. data/ci/network/admin/tnsnames.ora +0 -7
  31. data/ci/setup_accounts.sh +0 -9
  32. data/gemfiles/Gemfile.activerecord-5.0 +0 -21
  33. data/gemfiles/Gemfile.activerecord-5.1 +0 -21
  34. data/gemfiles/Gemfile.activerecord-5.2 +0 -21
  35. data/gemfiles/Gemfile.activerecord-6.0 +0 -21
  36. data/gemfiles/Gemfile.activerecord-6.1 +0 -21
  37. data/gemfiles/Gemfile.activerecord-main +0 -21
  38. data/ruby-plsql.gemspec +0 -114
  39. data/spec/plsql/connection_spec.rb +0 -505
  40. data/spec/plsql/package_spec.rb +0 -172
  41. data/spec/plsql/procedure_spec.rb +0 -2390
  42. data/spec/plsql/schema_spec.rb +0 -364
  43. data/spec/plsql/sequence_spec.rb +0 -67
  44. data/spec/plsql/sql_statements_spec.rb +0 -91
  45. data/spec/plsql/table_spec.rb +0 -376
  46. data/spec/plsql/type_spec.rb +0 -299
  47. data/spec/plsql/variable_spec.rb +0 -497
  48. data/spec/plsql/version_spec.rb +0 -8
  49. data/spec/plsql/view_spec.rb +0 -264
  50. data/spec/spec.opts +0 -6
  51. data/spec/spec_helper.rb +0 -121
  52. data/spec/support/create_arunit_user.sql +0 -2
  53. data/spec/support/custom_config.rb.sample +0 -14
  54. data/spec/support/file_check_script.sh +0 -9
  55. data/spec/support/test_db.rb +0 -149
  56. data/spec/support/unlock_and_setup_hr_user.sql +0 -2
@@ -1,376 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe "Table" do
4
- before(:all) do
5
- plsql.connect! CONNECTION_PARAMS
6
- plsql.connection.autocommit = false
7
- plsql.execute <<-SQL
8
- CREATE TABLE test_employees (
9
- employee_id NUMBER(15) NOT NULL,
10
- first_name VARCHAR2(50),
11
- last_name VARCHAR(50),
12
- hire_date DATE,
13
- created_at TIMESTAMP,
14
- status VARCHAR2(1) DEFAULT 'N'
15
- )
16
- SQL
17
-
18
- plsql.execute <<-SQL
19
- CREATE OR REPLACE TYPE t_address AS OBJECT (
20
- street VARCHAR2(50),
21
- city VARCHAR2(50),
22
- country VARCHAR2(50)
23
- )
24
- SQL
25
- plsql.execute <<-SQL
26
- CREATE OR REPLACE TYPE t_phone AS OBJECT (
27
- type VARCHAR2(10),
28
- phone_number VARCHAR2(50)
29
- )
30
- SQL
31
- plsql.execute <<-SQL
32
- CREATE OR REPLACE TYPE t_phones AS VARRAY(10) OF T_PHONE
33
- SQL
34
- plsql.execute <<-SQL
35
- CREATE TABLE test_employees2 (
36
- employee_id NUMBER(15) NOT NULL,
37
- first_name VARCHAR2(50),
38
- last_name VARCHAR(50),
39
- hire_date DATE DEFAULT SYSDATE,
40
- address t_address,
41
- phones t_phones
42
- )
43
- SQL
44
- @employees = (1..10).map do |i|
45
- {
46
- employee_id: i,
47
- first_name: "First #{i}",
48
- last_name: "Last #{i}",
49
- hire_date: Time.local(2000, 01, i),
50
- created_at: Time.local(2000, 01, i, 9, 15, 30, i),
51
- status: "A"
52
- }
53
- end
54
- @employees_all_fields = [:employee_id, :first_name, :last_name, :hire_date, :created_at, :status]
55
- @employees_all_values = @employees.map { |e| @employees_all_fields.map { |f| e[f] } }
56
- @employees_some_fields = [:employee_id, :first_name, :last_name]
57
- @employees_some_values = @employees.map { |e| @employees_some_fields.map { |f| e[f] } }
58
- @employee_default_values = { hire_date: nil, created_at: nil, status: "N" }
59
-
60
- @employees2 = (1..10).map do |i|
61
- {
62
- employee_id: i,
63
- first_name: "First #{i}",
64
- last_name: "Last #{i}",
65
- hire_date: Time.local(2000, 01, i),
66
- address: { street: "Street #{i}", city: "City #{i}", country: "County #{i}" },
67
- phones: [{ type: "mobile", phone_number: "Mobile#{i}" }, { type: "fixed", phone_number: "Fixed#{i}" }]
68
- }
69
- end
70
- end
71
-
72
- after(:all) do
73
- plsql.execute "DROP TABLE test_employees"
74
- plsql.execute "DROP TABLE test_employees2"
75
- plsql.execute "DROP TYPE t_phones"
76
- plsql.execute "DROP TYPE t_phone"
77
- plsql.execute "DROP TYPE t_address"
78
- plsql.logoff
79
- end
80
-
81
- after(:each) do
82
- plsql.rollback
83
- end
84
-
85
- describe "find" do
86
-
87
- it "should find existing table" do
88
- expect(PLSQL::Table.find(plsql, :test_employees)).not_to be_nil
89
- end
90
-
91
- it "should not find nonexisting table" do
92
- expect(PLSQL::Table.find(plsql, :qwerty123456)).to be_nil
93
- end
94
-
95
- it "should find existing table in schema" do
96
- expect(plsql.test_employees).to be_a(PLSQL::Table)
97
- end
98
-
99
- end
100
-
101
- describe "synonym" do
102
-
103
- before(:all) do
104
- plsql.execute "CREATE SYNONYM test_employees_synonym FOR hr.test_employees"
105
- end
106
-
107
- after(:all) do
108
- plsql.execute "DROP SYNONYM test_employees_synonym" rescue nil
109
- end
110
-
111
- it "should find synonym to table" do
112
- expect(PLSQL::Table.find(plsql, :test_employees_synonym)).not_to be_nil
113
- end
114
-
115
- it "should find table using synonym in schema" do
116
- expect(plsql.test_employees_synonym).to be_a(PLSQL::Table)
117
- end
118
-
119
- end
120
-
121
- describe "public synonym" do
122
-
123
- it "should find public synonym to table" do
124
- expect(PLSQL::Table.find(plsql, :dual)).not_to be_nil
125
- end
126
-
127
- it "should find table using public synonym in schema" do
128
- expect(plsql.dual).to be_a(PLSQL::Table)
129
- end
130
-
131
- end
132
-
133
- describe "columns" do
134
-
135
- it "should get column names for table" do
136
- expect(plsql.test_employees.column_names).to eq(@employees_all_fields)
137
- end
138
-
139
- it "should get columns metadata for table" do
140
- expect(plsql.test_employees.columns).to eq(
141
- employee_id: {
142
- position: 1, data_type: "NUMBER", data_length: 22, data_precision: 15, data_scale: 0, char_used: nil,
143
- type_owner: nil, type_name: nil, sql_type_name: nil, nullable: false, data_default: nil },
144
- first_name: {
145
- position: 2, data_type: "VARCHAR2", data_length: 50, data_precision: nil, data_scale: nil, char_used: "B",
146
- type_owner: nil, type_name: nil, sql_type_name: nil, nullable: true, data_default: nil },
147
- last_name: {
148
- position: 3, data_type: "VARCHAR2", data_length: 50, data_precision: nil, data_scale: nil, char_used: "B",
149
- type_owner: nil, type_name: nil, sql_type_name: nil, nullable: true, data_default: nil },
150
- hire_date: {
151
- position: 4, data_type: "DATE", data_length: 7, data_precision: nil, data_scale: nil, char_used: nil,
152
- type_owner: nil, type_name: nil, sql_type_name: nil, nullable: true, data_default: nil },
153
- created_at: {
154
- position: 5, data_type: "TIMESTAMP", data_length: 11, data_precision: nil, data_scale: 6, char_used: nil,
155
- type_owner: nil, type_name: nil, sql_type_name: nil, nullable: true, data_default: nil },
156
- status: {
157
- position: 6, data_type: "VARCHAR2", data_length: 1, data_precision: nil, data_scale: nil, char_used: "B",
158
- type_owner: nil, type_name: nil, sql_type_name: nil, nullable: true, data_default: "'N'" }
159
- )
160
- end
161
-
162
- it "should get columns metadata for table with object columns" do
163
- expect(plsql.test_employees2.columns).to eq(
164
- employee_id: {
165
- position: 1, data_type: "NUMBER", data_length: 22, data_precision: 15, data_scale: 0, char_used: nil,
166
- type_owner: nil, type_name: nil, sql_type_name: nil, nullable: false, data_default: nil },
167
- first_name: {
168
- position: 2, data_type: "VARCHAR2", data_length: 50, data_precision: nil, data_scale: nil, char_used: "B",
169
- type_owner: nil, type_name: nil, sql_type_name: nil, nullable: true, data_default: nil },
170
- last_name: {
171
- position: 3, data_type: "VARCHAR2", data_length: 50, data_precision: nil, data_scale: nil, char_used: "B",
172
- type_owner: nil, type_name: nil, sql_type_name: nil, nullable: true, data_default: nil },
173
- hire_date: {
174
- position: 4, data_type: "DATE", data_length: 7, data_precision: nil, data_scale: nil, char_used: nil,
175
- type_owner: nil, type_name: nil, sql_type_name: nil, nullable: true, data_default: "SYSDATE" },
176
- address: {
177
- position: 5, data_type: "OBJECT", data_length: nil, data_precision: nil, data_scale: nil,
178
- char_used: nil, type_owner: "HR", type_name: "T_ADDRESS", sql_type_name: "HR.T_ADDRESS", nullable: true, data_default: nil },
179
- phones: {
180
- position: 6, data_type: "TABLE", data_length: nil, data_precision: nil, data_scale: nil, char_used: nil,
181
- type_owner: "HR", type_name: "T_PHONES", sql_type_name: "HR.T_PHONES", nullable: true, data_default: nil }
182
- )
183
- end
184
-
185
- end
186
-
187
- describe "insert" do
188
- it "should insert a record in table" do
189
- plsql.test_employees.insert @employees.first
190
- expect(plsql.test_employees.all).to eq([@employees.first])
191
- end
192
-
193
- it "should insert a record in table using partial list of columns" do
194
- plsql.test_employees.insert @employees.first.except(:hire_date)
195
- expect(plsql.test_employees.all).to eq([@employees.first.merge(hire_date: nil)])
196
- end
197
-
198
- it "should insert default value from table definition if value not provided" do
199
- plsql.test_employees.insert @employees.first.except(:status)
200
- expect(plsql.test_employees.all).to eq([@employees.first.merge(status: "N")])
201
- end
202
-
203
- it "should insert array of records in table" do
204
- plsql.test_employees.insert @employees
205
- expect(plsql.test_employees.all("ORDER BY employee_id")).to eq(@employees)
206
- end
207
-
208
- it "should insert a record in table with object types" do
209
- plsql.test_employees2.insert @employees2.first
210
- expect(plsql.test_employees2.all).to eq([@employees2.first])
211
- end
212
-
213
- it "should insert array of records in table with object types" do
214
- plsql.test_employees2.insert @employees2
215
- expect(plsql.test_employees2.all("ORDER BY employee_id")).to eq(@employees2)
216
- end
217
-
218
- it "should insert with case-insensetive table name" do
219
- plsql.test_employees.insert @employees.first.map { |k, v| [k.upcase.to_sym, v] }.to_h
220
- expect(plsql.test_employees.all).to eq([@employees.first])
221
- end
222
-
223
- end
224
-
225
- describe "insert values" do
226
- it "should insert a record with array of values" do
227
- plsql.test_employees.insert_values @employees_all_values.first
228
- expect(plsql.test_employees.all).to eq([@employees.first])
229
- end
230
-
231
- it "should insert a record with list of all fields and array of values" do
232
- plsql.test_employees.insert_values @employees_all_fields, @employees_all_values.first
233
- expect(plsql.test_employees.all).to eq([@employees.first])
234
- end
235
-
236
- it "should insert a record with list of some fields and array of values" do
237
- plsql.test_employees.insert_values @employees_some_fields, @employees_some_values.first
238
- expect(plsql.test_employees.all).to eq([@employees.first.merge(@employee_default_values)])
239
- end
240
-
241
- it "should insert many records with array of values" do
242
- plsql.test_employees.insert_values *@employees_all_values
243
- expect(plsql.test_employees.all).to eq(@employees)
244
- end
245
-
246
- it "should insert many records with list of all fields and array of values" do
247
- plsql.test_employees.insert_values @employees_all_fields, *@employees_all_values
248
- expect(plsql.test_employees.all).to eq(@employees)
249
- end
250
-
251
- it "should insert many records with list of some fields and array of values" do
252
- plsql.test_employees.insert_values @employees_some_fields, *@employees_some_values
253
- expect(plsql.test_employees.all).to eq(@employees.map { |e| e.merge(@employee_default_values) })
254
- end
255
-
256
- end
257
-
258
- describe "select" do
259
- before(:each) do
260
- plsql.test_employees.insert @employees
261
- end
262
-
263
- it "should select first record in table" do
264
- expect(plsql.test_employees.select(:first, "ORDER BY employee_id")).to eq(@employees.first)
265
- expect(plsql.test_employees.first("ORDER BY employee_id")).to eq(@employees.first)
266
- end
267
-
268
- it "should select all records in table" do
269
- expect(plsql.test_employees.select(:all, "ORDER BY employee_id")).to eq(@employees)
270
- expect(plsql.test_employees.all("ORDER BY employee_id")).to eq(@employees)
271
- expect(plsql.test_employees.all(order_by: :employee_id)).to eq(@employees)
272
- end
273
-
274
- it "should select record in table using WHERE condition" do
275
- expect(plsql.test_employees.select(:first, "WHERE employee_id = :1", @employees.first[:employee_id])).to eq(@employees.first)
276
- expect(plsql.test_employees.first("WHERE employee_id = :1", @employees.first[:employee_id])).to eq(@employees.first)
277
- expect(plsql.test_employees.first(employee_id: @employees.first[:employee_id])).to eq(@employees.first)
278
- end
279
-
280
- it "should select records in table using WHERE condition and ORDER BY sorting" do
281
- expect(plsql.test_employees.all(employee_id: @employees.first[:employee_id], order_by: :employee_id)).to eq([@employees.first])
282
- end
283
-
284
- it "should select record in table using :column => nil condition" do
285
- employee = @employees.last.dup
286
- employee[:employee_id] = employee[:employee_id] + 1
287
- employee[:hire_date] = nil
288
- plsql.test_employees.insert employee
289
- expect(plsql.test_employees.first("WHERE hire_date IS NULL")).to eq(employee)
290
- expect(plsql.test_employees.first(hire_date: nil)).to eq(employee)
291
- end
292
-
293
- it "should select record in table using :column => :is_null condition" do
294
- employee = @employees.last.dup
295
- employee[:employee_id] = employee[:employee_id] + 1
296
- employee[:hire_date] = nil
297
- plsql.test_employees.insert employee
298
- expect(plsql.test_employees.first(hire_date: :is_null)).to eq(employee)
299
- end
300
-
301
- it "should select record in table using :column => :is_not_null condition" do
302
- employee = @employees.last.dup
303
- employee[:employee_id] = employee[:employee_id] + 1
304
- employee[:hire_date] = nil
305
- plsql.test_employees.insert employee
306
- expect(plsql.test_employees.all(hire_date: :is_not_null, order_by: :employee_id)).to eq(@employees)
307
- end
308
-
309
- it "should count records in table" do
310
- expect(plsql.test_employees.select(:count)).to eq(@employees.size)
311
- expect(plsql.test_employees.count).to eq(@employees.size)
312
- end
313
-
314
- it "should count records in table using condition" do
315
- expect(plsql.test_employees.select(:count, "WHERE employee_id <= :1", @employees[2][:employee_id])).to eq(3)
316
- expect(plsql.test_employees.count("WHERE employee_id <= :1", @employees[2][:employee_id])).to eq(3)
317
- end
318
-
319
- end
320
-
321
- describe "update" do
322
- it "should update a record in table" do
323
- employee_id = @employees.first[:employee_id]
324
- plsql.test_employees.insert @employees.first
325
- plsql.test_employees.update first_name: "Test", where: { employee_id: employee_id }
326
- expect(plsql.test_employees.first(employee_id: employee_id)[:first_name]).to eq("Test")
327
- end
328
-
329
- it "should update a record in table using String WHERE condition" do
330
- employee_id = @employees.first[:employee_id]
331
- plsql.test_employees.insert @employees
332
- plsql.test_employees.update first_name: "Test", where: "employee_id = #{employee_id}"
333
- expect(plsql.test_employees.first(employee_id: employee_id)[:first_name]).to eq("Test")
334
- # all other records should not be changed
335
- plsql.test_employees.all("WHERE employee_id > :1", employee_id) do |employee|
336
- expect(employee[:first_name]).not_to eq("Test")
337
- end
338
- end
339
-
340
- it "should update all records in table" do
341
- plsql.test_employees.insert @employees
342
- plsql.test_employees.update first_name: "Test"
343
- plsql.test_employees.all do |employee|
344
- expect(employee[:first_name]).to eq("Test")
345
- end
346
- end
347
-
348
- it "should update a record in table with object type" do
349
- employee = @employees2[0]
350
- employee2 = @employees2[1]
351
- plsql.test_employees2.insert employee
352
- plsql.test_employees2.update address: employee2[:address], phones: employee2[:phones], where: { employee_id: employee[:employee_id] }
353
- updated_employee = plsql.test_employees2.first(employee_id: employee[:employee_id])
354
- expect(updated_employee[:address]).to eq(employee2[:address])
355
- expect(updated_employee[:phones]).to eq(employee2[:phones])
356
- end
357
-
358
- end
359
-
360
- describe "delete" do
361
- it "should delete record from table" do
362
- employee_id = @employees.first[:employee_id]
363
- plsql.test_employees.insert @employees
364
- plsql.test_employees.delete employee_id: employee_id
365
- expect(plsql.test_employees.first(employee_id: employee_id)).to be_nil
366
- expect(plsql.test_employees.all(order_by: :employee_id)).to eq(@employees[1, @employees.size - 1])
367
- end
368
-
369
- it "should delete all records from table" do
370
- plsql.test_employees.insert @employees
371
- plsql.test_employees.delete
372
- expect(plsql.test_employees.all).to be_empty
373
- end
374
- end
375
-
376
- end
@@ -1,299 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe "Type" do
4
- before(:all) do
5
- plsql.connection = get_connection
6
- plsql.execute "DROP TYPE t_employee" rescue nil
7
- plsql.execute "DROP TYPE t_phones" rescue nil
8
- plsql.execute "DROP TYPE t_phone" rescue nil
9
- plsql.execute <<-SQL
10
- CREATE OR REPLACE TYPE t_address AS OBJECT (
11
- street VARCHAR2(50),
12
- city VARCHAR2(50),
13
- country VARCHAR2(50),
14
- CONSTRUCTOR FUNCTION t_address(p_full_address VARCHAR2)
15
- RETURN SELF AS RESULT,
16
- MEMBER FUNCTION display_address(p_separator VARCHAR2 DEFAULT ',') RETURN VARCHAR2,
17
- MEMBER FUNCTION display_address(p_uppercase BOOLEAN, p_separator VARCHAR2 DEFAULT ',') RETURN VARCHAR2,
18
- MEMBER PROCEDURE set_country(p_country VARCHAR2),
19
- MEMBER PROCEDURE set_country2(p_country VARCHAR2, x_display_address OUT VARCHAR2),
20
- STATIC FUNCTION create_address(p_full_address VARCHAR2) RETURN t_address
21
- );
22
- SQL
23
- plsql.execute <<-SQL
24
- CREATE OR REPLACE TYPE BODY t_address AS
25
- CONSTRUCTOR FUNCTION t_address(p_full_address VARCHAR2)
26
- RETURN SELF AS RESULT
27
- AS
28
- l_comma1_pos INTEGER;
29
- l_comma2_pos INTEGER;
30
- BEGIN
31
- l_comma1_pos := INSTR(p_full_address, ',', 1, 1);
32
- l_comma2_pos := INSTR(p_full_address, ',', 1, 2);
33
- SELF.street := TRIM(SUBSTR(p_full_address, 1, l_comma1_pos - 1));
34
- SELF.city := TRIM(SUBSTR(p_full_address, l_comma1_pos+1, l_comma2_pos - l_comma1_pos - 1));
35
- SELF.country := TRIM(SUBSTR(p_full_address, l_comma2_pos+1));
36
- RETURN;
37
- END;
38
- MEMBER FUNCTION display_address(p_separator VARCHAR2) RETURN VARCHAR2 IS
39
- l_separator VARCHAR2(10) := p_separator;
40
- BEGIN
41
- IF SUBSTR(l_separator,-1) != ' ' THEN
42
- l_separator := l_separator || ' ';
43
- END IF;
44
- RETURN SELF.street || l_separator || SELF.city || l_separator || SELF.country;
45
- END;
46
- MEMBER FUNCTION display_address(p_uppercase BOOLEAN, p_separator VARCHAR2) RETURN VARCHAR2 IS
47
- l_separator VARCHAR2(10) := p_separator;
48
- BEGIN
49
- IF p_uppercase THEN
50
- RETURN UPPER(SELF.display_address(p_separator));
51
- ELSE
52
- RETURN SELF.display_address(p_separator);
53
- END IF;
54
- END;
55
- MEMBER PROCEDURE set_country(p_country VARCHAR2) IS
56
- BEGIN
57
- SELF.country := p_country;
58
- END;
59
- MEMBER PROCEDURE set_country2(p_country VARCHAR2, x_display_address OUT VARCHAR2) IS
60
- BEGIN
61
- SELF.country := p_country;
62
- x_display_address := SELF.display_address();
63
- END;
64
- STATIC FUNCTION create_address(p_full_address VARCHAR2) RETURN t_address IS
65
- BEGIN
66
- RETURN t_address(p_full_address);
67
- END;
68
- END;
69
- SQL
70
- plsql.execute <<-SQL
71
- CREATE OR REPLACE TYPE t_phone AS OBJECT (
72
- type VARCHAR2(10),
73
- phone_number VARCHAR2(50)
74
- )
75
- SQL
76
- plsql.execute <<-SQL
77
- CREATE OR REPLACE TYPE t_phones AS VARRAY(10) OF T_PHONE
78
- SQL
79
- plsql.execute <<-SQL
80
- CREATE OR REPLACE TYPE t_employee AS OBJECT (
81
- employee_id NUMBER(15),
82
- first_name VARCHAR2(50),
83
- last_name VARCHAR(50),
84
- hire_date DATE,
85
- address t_address,
86
- phones t_phones
87
- )
88
- SQL
89
- end
90
-
91
- after(:all) do
92
- plsql.execute "DROP TYPE t_employee"
93
- plsql.execute "DROP TYPE t_address"
94
- plsql.execute "DROP TYPE t_phones"
95
- plsql.execute "DROP TYPE t_phone"
96
- plsql.logoff
97
- end
98
-
99
- after(:each) do
100
- plsql.rollback
101
- end
102
-
103
- describe "find" do
104
-
105
- it "should find existing type" do
106
- expect(PLSQL::Type.find(plsql, :t_employee)).not_to be_nil
107
- end
108
-
109
- it "should not find nonexisting type" do
110
- expect(PLSQL::Type.find(plsql, :qwerty123456)).to be_nil
111
- end
112
-
113
- it "should find existing type in schema" do
114
- expect(plsql.t_employee).to be_a(PLSQL::Type)
115
- end
116
-
117
- end
118
-
119
- describe "synonym" do
120
-
121
- before(:all) do
122
- plsql.execute "CREATE SYNONYM t_employee_synonym FOR hr.t_employee"
123
- end
124
-
125
- after(:all) do
126
- plsql.execute "DROP SYNONYM t_employee_synonym" rescue nil
127
- end
128
-
129
- it "should find synonym to type" do
130
- expect(PLSQL::Type.find(plsql, :t_employee_synonym)).not_to be_nil
131
- end
132
-
133
- it "should find type using synonym in schema" do
134
- expect(plsql.t_employee_synonym).to be_a(PLSQL::Type)
135
- end
136
-
137
- end
138
-
139
- describe "public synonym" do
140
-
141
- it "should find public synonym to type" do
142
- expect(PLSQL::Type.find(plsql, :xmltype)).not_to be_nil
143
- end
144
-
145
- it "should find type using public synonym in schema" do
146
- expect(plsql.xmltype).to be_a(PLSQL::Type)
147
- end
148
-
149
- end
150
-
151
- describe "typecode" do
152
-
153
- it "should get typecode of object type" do
154
- expect(plsql.t_employee.typecode).to eq("OBJECT")
155
- end
156
-
157
- it "should get typecode of collection type" do
158
- expect(plsql.t_phones.typecode).to eq("COLLECTION")
159
- end
160
-
161
- end
162
-
163
- describe "attributes" do
164
-
165
- it "should get attribute names" do
166
- expect(plsql.t_employee.attribute_names).to eq([:employee_id, :first_name, :last_name, :hire_date, :address, :phones])
167
- end
168
-
169
- it "should get attributes metadata" do
170
- expect(plsql.t_employee.attributes).to eq(
171
- employee_id: { position: 1, data_type: "NUMBER", data_length: nil, data_precision: 15, data_scale: 0, type_owner: nil, type_name: nil, sql_type_name: nil },
172
- first_name: { position: 2, data_type: "VARCHAR2", data_length: 50, data_precision: nil, data_scale: nil, type_owner: nil, type_name: nil, sql_type_name: nil },
173
- last_name: { position: 3, data_type: "VARCHAR2", data_length: 50, data_precision: nil, data_scale: nil, type_owner: nil, type_name: nil, sql_type_name: nil },
174
- hire_date: { position: 4, data_type: "DATE", data_length: nil, data_precision: nil, data_scale: nil, type_owner: nil, type_name: nil, sql_type_name: nil },
175
- address: { position: 5, data_type: "OBJECT", data_length: nil, data_precision: nil, data_scale: nil, type_owner: "HR", type_name: "T_ADDRESS", sql_type_name: "HR.T_ADDRESS" },
176
- phones: { position: 6, data_type: "TABLE", data_length: nil, data_precision: nil, data_scale: nil, type_owner: "HR", type_name: "T_PHONES", sql_type_name: "HR.T_PHONES" }
177
- )
178
- end
179
-
180
- end
181
-
182
- describe "object instance" do
183
- before(:all) do
184
- @phone_attributes = { type: "mobile", phone_number: "123456" }
185
- @address_attributes = { street: "Street", city: "City", country: "Country" }
186
- @full_address = "#{@address_attributes[:street]}, #{@address_attributes[:city]}, #{@address_attributes[:country]}"
187
- end
188
-
189
- it "should get new object instance using named parameters" do
190
- expect(plsql.t_phone(@phone_attributes)).to eq(@phone_attributes)
191
- end
192
-
193
- it "should be an ObjectInstance" do
194
- expect(plsql.t_phone(@phone_attributes)).to be_a(PLSQL::ObjectInstance)
195
- end
196
-
197
- it "should get new object instance using sequential parameters" do
198
- expect(plsql.t_phone(@phone_attributes[:type], @phone_attributes[:phone_number])).to eq(@phone_attributes)
199
- end
200
-
201
- it "should get new object instance using custom constructor" do
202
- expect(plsql.t_address(@full_address)).to eq(@address_attributes)
203
- expect(plsql.t_address(p_full_address: @full_address)).to eq(@address_attributes)
204
- end
205
-
206
- it "should get new object instance using default constructor when custom constructor exists" do
207
- expect(plsql.t_address(@address_attributes)).to eq(@address_attributes)
208
- expect(plsql.t_address(@address_attributes[:street], @address_attributes[:city], @address_attributes[:country])).to eq(@address_attributes)
209
- end
210
-
211
- it "should get new empty collection of objects instance" do
212
- expect(plsql.t_phones.new).to eq([])
213
- expect(plsql.t_phones([])).to eq([])
214
- end
215
-
216
- it "should get new collection of objects instances" do
217
- phone = plsql.t_phone(@phone_attributes)
218
- expect(plsql.t_phones([phone, phone])).to eq([phone, phone])
219
- expect(plsql.t_phones(phone, phone)).to eq([phone, phone])
220
- expect(plsql.t_phones(@phone_attributes, @phone_attributes)).to eq([phone, phone])
221
- end
222
-
223
- end
224
-
225
- describe "member procedures" do
226
- before(:all) do
227
- @address_attributes = { street: "Street", city: "City", country: "Country" }
228
- @full_address = "#{@address_attributes[:street]}, #{@address_attributes[:city]}, #{@address_attributes[:country]}"
229
- end
230
-
231
- it "should call object instance member function without parameters" do
232
- expect(plsql.t_address(@address_attributes).display_address).to eq(@full_address)
233
- end
234
-
235
- it "should call object instance member function with parameters" do
236
- expect(plsql.t_address(@address_attributes).display_address(",")).to eq(@full_address)
237
- end
238
-
239
- it "should call object instance member function with named parameters" do
240
- expect(plsql.t_address(@address_attributes).display_address(p_separator: ",")).to eq(@full_address)
241
- end
242
-
243
- it "should call object overloaded instance member function" do
244
- expect(plsql.t_address(@address_attributes).display_address(true)).to eq(@full_address.upcase)
245
- expect(plsql.t_address(@address_attributes).display_address(true, ",")).to eq(@full_address.upcase)
246
- end
247
-
248
- it "should call object instance member function with explicit first SELF parameter" do
249
- expect(plsql.t_address.display_address(@address_attributes, ",")).to eq(@full_address)
250
- end
251
-
252
- it "should call object instance member function with explicit named SELF parameter" do
253
- expect(plsql.t_address.display_address(self: @address_attributes, p_separator: ",")).to eq(@full_address)
254
- end
255
-
256
- it "should call object instance member procedure" do
257
- other_country = "Other"
258
- expect(plsql.t_address(@address_attributes).set_country(other_country)).to eq(@address_attributes.merge(country: other_country))
259
- end
260
-
261
- it "should call object instance member procedure with output parameters" do
262
- other_country = "Other"
263
- expect(plsql.t_address(@address_attributes).set_country2(other_country)).to eq(
264
- [@address_attributes.merge(country: other_country),
265
- { x_display_address: "#{@address_attributes[:street]}, #{@address_attributes[:city]}, #{other_country}" }]
266
- )
267
- end
268
-
269
- it "should raise error if invalid member procedure is called" do
270
- expect do
271
- plsql.t_address(@address_attributes).invalid_procedure
272
- end.to raise_error(ArgumentError)
273
- end
274
-
275
- end
276
-
277
- describe "static procedures" do
278
- before(:all) do
279
- @address_attributes = { street: "Street", city: "City", country: "Country" }
280
- @full_address = "#{@address_attributes[:street]}, #{@address_attributes[:city]}, #{@address_attributes[:country]}"
281
- end
282
-
283
- it "should call object type static function" do
284
- expect(plsql.t_address.create_address(@full_address)).to eq(@address_attributes)
285
- end
286
-
287
- it "should call object type static function with named parameters" do
288
- expect(plsql.t_address.create_address(p_full_address: @full_address)).to eq(@address_attributes)
289
- end
290
-
291
- it "should raise error if invalid static procedure is called" do
292
- expect do
293
- plsql.t_address.invalid_procedure
294
- end.to raise_error(ArgumentError)
295
- end
296
-
297
- end
298
-
299
- end