activerecord 1.10.1 → 1.11.0
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.
Potentially problematic release.
This version of activerecord might be problematic. Click here for more details.
- data/CHANGELOG +187 -19
 - data/RUNNING_UNIT_TESTS +11 -0
 - data/lib/active_record.rb +3 -1
 - data/lib/active_record/acts/list.rb +25 -14
 - data/lib/active_record/acts/nested_set.rb +4 -4
 - data/lib/active_record/acts/tree.rb +18 -1
 - data/lib/active_record/associations.rb +90 -17
 - data/lib/active_record/associations/association_collection.rb +44 -5
 - data/lib/active_record/associations/has_and_belongs_to_many_association.rb +17 -4
 - data/lib/active_record/associations/has_many_association.rb +13 -3
 - data/lib/active_record/associations/has_one_association.rb +19 -0
 - data/lib/active_record/base.rb +292 -268
 - data/lib/active_record/callbacks.rb +14 -14
 - data/lib/active_record/connection_adapters/abstract_adapter.rb +137 -75
 - data/lib/active_record/connection_adapters/db2_adapter.rb +10 -8
 - data/lib/active_record/connection_adapters/mysql_adapter.rb +91 -64
 - data/lib/active_record/connection_adapters/oci_adapter.rb +6 -6
 - data/lib/active_record/connection_adapters/postgresql_adapter.rb +113 -60
 - data/lib/active_record/connection_adapters/sqlite_adapter.rb +15 -12
 - data/lib/active_record/connection_adapters/sqlserver_adapter.rb +159 -132
 - data/lib/active_record/fixtures.rb +59 -12
 - data/lib/active_record/locking.rb +10 -9
 - data/lib/active_record/migration.rb +112 -5
 - data/lib/active_record/query_cache.rb +64 -0
 - data/lib/active_record/timestamp.rb +10 -8
 - data/lib/active_record/validations.rb +121 -26
 - data/rakefile +16 -10
 - data/test/aaa_create_tables_test.rb +26 -48
 - data/test/abstract_unit.rb +3 -0
 - data/test/aggregations_test.rb +19 -19
 - data/test/association_callbacks_test.rb +110 -0
 - data/test/associations_go_eager_test.rb +48 -14
 - data/test/associations_test.rb +344 -142
 - data/test/base_test.rb +150 -31
 - data/test/binary_test.rb +7 -0
 - data/test/callbacks_test.rb +24 -5
 - data/test/column_alias_test.rb +2 -2
 - data/test/connections/native_sqlserver_odbc/connection.rb +26 -0
 - data/test/deprecated_associations_test.rb +27 -28
 - data/test/deprecated_finder_test.rb +8 -9
 - data/test/finder_test.rb +52 -17
 - data/test/fixtures/author.rb +39 -0
 - data/test/fixtures/categories.yml +7 -0
 - data/test/fixtures/categories_posts.yml +8 -0
 - data/test/fixtures/category.rb +2 -0
 - data/test/fixtures/comment.rb +3 -1
 - data/test/fixtures/comments.yml +43 -1
 - data/test/fixtures/companies.yml +14 -0
 - data/test/fixtures/company.rb +1 -1
 - data/test/fixtures/computers.yml +2 -1
 - data/test/fixtures/db_definitions/db2.sql +7 -2
 - data/test/fixtures/db_definitions/mysql.drop.sql +2 -0
 - data/test/fixtures/db_definitions/mysql.sql +11 -6
 - data/test/fixtures/db_definitions/oci.sql +7 -2
 - data/test/fixtures/db_definitions/postgresql.drop.sql +3 -1
 - data/test/fixtures/db_definitions/postgresql.sql +8 -5
 - data/test/fixtures/db_definitions/sqlite.drop.sql +2 -0
 - data/test/fixtures/db_definitions/sqlite.sql +9 -4
 - data/test/fixtures/db_definitions/sqlserver.drop.sql +2 -0
 - data/test/fixtures/db_definitions/sqlserver.sql +12 -7
 - data/test/fixtures/developer.rb +8 -1
 - data/test/fixtures/migrations/3_innocent_jointable.rb +12 -0
 - data/test/fixtures/post.rb +8 -2
 - data/test/fixtures/posts.yml +21 -0
 - data/test/fixtures/project.rb +14 -1
 - data/test/fixtures/subscriber.rb +3 -0
 - data/test/fixtures_test.rb +14 -0
 - data/test/inheritance_test.rb +30 -22
 - data/test/lifecycle_test.rb +3 -4
 - data/test/locking_test.rb +2 -4
 - data/test/migration_test.rb +186 -0
 - data/test/mixin_nested_set_test.rb +19 -19
 - data/test/mixin_test.rb +88 -88
 - data/test/modules_test.rb +5 -10
 - data/test/multiple_db_test.rb +2 -0
 - data/test/pk_test.rb +8 -12
 - data/test/reflection_test.rb +8 -4
 - data/test/schema_test_postgresql.rb +63 -0
 - data/test/thread_safety_test.rb +4 -1
 - data/test/transactions_test.rb +9 -2
 - data/test/unconnected_test.rb +1 -0
 - data/test/validations_test.rb +151 -8
 - metadata +11 -5
 - data/test/migration_mysql.rb +0 -104
 
    
        data/test/base_test.rb
    CHANGED
    
    | 
         @@ -2,6 +2,7 @@ require 'abstract_unit' 
     | 
|
| 
       2 
2 
     | 
    
         
             
            require 'fixtures/topic'
         
     | 
| 
       3 
3 
     | 
    
         
             
            require 'fixtures/reply'
         
     | 
| 
       4 
4 
     | 
    
         
             
            require 'fixtures/company'
         
     | 
| 
      
 5 
     | 
    
         
            +
            require 'fixtures/developer'
         
     | 
| 
       5 
6 
     | 
    
         
             
            require 'fixtures/project'
         
     | 
| 
       6 
7 
     | 
    
         
             
            require 'fixtures/default'
         
     | 
| 
       7 
8 
     | 
    
         
             
            require 'fixtures/auto_id'
         
     | 
| 
         @@ -11,23 +12,33 @@ class Category < ActiveRecord::Base; end 
     | 
|
| 
       11 
12 
     | 
    
         
             
            class Smarts < ActiveRecord::Base; end
         
     | 
| 
       12 
13 
     | 
    
         
             
            class CreditCard < ActiveRecord::Base; end
         
     | 
| 
       13 
14 
     | 
    
         
             
            class MasterCreditCard < ActiveRecord::Base; end
         
     | 
| 
      
 15 
     | 
    
         
            +
            class Post < ActiveRecord::Base; end
         
     | 
| 
      
 16 
     | 
    
         
            +
            class Computer < ActiveRecord::Base; end
         
     | 
| 
       14 
17 
     | 
    
         | 
| 
       15 
18 
     | 
    
         
             
            class LoosePerson < ActiveRecord::Base
         
     | 
| 
       16 
19 
     | 
    
         
             
              attr_protected :credit_rating, :administrator
         
     | 
| 
       17 
20 
     | 
    
         
             
            end
         
     | 
| 
       18 
21 
     | 
    
         | 
| 
      
 22 
     | 
    
         
            +
            class LooseDescendant < LoosePerson
         
     | 
