composite_primary_keys 3.0.9 → 3.1.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.
- data/History.txt +6 -0
- data/Rakefile +10 -1
- data/lib/composite_primary_keys.rb +75 -75
- data/lib/composite_primary_keys/base.rb +190 -194
- data/lib/composite_primary_keys/composite_arrays.rb +23 -23
- data/lib/composite_primary_keys/finder_methods.rb +0 -11
- data/lib/composite_primary_keys/reflection.rb +38 -38
- data/lib/composite_primary_keys/version.rb +2 -2
- data/test/abstract_unit.rb +3 -2
- data/test/connections/connection_spec.rb +1 -2
- data/test/connections/databases.example.yml +14 -12
- data/test/connections/databases.yml +14 -14
- data/test/connections/native_ibm_db/connection.rb +0 -3
- data/test/connections/native_mysql/connection.rb +3 -9
- data/test/connections/native_oracle/connection.rb +4 -10
- data/test/connections/native_oracle_enhanced/connection.rb +4 -11
- data/test/connections/native_postgresql/connection.rb +1 -3
- data/test/connections/native_sqlite/connection.rb +2 -4
- data/test/debug.log +589 -589
- data/test/fixtures/article.rb +5 -5
- data/test/fixtures/articles.yml +5 -5
- data/test/fixtures/capitol.rb +3 -0
- data/test/fixtures/capitols.yml +16 -0
- data/test/fixtures/db_definitions/mysql.sql +5 -0
- data/test/fixtures/db_definitions/postgresql.sql +5 -0
- data/test/fixtures/product.rb +7 -7
- data/test/fixtures/product_tariff.rb +5 -5
- data/test/fixtures/product_tariffs.yml +12 -12
- data/test/fixtures/products.yml +5 -5
- data/test/fixtures/reading.rb +4 -4
- data/test/fixtures/readings.yml +9 -9
- data/test/fixtures/reference_code.rb +7 -7
- data/test/fixtures/reference_codes.yml +29 -29
- data/test/fixtures/reference_type.rb +7 -7
- data/test/fixtures/reference_types.yml +9 -9
- data/test/fixtures/suburb.rb +5 -5
- data/test/fixtures/suburbs.yml +8 -8
- data/test/fixtures/tariff.rb +6 -6
- data/test/fixtures/tariffs.yml +12 -12
- data/test/fixtures/user.rb +10 -10
- data/test/fixtures/users.yml +5 -5
- data/test/hash_tricks.rb +34 -34
- data/test/test_associations.rb +180 -180
- data/test/test_attribute_methods.rb +0 -2
- data/test/test_attributes.rb +0 -5
- data/test/test_clone.rb +31 -33
- data/test/test_composite_arrays.rb +0 -2
- data/test/test_create.rb +0 -4
- data/test/test_delete.rb +92 -96
- data/test/test_equal.rb +21 -0
- data/test/test_exists.rb +0 -2
- data/test/test_find.rb +79 -76
- data/test/test_ids.rb +81 -83
- data/test/test_miscellaneous.rb +36 -38
- data/test/test_pagination.rb +35 -37
- data/test/test_polymorphic.rb +0 -6
- data/test/test_santiago.rb +23 -27
- data/test/test_suite.rb +1 -0
- data/test/test_tutorial_example.rb +0 -4
- data/test/test_update.rb +37 -39
- data/test/test_validations.rb +0 -1
- metadata +8 -4
    
        data/test/test_associations.rb
    CHANGED
    
    | @@ -1,181 +1,181 @@ | |
| 1 | 
            -
            require 'abstract_unit'
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            class TestAssociations < ActiveSupport::TestCase
         | 
| 4 | 
            -
              fixtures :articles, :products, :tariffs, :product_tariffs, :suburbs, :streets, :restaurants, :restaurants_suburbs,
         | 
| 5 | 
            -
                       :dorms, :rooms, :room_attributes, :room_attribute_assignments, :students, :room_assignments, :users, :readings,
         | 
| 6 | 
            -
                       :memberships
         | 
| 7 | 
            -
              
         | 
| 8 | 
            -
              def test_has_many_through_with_conditions_when_through_association_is_not_composite
         | 
| 9 | 
            -
                user = User.find(:first)
         | 
