rsim-activerecord-oracle_enhanced-adapter 1.2.0.1 → 1.2.0.2

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.
@@ -346,8 +346,11 @@ module ActiveRecord
346
346
  # unescaped table name should start with letter and
347
347
  # contain letters, digits, _, $ or #
348
348
  # can be prefixed with schema name
349
+ # CamelCase table names should be quoted
349
350
  def self.valid_table_name?(name)
350
- name.to_s =~ /^([A-Z_0-9]+\.)?[A-Z][A-Z_0-9\$#]*$/i ? true : false
351
+ name = name.to_s
352
+ name =~ /^([A-Za-z_0-9]+\.)?[a-z][a-z_0-9\$#]*$/ ||
353
+ name =~ /^([A-Za-z_0-9]+\.)?[A-Z][A-Z_0-9\$#]*$/ ? true : false
351
354
  end
352
355
 
353
356
  # abstract_adapter calls quote_column_name from quote_table_name, so prevent that
@@ -556,7 +559,7 @@ module ActiveRecord
556
559
 
557
560
  # RSI: changed select from user_tables to all_tables - much faster in large data dictionaries
558
561
  def tables(name = nil) #:nodoc:
559
- select_all("select lower(table_name) name from all_tables where owner = sys_context('userenv','session_user')").map {|t| t['name']}
562
+ select_all("select decode(table_name,upper(table_name),lower(table_name),table_name) name from all_tables where owner = sys_context('userenv','session_user')").map {|t| t['name']}
560
563
  end
561
564
 
562
565
  def indexes(table_name, name = nil) #:nodoc:
@@ -822,12 +825,12 @@ module ActiveRecord
822
825
  end
823
826
 
824
827
  def structure_dump #:nodoc:
825
- s = select_all("select sequence_name from user_sequences").inject("") do |structure, seq|
828
+ s = select_all("select sequence_name from user_sequences order by 1").inject("") do |structure, seq|
826
829
  structure << "create sequence #{seq.to_a.first.last};\n\n"
827
830
  end
828
831
 
829
832
  # RSI: changed select from user_tables to all_tables - much faster in large data dictionaries
830
- select_all("select table_name from all_tables where owner = sys_context('userenv','session_user')").inject(s) do |structure, table|
833
+ select_all("select table_name from all_tables where owner = sys_context('userenv','session_user') order by 1").inject(s) do |structure, table|
831
834
  ddl = "create table #{table.to_a.first.last} (\n "
832
835
  cols = select_all(%Q{
833
836
  select column_name, data_type, data_length, char_used, char_length, data_precision, data_scale, data_default, nullable
@@ -855,12 +858,12 @@ module ActiveRecord
855
858
  end
856
859
 
857
860
  def structure_drop #:nodoc:
858
- s = select_all("select sequence_name from user_sequences").inject("") do |drop, seq|
861
+ s = select_all("select sequence_name from user_sequences order by 1").inject("") do |drop, seq|
859
862
  drop << "drop sequence #{seq.to_a.first.last};\n\n"
860
863
  end
861
864
 
862
865
  # RSI: changed select from user_tables to all_tables - much faster in large data dictionaries
863
- select_all("select table_name from all_tables where owner = sys_context('userenv','session_user')").inject(s) do |drop, table|
866
+ select_all("select table_name from all_tables where owner = sys_context('userenv','session_user') order by 1").inject(s) do |drop, table|
864
867
  drop << "drop table #{table.to_a.first.last} cascade constraints;\n\n"
865
868
  end
866
869
  end
@@ -1,11 +1,7 @@
1
1
  module ActiveRecord #:nodoc:
2
2
  module ConnectionAdapters #:nodoc:
3
3
  module OracleEnhancedVersion #:nodoc:
4
- MAJOR = 1
5
- MINOR = 2
6
- TINY = 0
7
-
8
- STRING = [MAJOR, MINOR, TINY].join('.')
4
+ VERSION = '1.2.0'
9
5
  end
10
6
  end
11
7
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{activerecord-oracle_enhanced-adapter}
5
- s.version = "1.2.0.1"
5
+ s.version = "1.2.0.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Raimonds Simanovskis"]
@@ -47,6 +47,17 @@ describe "OracleEnhancedAdapter schema dump" do
47
47
  @new_conn = ActiveRecord::Base.oracle_enhanced_connection(CONNECTION_PARAMS)
48
48
  @new_conn.class.should == ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter
49
49
  end
50
+
51
+ after(:all) do
52
+ # Workaround for undefining callback that was defined by JDBC adapter
53
+ if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
54
+ ActiveRecord::Base.class_eval do
55
+ def after_save_with_oracle_lob
56
+ nil
57
+ end
58
+ end
59
+ end
60
+ end
50
61
 
51
62
  unless defined?(RUBY_ENGINE) && RUBY_ENGINE == "ruby" && RUBY_VERSION =~ /^1\.9/
52
63
  it "should return the same tables list as original oracle adapter" do
@@ -66,11 +77,11 @@ describe "OracleEnhancedAdapter schema dump" do
66
77
  end
67
78
 
68
79
  it "should return the same structure dump as original oracle adapter" do
69
- @new_conn.structure_dump.should == @old_conn.structure_dump
80
+ @new_conn.structure_dump.split(";\n\n").sort.should == @old_conn.structure_dump.split(";\n\n").sort
70
81
  end
71
82
 
72
83
  it "should return the same structure drop as original oracle adapter" do
73
- @new_conn.structure_drop.should == @old_conn.structure_drop
84
+ @new_conn.structure_drop.split(";\n\n").sort.should == @old_conn.structure_drop.split(";\n\n").sort
74
85
  end
75
86
  end
76
87
 
@@ -530,14 +541,26 @@ describe "OracleEnhancedAdapter table quoting" do
530
541
  end
531
542
  end
532
543
 
544
+ def create_camel_case_table
545
+ ActiveRecord::Schema.define do
546
+ suppress_messages do
547
+ create_table "CamelCase" do |t|
548
+ t.string :name
549
+ t.integer :foo
550
+ end
551
+ end
552
+ end
553
+ end
554
+
533
555
  after(:each) do
534
556
  ActiveRecord::Schema.define do
535
557
  suppress_messages do
536
- drop_table "warehouse-things"
558
+ drop_table "warehouse-things" rescue nil
559
+ drop_table "CamelCase" rescue nil
537
560
  end
538
561
  end
539
- Object.send(:remove_const, "WarehouseThing")
540
- ActiveRecord::Base.table_name_prefix = nil
562
+ Object.send(:remove_const, "WarehouseThing") rescue nil
563
+ Object.send(:remove_const, "CamelCase") rescue nil
541
564
  end
542
565
 
543
566
  it "should allow creation of a table with non alphanumeric characters" do
@@ -548,6 +571,20 @@ describe "OracleEnhancedAdapter table quoting" do
548
571
 
549
572
  wh = WarehouseThing.create!(:name => "Foo", :foo => 2)
550
573
  wh.id.should_not be_nil
574
+
575
+ @conn.tables.should include("warehouse-things")
576
+ end
577
+
578
+ it "should allow creation of a table with CamelCase name" do
579
+ create_camel_case_table
580
+ class ::CamelCase < ActiveRecord::Base
581
+ set_table_name "CamelCase"
582
+ end
583
+
584
+ cc = CamelCase.create!(:name => "Foo", :foo => 2)
585
+ cc.id.should_not be_nil
586
+
587
+ @conn.tables.should include("CamelCase")
551
588
  end
552
589
 
553
590
  end
data/spec/spec_helper.rb CHANGED
@@ -58,28 +58,35 @@ module LoggerSpecHelper
58
58
  end
59
59
  end
60
60
 
61
+ DATABASE_NAME = ENV['DATABASE_NAME'] || 'orcl'
62
+ DATABASE_HOST = ENV['DATABASE_HOST'] || 'localhost'
63
+ DATABASE_PORT = ENV['DATABASE_PORT'] || 1521
64
+ DATABASE_USER = ENV['DATABASE_USER'] || 'hr'
65
+ DATABASE_PASSWORD = ENV['DATABASE_PASSWORD'] || 'hr'
66
+ DATABASE_SYS_PASSWORD = ENV['DATABASE_SYS_PASSWORD'] || 'admin'
67
+
61
68
  CONNECTION_PARAMS = {
62
69
  :adapter => "oracle_enhanced",
63
- :database => "xe",
64
- :host => "ubuntu810",
65
- :username => "hr",
66
- :password => "hr"
70
+ :database => DATABASE_NAME,
71
+ :host => DATABASE_HOST,
72
+ :username => DATABASE_USER,
73
+ :password => DATABASE_PASSWORD
67
74
  }
68
75
 
69
76
  JDBC_CONNECTION_PARAMS = {
70
77
  :adapter => "jdbc",
71
78
  :driver => "oracle.jdbc.driver.OracleDriver",
72
- :url => "jdbc:oracle:thin:@ubuntu810:1521:XE",
73
- :username => "hr",
74
- :password => "hr"
79
+ :url => "jdbc:oracle:thin:@#{DATABASE_HOST}:#{DATABASE_PORT}:#{DATABASE_NAME}",
80
+ :username => DATABASE_USER,
81
+ :password => DATABASE_PASSWORD
75
82
  }
76
83
 
77
84
  SYS_CONNECTION_PARAMS = {
78
85
  :adapter => "oracle_enhanced",
79
- :database => "xe",
80
- :host => "ubuntu810",
86
+ :database => DATABASE_NAME,
87
+ :host => DATABASE_HOST,
81
88
  :username => "sys",
82
- :password => "manager",
89
+ :password => DATABASE_SYS_PASSWORD,
83
90
  :privilege => "SYSDBA"
84
91
  }
85
92
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rsim-activerecord-oracle_enhanced-adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0.1
4
+ version: 1.2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Raimonds Simanovskis