oracle_enhanced_plus_xmltype 0.0.4 → 0.0.5

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.
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour
data/Gemfile CHANGED
@@ -3,7 +3,11 @@ source "http://rubygems.org"
3
3
  # Specify your gem's dependencies in oracle_enhanced_plus_xmltype.gemspec
4
4
  gemspec
5
5
 
6
- gem 'rails', '3.1.0.rc4'
6
+ gem 'rails', '3.1.3'
7
7
  gem 'ruby-oci8', '2.0.6'
8
8
  #gem 'activerecord-oracle_enhanced-adapter', '1.3.2'
9
- gem 'activerecord-oracle_enhanced-adapter', :git => "https://github.com/rsim/oracle-enhanced.git"
9
+ gem 'activerecord-oracle_enhanced-adapter'
10
+
11
+ group :development, :test do
12
+ gem "ruby-debug"
13
+ end
@@ -17,6 +17,17 @@ if defined?(::Rails::Railtie)
17
17
 
18
18
  ActiveRecord::ConnectionAdapters::OracleEnhancedColumn.class_eval do
19
19
  self.send :include, ::OracleEnhancedColumnWithXmltype
20
+ #ugly, i know.
21
+ def initialize(name, default, sql_type = nil, null = true, table_name = nil, forced_column_type = nil, virtual=false) #:nodoc:
22
+ @table_name = table_name
23
+ @forced_column_type = forced_column_type
24
+ @virtual = sql_type =~ /xmltype/i ? false : virtual
25
+ super(name, default, sql_type, null)
26
+ @virtual_column_data_default = default.inspect if @virtual
27
+ # Is column NCHAR or NVARCHAR2 (will need to use N'...' value quoting for these data types)?
28
+ # Define only when needed as adapter "quote" method will check at first if instance variable is defined.
29
+ @nchar = true if @type == :string && sql_type[0,1] == 'N'
30
+ end
20
31
  end
21
32
 
22
33
  ActiveRecord::ConnectionAdapters::OracleEnhancedOCIConnection.class_eval do
@@ -1,9 +1,11 @@
1
+
1
2
  module OracleEnhancedColumnWithXmltype
2
3
  module ClassMethods
3
4
 
4
5
  end
5
6
 
6
7
  module InstanceMethods
8
+
7
9
  def simplified_type(field_type)
8
10
  forced_column_type ||
9
11
  case field_type
@@ -1,3 +1,3 @@
1
1
  module OracleEnhancedPlusXmltype
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -12,8 +12,8 @@ Gem::Specification.new do |s|
12
12
  s.description = %q{add XMLTYPE to active record oracle adapter}
13
13
  s.add_development_dependency "rspec", ">= 2.6.0"
14
14
  s.rubyforge_project = "oracle_enhanced_plus_xmltype"
15
- s.add_dependency "rails", ">= 3.0.0"
16
- #s.add_dependency "activerecord-oracle_enhanced-adapter", ">= 1.3.2"
15
+ s.add_dependency "rails", ">= 3.1.0"
16
+ # s.add_dependency "activerecord-oracle_enhanced-adapter", ">= 1.3.2"
17
17
  s.files = `git ls-files`.split("\n")
