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/schema_spec.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe "Schema" do
|
4
|
-
|
4
|
+
|
5
5
|
it "should create Schema object" do
|
6
6
|
expect(plsql.class).to eq(PLSQL::Schema)
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
end
|
10
10
|
|
11
11
|
describe "Schema connection" do
|
12
|
-
|
12
|
+
|
13
13
|
before(:each) do
|
14
14
|
@conn = get_connection
|
15
15
|
end
|
@@ -31,13 +31,13 @@ describe "Schema connection" do
|
|
31
31
|
plsql(:hr).connection = @conn
|
32
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
37
|
expect(plsql.schema_name).to eq(DATABASE_USERS_AND_PASSWORDS[0][0].upcase)
|
38
38
|
end
|
39
39
|
|
40
|
-
it
|
40
|
+
it "should match altered current_schema in database session" do
|
41
41
|
plsql.connection = @conn
|
42
42
|
expected_current_schema = DATABASE_USERS_AND_PASSWORDS[1][0]
|
43
43
|
plsql.execute "ALTER SESSION set current_schema=#{expected_current_schema}"
|
@@ -78,39 +78,38 @@ describe "Connection with connect!" do
|
|
78
78
|
end
|
79
79
|
|
80
80
|
it "should connect with username, password, host, port and database name" do
|
81
|
-
plsql.connect! @username, @password, :
|
81
|
+
plsql.connect! @username, @password, host: @host, port: @port, database: @database_service
|
82
82
|
expect(plsql.connection).not_to be_nil
|
83
83
|
expect(plsql.schema_name).to eq(@username.upcase)
|
84
84
|
end
|
85
85
|
|
86
86
|
it "should connect with username, password, host, database name and default port" do
|
87
87
|
skip "Non-default port used for test database" unless @port == 1521
|
88
|
-
plsql.connect! @username, @password, :
|
88
|
+
plsql.connect! @username, @password, host: @host, database: @database_service
|
89
89
|
expect(plsql.connection).not_to be_nil
|
90
90
|
expect(plsql.schema_name).to eq(@username.upcase)
|
91
91
|
end
|
92
92
|
|
93
93
|
it "should not connect with wrong port number" do
|
94
94
|
expect {
|
95
|
-
plsql.connect! @username, @password, :
|
95
|
+
plsql.connect! @username, @password, host: @host, port: 9999, database: @database
|
96
96
|
}.to raise_error(/ORA-12541|could not establish the connection/)
|
97
97
|
end
|
98
98
|
|
99
99
|
it "should connect with one Hash parameter" do
|
100
|
-
plsql.connect! :
|
100
|
+
plsql.connect! username: @username, password: @password, database: @database
|
101
101
|
expect(plsql.connection).not_to be_nil
|
102
102
|
expect(plsql.schema_name).to eq(@username.upcase)
|
103
103
|
end
|
104
104
|
|
105
105
|
it "should set session time zone from ORA_SDTZ environment variable" do
|
106
106
|
plsql.connect! @username, @password, @database
|
107
|
-
expect(plsql.connection.time_zone).to eq(ENV[
|
108
|
-
end if ENV[
|
109
|
-
|
107
|
+
expect(plsql.connection.time_zone).to eq(ENV["ORA_SDTZ"])
|
108
|
+
end if ENV["ORA_SDTZ"]
|
110
109
|
|
111
110
|
it "should set session time zone from :time_zone parameter" do
|
112
|
-
plsql.connect! :
|
113
|
-
expect(plsql.connection.time_zone).to eq(
|
111
|
+
plsql.connect! username: @username, password: @password, database: @database, time_zone: "EET"
|
112
|
+
expect(plsql.connection.time_zone).to eq("EET")
|
114
113
|
end
|
115
114
|
|
116
115
|
end
|
@@ -133,7 +132,7 @@ describe "Named Schema" do
|
|
133
132
|
end
|
134
133
|
|
135
134
|
it "should return schema name" do
|
136
|
-
expect(plsql.hr.schema_name).to eq(
|
135
|
+
expect(plsql.hr.schema_name).to eq("HR")
|
137
136
|
end
|
138
137
|
|
139
138
|
it "should not find named schema if specified twice" do
|
@@ -147,8 +146,8 @@ describe "Schema commit and rollback" do
|
|
147
146
|
plsql.connection = @conn = get_connection
|
148
147
|
plsql.connection.autocommit = false
|
149
148
|
plsql.execute "CREATE TABLE test_commit (dummy VARCHAR2(100))"
|
150
|
-
@data = {:
|
151
|
-
@data2 = {:
|
149
|
+
@data = { dummy: "test" }
|
150
|
+
@data2 = { dummy: "test2" }
|
152
151
|
end
|
153
152
|
|
154
153
|
after(:all) do
|
@@ -175,10 +174,10 @@ describe "Schema commit and rollback" do
|
|
175
174
|
|
176
175
|
it "should create savepoint and rollback to savepoint" do
|
177
176
|
plsql.test_commit.insert @data
|
178
|
-
plsql.savepoint
|
177
|
+
plsql.savepoint "test"
|
179
178
|
plsql.test_commit.insert @data2
|
180
179
|
expect(plsql.test_commit.all).to eq([@data, @data2])
|
181
|
-
plsql.rollback_to
|
180
|
+
plsql.rollback_to "test"
|
182
181
|
expect(plsql.test_commit.all).to eq([@data])
|
183
182
|
end
|
184
183
|
|
@@ -207,7 +206,7 @@ describe "ActiveRecord connection" do
|
|
207
206
|
end
|
208
207
|
|
209
208
|
it "should return schema name" do
|
210
|
-
expect(plsql.schema_name).to eq(
|
209
|
+
expect(plsql.schema_name).to eq("HR")
|
211
210
|
end
|
212
211
|
|
213
212
|
it "should use ActiveRecord::Base.default_timezone as default" do
|
@@ -221,12 +220,12 @@ describe "ActiveRecord connection" do
|
|
221
220
|
|
222
221
|
it "should accept inherited ActiveRecord class" do
|
223
222
|
plsql.activerecord_class = TestBaseModel
|
224
|
-
expect(plsql.schema_name).to eq(
|
223
|
+
expect(plsql.schema_name).to eq("HR")
|
225
224
|
end
|
226
225
|
|
227
226
|
it "should accept subclass of inherited ActiveRecord class" do
|
228
227
|
plsql.activerecord_class = TestModel
|
229
|
-
expect(plsql.schema_name).to eq(
|
228
|
+
expect(plsql.schema_name).to eq("HR")
|
230
229
|
end
|
231
230
|
|
232
231
|
it "should safely close cursors in threaded environment" do
|
data/spec/plsql/sequence_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe "SQL statements /" do
|
4
4
|
before(:all) do
|
@@ -35,10 +35,10 @@ describe "SQL statements /" do
|
|
35
35
|
SQL
|
36
36
|
@employees = (1..10).map do |i|
|
37
37
|
{
|
38
|
-
:
|
39
|
-
:
|
40
|
-
:
|
41
|
-
:
|
38
|
+
employee_id: i,
|
39
|
+
first_name: "First #{i}",
|
40
|
+
last_name: "Last #{i}",
|
41
|
+
hire_date: Time.local(2000, 01, i)
|
42
42
|
}
|
43
43
|
end
|
44
44
|
plsql.connection.prefetch_rows = 100
|
data/spec/plsql/table_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe "Table" do
|
4
4
|
before(:all) do
|
@@ -43,28 +43,28 @@ describe "Table" do
|
|
43
43
|
SQL
|
44
44
|
@employees = (1..10).map do |i|
|
45
45
|
{
|
46
|
-
:
|
47
|
-
:
|
48
|
-
:
|
49
|
-
:
|
50
|
-
:
|
51
|
-
:
|
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
52
|
}
|
53
53
|
end
|
54
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]}}
|
55
|
+
@employees_all_values = @employees.map { |e| @employees_all_fields.map { |f| e[f] } }
|
56
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 = {:
|
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
59
|
|
60
60
|
@employees2 = (1..10).map do |i|
|
61
61
|
{
|
62
|
-
:
|
63
|
-
:
|
64
|
-
:
|
65
|
-
:
|
66
|
-
:
|
67
|
-
:
|
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
68
|
}
|
69
69
|
end
|
70
70
|
end
|
@@ -137,49 +137,49 @@ describe "Table" do
|
|
137
137
|
end
|
138
138
|
|
139
139
|
it "should get columns metadata for table" do
|
140
|
-
expect(plsql.test_employees.columns).to eq(
|
141
|
-
:
|
142
|
-
:
|
143
|
-
:
|
144
|
-
:
|
145
|
-
:
|
146
|
-
:
|
147
|
-
:
|
148
|
-
:
|
149
|
-
:
|
150
|
-
:
|
151
|
-
:
|
152
|
-
:
|
153
|
-
:
|
154
|
-
:
|
155
|
-
:
|
156
|
-
:
|
157
|
-
:
|
158
|
-
:
|
159
|
-
|
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
160
|
end
|
161
161
|
|
162
162
|
it "should get columns metadata for table with object columns" do
|
163
|
-
expect(plsql.test_employees2.columns).to eq(
|
164
|
-
:
|
165
|
-
:
|
166
|
-
:
|
167
|
-
:
|
168
|
-
:
|
169
|
-
:
|
170
|
-
:
|
171
|
-
:
|
172
|
-
:
|
173
|
-
:
|
174
|
-
:
|
175
|
-
:
|
176
|
-
:
|
177
|
-
:
|
178
|
-
:
|
179
|
-
:
|
180
|
-
:
|
181
|
-
:
|
182
|
-
|
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
183
|
end
|
184
184
|
|
185
185
|
end
|
@@ -192,12 +192,12 @@ describe "Table" do
|
|
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
|
-
expect(plsql.test_employees.all).to eq([@employees.first.merge(:
|
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
|
-
expect(plsql.test_employees.all).to eq([@employees.first.merge(:
|
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
|
@@ -245,7 +245,7 @@ describe "Table" do
|
|
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
|
-
expect(plsql.test_employees.all).to eq(@employees.map{|e| e.merge(@employee_default_values)})
|
248
|
+
expect(plsql.test_employees.all).to eq(@employees.map { |e| e.merge(@employee_default_values) })
|
249
249
|
end
|
250
250
|
|
251
251
|
end
|
@@ -263,17 +263,17 @@ describe "Table" do
|
|
263
263
|
it "should select all records in table" do
|
264
264
|
expect(plsql.test_employees.select(:all, "ORDER BY employee_id")).to eq(@employees)
|
265
265
|
expect(plsql.test_employees.all("ORDER BY employee_id")).to eq(@employees)
|
266
|
-
expect(plsql.test_employees.all(:
|
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
270
|
expect(plsql.test_employees.select(:first, "WHERE employee_id = :1", @employees.first[:employee_id])).to eq(@employees.first)
|
271
271
|
expect(plsql.test_employees.first("WHERE employee_id = :1", @employees.first[:employee_id])).to eq(@employees.first)
|
272
|
-
expect(plsql.test_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
|
-
expect(plsql.test_employees.all(:
|
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
|
@@ -282,7 +282,7 @@ describe "Table" do
|
|
282
282
|
employee[:hire_date] = nil
|
283
283
|
plsql.test_employees.insert employee
|
284
284
|
expect(plsql.test_employees.first("WHERE hire_date IS NULL")).to eq(employee)
|
285
|
-
expect(plsql.test_employees.first(:
|
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
|
-
expect(plsql.test_employees.first(:
|
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,7 +298,7 @@ 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
|
-
expect(plsql.test_employees.all(:
|
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
|
@@ -317,26 +317,26 @@ describe "Table" do
|
|
317
317
|
it "should update a record in table" do
|
318
318
|
employee_id = @employees.first[:employee_id]
|
319
319
|
plsql.test_employees.insert @employees.first
|
320
|
-
plsql.test_employees.update :
|
321
|
-
expect(plsql.test_employees.first(:
|
320
|
+
plsql.test_employees.update first_name: "Test", where: { employee_id: employee_id }
|
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
|
-
plsql.test_employees.update :
|
328
|
-
expect(plsql.test_employees.first(:
|
327
|
+
plsql.test_employees.update first_name: "Test", where: "employee_id = #{employee_id}"
|
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
|
-
expect(employee[:first_name]).not_to eq(
|
331
|
+
expect(employee[:first_name]).not_to eq("Test")
|
332
332
|
end
|
333
333
|
end
|
334
334
|
|
335
335
|
it "should update all records in table" do
|
336
336
|
plsql.test_employees.insert @employees
|
337
|
-
plsql.test_employees.update :
|
337
|
+
plsql.test_employees.update first_name: "Test"
|
338
338
|
plsql.test_employees.all do |employee|
|
339
|
-
expect(employee[:first_name]).to eq(
|
339
|
+
expect(employee[:first_name]).to eq("Test")
|
340
340
|
end
|
341
341
|
end
|
342
342
|
|
@@ -344,8 +344,8 @@ describe "Table" do
|
|
344
344
|
employee = @employees2[0]
|
345
345
|
employee2 = @employees2[1]
|
346
346
|
plsql.test_employees2.insert employee
|
347
|
-
plsql.test_employees2.update :
|
348
|
-
updated_employee = plsql.test_employees2.first(:
|
347
|
+
plsql.test_employees2.update address: employee2[:address], phones: employee2[:phones], where: { employee_id: employee[:employee_id] }
|
348
|
+
updated_employee = plsql.test_employees2.first(employee_id: employee[:employee_id])
|
349
349
|
expect(updated_employee[:address]).to eq(employee2[:address])
|
350
350
|
expect(updated_employee[:phones]).to eq(employee2[:phones])
|
351
351
|
end
|
@@ -356,9 +356,9 @@ describe "Table" do
|
|
356
356
|
it "should delete record from table" do
|
357
357
|
employee_id = @employees.first[:employee_id]
|
358
358
|
plsql.test_employees.insert @employees
|
359
|
-
plsql.test_employees.delete :
|
360
|
-
expect(plsql.test_employees.first(:
|
361
|
-
expect(plsql.test_employees.all(:
|
359
|
+
plsql.test_employees.delete employee_id: 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
|
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
|
@@ -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
|