composite_primary_keys 8.1.1 → 8.1.2
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.
- checksums.yaml +4 -4
- data/History.rdoc +4 -1
- data/lib/composite_primary_keys.rb +5 -1
- data/lib/composite_primary_keys/arel/visitors/to_sql.rb +24 -0
- data/lib/composite_primary_keys/associations/association_scope.rb +32 -58
- data/lib/composite_primary_keys/associations/join_dependency/join_association.rb +22 -22
- data/lib/composite_primary_keys/associations/preloader/association.rb +12 -6
- data/lib/composite_primary_keys/associations/preloader/belongs_to.rb +19 -19
- data/lib/composite_primary_keys/attribute_methods/primary_key.rb +1 -2
- data/lib/composite_primary_keys/attribute_methods/read.rb +2 -2
- data/lib/composite_primary_keys/attribute_methods/write.rb +1 -1
- data/lib/composite_primary_keys/composite_predicates.rb +55 -50
- data/lib/composite_primary_keys/composite_relation.rb +48 -48
- data/lib/composite_primary_keys/connection_adapters/abstract/connection_specification_changes.rb +2 -2
- data/lib/composite_primary_keys/connection_adapters/postgresql_adapter.rb +19 -46
- data/lib/composite_primary_keys/connection_adapters/sqlserver_adapter.rb +8 -4
- data/lib/composite_primary_keys/fixtures.rb +26 -22
- data/lib/composite_primary_keys/locking/optimistic.rb +54 -55
- data/lib/composite_primary_keys/relation.rb +15 -8
- data/lib/composite_primary_keys/relation/batches.rb +23 -19
- data/lib/composite_primary_keys/relation/calculations.rb +4 -2
- data/lib/composite_primary_keys/relation/finder_methods.rb +33 -27
- data/lib/composite_primary_keys/relation/predicate_builder.rb +18 -3
- data/lib/composite_primary_keys/relation/query_methods.rb +41 -41
- data/lib/composite_primary_keys/sanitization.rb +7 -5
- data/lib/composite_primary_keys/validations/uniqueness.rb +20 -16
- data/lib/composite_primary_keys/version.rb +1 -1
- data/tasks/databases/oracle.rake +27 -25
- data/tasks/databases/oracle_enhanced.rake +27 -0
- data/test/connections/databases.ci.yml +15 -15
- data/test/connections/native_oracle/connection.rb +11 -11
- data/test/connections/native_oracle_enhanced/connection.rb +16 -16
- data/test/fixtures/comment.rb +7 -7
- data/test/fixtures/db_definitions/db2-create-tables.sql +126 -126
- data/test/fixtures/db_definitions/db2-drop-tables.sql +18 -18
- data/test/fixtures/db_definitions/oracle.drop.sql +48 -45
- data/test/fixtures/db_definitions/oracle.sql +236 -223
- data/test/fixtures/dorm.rb +2 -2
- data/test/fixtures/membership.rb +6 -6
- data/test/fixtures/membership_statuses.yml +16 -16
- data/test/fixtures/memberships.yml +10 -10
- data/test/fixtures/product_tariffs.yml +14 -14
- data/test/fixtures/reference_code.rb +7 -7
- data/test/fixtures/restaurants_suburb.rb +2 -2
- data/test/fixtures/suburb.rb +5 -5
- data/test/fixtures/topic.rb +5 -5
- data/test/fixtures/topic_source.rb +6 -6
- data/test/fixtures/topic_sources.yml +3 -3
- data/test/fixtures/topics.yml +8 -8
- data/test/fixtures/users.yml +10 -10
- data/test/test_attribute_methods.rb +63 -63
- data/test/test_calculations.rb +42 -37
- data/test/test_callbacks.rb +99 -99
- data/test/test_delete.rb +28 -21
- data/test/test_delete_all.rb +5 -4
- data/test/test_dumpable.rb +15 -15
- data/test/test_nested_attributes.rb +124 -124
- data/test/test_optimistic.rb +18 -18
- data/test/test_polymorphic.rb +1 -1
- data/test/test_predicates.rb +40 -40
- data/test/test_santiago.rb +23 -23
- data/test/test_suite.rb +34 -34
- data/test/test_touch.rb +23 -23
- data/test/test_update.rb +71 -71
- metadata +9 -8
- data/lib/composite_primary_keys/model_schema.rb +0 -15
    
        data/test/fixtures/dorm.rb
    CHANGED
    
    | @@ -1,3 +1,3 @@ | |
| 1 | 
            -
            class Dorm < ActiveRecord::Base
         | 
| 2 | 
            -
              has_many :rooms, -> {includes(:room_attributes)}, :primary_key => [:id]
         | 
| 1 | 
            +
            class Dorm < ActiveRecord::Base
         | 
| 2 | 
            +
              has_many :rooms, -> {includes(:room_attributes)}, :primary_key => [:id]
         | 
| 3 3 | 
             
            end
         | 
    
        data/test/fixtures/membership.rb
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 | 
            -
            class Membership < ActiveRecord::Base
         | 
| 2 | 
            -
              self.primary_keys = :user_id, :group_id
         | 
