Skip to content
This repository
Browse code

Merge branch 'oracle_enhanced'

  • Loading branch information...
commit 06afa48c8c7bb7bf75f9e7ae48e06528f8ff82ed 2 parents 010a0c9 + 5f0c425
Jeremy Kemper authored August 07, 2009

Showing 23 changed files with 335 additions and 113 deletions. Show diff stats Hide diff stats

  1. 25  activerecord/test/cases/adapter_test.rb
  2. 6  activerecord/test/cases/associations/belongs_to_associations_test.rb
  3. 7  activerecord/test/cases/associations/eager_test.rb
  4. 6  activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
  5. 80  activerecord/test/cases/associations/has_many_associations_test.rb
  6. 10  activerecord/test/cases/associations/join_model_test.rb
  7. 14  activerecord/test/cases/attribute_methods_test.rb
  8. 46  activerecord/test/cases/autosave_association_test.rb
  9. 7  activerecord/test/cases/calculations_test.rb
  10. 9  activerecord/test/cases/database_statements_test.rb
  11. 2  activerecord/test/cases/finder_test.rb
  12. 3  activerecord/test/cases/inheritance_test.rb
  13. 14  activerecord/test/cases/invalid_date_test.rb
  14. 3  activerecord/test/cases/method_scoping_test.rb
  15. 63  activerecord/test/cases/migration_test.rb
  16. 3  activerecord/test/cases/named_scope_test.rb
  17. 7  activerecord/test/cases/query_cache_test.rb
  18. 12  activerecord/test/cases/schema_dumper_test.rb
  19. 55  activerecord/test/connections/native_oracle/connection.rb
  20. 8  activerecord/test/models/company.rb
  21. 10  activerecord/test/models/subject.rb
  22. 27  activerecord/test/schema/oracle_specific_schema.rb
  23. 31  activerecord/test/schema/schema.rb
25  activerecord/test/cases/adapter_test.rb
@@ -112,23 +112,14 @@ def test_reset_table_with_non_integer_pk
112 112
 
113 113
   def test_add_limit_offset_should_sanitize_sql_injection_for_limit_without_comas
114 114
     sql_inject = "1 select * from schema"
115  
-      assert_equal " LIMIT 1", @connection.add_limit_offset!("", :limit=>sql_inject)
116  
-    if current_adapter?(:MysqlAdapter)
117  
-      assert_equal " LIMIT 7, 1", @connection.add_limit_offset!("", :limit=>sql_inject, :offset=>7)
118  
-    else
119  
-      assert_equal " LIMIT 1 OFFSET 7", @connection.add_limit_offset!("", :limit=>sql_inject, :offset=>7)
120  
-    end
  115
+    assert_no_match /schema/, @connection.add_limit_offset!("", :limit=>sql_inject)
  116
+    assert_no_match /schema/, @connection.add_limit_offset!("", :limit=>sql_inject, :offset=>7)
121 117
   end
122 118
 
123 119
   def test_add_limit_offset_should_sanitize_sql_injection_for_limit_with_comas
124 120
     sql_inject = "1, 7 procedure help()"
125  
-    if current_adapter?(:MysqlAdapter)
126  
-      assert_equal " LIMIT 1,7", @connection.add_limit_offset!("", :limit=>sql_inject)
127  
-      assert_equal " LIMIT 7, 1", @connection.add_limit_offset!("", :limit=> '1 ; DROP TABLE USERS', :offset=>7)
128  
-    else
129  
-      assert_equal " LIMIT 1,7", @connection.add_limit_offset!("", :limit=>sql_inject)
130  
-      assert_equal " LIMIT 1,7 OFFSET 7", @connection.add_limit_offset!("", :limit=>sql_inject, :offset=>7)
131  
-    end
  121
+    assert_no_match /procedure/, @connection.add_limit_offset!("", :limit=>sql_inject)
  122
+    assert_no_match /procedure/, @connection.add_limit_offset!("", :limit=>sql_inject, :offset=>7)
132 123
   end
133 124
 
134 125
   def test_uniqueness_violations_are_translated_to_specific_exception
@@ -141,7 +132,13 @@ def test_uniqueness_violations_are_translated_to_specific_exception
141 132
   def test_foreign_key_violations_are_translated_to_specific_exception
142 133
     unless @connection.adapter_name == 'SQLite'
143 134
       assert_raises(ActiveRecord::InvalidForeignKey) do
144  
-        @connection.execute "INSERT INTO fk_test_has_fk (fk_id) VALUES (0)"
  135
+        # Oracle adapter uses prefetched primary key values from sequence and passes them to connection adapter insert method
  136
+        if @connection.prefetch_primary_key?
  137
+          id_value = @connection.next_sequence_value(@connection.default_sequence_name("fk_test_has_fk", "id"))
  138
+          @connection.execute "INSERT INTO fk_test_has_fk (id, fk_id) VALUES (#{id_value},0)"
  139
+        else
  140
+          @connection.execute "INSERT INTO fk_test_has_fk (fk_id) VALUES (0)"
  141
+        end
145 142
       end
146 143
     end
147 144
   end
6  activerecord/test/cases/associations/belongs_to_associations_test.rb
@@ -293,7 +293,8 @@ def test_assignment_before_child_saved_with_primary_key
293 293
 
294 294
   def test_new_record_with_foreign_key_but_no_object
295 295
     c = Client.new("firm_id" => 1)
296  
-    assert_equal Firm.find(:first), c.firm_with_basic_id
  296
+    # sometimes tests on Oracle fail if ORDER BY is not provided therefore add always :order with :first
  297
+    assert_equal Firm.find(:first, :order => "id"), c.firm_with_basic_id
297 298
   end
298 299
 
299 300
   def test_forgetting_the_load_when_foreign_key_enters_late
@@ -301,7 +302,8 @@ def test_forgetting_the_load_when_foreign_key_enters_late
301 302
     assert_nil c.firm_with_basic_id
302 303
 
303 304
     c.firm_id = 1
304  
-    assert_equal Firm.find(:first), c.firm_with_basic_id
  305
+    # sometimes tests on Oracle fail if ORDER BY is not provided therefore add always :order with :first
  306
+    assert_equal Firm.find(:first, :order => "id"), c.firm_with_basic_id
305 307
   end
306 308
 
307 309
   def test_field_name_same_as_foreign_key
7  activerecord/test/cases/associations/eager_test.rb
@@ -813,7 +813,12 @@ def test_preload_has_many_using_primary_key
813 813
 
814 814
   def test_include_has_many_using_primary_key
815 815
     expected = Firm.find(1).clients_using_primary_key.sort_by &:name
816  
-    firm = Firm.find 1, :include => :clients_using_primary_key, :order => 'clients_using_primary_keys_companies.name'
  816
+    # Oracle adapter truncates alias to 30 characters
  817
+    if current_adapter?(:OracleAdapter)
  818
+      firm = Firm.find 1, :include => :clients_using_primary_key, :order => 'clients_using_primary_keys_companies'[0,30]+'.name'
  819