| 
      
 23 
     | 
    
         
            +
              attr_protected :phone_number
         
     | 
| 
      
 24 
     | 
    
         
            +
            end
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
       19 
26 
     | 
    
         
             
            class TightPerson < ActiveRecord::Base
         
     | 
| 
       20 
27 
     | 
    
         
             
              attr_accessible :name, :address
         
     | 
| 
       21 
28 
     | 
    
         
             
            end
         
     | 
| 
       22 
29 
     | 
    
         | 
| 
       23 
     | 
    
         
            -
            class  
     | 
| 
      
 30 
     | 
    
         
            +
            class TightDescendant < TightPerson
         
     | 
| 
       24 
31 
     | 
    
         
             
              attr_accessible :phone_number
         
     | 
| 
       25 
32 
     | 
    
         
             
            end
         
     | 
| 
       26 
33 
     | 
    
         | 
| 
       27 
34 
     | 
    
         
             
            class Booleantest < ActiveRecord::Base; end
         
     | 
| 
       28 
35 
     | 
    
         | 
| 
      
 36 
     | 
    
         
            +
            class Task < ActiveRecord::Base
         
     | 
| 
      
 37 
     | 
    
         
            +
              attr_protected :starting
         
     | 
| 
      
 38 
     | 
    
         
            +
            end
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
       29 
40 
     | 
    
         
             
            class BasicsTest < Test::Unit::TestCase
         
     | 
| 
       30 
     | 
    
         
            -
              fixtures :topics, :companies, :projects
         
     | 
| 
      
 41 
     | 
    
         
            +
              fixtures :topics, :companies, :developers, :projects, :computers
         
     | 
| 
       31 
42 
     | 
    
         | 
| 
       32 
43 
     | 
    
         
             
              def test_set_attributes
         
     | 
| 
       33 
44 
     | 
    
         
             
                topic = Topic.find(1)
         
     | 
| 
         @@ -35,7 +46,7 @@ class BasicsTest < Test::Unit::TestCase 
     | 
|
| 
       35 
46 
     | 
    
         
             
                topic.save
         
     | 
| 
       36 
47 
     | 
    
         
             
                assert_equal("Budget", topic.title)
         
     | 
| 
       37 
48 
     | 
    
         
             
                assert_equal("Jason", topic.author_name)
         
     | 
