activerecord 1.12.2 → 1.13.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activerecord might be problematic. Click here for more details.

Files changed (66) hide show
  1. data/CHANGELOG +92 -0
  2. data/README +9 -9
  3. data/lib/active_record/acts/list.rb +1 -1
  4. data/lib/active_record/acts/nested_set.rb +13 -13
  5. data/lib/active_record/acts/tree.rb +7 -6
  6. data/lib/active_record/aggregations.rb +4 -4
  7. data/lib/active_record/associations.rb +82 -21
  8. data/lib/active_record/associations/association_collection.rb +0 -8
  9. data/lib/active_record/associations/association_proxy.rb +5 -2
  10. data/lib/active_record/associations/belongs_to_association.rb +6 -2
  11. data/lib/active_record/associations/has_and_belongs_to_many_association.rb +11 -1
  12. data/lib/active_record/associations/has_many_association.rb +34 -5
  13. data/lib/active_record/associations/has_one_association.rb +1 -1
  14. data/lib/active_record/base.rb +144 -59
  15. data/lib/active_record/callbacks.rb +6 -6
  16. data/lib/active_record/connection_adapters/abstract/connection_specification.rb +3 -2
  17. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +4 -4
  18. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +10 -8
  19. data/lib/active_record/connection_adapters/abstract_adapter.rb +1 -1
  20. data/lib/active_record/connection_adapters/db2_adapter.rb +17 -1
  21. data/lib/active_record/connection_adapters/oci_adapter.rb +322 -185
  22. data/lib/active_record/connection_adapters/sqlite_adapter.rb +9 -8
  23. data/lib/active_record/connection_adapters/sqlserver_adapter.rb +107 -14
  24. data/lib/active_record/fixtures.rb +10 -8
  25. data/lib/active_record/migration.rb +20 -6
  26. data/lib/active_record/observer.rb +4 -3
  27. data/lib/active_record/reflection.rb +5 -5
  28. data/lib/active_record/transactions.rb +2 -2
  29. data/lib/active_record/validations.rb +70 -40
  30. data/lib/active_record/vendor/mysql411.rb +9 -13
  31. data/lib/active_record/version.rb +2 -2
  32. data/rakefile +1 -1
  33. data/test/abstract_unit.rb +5 -0
  34. data/test/ar_schema_test.rb +1 -1
  35. data/test/associations_extensions_test.rb +37 -0
  36. data/test/associations_go_eager_test.rb +25 -0
  37. data/test/associations_test.rb +14 -6
  38. data/test/base_test.rb +63 -45
  39. data/test/connections/native_sqlite/connection.rb +2 -2
  40. data/test/connections/native_sqlite3/connection.rb +2 -2
  41. data/test/connections/native_sqlite3/in_memory_connection.rb +1 -1
  42. data/test/debug.log +2857 -0
  43. data/test/deprecated_finder_test.rb +3 -9
  44. data/test/finder_test.rb +27 -13
  45. data/test/fixtures/author.rb +4 -0
  46. data/test/fixtures/comment.rb +4 -8
  47. data/test/fixtures/db_definitions/create_oracle_db.bat +0 -5
  48. data/test/fixtures/db_definitions/create_oracle_db.sh +0 -5
  49. data/test/fixtures/db_definitions/db2.drop.sql +0 -1
  50. data/test/fixtures/db_definitions/oci.sql +2 -0
  51. data/test/fixtures/db_definitions/sqlserver.drop.sql +1 -1
  52. data/test/fixtures/developer.rb +18 -1
  53. data/test/fixtures/fixture_database.sqlite +0 -0
  54. data/test/fixtures/fixture_database_2.sqlite +0 -0
  55. data/test/fixtures/migrations_with_duplicate/1_people_have_last_names.rb +9 -0
  56. data/test/fixtures/migrations_with_duplicate/2_we_need_reminders.rb +12 -0
  57. data/test/fixtures/migrations_with_duplicate/3_foo.rb +7 -0
  58. data/test/fixtures/migrations_with_duplicate/3_innocent_jointable.rb +12 -0
  59. data/test/fixtures/post.rb +18 -4
  60. data/test/fixtures/reply.rb +3 -1
  61. data/test/inheritance_test.rb +3 -2
  62. data/test/{conditions_scoping_test.rb → method_scoping_test.rb} +55 -10
  63. data/test/migration_test.rb +68 -31
  64. data/test/readonly_test.rb +65 -5
  65. data/test/validations_test.rb +10 -2
  66. metadata +13 -4