| 10 | 
            -
                assert_equal 1, user.articles.find(:all, :conditions => ["articles.name = ?", "Article One"]).size
         | 
| 11 | 
            -
              end
         | 
| 12 | 
            -
             | 
| 13 | 
            -
              def test_has_many_through_with_conditions_when_through_association_is_composite
         | 
| 14 | 
            -
                room = Room.find(:first)
         | 
| 15 | 
            -
                assert_equal 0, room.room_attributes.find(:all, :conditions => ["room_attributes.name != ?", "keg"]).size
         | 
| 16 | 
            -
              end
         | 
| 17 | 
            -
             | 
| 18 | 
            -
              def test_has_many_through_on_custom_finder_when_through_association_is_composite_finder_when_through_association_is_not_composite
         | 
| 19 | 
            -
                user = User.find(:first)
         | 
| 20 | 
            -
                assert_equal 1, user.find_custom_articles.size
         | 
| 21 | 
            -
              end
         | 
| 22 | 
            -
             | 
| 23 | 
            -
              def test_has_many_through_on_custom_finder_when_through_association_is_composite
         | 
| 24 | 
            -
                room = Room.find(:first)
         | 
| 25 | 
            -
                assert_equal 0, room.find_custom_room_attributes.size
         | 
| 26 | 
            -
              end
         | 
| 27 | 
            -
             | 
| 28 | 
            -
              def test_count
         | 
| 29 | 
            -
                assert_equal 2, Product.count(:include => :product_tariffs)
         | 
| 30 | 
            -
                assert_equal 3, Tariff.count(:include => :product_tariffs)
         | 
| 31 | 
            -
                assert_equal 2, Tariff.count(:group => :start_date).size
         | 
| 32 | 
            -
              end
         | 
| 33 | 
            -
             | 
| 34 | 
            -
              def test_products
         | 
| 35 | 
            -
                assert_not_nil products(:first_product).product_tariffs
         | 
| 36 | 
            -
                assert_equal 2, products(:first_product).product_tariffs.length
         | 
| 37 | 
            -
                assert_not_nil products(:first_product).tariffs
         | 
| 38 | 
            -
                assert_equal 2, products(:first_product).tariffs.length
         | 
| 39 | 
            -
                assert_not_nil products(:first_product).product_tariff
         | 
| 40 | 
            -
              end
         | 
| 41 | 
            -
             | 
| 42 | 
            -
              def test_product_tariffs
         | 
| 43 | 
            -
                assert_not_nil product_tariffs(:first_flat).product
         | 
| 44 | 
            -
                assert_not_nil product_tariffs(:first_flat).tariff
         | 
| 45 | 
            -
                assert_equal Product, product_tariffs(:first_flat).product.class
         | 
| 46 | 
            -
                assert_equal Tariff, product_tariffs(:first_flat).tariff.class
         | 
| 47 | 
            -
              end
         | 
| 48 | 
            -
             | 
| 49 | 
            -
              def test_tariffs
         | 
| 50 | 
            -
                assert_not_nil tariffs(:flat).product_tariffs
         | 
| 51 | 
            -
                assert_equal 1, tariffs(:flat).product_tariffs.length
         | 
| 52 | 
            -
                assert_not_nil tariffs(:flat).products
         | 
| 53 | 
            -
                assert_equal 1, tariffs(:flat).products.length
         | 
| 54 | 
            -
                assert_not_nil tariffs(:flat).product_tariff
         | 
| 55 | 
            -
              end
         | 
| 56 | 
            -
             | 
| 57 | 
            -
              # Its not generating the instances of associated classes from the rows
         | 
| 58 | 
            -
              def test_find_includes_products
         | 
| 59 | 
            -
                assert @products = Product.find(:all, :include => :product_tariffs)
         | 
| 60 | 
            -
                assert_equal 2, @products.length
         | 
| 61 | 
            -
                assert_not_nil @products.first.instance_variable_get('@product_tariffs'), '@product_tariffs not set; should be array'
         | 
| 62 | 
            -
                assert_equal 3, @products.inject(0) {|sum, tariff| sum + tariff.instance_variable_get('@product_tariffs').length},
         | 
| 63 | 
            -
                  "Incorrect number of product_tariffs returned"
         | 
| 64 | 
            -
              end
         | 
| 65 | 
            -
             | 
