composite_primary_keys 9.0.4 → 9.0.5
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 +20 -0
- data/Rakefile +37 -34
- data/lib/composite_primary_keys.rb +5 -10
- data/lib/composite_primary_keys/arel/in.rb +6 -6
- data/lib/composite_primary_keys/arel/sqlserver.rb +36 -0
- data/lib/composite_primary_keys/associations/association_scope.rb +51 -29
- data/lib/composite_primary_keys/attribute_methods/read.rb +3 -1
- data/lib/composite_primary_keys/connection_adapters/abstract_mysql_adapter.rb +22 -0
- data/lib/composite_primary_keys/relation.rb +30 -0
- data/lib/composite_primary_keys/relation/query_methods.rb +25 -36
- data/lib/composite_primary_keys/sanitization.rb +31 -47
- data/lib/composite_primary_keys/version.rb +1 -1
- data/tasks/databases/mysql.rake +40 -42
- data/tasks/databases/oracle.rake +29 -15
- data/tasks/databases/postgresql.rake +38 -47
- data/tasks/databases/sqlite.rake +25 -0
- data/tasks/databases/sqlserver.rake +32 -16
- data/test/abstract_unit.rb +12 -11
- data/test/connections/connection_spec.rb +27 -18
- data/test/connections/databases.ci.yml +5 -4
- data/test/connections/databases.example.yml +19 -4
- data/test/connections/databases.yml +25 -4
- data/test/fixtures/article.rb +6 -5
- data/test/fixtures/db_definitions/mysql.sql +16 -7
- data/test/fixtures/db_definitions/oracle.drop.sql +2 -0
- data/test/fixtures/db_definitions/oracle.sql +25 -15
- data/test/fixtures/db_definitions/postgresql.sql +11 -2
- data/test/fixtures/db_definitions/sqlite.sql +8 -0
- data/test/fixtures/db_definitions/sqlserver.sql +19 -33
- data/test/fixtures/pk_called_id.rb +5 -0
- data/test/fixtures/pk_called_ids.yml +11 -0
- data/test/test_associations.rb +334 -332
- data/test/test_create.rb +9 -1
- data/test/test_delete.rb +17 -39
- data/test/test_ids.rb +113 -109
- data/test/test_preload.rb +94 -0
- data/test/test_suite.rb +1 -1
- data/test/test_update.rb +12 -7
- metadata +14 -24
- data/lib/composite_primary_keys/associations/singular_association.rb +0 -14
- data/lib/composite_primary_keys/connection_adapters/abstract/connection_specification_changes.rb +0 -71
- data/lib/composite_primary_keys/connection_adapters/postgresql_adapter.rb +0 -50
- data/lib/composite_primary_keys/dirty.rb +0 -19
- data/lib/composite_primary_keys/validations/uniqueness.rb +0 -41
- data/tasks/databases/oracle_enhanced.rake +0 -27
- data/tasks/databases/sqlite3.rake +0 -27
- data/test/connections/native_ibm_db/connection.rb +0 -19
- data/test/connections/native_mysql/connection.rb +0 -17
- data/test/connections/native_oracle/connection.rb +0 -11
- data/test/connections/native_oracle_enhanced/connection.rb +0 -16
- data/test/connections/native_postgresql/connection.rb +0 -13
- data/test/connections/native_sqlite3/connection.rb +0 -9
- data/test/connections/native_sqlserver/connection.rb +0 -11
- data/test/fixtures/db_definitions/sqlserver.drop.sql +0 -92
- data/test/test_delete_all.rb +0 -29
| @@ -1,59 +1,43 @@ | |
| 1 1 | 
             
            module ActiveRecord
         | 
| 2 2 | 
             
              module Sanitization
         | 
| 3 3 | 
             
                module ClassMethods
         | 
| 4 | 
            -
             | 
| 5 4 | 
             
                  protected
         | 
| 6 | 
            -
             | 
| 7 | 
            -
                   | 
| 8 | 
            -
             | 
| 9 | 
            -
             | 
| 10 | 
            -
             | 
| 11 | 
            -
             | 