| 
       38 
     | 
    
         
            -
                assert_equal( 
     | 
| 
      
 49 
     | 
    
         
            +
                assert_equal(topics(:first).author_email_address, Topic.find(1).author_email_address)
         
     | 
| 
       39 
50 
     | 
    
         
             
              end
         
     | 
| 
       40 
51 
     | 
    
         | 
| 
       41 
52 
     | 
    
         
             
              def test_integers_as_nil
         
     | 
| 
         @@ -103,7 +114,7 @@ class BasicsTest < Test::Unit::TestCase 
     | 
|
| 
       103 
114 
     | 
    
         
             
              end
         
     | 
| 
       104 
115 
     | 
    
         | 
| 
       105 
116 
     | 
    
         
             
              def test_attributes_hash
         
     | 
| 
       106 
     | 
    
         
            -
                assert_equal @ 
     | 
| 
      
 117 
     | 
    
         
            +
                assert_equal @loaded_fixtures['computers']['workstation'].to_hash, Computer.find(:first).attributes
         
     | 
| 
       107 
118 
     | 
    
         
             
              end
         
     | 
| 
       108 
119 
     | 
    
         | 
| 
       109 
120 
     | 
    
         
             
              def test_create
         
     | 
| 
         @@ -159,6 +170,21 @@ class BasicsTest < Test::Unit::TestCase 
     | 
|
| 
       159 
170 
     | 
    
         
             
                topicReloaded.send :write_attribute, 'does_not_exist', 'test'
         
     | 
| 
       160 
171 
     | 
    
         
             
                assert_nothing_raised { topicReloaded.save }
         
     | 
| 
       161 
172 
     | 
    
         
             
              end
         
     | 
| 
      
 173 
     | 
    
         
            +
              
         
     | 
| 
      
 174 
     | 
    
         
            +
              def test_write_attribute
         
     | 
| 
      
 175 
     | 
    
         
            +
                topic = Topic.new
         
     | 
| 
      
 176 
     | 
    
         
            +
                topic.send(:write_attribute, :title, "Still another topic")
         
     | 
| 
      
 177 
     | 
    
         
            +
                assert_equal "Still another topic", topic.title
         
     | 
| 
      
 178 
     | 
    
         
            +
             
     | 
| 
      
 179 
     | 
    
         
            +
                topic.send(:write_attribute, "title", "Still another topic: part 2")
         
     | 
| 
      
 180 
     | 
    
         
            +
                assert_equal "Still another topic: part 2", topic.title
         
     | 
| 
      
 181 
     | 
    
         
            +
              end
         
     | 
| 
      
 182 
     | 
    
         
            +
             
     | 
| 
      
 183 
     | 
    
         
            +
              def test_read_attribute_when_false
         
     | 
| 
      
 184 
     | 
    
         
            +
                topic = topics(:first)
         
     | 
| 
      
 185 
     | 
    
         
            +
                topic.approved = false
         
     | 
| 
      
 186 
     | 
    
         
            +
                assert_equal 0, topic.approved, "approved should be 0"
         
     | 
| 
      
 187 
     | 
    
         
            +
              end
         
     | 
| 
       162 
188 
     | 
    
         | 
| 
       163 
189 
     | 
    
         
             
              def test_preserving_date_objects
         
     | 
| 
       164 
190 
     | 
    
         
             
                # SQL Server doesn't have a separate column type just for dates, so all are returned as time
         
     | 
| 
         @@ -194,7 +220,6 @@ class BasicsTest < Test::Unit::TestCase 
     | 
|
| 
       194 
220 
     | 
    
         
             
                topic.written_on = "2003-12-12 23:23:00"
         
     | 
| 
       195 
221 
     | 
    
         
             
                topic.save
         
     | 
| 
       196 
222 
     | 
    
         
             
                topic.destroy
         
     | 
| 
       197 
     | 
    
         
            -
                assert_raise(TypeError) { topic.save }
         
     | 
| 
       198 
223 
     | 
    
         
             
                assert_raise(ActiveRecord::RecordNotFound) { Topic.find(topic.id) }
         
     | 
| 
       199 
224 
     | 
    
         
             
              end
         
     | 
| 
       200 
225 
     | 
    
         | 
| 
         @@ -221,16 +246,16 @@ class BasicsTest < Test::Unit::TestCase 
     | 
|
| 
       221 
246 
     | 
    
         
             
              end
         
     | 
| 
       222 
247 
     | 
    
         | 
| 
       223 
248 
     | 
    
         
             
              def test_load
         
     | 
| 
       224 
     | 
    
         
            -
                topics = Topic. 
     | 
| 
      
 249 
     | 
    
         
            +
                topics = Topic.find(:all, :order => 'id')    
         
     | 
| 
       225 
250 
     | 
    
         
             
                assert_equal(2, topics.size)
         
     | 
| 
       226 
     | 
    
         
            -
                assert_equal( 
     | 
| 
      
 251 
     | 
    
         
            +
                assert_equal(topics(:first).title, topics.first.title)
         
     | 
| 
       227 
252 
     | 
    
         
             
              end
         
     | 
| 
       228 
253 
     | 
    
         | 
| 
       229 
254 
     | 
    
         
             
              def test_load_with_condition
         
     | 
| 
       230 
     | 
    
         
            -
                topics = Topic. 
     | 
| 
      
 255 
     | 
    
         
            +
                topics = Topic.find(:all, :conditions => "author_name = 'Mary'")
         
     | 
| 
       231 
256 
     | 
    
         | 
| 
       232 
257 
     | 
    
         
             
                assert_equal(1, topics.size)
         
     | 
| 
       233 
     | 
    
         
            -
                assert_equal( 
     | 
| 
      
 258 
     | 
    
         
            +
                assert_equal(topics(:second).title, topics.first.title)
         
     | 
| 
       234 
259 
     | 
    
         
             
              end
         
     | 
| 
       235 
260 
     | 
    
         | 
| 
       236 
261 
     | 
    
         
             
              def test_table_name_guesses
         
     | 
| 
         @@ -270,15 +295,16 @@ class BasicsTest < Test::Unit::TestCase 
     | 
|
| 
       270 
295 
     | 
    
         
             
              end
         
     | 
| 
       271 
296 
     | 
    
         | 
| 
       272 
297 
     | 
    
         
             
              def test_destroy_all
         
     | 
| 
       273 
     | 
    
         
            -
                assert_equal 2, Topic. 
     | 
| 
      
 298 
     | 
    
         
            +
                assert_equal 2, Topic.count
         
     | 
| 
       274 
299 
     | 
    
         | 
| 
       275 
300 
     | 
    
         
             
                Topic.destroy_all "author_name = 'Mary'"
         
     | 
| 
       276 
     | 
    
         
            -
                assert_equal 1, Topic. 
     | 
| 
      
 301 
     | 
    
         
            +
                assert_equal 1, Topic.count
         
     | 
| 
       277 
302 
     | 
    
         
             
              end
         
     | 
| 
       278 
303 
     | 
    
         | 
| 
       279 
304 
     | 
    
         
             
              def test_destroy_many
         
     | 
| 
      
 305 
     | 
    
         
            +
                assert_equal 3, Client.count
         
     | 
| 
       280 
306 
     | 
    
         
             
                Client.destroy([2, 3])
         
     | 
| 
       281 
     | 
    
         
            -
                assert_equal  
     | 
| 
      
 307 
     | 
    
         
            +
                assert_equal 1, Client.count
         
     | 
| 
       282 
308 
     | 
    
         
             
              end
         
     | 
| 
       283 
309 
     | 
    
         | 
| 
       284 
310 
     | 
    
         
             
              def test_delete_many
         
     | 
| 
         @@ -308,6 +334,10 @@ class BasicsTest < Test::Unit::TestCase 
     | 
|
| 
       308 
334 
     | 
    
         
             
              end
         
     | 
| 
       309 
335 
     | 
    
         | 
| 
       310 
336 
     | 
    
         
             
              def test_update_all
         
     | 
| 
      
 337 
     | 
    
         
            +
                # The ADO library doesn't support the number of affected rows
         
     | 
| 
      
 338 
     | 
    
         
            +
                if ActiveRecord::ConnectionAdapters.const_defined? :SQLServerAdapter
         
     | 
| 
      
 339 
     | 
    
         
            +
                  return true if ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::SQLServerAdapter)
         
     | 
| 
      
 340 
     | 
    
         
            +
                end
         
     | 
| 
       311 
341 
     | 
    
         
             
                assert_equal 2, Topic.update_all("content = 'bulk updated!'")
         
     | 
| 
       312 
342 
     | 
    
         
             
                assert_equal "bulk updated!", Topic.find(1).content
         
     | 
| 
       313 
343 
     | 
    
         
             
                assert_equal "bulk updated!", Topic.find(2).content
         
     | 
| 
         @@ -326,6 +356,10 @@ class BasicsTest < Test::Unit::TestCase 
     | 
|
| 
       326 
356 
     | 
    
         
             
              end
         
     | 
| 
       327 
357 
     | 
    
         | 
| 
       328 
358 
     | 
    
         
             
              def test_delete_all
         
     | 
| 
      
 359 
     | 
    
         
            +
                # The ADO library doesn't support the number of affected rows
         
     | 
| 
      
 360 
     | 
    
         
            +
                if ActiveRecord::ConnectionAdapters.const_defined? :SQLServerAdapter
         
     | 
| 
      
 361 
     | 
    
         
            +
                  return true if ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::SQLServerAdapter)
         
     | 
| 
      
 362 
     | 
    
         
            +
                end
         
     | 
| 
       329 
363 
     | 
    
         
             
                assert_equal 2, Topic.delete_all
         
     | 
| 
       330 
364 
     | 
    
         
             
              end
         
     | 
| 
       331 
365 
     | 
    
         | 
| 
         @@ -428,6 +462,14 @@ class BasicsTest < Test::Unit::TestCase 
     | 
|
| 
       428 
462 
     | 
    
         
             
                assert client.frozen?
         
     | 
| 
       429 
463 
     | 
    
         
             
              end
         
     | 
| 
       430 
464 
     | 
    
         | 
| 
      
 465 
     | 
    
         
            +
              def test_destroy_record_with_associations
         
     | 
| 
      
 466 
     | 
    
         
            +
                client = Client.find(3)
         
     | 
| 
      
 467 
     | 
    
         
            +
                client.destroy
         
     | 
| 
      
 468 
     | 
    
         
            +
                assert client.frozen?
         
     | 
| 
      
 469 
     | 
    
         
            +
                assert_kind_of Firm, client.firm
         
     | 
| 
      
 470 
     | 
    
         
            +
                assert_raises(TypeError) { client.name = "something else" }
         
     | 
| 
      
 471 
     | 
    
         
            +
              end
         
     | 
| 
      
 472 
     | 
    
         
            +
              
         
     | 
| 
       431 
473 
     | 
    
         
             
              def test_update_attribute
         
     | 
| 
       432 
474 
     | 
    
         
             
                assert !Topic.find(1).approved?
         
     | 
| 
       433 
475 
     | 
    
         
             
                Topic.find(1).update_attribute("approved", true)
         
     | 
| 
         @@ -463,8 +505,17 @@ class BasicsTest < Test::Unit::TestCase 
     | 
|
| 
       463 
505 
     | 
    
         
             
              end
         
     | 
| 
       464 
506 
     | 
    
         | 
| 
       465 
507 
     | 
    
         
             
              def test_mass_assignment_protection_inheritance
         
     | 
| 
      
 508 
     | 
    
         
            +
                assert_nil LoosePerson.accessible_attributes
         
     | 
| 
       466 
509 
     | 
    
         
             
                assert_equal [ :credit_rating, :administrator ], LoosePerson.protected_attributes
         
     | 
| 
      
 510 
     | 
    
         
            +
             
     | 
| 
      
 511 
     | 
    
         
            +
                assert_nil LooseDescendant.accessible_attributes
         
     | 
| 
      
 512 
     | 
    
         
            +
                assert_equal [ :credit_rating, :administrator, :phone_number  ], LooseDescendant.protected_attributes
         
     | 
| 
      
 513 
     | 
    
         
            +
             
     | 
| 
       467 
514 
     | 
    
         
             
                assert_nil TightPerson.protected_attributes
         
     | 
| 
      
 515 
     | 
    
         
            +
                assert_equal [ :name, :address ], TightPerson.accessible_attributes
         
     | 
| 
      
 516 
     | 
    
         
            +
             
     | 
| 
      
 517 
     | 
    
         
            +
                assert_nil TightDescendant.protected_attributes
         
     | 
| 
      
 518 
     | 
    
         
            +
                assert_equal [ :name, :address, :phone_number  ], TightDescendant.accessible_attributes
         
     | 
| 
       468 
519 
     | 
    
         
             
              end
         
     | 
| 
       469 
520 
     | 
    
         | 
| 
       470 
521 
     | 
    
         
             
              def test_multiparameter_attributes_on_date
         
     | 
| 
         @@ -518,6 +569,15 @@ class BasicsTest < Test::Unit::TestCase 
     | 
|
| 
       518 
569 
     | 
    
         
             
                assert_equal Time.local(2004, 6, 24, 16, 24, 0), topic.written_on
         
     | 
| 
       519 
570 
     | 
    
         
             
              end
         
     | 
| 
       520 
571 
     | 
    
         | 
| 
      
 572 
     | 
    
         
            +
              def test_multiparameter_mass_assignment_protector
         
     | 
| 
      
 573 
     | 
    
         
            +
                task = Task.new
         
     | 
| 
      
 574 
     | 
    
         
            +
                time = Time.mktime(0)
         
     | 
| 
      
 575 
     | 
    
         
            +
                task.starting = time 
         
     | 
| 
      
 576 
     | 
    
         
            +
                attributes = { "starting(1i)" => "2004", "starting(2i)" => "6", "starting(3i)" => "24" }
         
     | 
| 
      
 577 
     | 
    
         
            +
                task.attributes = attributes
         
     | 
| 
      
 578 
     | 
    
         
            +
                assert_equal time, task.starting
         
     | 
| 
      
 579 
     | 
    
         
            +
              end
         
     | 
| 
      
 580 
     | 
    
         
            +
             
     | 
| 
       521 
581 
     | 
    
         
             
              def test_attributes_on_dummy_time
         
     | 
| 
       522 
582 
     | 
    
         
             
                # Oracle does not have a TIME datatype.
         
     | 
| 
       523 
583 
     | 
    
         
             
                if ActiveRecord::ConnectionAdapters.const_defined? :OracleAdapter
         
     | 
| 
         @@ -546,7 +606,8 @@ class BasicsTest < Test::Unit::TestCase 
     | 
|
| 
       546 
606 
     | 
    
         | 
| 
       547 
607 
     | 
    
         
             
              def test_clone
         
     | 
| 
       548 
608 
     | 
    
         
             
                topic = Topic.find(1)
         
     | 
| 
       549 
     | 
    
         
            -
                cloned_topic =  
     | 
| 
      
 609 
     | 
    
         
            +
                cloned_topic = nil
         
     | 
| 
      
 610 
     | 
    
         
            +
                assert_nothing_raised { cloned_topic = topic.clone }
         
     | 
| 
       550 
611 
     | 
    
         
             
                assert_equal topic.title, cloned_topic.title
         
     | 
| 
       551 
612 
     | 
    
         
             
                assert cloned_topic.new_record?
         
     | 
| 
       552 
613 
     | 
    
         | 
| 
         @@ -566,7 +627,33 @@ class BasicsTest < Test::Unit::TestCase 
     | 
|
| 
       566 
627 
     | 
    
         
             
                assert !cloned_topic.new_record?
         
     | 
| 
       567 
628 
     | 
    
         
             
                assert cloned_topic.id != topic.id
         
     | 
| 
       568 
629 
     | 
    
         
             
              end
         
     | 
| 
       569 
     | 
    
         
            -
             
     | 
| 
      
 630 
     | 
    
         
            +
             
     | 
| 
      
 631 
     | 
    
         
            +
              def test_clone_with_aggregate_of_same_name_as_attribute
         
     | 
| 
      
 632 
     | 
    
         
            +
                dev = DeveloperWithAggregate.find(1)
         
     | 
| 
      
 633 
     | 
    
         
            +
                assert_kind_of DeveloperSalary, dev.salary
         
     | 
| 
      
 634 
     | 
    
         
            +
             
     | 
| 
      
 635 
     | 
    
         
            +
                clone = nil
         
     | 
| 
      
 636 
     | 
    
         
            +
                assert_nothing_raised { clone = dev.clone }
         
     | 
| 
      
 637 
     | 
    
         
            +
                assert_kind_of DeveloperSalary, clone.salary
         
     | 
| 
      
 638 
     | 
    
         
            +
                assert_equal dev.salary.amount, clone.salary.amount
         
     | 
| 
      
 639 
     | 
    
         
            +
                assert clone.new_record?
         
     | 
| 
      
 640 
     | 
    
         
            +
             
     | 
| 
      
 641 
     | 
    
         
            +
                # test if the attributes have been cloned
         
     | 
| 
      
 642 
     | 
    
         
            +
                original_amount = clone.salary.amount
         
     | 
| 
      
 643 
     | 
    
         
            +
                dev.salary.amount = 1
         
     | 
| 
      
 644 
     | 
    
         
            +
                assert_equal original_amount, clone.salary.amount
         
     | 
| 
      
 645 
     | 
    
         
            +
             
     | 
| 
      
 646 
     | 
    
         
            +
                assert clone.save
         
     | 
| 
      
 647 
     | 
    
         
            +
                assert !clone.new_record?
         
     | 
| 
      
 648 
     | 
    
         
            +
                assert clone.id != dev.id
         
     | 
| 
      
 649 
     | 
    
         
            +
              end
         
     | 
| 
      
 650 
     | 
    
         
            +
             
     | 
| 
      
 651 
     | 
    
         
            +
              def test_clone_preserves_subtype
         
     | 
| 
      
 652 
     | 
    
         
            +
                clone = nil
         
     | 
| 
      
 653 
     | 
    
         
            +
                assert_nothing_raised { clone = Company.find(3).clone }
         
     | 
| 
      
 654 
     | 
    
         
            +
                assert_kind_of Client, clone
         
     | 
| 
      
 655 
     | 
    
         
            +
              end
         
     | 
| 
      
 656 
     | 
    
         
            +
             
     | 
| 
       570 
657 
     | 
    
         
             
              def test_bignum
         
     | 
| 
       571 
658 
     | 
    
         
             
                company = Company.find(1)
         
     | 
| 
       572 
659 
     | 
    
         
             
                company.rating = 2147483647
         
     | 
| 
         @@ -671,35 +758,35 @@ class BasicsTest < Test::Unit::TestCase 
     | 
|
| 
       671 
758 
     | 
    
         
             
              end
         
     | 
| 
       672 
759 
     | 
    
         | 
| 
       673 
760 
     | 
    
         
             
              def test_increment_attribute
         
     | 
| 
       674 
     | 
    
         
            -
                assert_equal 0,  
     | 
| 
       675 
     | 
    
         
            -
                 
     | 
| 
       676 
     | 
    
         
            -
                assert_equal 1,  
     | 
| 
      
 761 
     | 
    
         
            +
                assert_equal 0, topics(:first).replies_count
         
     | 
| 
      
 762 
     | 
    
         
            +
                topics(:first).increment! :replies_count
         
     | 
| 
      
 763 
     | 
    
         
            +
                assert_equal 1, topics(:first, :reload).replies_count
         
     | 
| 
       677 
764 
     | 
    
         | 
| 
       678 
     | 
    
         
            -
                 
     | 
| 
       679 
     | 
    
         
            -
                assert_equal 3,  
     | 
| 
      
 765 
     | 
    
         
            +
                topics(:first).increment(:replies_count).increment!(:replies_count)
         
     | 
| 
      
 766 
     | 
    
         
            +
                assert_equal 3, topics(:first, :reload).replies_count
         
     | 
| 
       680 
767 
     | 
    
         
             
              end
         
     | 
| 
       681 
768 
     | 
    
         | 
| 
       682 
769 
     | 
    
         
             
              def test_increment_nil_attribute
         
     | 
| 
       683 
     | 
    
         
            -
                assert_nil  
     | 
| 
       684 
     | 
    
         
            -
                 
     | 
| 
       685 
     | 
    
         
            -
                assert_equal 1,  
     | 
| 
      
 770 
     | 
    
         
            +
                assert_nil topics(:first).parent_id
         
     | 
| 
      
 771 
     | 
    
         
            +
                topics(:first).increment! :parent_id
         
     | 
| 
      
 772 
     | 
    
         
            +
                assert_equal 1, topics(:first).parent_id
         
     | 
| 
       686 
773 
     | 
    
         
             
              end
         
     | 
| 
       687 
774 
     | 
    
         | 
| 
       688 
775 
     | 
    
         
             
              def test_decrement_attribute
         
     | 
| 
       689 
     | 
    
         
            -
                 
     | 
| 
       690 
     | 
    
         
            -
                assert_equal 2,  
     | 
| 
      
 776 
     | 
    
         
            +
                topics(:first).increment(:replies_count).increment!(:replies_count)
         
     | 
| 
      
 777 
     | 
    
         
            +
                assert_equal 2, topics(:first).replies_count
         
     | 
| 
       691 
778 
     | 
    
         | 
| 
       692 
     | 
    
         
            -
                 
     | 
| 
       693 
     | 
    
         
            -
                assert_equal 1,  
     | 
| 
      
 779 
     | 
    
         
            +
                topics(:first).decrement!(:replies_count)
         
     | 
| 
      
 780 
     | 
    
         
            +
                assert_equal 1, topics(:first, :reload).replies_count
         
     | 
| 
       694 
781 
     | 
    
         | 
| 
       695 
     | 
    
         
            -
                 
     | 
| 
       696 
     | 
    
         
            -
                assert_equal -1,  
     | 
| 
      
 782 
     | 
    
         
            +
                topics(:first).decrement(:replies_count).decrement!(:replies_count)
         
     | 
| 
      
 783 
     | 
    
         
            +
                assert_equal -1, topics(:first, :reload).replies_count
         
     | 
| 
       697 
784 
     | 
    
         
             
              end
         
     | 
| 
       698 
785 
     | 
    
         | 
| 
       699 
786 
     | 
    
         
             
              def test_toggle_attribute
         
     | 
| 
       700 
     | 
    
         
            -
                assert  
     | 
| 
       701 
     | 
    
         
            -
                 
     | 
| 
       702 
     | 
    
         
            -
                assert  
     | 
| 
      
 787 
     | 
    
         
            +
                assert !topics(:first).approved?
         
     | 
| 
      
 788 
     | 
    
         
            +
                topics(:first).toggle!(:approved)
         
     | 
| 
      
 789 
     | 
    
         
            +
                assert topics(:first).approved?
         
     | 
| 
       703 
790 
     | 
    
         
             
              end
         
     | 
| 
       704 
791 
     | 
    
         | 
| 
       705 
792 
     | 
    
         
             
              def test_reload
         
     | 
| 
         @@ -764,4 +851,36 @@ class BasicsTest < Test::Unit::TestCase 
     | 
|
| 
       764 
851 
     | 
    
         
             
                k.set_inheritance_column { original_inheritance_column + "_id" }
         
     | 
| 
       765 
852 
     | 
    
         
             
                assert_equal "type_id", k.inheritance_column
         
     | 
| 
       766 
853 
     | 
    
         
             
              end
         
     | 
| 
      
 854 
     | 
    
         
            +
             
     | 
| 
      
 855 
     | 
    
         
            +
              def test_count_with_join
         
     | 
| 
      
 856 
     | 
    
         
            +
                res = Post.count_by_sql "SELECT COUNT(*) FROM posts LEFT JOIN comments ON posts.id=comments.post_id WHERE posts.type = 'Post'"
         
     | 
| 
      
 857 
     | 
    
         
            +
                res2 = res + 1
         
     | 
| 
      
 858 
     | 
    
         
            +
                assert_nothing_raised do
         
     | 
| 
      
 859 
     | 
    
         
            +
                  res2 = Post.count("posts.type = 'Post'",
         
     | 
| 
      
 860 
     | 
    
         
            +
                                    "LEFT JOIN comments ON posts.id=comments.post_id")
         
     | 
| 
      
 861 
     | 
    
         
            +
                end
         
     | 
| 
      
 862 
     | 
    
         
            +
                assert_equal res, res2
         
     | 
| 
      
 863 
     | 
    
         
            +
              end
         
     | 
| 
      
 864 
     | 
    
         
            +
              
         
     | 
| 
      
 865 
     | 
    
         
            +
              def test_clear_association_cache_stored     
         
     | 
| 
      
 866 
     | 
    
         
            +
                firm = Firm.find(1)
         
     | 
| 
      
 867 
     | 
    
         
            +
                assert_kind_of Firm, firm
         
     | 
| 
      
 868 
     | 
    
         
            +
             
     | 
| 
      
 869 
     | 
    
         
            +
                firm.clear_association_cache
         
     | 
| 
      
 870 
     | 
    
         
            +
                assert_equal Firm.find(1).clients.collect{ |x| x.name }.sort, firm.clients.collect{ |x| x.name }.sort
         
     | 
| 
      
 871 
     | 
    
         
            +
              end
         
     | 
| 
      
 872 
     | 
    
         
            +
              
         
     | 
| 
      
 873 
     | 
    
         
            +
              def test_clear_association_cache_new_record
         
     | 
| 
      
 874 
     | 
    
         
            +
                 firm            = Firm.new
         
     | 
| 
      
 875 
     | 
    
         
            +
                 client_stored   = Client.find(3)
         
     | 
| 
      
 876 
     | 
    
         
            +
                 client_new      = Client.new
         
     | 
| 
      
 877 
     | 
    
         
            +
                 client_new.name = "The Joneses"
         
     | 
| 
      
 878 
     | 
    
         
            +
                 clients         = [ client_stored, client_new ]
         
     | 
| 
      
 879 
     | 
    
         
            +
                 
         
     | 
| 
      
 880 
     | 
    
         
            +
                 firm.clients    << clients
         
     | 
| 
      
 881 
     | 
    
         
            +
             
     | 
| 
      
 882 
     | 
    
         
            +
                 firm.clear_association_cache
         
     | 
| 
      
 883 
     | 
    
         
            +
             
     | 
| 
      
 884 
     | 
    
         
            +
                 assert_equal    firm.clients.collect{ |x| x.name }.sort, clients.collect{ |x| x.name }.sort
         
     | 
| 
      
 885 
     | 
    
         
            +
              end
         
     | 
| 
       767 
886 
     | 
    
         
             
            end
         
     | 
    
        data/test/binary_test.rb
    CHANGED
    
    | 
         @@ -7,6 +7,13 @@ class BinaryTest < Test::Unit::TestCase 
     | 
|
| 
       7 
7 
     | 
    
         
             
              end
         
     | 
| 
       8 
8 
     | 
    
         | 
| 
       9 
9 
     | 
    
         
             
              def test_load_save
         
     | 
| 
      
 10 
     | 
    
         
            +
                # Without using prepared statements, it makes no sense to test
         
     | 
| 
      
 11 
     | 
    
         
            +
                # BLOB data with SQL Server, because the length of a statement is
         
     | 
| 
      
 12 
     | 
    
         
            +
                # limited to 8KB.
         
     | 
| 
      
 13 
     | 
    
         
            +
                if ActiveRecord::ConnectionAdapters.const_defined? :SQLServerAdapter
         
     | 
| 
      
 14 
     | 
    
         
            +
                  return true if ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::SQLServerAdapter)
         
     | 