| 66 | 
            -
              def test_find_includes_tariffs
         | 
| 67 | 
            -
                assert @tariffs = Tariff.find(:all, :include => :product_tariffs)
         | 
| 68 | 
            -
                assert_equal 3, @tariffs.length
         | 
| 69 | 
            -
                assert_not_nil @tariffs.first.instance_variable_get('@product_tariffs'), '@product_tariffs not set; should be array'
         | 
| 70 | 
            -
                assert_equal 3, @tariffs.inject(0) {|sum, tariff| sum + tariff.instance_variable_get('@product_tariffs').length},
         | 
| 71 | 
            -
                  "Incorrect number of product_tariffs returnedturned"
         | 
| 72 | 
            -
              end
         | 
| 73 | 
            -
             | 
| 74 | 
            -
              def test_find_includes_product
         | 
| 75 | 
            -
                assert @product_tariffs = ProductTariff.find(:all, :include => :product)
         | 
| 76 | 
            -
                assert_equal 3, @product_tariffs.length
         | 
| 77 | 
            -
                assert_not_nil @product_tariffs.first.instance_variable_get('@product'), '@product not set'
         | 
| 78 | 
            -
              end
         | 
| 79 | 
            -
             | 
| 80 | 
            -
              def test_find_includes_comp_belongs_to_tariff
         | 
| 81 | 
            -
                assert @product_tariffs = ProductTariff.find(:all, :include => :tariff)
         | 
| 82 | 
            -
                assert_equal 3, @product_tariffs.length
         | 
| 83 | 
            -
                assert_not_nil @product_tariffs.first.instance_variable_get('@tariff'), '@tariff not set'
         | 
| 84 | 
            -
              end
         | 
| 85 | 
            -
             | 
| 86 | 
            -
              def test_find_includes_extended
         | 
| 87 | 
            -
                assert @products = Product.find(:all, :include => {:product_tariffs => :tariff})
         | 
| 88 | 
            -
                assert_equal 3, @products.inject(0) {|sum, product| sum + product.instance_variable_get('@product_tariffs').length},
         | 
| 89 | 
            -
                  "Incorrect number of product_tariffs returned"
         | 
| 90 | 
            -
             | 
| 91 | 
            -
                assert @tariffs = Tariff.find(:all, :include => {:product_tariffs => :product})
         | 
| 92 | 
            -
                assert_equal 3, @tariffs.inject(0) {|sum, tariff| sum + tariff.instance_variable_get('@product_tariffs').length},
         | 
| 93 | 
            -
                  "Incorrect number of product_tariffs returned"
         | 
| 94 | 
            -
              end
         | 
| 95 | 
            -
             | 
| 96 | 
            -
              def test_has_many_through
         | 
| 97 | 
            -
                @products = Product.find(:all, :include => :tariffs)
         | 
| 98 | 
            -
                assert_equal 3, @products.inject(0) {|sum, product| sum + product.instance_variable_get('@tariffs').length},
         | 
| 99 | 
            -
                  "Incorrect number of tariffs returned"
         | 
| 100 | 
            -
              end
         | 
| 101 | 
            -
             | 
| 102 | 
            -
              def test_has_many_through_when_not_pre_loaded
         | 
| 103 | 
            -
              	student = Student.find(:first)
         | 
| 104 | 
            -
              	rooms = student.rooms
         | 
| 105 | 
            -
              	assert_equal 1, rooms.size
         | 
| 106 | 
            -
              	assert_equal 1, rooms.first.dorm_id
         | 
| 107 | 
            -
              	assert_equal 1, rooms.first.room_id
         | 
| 108 | 
            -
              end
         | 
| 109 | 
            -
             | 
| 110 | 
            -
              def test_has_many_through_when_through_association_is_composite
         | 
| 111 | 
            -
                dorm = Dorm.find(:first)
         | 
| 112 | 
            -
                assert_equal 1, dorm.rooms.length
         | 
| 113 | 
            -
                assert_equal 1, dorm.rooms.first.room_attributes.length
         | 
| 114 | 
            -
                assert_equal 'keg', dorm.rooms.first.room_attributes.first.name
         | 
| 115 | 
            -
              end
         | 
| 116 | 
            -
             | 
| 117 | 
            -
              def test_associations_with_conditions
         | 