| 12 | 
            -
             | 
| 13 | 
            -
             | 
| 14 | 
            -
             | 
| 15 | 
            -
             | 
| 16 | 
            -
             | 
| 17 | 
            -
             | 
| 18 | 
            -
             | 
| 19 | 
            -
             | 
| 20 | 
            -
             | 
| 21 | 
            -
             | 
| 22 | 
            -
             | 
| 23 | 
            -
             | 
| 24 | 
            -
                      attrs.each do |attr, value|
         | 
| 25 | 
            -
                        # CPK
         | 
| 26 | 
            -
                        # if aggregation = reflect_on_aggregation(attr.to_sym)
         | 
| 27 | 
            -
                        if attr.is_a?(CompositePrimaryKeys::CompositeKeys)
         | 
| 28 | 
            -
                          attr.each_with_index do |key,i|
         | 
| 29 | 
            -
                            expanded_attrs[key] = value.respond_to?(:flatten) ? value.flatten[i] : value
         | 
| 30 | 
            -
                          end
         | 
| 31 | 
            -
                        elsif aggregation = reflect_on_aggregation(attr.to_sym)
         | 
| 32 | 
            -
                          mapping = aggregation.mapping
         | 
| 33 | 
            -
                          mapping.each do |field_attr, aggregate_attr|
         | 
| 34 | 
            -
                            if mapping.size == 1 && !value.respond_to?(aggregate_attr)
         | 
| 35 | 
            -
                              expanded_attrs[field_attr] = value
         | 
| 36 | 
            -
                            else
         | 
| 37 | 
            -
                              expanded_attrs[field_attr] = value.send(aggregate_attr)
         | 
| 38 | 
            -
                            end
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                  def expand_hash_conditions_for_aggregates(attrs)
         | 
| 7 | 
            +
                    expanded_attrs = {}
         | 
| 8 | 
            +
                    attrs.each do |attr, value|
         | 
| 9 | 
            +
                      # CPK
         | 
| 10 | 
            +
                      # if aggregation = reflect_on_aggregation(attr.to_sym)
         | 
| 11 | 
            +
                      if attr.is_a?(CompositePrimaryKeys::CompositeKeys)
         | 
| 12 | 
            +
                        value = value.split('/') if value.is_a?(String)
         | 
| 13 | 
            +
                        attr.each_with_index do |key,i|
         | 
| 14 | 
            +
                          expanded_attrs[key] = value.respond_to?(:flatten) ? value.flatten[i] : value
         | 
| 15 | 
            +
                        end
         | 
| 16 | 
            +
                      elsif aggregation = reflect_on_aggregation(attr.to_sym)
         | 
| 17 | 
            +
                        mapping = aggregation.mapping
         | 
| 18 | 
            +
                        mapping.each do |field_attr, aggregate_attr|
         | 
| 19 | 
            +
                          if mapping.size == 1 && !value.respond_to?(aggregate_attr)
         | 
| 20 | 
            +
                            expanded_attrs[field_attr] = value
         | 
| 21 | 
            +
                          else
         | 
| 22 | 
            +
                            expanded_attrs[field_attr] = value.send(aggregate_attr)
         | 
| 39 23 | 
             
                          end
         | 
| 40 | 
            -
                        else
         | 
| 41 | 
            -
                          expanded_attrs[attr] = value
         | 
| 42 24 | 
             
                        end
         | 
| 25 | 
            +
                      else
         | 
| 26 | 
            +
                        expanded_attrs[attr] = value
         | 
| 43 27 | 
             
                      end
         | 
| 44 | 
            -
                      expanded_attrs
         | 
| 45 28 | 
             
                    end
         | 
| 29 | 
            +
                    expanded_attrs
         | 
| 30 | 
            +
                  end
         | 
| 46 31 |  | 
| 47 | 
            -
             | 
| 48 | 
            -
             | 
| 49 | 
            -
             | 
| 50 | 
            -
             | 
| 51 | 
            -
             | 
| 52 | 
            -
             | 
| 53 | 
            -
             | 
| 54 | 
            -
             | 