| 3 | 
            -
              belongs_to :user
         | 
| 4 | 
            -
            	belongs_to :group
         | 
| 5 | 
            -
            	has_many :statuses, :class_name => 'MembershipStatus', :foreign_key => [:user_id, :group_id]
         | 
| 6 | 
            -
              has_many :readings, :primary_key => :user_id, :foreign_key => :user_id
         | 
| 1 | 
            +
            class Membership < ActiveRecord::Base
         | 
| 2 | 
            +
              self.primary_keys = :user_id, :group_id
         | 
| 3 | 
            +
              belongs_to :user
         | 
| 4 | 
            +
            	belongs_to :group
         | 
| 5 | 
            +
            	has_many :statuses, :class_name => 'MembershipStatus', :foreign_key => [:user_id, :group_id]
         | 
| 6 | 
            +
              has_many :readings, :primary_key => :user_id, :foreign_key => :user_id
         | 
| 7 7 | 
             
            end
         | 
| @@ -1,17 +1,17 @@ | |
| 1 | 
            -
            santiago-cpk:
         | 
| 2 | 
            -
              id: 1
         | 
| 3 | 
            -
              user_id: 1
         | 
| 4 | 
            -
              group_id: 1
         | 
| 5 | 
            -
              status: Active
         | 
| 6 | 
            -
             | 
| 7 | 
            -
            drnic-cpk:
         | 
| 8 | 
            -
              id: 2
         | 
| 9 | 
            -
              user_id: 2
         | 
| 10 | 
            -
              group_id: 1
         | 
| 11 | 
            -
              status: Owner
         | 
| 12 | 
            -
             | 
| 13 | 
            -
            cfis-cpk:
         | 
| 14 | 
            -
              id: 3
         | 
| 15 | 
            -
              user_id: 3
         | 
| 16 | 
            -
              group_id: 2
         | 
| 1 | 
            +
            santiago-cpk:
         | 
| 2 | 
            +
              id: 1
         | 
| 3 | 
            +
              user_id: 1
         | 
| 4 | 
            +
              group_id: 1
         | 
| 5 | 
            +
              status: Active
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            drnic-cpk:
         | 
| 8 | 
            +
              id: 2
         | 
| 9 | 
            +
              user_id: 2
         | 
| 10 | 
            +
              group_id: 1
         | 
| 11 | 
            +
              status: Owner
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            cfis-cpk:
         | 
| 14 | 
            +
              id: 3
         | 
| 15 | 
            +
              user_id: 3
         | 
| 16 | 
            +
              group_id: 2
         | 
| 17 17 | 
             
              status: Active
         | 
| @@ -1,11 +1,11 @@ | |
| 1 | 
            -
            santiago-cpk:
         | 
| 2 | 
            -
              user_id: 1
         | 
| 3 | 
            -
              group_id: 1
         | 
| 4 | 
            -
             | 
| 5 | 
            -
            drnic-cpk:
         | 
| 6 | 
            -
              user_id: 2
         | 
| 7 | 
            -
              group_id: 1
         | 
| 8 | 
            -
             | 
| 9 | 
            -
            cfis-cpk:
         | 
| 10 | 
            -
              user_id: 3
         | 
| 1 | 
            +
            santiago-cpk:
         | 
| 2 | 
            +
              user_id: 1
         | 
| 3 | 
            +
              group_id: 1
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            drnic-cpk:
         | 
| 6 | 
            +
              user_id: 2
         | 
| 7 | 
            +
              group_id: 1
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            cfis-cpk:
         | 
| 10 | 
            +
              user_id: 3
         | 
| 11 11 | 
             
              group_id: 2
         | 
| @@ -1,14 +1,14 @@ | |
| 1 | 
            -
            first_flat:
         | 
| 2 | 
            -
              product_id: 1
         | 
| 3 | 
            -
              tariff_id: 1
         | 
| 4 | 
            -
              tariff_start_date: <%= Date.today.to_s(:db) %>
         | 
| 5 | 
            -
             | 
| 6 | 
            -
            first_free:
         | 
| 7 | 
            -
              product_id: 1
         | 
| 8 | 
            -
              tariff_id: 2
         | 
| 9 | 
            -
              tariff_start_date: <%= Date.today.to_s(:db) %>
         | 
| 10 | 
            -
             | 
| 11 | 
            -
            second_free:
         | 
| 12 | 
            -
              product_id: 2
         | 
| 13 | 
            -
              tariff_id: 2
         | 
| 14 | 
            -
              tariff_start_date: <%= Date.today.to_s(:db) %>
         | 
| 1 | 
            +
            first_flat:
         | 
| 2 | 
            +
              product_id: 1
         | 
| 3 | 
            +
              tariff_id: 1
         | 
| 4 | 
            +
              tariff_start_date: <%= Date.today.to_s(:db) %>
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            first_free:
         | 
| 7 | 
            +
              product_id: 1
         | 
| 8 | 
            +
              tariff_id: 2
         | 
| 9 | 
            +
              tariff_start_date: <%= Date.today.to_s(:db) %>
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            second_free:
         | 
| 12 | 
            +
              product_id: 2
         | 