+    else
  820
+      firm = Firm.find 1, :include => :clients_using_primary_key, :order => 'clients_using_primary_keys_companies.name'
  821
+    end
817 822
     assert_no_queries do
818 823
       assert_equal expected, firm.clients_using_primary_key
819 824
     end
6  activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
@@ -284,12 +284,14 @@ def test_create_by_new_record
284 284
   end
285 285
 
286 286
   def test_creation_respects_hash_condition
287  
-    post = categories(:general).post_with_conditions.build(:body => '')
  287
+    # in Oracle '' is saved as null therefore need to save ' ' in not null column
  288
+    post = categories(:general).post_with_conditions.build(:body => ' ')
288 289
 
289 290
     assert        post.save
290 291
     assert_equal  'Yet Another Testing Title', post.title
291 292
 
292  
-    another_post = categories(:general).post_with_conditions.create(:body => '')
  293
+    # in Oracle '' is saved as null therefore need to save ' ' in not null column
  294
+    another_post = categories(:general).post_with_conditions.create(:body => ' ')
293 295
 
294 296
     assert        !another_post.new_record?
295 297
     assert_equal  'Yet Another Testing Title', another_post.title
80  activerecord/test/cases/associations/has_many_associations_test.rb
@@ -24,28 +24,29 @@ def force_signal37_to_load_all_clients_of_firm
24 24
     companies(:first_firm).clients_of_firm.each {|f| }
25 25
   end
26 26
 
  27
+  # sometimes tests on Oracle fail if ORDER BY is not provided therefore add always :order with :first
27 28
   def test_counting_with_counter_sql
28  
-    assert_equal 2, Firm.find(:first).clients.count
  29
+    assert_equal 2, Firm.find(:first, :order => "id").clients.count
29 30
   end
30 31
 
31 32
   def test_counting
32  
-    assert_equal 2, Firm.find(:first).plain_clients.count
  33
+    assert_equal 2, Firm.find(:first, :order => "id").plain_clients.count
33 34
   end
34 35
 
35 36
   def test_counting_with_empty_hash_conditions
36  
-    assert_equal 2, Firm.find(:first).plain_clients.count(:conditions => {})
  37
+    assert_equal 2, Firm.find(:first, :order => "id").plain_clients.count(:conditions => {})
37 38
   end
38 39
 
39 40
   def test_counting_with_single_conditions
40  
-    assert_equal 1, Firm.find(:first).plain_clients.count(:conditions => ['name=?', "Microsoft"])
  41
+    assert_equal 1, Firm.find(:first, :order => "id").plain_clients.count(:conditions => ['name=?', "Microsoft"])
41 42
   end
42 43
 
43 44
   def test_counting_with_single_hash
44  
-    assert_equal 1, Firm.find(:first).plain_clients.count(:conditions => {:name => "Microsoft"})
  45
+    assert_equal 1, Firm.find(:first, :order => "id").plain_clients.count(:conditions => {:name => "Microsoft"})
45 46
   end
46 47
 
47 48
   def test_counting_with_column_name_and_hash
48  
-    assert_equal 2, Firm.find(:first).plain_clients.count(:name)
  49
+    assert_equal 2, Firm.find(:first, :order => "id").plain_clients.count(:name)
49 50
   end
50 51
 
51 52
   def test_counting_with_association_limit
@@ -55,12 +56,12 @@ def test_counting_with_association_limit
55 56
   end
56 57
 
57 58
   def test_finding
58  
-    assert_equal 2, Firm.find(:first).clients.length
  59
+    assert_equal 2, Firm.find(:first, :order => "id").clients.length
59 60
   end
60 61
 
61 62
   def test_find_with_blank_conditions
62 63
     [[], {}, nil, ""].each do |blank|
63  
-      assert_equal 2, Firm.find(:first).clients.find(:all, :conditions => blank).size
  64
+      assert_equal 2, Firm.find(:first, :order => "id").clients.find(:all, :conditions => blank).size
64 65
     end
65 66
   end
66 67
 
@@ -115,52 +116,53 @@ def test_cant_save_has_many_readonly_association
115 116
   end
116 117
 
117 118
   def test_triple_equality
118  
-    assert !(Array === Firm.find(:first).clients)
119  
-    assert Firm.find(:first).clients === Array
  119
+    # sometimes tests on Oracle fail if ORDER BY is not provided therefore add always :order with :first
  120
+    assert !(Array === Firm.find(:first, :order => "id").clients)
  121
+    assert Firm.find(:first, :order => "id").clients === Array
120 122
   end
121 123
 
122 124
   def test_finding_default_orders
123  
-    assert_equal "Summit", Firm.find(:first).clients.first.name
  125
+    assert_equal "Summit", Firm.find(:first, :order => "id").clients.first.name
124 126
   end
125 127
 
126 128
   def test_finding_with_different_class_name_and_order
127  
-    assert_equal "Microsoft", Firm.find(:first).clients_sorted_desc.first.name
  129
+    assert_equal "Microsoft", Firm.find(:first, :order => "id").clients_sorted_desc.first.name
128 130
   end
129 131
 
130 132
   def test_finding_with_foreign_key
131  
-    assert_equal "Microsoft", Firm.find(:first).clients_of_firm.first.name
  133
+    assert_equal "Microsoft", Firm.find(:first, :order => "id").clients_of_firm.first.name
132 134
   end
133 135
 
134 136
   def test_finding_with_condition
135  
-    assert_equal "Microsoft", Firm.find(:first).clients_like_ms.first.name
  137
+    assert_equal "Microsoft", Firm.find(:first, :order => "id").clients_like_ms.first.name
136 138
   end
137 139
 
138 140
   def test_finding_with_condition_hash
139  
-    assert_equal "Microsoft", Firm.find(:first).clients_like_ms_with_hash_conditions.first.name
  141
+    assert_equal "Microsoft", Firm.find(:first, :order => "id").clients_like_ms_with_hash_conditions.first.name
140 142
   end
141 143
 
142 144
   def test_finding_using_primary_key
143  
-    assert_equal "Summit", Firm.find(:first).clients_using_primary_key.first.name
  145
+    assert_equal "Summit", Firm.find(:first, :order => "id").clients_using_primary_key.first.name
144 146
   end
145 147
 
146 148
   def test_finding_using_sql
147  
-    firm = Firm.find(:first)
  149
+    firm = Firm.find(:first, :order => "id")
148 150
     first_client = firm.clients_using_sql.first
149 151
     assert_not_nil first_client
150 152
     assert_equal "Microsoft", first_client.name
151 153
     assert_equal 1, firm.clients_using_sql.size
152  
-    assert_equal 1, Firm.find(:first).clients_using_sql.size
  154
+    assert_equal 1, Firm.find(:first, :order => "id").clients_using_sql.size
153 155
   end
154 156
 
155 157
   def test_counting_using_sql