@@ -59,8 +59,8 @@ class Mysql
59
59
 
60
60
  # Store the version number components for speedy comparison
61
61
  version, ostag = @server_version.split( /-/, 2 )
62
- @major_ver, @minor_ver, @revision_num = version.split( /\./ ).map { |v| v.to_i }
63
-
62
+ @use_411 = (version.strip >= '4.1.1')
63
+
64
64
  @thread_id, @scramble_buff = a.slice!(0,13).unpack("La8")
65
65
  if a.size >= 2 then
66
66
  @server_capabilities, = a.slice!(0,2).unpack("v")
@@ -74,7 +74,7 @@ class Mysql
74
74
  flag |= @client_flag | CLIENT_CAPABILITIES
75
75
  flag |= CLIENT_CONNECT_WITH_DB if db
76
76
 
77
- if version_meets_minimum?( 4, 1, 1 )
77
+ if @use_411
78
78
  # In 4.1.1+ the seed comes in two parts which must be combined
79
79
  a.slice!( 0, 16 )
80
80
  seed_part_2 = a.slice!( 0, 12 );
@@ -116,11 +116,7 @@ class Mysql
116
116
 
117
117
  [ flag, @max_allowed_packet, @server_language, user, password.size, password, db ].pack( template )
118
118
  end
119
-
120
- def version_meets_minimum?( major, minor, revision )
121
- @major_ver >= major && @minor_ver >= minor && @revision_num >= revision
122
- end
123
-
119
+
124
120
  # SERVER: public_seed=create_random_string()
125
121
  # send(public_seed)
126
122
  #
@@ -161,7 +157,7 @@ class Mysql
161
157
  end
162
158
 
163
159
  def change_user(user="", passwd="", db="")
164
- scrambled_password = version_meets_minimum?( 4, 1, 1 ) ? scramble411( passwd, @scramble_buff, @protocol_version==9 ) : scramble( passwd, @scramble_buff, @protocol_version==9 )
160
+ scrambled_password = @use_411 ? scramble411( passwd, @scramble_buff, @protocol_version==9 ) : scramble( passwd, @scramble_buff, @protocol_version==9 )
165
161
  data = user+"\0"+scrambled_password+"\0"+db
166
162
  command COM_CHANGE_USER, data
167
163
  @user = user
@@ -175,7 +171,7 @@ class Mysql
175
171
  alias_method :old_read_one_row, :read_one_row
176
172
 
177
173
  def read_one_row( field_count )
178
- if version_meets_minimum?( 4, 1, 1 )
174
+ if @use_411
179
175
  read_one_row_41( field_count )
180
176
  else
181
177
  old_read_one_row( field_count )
@@ -203,7 +199,7 @@ class Mysql
203
199
  alias_method :old_skip_result, :skip_result
204
200
 
205
201
  def skip_result
206
- if version_meets_minimum?( 4, 1, 1 )
202
+ if @use_411
207
203
  skip_result_41
208
204
  else
209
205
  old_skip_result
@@ -229,7 +225,7 @@ class Mysql
229
225
  alias_method :old_unpack_fields, :unpack_fields
230
226
 
231
227
  def unpack_fields( data, long_flag_protocol )
232
- if version_meets_minimum?( 4, 1, 1 )
228
+ if @use_411
233
229
  unpack_fields_41( data, long_flag_protocol )
234
230
  else
235
231
  old_unpack_fields( data, long_flag_protocol )
@@ -267,7 +263,7 @@ class Mysql
267
263
  alias_method :old_read_query_result, :read_query_result
268
264
 
269
265
  def read_query_result
270
- if version_meets_minimum?( 4, 1, 1 )
266
+ if @use_411
271
267
  read_query_result_41
272
268
  else
273
269
  old_read_query_result
@@ -1,8 +1,8 @@
1
1
  module ActiveRecord
2
2
  module Version #:nodoc:
3
3
  MAJOR = 1