| 55 | 
            -
             | 
| 56 | 
            -
                      end
         | 
| 32 | 
            +
                  def quoted_id
         | 
| 33 | 
            +
                    # CPK
         | 
| 34 | 
            +
                    # self.class.quote_value(@attributes[self.class.primary_key].value_for_database)
         | 
| 35 | 
            +
                    if self.composite?
         | 
| 36 | 
            +
                      [self.class.primary_keys, ids].transpose.map { |attr_name,id|
         | 
| 37 | 
            +
                        self.class.quote_value(@attributes[attr_name].value_for_database)
         | 
| 38 | 
            +
                      }
         | 
| 39 | 
            +
                    else
         | 
| 40 | 
            +
                      self.class.quote_value(@attributes[self.class.primary_key].value_for_database)
         | 
| 57 41 | 
             
                    end
         | 
| 58 42 | 
             
                  end
         | 
| 59 43 | 
             
                end
         | 
    
        data/tasks/databases/mysql.rake
    CHANGED
    
    | @@ -1,42 +1,40 @@ | |
| 1 | 
            -
             | 
| 2 | 
            -
             | 
| 3 | 
            -
             | 
| 4 | 
            -
             | 
| 5 | 
            -
               | 
| 6 | 
            -
             | 
| 7 | 
            -
             | 
| 8 | 
            -
                spec = CompositePrimaryKeys::ConnectionSpec['mysql'] | 
| 9 | 
            -
                 | 
| 10 | 
            -
                 | 
| 11 | 
            -
                 | 
| 12 | 
            -
                ActiveRecord::Base. | 
| 13 | 
            -
             | 
| 14 | 
            -
             | 
| 15 | 
            -
               | 
| 16 | 
            -
             | 
| 17 | 
            -
             | 
| 18 | 
            -
             | 
| 19 | 
            -
             | 
| 20 | 
            -
                 | 
| 21 | 
            -
             | 
| 22 | 
            -
                 | 
| 23 | 
            -
             | 
| 24 | 
            -
                 | 
| 25 | 
            -
                 | 
| 26 | 
            -
             | 
| 27 | 
            -
             | 
| 28 | 
            -
             | 
| 29 | 
            -
             | 
| 30 | 
            -
             | 
| 31 | 
            -
               | 
| 32 | 
            -
             | 
| 33 | 
            -
             | 
| 34 | 
            -
             | 
| 35 | 
            -
             | 
| 36 | 
            -
               | 
| 37 | 
            -
             | 
| 38 | 
            -
               | 
| 39 | 
            -
             | 
| 40 | 
            -
             | 
| 41 | 
            -
              end
         | 
| 42 | 
            -
            end
         | 
| 1 | 
            +
            namespace :mysql do
         | 
| 2 | 
            +
              task :setup do
         | 
| 3 | 
            +
                require 'bundler'
         | 
| 4 | 
            +
                Bundler.require(:default, :mysql)
         | 
| 5 | 
            +
              end
         | 
| 6 | 
            +
             | 
| 7 | 
            +
              task :create_database => :setup do
         | 
| 8 | 
            +
                spec = CompositePrimaryKeys::ConnectionSpec['mysql']
         | 
| 9 | 
            +
                ActiveRecord::Base.clear_all_connections!
         | 
| 10 | 
            +
                new_spec = spec.dup
         | 
| 11 | 
            +
                new_spec.delete('database')
         | 
| 12 | 
            +
                connection = ActiveRecord::Base.establish_connection(new_spec)
         | 
| 13 | 
            +
                ActiveRecord::Base.connection.create_database(spec['database'])
         | 
| 14 | 
            +
                ActiveRecord::Base.clear_all_connections!
         | 
| 15 | 
            +
              end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
              desc 'Build the MySQL test database'
         | 
| 18 | 
            +
              task :build_database => [:create_database] do
         | 
| 19 | 
            +
                path = File.join(PROJECT_ROOT, 'test', 'fixtures', 'db_definitions', 'mysql.sql')
         | 
| 20 | 
            +
                sql = File.open(path, 'rb') do |file|
         | 