| 13 | 
            +
              tariff_id: 2
         | 
| 14 | 
            +
              tariff_start_date: <%= Date.today.to_s(:db) %>
         | 
| @@ -1,7 +1,7 @@ | |
| 1 | 
            -
            class ReferenceCode < ActiveRecord::Base
         | 
| 2 | 
            -
              self.primary_keys = :reference_type_id, :reference_code
         | 
| 3 | 
            -
             | 
| 4 | 
            -
              belongs_to :reference_type, :foreign_key => "reference_type_id"
         | 
| 5 | 
            -
             | 
| 6 | 
            -
              validates_presence_of :reference_code, :code_label, :abbreviation
         | 
| 7 | 
            -
            end
         | 
| 1 | 
            +
            class ReferenceCode < ActiveRecord::Base
         | 
| 2 | 
            +
              self.primary_keys = :reference_type_id, :reference_code
         | 
| 3 | 
            +
             | 
| 4 | 
            +
              belongs_to :reference_type, :foreign_key => "reference_type_id"
         | 
| 5 | 
            +
             | 
| 6 | 
            +
              validates_presence_of :reference_code, :code_label, :abbreviation
         | 
| 7 | 
            +
            end
         | 
| @@ -1,3 +1,3 @@ | |
| 1 | 
            -
            class RestaurantsSuburb < ActiveRecord::Base
         | 
| 2 | 
            -
             | 
| 1 | 
            +
            class RestaurantsSuburb < ActiveRecord::Base
         | 
| 2 | 
            +
             | 
| 3 3 | 
             
            end
         | 
    
        data/test/fixtures/suburb.rb
    CHANGED
    
    | @@ -1,6 +1,6 @@ | |
| 1 | 
            -
            class Suburb < ActiveRecord::Base
         | 
| 2 | 
            -
              self.primary_keys = :city_id, :suburb_id
         | 
| 3 | 
            -
              has_many :streets,  :foreign_key => [:city_id, :suburb_id]
         | 
| 4 | 
            -
              has_many :first_streets, -> {where("streets.name = 'First Street'")},
         | 
| 5 | 
            -
                       :foreign_key => [:city_id, :suburb_id], :class_name => 'Street'
         | 
| 1 | 
            +
            class Suburb < ActiveRecord::Base
         | 
| 2 | 
            +
              self.primary_keys = :city_id, :suburb_id
         | 
| 3 | 
            +
              has_many :streets,  :foreign_key => [:city_id, :suburb_id]
         | 
| 4 | 
            +
              has_many :first_streets, -> {where("streets.name = 'First Street'")},
         | 
| 5 | 
            +
                       :foreign_key => [:city_id, :suburb_id], :class_name => 'Street'
         | 
| 6 6 | 
             
            end
         | 
    
        data/test/fixtures/topic.rb
    CHANGED
    
    | @@ -1,6 +1,6 @@ | |
| 1 | 
            -
            class Topic < ActiveRecord::Base
         | 
| 2 | 
            -
            	has_many :topic_sources, dependent: :destroy
         | 
| 3 | 
            -
            	accepts_nested_attributes_for :topic_sources
         | 
| 4 | 
            -
             | 
| 5 | 
            -
            	validates :name, :feed_size, presence: true
         | 
| 1 | 
            +
            class Topic < ActiveRecord::Base
         | 
| 2 | 
            +
            	has_many :topic_sources, dependent: :destroy
         | 
| 3 | 
            +
            	accepts_nested_attributes_for :topic_sources
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            	validates :name, :feed_size, presence: true
         | 
| 6 6 | 
             
            end
         | 
| @@ -1,7 +1,7 @@ | |
| 1 | 
            -
            class TopicSource < ActiveRecord::Base
         | 
| 2 | 
            -
            	self.primary_keys = :topic_id, :platform
         | 
| 3 | 
            -
             | 
| 4 | 
            -
            	belongs_to :topic, inverse_of: :topic_sources
         | 
| 5 | 
            -
             | 
| 6 | 
            -
            	validates :platform, presence: true
         | 
| 1 | 
            +
            class TopicSource < ActiveRecord::Base
         | 
| 2 | 
            +
            	self.primary_keys = :topic_id, :platform
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            	belongs_to :topic, inverse_of: :topic_sources
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            	validates :platform, presence: true
         | 
| 7 7 | 
             
            end
         | 
| @@ -1,4 +1,4 @@ | |
| 1 | 
            -
            music_source:
         | 
| 2 | 
            -
              topic_id: 1
         | 
| 3 | 
            -
              platform: 'twitter'
         | 
| 1 | 
            +
            music_source:
         | 
| 2 | 
            +
              topic_id: 1
         | 
| 3 | 
            +
              platform: 'twitter'
         | 
| 4 4 | 
             
              keywords: 'classical'
         | 
    
        data/test/fixtures/topics.yml
    CHANGED
    
    | @@ -1,9 +1,9 @@ | |
| 1 | 
            -
            music:
         | 
| 2 | 
            -
              id: 1
         | 
| 3 | 
            -
              name: Guitar
         | 
| 4 | 
            -
              feed_size: 500
         | 
| 5 | 
            -
             | 