4
- MINOR = 12
5
- TINY = 2
4
+ MINOR = 13
5
+ TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/rakefile CHANGED
@@ -71,7 +71,7 @@ spec = Gem::Specification.new do |s|
71
71
  s.files = s.files + Dir.glob( "#{dir}/**/*" ).delete_if { |item| item.include?( "\.svn" ) }
72
72
  end
73
73
 
74
- s.add_dependency('activesupport', '= 1.2.2' + PKG_BUILD)
74
+ s.add_dependency('activesupport', '= 1.2.3' + PKG_BUILD)
75
75
 
76
76
  s.files.delete "test/fixtures/fixture_database.sqlite"
77
77
  s.files.delete "test/fixtures/fixture_database_2.sqlite"
@@ -17,3 +17,8 @@ class Test::Unit::TestCase #:nodoc:
17
17
  Fixtures.create_fixtures(File.dirname(__FILE__) + "/fixtures/", table_names, &block)
18
18
  end
19
19
  end
20
+
21
+ def current_adapter?(type)
22
+ ActiveRecord::ConnectionAdapters.const_defined?(type) &&
23
+ ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters.const_get(type))
24
+ end
@@ -18,7 +18,7 @@ if ActiveRecord::Base.connection.supports_migrations?
18
18
  ActiveRecord::Schema.define(:version => 7) do
19
19
  create_table :fruits do |t|
20
20
  t.column :color, :string
21
- t.column :size, :string
21
+ t.column :fruit_size, :string # NOTE: "size" is reserved in Oracle
22
22
  t.column :texture, :string
23
23
  t.column :flavor, :string
24
24
  end
@@ -0,0 +1,37 @@
1
+ require 'abstract_unit'
2
+ require 'fixtures/post'
3
+ require 'fixtures/comment'
4
+ require 'fixtures/project'
5
+ require 'fixtures/developer'
6
+
7
+ class AssociationsExtensionsTest < Test::Unit::TestCase
8
+ fixtures :projects, :developers, :developers_projects, :comments, :posts
9
+
10
+ def test_extension_on_has_many
11
+ assert_equal comments(:more_greetings), posts(:welcome).comments.find_most_recent
12
+ end
13
+
14
+ def test_extension_on_habtm
15
+ assert_equal projects(:action_controller), developers(:david).projects.find_most_recent
16
+ end
17
+
18
+ def test_named_extension_on_habtm
19
+ assert_equal projects(:action_controller), developers(:david).projects_extended_by_name.find_most_recent
20
+ end
21
+
22
+ def test_marshalling_extensions
23
+ david = developers(:david)
24
+ assert_equal projects(:action_controller), david.projects.find_most_recent
25
+
26
+ david = Marshal.load(Marshal.dump(david))
27
+ assert_equal projects(:action_controller), david.projects.find_most_recent
28
+ end
29
+
30
+ def test_marshalling_named_extensions
31
+ david = developers(:david)
32
+ assert_equal projects(:action_controller), david.projects_extended_by_name.find_most_recent
33
+
34
+ david = Marshal.load(Marshal.dump(david))
35
+ assert_equal projects(:action_controller), david.projects_extended_by_name.find_most_recent
36
+ end
37
+ end
@@ -186,4 +186,29 @@ class EagerAssociationTest < Test::Unit::TestCase
186
186
  assert_nothing_raised { Post.find(:all, :include => 'comments') }
187
187
  end
188
188
 
189
+ def test_preconfigured_includes_with_belongs_to
190
+ author = posts(:welcome).author_with_posts
191
+ assert_equal 5, author.posts.size
192
+ end
193
+
194
+ def test_preconfigured_includes_with_has_one
195
+ comment = posts(:sti_comments).very_special_comment_with_post
196
+ assert_equal posts(:sti_comments), comment.post
197
+ end
198
+
199
+ def test_preconfigured_includes_with_has_many
200
+ posts = authors(:david).posts_with_comments
201
+ assert_equal 2, posts.first.comments.size
202
+ end
203
+
204
+ def test_preconfigured_includes_with_habtm
205
+ posts = authors(:david).posts_with_categories
206
+ assert_equal 2, posts.first.categories.size
207
+ end
208
+
209
+ def test_preconfigured_includes_with_has_many_and_habtm
210
+ posts = authors(:david).posts_with_comments_and_categories
211
+ assert_equal 2, posts.first.comments.size
212
+ assert_equal 2, posts.first.categories.size
213
+ end
189
214
  end