| 21 | 
            +
                  file.read
         | 
| 22 | 
            +
                end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                spec = CompositePrimaryKeys::ConnectionSpec['mysql']
         | 
| 25 | 
            +
                connection = ActiveRecord::Base.establish_connection(spec)
         | 
| 26 | 
            +
                sql.split(";").each do |statement|
         | 
| 27 | 
            +
                  ActiveRecord::Base.connection.execute(statement) unless statement.strip.length == 0
         | 
| 28 | 
            +
                end
         | 
| 29 | 
            +
              end
         | 
| 30 | 
            +
             | 
| 31 | 
            +
              desc 'Drop the MySQL test database'
         | 
| 32 | 
            +
              task :drop_database => :setup do
         | 
| 33 | 
            +
                spec = CompositePrimaryKeys::ConnectionSpec['mysql']
         | 
| 34 | 
            +
                connection = ActiveRecord::Base.establish_connection(spec)
         | 
| 35 | 
            +
                ActiveRecord::Base.connection.drop_database(spec['database'])
         | 
| 36 | 
            +
              end
         | 
| 37 | 
            +
             | 
| 38 | 
            +
              desc 'Rebuild the MySQL test database'
         | 
| 39 | 
            +
              task :rebuild_database => [:drop_database, :build_database]
         | 
| 40 | 
            +
            end
         | 
    
        data/tasks/databases/oracle.rake
    CHANGED
    
    | @@ -1,27 +1,41 @@ | |
| 1 | 
            -
            require File.join(PROJECT_ROOT, 'lib', 'composite_primary_keys')
         | 
| 2 | 
            -
            require File.join(PROJECT_ROOT, 'test', 'connections', 'connection_spec')
         | 
| 3 | 
            -
             | 
| 4 1 | 
             
            namespace :oracle do
         | 
| 2 | 
            +
              task :setup do
         | 
| 3 | 
            +
                require 'bundler'
         | 
| 4 | 
            +
                Bundler.require(:default, :oracle)
         | 
| 5 | 
            +
              end
         | 
| 6 | 
            +
             | 
| 5 7 | 
             
              desc 'Build the Oracle test database'
         | 
| 6 | 
            -
              task :build_database => : | 
| 7 | 
            -
                 | 
| 8 | 
            +
              task :build_database => :setup do
         | 
| 9 | 
            +
                spec = CompositePrimaryKeys::ConnectionSpec['oracle']
         | 
| 10 | 
            +
                ActiveRecord::Base.clear_all_connections!
         | 
| 11 | 
            +
                ActiveRecord::Base.establish_connection(spec)
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                schema = File.join(PROJECT_ROOT, 'test', 'fixtures', 'db_definitions', 'oracle.sql')
         | 
| 14 | 
            +
                sql = File.read(schema)
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                sql.split(';').each do |command|
         | 
| 17 | 
            +
                  ActiveRecord::Base.connection.execute(command)
         | 
| 18 | 
            +
                end
         | 
| 8 19 |  | 
| 9 | 
            -
                 | 