| 6 | 
            -
            iphone:
         | 
| 7 | 
            -
              id: 2
         | 
| 8 | 
            -
              name: iPhone
         | 
| 1 | 
            +
            music:
         | 
| 2 | 
            +
              id: 1
         | 
| 3 | 
            +
              name: Guitar
         | 
| 4 | 
            +
              feed_size: 500
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            iphone:
         | 
| 7 | 
            +
              id: 2
         | 
| 8 | 
            +
              name: iPhone
         | 
| 9 9 | 
             
              feed_size: 500
         | 
    
        data/test/fixtures/users.yml
    CHANGED
    
    | @@ -1,11 +1,11 @@ | |
| 1 | 
            -
            santiago:
         | 
| 2 | 
            -
              id: 1
         | 
| 3 | 
            -
              name: Santiago
         | 
| 4 | 
            -
              
         | 
| 5 | 
            -
            drnic:
         | 
| 6 | 
            -
              id: 2
         | 
| 7 | 
            -
              name: Dr Nic
         | 
| 8 | 
            -
             | 
| 9 | 
            -
            cfis:
         | 
| 10 | 
            -
              id: 3
         | 
| 1 | 
            +
            santiago:
         | 
| 2 | 
            +
              id: 1
         | 
| 3 | 
            +
              name: Santiago
         | 
| 4 | 
            +
              
         | 
| 5 | 
            +
            drnic:
         | 
| 6 | 
            +
              id: 2
         | 
| 7 | 
            +
              name: Dr Nic
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            cfis:
         | 
| 10 | 
            +
              id: 3
         | 
| 11 11 | 
             
              name: cfis
         | 
| @@ -1,63 +1,63 @@ | |
| 1 | 
            -
            require File.expand_path('../abstract_unit', __FILE__)
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            class TestAttributeMethods < ActiveSupport::TestCase
         | 
| 4 | 
            -
              fixtures :reference_types, :reference_codes
         | 
| 5 | 
            -
             | 
| 6 | 
            -
              def test_read_attribute_with_single_key
         | 
| 7 | 
            -
                rt = ReferenceType.find(1)
         | 
| 8 | 
            -
                assert_equal(1, rt.reference_type_id)
         | 
| 9 | 
            -
                assert_equal('NAME_PREFIX', rt.type_label)
         | 
| 10 | 
            -
                assert_equal('Name Prefix', rt.abbreviation)
         | 
| 11 | 
            -
              end
         | 
| 12 | 
            -
             | 
| 13 | 
            -
              def test_read_attribute_with_composite_keys
         | 
| 14 | 
            -
                ref_code = ReferenceCode.find([1, 1])
         | 
| 15 | 
            -
                assert_equal(1, ref_code.id.first)
         | 
| 16 | 
            -
                assert_equal(1, ref_code.id.last)
         | 
| 17 | 
            -
                assert_equal('Mr', ref_code.abbreviation)
         | 
| 18 | 
            -
              end
         | 
| 19 | 
            -
             | 
| 20 | 
            -
              # to_key returns array even for single key
         | 
| 21 | 
            -
              def test_to_key_with_single_key
         | 
| 22 | 
            -
                rt = ReferenceType.find(1)
         | 
| 23 | 
            -
                assert_equal([1], rt.to_key)
         | 
| 24 | 
            -
              end
         | 
| 25 | 
            -
             | 
| 26 | 
            -
              def test_to_key_with_composite_keys
         | 
| 27 | 
            -
                ref_code = ReferenceCode.find([1, 1])
         | 
| 28 | 
            -
                assert_equal(1, ref_code.to_key.first)
         | 
| 29 | 
            -
                assert_equal(1, ref_code.to_key.last)
         | 
| 30 | 
            -
              end
         | 
| 31 | 
            -
             | 
| 32 | 
            -
              def test_to_key_with_single_key_unsaved
         | 
| 33 | 
            -
                rt = ReferenceType.new
         | 
| 34 | 
            -
                assert_nil(rt.to_key)
         | 
| 35 | 
            -
              end
         | 
| 36 | 
            -
             | 
| 37 | 
            -
              def test_to_key_with_composite_keys_unsaved
         | 
| 38 | 
            -
                ref_code = ReferenceCode.new
         | 
| 39 | 
            -
                assert_nil(ref_code.to_key)
         | 
| 40 | 
            -
              end
         | 
| 41 | 
            -
             | 
| 42 | 
            -
              def test_to_key_with_single_key_destroyed
         | 
| 43 | 
            -
                rt = ReferenceType.find(1)
         | 
| 44 | 
            -
                rt.destroy
         | 
| 45 | 
            -
                assert_equal([1], rt.to_key)
         | 
| 46 | 
            -
              end
         | 
| 47 | 
            -
             | 
| 48 | 
            -
              def test_to_key_with_composite_key_destroyed
         | 
| 49 | 
            -
                ref_code = ReferenceCode.find([1, 1])
         | 
| 50 | 
            -
                ref_code.destroy
         | 
| 51 | 
            -
                assert_equal([1,1], ref_code.to_key)
         | 
| 52 | 
            -
              end
         | 