156  
-    assert_equal 1, Firm.find(:first).clients_using_counter_sql.size
157  
-    assert Firm.find(:first).clients_using_counter_sql.any?
158  
-    assert_equal 0, Firm.find(:first).clients_using_zero_counter_sql.size
159  
-    assert !Firm.find(:first).clients_using_zero_counter_sql.any?
  158
+    assert_equal 1, Firm.find(:first, :order => "id").clients_using_counter_sql.size
  159
+    assert Firm.find(:first, :order => "id").clients_using_counter_sql.any?
  160
+    assert_equal 0, Firm.find(:first, :order => "id").clients_using_zero_counter_sql.size
  161
+    assert !Firm.find(:first, :order => "id").clients_using_zero_counter_sql.any?
160 162
   end
161 163
 
162 164
   def test_counting_non_existant_items_using_sql
163  
-    assert_equal 0, Firm.find(:first).no_clients_using_counter_sql.size
  165
+    assert_equal 0, Firm.find(:first, :order => "id").no_clients_using_counter_sql.size
164 166
   end
165 167
 
166 168
   def test_counting_using_finder_sql
@@ -183,7 +185,7 @@ def test_belongs_to_sanity
183 185
   end
184 186
 
185 187
   def test_find_ids
186  
-    firm = Firm.find(:first)
  188
+    firm = Firm.find(:first, :order => "id")
187 189
 
188 190
     assert_raise(ActiveRecord::RecordNotFound) { firm.clients.find }
189 191
 
@@ -203,7 +205,7 @@ def test_find_ids
203 205
   end
204 206
 
205 207
   def test_find_string_ids_when_using_finder_sql
206  
-    firm = Firm.find(:first)
  208
+    firm = Firm.find(:first, :order => "id")
207 209
 
208 210
     client = firm.clients_using_finder_sql.find("2")
209 211
     assert_kind_of Client, client
@@ -219,7 +221,7 @@ def test_find_string_ids_when_using_finder_sql
219 221
   end
220 222
 
221 223
   def test_find_all
222  
-    firm = Firm.find(:first)
  224
+    firm = Firm.find(:first, :order => "id")
223 225
     assert_equal 2, firm.clients.find(:all, :conditions => "#{QUOTED_TYPE} = 'Client'").length
224 226
     assert_equal 1, firm.clients.find(:all, :conditions => "name = 'Summit'").length
225 227
   end
@@ -264,24 +266,25 @@ def test_find_in_batches
264 266
   end
265 267
 
266 268
   def test_find_all_sanitized
267  
-    firm = Firm.find(:first)
  269
+    # sometimes tests on Oracle fail if ORDER BY is not provided therefore add always :order with :first
  270
+    firm = Firm.find(:first, :order => "id")
268 271
     summit = firm.clients.find(:all, :conditions => "name = 'Summit'")
269 272
     assert_equal summit, firm.clients.find(:all, :conditions => ["name = ?", "Summit"])
270 273
     assert_equal summit, firm.clients.find(:all, :conditions => ["name = :name", { :name => "Summit" }])
271 274
   end
272 275
 
273 276
   def test_find_first
274  
-    firm = Firm.find(:first)
  277
+    firm = Firm.find(:first, :order => "id")
275 278
     client2 = Client.find(2)
276  
-    assert_equal firm.clients.first, firm.clients.find(:first)
277  
-    assert_equal client2, firm.clients.find(:first, :conditions => "#{QUOTED_TYPE} = 'Client'")
  279
+    assert_equal firm.clients.first, firm.clients.find(:first, :order => "id")
  280
+    assert_equal client2, firm.clients.find(:first, :conditions => "#{QUOTED_TYPE} = 'Client'", :order => "id")
278 281
   end
279 282
 
280 283
   def test_find_first_sanitized
281  
-    firm = Firm.find(:first)
  284
+    firm = Firm.find(:first, :order => "id")
282 285
     client2 = Client.find(2)
283  
-    assert_equal client2, firm.clients.find(:first, :conditions => ["#{QUOTED_TYPE} = ?", 'Client'])
284  
-    assert_equal client2, firm.clients.find(:first, :conditions => ["#{QUOTED_TYPE} = :type", { :type => 'Client' }])
  286
+    assert_equal client2, firm.clients.find(:first, :conditions => ["#{QUOTED_TYPE} = ?", 'Client'], :order => "id")
  287
+    assert_equal client2, firm.clients.find(:first, :conditions => ["#{QUOTED_TYPE} = :type", { :type => 'Client' }], :order => "id")
285 288
   end
286 289
 
287 290
   def test_find_in_collection
@@ -341,7 +344,7 @@ def test_regular_create_on_has_many_when_parent_is_new_raises
341 344
 
342 345
   def test_create_with_bang_on_has_many_raises_when_record_not_saved
343 346
     assert_raise(ActiveRecord::RecordInvalid) do
344  
-      firm = Firm.find(:first)
  347
+      firm = Firm.find(:first, :order => "id")
345 348
       firm.plain_clients.create!
346 349
     end
347 350
   end
@@ -731,7 +734,8 @@ def test_dependence_for_associations_with_hash_condition
731 734
   end
732 735
 
733 736
   def test_destroy_dependent_when_deleted_from_association
734  
-    firm = Firm.find(:first)
  737
+    # sometimes tests on Oracle fail if ORDER BY is not provided therefore add always :order with :first
  738
+    firm = Firm.find(:first, :order => "id")
735 739
     assert_equal 2, firm.clients.size
736 740
 
737 741
     client = firm.clients.first
@@ -798,7 +802,7 @@ def test_find_all_without_conditions
798 802
   end
799 803
 
800 804
   def test_replace_with_less
801  
-    firm = Firm.find(:first)
  805
+    firm = Firm.find(:first, :order => "id")
802 806
     firm.clients = [companies(:first_client)]
803 807
     assert firm.save, "Could not save firm"
804 808
     firm.reload
@@ -812,7 +816,7 @@ def test_replace_with_less_and_dependent_nullify
812 816
   end
813 817
 
814 818
   def test_replace_with_new
815  
-    firm = Firm.find(:first)
  819
+    firm = Firm.find(:first, :order => "id")
816 820
     firm.clients = [companies(:second_client), Client.new("name" => "New Client")]
817 821
     firm.save
818 822
     firm.reload
@@ -1104,7 +1108,7 @@ def test_respond_to_private_class_methods
1104 1108
   end
1105 1109
 
1106 1110
   def test_creating_using_primary_key
1107  
-    firm = Firm.find(:first)
  1111
+    firm = Firm.find(:first, :order => "id")
1108 1112
     client = firm.clients_using_primary_key.create!(:name => 'test')
1109 1113
     assert_equal firm.name, client.firm_name
1110 1114
   end
10  activerecord/test/cases/associations/join_model_test.rb
@@ -14,7 +14,9 @@
14 14
 
15 15
 class AssociationsJoinModelTest < ActiveRecord::TestCase
16 16
   self.use_transactional_fixtures = false
