ruby-plsql 0.5.3 → 0.6.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.
@@ -37,6 +37,13 @@ describe "Schema connection" do
37
37
  expect(plsql.schema_name).to eq(DATABASE_USERS_AND_PASSWORDS[0][0].upcase)
38
38
  end
39
39
 
40
+ it 'should match altered current_schema in database session' do
41
+ plsql.connection = @conn
42
+ expected_current_schema = DATABASE_USERS_AND_PASSWORDS[1][0]
43
+ plsql.execute "ALTER SESSION set current_schema=#{expected_current_schema}"
44
+ expect(plsql.schema_name).to eq(expected_current_schema.upcase)
45
+ end
46
+
40
47
  it "should return new schema name after reconnection" do
41
48
  plsql.connection = @conn
42
49
  expect(plsql.schema_name).to eq(DATABASE_USERS_AND_PASSWORDS[0][0].upcase)
@@ -86,7 +93,7 @@ describe "Connection with connect!" do
86
93
  it "should not connect with wrong port number" do
87
94
  expect {
88
95
  plsql.connect! @username, @password, :host => @host, :port => 9999, :database => @database
89
- }.to raise_error(/no listener|could not establish the connection/)
96
+ }.to raise_error(/ORA-12541|could not establish the connection/)
90
97
  end
91
98
 
92
99
  it "should connect with one Hash parameter" do
@@ -95,10 +102,11 @@ describe "Connection with connect!" do
95
102
  expect(plsql.schema_name).to eq(@username.upcase)
96
103
  end
97
104
 
98
- it "should set session time zone from TZ environment variable" do
105
+ it "should set session time zone from ORA_SDTZ environment variable" do
99
106
  plsql.connect! @username, @password, @database
100
- expect(plsql.connection.time_zone).to eq(ENV['TZ'])
101
- end
107
+ expect(plsql.connection.time_zone).to eq(ENV['ORA_SDTZ'])
108
+ end if ENV['ORA_SDTZ']
109
+
102
110
 
103
111
  it "should set session time zone from :time_zone parameter" do
104
112
  plsql.connect! :username => @username, :password => @password, :database => @database, :time_zone => 'EET'
@@ -220,6 +228,15 @@ describe "ActiveRecord connection" do
220
228
  plsql.activerecord_class = TestModel
221
229
  expect(plsql.schema_name).to eq('HR')
222
230
  end
231
+
232
+ it "should safely close cursors in threaded environment" do
233
+ expect {
234
+ t1 = Thread.new { plsql.dbms_lock.sleep(1) }.tap { |t| t.abort_on_exception = true }
235
+ t2 = Thread.new { plsql.dbms_lock.sleep(2) }.tap { |t| t.abort_on_exception = true }
236
+ [t2, t1].each { |t| t.join }
237
+ }.not_to raise_error
238
+ end
239
+
223
240
  end if defined?(ActiveRecord)
224
241
 
225
242
  describe "DBMS_OUTPUT logging" do
@@ -21,7 +21,7 @@ describe "SQL statements /" do
21
21
  CREATE TABLE test_employees (
22
22
  employee_id NUMBER(15),
23
23
  first_name VARCHAR2(50),
24
- last_name VARCHAR2(50),
24
+ last_name VARCHAR(50),
25
25
  hire_date DATE
26
26
  )
27
27
  SQL