| 53 | 
            -
             | 
| 54 | 
            -
              def test_id_was
         | 
| 55 | 
            -
                rt = ReferenceType.find(1)
         | 
| 56 | 
            -
                rt.id = 2
         | 
| 57 | 
            -
                assert_equal 1, rt.id_was
         | 
| 58 | 
            -
                
         | 
| 59 | 
            -
                ref_code = ReferenceCode.find([1, 1])
         | 
| 60 | 
            -
                ref_code.id = [1,2]
         | 
| 61 | 
            -
                assert_equal [1,1], ref_code.id_was
         | 
| 62 | 
            -
              end
         | 
| 63 | 
            -
            end
         | 
| 1 | 
            +
            require File.expand_path('../abstract_unit', __FILE__)
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            class TestAttributeMethods < ActiveSupport::TestCase
         | 
| 4 | 
            +
              fixtures :reference_types, :reference_codes
         | 
| 5 | 
            +
             | 
| 6 | 
            +
              def test_read_attribute_with_single_key
         | 
| 7 | 
            +
                rt = ReferenceType.find(1)
         | 
| 8 | 
            +
                assert_equal(1, rt.reference_type_id)
         | 
| 9 | 
            +
                assert_equal('NAME_PREFIX', rt.type_label)
         | 
| 10 | 
            +
                assert_equal('Name Prefix', rt.abbreviation)
         | 
| 11 | 
            +
              end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
              def test_read_attribute_with_composite_keys
         | 
| 14 | 
            +
                ref_code = ReferenceCode.find([1, 1])
         | 
| 15 | 
            +
                assert_equal(1, ref_code.id.first)
         | 
| 16 | 
            +
                assert_equal(1, ref_code.id.last)
         | 
| 17 | 
            +
                assert_equal('Mr', ref_code.abbreviation)
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
              # to_key returns array even for single key
         | 
| 21 | 
            +
              def test_to_key_with_single_key
         | 
| 22 | 
            +
                rt = ReferenceType.find(1)
         | 
| 23 | 
            +
                assert_equal([1], rt.to_key)
         | 
| 24 | 
            +
              end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
              def test_to_key_with_composite_keys
         | 
| 27 | 
            +
                ref_code = ReferenceCode.find([1, 1])
         | 
| 28 | 
            +
                assert_equal(1, ref_code.to_key.first)
         | 
| 29 | 
            +
                assert_equal(1, ref_code.to_key.last)
         | 
| 30 | 
            +
              end
         | 
| 31 | 
            +
             | 
| 32 | 
            +
              def test_to_key_with_single_key_unsaved
         | 
| 33 | 
            +
                rt = ReferenceType.new
         | 
| 34 | 
            +
                assert_nil(rt.to_key)
         | 
| 35 | 
            +
              end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
              def test_to_key_with_composite_keys_unsaved
         | 
| 38 | 
            +
                ref_code = ReferenceCode.new
         | 
| 39 | 
            +
                assert_nil(ref_code.to_key)
         | 
| 40 | 
            +
              end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
              def test_to_key_with_single_key_destroyed
         | 
| 43 | 
            +
                rt = ReferenceType.find(1)
         | 
| 44 | 
            +
                rt.destroy
         | 
| 45 | 
            +
                assert_equal([1], rt.to_key)
         | 
| 46 | 
            +
              end
         | 
| 47 | 
            +
             | 
| 48 | 
            +
              def test_to_key_with_composite_key_destroyed
         | 
| 49 | 
            +
                ref_code = ReferenceCode.find([1, 1])
         | 
| 50 | 
            +
                ref_code.destroy
         | 
| 51 | 
            +
                assert_equal([1,1], ref_code.to_key)
         | 
| 52 | 
            +
              end
         | 
| 53 | 
            +
             | 
| 54 | 
            +
              def test_id_was
         | 
| 55 | 
            +
                rt = ReferenceType.find(1)
         | 
| 56 | 
            +
                rt.id = 2
         | 
| 57 | 
            +
                assert_equal 1, rt.id_was
         | 
| 58 | 
            +
                
         | 
| 59 | 
            +
                ref_code = ReferenceCode.find([1, 1])
         | 
| 60 | 
            +
                ref_code.id = [1,2]
         | 
| 61 | 
            +
                assert_equal [1,1], ref_code.id_was
         | 
| 62 | 
            +
              end
         | 
| 63 | 
            +
            end
         | 
    
        data/test/test_calculations.rb
    CHANGED
    
    | @@ -1,37 +1,42 @@ | |
| 1 | 
            -
            require File.expand_path('../abstract_unit', __FILE__)
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            class TestCalculations < ActiveSupport::TestCase
         | 
| 4 | 
            -
              fixtures :articles, :products, :tariffs, :product_tariffs, :suburbs, :streets, :restaurants,
         | 
| 5 | 
            -
                       :dorms, :rooms, :room_attributes, :room_attribute_assignments, :students, :room_assignments, :users, :readings,
         | 
| 6 | 
            -
                       :departments, :employees, :memberships, :membership_statuses
         | 
| 7 | 
            -
             | 
| 8 | 
            -
              def test_count
         | 