17  
-  fixtures :posts, :authors, :categories, :categorizations, :comments, :tags, :taggings, :author_favorites, :vertices, :items, :books
  17
+  fixtures :posts, :authors, :categories, :categorizations, :comments, :tags, :taggings, :author_favorites, :vertices, :items, :books,
  18
+    # Reload edges table from fixtures as otherwise repeated test was failing
  19
+    :edges
18 20
 
19 21
   def test_has_many
20 22
     assert authors(:david).categories.include?(categories(:general))
@@ -343,14 +345,16 @@ def test_has_many_polymorphic
343 345
   end
344 346
 
345 347
   def test_has_many_polymorphic_with_source_type
346  
-    assert_equal posts(:welcome, :thinking), tags(:general).tagged_posts
  348
+    # added sort by ID as otherwise Oracle select sometimes returned rows in different order
  349
+    assert_equal posts(:welcome, :thinking).sort_by(&:id), tags(:general).tagged_posts.sort_by(&:id)
347 350
   end
348 351
 
349 352
   def test_eager_has_many_polymorphic_with_source_type
350 353
     tag_with_include = Tag.find(tags(:general).id, :include => :tagged_posts)
351 354
     desired = posts(:welcome, :thinking)
352 355
     assert_no_queries do
353  
-      assert_equal desired, tag_with_include.tagged_posts
  356
+      # added sort by ID as otherwise test using JRuby was failing as array elements were in different order
  357
+      assert_equal desired.sort_by(&:id), tag_with_include.tagged_posts.sort_by(&:id)
354 358
     end
355 359
     assert_equal 5, tag_with_include.taggings.length
356 360
   end
14  activerecord/test/cases/attribute_methods_test.rb
@@ -75,13 +75,23 @@ def test_should_unserialize_attributes_for_frozen_records
75 75
 
76 76
   def test_typecast_attribute_from_select_to_false
77 77
     topic = Topic.create(:title => 'Budget')
78  
-    topic = Topic.find(:first, :select => "topics.*, 1=2 as is_test")
  78
+    # Oracle does not support boolean expressions in SELECT
  79
+    if current_adapter?(:OracleAdapter)
  80
+      topic = Topic.find(:first, :select => "topics.*, 0 as is_test")
  81
+    else
  82
+      topic = Topic.find(:first, :select => "topics.*, 1=2 as is_test")
  83
+    end
79 84
     assert !topic.is_test?
80 85
   end
81 86
 
82 87
   def test_typecast_attribute_from_select_to_true
83 88
     topic = Topic.create(:title => 'Budget')
84  
-    topic = Topic.find(:first, :select => "topics.*, 2=2 as is_test")
  89
+    # Oracle does not support boolean expressions in SELECT
  90
+    if current_adapter?(:OracleAdapter)
  91
+      topic = Topic.find(:first, :select => "topics.*, 1 as is_test")
  92
+    else
  93
+      topic = Topic.find(:first, :select => "topics.*, 2=2 as is_test")
  94
+    end
85 95
     assert topic.is_test?
86 96
   end
87 97
 
46  activerecord/test/cases/autosave_association_test.rb
@@ -154,7 +154,8 @@ def test_should_save_parent_but_not_invalid_child
154 154
   end
155 155
 
156 156
   def test_save_fails_for_invalid_belongs_to
157  
-    assert log = AuditLog.create(:developer_id => 0, :message => "")
  157
+    # Oracle saves empty string as NULL therefore :message changed to one space
  158
+    assert log = AuditLog.create(:developer_id => 0, :message => " ")
158 159
 
159 160
     log.developer = Developer.new
160 161
     assert !log.developer.valid?
@@ -164,7 +165,8 @@ def test_save_fails_for_invalid_belongs_to
164 165
   end
165 166
 
166 167
   def test_save_succeeds_for_invalid_belongs_to_with_validate_false
167  
-    assert log = AuditLog.create(:developer_id => 0, :message=> "")
  168
+    # Oracle saves empty string as NULL therefore :message changed to one space
  169
+    assert log = AuditLog.create(:developer_id => 0, :message=> " ")
168 170
 
169 171
     log.unvalidated_developer = Developer.new
170 172
     assert !log.unvalidated_developer.valid?
@@ -666,7 +668,12 @@ def test_should_still_allow_to_bypass_validations_on_the_associated_model
666 668
     @pirate.catchphrase = ''
667 669
     @pirate.ship.name = ''
668 670
     @pirate.save(false)
669  
-    assert_equal ['', ''], [@pirate.reload.catchphrase, @pirate.ship.name]
  671
+    # Oracle saves empty string as NULL
  672
+    if current_adapter?(:OracleAdapter)
  673
+      assert_equal [nil, nil], [@pirate.reload.catchphrase, @pirate.ship.name]
  674
+    else
  675
+      assert_equal ['', ''], [@pirate.reload.catchphrase, @pirate.ship.name]
  676
+    end
670 677
   end
671 678
 
672 679
   def test_should_allow_to_bypass_validations_on_associated_models_at_any_depth
@@ -678,7 +685,12 @@ def test_should_allow_to_bypass_validations_on_associated_models_at_any_depth
678 685
     @pirate.save(false)
679 686
 
680 687
     values = [@pirate.reload.catchphrase, @pirate.ship.name, *@pirate.ship.parts.map(&:name)]
681  
-    assert_equal ['', '', '', ''], values
  688
+    # Oracle saves empty string as NULL
  689
+    if current_adapter?(:OracleAdapter)
  690
+      assert_equal [nil, nil, nil, nil], values
  691
+    else
  692
+      assert_equal ['', '', '', ''], values
  693
+    end
682 694
   end
683 695
 
684 696
   def test_should_still_raise_an_ActiveRecordRecord_Invalid_exception_if_we_want_that
@@ -756,7 +768,12 @@ def test_should_still_allow_to_bypass_validations_on_the_associated_model
756 768
     @ship.pirate.catchphrase = ''
757 769
     @ship.name = ''
758 770
     @ship.save(false)
759  
-    assert_equal ['', ''], [@ship.reload.name, @ship.pirate.catchphrase]
  771
+    # Oracle saves empty string as NULL
  772
+    if current_adapter?(:OracleAdapter)
  773
+      assert_equal [nil, nil], [@ship.reload.name, @ship.pirate.catchphrase]
  774
+    else
  775
+      assert_equal ['', ''], [@ship.reload.name, @ship.pirate.catchphrase]
  776
+    end
760 777
   end
761 778
 
762 779
   def test_should_still_raise_an_ActiveRecordRecord_Invalid_exception_if_we_want_that
@@ -837,11 +854,20 @@ def test_should_allow_to_bypass_validations_on_the_associated_models_on_update
837 854
     @pirate.send(@association_name).each { |child| child.name = '' }
838 855
 
839 856
     assert @pirate.save(false)