| 10 | 
            -
                sh %( sqlplus #{options_str} < #{sql} )
         | 
| 20 | 
            +
                ActiveRecord::Base.clear_all_connections!
         | 
| 11 21 | 
             
              end
         | 
| 12 22 |  | 
| 13 23 | 
             
              desc 'Drop the Oracle test database'
         | 
| 14 | 
            -
              task :drop_database => : | 
| 15 | 
            -
                 | 
| 24 | 
            +
              task :drop_database => :setup do
         | 
| 25 | 
            +
                spec = CompositePrimaryKeys::ConnectionSpec['oracle']
         | 
| 26 | 
            +
                ActiveRecord::Base.clear_all_connections!
         | 
| 27 | 
            +
                ActiveRecord::Base.establish_connection(spec)
         | 
| 16 28 |  | 
| 17 | 
            -
                 | 
| 18 | 
            -
                 | 
| 29 | 
            +
                schema = File.join(PROJECT_ROOT, 'test', 'fixtures', 'db_definitions', 'oracle.drop.sql')
         | 
| 30 | 
            +
                sql = File.read(schema)
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                sql.split(';').each do |command|
         | 
| 33 | 
            +
                  ActiveRecord::Base.connection.execute(command)
         | 
| 34 | 
            +
                end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                ActiveRecord::Base.clear_all_connections!
         | 
| 19 37 | 
             
              end
         | 
| 20 38 |  | 
| 21 39 | 
             
              desc 'Rebuild the Oracle test database'
         | 
| 22 40 | 
             
              task :rebuild_database => [:drop_database, :build_database]
         | 
| 23 | 
            -
             | 
| 24 | 
            -
              task :load_connection do
         | 
| 25 | 
            -
                require File.join(PROJECT_ROOT, "test", "connections", "native_oracle", "connection")
         | 
| 26 | 
            -
              end
         | 
| 27 41 | 
             
            end
         | 
| @@ -1,48 +1,39 @@ | |
| 1 | 
            -
             | 
| 2 | 
            -
             | 
| 3 | 
            -
             | 
| 4 | 
            -
             | 
| 5 | 
            -
               | 
| 6 | 
            -
             | 
| 7 | 
            -
             | 
| 8 | 
            -
                spec = CompositePrimaryKeys::ConnectionSpec['postgresql'] | 
| 9 | 
            -
                 | 
| 10 | 
            -
                spec | 
| 11 | 
            -
                 | 
| 12 | 
            -
                ActiveRecord::Base. | 
| 13 | 
            -
             | 
| 14 | 
            -
             | 
| 15 | 
            -
             | 
| 16 | 
            -
               | 
| 17 | 
            -
             | 
| 18 | 
            -
                ActiveRecord::Base.clear_all_connections!
         | 
| 19 | 
            -
                 | 
| 20 | 
            -
             | 
| 21 | 
            -
             | 
| 22 | 
            -
                 | 
| 23 | 
            -
             | 
| 24 | 
            -
             | 
| 25 | 
            -
                 | 
| 26 | 
            -
             | 
| 27 | 
            -
             | 
| 28 | 
            -
             | 
| 29 | 
            -
               | 
| 30 | 
            -
             | 
| 31 | 
            -
             | 
| 32 | 
            -
             | 
| 33 | 
            -
                ActiveRecord::Base. | 
| 34 | 
            -
                 | 
| 35 | 
            -
             | 
| 36 | 
            -
             | 
| 37 | 
            -
             | 
| 38 | 
            -
             | 
| 39 | 
            -
                ActiveRecord::Base.clear_all_connections!
         | 
| 40 | 
            -
              end
         | 
| 41 | 
            -
             | 
| 42 | 
            -
              desc 'Rebuild the PostgreSQL test database'
         | 
| 43 | 
            -
              task :rebuild_database => [:drop_database, :build_database]
         | 
| 44 | 
            -
             | 
| 45 | 
            -
              task :load_connection do
         | 
| 46 | 
            -
                require File.join(PROJECT_ROOT, "test", "connections", "native_postgresql", "connection")
         | 
| 47 | 
            -
              end
         | 
| 1 | 
            +
            namespace :postgresql do
         | 
| 2 | 
            +
              task :setup do
         | 
| 3 | 
            +
                require 'bundler'
         | 
| 4 | 
            +
                Bundler.require(:default, :postgresql)
         | 
| 5 | 
            +
              end
         | 
| 6 | 
            +
             | 
| 7 | 
            +
              task :create_database => :setup do
         | 
| 8 | 
            +
                spec = CompositePrimaryKeys::ConnectionSpec['postgresql']
         | 
| 9 | 
            +
                ActiveRecord::Base.clear_all_connections!
         | 
| 10 | 
            +
                ActiveRecord::Base.establish_connection(spec.dup.merge('database' => 'postgres'))
         | 
| 11 | 
            +
                ActiveRecord::Base.connection.create_database(spec['database'])
         | 
| 12 | 
            +
                ActiveRecord::Base.clear_all_connections!
         | 
| 13 | 
            +
              end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
              desc 'Build the Postgresql test database'
         | 
| 16 | 
            +
              task :build_database => :create_database do
         | 
| 17 | 
            +
                spec = CompositePrimaryKeys::ConnectionSpec['postgresql']
         | 
| 18 | 
            +
                ActiveRecord::Base.clear_all_connections!
         | 
| 19 | 
            +
                connection = ActiveRecord::Base.establish_connection(spec)
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                schema = File.join(PROJECT_ROOT, 'test', 'fixtures', 'db_definitions', 'postgresql.sql')
         | 
| 22 | 
            +
                sql = File.read(schema)
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                ActiveRecord::Base.connection.execute(sql)
         | 
| 25 | 
            +
                ActiveRecord::Base.clear_all_connections!
         | 
| 26 | 
            +
              end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
              desc 'Drop the Postgresql test database'
         | 
| 29 | 
            +
              task :drop_database  => :setup do
         | 
| 30 | 
            +
                spec = CompositePrimaryKeys::ConnectionSpec['postgresql']
         | 
| 31 | 
            +
                ActiveRecord::Base.clear_all_connections!
         | 
| 32 | 
            +
                connection = ActiveRecord::Base.establish_connection(spec.merge('database' => 'postgres'))
         | 
| 33 | 
            +
                ActiveRecord::Base.connection.drop_database(spec['database'])
         | 
| 34 | 
            +
                ActiveRecord::Base.clear_all_connections!
         | 
| 35 | 
            +
              end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
              desc 'Rebuild the PostgreSQL test database'
         | 
| 38 | 
            +
              task :rebuild_database => [:drop_database, :build_database]
         | 
| 48 39 | 
             
            end
         | 
| @@ -0,0 +1,25 @@ | |
| 1 | 
            +
            namespace :sqlite do
         | 
| 2 | 
            +
              task :setup do
         | 
| 3 | 
            +
                require 'bundler'
         | 
| 4 | 
            +
                Bundler.require(:default, :sqlite)
         | 
| 5 | 
            +
              end
         | 
| 6 | 
            +
             | 
| 7 | 
            +
              desc 'Build the sqlite test database'
         | 
| 8 | 
            +
              task :build_database => :setup do
         | 
| 9 | 
            +
                spec = CompositePrimaryKeys::ConnectionSpec['sqlite']
         | 
| 10 | 
            +
                schema = File.join(PROJECT_ROOT, 'test', 'fixtures', 'db_definitions', 'sqlite.sql')
         | 
| 11 | 
            +
                FileUtils.mkdir_p(File.dirname(spec['database']))
         | 
| 12 | 
            +
                cmd = "sqlite3 #{spec['database']} < #{schema}"
         | 
| 13 | 
            +
                puts cmd
         | 
| 14 | 
            +
                sh %{ #{cmd} }
         | 
| 15 | 
            +
              end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
              desc 'Drop the sqlite test database'
         | 
| 18 | 
            +
              task :drop_database => :setup do
         | 
| 19 | 
            +
                spec = CompositePrimaryKeys::ConnectionSpec['sqlite']
         | 
| 20 | 
            +
                sh %{ rm -f #{spec['database']} }
         | 
| 21 | 
            +
              end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
              desc 'Rebuild the sqlite test database'
         | 
| 24 | 
            +
              task :rebuild_database => [:drop_database, :build_database]
         | 
| 25 | 
            +
            end
         | 
| @@ -1,27 +1,43 @@ | |
| 1 | 
            -
            require File.join(PROJECT_ROOT, 'lib', 'composite_primary_keys')
         | 
| 2 | 
            -
            require File.join(PROJECT_ROOT, 'test', 'connections', 'connection_spec')
         | 
| 3 | 
            -
             | 
| 4 1 | 
             
            namespace :sqlserver do
         | 
| 5 | 
            -
               | 
| 6 | 
            -
             | 
| 7 | 
            -
                 | 
| 2 | 
            +
              task :setup do
         | 
| 3 | 
            +
                require 'bundler'
         | 
| 4 | 
            +
                Bundler.require(:default, :sqlserver)
         | 
| 5 | 
            +
              end
         | 
| 6 | 
            +
             | 
| 7 | 
            +
              task :create_database => :setup do
         | 
| 8 | 
            +
                spec = CompositePrimaryKeys::ConnectionSpec['sqlserver']
         | 
| 9 | 
            +
                database = spec.delete('database')
         | 
| 10 | 
            +
                ActiveRecord::Base.clear_all_connections!
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                ActiveRecord::Base.establish_connection(spec)
         | 
| 13 | 
            +
                ActiveRecord::Base.connection.execute("CREATE DATABASE [#{database}]")
         | 
| 14 | 
            +
                ActiveRecord::Base.clear_all_connections!
         | 
| 15 | 
            +
              end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
              task :build_database => :create_database do
         | 
| 18 | 
            +
                spec = CompositePrimaryKeys::ConnectionSpec['sqlserver']
         | 
| 19 | 
            +
                ActiveRecord::Base.establish_connection(spec)
         | 
| 8 20 |  | 
| 9 21 | 
             
                schema = File.join(PROJECT_ROOT, 'test', 'fixtures', 'db_definitions', 'sqlserver.sql')
         | 
| 10 | 
            -
                 | 
| 22 | 
            +
                sql = File.read(schema)
         | 
| 23 | 
            +
                ActiveRecord::Base.connection.execute(sql)
         | 
| 24 | 
            +
                ActiveRecord::Base.clear_all_connections!
         | 
| 11 25 | 
             
              end
         | 
| 12 26 |  | 
| 13 27 | 
             
              desc 'Drop the SQL Server test database'
         | 
| 14 | 
            -
              task :drop_database => : | 
| 15 | 
            -
                 | 
| 16 | 
            -
                
         | 
| 17 | 
            -
                 | 
| 18 | 
            -
                 | 
| 28 | 
            +
              task :drop_database => :setup do
         | 
| 29 | 
            +
                spec = CompositePrimaryKeys::ConnectionSpec['sqlserver']
         | 
| 30 | 
            +
                ActiveRecord::Base.clear_all_connections!
         | 
| 31 | 
            +
                ActiveRecord::Base.establish_connection(spec)
         | 
| 32 | 
            +
                database = spec.delete('database')
         | 
| 33 | 
            +
                ActiveRecord::Base.connection.execute(<<-SQL)
         | 
| 34 | 
            +
                  USE master;
         | 
| 35 | 
            +
                  ALTER DATABASE [#{database}] SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
         | 
| 36 | 
            +
                  DROP DATABASE [#{database}];
         | 
| 37 | 
            +
                SQL
         | 
| 38 | 
            +
                ActiveRecord::Base.clear_all_connections!
         | 
| 19 39 | 
             
              end
         | 
| 20 40 |  | 
| 21 41 | 
             
              desc 'Rebuild the SQL Server test database'
         | 
| 22 42 | 
             
              task :rebuild_database => [:drop_database, :build_database]
         | 
| 23 | 
            -
             | 
| 24 | 
            -
              task :load_connection do
         | 
| 25 | 
            -
                require File.join(PROJECT_ROOT, "test", "connections", "native_sqlserver", "connection")
         | 
| 26 | 
            -
              end
         | 
| 27 43 | 
             
            end
         | 
    
        data/test/abstract_unit.rb
    CHANGED
    
    | @@ -1,6 +1,6 @@ | |
| 1 | 
            -
            ENV[ | 
| 2 | 
            -
             | 
| 3 | 
            -
             | 
| 1 | 
            +
            spec_name = ENV['ADAPTER'] || 'postgresql'
         | 
| 2 | 
            +
            require 'bundler'
         | 
| 3 | 
            +
            Bundler.require(:default, spec_name.to_sym)
         | 
| 4 4 |  | 
| 5 5 | 
             
            # To make debugging easier, test within this source tree versus an installed gem
         | 
| 6 6 | 
             
            $LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
         | 
| @@ -8,14 +8,15 @@ require 'composite_primary_keys' | |
| 8 8 | 
             
            require 'minitest/autorun'
         | 
| 9 9 | 
             
            require 'active_support/test_case'
         | 
| 10 10 |  | 
| 11 | 
            -
            #  | 
| 12 | 
            -
             | 
| 11 | 
            +
            # Require the connection spec
         | 
| 12 | 
            +
            PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
         | 
| 13 | 
            +
            require File.join(PROJECT_ROOT, 'test', 'connections', 'connection_spec')
         | 
| 13 14 |  | 
| 14 | 
            -
            spec_name = ENV['ADAPTER'] || 'postgresql'
         | 
| 15 15 | 
             
            spec = CompositePrimaryKeys::ConnectionSpec[spec_name]
         | 
| 16 | 
            +
            puts "Loaded #{spec_name}"
         | 
| 16 17 |  | 
| 17 18 | 
             
            # And now connect to the database
         | 
| 18 | 
            -
             | 
| 19 | 
            +
            ActiveRecord::Base.establish_connection(spec)
         | 
| 19 20 |  | 
| 20 21 | 
             
            # Tell active record about the configuration
         | 
| 21 22 | 
             
            ActiveRecord::Base.configurations[:test] = spec
         | 
| @@ -28,7 +29,7 @@ I18n.config.enforce_available_locales = true | |
| 28 29 | 
             
            class ActiveSupport::TestCase
         | 
| 29 30 | 
             
              include ActiveRecord::TestFixtures
         | 
| 30 31 |  | 
| 31 | 
            -
              self.fixture_path = File.dirname(__FILE__) +  | 
| 32 | 
            +
              self.fixture_path = File.dirname(__FILE__) + '/fixtures/'
         | 
| 32 33 | 
             
              self.use_instantiated_fixtures = false
         | 
| 33 34 | 
             
              self.use_transactional_tests = true
         | 
| 34 35 | 
             
              self.test_order = :random
         | 
| @@ -37,7 +38,7 @@ class ActiveSupport::TestCase | |
| 37 38 | 
             
                # SQL Server doesn't have a separate column type just for dates,
         | 
| 38 39 | 
             
                # so the time is in the string and incorrectly formatted
         | 
| 39 40 | 
             
                if current_adapter?(:SQLServerAdapter)
         | 
| 40 | 
            -
                  assert_equal expected.strftime( | 
| 41 | 
            +
                  assert_equal expected.strftime('%Y/%m/%d 00:00:00'), actual.strftime('%Y/%m/%d 00:00:00')
         | 
| 41 42 | 
             
                elsif current_adapter?(:SybaseAdapter)
         | 
| 42 43 | 
             
                  assert_equal expected.to_s, actual.to_date.to_s, message
         | 
| 43 44 | 
             
                else
         | 
| @@ -55,7 +56,7 @@ class ActiveSupport::TestCase | |
| 55 56 | 
             
                ActiveRecord::Base.connection.class.class_eval do
         | 
| 56 57 | 
             
                  alias_method :execute, :execute_without_query_counting
         | 
| 57 58 | 
             
                end
         | 
| 58 | 
            -
                assert_equal num, ActiveRecord::Base.connection.query_count,  | 
| 59 | 
            +
                assert_equal num, ActiveRecord::Base.connection.query_count, '#{ActiveRecord::Base.connection.query_count} instead of #{num} queries were executed.'
         | 
| 59 60 | 
             
              end
         | 
| 60 61 |  | 
| 61 62 | 
             
              def assert_no_queries(&block)
         | 
| @@ -88,7 +89,7 @@ class ActiveSupport::TestCase | |
| 88 89 |  | 
| 89 90 | 
             
              # Oracle metadata is in all caps.
         | 
| 90 91 | 
             
              def with_quoted_identifiers(s)
         | 
| 91 | 
            -
                s.gsub(/ | 
| 92 | 
            +
                s.gsub(/'(\w+)'/) { |m|
         | 
| 92 93 | 
             
                  if ActiveRecord::Base.configurations[:test]['adapter'] =~ /oracle/i
         | 
| 93 94 | 
             
                    m.upcase
         | 
| 94 95 | 
             
                  else
         |