@@ -490,6 +490,14 @@ class HasManyAssociationsTest < Test::Unit::TestCase
490
490
  assert_equal 3, companies(:first_firm).clients_of_firm(true).size
491
491
  end
492
492
 
493
+ def test_find_or_create
494
+ number_of_clients = companies(:first_firm).clients.size
495
+ the_client = companies(:first_firm).clients.find_or_create_by_name("Yet another client")
496
+ assert_equal number_of_clients + 1, companies(:first_firm, :refresh).clients.size
497
+ assert_equal the_client, companies(:first_firm).clients.find_or_create_by_name("Yet another client")
498
+ assert_equal number_of_clients + 1, companies(:first_firm, :refresh).clients.size
499
+ end
500
+
493
501
  def test_deleting
494
502
  force_signal37_to_load_all_clients_of_firm
495
503
  companies(:first_firm).clients_of_firm.delete(companies(:first_firm).clients_of_firm.first)
@@ -1151,7 +1159,7 @@ class HasAndBelongsToManyAssociationsTest < Test::Unit::TestCase
1151
1159
  kenReloaded = Developer.find_by_name 'Ken'
1152
1160
  # SQL Server doesn't have a separate column type just for dates,
1153
1161
  # so the time is in the string and incorrectly formatted
1154
- if ActiveRecord::ConnectionAdapters.const_defined? :SQLServerAdapter and ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::SQLServerAdapter)
1162
+ if current_adapter?(:SQLServerAdapter)
1155
1163
  kenReloaded.projects.each { |prj| assert_equal(sqlnow, prj.joined_on.strftime("%Y/%m/%d 00:00:00")) }
1156
1164
  else
1157
1165
  kenReloaded.projects.each { |prj| assert_equal(now.to_s, prj.joined_on.to_s) }
@@ -1245,8 +1253,8 @@ class HasAndBelongsToManyAssociationsTest < Test::Unit::TestCase
1245
1253
  def test_additional_columns_from_join_table
1246
1254
  # SQL Server doesn't have a separate column type just for dates,
1247
1255
  # so the time is in the string and incorrectly formatted
1248
- if ActiveRecord::ConnectionAdapters.const_defined? :SQLServerAdapter and ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::SQLServerAdapter)
1249
- assert_equal Time.mktime(2004, 10, 10).strftime("%Y/%m/%d 00:00:00"), Time.parse(Developer.find(1).projects.first.joined_on).strftime("%Y/%m/%d 00:00:00")
1256
+ if current_adapter?(:SQLServerAdapter)
1257
+ assert_equal Time.mktime(2004, 10, 10).strftime("%Y/%m/%d 00:00:00"), Developer.find(1).projects.first.joined_on.strftime("%Y/%m/%d 00:00:00")
1250
1258
  else
1251
1259
  assert_equal Date.new(2004, 10, 10).to_s, Developer.find(1).projects.first.joined_on.to_s
1252
1260
  end
@@ -1266,9 +1274,9 @@ class HasAndBelongsToManyAssociationsTest < Test::Unit::TestCase
1266
1274
  jamis.projects.push_with_attributes(projects(:action_controller), :joined_on => Date.today)
1267
1275
  # SQL Server doesn't have a separate column type just for dates,
1268
1276
  # so the time is in the string and incorrectly formatted
1269
- if ActiveRecord::ConnectionAdapters.const_defined? :SQLServerAdapter and ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::SQLServerAdapter)
1270
- assert_equal Time.now.strftime("%Y/%m/%d 00:00:00"), Time.parse(jamis.projects.select { |p| p.name == projects(:action_controller).name }.first.joined_on).strftime("%Y/%m/%d 00:00:00")
1271
- assert_equal Time.now.strftime("%Y/%m/%d 00:00:00"), Time.parse(developers(:jamis).projects.select { |p| p.name == projects(:action_controller).name }.first.joined_on).strftime("%Y/%m/%d 00:00:00")
1277
+ if current_adapter?(:SQLServerAdapter)
1278
+ assert_equal Time.now.strftime("%Y/%m/%d 00:00:00"), jamis.projects.select { |p| p.name == projects(:action_controller).name }.first.joined_on.strftime("%Y/%m/%d 00:00:00")
1279
+ assert_equal Time.now.strftime("%Y/%m/%d 00:00:00"), developers(:jamis).projects.select { |p| p.name == projects(:action_controller).name }.first.joined_on.strftime("%Y/%m/%d 00:00:00")
1272
1280
  else
