ruby-plsql 0.6.0 → 0.7.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.
- checksums.yaml +5 -5
- data/.codeclimate.yml +30 -0
- data/.github/stale.yml +37 -0
- data/.rubocop.yml +153 -0
- data/.travis.yml +20 -6
- data/.travis/oracle/download.sh +9 -10
- data/.travis/oracle/install.sh +6 -6
- data/Gemfile +13 -9
- data/History.txt +26 -0
- data/README.md +9 -5
- data/Rakefile +31 -26
- data/VERSION +1 -1
- data/Vagrantfile +2 -2
- data/gemfiles/Gemfile.activerecord-5.0 +21 -0
- data/gemfiles/Gemfile.activerecord-5.1 +21 -0
- data/gemfiles/Gemfile.activerecord-5.2 +21 -0
- data/lib/plsql/connection.rb +16 -18
- data/lib/plsql/helpers.rb +1 -3
- data/lib/plsql/jdbc_connection.rb +66 -61
- data/lib/plsql/oci8_patches.rb +2 -2
- data/lib/plsql/oci_connection.rb +51 -69
- data/lib/plsql/package.rb +5 -8
- data/lib/plsql/procedure.rb +75 -78
- data/lib/plsql/procedure_call.rb +498 -501
- data/lib/plsql/schema.rb +95 -100
- data/lib/plsql/sequence.rb +10 -13
- data/lib/plsql/sql_statements.rb +9 -11
- data/lib/plsql/table.rb +59 -63
- data/lib/plsql/type.rb +71 -76
- data/lib/plsql/variable.rb +89 -94
- data/lib/plsql/version.rb +1 -1
- data/lib/plsql/view.rb +16 -19
- data/ruby-plsql.gemspec +41 -37
- data/spec/plsql/connection_spec.rb +67 -67
- data/spec/plsql/package_spec.rb +15 -15
- data/spec/plsql/procedure_spec.rb +286 -233
- data/spec/plsql/schema_spec.rb +22 -23
- data/spec/plsql/sequence_spec.rb +2 -2
- data/spec/plsql/sql_statements_spec.rb +5 -5
- data/spec/plsql/table_spec.rb +77 -77
- data/spec/plsql/type_spec.rb +23 -29
- data/spec/plsql/variable_spec.rb +59 -59
- data/spec/plsql/version_spec.rb +4 -4
- data/spec/plsql/view_spec.rb +42 -42
- data/spec/spec_helper.rb +37 -29
- data/spec/support/test_db.rb +12 -13
- metadata +44 -26
- data/.travis/oracle/LICENSE +0 -5
- data/.travis/oracle/README.md +0 -64
- data/.travis/oracle/download.js +0 -100
data/spec/plsql/variable_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require
|
3
|
+
require "spec_helper"
|
4
4
|
|
5
5
|
describe "Package variables /" do
|
6
6
|
|
@@ -35,24 +35,24 @@ describe "Package variables /" do
|
|
35
35
|
end
|
36
36
|
|
37
37
|
it "should set and get VARCHAR variable" do
|
38
|
-
plsql.test_package.varchar_variable =
|
39
|
-
expect(plsql.test_package.varchar_variable).to eq(
|
38
|
+
plsql.test_package.varchar_variable = "abc"
|
39
|
+
expect(plsql.test_package.varchar_variable).to eq("abc")
|
40
40
|
end
|
41
41
|
|
42
42
|
it "should set and get VARCHAR2 variable" do
|
43
|
-
plsql.test_package.varchar2_variable =
|
44
|
-
expect(plsql.test_package.varchar2_variable).to eq(
|
43
|
+
plsql.test_package.varchar2_variable = "abc"
|
44
|
+
expect(plsql.test_package.varchar2_variable).to eq("abc")
|
45
45
|
end
|
46
46
|
|
47
47
|
it "should set and get VARCHAR2 variable with comment" do
|
48
|
-
plsql.test_package.varchar2_variable2 =
|
49
|
-
expect(plsql.test_package.varchar2_variable2).to eq(
|
48
|
+
plsql.test_package.varchar2_variable2 = "abc"
|
49
|
+
expect(plsql.test_package.varchar2_variable2).to eq("abc")
|
50
50
|
end
|
51
51
|
|
52
52
|
it "should get VARCHAR2 variable default value" do
|
53
|
-
expect(plsql.test_package.varchar2_default).to eq(
|
54
|
-
expect(plsql.test_package.varchar2_default2).to eq(
|
55
|
-
expect(plsql.test_package.varchar2_default3).to eq(
|
53
|
+
expect(plsql.test_package.varchar2_default).to eq("default")
|
54
|
+
expect(plsql.test_package.varchar2_default2).to eq("default")
|
55
|
+
expect(plsql.test_package.varchar2_default3).to eq("default")
|
56
56
|
end
|
57
57
|
|
58
58
|
describe "with character or byte limit" do
|
@@ -70,33 +70,33 @@ describe "Package variables /" do
|
|
70
70
|
end
|
71
71
|
|
72
72
|
it "should set and get VARCHAR2(n CHAR) variable" do
|
73
|
-
plsql.test_package.varchar2_3_char =
|
74
|
-
expect(plsql.test_package.varchar2_3_char).to eq(
|
75
|
-
expect { plsql.test_package.varchar2_3_char =
|
73
|
+
plsql.test_package.varchar2_3_char = "āčē"
|
74
|
+
expect(plsql.test_package.varchar2_3_char).to eq("āčē")
|
75
|
+
expect { plsql.test_package.varchar2_3_char = "aceg" }.to raise_error(/buffer too small/)
|
76
76
|
end
|
77
77
|
|
78
78
|
it "should set and get VARCHAR2(n BYTE) variable" do
|
79
|
-
plsql.test_package.varchar2_3_byte =
|
80
|
-
expect(plsql.test_package.varchar2_3_byte).to eq(
|
81
|
-
expect { plsql.test_package.varchar2_3_byte =
|
82
|
-
expect { plsql.test_package.varchar2_3_byte =
|
79
|
+
plsql.test_package.varchar2_3_byte = "ace"
|
80
|
+
expect(plsql.test_package.varchar2_3_byte).to eq("ace")
|
81
|
+
expect { plsql.test_package.varchar2_3_byte = "āce" }.to raise_error(/buffer too small/)
|
82
|
+
expect { plsql.test_package.varchar2_3_byte = "aceg" }.to raise_error(/buffer too small/)
|
83
83
|
end
|
84
84
|
|
85
85
|
end
|
86
86
|
|
87
87
|
it "should set and get CHAR variable" do
|
88
|
-
plsql.test_package.char_variable =
|
89
|
-
expect(plsql.test_package.char_variable).to eq(
|
88
|
+
plsql.test_package.char_variable = "abc"
|
89
|
+
expect(plsql.test_package.char_variable).to eq("abc" + " " * 7)
|
90
90
|
end
|
91
91
|
|
92
92
|
it "should set and get NVARCHAR2 variable" do
|
93
|
-
plsql.test_package.nvarchar2_variable =
|
94
|
-
expect(plsql.test_package.nvarchar2_variable).to eq(
|
93
|
+
plsql.test_package.nvarchar2_variable = "abc"
|
94
|
+
expect(plsql.test_package.nvarchar2_variable).to eq("abc")
|
95
95
|
end
|
96
96
|
|
97
97
|
it "should set and get NCHAR variable" do
|
98
|
-
plsql.test_package.nchar_variable =
|
99
|
-
expect(plsql.test_package.nchar_variable).to eq(
|
98
|
+
plsql.test_package.nchar_variable = "abc"
|
99
|
+
expect(plsql.test_package.nchar_variable).to eq("abc" + " " * 7)
|
100
100
|
end
|
101
101
|
|
102
102
|
end
|
@@ -134,22 +134,22 @@ describe "Package variables /" do
|
|
134
134
|
end
|
135
135
|
|
136
136
|
[
|
137
|
-
{:
|
138
|
-
{:
|
139
|
-
{:
|
140
|
-
{:
|
141
|
-
{:
|
142
|
-
{:
|
143
|
-
{:
|
144
|
-
{:
|
145
|
-
{:
|
146
|
-
{:
|
147
|
-
{:
|
148
|
-
{:
|
149
|
-
{:
|
137
|
+
{ ora_data_type: "INTEGER", default: nil, class: Integer, given: 1, expected: 1 },
|
138
|
+
{ ora_data_type: "NUMBER(10)", default: nil, class: Integer, given: 1, expected: 1 },
|
139
|
+
{ ora_data_type: "NUMBER(10)", default: 5, class: Integer, given: 1, expected: 1 },
|
140
|
+
{ ora_data_type: "NUMBER", default: nil, class: BigDecimal, given: 123.456, expected: 123.456 },
|
141
|
+
{ ora_data_type: "NUMBER(15,2)", default: nil, class: BigDecimal, given: 123.456, expected: 123.46 },
|
142
|
+
{ ora_data_type: "PLS_INTEGER", default: nil, class: Integer, given: 1, expected: 1 },
|
143
|
+
{ ora_data_type: "BINARY_INTEGER", default: nil, class: Integer, given: 1, expected: 1 },
|
144
|
+
{ ora_data_type: "SIMPLE_INTEGER", default: 10, class: Integer, given: 1, expected: 1 },
|
145
|
+
{ ora_data_type: "NATURAL", default: nil, class: Integer, given: 1, expected: 1 },
|
146
|
+
{ ora_data_type: "NATURALN", default: 0, class: Integer, given: 1, expected: 1 },
|
147
|
+
{ ora_data_type: "POSITIVE", default: nil, class: Integer, given: 1, expected: 1 },
|
148
|
+
{ ora_data_type: "POSITIVEN", default: 5, class: Integer, given: 1, expected: 1 },
|
149
|
+
{ ora_data_type: "SIGNTYPE", default: -1, class: Integer, given: 1, expected: 1 },
|
150
150
|
].each do |row|
|
151
151
|
ora_data_type, default, class_, given, expected = row.values
|
152
|
-
describe ora_data_type+(default ?
|
152
|
+
describe ora_data_type + (default ? " with default" : "") do
|
153
153
|
include_examples "Numeric", ora_data_type, default, class_, given, expected
|
154
154
|
end
|
155
155
|
end
|
@@ -170,8 +170,8 @@ describe "Package variables /" do
|
|
170
170
|
CREATE OR REPLACE PACKAGE BODY test_package IS
|
171
171
|
END;
|
172
172
|
SQL
|
173
|
-
@date = Time.local(2009,12,21)
|
174
|
-
@timestamp = Time.local(2009,12,21,14,10,30,11)
|
173
|
+
@date = Time.local(2009, 12, 21)
|
174
|
+
@timestamp = Time.local(2009, 12, 21, 14, 10, 30, 11)
|
175
175
|
end
|
176
176
|
|
177
177
|
after(:all) do
|
@@ -233,17 +233,17 @@ describe "Package variables /" do
|
|
233
233
|
end
|
234
234
|
|
235
235
|
it "should set and get CLOB variable" do
|
236
|
-
plsql.test_package.clob_variable =
|
237
|
-
expect(plsql.test_package.clob_variable).to eq(
|
236
|
+
plsql.test_package.clob_variable = "abc"
|
237
|
+
expect(plsql.test_package.clob_variable).to eq("abc")
|
238
238
|
end
|
239
239
|
|
240
240
|
it "should get CLOB variable default value" do
|
241
|
-
expect(plsql.test_package.clob_default).to eq(
|
241
|
+
expect(plsql.test_package.clob_default).to eq("default")
|
242
242
|
end
|
243
243
|
|
244
244
|
it "should set and get NCLOB variable" do
|
245
|
-
plsql.test_package.nclob_variable =
|
246
|
-
expect(plsql.test_package.nclob_variable).to eq(
|
245
|
+
plsql.test_package.nclob_variable = "abc"
|
246
|
+
expect(plsql.test_package.nclob_variable).to eq("abc")
|
247
247
|
end
|
248
248
|
|
249
249
|
it "should set and get BLOB variable" do
|
@@ -291,12 +291,12 @@ describe "Package variables /" do
|
|
291
291
|
end
|
292
292
|
|
293
293
|
it "should set and get VARCHAR2 variable" do
|
294
|
-
plsql.test_package.first_name =
|
295
|
-
expect(plsql.test_package.first_name).to eq(
|
294
|
+
plsql.test_package.first_name = "First"
|
295
|
+
expect(plsql.test_package.first_name).to eq("First")
|
296
296
|
end
|
297
297
|
|
298
298
|
it "should set and get DATE variable" do
|
299
|
-
today = Time.local(2009,12,22)
|
299
|
+
today = Time.local(2009, 12, 22)
|
300
300
|
plsql.test_package.hire_date = today
|
301
301
|
expect(plsql.test_package.hire_date).to eq(today)
|
302
302
|
end
|
@@ -329,7 +329,7 @@ describe "Package variables /" do
|
|
329
329
|
end
|
330
330
|
|
331
331
|
it "should get VARCHAR2 constant" do
|
332
|
-
expect(plsql.test_package.string_constant).to eq(
|
332
|
+
expect(plsql.test_package.string_constant).to eq("constant")
|
333
333
|
end
|
334
334
|
|
335
335
|
it "should raise error when trying to set constant" do
|
@@ -371,14 +371,14 @@ describe "Package variables /" do
|
|
371
371
|
phones t_phones
|
372
372
|
)
|
373
373
|
SQL
|
374
|
-
@phones = [{:
|
374
|
+
@phones = [{ type: "mobile", phone_number: "123456" }, { type: "home", phone_number: "654321" }]
|
375
375
|
@employee = {
|
376
|
-
:
|
377
|
-
:
|
378
|
-
:
|
379
|
-
:
|
380
|
-
:
|
381
|
-
:
|
376
|
+
employee_id: 1,
|
377
|
+
first_name: "First",
|
378
|
+
last_name: "Last",
|
379
|
+
hire_date: Time.local(2000, 01, 31),
|
380
|
+
address: { street: "Main street 1", city: "Riga", country: "Latvia" },
|
381
|
+
phones: @phones
|
382
382
|
}
|
383
383
|
|
384
384
|
plsql.execute <<-SQL
|
@@ -433,10 +433,10 @@ describe "Package variables /" do
|
|
433
433
|
)
|
434
434
|
SQL
|
435
435
|
@employee = {
|
436
|
-
:
|
437
|
-
:
|
438
|
-
:
|
439
|
-
:
|
436
|
+
employee_id: 1,
|
437
|
+
first_name: "First",
|
438
|
+
last_name: "Last",
|
439
|
+
hire_date: Time.local(2000, 01, 31)
|
440
440
|
}
|
441
441
|
|
442
442
|
plsql.execute <<-SQL
|
data/spec/plsql/version_spec.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe "Version" do
|
4
4
|
it "should return ruby-plsql version" do
|
5
|
-
expect(PLSQL::VERSION).to eq(File.read(File.dirname(__FILE__)+
|
5
|
+
expect(PLSQL::VERSION).to eq(File.read(File.dirname(__FILE__) + "/../../VERSION").chomp)
|
6
6
|
end
|
7
|
-
|
8
|
-
end
|
7
|
+
|
8
|
+
end
|
data/spec/plsql/view_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe "View" do
|
4
4
|
before(:all) do
|
@@ -17,18 +17,18 @@ describe "View" do
|
|
17
17
|
|
18
18
|
@employees = (1..10).map do |i|
|
19
19
|
{
|
20
|
-
:
|
21
|
-
:
|
22
|
-
:
|
23
|
-
:
|
24
|
-
:
|
20
|
+
employee_id: i,
|
21
|
+
first_name: "First #{i}",
|
22
|
+
last_name: "Last #{i}",
|
23
|
+
hire_date: Time.local(2000, 01, i),
|
24
|
+
status: "A"
|
25
25
|
}
|
26
26
|
end
|
27
27
|
@employees_all_fields = [:employee_id, :first_name, :last_name, :hire_date, :status]
|
28
|
-
@employees_all_values = @employees.map{|e| @employees_all_fields.map{|f| e[f]}}
|
28
|
+
@employees_all_values = @employees.map { |e| @employees_all_fields.map { |f| e[f] } }
|
29
29
|
@employees_some_fields = [:employee_id, :first_name, :last_name]
|
30
|
-
@employees_some_values = @employees.map{|e| @employees_some_fields.map{|f| e[f]}}
|
31
|
-
@employee_default_values = {:
|
30
|
+
@employees_some_values = @employees.map { |e| @employees_some_fields.map { |f| e[f] } }
|
31
|
+
@employee_default_values = { hire_date: nil, status: "N" }
|
32
32
|
end
|
33
33
|
|
34
34
|
after(:all) do
|
@@ -96,23 +96,23 @@ describe "View" do
|
|
96
96
|
end
|
97
97
|
|
98
98
|
it "should get columns metadata for view" do
|
99
|
-
expect(plsql.test_employees_v.columns).to eq(
|
100
|
-
:
|
101
|
-
:
|
102
|
-
:
|
103
|
-
:
|
104
|
-
:
|
105
|
-
:
|
106
|
-
:
|
107
|
-
:
|
108
|
-
:
|
109
|
-
:
|
110
|
-
:
|
111
|
-
:
|
112
|
-
:
|
113
|
-
:
|
114
|
-
:
|
115
|
-
|
99
|
+
expect(plsql.test_employees_v.columns).to eq(
|
100
|
+
employee_id: {
|
101
|
+
position: 1, data_type: "NUMBER", data_length: 22, data_precision: 15, data_scale: 0, char_used: nil,
|
102
|
+
type_owner: nil, type_name: nil, sql_type_name: nil, nullable: false, data_default: nil },
|
103
|
+
first_name: {
|
104
|
+
position: 2, data_type: "VARCHAR2", data_length: 50, data_precision: nil, data_scale: nil, char_used: "B",
|
105
|
+
type_owner: nil, type_name: nil, sql_type_name: nil, nullable: true, data_default: nil },
|
106
|
+
last_name: {
|
107
|
+
position: 3, data_type: "VARCHAR2", data_length: 50, data_precision: nil, data_scale: nil, char_used: "B",
|
108
|
+
type_owner: nil, type_name: nil, sql_type_name: nil, nullable: true, data_default: nil },
|
109
|
+
hire_date: {
|
110
|
+
position: 4, data_type: "DATE", data_length: 7, data_precision: nil, data_scale: nil, char_used: nil,
|
111
|
+
type_owner: nil, type_name: nil, sql_type_name: nil, nullable: true, data_default: nil },
|
112
|
+
status: {
|
113
|
+
position: 5, data_type: "VARCHAR2", data_length: 1, data_precision: nil, data_scale: nil, char_used: "B",
|
114
|
+
type_owner: nil, type_name: nil, sql_type_name: nil, nullable: true, data_default: nil }
|
115
|
+
)
|
116
116
|
end
|
117
117
|
|
118
118
|
end
|
@@ -125,12 +125,12 @@ describe "View" do
|
|
125
125
|
|
126
126
|
it "should insert a record in view using partial list of columns" do
|
127
127
|
plsql.test_employees_v.insert @employees.first.except(:hire_date)
|
128
|
-
expect(plsql.test_employees_v.all).to eq([@employees.first.merge(:
|
128
|
+
expect(plsql.test_employees_v.all).to eq([@employees.first.merge(hire_date: nil)])
|
129
129
|
end
|
130
130
|
|
131
131
|
it "should insert default value from table definition if value not provided" do
|
132
132
|
plsql.test_employees_v.insert @employees.first.except(:status)
|
133
|
-
expect(plsql.test_employees_v.all).to eq([@employees.first.merge(:
|
133
|
+
expect(plsql.test_employees_v.all).to eq([@employees.first.merge(status: "N")])
|
134
134
|
end
|
135
135
|
|
136
136
|
it "should insert array of records in view" do
|
@@ -168,7 +168,7 @@ describe "View" do
|
|
168
168
|
|
169
169
|
it "should insert many records with list of some fields and array of values" do
|
170
170
|
plsql.test_employees_v.insert_values @employees_some_fields, *@employees_some_values
|
171
|
-
expect(plsql.test_employees_v.all).to eq(@employees.map{|e| e.merge(@employee_default_values)})
|
171
|
+
expect(plsql.test_employees_v.all).to eq(@employees.map { |e| e.merge(@employee_default_values) })
|
172
172
|
end
|
173
173
|
|
174
174
|
end
|
@@ -186,13 +186,13 @@ describe "View" do
|
|
186
186
|
it "should select all records in view" do
|
187
187
|
expect(plsql.test_employees_v.select(:all, "ORDER BY employee_id")).to eq(@employees)
|
188
188
|
expect(plsql.test_employees_v.all("ORDER BY employee_id")).to eq(@employees)
|
189
|
-
expect(plsql.test_employees_v.all(:
|
189
|
+
expect(plsql.test_employees_v.all(order_by: :employee_id)).to eq(@employees)
|
190
190
|
end
|
191
191
|
|
192
192
|
it "should select record in view using WHERE condition" do
|
193
193
|
expect(plsql.test_employees_v.select(:first, "WHERE employee_id = :1", @employees.first[:employee_id])).to eq(@employees.first)
|
194
194
|
expect(plsql.test_employees_v.first("WHERE employee_id = :1", @employees.first[:employee_id])).to eq(@employees.first)
|
195
|
-
expect(plsql.test_employees_v.first(:
|
195
|
+
expect(plsql.test_employees_v.first(employee_id: @employees.first[:employee_id])).to eq(@employees.first)
|
196
196
|
end
|
197
197
|
|
198
198
|
it "should select record in view using :column => nil condition" do
|
@@ -201,7 +201,7 @@ describe "View" do
|
|
201
201
|
employee[:hire_date] = nil
|
202
202
|
plsql.test_employees_v.insert employee
|
203
203
|
expect(plsql.test_employees_v.first("WHERE hire_date IS NULL")).to eq(employee)
|
204
|
-
expect(plsql.test_employees_v.first(:
|
204
|
+
expect(plsql.test_employees_v.first(hire_date: nil)).to eq(employee)
|
205
205
|
end
|
206
206
|
|
207
207
|
it "should count records in view" do
|
@@ -220,26 +220,26 @@ describe "View" do
|
|
220
220
|
it "should update a record in view" do
|
221
221
|
employee_id = @employees.first[:employee_id]
|
222
222
|
plsql.test_employees_v.insert @employees.first
|
223
|
-
plsql.test_employees_v.update :
|
224
|
-
expect(plsql.test_employees_v.first(:
|
223
|
+
plsql.test_employees_v.update first_name: "Test", where: { employee_id: employee_id }
|
224
|
+
expect(plsql.test_employees_v.first(employee_id: employee_id)[:first_name]).to eq("Test")
|
225
225
|
end
|
226
226
|
|
227
227
|
it "should update a record in view using String WHERE condition" do
|
228
228
|
employee_id = @employees.first[:employee_id]
|
229
229
|
plsql.test_employees_v.insert @employees
|
230
|
-
plsql.test_employees_v.update :
|
231
|
-
expect(plsql.test_employees_v.first(:
|
230
|
+
plsql.test_employees_v.update first_name: "Test", where: "employee_id = #{employee_id}"
|
231
|
+
expect(plsql.test_employees_v.first(employee_id: employee_id)[:first_name]).to eq("Test")
|
232
232
|
# all other records should not be changed
|
233
233
|
plsql.test_employees_v.all("WHERE employee_id > :1", employee_id) do |employee|
|
234
|
-
expect(employee[:first_name]).not_to eq(
|
234
|
+
expect(employee[:first_name]).not_to eq("Test")
|
235
235
|
end
|
236
236
|
end
|
237
237
|
|
238
238
|
it "should update all records in view" do
|
239
239
|
plsql.test_employees_v.insert @employees
|
240
|
-
plsql.test_employees_v.update :
|
240
|
+
plsql.test_employees_v.update first_name: "Test"
|
241
241
|
plsql.test_employees_v.all do |employee|
|
242
|
-
expect(employee[:first_name]).to eq(
|
242
|
+
expect(employee[:first_name]).to eq("Test")
|
243
243
|
end
|
244
244
|
end
|
245
245
|
|
@@ -249,9 +249,9 @@ describe "View" do
|
|
249
249
|
it "should delete record from view" do
|
250
250
|
employee_id = @employees.first[:employee_id]
|
251
251
|
plsql.test_employees_v.insert @employees
|
252
|
-
plsql.test_employees_v.delete :
|
253
|
-
expect(plsql.test_employees_v.first(:
|
254
|
-
expect(plsql.test_employees_v.all(:
|
252
|
+
plsql.test_employees_v.delete employee_id: employee_id
|
253
|
+
expect(plsql.test_employees_v.first(employee_id: employee_id)).to be_nil
|
254
|
+
expect(plsql.test_employees_v.all(order_by: :employee_id)).to eq(@employees[1, @employees.size - 1])
|
255
255
|
end
|
256
256
|
|
257
257
|
it "should delete all records from view" do
|
data/spec/spec_helper.rb
CHANGED
@@ -1,50 +1,50 @@
|
|
1
1
|
require "rubygems"
|
2
2
|
require "bundler"
|
3
3
|
Bundler.setup(:default, :development)
|
4
|
-
require
|
4
|
+
require "simplecov"
|
5
5
|
|
6
6
|
SimpleCov.configure do
|
7
|
-
load_profile
|
8
|
-
load_profile
|
7
|
+
load_profile "root_filter"
|
8
|
+
load_profile "test_frameworks"
|
9
9
|
end
|
10
10
|
|
11
11
|
ENV["COVERAGE"] && SimpleCov.start do
|
12
12
|
add_filter "/.rvm/"
|
13
13
|
end
|
14
14
|
|
15
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__),
|
16
|
-
require
|
15
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
|
16
|
+
require "rspec"
|
17
17
|
|
18
|
-
unless ENV[
|
19
|
-
require
|
18
|
+
unless ENV["NO_ACTIVERECORD"]
|
19
|
+
require "active_record"
|
20
20
|
else
|
21
|
-
puts
|
21
|
+
puts "Without ActiveRecord"
|
22
22
|
end
|
23
23
|
|
24
|
-
require
|
24
|
+
require "ruby-plsql"
|
25
25
|
|
26
26
|
# Requires supporting ruby files with custom matchers and macros, etc,
|
27
27
|
# in spec/support/ and its subdirectories.
|
28
|
-
Dir[File.join(File.dirname(__FILE__),
|
28
|
+
Dir[File.join(File.dirname(__FILE__), "support/**/*.rb")].each { |f| require f }
|
29
29
|
|
30
|
-
if ENV[
|
31
|
-
DATABASE_NAME =
|
30
|
+
if ENV["USE_VM_DATABASE"] == "Y"
|
31
|
+
DATABASE_NAME = "XE"
|
32
32
|
else
|
33
|
-
DATABASE_NAME = ENV[
|
33
|
+
DATABASE_NAME = ENV["DATABASE_NAME"] || "orcl"
|
34
34
|
end
|
35
35
|
|
36
36
|
DATABASE_SERVICE_NAME = (defined?(JRUBY_VERSION) ? "/" : "") +
|
37
|
-
(ENV[
|
38
|
-
DATABASE_HOST = ENV[
|
39
|
-
DATABASE_PORT = (ENV[
|
37
|
+
(ENV["DATABASE_SERVICE_NAME"] || DATABASE_NAME)
|
38
|
+
DATABASE_HOST = ENV["DATABASE_HOST"] || "localhost"
|
39
|
+
DATABASE_PORT = (ENV["DATABASE_PORT"] || 1521).to_i
|
40
40
|
DATABASE_USERS_AND_PASSWORDS = [
|
41
|
-
[ENV[
|
42
|
-
[ENV[
|
41
|
+
[ENV["DATABASE_USER"] || "hr", ENV["DATABASE_PASSWORD"] || "hr"],
|
42
|
+
[ENV["DATABASE_USER2"] || "arunit", ENV["DATABASE_PASSWORD2"] || "arunit"]
|
43
43
|
]
|
44
44
|
# specify which database version is used (will be verified in one test)
|
45
|
-
DATABASE_VERSION = ENV[
|
45
|
+
DATABASE_VERSION = ENV["DATABASE_VERSION"] || "10.2.0.4"
|
46
46
|
|
47
|
-
if ENV[
|
47
|
+
if ENV["USE_VM_DATABASE"] == "Y"
|
48
48
|
RSpec.configure do |config|
|
49
49
|
config.before(:suite) do
|
50
50
|
TestDb.build
|
@@ -58,13 +58,21 @@ if ENV['USE_VM_DATABASE'] == 'Y'
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
+
def oracle_error_class
|
62
|
+
unless defined?(JRUBY_VERSION)
|
63
|
+
OCIError
|
64
|
+
else
|
65
|
+
java.sql.SQLException
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
61
69
|
def get_eazy_connect_url(svc_separator = "")
|
62
70
|
"#{DATABASE_HOST}:#{DATABASE_PORT}#{svc_separator}#{DATABASE_SERVICE_NAME}"
|
63
71
|
end
|
64
72
|
|
65
73
|
def get_connection_url
|
66
74
|
unless defined?(JRUBY_VERSION)
|
67
|
-
(ENV[
|
75
|
+
(ENV["DATABASE_USE_TNS"] == "NO") ? get_eazy_connect_url("/") : DATABASE_NAME
|
68
76
|
else
|
69
77
|
"jdbc:oracle:thin:@#{get_eazy_connect_url}"
|
70
78
|
end
|
@@ -94,20 +102,20 @@ def try_to_connect(exception)
|
|
94
102
|
end
|
95
103
|
|
96
104
|
CONNECTION_PARAMS = {
|
97
|
-
:
|
98
|
-
:
|
99
|
-
:
|
100
|
-
:
|
101
|
-
:
|
102
|
-
:
|
105
|
+
adapter: "oracle_enhanced",
|
106
|
+
database: DATABASE_SERVICE_NAME,
|
107
|
+
host: DATABASE_HOST,
|
108
|
+
port: DATABASE_PORT,
|
109
|
+
username: DATABASE_USERS_AND_PASSWORDS[0][0],
|
110
|
+
password: DATABASE_USERS_AND_PASSWORDS[0][1]
|
103
111
|
}
|
104
112
|
|
105
113
|
class Hash
|
106
114
|
def except(*blacklist)
|
107
|
-
self.reject {|key, value| blacklist.include?(key) }
|
115
|
+
self.reject { |key, value| blacklist.include?(key) }
|
108
116
|
end unless method_defined?(:except)
|
109
117
|
|
110
118
|
def only(*whitelist)
|
111
|
-
self.reject {|key, value| !whitelist.include?(key) }
|
119
|
+
self.reject { |key, value| !whitelist.include?(key) }
|
112
120
|
end unless method_defined?(:only)
|
113
121
|
end
|