| 
      
 15 
     | 
    
         
            +
                end
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
       10 
17 
     | 
    
         
             
                # Without using prepared statements, it makes no sense to test
         
     | 
| 
       11 
18 
     | 
    
         
             
                # BLOB data with DB2, because the length of a statement is
         
     | 
| 
       12 
19 
     | 
    
         
             
                # limited to 32KB.
         
     | 
    
        data/test/callbacks_test.rb
    CHANGED
    
    | 
         @@ -1,9 +1,9 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'abstract_unit'
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            class CallbackDeveloper < ActiveRecord::Base
         
     | 
| 
       4 
     | 
    
         
            -
               
     | 
| 
       5 
     | 
    
         
            -
                def table_name; 'developers' end
         
     | 
| 
      
 4 
     | 
    
         
            +
              set_table_name 'developers'
         
     | 
| 
       6 
5 
     | 
    
         | 
| 
      
 6 
     | 
    
         
            +
              class << self
         
     | 
| 
       7 
7 
     | 
    
         
             
                def callback_string(callback_method)
         
     | 
| 
       8 
8 
     | 
    
         
             
                  "history << [#{callback_method.to_sym.inspect}, :string]"
         
     | 
| 
       9 
9 
     | 
    
         
             
                end
         
     | 
| 
         @@ -49,12 +49,31 @@ class CallbackDeveloper < ActiveRecord::Base 
     | 