840  
-    assert_equal ['', '', ''], [
841  
-      @pirate.reload.catchphrase,
842  
-      @pirate.send(@association_name).first.name,
843  
-      @pirate.send(@association_name).last.name
844  
-    ]
  857
+    # Oracle saves empty string as NULL
  858
+    if current_adapter?(:OracleAdapter)
  859
+      assert_equal [nil, nil, nil], [
  860
+        @pirate.reload.catchphrase,
  861
+        @pirate.send(@association_name).first.name,
  862
+        @pirate.send(@association_name).last.name
  863
+      ]
  864
+    else
  865
+      assert_equal ['', '', ''], [
  866
+        @pirate.reload.catchphrase,
  867
+        @pirate.send(@association_name).first.name,
  868
+        @pirate.send(@association_name).last.name
  869
+      ]
  870
+    end
845 871
   end
846 872
 
847 873
   def test_should_validation_the_associated_models_on_create
7  activerecord/test/cases/calculations_test.rb
@@ -298,7 +298,12 @@ def test_count_with_too_many_parameters_raises
298 298
   end
299 299
 
300 300
   def test_should_sum_expression
301  
-    assert_equal '636', Account.sum("2 * credit_limit")
  301
+    # Oracle adapter returns floating point value 636.0 after SUM
  302
+    if current_adapter?(:OracleAdapter)
  303
+      assert_equal 636, Account.sum("2 * credit_limit")
  304
+    else
  305
+      assert_equal '636', Account.sum("2 * credit_limit")
  306
+    end
302 307
   end
303 308
 
304 309
   def test_count_with_from_option
9  activerecord/test/cases/database_statements_test.rb
@@ -6,7 +6,14 @@ def setup
6 6
   end
7 7
 
8 8
   def test_insert_should_return_the_inserted_id
9  
-    id = @connection.insert("INSERT INTO accounts (firm_id,credit_limit) VALUES (42,5000)")
  9
+    # Oracle adapter uses prefetched primary key values from sequence and passes them to connection adapter insert method
  10
+    if current_adapter?(:OracleAdapter)
  11
+      sequence_name = "accounts_seq"
  12
+      id_value = @connection.next_sequence_value(sequence_name)
  13
+      id = @connection.insert("INSERT INTO accounts (id, firm_id,credit_limit) VALUES (accounts_seq.nextval,42,5000)", nil, :id, id_value, sequence_name)
  14
+    else
  15
+      id = @connection.insert("INSERT INTO accounts (firm_id,credit_limit) VALUES (42,5000)")
  16
+    end
10 17
     assert_not_nil id
11 18
   end
12 19
 end
2  activerecord/test/cases/finder_test.rb
@@ -1027,7 +1027,7 @@ def test_find_all_with_join
1027 1027
   def test_joins_dont_clobber_id
1028 1028
     first = Firm.find(
1029 1029
       :first,
1030  
-      :joins => 'INNER JOIN companies AS clients ON clients.firm_id = companies.id',
  1030
+      :joins => 'INNER JOIN companies clients ON clients.firm_id = companies.id',
1031 1031
       :conditions => 'companies.id = 1'
1032 1032
     )
1033 1033
     assert_equal 1, first.id
3  activerecord/test/cases/inheritance_test.rb
@@ -137,7 +137,8 @@ def test_alt_finding_incorrect_type_data
137 137
   def test_update_all_within_inheritance
138 138
     Client.update_all "name = 'I am a client'"
139 139
     assert_equal "I am a client", Client.find(:all).first.name
140  
-    assert_equal "37signals", Firm.find(:all).first.name
  140
+    # Order by added as otherwise Oracle tests were failing because of different order of results
  141
+    assert_equal "37signals", Firm.find(:all, :order => "id").first.name
141 142
   end
142 143
 
143 144
   def test_alt_update_all_within_inheritance
14  activerecord/test/cases/invalid_date_test.rb
@@ -11,13 +11,23 @@ def test_assign_valid_dates
11 11
 
12 12
     valid_dates.each do |date_src|
13 13
       topic = Topic.new("last_read(1i)" => date_src[0].to_s, "last_read(2i)" => date_src[1].to_s, "last_read(3i)" => date_src[2].to_s)
14  
-      assert_equal(topic.last_read, Date.new(*date_src))
  14
+      # Oracle DATE columns are datetime columns and Oracle adapter returns Time value
  15
+      if current_adapter?(:OracleAdapter)
  16
+        assert_equal(topic.last_read.to_date, Date.new(*date_src))
  17
+      else
  18
+        assert_equal(topic.last_read, Date.new(*date_src))
  19
+      end
15 20
     end
16 21
 
17 22
     invalid_dates.each do |date_src|
18 23
       assert_nothing_raised do
19 24
         topic = Topic.new({"last_read(1i)" => date_src[0].to_s, "last_read(2i)" => date_src[1].to_s, "last_read(3i)" => date_src[2].to_s})
20  
-        assert_equal(topic.last_read, Time.local(*date_src).to_date, "The date should be modified according to the behaviour of the Time object")
  25
+        # Oracle DATE columns are datetime columns and Oracle adapter returns Time value
  26
+        if current_adapter?(:OracleAdapter)
  27
+          assert_equal(topic.last_read.to_date, Time.local(*date_src).to_date, "The date should be modified according to the behaviour of the Time object")
  28
+        else
  29
+          assert_equal(topic.last_read, Time.local(*date_src).to_date, "The date should be modified according to the behaviour of the Time object")
  30
+        end
21 31
       end
22 32
     end
23 33
   end
3  activerecord/test/cases/method_scoping_test.rb
@@ -379,7 +379,8 @@ def test_merged_scoped_find
379 379
     poor_jamis = developers(:poor_jamis)
380 380
     Developer.with_scope(:find => { :conditions => "salary < 100000" }) do
381 381
       Developer.with_scope(:find => { :offset => 1, :order => 'id asc' }) do
382  
-        assert_sql /ORDER BY id asc / do
  382
+        # Oracle adapter does not generated space after asc therefore trailing space removed from regex
  383
+        assert_sql /ORDER BY id asc/ do
383 384
           assert_equal(poor_jamis, Developer.find(:first, :order => 'id asc'))
384 385
         end
385 386
       end
63  activerecord/test/cases/migration_test.rb
@@ -446,18 +446,22 @@ def test_native_types
446 446
         assert_equal Date, bob.favorite_day.class
447 447
       end
448 448
 
449  
-      # Test DateTime column and defaults, including timezone.
450  
-      # FIXME: moment of truth may be Time on 64-bit platforms.
451  
-      if bob.moment_of_truth.is_a?(DateTime)
452  
-
453  
-        with_env_tz 'US/Eastern' do
454  
-          assert_equal DateTime.local_offset, bob.moment_of_truth.offset
455  
-          assert_not_equal 0, bob.moment_of_truth.offset
456  
-          assert_not_equal "Z", bob.moment_of_truth.zone
457  
-          # US/Eastern is -5 hours from GMT
458  
-          assert_equal Rational(-5, 24), bob.moment_of_truth.offset
459  
-          assert_match /\A-05:?00\Z/, bob.moment_of_truth.zone #ruby 1.8.6 uses HH:MM, prior versions use HHMM
460  
-          assert_equal DateTime::ITALY, bob.moment_of_truth.start
  449