| 118 | 
            -
                @suburb = Suburb.find([2, 1])
         | 
| 119 | 
            -
                assert_equal 2, @suburb.streets.size
         | 
| 120 | 
            -
             | 
| 121 | 
            -
                @suburb = Suburb.find([2, 1])
         | 
| 122 | 
            -
                assert_equal 1, @suburb.first_streets.size
         | 
| 123 | 
            -
             | 
| 124 | 
            -
                @suburb = Suburb.find([2, 1], :include => :streets)
         | 
| 125 | 
            -
                assert_equal 2, @suburb.streets.size
         | 
| 126 | 
            -
             | 
| 127 | 
            -
                @suburb = Suburb.find([2, 1], :include => :first_streets)
         | 
| 128 | 
            -
                assert_equal 1, @suburb.first_streets.size
         | 
| 129 | 
            -
              end
         | 
| 130 | 
            -
             | 
| 131 | 
            -
              def test_has_and_belongs_to_many
         | 
| 132 | 
            -
                @restaurant = Restaurant.find([1,1])
         | 
| 133 | 
            -
                assert_equal 2, @restaurant.suburbs.size
         | 
| 134 | 
            -
             | 
| 135 | 
            -
                @restaurant = Restaurant.find([1,1], :include => :suburbs)
         | 
| 136 | 
            -
                assert_equal 2, @restaurant.suburbs.size
         | 
| 137 | 
            -
              end
         | 
| 138 | 
            -
             | 
| 139 | 
            -
              def test_has_many_with_primary_key
         | 
| 140 | 
            -
                @membership = Membership.find([1, 1])
         | 
| 141 | 
            -
             | 
| 142 | 
            -
                assert_equal 2, @membership.readings.size
         | 
| 143 | 
            -
              end
         | 
| 144 | 
            -
             | 
| 145 | 
            -
              def test_has_one_with_primary_key
         | 
| 146 | 
            -
                @membership = Membership.find([1, 1])
         | 
| 147 | 
            -
             | 
| 148 | 
            -
                assert_equal 2, @membership.reading.id
         | 
| 149 | 
            -
              end
         | 
| 150 | 
            -
             | 
| 151 | 
            -
              def test_joins_has_many_with_primary_key
         | 
| 152 | 
            -
                @membership = Membership.find(:first, :joins => :readings, :conditions => { :readings => { :id => 1 } })
         | 
| 153 | 
            -
             | 
| 154 | 
            -
                assert_equal [1, 1], @membership.id
         | 
| 155 | 
            -
              end
         | 
| 156 | 
            -
             | 
| 157 | 
            -
              def test_joins_has_one_with_primary_key
         | 
| 158 | 
            -
                @membership = Membership.find(:first, :joins => :reading, :conditions => { :readings => { :id => 2 } })
         | 
| 159 | 
            -
             | 
| 160 | 
            -
                assert_equal [1, 1], @membership.id
         | 
| 161 | 
            -
              end
         | 
| 162 | 
            -
             | 
| 163 | 
            -
              def test_has_many_with_primary_key_with_associations
         | 
| 164 | 
            -
                # Trigger Active Records find_with_associations method
         | 
| 165 | 
            -
                memberships = Membership.find(:all, :include => :statuses,
         | 
| 166 | 
            -
                                                    :conditions => ["membership_statuses.status = ?",
         | 
| 167 | 
            -
                                                                    'Active'])
         | 
| 168 | 
            -
             | 
| 169 | 
            -
                assert_equal(1, memberships.length)
         | 
| 170 | 
            -
                assert_equal([1,1], memberships[0].id)
         | 
| 171 | 
            -
              end
         | 
| 172 | 
            -
             | 
| 173 | 
            -
              def test_limitable_reflections
         | 
| 174 | 
            -
                memberships = Membership.find(:all, :include => :statuses,
         | 
| 175 | 
            -
                                                    :conditions => ["membership_statuses.status = ?",
         | 
| 176 | 
            -
                                                                    'Active'],
         | 
| 177 | 
            -
                                                    :limit => 1)
         | 
| 178 | 
            -
                assert_equal(1, memberships.length)
         | 
| 179 | 
            -
                assert_equal([1,1], memberships[0].id)
         | 
| 180 | 
            -
              end
         | 