| 9 | 
            -
                assert_equal(3, Product.includes(:product_tariffs).count)
         | 
| 10 | 
            -
                assert_equal(3, Tariff.includes(:product_tariffs).count)
         | 
| 11 | 
            -
             | 
| 12 | 
            -
                expected = {Date.today => 2,
         | 
| 13 | 
            -
                            Date.today.next => 1}
         | 
| 14 | 
            -
             | 
| 15 | 
            -
                assert_equal(expected, Tariff.group(:start_date).count)
         | 
| 16 | 
            -
              end
         | 
| 17 | 
            -
             | 
| 18 | 
            -
              def test_count_distinct
         | 
| 19 | 
            -
                product = products(:first_product)
         | 
| 20 | 
            -
                assert_equal(1, product.product_tariffs.select('tariff_start_date').distinct.count)
         | 
| 21 | 
            -
              end
         | 
| 22 | 
            -
              
         | 
| 23 | 
            -
              def test_count_not_distinct
         | 
| 24 | 
            -
                product = products(:first_product)
         | 
| 25 | 
            -
                assert_equal(2, product.product_tariffs.select('tariff_start_date').count)
         | 
| 26 | 
            -
              end
         | 
| 27 | 
            -
             | 
| 28 | 
            -
              def test_count_includes
         | 
| 29 | 
            -
                count = Dorm.where("rooms.room_id = ?", 2).includes(:rooms).references(:rooms).count
         | 
| 30 | 
            -
                assert_equal(1, count)
         | 
| 31 | 
            -
              end
         | 
| 32 | 
            -
             | 
| 33 | 
            -
              def test_count_includes_dup_columns
         | 
| 34 | 
            -
                count = Tariff.includes(:product_tariffs).references(:product_tariffs).where("product_tariffs.tariff_id = ?", 2).count
         | 
| 35 | 
            -
                assert_equal(1, count)
         | 
| 36 | 
            -
              end
         | 
| 37 | 
            -
             | 
| 1 | 
            +
            require File.expand_path('../abstract_unit', __FILE__)
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            class TestCalculations < ActiveSupport::TestCase
         | 
| 4 | 
            +
              fixtures :articles, :products, :tariffs, :product_tariffs, :suburbs, :streets, :restaurants,
         | 
| 5 | 
            +
                       :dorms, :rooms, :room_attributes, :room_attribute_assignments, :students, :room_assignments, :users, :readings,
         | 
| 6 | 
            +
                       :departments, :employees, :memberships, :membership_statuses
         | 
| 7 | 
            +
             | 
| 8 | 
            +
              def test_count
         | 
| 9 | 
            +
                assert_equal(3, Product.includes(:product_tariffs).count)
         | 
| 10 | 
            +
                assert_equal(3, Tariff.includes(:product_tariffs).count)
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                expected = {Date.today => 2,
         | 
| 13 | 
            +
                            Date.today.next => 1}
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                assert_equal(expected, Tariff.group(:start_date).count)
         | 
| 16 | 
            +
              end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
              def test_count_distinct
         | 
| 19 | 
            +
                product = products(:first_product)
         | 
| 20 | 
            +
                assert_equal(1, product.product_tariffs.select('tariff_start_date').distinct.count)
         | 
| 21 | 
            +
              end
         | 
| 22 | 
            +
              
         | 
| 23 | 
            +
              def test_count_not_distinct
         | 
| 24 | 
            +
                product = products(:first_product)
         | 
| 25 | 
            +
                assert_equal(2, product.product_tariffs.select('tariff_start_date').count)
         | 
| 26 | 
            +
              end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
              def test_count_includes
         | 
| 29 | 
            +
                count = Dorm.where("rooms.room_id = ?", 2).includes(:rooms).references(:rooms).count
         | 
| 30 | 
            +
                assert_equal(1, count)
         | 
| 31 | 
            +
              end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
              def test_count_includes_dup_columns
         | 
| 34 | 
            +
                count = Tariff.includes(:product_tariffs).references(:product_tariffs).where("product_tariffs.tariff_id = ?", 2).count
         | 
| 35 | 
            +
                assert_equal(1, count)
         | 
| 36 | 
            +
              end
         | 
| 37 | 
            +
             | 
| 38 | 
            +
              def test_average
         | 
| 39 | 
            +
                average = Tariff.average(:amount)
         | 
| 40 | 
            +
                assert_equal(50, average)
         | 
| 41 | 
            +
              end
         | 
| 42 | 
            +
            end
         | 
    
        data/test/test_callbacks.rb
    CHANGED
    
    | @@ -1,99 +1,99 @@ | |
| 1 | 
            -
            require File.expand_path('../abstract_unit', __FILE__)
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            class TestCallbacks < ActiveSupport::TestCase
         | 
| 4 | 
            -
              fixtures :suburbs
         | 
| 5 | 
            -
             | 
| 6 | 
            -
              def setup
         | 
| 7 | 
            -
                @@callbacks = OpenStruct.new
         | 
| 8 | 
            -
             | 
| 9 | 
            -
                Suburb.class_eval do
         | 
| 10 | 
            -
                  before_create do
         | 