+      # Oracle adapter stores Time or DateTime with timezone value already in _before_type_cast column
  450
+      # therefore no timezone change is done afterwards when default timezone is changed
  451
+      unless current_adapter?(:OracleAdapter)
  452
+        # Test DateTime column and defaults, including timezone.
  453
+        # FIXME: moment of truth may be Time on 64-bit platforms.
  454
+        if bob.moment_of_truth.is_a?(DateTime)
  455
+
  456
+          with_env_tz 'US/Eastern' do
  457
+            assert_equal DateTime.local_offset, bob.moment_of_truth.offset
  458
+            assert_not_equal 0, bob.moment_of_truth.offset
  459
+            assert_not_equal "Z", bob.moment_of_truth.zone
  460
+            # US/Eastern is -5 hours from GMT
  461
+            assert_equal Rational(-5, 24), bob.moment_of_truth.offset
  462
+            assert_match /\A-05:?00\Z/, bob.moment_of_truth.zone #ruby 1.8.6 uses HH:MM, prior versions use HHMM
  463
+            assert_equal DateTime::ITALY, bob.moment_of_truth.start
  464
+          end
461 465
         end
462 466
       end
463 467
 
@@ -571,7 +575,7 @@ def test_rename_nonexistent_column
571 575
       ActiveRecord::Base.connection.create_table(:hats) do |table|
572 576
         table.column :hat_name, :string, :default => nil
573 577
       end
574  
-      exception = if current_adapter?(:PostgreSQLAdapter)
  578
+      exception = if current_adapter?(:PostgreSQLAdapter, :OracleAdapter)
575 579
         ActiveRecord::StatementInvalid
576 580
       else
577 581
         ActiveRecord::ActiveRecordError
@@ -625,7 +629,13 @@ def test_remove_column_with_multi_column_index
625 629
         table.column :hat_size, :integer
626 630
         table.column :hat_style, :string, :limit => 100
627 631
       end
628  
-      ActiveRecord::Base.connection.add_index "hats", ["hat_style", "hat_size"], :unique => true
  632
+      # Oracle index names should be 30 or less characters
  633
+      if current_adapter?(:OracleAdapter)
  634
+        ActiveRecord::Base.connection.add_index "hats", ["hat_style", "hat_size"], :unique => true,
  635
+          :name => 'index_hats_on_hat_style_size'
  636
+      else
  637
+        ActiveRecord::Base.connection.add_index "hats", ["hat_style", "hat_size"], :unique => true
  638
+      end
629 639
 
630 640
       assert_nothing_raised { Person.connection.remove_column("hats", "hat_size") }
631 641
     ensure
@@ -783,7 +793,12 @@ def test_change_column_quotes_column_names
783 793
 
784 794
       assert_nothing_raised { Person.connection.change_column :testings, :select, :string, :limit => 10 }
785 795
 
786  
-      assert_nothing_raised { Person.connection.execute "insert into testings (#{Person.connection.quote_column_name('select')}) values ('7 chars')" }
  796
+      # Oracle needs primary key value from sequence
  797
+      if current_adapter?(:OracleAdapter)
  798
+        assert_nothing_raised { Person.connection.execute "insert into testings (id, #{Person.connection.quote_column_name('select')}) values (testings_seq.nextval, '7 chars')" }
  799
+      else
  800
+        assert_nothing_raised { Person.connection.execute "insert into testings (#{Person.connection.quote_column_name('select')}) values ('7 chars')" }
  801
+      end
787 802
     ensure
788 803
       Person.connection.drop_table :testings rescue nil
789 804
     end
@@ -799,7 +814,12 @@ def test_keeping_default_and_notnull_constaint_on_change
799 814
       person_klass.reset_column_information
800 815
       assert_equal 99, person_klass.columns_hash["wealth"].default
801 816
       assert_equal false, person_klass.columns_hash["wealth"].null
802  
-      assert_nothing_raised {person_klass.connection.execute("insert into testings (title) values ('tester')")}
  817
+      # Oracle needs primary key value from sequence
  818
+      if current_adapter?(:OracleAdapter)
  819
+        assert_nothing_raised {person_klass.connection.execute("insert into testings (id, title) values (testings_seq.nextval, 'tester')")}
  820
+      else
  821
+        assert_nothing_raised {person_klass.connection.execute("insert into testings (title) values ('tester')")}
  822
+      end
803 823
 
804 824
       # change column default to see that column doesn't lose its not null definition
805 825
       person_klass.connection.change_column_default "testings", "wealth", 100
@@ -1054,7 +1074,12 @@ def test_migrator_interleaved_migrations
1054 1074
     end
1055 1075
 
1056 1076
     def test_migrator_db_has_no_schema_migrations_table
1057  
-      ActiveRecord::Base.connection.execute("DROP TABLE schema_migrations;")
  1077
+      # Oracle adapter raises error if semicolon is present as last character
  1078
+      if current_adapter?(:OracleAdapter)
  1079
+        ActiveRecord::Base.connection.execute("DROP TABLE schema_migrations")
  1080
+      else
  1081
+        ActiveRecord::Base.connection.execute("DROP TABLE schema_migrations;")
  1082
+      end
1058 1083
       assert_nothing_raised do
1059 1084
         ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/valid", 1)
1060 1085
       end
@@ -1412,6 +1437,8 @@ def test_remove_timestamps_creates_updated_at_and_created_at
1412 1437
     def string_column
1413 1438
       if current_adapter?(:PostgreSQLAdapter)
1414 1439
         "character varying(255)"
  1440
+      elsif current_adapter?(:OracleAdapter)
  1441
+        'VARCHAR2(255)'
1415 1442
       else
1416 1443
         'varchar(255)'
1417 1444
       end
@@ -1420,6 +1447,8 @@ def string_column
1420 1447
     def integer_column
1421 1448
       if current_adapter?(:MysqlAdapter)
1422 1449
         'int(11)'
  1450
+      elsif current_adapter?(:OracleAdapter)
  1451
+        'NUMBER(38)'
1423 1452
       else
1424 1453
         'integer'
1425 1454
       end
3  activerecord/test/cases/named_scope_test.rb
@@ -154,7 +154,8 @@ def test_named_scopes_honor_current_scopes_from_when_defined
154 154
     assert !authors(:david).posts.ranked_by_comments.limit(5).empty?
155 155
     assert_not_equal Post.ranked_by_comments.limit(5), authors(:david).posts.ranked_by_comments.limit(5)
156 156
     assert_not_equal Post.top(5), authors(:david).posts.top(5)
157  
-    assert_equal authors(:david).posts.ranked_by_comments.limit(5), authors(:david).posts.top(5)
  157