| 1 | 
            +
            require 'abstract_unit'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            class TestAssociations < ActiveSupport::TestCase
         | 
| 4 | 
            +
              fixtures :articles, :products, :tariffs, :product_tariffs, :suburbs, :streets, :restaurants, :restaurants_suburbs,
         | 
| 5 | 
            +
                       :dorms, :rooms, :room_attributes, :room_attribute_assignments, :students, :room_assignments, :users, :readings,
         | 
| 6 | 
            +
                       :memberships
         | 
| 7 | 
            +
              
         | 
| 8 | 
            +
              def test_has_many_through_with_conditions_when_through_association_is_not_composite
         | 
| 9 | 
            +
                user = User.find(:first)
         | 
| 10 | 
            +
                assert_equal 1, user.articles.find(:all, :conditions => ["articles.name = ?", "Article One"]).size
         | 
| 11 | 
            +
              end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
              def test_has_many_through_with_conditions_when_through_association_is_composite
         | 
| 14 | 
            +
                room = Room.find(:first)
         | 
| 15 | 
            +
                assert_equal 0, room.room_attributes.find(:all, :conditions => ["room_attributes.name != ?", "keg"]).size
         | 
| 16 | 
            +
              end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
              def test_has_many_through_on_custom_finder_when_through_association_is_composite_finder_when_through_association_is_not_composite
         | 
| 19 | 
            +
                user = User.find(:first)
         | 
| 20 | 
            +
                assert_equal 1, user.find_custom_articles.size
         | 
| 21 | 
            +
              end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
              def test_has_many_through_on_custom_finder_when_through_association_is_composite
         | 
| 24 | 
            +
                room = Room.find(:first)
         | 
| 25 | 
            +
                assert_equal 0, room.find_custom_room_attributes.size
         | 
| 26 | 
            +
              end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
              def test_count
         | 
| 29 | 
            +
                assert_equal 2, Product.count(:include => :product_tariffs)
         | 
| 30 | 
            +
                assert_equal 3, Tariff.count(:include => :product_tariffs)
         | 
| 31 | 
            +
                assert_equal 2, Tariff.count(:group => :start_date).size
         | 
| 32 | 
            +
              end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
              def test_products
         | 
| 35 | 
            +
                assert_not_nil products(:first_product).product_tariffs
         | 
| 36 | 
            +
                assert_equal 2, products(:first_product).product_tariffs.length
         | 
| 37 | 
            +
                assert_not_nil products(:first_product).tariffs
         | 
| 38 | 
            +
                assert_equal 2, products(:first_product).tariffs.length
         | 
| 39 | 
            +
                assert_not_nil products(:first_product).product_tariff
         | 
| 40 | 
            +
              end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
              def test_product_tariffs
         | 
| 43 | 
            +
                assert_not_nil product_tariffs(:first_flat).product
         | 
| 44 | 
            +
                assert_not_nil product_tariffs(:first_flat).tariff
         | 
| 45 | 
            +
                assert_equal Product, product_tariffs(:first_flat).product.class
         | 
| 46 | 
            +
                assert_equal Tariff, product_tariffs(:first_flat).tariff.class
         | 
| 47 | 
            +
              end
         | 
| 48 | 
            +
             | 
| 49 | 
            +
              def test_tariffs
         | 
| 50 | 
            +
                assert_not_nil tariffs(:flat).product_tariffs
         | 
| 51 | 
            +
                assert_equal 1, tariffs(:flat).product_tariffs.length
         | 
| 52 | 
            +
                assert_not_nil tariffs(:flat).products
         | 
| 53 | 
            +
                assert_equal 1, tariffs(:flat).products.length
         | 
| 54 | 
            +
                assert_not_nil tariffs(:flat).product_tariff
         | 
| 55 | 
            +
              end
         | 
| 56 | 
            +
             | 
| 57 | 
            +
              # Its not generating the instances of associated classes from the rows
         | 
| 58 | 
            +
              def test_find_includes_products
         | 
| 59 | 
            +
                assert @products = Product.find(:all, :include => :product_tariffs)
         | 
| 60 | 
            +
                assert_equal 2, @products.length
         | 
| 61 | 
            +
                assert_not_nil @products.first.instance_variable_get('@product_tariffs'), '@product_tariffs not set; should be array'
         | 