|
| 
       49 
49 
     | 
    
         
             
              end
         
     | 
| 
       50 
50 
     | 
    
         
             
            end
         
     | 
| 
       51 
51 
     | 
    
         | 
| 
      
 52 
     | 
    
         
            +
            class RecursiveCallbackDeveloper < ActiveRecord::Base
         
     | 
| 
      
 53 
     | 
    
         
            +
              set_table_name 'developers'
         
     | 
| 
       52 
54 
     | 
    
         | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
       54 
     | 
    
         
            -
               
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
      
 55 
     | 
    
         
            +
              before_save :on_before_save
         
     | 
| 
      
 56 
     | 
    
         
            +
              after_save :on_after_save
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
              attr_reader :on_before_save_called, :on_after_save_called
         
     | 
| 
      
 59 
     | 
    
         
            +
             
     | 
| 
      
 60 
     | 
    
         
            +
              def on_before_save
         
     | 
| 
      
 61 
     | 
    
         
            +
                @on_before_save_called ||= 0
         
     | 
| 
      
 62 
     | 
    
         
            +
                @on_before_save_called += 1
         
     | 
| 
      
 63 
     | 
    
         
            +
                save unless @on_before_save_called > 1
         
     | 
| 
       56 
64 
     | 
    
         
             
              end
         
     | 