+    # Oracle sometimes sorts differently if WHERE condition is changed
  158
+    assert_equal authors(:david).posts.ranked_by_comments.limit(5).sort_by(&:id), authors(:david).posts.top(5).sort_by(&:id)
158 159
     assert_equal Post.ranked_by_comments.limit(5), Post.top(5)
159 160
   end
160 161
 
7  activerecord/test/cases/query_cache_test.rb
@@ -50,7 +50,12 @@ def test_cache_is_flat
50 50
 
51 51
   def test_cache_does_not_wrap_string_results_in_arrays
52 52
     Task.cache do
53  
-      assert_instance_of String, Task.connection.select_value("SELECT count(*) AS count_all FROM tasks")
  53
+      # Oracle adapter returns count() as Fixnum or Float
  54
+      if current_adapter?(:OracleAdapter)
  55
+        assert Task.connection.select_value("SELECT count(*) AS count_all FROM tasks").is_a?(Numeric)
  56
+      else
  57
+        assert_instance_of String, Task.connection.select_value("SELECT count(*) AS count_all FROM tasks")
  58
+      end
54 59
     end
55 60
   end
56 61
 end
12  activerecord/test/cases/schema_dumper_test.rb
@@ -114,6 +114,11 @@ def test_schema_dump_includes_limit_constraint_for_integer_columns
114 114
       assert_match %r{c_int_6.*:limit => 6}, output
115 115
       assert_match %r{c_int_7.*:limit => 7}, output
116 116
       assert_match %r{c_int_8.*:limit => 8}, output
  117
+    elsif current_adapter?(:OracleAdapter)
  118
+      assert_match %r{c_int_5.*:limit => 5}, output
  119
+      assert_match %r{c_int_6.*:limit => 6}, output
  120
+      assert_match %r{c_int_7.*:limit => 7}, output
  121
+      assert_match %r{c_int_8.*:limit => 8}, output
117 122
     else
118 123
       assert_match %r{c_int_5.*:limit => 8}, output
119 124
       assert_match %r{c_int_6.*:limit => 8}, output
@@ -193,6 +198,11 @@ def test_schema_dump_includes_decimal_options
193 198
 
194 199
   def test_schema_dump_keeps_large_precision_integer_columns_as_decimal
195 200
     output = standard_dump
196  
-    assert_match %r{t.decimal\s+"atoms_in_universe",\s+:precision => 55,\s+:scale => 0}, output
  201
+    # Oracle supports precision up to 38 and it identifies decimals with scale 0 as integers
  202
+    if current_adapter?(:OracleAdapter)
  203
+      assert_match %r{t.integer\s+"atoms_in_universe",\s+:precision => 38,\s+:scale => 0}, output
  204
+    else
  205
+      assert_match %r{t.decimal\s+"atoms_in_universe",\s+:precision => 55,\s+:scale => 0}, output
  206
+    end
197 207
   end
198 208
 end
55  activerecord/test/connections/native_oracle/connection.rb
... ...
@@ -1,27 +1,68 @@
  1
+# gem "rsim-activerecord-oracle_enhanced-adapter"
  2
+# gem "activerecord-oracle_enhanced-adapter", ">=1.2.1"
  3
+# uses local copy of oracle_enhanced adapter
  4
+$:.unshift("../../oracle-enhanced/lib")
  5
+require 'active_record/connection_adapters/oracle_enhanced_adapter'
  6
+# gem "activerecord-jdbc-adapter"
  7
+# require 'active_record/connection_adapters/jdbc_adapter'
  8
+
  9
+# otherwise failed with silence_warnings method missing exception
  10
+require 'active_support/core_ext/kernel/reporting'
  11
+
1 12
 print "Using Oracle\n"
2 13
 require_dependency 'models/course'
3 14
 require 'logger'
4 15
 
5  
-ActiveRecord::Base.logger = Logger.new STDOUT
6  
-ActiveRecord::Base.logger.level = Logger::WARN
  16
+# ActiveRecord::Base.logger = Logger.new STDOUT
  17
+# ActiveRecord::Base.logger.level = Logger::WARN
  18
+ActiveRecord::Base.logger = Logger.new("debug.log")
7 19
 
8 20
 # Set these to your database connection strings
9  
-db = ENV['ARUNIT_DB'] || 'activerecord_unittest'
  21
+db = ENV['ARUNIT_DB_NAME'] = 'orcl'
10 22
 
11 23
 ActiveRecord::Base.configurations = {
12 24
   'arunit' => {
13  
-    :adapter  => 'oracle',
  25
+    :adapter  => 'oracle_enhanced',
  26
+    :database => db,
  27
+    :host => "localhost", # used just by JRuby to construct JDBC connect string
  28
+    # :adapter => "jdbc",
  29
+    # :driver => "oracle.jdbc.driver.OracleDriver",
  30
+    # :url => "jdbc:oracle:thin:@localhost:1521:#{db}",
14 31
     :username => 'arunit',
15 32
     :password => 'arunit',
16  
-    :database => db,
  33
+    :emulate_oracle_adapter => true
17 34
   },
18 35
   'arunit2' => {
19  
-    :adapter  => 'oracle',
  36
+    :adapter  => 'oracle_enhanced',
  37
+    :database => db,
  38
+    :host => "localhost", # used just by JRuby to construct JDBC connect string
  39
+    # :adapter => "jdbc",
  40
+    # :driver => "oracle.jdbc.driver.OracleDriver",
  41
+    # :url => "jdbc:oracle:thin:@localhost:1521:#{db}",
20 42
     :username => 'arunit2',
21 43
     :password => 'arunit2',
22  
-    :database => db
  44
+    :emulate_oracle_adapter => true
23 45
   }
24 46
 }
25 47
 
26 48
 ActiveRecord::Base.establish_connection 'arunit'
27 49
 Course.establish_connection 'arunit2'
  50
+
  51
+# ActiveRecord::Base.connection.execute %q{alter session set nls_date_format = 'YYYY-MM-DD HH24:MI:SS'}
  52
+# ActiveRecord::Base.connection.execute %q{alter session set nls_timestamp_format = 'YYYY-MM-DD HH24:MI:SS'} rescue nil
  53
+
  54
+# for assert_queries test helper
  55
+ActiveRecord::Base.connection.class.class_eval do
  56
+  IGNORED_SELECT_SQL = [/^select .*nextval/i, /^SAVEPOINT/, /^ROLLBACK TO SAVEPOINT/, /^RELEASE SAVEPOINT/, /^\s*select .* from all_tab_columns/im]
  57
+
  58
+  def select_with_query_record(sql, name = nil, return_column_names = false)
  59
+    $queries_executed ||= []
  60
+    $queries_executed << sql unless IGNORED_SELECT_SQL.any? { |r| sql =~ r }
  61
+    select_without_query_record(sql, name, return_column_names)
  62
+  end
  63
+
  64
+  alias_method_chain :select, :query_record
  65
+end
  66
+
  67