| 62 | 
            +
                assert_equal 3, @products.inject(0) {|sum, tariff| sum + tariff.instance_variable_get('@product_tariffs').length},
         | 
| 63 | 
            +
                  "Incorrect number of product_tariffs returned"
         | 
| 64 | 
            +
              end
         | 
| 65 | 
            +
             | 
| 66 | 
            +
              def test_find_includes_tariffs
         | 
| 67 | 
            +
                assert @tariffs = Tariff.find(:all, :include => :product_tariffs)
         | 
| 68 | 
            +
                assert_equal 3, @tariffs.length
         | 
| 69 | 
            +
                assert_not_nil @tariffs.first.instance_variable_get('@product_tariffs'), '@product_tariffs not set; should be array'
         | 
| 70 | 
            +
                assert_equal 3, @tariffs.inject(0) {|sum, tariff| sum + tariff.instance_variable_get('@product_tariffs').length},
         | 
| 71 | 
            +
                  "Incorrect number of product_tariffs returnedturned"
         | 
| 72 | 
            +
              end
         | 
| 73 | 
            +
             | 
| 74 | 
            +
              def test_find_includes_product
         | 
| 75 | 
            +
                assert @product_tariffs = ProductTariff.find(:all, :include => :product)
         | 
| 76 | 
            +
                assert_equal 3, @product_tariffs.length
         | 
| 77 | 
            +
                assert_not_nil @product_tariffs.first.instance_variable_get('@product'), '@product not set'
         | 
| 78 | 
            +
              end
         | 
| 79 | 
            +
             | 
| 80 | 
            +
              def test_find_includes_comp_belongs_to_tariff
         | 
| 81 | 
            +
                assert @product_tariffs = ProductTariff.find(:all, :include => :tariff)
         | 
| 82 | 
            +
                assert_equal 3, @product_tariffs.length
         | 
| 83 | 
            +
                assert_not_nil @product_tariffs.first.instance_variable_get('@tariff'), '@tariff not set'
         | 
| 84 | 
            +
              end
         | 
| 85 | 
            +
             | 
| 86 | 
            +
              def test_find_includes_extended
         | 
| 87 | 
            +
                assert @products = Product.find(:all, :include => {:product_tariffs => :tariff})
         | 
| 88 | 
            +
                assert_equal 3, @products.inject(0) {|sum, product| sum + product.instance_variable_get('@product_tariffs').length},
         | 
| 89 | 
            +
                  "Incorrect number of product_tariffs returned"
         | 
| 90 | 
            +
             | 
| 91 | 
            +
                assert @tariffs = Tariff.find(:all, :include => {:product_tariffs => :product})
         | 
| 92 | 
            +
                assert_equal 3, @tariffs.inject(0) {|sum, tariff| sum + tariff.instance_variable_get('@product_tariffs').length},
         | 
| 93 | 
            +
                  "Incorrect number of product_tariffs returned"
         | 
| 94 | 
            +
              end
         | 
| 95 | 
            +
             | 
| 96 | 
            +
              def test_has_many_through
         | 
| 97 | 
            +
                @products = Product.find(:all, :include => :tariffs)
         | 
| 98 | 
            +
                assert_equal 3, @products.inject(0) {|sum, product| sum + product.instance_variable_get('@tariffs').length},
         | 
| 99 | 
            +
                  "Incorrect number of tariffs returned"
         | 
| 100 | 
            +
              end
         | 
| 101 | 
            +
             | 
| 102 | 
            +
              def test_has_many_through_when_not_pre_loaded
         | 
| 103 | 
            +
              	student = Student.find(:first)
         | 
| 104 | 
            +
              	rooms = student.rooms
         | 
| 105 | 
            +
              	assert_equal 1, rooms.size
         | 
| 106 | 
            +
              	assert_equal 1, rooms.first.dorm_id
         | 
| 107 | 
            +
              	assert_equal 1, rooms.first.room_id
         | 
| 108 | 
            +
              end
         | 
| 109 | 
            +
             | 
| 110 | 
            +
              def test_has_many_through_when_through_association_is_composite
         | 
| 111 | 
            +
                dorm = Dorm.find(:first)
         | 
| 112 | 
            +
                assert_equal 1, dorm.rooms.length
         | 
| 113 | 
            +
                assert_equal 1, dorm.rooms.first.room_attributes.length
         | 