1273
1281
  assert_equal Date.today.to_s, jamis.projects.select { |p| p.name == projects(:action_controller).name }.first.joined_on.to_s
1274
1282
  assert_equal Date.today.to_s, developers(:jamis).projects.select { |p| p.name == projects(:action_controller).name }.first.joined_on.to_s
@@ -16,6 +16,7 @@ class CreditCard < ActiveRecord::Base; end
16
16
  class MasterCreditCard < ActiveRecord::Base; end
17
17
  class Post < ActiveRecord::Base; end
18
18
  class Computer < ActiveRecord::Base; end
19
+ class NonExistentTable < ActiveRecord::Base; end
19
20
 
20
21
  class LoosePerson < ActiveRecord::Base
21
22
  attr_protected :credit_rating, :administrator
@@ -42,6 +43,11 @@ end
42
43
  class BasicsTest < Test::Unit::TestCase
43
44
  fixtures :topics, :companies, :developers, :projects, :computers
44
45
 
46
+ def test_table_exists
47
+ assert !NonExistentTable.table_exists?
48
+ assert Topic.table_exists?
49
+ end
50
+
45
51
  def test_set_attributes
46
52
  topic = Topic.find(1)
47
53
  topic.attributes = { "title" => "Budget", "author_name" => "Jason" }
@@ -115,7 +121,10 @@ class BasicsTest < Test::Unit::TestCase
115
121
  assert_equal(%w( one two three four five ), topic.content)
116
122
  end
117
123
 
118
- def test_attributes_hash
124
+ def test_case_sensitive_attributes_hash
125
+ # DB2 is not case-sensitive
126
+ return true if current_adapter?(:DB2Adapter)
127
+
119
128
  assert_equal @loaded_fixtures['computers']['workstation'].to_hash, Computer.find(:first).attributes
120
129
  end
121
130
 
@@ -220,26 +229,20 @@ class BasicsTest < Test::Unit::TestCase
220
229
 
221
230
  def test_preserving_date_objects
222
231
  # SQL Server doesn't have a separate column type just for dates, so all are returned as time
223
- if ActiveRecord::ConnectionAdapters.const_defined? :SQLServerAdapter
224
- return true if ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::SQLServerAdapter)
225
- end
232
+ return true if current_adapter?(:SQLServerAdapter)
226
233
 
227
234
  assert_kind_of(
228
235
  Date, Topic.find(1).last_read,
229
236
  "The last_read attribute should be of the Date class"
230
237
  )
238
+ end
231
239
 
232
- # Oracle does not have a TIME datatype.
233
- if ActiveRecord::ConnectionAdapters.const_defined? :OracleAdapter
234
- return true if ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::OracleAdapter)
235
- end
240
+ def test_preserving_time_objects
236
241
  assert_kind_of(
237
242
  Time, Topic.find(1).bonus_time,
238
243
  "The bonus_time attribute should be of the Time class"
239
244
  )
240
- end
241
245
 
242
- def test_preserving_time_objects
243
246
  assert_kind_of(
244
247
  Time, Topic.find(1).written_on,
245
248
  "The written_on attribute should be of the Time class"
@@ -384,9 +387,8 @@ class BasicsTest < Test::Unit::TestCase
384
387
 
385
388
  def test_update_all
386
389
  # The ADO library doesn't support the number of affected rows
387
- if ActiveRecord::ConnectionAdapters.const_defined? :SQLServerAdapter
388
- return true if ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::SQLServerAdapter)
389
- end
390
+ return true if current_adapter?(:SQLServerAdapter)
391
+
390
392
  assert_equal 2, Topic.update_all("content = 'bulk updated!'")