+# For JRuby Set default $KCODE to UTF8
  68
+$KCODE = "UTF8" if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
8  activerecord/test/models/company.rb
@@ -73,12 +73,16 @@ class Firm < Company
73 73
   has_one :unvalidated_account, :foreign_key => "firm_id", :class_name => 'Account', :validate => false
74 74
   has_one :account_with_select, :foreign_key => "firm_id", :select => "id, firm_id", :class_name=>'Account'
75 75
   has_one :readonly_account, :foreign_key => "firm_id", :class_name => "Account", :readonly => true
76  
-  has_one :account_using_primary_key, :primary_key => "firm_id", :class_name => "Account"
  76
+  # added order by id as in fixtures there are two accounts for Rails Core
  77
+  # Oracle tests were failing because of that as the second fixture was selected
  78
+  has_one :account_using_primary_key, :primary_key => "firm_id", :class_name => "Account", :order => "id"
77 79
   has_one :deletable_account, :foreign_key => "firm_id", :class_name => "Account", :dependent => :delete
78 80
 end
79 81
 
80 82
 class DependentFirm < Company
81  
-  has_one :account, :foreign_key => "firm_id", :dependent => :nullify
  83
+  # added order by id as in fixtures there are two accounts for Rails Core
  84
+  # Oracle tests were failing because of that as the second fixture was selected
  85
+  has_one :account, :foreign_key => "firm_id", :dependent => :nullify, :order => "id"
82 86
   has_many :companies, :foreign_key => 'client_of', :order => "id", :dependent => :nullify
83 87
 end
84 88
 
10  activerecord/test/models/subject.rb
... ...
@@ -1,4 +1,12 @@
1  
-# used for OracleSynonymTest, see test/synonym_test_oci.rb
  1
+# used for OracleSynonymTest, see test/synonym_test_oracle.rb
2 2
 #
3 3
 class Subject < ActiveRecord::Base
  4
+  protected
  5
+    # added initialization of author_email_address in the same way as in Topic class
  6
+    # as otherwise synonym test was failing
  7
+    def after_initialize
  8
+      if self.new_record?
  9
+        self.author_email_address = 'test@test.com'
  10
+      end
  11
+    end
4 12
 end
27  activerecord/test/schema/oracle_specific_schema.rb
@@ -2,6 +2,10 @@
2 2
 
3 3
   execute "drop table test_oracle_defaults" rescue nil
4 4
   execute "drop sequence test_oracle_defaults_seq" rescue nil
  5
+  execute "drop sequence companies_nonstd_seq" rescue nil
  6
+  execute "drop synonym subjects" rescue nil
  7
+  execute "drop table defaults" rescue nil
  8
+  execute "drop sequence defaults_seq" rescue nil
5 9
 
6 10
   execute <<-SQL
7 11
 create table test_oracle_defaults (
@@ -16,4 +20,27 @@
16 20
 create sequence test_oracle_defaults_seq minvalue 10000
17 21
   SQL
18 22
 
  23
+  execute "create sequence companies_nonstd_seq minvalue 10000"
  24
+
  25
+  execute "create synonym subjects for topics"
  26
+
  27
+  execute <<-SQL
  28
+  CREATE TABLE defaults (
  29
+      id integer not null,
  30
+      modified_date date default sysdate,
  31
+      modified_date_function date default sysdate,
  32
+      fixed_date date default to_date('2004-01-01', 'YYYY-MM-DD'),
  33
+      modified_time date default sysdate,
  34
+      modified_time_function date default sysdate,
  35
+      fixed_time date default TO_DATE('2004-01-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS'),
  36
+      char1 varchar2(1) default 'Y',
  37
+      char2 varchar2(50) default 'a varchar field',
  38
+      char3 clob default 'a text field',
  39
+      positive_integer integer default 1,
  40
+      negative_integer integer default -1,
  41
+      decimal_number number(3,2) default 2.78
  42
+  )
  43
+  SQL
  44
+  execute "create sequence defaults_seq minvalue 10000"
  45
+
19 46
 end
31  activerecord/test/schema/schema.rb
@@ -104,7 +104,13 @@ def create_table(*args, &block)
104 104
 
105 105
   create_table :comments, :force => true do |t|
106 106
     t.integer :post_id, :null => false
107  
-    t.text    :body, :null => false
  107
+    # use VARCHAR2(4000) instead of CLOB datatype as CLOB data type has many limitations in
  108
+    # Oracle SELECT WHERE clause which causes many unit test failures
  109
+    if current_adapter?(:OracleAdapter)
  110
+      t.string  :body, :null => false, :limit => 4000
  111
+    else
  112
+      t.text    :body, :null => false
  113
+    end
108 114
     t.string  :type
109 115
   end
110 116
 
@@ -279,7 +285,12 @@ def create_table(*args, &block)
279 285
     t.decimal :my_house_population, :precision => 2, :scale => 0
280 286
     t.decimal :decimal_number_with_default, :precision => 3, :scale => 2, :default => 2.78
281 287
     t.float   :temperature
282  
-    t.decimal :atoms_in_universe, :precision => 55, :scale => 0
  288
+    # Oracle supports precision up to 38
  289
+    if current_adapter?(:OracleAdapter)
  290
+      t.decimal :atoms_in_universe, :precision => 38, :scale => 0
  291
+    else
  292
+      t.decimal :atoms_in_universe, :precision => 55, :scale => 0
  293
+    end
283 294
   end
284 295
 
285 296
   create_table :orders, :force => true do |t|
@@ -350,7 +361,13 @@ def create_table(*args, &block)
350 361
   create_table :posts, :force => true do |t|
351 362
     t.integer :author_id
352 363
     t.string  :title, :null => false
353  
-    t.text    :body, :null => false
  364
+    # use VARCHAR2(4000) instead of CLOB datatype as CLOB data type has many limitations in
  365
+    # Oracle SELECT WHERE clause which causes many unit test failures
  366
+    if current_adapter?(:OracleAdapter)
  367
+      t.string  :body, :null => false, :limit => 4000
  368
+    else
  369
+      t.text    :body, :null => false
  370
+    end
354 371
     t.string  :type
355 372
     t.integer :comments_count, :default => 0
356 373
     t.integer :taggings_count, :default => 0
@@ -423,7 +440,13 @@ def create_table(*args, &block)
423 440
     t.datetime :written_on
424 441
     t.time     :bonus_time
425 442
     t.date     :last_read
426  
-    t.text     :content
  443
+    # use VARCHAR2(4000) instead of CLOB datatype as CLOB data type has many limitations in
  444
+    # Oracle SELECT WHERE clause which causes many unit test failures
  445
+    if current_adapter?(:OracleAdapter)
  446
+      t.string   :content, :limit => 4000
  447
+    else
  448
+      t.text     :content
  449
+    end
427 450
     t.boolean  :approved, :default => true
428 451
     t.integer  :replies_count, :default => 0
429 452
     t.integer  :parent_id

0 notes on commit 06afa48

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