| 114 | 
            +
                assert_equal 'keg', dorm.rooms.first.room_attributes.first.name
         | 
| 115 | 
            +
              end
         | 
| 116 | 
            +
             | 
| 117 | 
            +
              def test_associations_with_conditions
         | 
| 118 | 
            +
                @suburb = Suburb.find([2, 1])
         | 
| 119 | 
            +
                assert_equal 2, @suburb.streets.size
         | 
| 120 | 
            +
             | 
| 121 | 
            +
                @suburb = Suburb.find([2, 1])
         | 
| 122 | 
            +
                assert_equal 1, @suburb.first_streets.size
         | 
| 123 | 
            +
             | 
| 124 | 
            +
                @suburb = Suburb.find([2, 1], :include => :streets)
         | 
| 125 | 
            +
                assert_equal 2, @suburb.streets.size
         | 
| 126 | 
            +
             | 
| 127 | 
            +
                @suburb = Suburb.find([2, 1], :include => :first_streets)
         | 
| 128 | 
            +
                assert_equal 1, @suburb.first_streets.size
         | 
| 129 | 
            +
              end
         | 
| 130 | 
            +
             | 
| 131 | 
            +
              def test_has_and_belongs_to_many
         | 
| 132 | 
            +
                @restaurant = Restaurant.find([1,1])
         | 
| 133 | 
            +
                assert_equal 2, @restaurant.suburbs.size
         | 
| 134 | 
            +
             | 
| 135 | 
            +
                @restaurant = Restaurant.find([1,1], :include => :suburbs)
         | 
| 136 | 
            +
                assert_equal 2, @restaurant.suburbs.size
         | 
| 137 | 
            +
              end
         | 
| 138 | 
            +
             | 
| 139 | 
            +
              def test_has_many_with_primary_key
         | 
| 140 | 
            +
                @membership = Membership.find([1, 1])
         | 
| 141 | 
            +
             | 
| 142 | 
            +
                assert_equal 2, @membership.readings.size
         | 
| 143 | 
            +
              end
         | 
| 144 | 
            +
             | 
| 145 | 
            +
              def test_has_one_with_primary_key
         | 
| 146 | 
            +
                @membership = Membership.find([1, 1])
         | 
| 147 | 
            +
             | 
| 148 | 
            +
                assert_equal 2, @membership.reading.id
         | 
| 149 | 
            +
              end
         | 
| 150 | 
            +
             | 
| 151 | 
            +
              def test_joins_has_many_with_primary_key
         | 
| 152 | 
            +
                @membership = Membership.find(:first, :joins => :readings, :conditions => { :readings => { :id => 1 } })
         | 
| 153 | 
            +
             | 
| 154 | 
            +
                assert_equal [1, 1], @membership.id
         | 
| 155 | 
            +
              end
         | 
| 156 | 
            +
             | 
| 157 | 
            +
              def test_joins_has_one_with_primary_key
         | 
| 158 | 
            +
                @membership = Membership.find(:first, :joins => :reading, :conditions => { :readings => { :id => 2 } })
         | 
| 159 | 
            +
             | 
| 160 | 
            +
                assert_equal [1, 1], @membership.id
         | 
| 161 | 
            +
              end
         | 
| 162 | 
            +
             | 
| 163 | 
            +
              def test_has_many_with_primary_key_with_associations
         | 
| 164 | 
            +
                # Trigger Active Records find_with_associations method
         | 
| 165 | 
            +
                memberships = Membership.find(:all, :include => :statuses,
         | 
| 166 | 
            +
                                                    :conditions => ["membership_statuses.status = ?",
         | 
| 167 | 
            +
                                                                    'Active'])
         | 
| 168 | 
            +
             | 
| 169 | 
            +
                assert_equal(1, memberships.length)
         | 
| 170 | 
            +
                assert_equal([1,1], memberships[0].id)
         | 
| 171 | 
            +
              end
         | 
| 172 | 
            +
             | 
| 173 | 
            +
              def test_limitable_reflections
         | 
| 174 | 
            +
                memberships = Membership.find(:all, :include => :statuses,
         | 
| 175 | 
            +
                                                    :conditions => ["membership_statuses.status = ?",
         | 
| 176 | 
            +
                                                                    'Active'],
         | 
| 177 | 
            +
                                                    :limit => 1)
         | 