391
393
  assert_equal "bulk updated!", Topic.find(1).content
392
394
  assert_equal "bulk updated!", Topic.find(2).content
@@ -406,9 +408,8 @@ class BasicsTest < Test::Unit::TestCase
406
408
 
407
409
  def test_delete_all
408
410
  # The ADO library doesn't support the number of affected rows
409
- if ActiveRecord::ConnectionAdapters.const_defined? :SQLServerAdapter
410
- return true if ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::SQLServerAdapter)
411
- end
411
+ return true if current_adapter?(:SQLServerAdapter)
412
+
412
413
  assert_equal 2, Topic.delete_all
413
414
  end
414
415
 
@@ -471,16 +472,16 @@ class BasicsTest < Test::Unit::TestCase
471
472
  assert_nil topic.last_read
472
473
  end
473
474
 
474
- # Oracle and SQLServer do not have a TIME datatype.
475
- unless 'OCI' == ActiveRecord::Base.connection.adapter_name or ActiveRecord::ConnectionAdapters.const_defined?(:SQLServerAdapter)
476
- def test_utc_as_time_zone
477
- Topic.default_timezone = :utc
478
- attributes = { "bonus_time" => "5:42:00AM" }
479
- topic = Topic.find(1)
480
- topic.attributes = attributes
481
- assert_equal Time.utc(2000, 1, 1, 5, 42, 0), topic.bonus_time
482
- Topic.default_timezone = :local
483
- end
475
+ def test_utc_as_time_zone
476
+ # Oracle and SQLServer do not have a TIME datatype.
477
+ return true if current_adapter?(:SQLServerAdapter) || current_adapter?(:OCIAdapter)
478
+
479
+ Topic.default_timezone = :utc
480
+ attributes = { "bonus_time" => "5:42:00AM" }
481
+ topic = Topic.find(1)
482
+ topic.attributes = attributes
483
+ assert_equal Time.utc(2000, 1, 1, 5, 42, 0), topic.bonus_time
484
+ Topic.default_timezone = :local
484
485
  end
485
486
 
486
487
  def test_default_values_on_empty_strings
@@ -587,26 +588,26 @@ class BasicsTest < Test::Unit::TestCase
587
588
 
588
589
  def test_multiparameter_attributes_on_date
589
590
  # SQL Server doesn't have a separate column type just for dates, so all are returned as time
590
- if ActiveRecord::ConnectionAdapters.const_defined? :SQLServerAdapter
591
- return true if ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::SQLServerAdapter)
592
- end
591
+ return true if current_adapter?(:SQLServerAdapter)
593
592
 
594
593
  attributes = { "last_read(1i)" => "2004", "last_read(2i)" => "6", "last_read(3i)" => "24" }
595
594
  topic = Topic.find(1)
596
595
  topic.attributes = attributes
597
- assert_equal Date.new(2004, 6, 24).to_s, topic.last_read.to_s
596
+ # note that extra #to_date call allows test to pass for Oracle, which
597
+ # treats dates/times the same
598
+ assert_equal Date.new(2004, 6, 24).to_s, topic.last_read.to_date.to_s
598
599
  end
599
600
 
600
601
  def test_multiparameter_attributes_on_date_with_empty_date
601
602
  # SQL Server doesn't have a separate column type just for dates, so all are returned as time
602
- if ActiveRecord::ConnectionAdapters.const_defined? :SQLServerAdapter
603
- return true if ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::SQLServerAdapter)
604
- end
603
+ return true if current_adapter?(:SQLServerAdapter)
605
604
 
606
605
  attributes = { "last_read(1i)" => "2004", "last_read(2i)" => "6", "last_read(3i)" => "" }
607
606
  topic = Topic.find(1)
608
607
  topic.attributes = attributes
609
- assert_equal Date.new(2004, 6, 1).to_s, topic.last_read.to_s
608
+ # note that extra #to_date call allows test to pass for Oracle, which
609
+ # treats dates/times the same
610
+ assert_equal Date.new(2004, 6, 1).to_s, topic.last_read.to_date.to_s
610
611
  end
611
612
 
612
613
  def test_multiparameter_attributes_on_date_with_all_empty