18
18
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
@@ -0,0 +1,135 @@
1
+ require 'spec_helper'
2
+
3
+ describe "OracleEnhancedAdapter with xml type connection sanity check" do
4
+
5
+ it "should connect to database" do
6
+ ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
7
+ ActiveRecord::Base.connection.should_not be_nil
8
+ ActiveRecord::Base.connection.class.should == ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter
9
+ end
10
+
11
+ it "should connect to database as SYSDBA" do
12
+ ActiveRecord::Base.establish_connection(SYS_CONNECTION_PARAMS)
13
+ ActiveRecord::Base.connection.should_not be_nil
14
+ ActiveRecord::Base.connection.class.should == ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter
15
+ end
16
+
17
+ it "should be active after connection to database" do
18
+ ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
19
+ ActiveRecord::Base.connection.should be_active
20
+ end
21
+
22
+ it "should not be active after disconnection to database" do
23
+ ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
24
+ ActiveRecord::Base.connection.disconnect!
25
+ ActiveRecord::Base.connection.should_not be_active
26
+ end
27
+
28
+ it "should be active after reconnection to database" do
29
+ ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
30
+ ActiveRecord::Base.connection.reconnect!
31
+ ActiveRecord::Base.connection.should be_active
32
+ end
33
+
34
+ end
35
+
36
+ describe "OracleEnhancedAdapter" do
37
+
38
+
39
+
40
+ describe "test constant update" do
41
+ it "should update NATIVE_DATABASE_TYPES to include the xmltype type" do
42
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter::NATIVE_DATABASE_TYPES.keys.should include(:xmltype)
43
+ end
44
+
45
+ it "should update NATIVE_DATABASE_TYPES_BOOLEAN_STRINGS to include the xmltype type" do
46
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter::NATIVE_DATABASE_TYPES_BOOLEAN_STRINGS.keys.should include(:xmltype)
47
+ end
48
+ end
49
+
50
+ describe "test 4k limit" do
51
+ before(:all) do
52
+ set_test_employees
53
+ end
54
+
55
+ after(:all) do
56
+ remove_test_employees
57
+ end
58
+
59
+ it "should let data in that's larger than 4k" do
60
+ pending "need to fix 4k problem"
61
+ t = TestEmployee.new(:first_name => "some", :last_name => "name" , :data => test_data.merge(:bigKey => (1..(1024*1024)).map { |e| "#{rand(100)}" }.join("\n") ))
62
+ t.save
63
+ end
64
+ end
65
+
66
+ describe "test quote xml override" do
67
+ before(:all) do
68
+ set_test_employees
69
+ end
70
+
71
+ after(:all) do
72
+ remove_test_employees
73
+ end
74
+
75
+
76
+ before(:each) do
77
+ @xml_column = TestEmployee.columns.find {|c| c.type == :xmltype}
78
+ end
79
+
80
+ it "should quote xml" do
81
+ TestEmployee.connection.should_receive(:quote_xml)
82
+ t = TestEmployee.create(:first_name => "some", :last_name => "name" , :data => test_data)
83
+ end
84
+
85
+ it "should throw error if xml value isnt a hash" do
86
+ lambda { TestEmployee.create(:first_name => "some name", :last_name => "name", :data => "somestring") }.should raise_error( /XMLTYPE column must be of type Hash/)
87
+ end
88
+
89
+ it "should throw an error if metadata is not a valid hash when saved" do
90
+ t = TestEmployee.new(:first_name => "some name", :last_name => "name", :data => (1..10).to_a)
91
+ expect { t.save }.to raise_error( /XMLTYPE column must be of type Hash/)
92
+ end
93
+
94
+
95
+ it "should return nil if value is nil" do
96
+ TestEmployee.connection.should_receive(:quote_xml).and_return(nil)
97
+ TestEmployee.create(:first_name => "some name", :last_name => "name", :data => nil)
98
+ end
99
+
100
+ it "should return the hash exactly as it was received", :wip => true do
101
+ t = TestEmployee.create(:first_name => "some", :last_name => "name" , :data => test_data)
102
+ t.data.stringify_keys.sort.should == test_data.stringify_keys.sort
103
+ end
104
+
105
+
106
+ end
107
+
108
+ describe "test column changes" do
109
+ before(:all) do
110
+ set_test_employees
111
+ end
112
+
113
+ after(:all) do
114
+ remove_test_employees
115
+ end
116
+
117
+
118
+ before(:each) do
119
+ @xml_column = TestEmployee.columns.find {|c| c.type == :xmltype}
120
+ end
121
+
122
+ it "should not set virtual for xmltypes" do
123
+ @xml_column.should_not be_virtual
124
+ end
125
+
126
+ it "should set virtual for reg virtual columns" do
127
+ TestEmployee.columns.find {|c| c.name == "percent" }.should be_virtual
128
+ end
129
+
130
+ it "should set virtual default data for reg virtual columns" do
131
+ TestEmployee.columns.find {|c| c.name == "percent" }.virtual_column_data_default.should_not be_blank
132
+ end
133
+ end
134
+
135
+ end
@@ -0,0 +1,63 @@
1
+ require 'rubygems'
2
+ require "bundler"
3
+ Bundler.setup(:default, :development)
4
+
5
+ $:.unshift(File.expand_path('../lib', __FILE__))
6
+
7
+ require 'rspec'
8
+
9
+ require "rails/all"
10
+ require 'activerecord-oracle_enhanced-adapter'
11
+ require 'oracle_enhanced_plus_xmltype.rb'
12
+
13
+ DATABASE_NAME = ENV['DATABASE_NAME'] || 'orcl'
14
+ DATABASE_HOST = ENV['DATABASE_HOST'] || "192.168.1.7"
15
+ DATABASE_PORT = ENV['DATABASE_PORT']
16
+ DATABASE_USER = ENV['DATABASE_USER'] || 'oracle_enhanced'
17
+ DATABASE_PASSWORD = ENV['DATABASE_PASSWORD'] || 'oracle_enhanced'
18
+ DATABASE_SYS_PASSWORD = ENV['DATABASE_SYS_PASSWORD'] || 'oracle'
19
+
20
+ CONNECTION_PARAMS = {
21
+ :adapter => "oracle_enhanced",
22
+ :database => DATABASE_NAME,
23
+ :host => DATABASE_HOST,
24
+ :port => DATABASE_PORT,
25
+ :username => DATABASE_USER,
26
+ :password => DATABASE_PASSWORD,
27
+ :encoding => "utf8"
28
+ }
29
+
30
+ SYS_CONNECTION_PARAMS = {
31
+ :adapter => "oracle_enhanced",
32
+ :database => DATABASE_NAME,
33
+ :host => DATABASE_HOST,
34
+ :port => DATABASE_PORT,
35
+ :username => "sys",
36
+ :password => DATABASE_SYS_PASSWORD,
37
+ :privilege => "SYSDBA"
38
+ }
39
+
40
+ SYSTEM_CONNECTION_PARAMS = {
41
+ :adapter => "oracle_enhanced",
42
+ :database => DATABASE_NAME,
43
+ :host => DATABASE_HOST,
44
+ :port => DATABASE_PORT,
45
+ :username => "system",
46
+ :password => DATABASE_SYS_PASSWORD
47
+ }
48
+
49
+ DATABASE_NON_DEFAULT_TABLESPACE = ENV['DATABASE_NON_DEFAULT_TABLESPACE'] || "SYSTEM"
50
+
51
+ # Set default $KCODE to UTF8
52
+ $KCODE = "UTF8"
53
+
54
+ # set default time zone in TZ environment variable
55
+ # which will be used to set session time zone
56
+ ENV['TZ'] ||= 'Europe/Riga'
57
+
58
+ Dir[File.join(File.dirname(__FILE__), "support/**/*.rb")].each {|f| require f}
59
+ include SchemaSpecHelper
60
+ include DataSpecHelper
61
+
62
+
63
+
@@ -0,0 +1,11 @@
1
+
2
+ module DataSpecHelper
3
+ def test_data
4
+ {
5
+ :key => "some_value",
6
+ :arrayKey => ("a".."z").to_a,
7
+ :hashKey => {:innerKey => "innerValue", :innerKey2 => "inners"}
8
+ }
9
+ end
10
+
11
+ end
@@ -0,0 +1,35 @@
1
+ module SchemaSpecHelper
2
+ def schema_define(&block)
3
+ ActiveRecord::Schema.define do
4
+ suppress_messages do
5
+ instance_eval(&block)
6
+ end
7
+ end
8
+ end
9
+
10
+ def remove_test_employees
11
+ ActiveRecord::Base.connection.execute "DROP TABLE test_employees"
12
+ ActiveRecord::Base.connection.execute "DROP SEQUENCE test_employees_seq"
13
+ Object.send(:remove_const, "TestEmployee")
14
+ end
15
+
16
+ def set_test_employees
17
+ @conn = ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
18
+ # debugger
19
+ schema_define do
20
+ expr = "( numerator/NULLIF(denominator,0) )*100"
21
+ create_table :test_employees, :force => true do |t|
22
+ t.string :first_name
23
+ t.string :last_name
24
+ t.integer :numerator, :default=>0
25
+ t.integer :denominator, :default=>0
26
+ t.virtual :percent, :default => expr
27
+ t.xmltype :data
28
+ # t.virtual :employee_name, :default => "first_name || ' ' || last_name"
29
+ end
30
+ end
31
+ cls = Class.new(ActiveRecord::Base)
32
+ Object.const_set "TestEmployee", cls
33
+
34
+ end
35
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oracle_enhanced_plus_xmltype
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
5
- prerelease: false
4
+ hash: 21
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 5
10
+ version: 0.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jake Varghese
@@ -15,13 +15,13 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-08-22 00:00:00 -05:00
18
+ date: 2012-03-05 00:00:00 -06:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: rspec
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
23
+ type: :development
24
+ version_requirements: &id001 !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
27
  - - ">="