| 
       57 
65 
     | 
    
         | 
| 
      
 66 
     | 
    
         
            +
              def on_after_save
         
     | 
| 
      
 67 
     | 
    
         
            +
                @on_after_save_called ||= 0
         
     | 
| 
      
 68 
     | 
    
         
            +
                @on_after_save_called += 1
         
     | 
| 
      
 69 
     | 
    
         
            +
                save unless @on_after_save_called > 1
         
     | 
| 
      
 70 
     | 
    
         
            +
              end
         
     | 
| 
      
 71 
     | 
    
         
            +
            end
         
     | 
| 
      
 72 
     | 
    
         
            +
             
     | 
| 
      
 73 
     | 
    
         
            +
             
     | 
| 
      
 74 
     | 
    
         
            +
            class CallbacksTest < Test::Unit::TestCase
         
     | 
| 
      
 75 
     | 
    
         
            +
              fixtures :developers
         
     | 
| 
      
 76 
     | 
    
         
            +
             
     | 
| 
       58 
77 
     | 
    
         
             
              def test_initialize
         
     | 
| 
       59 
78 
     | 
    
         
             
                david = CallbackDeveloper.new
         
     | 
| 
       60 
79 
     | 
    
         
             
                assert_equal [
         
     | 
    
        data/test/column_alias_test.rb
    CHANGED
    
    | 
         @@ -8,11 +8,11 @@ class TestColumnAlias < Test::Unit::TestCase 
     | 
|
| 
       8 
8 
     | 
    
         
             
                if ActiveRecord::ConnectionAdapters.const_defined? :OracleAdapter
         
     | 
| 
       9 
9 
     | 
    
         
             
                  if ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::OracleAdapter)
         
     | 
| 
       10 
10 
     | 
    
         
             
                    records = topic.connection.select_all("SELECT id AS pk FROM topics WHERE ROWNUM < 2")
         
     | 