| 11 | 
            -
                    @@callbacks.before_create = true
         | 
| 12 | 
            -
                  end
         | 
| 13 | 
            -
             | 
| 14 | 
            -
                  after_create do
         | 
| 15 | 
            -
                    @@callbacks.after_create = true
         | 
| 16 | 
            -
                  end
         | 
| 17 | 
            -
             | 
| 18 | 
            -
                  around_create do |suburb, block|
         | 
| 19 | 
            -
                    @@callbacks.around_create = true
         | 
| 20 | 
            -
                    block.call
         | 
| 21 | 
            -
                  end
         | 
| 22 | 
            -
             | 
| 23 | 
            -
                  before_save do
         | 
| 24 | 
            -
                    @@callbacks.before_save = true
         | 
| 25 | 
            -
                  end
         | 
| 26 | 
            -
             | 
| 27 | 
            -
                  after_save do
         | 
| 28 | 
            -
                    @@callbacks.after_save = true
         | 
| 29 | 
            -
                  end
         | 
| 30 | 
            -
             | 
| 31 | 
            -
                  around_save do |suburb, block|
         | 
| 32 | 
            -
                    @@callbacks.around_save = true
         | 
| 33 | 
            -
                    block.call
         | 
| 34 | 
            -
                  end
         | 
| 35 | 
            -
             | 
| 36 | 
            -
                  before_update do
         | 
| 37 | 
            -
                    @@callbacks.before_update = true
         | 
| 38 | 
            -
                  end
         | 
| 39 | 
            -
             | 
| 40 | 
            -
                  after_update do
         | 
| 41 | 
            -
                    @@callbacks.after_update = true
         | 
| 42 | 
            -
                  end
         | 
| 43 | 
            -
             | 
| 44 | 
            -
                  around_update do |suburb, block|
         | 
| 45 | 
            -
                    @@callbacks.around_update = true
         | 
| 46 | 
            -
                    block.call
         | 
| 47 | 
            -
                  end
         | 
| 48 | 
            -
                end
         | 
| 49 | 
            -
              end
         | 
| 50 | 
            -
             | 
| 51 | 
            -
              def teardown
         | 
| 52 | 
            -
                Suburb.reset_callbacks(:create)
         | 
| 53 | 
            -
                Suburb.reset_callbacks(:save)
         | 
| 54 | 
            -
                Suburb.reset_callbacks(:update)
         | 
| 55 | 
            -
              end
         | 
| 56 | 
            -
             | 
| 57 | 
            -
              def test_create
         | 
| 58 | 
            -
                refute(@@callbacks.before_save)
         | 
| 59 | 
            -
                refute(@@callbacks.after_save)
         | 
| 60 | 
            -
                refute(@@callbacks.around_save)
         | 
| 61 | 
            -
             | 
| 62 | 
            -
                refute(@@callbacks.before_create)
         | 
| 63 | 
            -
                refute(@@callbacks.after_create)
         | 
| 64 | 
            -
                refute(@@callbacks.around_create)
         | 
| 65 | 
            -
             | 
| 66 | 
            -
                suburb = Suburb.new(:city_id => 3, :suburb_id => 3, :name => 'created')
         | 
| 67 | 
            -
                suburb.save!
         | 
| 68 | 
            -
             | 
| 69 | 
            -
                assert(@@callbacks.before_save)
         | 
| 70 | 
            -
                assert(@@callbacks.after_save)
         | 
| 71 | 
            -
                assert(@@callbacks.around_save)
         | 
| 72 | 
            -
             | 
| 73 | 
            -
                assert(@@callbacks.before_create)
         | 
| 74 | 
            -
                assert(@@callbacks.after_create)
         | 
| 75 | 
            -
                assert(@@callbacks.around_create)
         | 
| 76 | 
            -
              end
         | 
| 77 | 
            -
             | 
| 78 | 
            -
              def test_update
         | 
| 79 | 
            -
                refute(@@callbacks.before_save)
         | 
| 80 | 
            -
                refute(@@callbacks.after_save)
         | 
| 81 | 
            -
                refute(@@callbacks.around_save)
         | 
| 82 | 
            -
             | 
| 83 | 
            -
                refute(@@callbacks.before_create)
         | 
| 84 | 
            -
                refute(@@callbacks.after_create)
         | 
| 85 | 
            -
                refute(@@callbacks.around_create)
         | 
| 86 | 
            -
             | 
| 87 | 
            -
                suburb = suburbs(:first)
         | 
| 88 | 
            -
                suburb.name = 'Updated'
         | 
| 89 | 
            -
                suburb.save
         | 
| 90 | 
            -
             | 
| 91 | 
            -
                assert(@@callbacks.before_update)
         | 
| 92 | 
            -
                assert(@@callbacks.after_update)
         | 
| 93 | 
            -
                assert(@@callbacks.around_update)
         | 
| 94 | 
            -
             | 
| 95 | 
            -
                assert(@@callbacks.before_save)
         | 
| 96 | 
            -
                assert(@@callbacks.after_save)
         | 
| 97 | 
            -
                assert(@@callbacks.around_save)
         | 
| 98 | 
            -
              end
         | 