@@ -32,24 +32,24 @@ dependencies:
32
32
  - 6
33
33
  - 0
34
34
  version: 2.6.0
35
- type: :development
36
- version_requirements: *id001
35
+ prerelease: false
36
+ requirement: *id001
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: rails
39
- prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
39
+ type: :runtime
40
+ version_requirements: &id002 !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
43
  - - ">="
44
44
  - !ruby/object:Gem::Version
45
- hash: 7
45
+ hash: 3
46
46
  segments:
47
47
  - 3
48
+ - 1
48
49
  - 0
49
- - 0
50
- version: 3.0.0
51
- type: :runtime
52
- version_requirements: *id002
50
+ version: 3.1.0
51
+ prerelease: false
52
+ requirement: *id002
53
53
  description: add XMLTYPE to active record oracle adapter
54
54
  email:
55
55
  - jake3030@yahoo.com
@@ -61,6 +61,7 @@ extra_rdoc_files: []
61
61
 
62
62
  files:
63
63
  - .gitignore
64
+ - .rspec
64
65
  - Gemfile
65
66
  - Rakefile
66
67
  - lib/oracle_enhanced_plus_xmltype.rb
@@ -70,6 +71,10 @@ files:
70
71
  - lib/oracle_enhanced_plus_xmltype/oracle_enhanced_schema_definitions_with_xmltype.rb
71
72
  - lib/oracle_enhanced_plus_xmltype/version.rb
72
73
  - oracle_enhanced_plus_xmltype.gemspec
74
+ - spec/oracle_enhanced_plus_xmltype/oracle_enhanced_adapter_with_xmltype_spec.rb
75
+ - spec/spec_helper.rb
76
+ - spec/support/data_spec_helper.rb
77
+ - spec/support/schema_spec_helper.rb
73
78
  has_rdoc: true
74
79
  homepage: ""
75
80
  licenses: []
@@ -100,9 +105,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
105
  requirements: []
101
106
 
102
107
  rubyforge_project: oracle_enhanced_plus_xmltype
103
- rubygems_version: 1.3.7
108
+ rubygems_version: 1.5.2
104
109
  signing_key:
105
110
  specification_version: 3
106
111
  summary: add XMLTYPE to active record oracle adapter
107
- test_files: []
108
-
112
+ test_files:
113
+ - spec/oracle_enhanced_plus_xmltype/oracle_enhanced_adapter_with_xmltype_spec.rb
114
+ - spec/spec_helper.rb
115
+ - spec/support/data_spec_helper.rb
116
+ - spec/support/schema_spec_helper.rb