| 178 | 
            +
                assert_equal(1, memberships.length)
         | 
| 179 | 
            +
                assert_equal([1,1], memberships[0].id)
         | 
| 180 | 
            +
              end
         | 
| 181 181 | 
             
            end
         | 
    
        data/test/test_attributes.rb
    CHANGED
    
    | @@ -1,9 +1,4 @@ | |
| 1 1 | 
             
            require 'abstract_unit'
         | 
| 2 | 
            -
            require 'fixtures/reference_type'
         | 
| 3 | 
            -
            require 'fixtures/reference_code'
         | 
| 4 | 
            -
            require 'fixtures/product'
         | 
| 5 | 
            -
            require 'fixtures/tariff'
         | 
| 6 | 
            -
            require 'fixtures/product_tariff'
         | 
| 7 2 |  | 
| 8 3 | 
             
            class TestAttributes < ActiveSupport::TestCase
         | 
| 9 4 | 
             
              fixtures :reference_types, :reference_codes, :products, :tariffs, :product_tariffs
         | 
    
        data/test/test_clone.rb
    CHANGED
    
    | @@ -1,34 +1,32 @@ | |
| 1 | 
            -
            require 'abstract_unit'
         | 
| 2 | 
            -
             | 
| 3 | 
            -
             | 
| 4 | 
            -
             | 
| 5 | 
            -
             | 
| 6 | 
            -
               | 
| 7 | 
            -
             | 
| 8 | 
            -
             | 
| 9 | 
            -
             | 
| 10 | 
            -
             | 
| 11 | 
            -
             | 
| 12 | 
            -
             | 
| 13 | 
            -
             | 
| 14 | 
            -
             | 
| 15 | 
            -
             | 
| 16 | 
            -
             | 
| 17 | 
            -
               | 
| 18 | 
            -
             | 
| 19 | 
            -
               | 
| 20 | 
            -
             | 
| 21 | 
            -
               | 
| 22 | 
            -
             | 
| 23 | 
            -
             | 
| 24 | 
            -
             | 
| 25 | 
            -
                   | 
| 26 | 
            -
             | 
| 27 | 
            -
                   | 
| 28 | 
            -
                    @klass.primary_key | 
| 29 | 
            -
                   | 
| 30 | 
            -
             | 
| 31 | 
            -
             | 
| 32 | 
            -
                end
         | 
| 33 | 
            -
              end
         | 
| 1 | 
            +
            require 'abstract_unit'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            class TestClone < ActiveSupport::TestCase
         | 
| 4 | 
            +
              fixtures :reference_types, :reference_codes
         | 
| 5 | 
            +
              
         | 
| 6 | 
            +
              CLASSES = {
         | 
| 7 | 
            +
                :single => {
         | 
| 8 | 
            +
                  :class => ReferenceType,
         | 
| 9 | 
            +
                  :primary_keys => :reference_type_id,
         | 
| 10 | 
            +
                },
         | 
| 11 | 
            +
                :dual   => { 
         | 
| 12 | 
            +
                  :class => ReferenceCode,
         | 
| 13 | 
            +
                  :primary_keys => [:reference_type_id, :reference_code],
         | 
| 14 | 
            +
                },
         | 
| 15 | 
            +
              }
         | 
| 16 | 
            +
              
         | 
| 17 | 
            +
              def setup
         | 
| 18 | 
            +
                self.class.classes = CLASSES
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
              
         | 
| 21 | 
            +
              def test_truth
         | 
| 22 | 
            +
                testing_with do
         | 
| 23 | 
            +
                  clone = @first.clone
         | 
| 24 | 
            +
                  assert_equal @first.attributes.block(@klass.primary_key), clone.attributes
         | 
| 25 | 
            +
                  if composite?
         | 
| 26 | 
            +
                    @klass.primary_key.each {|key| assert_nil clone[key], "Primary key '#{key}' should be nil"} 
         | 
| 27 | 
            +
                  else
         | 
| 28 | 
            +
                    assert_nil clone[@klass.primary_key], "Sole primary key should be nil"
         | 
| 29 | 
            +
                  end
         | 
| 30 | 
            +
                end
         | 
| 31 | 
            +
              end
         | 
| 34 32 | 
             
            end
         |