| 99 | 
            -
            end
         | 
| 1 | 
            +
            require File.expand_path('../abstract_unit', __FILE__)
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            class TestCallbacks < ActiveSupport::TestCase
         | 
| 4 | 
            +
              fixtures :suburbs
         | 
| 5 | 
            +
             | 
| 6 | 
            +
              def setup
         | 
| 7 | 
            +
                @@callbacks = OpenStruct.new
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                Suburb.class_eval do
         | 
| 10 | 
            +
                  before_create do
         | 
| 11 | 
            +
                    @@callbacks.before_create = true
         | 
| 12 | 
            +
                  end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                  after_create do
         | 
| 15 | 
            +
                    @@callbacks.after_create = true
         | 
| 16 | 
            +
                  end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                  around_create do |suburb, block|
         | 
| 19 | 
            +
                    @@callbacks.around_create = true
         | 
| 20 | 
            +
                    block.call
         | 
| 21 | 
            +
                  end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                  before_save do
         | 
| 24 | 
            +
                    @@callbacks.before_save = true
         | 
| 25 | 
            +
                  end
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                  after_save do
         | 
| 28 | 
            +
                    @@callbacks.after_save = true
         | 
| 29 | 
            +
                  end
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                  around_save do |suburb, block|
         | 
| 32 | 
            +
                    @@callbacks.around_save = true
         | 
| 33 | 
            +
                    block.call
         | 
| 34 | 
            +
                  end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                  before_update do
         | 
| 37 | 
            +
                    @@callbacks.before_update = true
         | 
| 38 | 
            +
                  end
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                  after_update do
         | 
| 41 | 
            +
                    @@callbacks.after_update = true
         | 
| 42 | 
            +
                  end
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                  around_update do |suburb, block|
         | 
| 45 | 
            +
                    @@callbacks.around_update = true
         | 
| 46 | 
            +
                    block.call
         | 
| 47 | 
            +
                  end
         | 
| 48 | 
            +
                end
         | 
| 49 | 
            +
              end
         | 
| 50 | 
            +
             | 
| 51 | 
            +
              def teardown
         | 
| 52 | 
            +
                Suburb.reset_callbacks(:create)
         | 
| 53 | 
            +
                Suburb.reset_callbacks(:save)
         | 
| 54 | 
            +
                Suburb.reset_callbacks(:update)
         | 
| 55 | 
            +
              end
         | 
| 56 | 
            +
             | 
| 57 | 
            +
              def test_create
         | 
| 58 | 
            +
                refute(@@callbacks.before_save)
         | 
| 59 | 
            +
                refute(@@callbacks.after_save)
         | 
| 60 | 
            +
                refute(@@callbacks.around_save)
         | 
| 61 | 
            +
             | 
| 62 | 
            +
                refute(@@callbacks.before_create)
         | 
| 63 | 
            +
                refute(@@callbacks.after_create)
         | 
| 64 | 
            +
                refute(@@callbacks.around_create)
         | 
| 65 | 
            +
             | 
| 66 | 
            +
                suburb = Suburb.new(:city_id => 3, :suburb_id => 3, :name => 'created')
         | 
| 67 | 
            +
                suburb.save!
         | 
| 68 | 
            +
             | 
| 69 | 
            +
                assert(@@callbacks.before_save)
         | 
| 70 | 
            +
                assert(@@callbacks.after_save)
         | 
| 71 | 
            +
                assert(@@callbacks.around_save)
         | 
| 72 | 
            +
             | 
| 73 | 
            +
                assert(@@callbacks.before_create)
         | 
| 74 | 
            +
                assert(@@callbacks.after_create)
         | 
| 75 | 
            +
                assert(@@callbacks.around_create)
         | 
| 76 | 
            +
              end
         | 
| 77 | 
            +
             | 
| 78 | 
            +
              def test_update
         | 
| 79 | 
            +
                refute(@@callbacks.before_save)
         | 
| 80 | 
            +
                refute(@@callbacks.after_save)
         | 
| 81 | 
            +
                refute(@@callbacks.around_save)
         | 
| 82 | 
            +
             | 
| 83 | 
            +
                refute(@@callbacks.before_create)
         | 
| 84 | 
            +
                refute(@@callbacks.after_create)
         | 
| 85 | 
            +
                refute(@@callbacks.around_create)
         | 
| 86 | 
            +
             | 
| 87 | 
            +
                suburb = suburbs(:first)
         | 
| 88 | 
            +
                suburb.name = 'Updated'
         | 
| 89 | 
            +
                suburb.save
         | 
| 90 | 
            +
             | 
| 91 | 
            +
                assert(@@callbacks.before_update)
         | 
| 92 | 
            +
                assert(@@callbacks.after_update)
         | 
| 93 | 
            +
                assert(@@callbacks.around_update)
         | 
| 94 | 
            +
             | 
| 95 | 
            +
                assert(@@callbacks.before_save)
         | 
| 96 | 
            +
                assert(@@callbacks.after_save)
         | 
| 97 | 
            +
                assert(@@callbacks.around_save)
         | 
| 98 | 
            +
              end
         | 
| 99 | 
            +
            end
         |