ruby-plsql 0.5.3 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/stale.yml +37 -0
- data/.github/workflows/rubocop.yml +37 -0
- data/.github/workflows/test.yml +69 -0
- data/.rubocop.yml +147 -0
- data/.travis.yml +88 -0
- data/.travis/oracle/download.sh +15 -0
- data/.travis/oracle/install.sh +32 -0
- data/.travis/setup_accounts.sh +9 -0
- data/Gemfile +17 -9
- data/History.txt +76 -0
- data/README.md +29 -6
- data/Rakefile +31 -26
- data/VERSION +1 -1
- data/Vagrantfile +4 -4
- data/ci/network/admin/tnsnames.ora +7 -0
- data/ci/setup_accounts.sh +9 -0
- 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/gemfiles/Gemfile.activerecord-6.0 +21 -0
- data/gemfiles/Gemfile.activerecord-6.1 +21 -0
- data/gemfiles/Gemfile.activerecord-main +21 -0
- data/lib/plsql/connection.rb +19 -22
- data/lib/plsql/helpers.rb +1 -3
- data/lib/plsql/jdbc_connection.rb +70 -68
- data/lib/plsql/oci8_patches.rb +2 -2
- data/lib/plsql/oci_connection.rb +62 -77
- data/lib/plsql/package.rb +61 -46
- data/lib/plsql/procedure.rb +358 -78
- data/lib/plsql/procedure_call.rb +508 -463
- data/lib/plsql/schema.rb +96 -101
- data/lib/plsql/sequence.rb +10 -13
- data/lib/plsql/sql_statements.rb +9 -11
- data/lib/plsql/table.rb +60 -63
- data/lib/plsql/type.rb +71 -76
- data/lib/plsql/variable.rb +90 -94
- data/lib/plsql/version.rb +1 -1
- data/lib/plsql/view.rb +16 -19
- data/ruby-plsql.gemspec +55 -35
- data/spec/plsql/connection_spec.rb +72 -66
- data/spec/plsql/package_spec.rb +63 -14
- data/spec/plsql/procedure_spec.rb +603 -261
- data/spec/plsql/schema_spec.rb +47 -23
- data/spec/plsql/sequence_spec.rb +2 -2
- data/spec/plsql/sql_statements_spec.rb +6 -6
- data/spec/plsql/table_spec.rb +84 -79
- data/spec/plsql/type_spec.rb +24 -30
- data/spec/plsql/variable_spec.rb +80 -88
- data/spec/plsql/version_spec.rb +4 -4
- data/spec/plsql/view_spec.rb +42 -42
- data/spec/spec_helper.rb +38 -35
- data/spec/support/create_arunit_user.sql +2 -0
- data/spec/support/custom_config.rb.sample +14 -0
- data/spec/support/test_db.rb +12 -13
- data/spec/support/unlock_and_setup_hr_user.sql +2 -0
- metadata +111 -34
data/spec/plsql/type_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe "Type" do
|
4
4
|
before(:all) do
|
@@ -80,7 +80,7 @@ describe "Type" do
|
|
80
80
|
CREATE OR REPLACE TYPE t_employee AS OBJECT (
|
81
81
|
employee_id NUMBER(15),
|
82
82
|
first_name VARCHAR2(50),
|
83
|
-
last_name
|
83
|
+
last_name VARCHAR(50),
|
84
84
|
hire_date DATE,
|
85
85
|
address t_address,
|
86
86
|
phones t_phones
|
@@ -167,28 +167,22 @@ describe "Type" do
|
|
167
167
|
end
|
168
168
|
|
169
169
|
it "should get attributes metadata" do
|
170
|
-
expect(plsql.t_employee.attributes).to eq(
|
171
|
-
:
|
172
|
-
|
173
|
-
:
|
174
|
-
|
175
|
-
:
|
176
|
-
|
177
|
-
|
178
|
-
{:position=>4, :data_type=>"DATE", :data_length=>nil, :data_precision=>nil, :data_scale=>nil, :type_owner=>nil, :type_name=>nil, :sql_type_name=>nil},
|
179
|
-
:address =>
|
180
|
-
{: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"},
|
181
|
-
:phones =>
|
182
|
-
{: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"}
|
183
|
-
})
|
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
|
+
)
|
184
178
|
end
|
185
179
|
|
186
180
|
end
|
187
181
|
|
188
182
|
describe "object instance" do
|
189
183
|
before(:all) do
|
190
|
-
@phone_attributes = {:
|
191
|
-
@address_attributes = {:
|
184
|
+
@phone_attributes = { type: "mobile", phone_number: "123456" }
|
185
|
+
@address_attributes = { street: "Street", city: "City", country: "Country" }
|
192
186
|
@full_address = "#{@address_attributes[:street]}, #{@address_attributes[:city]}, #{@address_attributes[:country]}"
|
193
187
|
end
|
194
188
|
|
@@ -206,7 +200,7 @@ describe "Type" do
|
|
206
200
|
|
207
201
|
it "should get new object instance using custom constructor" do
|
208
202
|
expect(plsql.t_address(@full_address)).to eq(@address_attributes)
|
209
|
-
expect(plsql.t_address(:
|
203
|
+
expect(plsql.t_address(p_full_address: @full_address)).to eq(@address_attributes)
|
210
204
|
end
|
211
205
|
|
212
206
|
it "should get new object instance using default constructor when custom constructor exists" do
|
@@ -230,7 +224,7 @@ describe "Type" do
|
|
230
224
|
|
231
225
|
describe "member procedures" do
|
232
226
|
before(:all) do
|
233
|
-
@address_attributes = {:
|
227
|
+
@address_attributes = { street: "Street", city: "City", country: "Country" }
|
234
228
|
@full_address = "#{@address_attributes[:street]}, #{@address_attributes[:city]}, #{@address_attributes[:country]}"
|
235
229
|
end
|
236
230
|
|
@@ -239,36 +233,36 @@ describe "Type" do
|
|
239
233
|
end
|
240
234
|
|
241
235
|
it "should call object instance member function with parameters" do
|
242
|
-
expect(plsql.t_address(@address_attributes).display_address(
|
236
|
+
expect(plsql.t_address(@address_attributes).display_address(",")).to eq(@full_address)
|
243
237
|
end
|
244
238
|
|
245
239
|
it "should call object instance member function with named parameters" do
|
246
|
-
expect(plsql.t_address(@address_attributes).display_address(:
|
240
|
+
expect(plsql.t_address(@address_attributes).display_address(p_separator: ",")).to eq(@full_address)
|
247
241
|
end
|
248
242
|
|
249
243
|
it "should call object overloaded instance member function" do
|
250
244
|
expect(plsql.t_address(@address_attributes).display_address(true)).to eq(@full_address.upcase)
|
251
|
-
expect(plsql.t_address(@address_attributes).display_address(true,
|
245
|
+
expect(plsql.t_address(@address_attributes).display_address(true, ",")).to eq(@full_address.upcase)
|
252
246
|
end
|
253
247
|
|
254
248
|
it "should call object instance member function with explicit first SELF parameter" do
|
255
|
-
expect(plsql.t_address.display_address(@address_attributes,
|
249
|
+
expect(plsql.t_address.display_address(@address_attributes, ",")).to eq(@full_address)
|
256
250
|
end
|
257
251
|
|
258
252
|
it "should call object instance member function with explicit named SELF parameter" do
|
259
|
-
expect(plsql.t_address.display_address(:
|
253
|
+
expect(plsql.t_address.display_address(self: @address_attributes, p_separator: ",")).to eq(@full_address)
|
260
254
|
end
|
261
255
|
|
262
256
|
it "should call object instance member procedure" do
|
263
257
|
other_country = "Other"
|
264
|
-
expect(plsql.t_address(@address_attributes).set_country(other_country)).to eq(@address_attributes.merge(:
|
258
|
+
expect(plsql.t_address(@address_attributes).set_country(other_country)).to eq(@address_attributes.merge(country: other_country))
|
265
259
|
end
|
266
260
|
|
267
261
|
it "should call object instance member procedure with output parameters" do
|
268
262
|
other_country = "Other"
|
269
263
|
expect(plsql.t_address(@address_attributes).set_country2(other_country)).to eq(
|
270
|
-
[@address_attributes.merge(:
|
271
|
-
{:
|
264
|
+
[@address_attributes.merge(country: other_country),
|
265
|
+
{ x_display_address: "#{@address_attributes[:street]}, #{@address_attributes[:city]}, #{other_country}" }]
|
272
266
|
)
|
273
267
|
end
|
274
268
|
|
@@ -282,7 +276,7 @@ describe "Type" do
|
|
282
276
|
|
283
277
|
describe "static procedures" do
|
284
278
|
before(:all) do
|
285
|
-
@address_attributes = {:
|
279
|
+
@address_attributes = { street: "Street", city: "City", country: "Country" }
|
286
280
|
@full_address = "#{@address_attributes[:street]}, #{@address_attributes[:city]}, #{@address_attributes[:country]}"
|
287
281
|
end
|
288
282
|
|
@@ -291,7 +285,7 @@ describe "Type" do
|
|
291
285
|
end
|
292
286
|
|
293
287
|
it "should call object type static function with named parameters" do
|
294
|
-
expect(plsql.t_address.create_address(:
|
288
|
+
expect(plsql.t_address.create_address(p_full_address: @full_address)).to eq(@address_attributes)
|
295
289
|
end
|
296
290
|
|
297
291
|
it "should raise error if invalid static procedure is called" do
|
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
|
|
@@ -16,6 +16,7 @@ describe "Package variables /" do
|
|
16
16
|
varchar2_default3 varchar2(50) NOT NULL := 'default';
|
17
17
|
varchar2_3_char VARCHAR2(3 CHAR);
|
18
18
|
varchar2_3_byte VARCHAR2(3 BYTE);
|
19
|
+
varchar_variable VARCHAR(50);
|
19
20
|
char_variable char(10) ;
|
20
21
|
nvarchar2_variable NVARCHAR2(50);
|
21
22
|
nchar_variable NCHAR(10);
|
@@ -33,20 +34,25 @@ describe "Package variables /" do
|
|
33
34
|
plsql.logoff
|
34
35
|
end
|
35
36
|
|
37
|
+
it "should set and get VARCHAR variable" do
|
38
|
+
plsql.test_package.varchar_variable = "abc"
|
39
|
+
expect(plsql.test_package.varchar_variable).to eq("abc")
|
40
|
+
end
|
41
|
+
|
36
42
|
it "should set and get VARCHAR2 variable" do
|
37
|
-
plsql.test_package.varchar2_variable =
|
38
|
-
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")
|
39
45
|
end
|
40
46
|
|
41
47
|
it "should set and get VARCHAR2 variable with comment" do
|
42
|
-
plsql.test_package.varchar2_variable2 =
|
43
|
-
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")
|
44
50
|
end
|
45
51
|
|
46
52
|
it "should get VARCHAR2 variable default value" do
|
47
|
-
expect(plsql.test_package.varchar2_default).to eq(
|
48
|
-
expect(plsql.test_package.varchar2_default2).to eq(
|
49
|
-
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")
|
50
56
|
end
|
51
57
|
|
52
58
|
describe "with character or byte limit" do
|
@@ -64,56 +70,46 @@ describe "Package variables /" do
|
|
64
70
|
end
|
65
71
|
|
66
72
|
it "should set and get VARCHAR2(n CHAR) variable" do
|
67
|
-
plsql.test_package.varchar2_3_char =
|
68
|
-
expect(plsql.test_package.varchar2_3_char).to eq(
|
69
|
-
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/)
|
70
76
|
end
|
71
77
|
|
72
78
|
it "should set and get VARCHAR2(n BYTE) variable" do
|
73
|
-
plsql.test_package.varchar2_3_byte =
|
74
|
-
expect(plsql.test_package.varchar2_3_byte).to eq(
|
75
|
-
expect { plsql.test_package.varchar2_3_byte =
|
76
|
-
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/)
|
77
83
|
end
|
78
84
|
|
79
85
|
end
|
80
86
|
|
81
87
|
it "should set and get CHAR variable" do
|
82
|
-
plsql.test_package.char_variable =
|
83
|
-
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)
|
84
90
|
end
|
85
91
|
|
86
92
|
it "should set and get NVARCHAR2 variable" do
|
87
|
-
plsql.test_package.nvarchar2_variable =
|
88
|
-
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")
|
89
95
|
end
|
90
96
|
|
91
97
|
it "should set and get NCHAR variable" do
|
92
|
-
plsql.test_package.nchar_variable =
|
93
|
-
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)
|
94
100
|
end
|
95
101
|
|
96
102
|
end
|
97
103
|
|
98
|
-
|
104
|
+
shared_examples "Numeric" do |ora_data_type, default, class_, given, expected|
|
105
|
+
|
99
106
|
before(:all) do
|
100
107
|
plsql.connect! CONNECTION_PARAMS
|
101
108
|
plsql.execute <<-SQL
|
102
109
|
CREATE OR REPLACE PACKAGE test_package IS
|
103
|
-
|
104
|
-
integer10_variable NUMBER(10);
|
105
|
-
integer10_default NUMBER(10) := 1;
|
106
|
-
number_variable NUMBER;
|
107
|
-
number_with_scale NUMBER(15,2);
|
108
|
-
pls_int_variable PLS_INTEGER;
|
109
|
-
bin_int_variable BINARY_INTEGER;
|
110
|
+
numeric_var #{ora_data_type}#{default ? ':= ' + default.to_s : nil};
|
110
111
|
END;
|
111
112
|
SQL
|
112
|
-
plsql.execute <<-SQL
|
113
|
-
CREATE OR REPLACE PACKAGE BODY test_package IS
|
114
|
-
END;
|
115
|
-
SQL
|
116
|
-
|
117
113
|
end
|
118
114
|
|
119
115
|
after(:all) do
|
@@ -121,45 +117,41 @@ describe "Package variables /" do
|
|
121
117
|
plsql.logoff
|
122
118
|
end
|
123
119
|
|
124
|
-
it "should
|
125
|
-
plsql.test_package.
|
126
|
-
|
127
|
-
expect(plsql.test_package.integer_variable).to eq(1)
|
128
|
-
end
|
120
|
+
it "should get #{ora_data_type} variable default value" do
|
121
|
+
expect(plsql.test_package.numeric_var).to eq(default)
|
122
|
+
end if default
|
129
123
|
|
130
|
-
it "should
|
131
|
-
plsql.test_package.
|
132
|
-
expect(plsql.test_package.
|
133
|
-
expect(plsql.test_package.integer10_variable).to eq(1)
|
124
|
+
it "should get #{ora_data_type} variable type mapped to #{class_.to_s}" do
|
125
|
+
plsql.test_package.numeric_var = given
|
126
|
+
expect(plsql.test_package.numeric_var).to be_a class_
|
134
127
|
end
|
135
128
|
|
136
|
-
it "should get
|
137
|
-
|
129
|
+
it "should set and get #{ora_data_type} variable" do
|
130
|
+
plsql.test_package.numeric_var = given
|
131
|
+
expect(plsql.test_package.numeric_var).to eq(expected)
|
138
132
|
end
|
139
133
|
|
140
|
-
|
141
|
-
plsql.test_package.pls_int_variable = 1
|
142
|
-
expect(plsql.test_package.pls_int_variable).to be_a Fixnum
|
143
|
-
expect(plsql.test_package.pls_int_variable).to eq(1)
|
144
|
-
end
|
145
|
-
|
146
|
-
it "should set and get BINARY_INTEGER variable" do
|
147
|
-
plsql.test_package.bin_int_variable = 1
|
148
|
-
expect(plsql.test_package.bin_int_variable).to be_a Fixnum
|
149
|
-
expect(plsql.test_package.bin_int_variable).to eq(1)
|
150
|
-
end
|
151
|
-
|
152
|
-
it "should set and get NUMBER variable" do
|
153
|
-
plsql.test_package.number_variable = 123.456
|
154
|
-
expect(plsql.test_package.number_variable).to be_a BigDecimal
|
155
|
-
expect(plsql.test_package.number_variable).to eq(123.456)
|
156
|
-
end
|
134
|
+
end
|
157
135
|
|
158
|
-
|
159
|
-
|
160
|
-
|
136
|
+
[
|
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
|
+
].each do |row|
|
151
|
+
ora_data_type, default, class_, given, expected = row.values
|
152
|
+
describe ora_data_type + (default ? " with default" : "") do
|
153
|
+
include_examples "Numeric", ora_data_type, default, class_, given, expected
|
161
154
|
end
|
162
|
-
|
163
155
|
end
|
164
156
|
|
165
157
|
describe "Date and Time" do
|
@@ -178,8 +170,8 @@ describe "Package variables /" do
|
|
178
170
|
CREATE OR REPLACE PACKAGE BODY test_package IS
|
179
171
|
END;
|
180
172
|
SQL
|
181
|
-
@date = Time.local(2009,12,21)
|
182
|
-
@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)
|
183
175
|
end
|
184
176
|
|
185
177
|
after(:all) do
|
@@ -241,17 +233,17 @@ describe "Package variables /" do
|
|
241
233
|
end
|
242
234
|
|
243
235
|
it "should set and get CLOB variable" do
|
244
|
-
plsql.test_package.clob_variable =
|
245
|
-
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")
|
246
238
|
end
|
247
239
|
|
248
240
|
it "should get CLOB variable default value" do
|
249
|
-
expect(plsql.test_package.clob_default).to eq(
|
241
|
+
expect(plsql.test_package.clob_default).to eq("default")
|
250
242
|
end
|
251
243
|
|
252
244
|
it "should set and get NCLOB variable" do
|
253
|
-
plsql.test_package.nclob_variable =
|
254
|
-
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")
|
255
247
|
end
|
256
248
|
|
257
249
|
it "should set and get BLOB variable" do
|
@@ -299,12 +291,12 @@ describe "Package variables /" do
|
|
299
291
|
end
|
300
292
|
|
301
293
|
it "should set and get VARCHAR2 variable" do
|
302
|
-
plsql.test_package.first_name =
|
303
|
-
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")
|
304
296
|
end
|
305
297
|
|
306
298
|
it "should set and get DATE variable" do
|
307
|
-
today = Time.local(2009,12,22)
|
299
|
+
today = Time.local(2009, 12, 22)
|
308
300
|
plsql.test_package.hire_date = today
|
309
301
|
expect(plsql.test_package.hire_date).to eq(today)
|
310
302
|
end
|
@@ -337,7 +329,7 @@ describe "Package variables /" do
|
|
337
329
|
end
|
338
330
|
|
339
331
|
it "should get VARCHAR2 constant" do
|
340
|
-
expect(plsql.test_package.string_constant).to eq(
|
332
|
+
expect(plsql.test_package.string_constant).to eq("constant")
|
341
333
|
end
|
342
334
|
|
343
335
|
it "should raise error when trying to set constant" do
|
@@ -379,14 +371,14 @@ describe "Package variables /" do
|
|
379
371
|
phones t_phones
|
380
372
|
)
|
381
373
|
SQL
|
382
|
-
@phones = [{:
|
374
|
+
@phones = [{ type: "mobile", phone_number: "123456" }, { type: "home", phone_number: "654321" }]
|
383
375
|
@employee = {
|
384
|
-
:
|
385
|
-
:
|
386
|
-
:
|
387
|
-
:
|
388
|
-
:
|
389
|
-
:
|
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
|
390
382
|
}
|
391
383
|
|
392
384
|
plsql.execute <<-SQL
|
@@ -441,10 +433,10 @@ describe "Package variables /" do
|
|
441
433
|
)
|
442
434
|
SQL
|
443
435
|
@employee = {
|
444
|
-
:
|
445
|
-
:
|
446
|
-
:
|
447
|
-
:
|
436
|
+
employee_id: 1,
|
437
|
+
first_name: "First",
|
438
|
+
last_name: "Last",
|
439
|
+
hire_date: Time.local(2000, 01, 31)
|
448
440
|
}
|
449
441
|
|
450
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
|