Skip to content
This repository
Browse code

add test for eager loading fully-qualified table names with oracle

This test addresses improper detection of valid table names by the
Relation#tables_in_string method on Oracle.  To make the test fail,
setup test/config.yml use an oracle database with a username like
'ops$user', or any valid variation that has non-word characters
in it.  It should pass otherwise.
  • Loading branch information...
commit d1f75d1123a5f353d3724b93b340e0d52b779b4e 1 parent 37b77c6
Simon Chiang authored August 09, 2011
10  activerecord/test/cases/associations/eager_test.rb
@@ -22,12 +22,15 @@
22 22
 require 'models/club'
23 23
 require 'models/categorization'
24 24
 require 'models/sponsor'
  25
+require 'models/emp'
  26
+require 'models/dept'
25 27
 
26 28
 class EagerAssociationTest < ActiveRecord::TestCase
27 29
   fixtures :posts, :comments, :authors, :author_addresses, :categories, :categories_posts,
28 30
             :companies, :accounts, :tags, :taggings, :people, :readers, :categorizations,
29 31
             :owners, :pets, :author_favorites, :jobs, :references, :subscribers, :subscriptions, :books,
30  
-            :developers, :projects, :developers_projects, :members, :memberships, :clubs, :sponsors
  32
+            :developers, :projects, :developers_projects, :members, :memberships, :clubs, :sponsors,
  33
+            :emps, :depts
31 34
 
32 35
   def setup
33 36
     # preheat table existence caches
@@ -80,6 +83,11 @@ def test_with_two_tables_in_from_without_getting_double_quoted
80 83
     assert_equal 2, posts.first.comments.size
81 84
   end
82 85
 
  86
+  def test_with_full_qualified_table_name
  87
+    assert_equal "Research", Emp.find(1, :include => :dept).dept.nombre
  88
+    assert_equal "Research", Emp.find(:first, :include => :dept).dept.nombre
  89
+  end
  90
+
83 91
   def test_loading_with_multiple_associations
84 92
     posts = Post.find(:all, :include => [ :comments, :author, :categories ], :order => "posts.id")
85 93
     assert_equal 2, posts.first.comments.size
3  activerecord/test/fixtures/depts.yml
... ...
@@ -0,0 +1,3 @@
  1
+research:
  2
+  id: 1
  3
+  name: Research
4  activerecord/test/fixtures/emps.yml
... ...
@@ -0,0 +1,4 @@
  1
+doej:
  2
+  id: 1
  3
+  name: John Doe
  4
+  dept_id: 1
5  activerecord/test/models/dept.rb
... ...
@@ -0,0 +1,5 @@
  1
+class Dept < ActiveRecord::Base
  2
+  if connection.class.to_s == "ActiveRecord::ConnectionAdapters::OracleAdapter"
  3
+    set_table_name "#{connection.current_user.downcase}.depts"
  4
+  end
  5
+end
6  activerecord/test/models/emp.rb
... ...
@@ -0,0 +1,6 @@
  1
+class Emp < ActiveRecord::Base
  2
+  if connection.class.to_s == "ActiveRecord::ConnectionAdapters::OracleAdapter"
  3
+    set_table_name "#{connection.current_user.downcase}.emps"
  4
+  end
  5
+  belongs_to :dept, :select => "id, name nombre"
  6
+end
8  activerecord/test/schema/schema.rb
@@ -712,6 +712,14 @@ def create_table(*args, &block)
712 712
     t.string 'a$b'
713 713
   end
714 714
 
  715
+  create_table :emps, :force => true do |t|
  716
+    t.string :name
  717
+    t.integer :dept_id
  718
+  end
  719
+  create_table :depts, :force => true do |t|
  720
+    t.string :name
  721
+  end
  722
+
715 723
   except 'SQLite' do
716 724
     # fk_test_has_fk should be before fk_test_has_pk
717 725
     create_table :fk_test_has_fk, :force => true do |t|

0 notes on commit d1f75d1

Please sign in to comment.
Something went wrong with that request. Please try again.