@@ -8,7 +8,7 @@ describe "Table" do
8
8
  CREATE TABLE test_employees (
9
9
  employee_id NUMBER(15) NOT NULL,
10
10
  first_name VARCHAR2(50),
11
- last_name VARCHAR2(50),
11
+ last_name VARCHAR(50),
12
12
  hire_date DATE,
13
13
  created_at TIMESTAMP,
14
14
  status VARCHAR2(1) DEFAULT 'N'
@@ -35,7 +35,7 @@ describe "Table" do
35
35
  CREATE TABLE test_employees2 (
36
36
  employee_id NUMBER(15) NOT NULL,
37
37
  first_name VARCHAR2(50),
38
- last_name VARCHAR2(50),
38
+ last_name VARCHAR(50),
39
39
  hire_date DATE DEFAULT SYSDATE,
40
40
  address t_address,
41
41
  phones t_phones
@@ -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 VARCHAR2(50),
83
+ last_name VARCHAR(50),
84
84
  hire_date DATE,
85
85
  address t_address,
86
86
  phones t_phones
@@ -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,6 +34,11 @@ 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
43
  plsql.test_package.varchar2_variable = 'abc'
38
44
  expect(plsql.test_package.varchar2_variable).to eq('abc')
@@ -95,25 +101,15 @@ describe "Package variables /" do
95
101
 
96
102
  end
97
103
 
98
- describe "Numeric" do
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
- integer_variable INTEGER;
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 set and get INTEGER variable" do
125
- plsql.test_package.integer_variable = 1
126
- expect(plsql.test_package.integer_variable).to be_a Fixnum
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 set and get integer variable with precision" do
131
- plsql.test_package.integer10_variable = 1
132
- expect(plsql.test_package.integer10_variable).to be_a Fixnum
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 integer variable default value" do
137
- expect(plsql.test_package.integer10_default).to eq(1)
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
- it "should set and get PLS_INTEGER variable" do
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
- it "should set and get NUMBER variable with scale" do
159
- plsql.test_package.number_with_scale = 123.456
160
- expect(plsql.test_package.number_with_scale).to eq(123.46) # rounding to two decimal digits
136
+ [
137
+ {:ora_data_type => 'INTEGER', :default => nil, :class => Fixnum, :given => 1, :expected => 1},
138
+ {:ora_data_type => 'NUMBER(10)', :default => nil, :class => Fixnum, :given => 1, :expected => 1},
139
+ {:ora_data_type => 'NUMBER(10)', :default => 5, :class => Fixnum, :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 => Fixnum, :given => 1, :expected => 1},
143
+ {:ora_data_type => 'BINARY_INTEGER', :default => nil, :class => Fixnum, :given => 1, :expected => 1},
144
+ {:ora_data_type => 'SIMPLE_INTEGER', :default => 10, :class => Fixnum, :given => 1, :expected => 1},
145
+ {:ora_data_type => 'NATURAL', :default => nil, :class => Fixnum, :given => 1, :expected => 1},
146
+ {:ora_data_type => 'NATURALN', :default => 0, :class => Fixnum, :given => 1, :expected => 1},
147
+ {:ora_data_type => 'POSITIVE', :default => nil, :class => Fixnum, :given => 1, :expected => 1},
148
+ {:ora_data_type => 'POSITIVEN', :default => 5, :class => Fixnum, :given => 1, :expected => 1},
149
+ {:ora_data_type => 'SIGNTYPE', :default => -1, :class => Fixnum, :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
@@ -111,8 +111,3 @@ class Hash
111
111
  self.reject {|key, value| !whitelist.include?(key) }
112
112
  end unless method_defined?(:only)
113
113
  end
114
-
115
- # set default time zone in TZ environment variable
116
- # which will be used to set session time zone
117
- ENV['TZ'] ||= 'Europe/Riga'
118
- # ENV['TZ'] ||= 'UTC'
@@ -0,0 +1,2 @@
1
+ create user arunit identified by arunit;
2
+ grant create session to arunit;
@@ -0,0 +1,14 @@
1
+ # Template file should be copied to locale_support.rb to be automatically included by code
2
+ #
3
+
4
+ # Set Oracle Database session timezone, if not already set in env variable
5
+ # This setting needs to be in place to make sure that Oracle properly represents the timestamp format on your local machine.
6
+ # Do not use 'OS_TZ' value or fixed offset values like '05:00', for daylight saving-enabled timezones.
7
+ # See: http://docs.oracle.com/cd/E18283_01/server.112/e10729/ch4datetime.htm#CBBEEAFB
8
+ # The setting cannot be derived directly from operating system or ruby, as different timezone names are used.
9
+ ENV['ORA_SDTZ'] ||= 'Europe/Riga'
10
+ #Sets the Ruby timezone to be used, if not already set in env variable
11
+ ENV['TZ'] ||= 'Europe/Riga'
12
+ #Sets the Language, locale and encoding settings to be used by Oracle session, if not already set in env variable
13
+ ENV['NLS_LANG'] ||= 'AMERICAN_AMERICA.AL32UTF8'
14
+
@@ -0,0 +1,2 @@
1
+ alter user hr identified by hr account unlock;
2
+ grant execute on dbms_lock to hr;
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-plsql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Raimonds Simanovskis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-07 00:00:00.000000000 Z
11
+ date: 2016-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jeweler
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '3.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec_junit_formatter
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: activerecord
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -64,7 +78,7 @@ dependencies:
64
78
  requirements:
65
79
  - - "<"
66
80
  - !ruby/object:Gem::Version
67
- version: 1.6.0
81
+ version: 1.7.0
68
82
  - - ">="
69
83
  - !ruby/object:Gem::Version
70
84
  version: 1.4.1
@@ -74,7 +88,7 @@ dependencies:
74
88
  requirements:
75
89
  - - "<"
76
90
  - !ruby/object:Gem::Version
77
- version: 1.6.0
91
+ version: 1.7.0
78
92
  - - ">="
79
93
  - !ruby/object:Gem::Version
80
94
  version: 1.4.1
@@ -98,14 +112,14 @@ dependencies:
98
112
  requirements:
99
113
  - - "~>"
100
114
  - !ruby/object:Gem::Version
101
- version: 2.1.2
115
+ version: '2.1'
102
116
  type: :development
103
117
  prerelease: false
104
118
  version_requirements: !ruby/object:Gem::Requirement
105
119
  requirements:
106
120
  - - "~>"
107
121
  - !ruby/object:Gem::Version
108
- version: 2.1.2
122
+ version: '2.1'
109
123
  description: |
110
124
  ruby-plsql gem provides simple Ruby API for calling Oracle PL/SQL procedures.
111
125
  It could be used both for accessing Oracle PL/SQL API procedures in legacy applications
@@ -116,6 +130,13 @@ extensions: []
116
130
  extra_rdoc_files:
117
131
  - README.md
118
132
  files:
133
+ - ".travis.yml"
134
+ - ".travis/oracle/LICENSE"
135
+ - ".travis/oracle/README.md"
136
+ - ".travis/oracle/download.js"
137
+ - ".travis/oracle/download.sh"
138
+ - ".travis/oracle/install.sh"
139
+ - ".travis/setup_accounts.sh"
119
140
  - Gemfile
120
141
  - History.txt
121
142
  - License.txt
@@ -155,8 +176,11 @@ files:
155
176
  - spec/plsql/view_spec.rb
156
177
  - spec/spec.opts
157
178
  - spec/spec_helper.rb
179
+ - spec/support/create_arunit_user.sql
180
+ - spec/support/custom_config.rb.sample
158
181
  - spec/support/file_check_script.sh
159
182
  - spec/support/test_db.rb
183
+ - spec/support/unlock_and_setup_hr_user.sql
160
184
  homepage: http://github.com/rsim/ruby-plsql
161
185
  licenses: []
162
186
  metadata: {}
@@ -176,7 +200,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
176
200
  version: '0'
177
201
  requirements: []
178
202
  rubyforge_project:
179
- rubygems_version: 2.4.6
203
+ rubygems_version: 2.5.1
180
204
  signing_key:
181
205
  specification_version: 4
182
206
  summary: Ruby API for calling Oracle PL/SQL procedures.