| 
       11 
     | 
    
         
            -
                    assert_equal(records[0].keys[0] 
     | 
| 
      
 11 
     | 
    
         
            +
                    assert_equal("pk", records[0].keys[0])
         
     | 
| 
       12 
12 
     | 
    
         
             
                  end
         
     | 
| 
       13 
13 
     | 
    
         
             
                else
         
     | 
| 
       14 
14 
     | 
    
         
             
                  records = topic.connection.select_all("SELECT id AS pk FROM topics")
         
     | 
| 
       15 
     | 
    
         
            -
                  assert_equal(records[0].keys[0] 
     | 
| 
      
 15 
     | 
    
         
            +
                  assert_equal("pk", records[0].keys[0])
         
     | 
| 
       16 
16 
     | 
    
         
             
                end
         
     | 
| 
       17 
17 
     | 
    
         
             
              end
         
     | 
| 
       18 
18 
     | 
    
         | 
| 
         @@ -0,0 +1,26 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            print "Using native SQLServer via ODBC\n"
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'fixtures/course'
         
     | 
| 
      
 3 
     | 
    
         
            +
            require 'logger'
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            ActiveRecord::Base.logger = Logger.new("debug.log")
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            dsn1 = 'activerecord_unittest'
         
     | 
| 
      
 8 
     | 
    
         
            +
            dsn2 = 'activerecord_unittest2'
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
            ActiveRecord::Base.establish_connection(
         
     | 
| 
      
 11 
     | 
    
         
            +
              :adapter  => "sqlserver",
         
     | 
| 
      
 12 
     | 
    
         
            +
              :mode     => "ODBC",
         
     | 
| 
      
 13 
     | 
    
         
            +
              :host     => "localhost",
         
     | 
| 
      
 14 
     | 
    
         
            +
              :username => "sa",
         
     | 
| 
      
 15 
     | 
    
         
            +
              :password => "",
         
     | 
| 
      
 16 
     | 
    
         
            +
              :dsn => dsn1
         
     | 
| 
      
 17 
     | 
    
         
            +
            )
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
            Course.establish_connection(
         
     | 
| 
      
 20 
     | 
    
         
            +
              :adapter  => "sqlserver",
         
     | 
| 
      
 21 
     | 
    
         
            +
              :mode     => "ODBC",
         
     | 
| 
      
 22 
     | 
    
         
            +
              :host     => "localhost",
         
     | 
| 
      
 23 
     | 
    
         
            +
              :username => "sa",
         
     | 
| 
      
 24 
     | 
    
         
            +
              :password => "",
         
     | 
| 
      
 25 
     | 
    
         
            +
              :dsn => dsn2
         
     | 
| 
      
 26 
     | 
    
         
            +
            )
         
     | 
| 
         @@ -16,10 +16,8 @@ raise "ActiveRecord should have barked on bad collection keys" unless bad_collec 
     | 
|
| 
       16 
16 
     | 
    
         | 
| 
       17 
17 
     | 
    
         | 
| 
       18 
18 
     | 
    
         
             
            class DeprecatedAssociationsTest < Test::Unit::TestCase
         
     | 
| 
       19 
     | 
    
         
            -
               
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
                @signals37 = Firm.find(1)
         
     | 
| 
       22 
     | 
    
         
            -
              end
         
     | 
| 
      
 19 
     | 
    
         
            +
              fixtures :accounts, :companies, :developers, :projects, :topics,
         
     | 
| 
      
 20 
     | 
    
         
            +
                       :developers_projects
         
     | 
| 
       23 
21 
     | 
    
         | 
| 
       24 
22 
     | 
    
         
             
              def test_has_many_find
         
     | 
| 
       25 
23 
     | 
    
         
             
                assert_equal 2, Firm.find_first.clients.length
         
     | 
| 
         @@ -62,13 +60,14 @@ class DeprecatedAssociationsTest < Test::Unit::TestCase 
     | 
|
| 
       62 
60 
     | 
    
         
             
              end
         
     | 
| 
       63 
61 
     | 
    
         | 
| 
       64 
62 
     | 
    
         
             
              def test_has_many_dependence
         
     | 
| 
       65 
     | 
    
         
            -
                assert_equal  
     | 
| 
      
 63 
     | 
    
         
            +
                assert_equal 3, Client.find_all.length
         
     | 
| 
       66 
64 
     | 
    
         
             
                Firm.find_first.destroy
         
     | 
| 
       67 
     | 
    
         
            -
                assert_equal  
     | 
| 
      
 65 
     | 
    
         
            +
                assert_equal 1, Client.find_all.length
         
     | 
| 
       68 
66 
     | 
    
         
             
              end
         
     | 
| 
       69 
67 
     | 
    
         | 
| 
      
 68 
     | 
    
         
            +
              uses_transaction :test_has_many_dependence_with_transaction_support_on_failure
         
     | 
| 
       70 
69 
     | 
    
         
             
              def test_has_many_dependence_with_transaction_support_on_failure
         
     | 
| 
       71 
     | 
    
         
            -
                assert_equal  
     | 
| 
      
 70 
     | 
    
         
            +
                assert_equal 3, Client.find_all.length
         
     | 
| 
       72 
71 
     | 
    
         | 
| 
       73 
72 
     | 
    
         
             
                firm = Firm.find_first
         
     | 
| 
       74 
73 
     | 
    
         
             
                clients = firm.clients
         
     | 
| 
         @@ -76,7 +75,7 @@ class DeprecatedAssociationsTest < Test::Unit::TestCase 
     | 
|
| 
       76 
75 
     | 
    
         | 
| 
       77 
76 
     | 
    
         
             
                firm.destroy rescue "do nothing"
         
     | 
| 
       78 
77 
     | 
    
         | 
| 
       79 
     | 
    
         
            -
                assert_equal  
     | 
| 
      
 78 
     | 
    
         
            +
                assert_equal 3, Client.find_all.length
         
     | 
| 
       80 
79 
     | 
    
         
             
              end
         
     | 
| 
       81 
80 
     | 
    
         | 
| 
       82 
81 
     | 
    
         
             
              def test_has_one_dependence
         
     | 
| 
         @@ -94,7 +93,7 @@ class DeprecatedAssociationsTest < Test::Unit::TestCase 
     | 
|
| 
       94 
93 
     | 
    
         
             
              end
         
     | 
| 
       95 
94 
     | 
    
         | 
| 
       96 
95 
     | 
    
         
             
              def test_belongs_to
         
     | 
| 
       97 
     | 
    
         
            -
                assert_equal  
     | 
| 
      
 96 
     | 
    
         
            +
                assert_equal companies(:first_firm).name, Client.find(3).firm.name
         
     | 
| 
       98 
97 
     | 
    
         
             
                assert Client.find(3).has_firm?, "Microsoft should have a firm"
         
     | 
| 
       99 
98 
     | 
    
         
             
                # assert !Company.find(1).has_firm?, "37signals shouldn't have a firm"
         
     | 
| 
       100 
99 
     | 
    
         
             
              end
         
     | 
| 
         @@ -115,25 +114,25 @@ class DeprecatedAssociationsTest < Test::Unit::TestCase 
     | 
|
| 
       115 
114 
     | 
    
         
             
              end
         
     | 
| 
       116 
115 
     | 
    
         | 
| 
       117 
116 
     | 
    
         
             
              def test_has_one
         
     | 
| 
       118 
     | 
    
         
            -
                assert  
     | 
| 
       119 
     | 
    
         
            -
                assert_equal Account.find(1).credit_limit,  
     | 
| 
       120 
     | 
    
         
            -
                assert  
     | 
| 
       121 
     | 
    
         
            -
                assert Account.find(1).firm?( 
     | 
| 
      
 117 
     | 
    
         
            +
                assert companies(:first_firm).account?(Account.find(1))
         
     | 
| 
      
 118 
     | 
    
         
            +
                assert_equal Account.find(1).credit_limit, companies(:first_firm).account.credit_limit
         
     | 
| 
      
 119 
     | 
    
         
            +
                assert companies(:first_firm).has_account?, "37signals should have an account"
         
     | 
| 
      
 120 
     | 
    
         
            +
                assert Account.find(1).firm?(companies(:first_firm)), "37signals account should be able to backtrack"
         
     | 
| 
       122 
121 
     | 
    
         
             
                assert Account.find(1).has_firm?, "37signals account should be able to backtrack"
         
     | 
| 
       123 
122 
     | 
    
         | 
| 
       124 
123 
     | 
    
         
             
                assert !Account.find(2).has_firm?, "Unknown isn't linked"
         
     | 
| 
       125 
     | 
    
         
            -
                assert !Account.find(2).firm?( 
     | 
| 
      
 124 
     | 
    
         
            +
                assert !Account.find(2).firm?(companies(:first_firm)), "Unknown isn't linked"
         
     | 
| 
       126 
125 
     | 
    
         
             
              end
         
     | 
| 
       127 
126 
     | 
    
         | 
| 
       128 
127 
     | 
    
         
             
              def test_has_many_dependence_on_account
         
     | 
| 
       129 
128 
     | 
    
         
             
                assert_equal 2, Account.find_all.length
         
     | 
| 
       130 
     | 
    
         
            -
                 
     | 
| 
      
 129 
     | 
    
         
            +
                companies(:first_firm).destroy
         
     | 
| 
       131 
130 
     | 
    
         
             
                assert_equal 1, Account.find_all.length
         
     | 
| 
       132 
131 
     | 
    
         
             
              end
         
     | 
| 
       133 
132 
     | 
    
         | 
| 
       134 
133 
     | 
    
         
             
              def test_find_in
         
     | 
| 
       135 
     | 
    
         
            -
                assert_equal Client.find(2).name,  
     | 
| 
       136 
     | 
    
         
            -
                assert_raises(ActiveRecord::RecordNotFound) {  
     | 
| 
      
 134 
     | 
    
         
            +
                assert_equal Client.find(2).name, companies(:first_firm).find_in_clients(2).name
         
     | 
| 
      
 135 
     | 
    
         
            +
                assert_raises(ActiveRecord::RecordNotFound) { companies(:first_firm).find_in_clients(6) }
         
     | 
| 
       137 
136 
     | 
    
         
             
              end
         
     | 
| 
       138 
137 
     | 
    
         | 
| 
       139 
138 
     | 
    
         
             
              def test_force_reload
         
     | 
| 
         @@ -157,21 +156,21 @@ class DeprecatedAssociationsTest < Test::Unit::TestCase 
     | 
|
| 
       157 
156 
     | 
    
         
             
              end
         
     | 
| 
       158 
157 
     | 
    
         | 
| 
       159 
158 
     | 
    
         
             
              def test_included_in_collection
         
     | 
| 
       160 
     | 
    
         
            -
                assert  
     | 
| 
      
 159 
     | 
    
         
            +
                assert companies(:first_firm).clients.include?(Client.find(2))
         
     | 
| 
       161 
160 
     | 
    
         
             
              end
         
     | 
| 
       162 
161 
     | 
    
         | 
| 
       163 
162 
     | 
    
         
             
              def test_build_to_collection
         
     | 
| 
       164 
     | 
    
         
            -
                assert_equal 1,  
     | 
| 
       165 
     | 
    
         
            -
                new_client =  
     | 
| 
      
 163 
     | 
    
         
            +
                assert_equal 1, companies(:first_firm).clients_of_firm_count
         
     | 
| 
      
 164 
     | 
    
         
            +
                new_client = companies(:first_firm).build_to_clients_of_firm("name" => "Another Client")
         
     | 
| 
       166 
165 
     | 
    
         
             
                assert_equal "Another Client", new_client.name
         
     | 
| 
       167 
166 
     | 
    
         
             
                assert new_client.save
         
     | 
| 
       168 
167 
     | 
    
         | 
| 
       169 
     | 
    
         
            -
                assert new_client.firm?( 
     | 
| 
       170 
     | 
    
         
            -
                assert_equal 2,  
     | 
| 
      
 168 
     | 
    
         
            +
                assert new_client.firm?(companies(:first_firm))
         
     | 
| 
      
 169 
     | 
    
         
            +
                assert_equal 2, companies(:first_firm).clients_of_firm_count(true)
         
     | 
| 
       171 
170 
     | 
    
         
             
              end
         
     | 
| 
       172 
171 
     | 
    
         | 
| 
       173 
172 
     | 
    
         
             
              def test_create_in_collection
         
     | 
| 
       174 
     | 
    
         
            -
                assert_equal  
     | 
| 
      
 173 
     | 
    
         
            +
                assert_equal companies(:first_firm).create_in_clients_of_firm("name" => "Another Client"), companies(:first_firm).clients_of_firm(true).last
         
     | 
| 
       175 
174 
     | 
    
         
             
              end
         
     | 
| 
       176 
175 
     | 
    
         | 
| 
       177 
176 
     | 
    
         
             
              def test_has_and_belongs_to_many
         
     | 
| 
         @@ -182,7 +181,7 @@ class DeprecatedAssociationsTest < Test::Unit::TestCase 
     | 
|
| 
       182 
181 
     | 
    
         
             
                active_record = Project.find(1)
         
     | 
| 
       183 
182 
     | 
    
         
             
                assert active_record.has_developers?
         
     | 
| 
       184 
183 
     | 
    
         
             
                assert_equal 2, active_record.developers_count
         
     | 
| 
       185 
     | 
    
         
            -
                 
     | 
| 
      
 184 
     | 
    
         
            +
                assert active_record.developers.include?(david)
         
     | 
| 
       186 
185 
     | 
    
         
             
              end
         
     | 
| 
       187 
186 
     | 
    
         | 
| 
       188 
187 
     | 
    
         
             
              def test_has_and_belongs_to_many_removing
         
     | 
| 
         @@ -317,13 +316,13 @@ class DeprecatedAssociationsTest < Test::Unit::TestCase 
     | 
|
| 
       317 
316 
     | 
    
         
             
              end
         
     | 
| 
       318 
317 
     | 
    
         | 
| 
       319 
318 
     | 
    
         
             
              def test_has_one
         
     | 
| 
       320 
     | 
    
         
            -
                assert  
     | 
| 
       321 
     | 
    
         
            -
                assert  
     | 
| 
       322 
     | 
    
         
            -
                assert Account.find(1).firm?( 
     | 
| 
      
 319 
     | 
    
         
            +
                assert companies(:first_firm).account?(Account.find(1))
         
     | 
| 
      
 320 
     | 
    
         
            +
                assert companies(:first_firm).has_account?, "37signals should have an account"
         
     | 
| 
      
 321 
     | 
    
         
            +
                assert Account.find(1).firm?(companies(:first_firm)), "37signals account should be able to backtrack"
         
     | 
| 
       323 
322 
     | 
    
         
             
                assert Account.find(1).has_firm?, "37signals account should be able to backtrack"
         
     | 
| 
       324 
323 
     | 
    
         | 
| 
       325 
324 
     | 
    
         
             
                assert !Account.find(2).has_firm?, "Unknown isn't linked"
         
     | 
| 
       326 
     | 
    
         
            -
                assert !Account.find(2).firm?( 
     | 
| 
      
 325 
     | 
    
         
            +
                assert !Account.find(2).firm?(companies(:first_firm)), "Unknown isn't linked"
         
     | 
| 
       327 
326 
     | 
    
         
             
              end
         
     | 
| 
       328 
327 
     | 
    
         | 
| 
       329 
328 
     | 
    
         
             
              def test_has_one_build
         
     |