@@ -646,14 +647,8 @@ class BasicsTest < Test::Unit::TestCase
646
647
  end
647
648
 
648
649
  def test_attributes_on_dummy_time
649
- # Oracle does not have a TIME datatype.
650
- if ActiveRecord::ConnectionAdapters.const_defined? :OracleAdapter
651
- return true if ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::OracleAdapter)
652
- end
653
- # Sqlserver doesn't either .
654
- if ActiveRecord::ConnectionAdapters.const_defined? :SQLServerAdapter
655
- return true if ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::SQLServerAdapter)
656
- end
650
+ # Oracle and SQL Server do not have a TIME datatype.
651
+ return true if current_adapter?(:SQLServerAdapter) || current_adapter?(:OCIAdapter)
657
652
 
658
653
  attributes = {
659
654
  "bonus_time" => "5:42:00AM"
@@ -734,7 +729,7 @@ class BasicsTest < Test::Unit::TestCase
734
729
  end
735
730
 
736
731
  # TODO: extend defaults tests to other databases!
737
- if 'PostgreSQL' == ActiveRecord::Base.connection.adapter_name
732
+ if current_adapter?(:PostgreSQLAdapter)
738
733
  def test_default
739
734
  default = Default.new
740
735
 
@@ -1035,6 +1030,30 @@ class BasicsTest < Test::Unit::TestCase
1035
1030
  assert_nothing_raised { Category.new.send(:interpolate_sql, 'foo bar} baz') }
1036
1031
  end
1037
1032
 
1033
+ def test_scoped_find_conditions
1034
+ developers = Developer.with_scope(:find => { :conditions => 'salary > 90000' }) do
1035
+ Developer.find(:all, :conditions => 'id < 5')
1036
+ end
1037
+ david = Developer.find(1)
1038
+ assert !developers.include?(david) # David's salary is less than 90,000
1039
+ assert_equal 3, developers.size
1040
+ end
1041
+
1042
+ def test_scoped_find_limit_offset
1043
+ developers = Developer.with_scope(:find => { :limit => 3, :offset => 2 }) do
1044
+ Developer.find(:all, :order => 'id')
1045
+ end
1046
+ david = Developer.find(1)
1047
+ jamis = Developer.find(1)
1048
+ assert !developers.include?(david) # David has id 1
1049
+ assert !developers.include?(jamis) # Jamis has id 2
1050
+ assert_equal 3, developers.size
1051
+
1052
+ # Test without scoped find conditions to ensure we get the whole thing
1053
+ developers = Developer.find(:all, :order => 'id')
1054
+ assert_equal 10, developers.size
1055
+ end
1056
+
1038
1057
  # FIXME: this test ought to run, but it needs to run sandboxed so that it
1039
1058
  # doesn't b0rk the current test environment by undefing everything.
1040
1059
  #
@@ -1058,9 +1077,8 @@ class BasicsTest < Test::Unit::TestCase
1058
1077
  #end
1059
1078
 
1060
1079
  private
1061
-
1062
1080
  def assert_readers(model, exceptions)
1063
1081
  expected_readers = model.column_names - (model.serialized_attributes.keys + exceptions + ['id'])
1064
- assert_equal expected_readers.sort, model.read_methods.keys.sort
1082
+ assert_equal expected_readers.sort, model.read_methods.to_a.sort
1065
1083
  end
1066
1084
  end
@@ -18,7 +18,7 @@ def make_connection(clazz, db_file, db_definitions_file)
18
18
  raise SqliteError.new("Seems that there is no sqlite executable available") unless system(sqlite_command)
19
19
  clazz.establish_connection(
20
20
  :adapter => "sqlite",
21
- :dbfile => db_file)
21
+ :database => db_file)
22
22
  script = File.read("#{BASE_DIR}/db_definitions/#{db_definitions_file}")
23
23
  # SQLite-Ruby has problems with semi-colon separated commands, so split and execute one at a time
24
24
  script.split(';').each do
@@ -28,7 +28,7 @@ def make_connection(clazz, db_file, db_definitions_file)
28
28
  else
29
29
  clazz.establish_connection(
30
30
  :adapter => "sqlite",
31
- :dbfile => db_file)
31
+ :database => db_file)
32
32
  end
33
33
  end
34
34