activerecord 4.2.11.3 → 5.0.7.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.
Potentially problematic release.
This version of activerecord might be problematic. Click here for more details.
- checksums.yaml +4 -4
 - data/CHANGELOG.md +1638 -1132
 - data/MIT-LICENSE +2 -2
 - data/README.rdoc +7 -8
 - data/examples/performance.rb +2 -3
 - data/examples/simple.rb +0 -1
 - data/lib/active_record.rb +7 -2
 - data/lib/active_record/aggregations.rb +34 -21
 - data/lib/active_record/association_relation.rb +7 -4
 - data/lib/active_record/associations.rb +347 -218
 - data/lib/active_record/associations/alias_tracker.rb +19 -16
 - data/lib/active_record/associations/association.rb +22 -10
 - data/lib/active_record/associations/association_scope.rb +75 -104
 - data/lib/active_record/associations/belongs_to_association.rb +21 -32
 - data/lib/active_record/associations/builder/association.rb +28 -34
 - data/lib/active_record/associations/builder/belongs_to.rb +43 -18
 - data/lib/active_record/associations/builder/collection_association.rb +7 -19
 - data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +16 -11
 - data/lib/active_record/associations/builder/has_many.rb +4 -4
 - data/lib/active_record/associations/builder/has_one.rb +11 -6
 - data/lib/active_record/associations/builder/singular_association.rb +13 -11
 - data/lib/active_record/associations/collection_association.rb +85 -69
 - data/lib/active_record/associations/collection_proxy.rb +104 -46
 - data/lib/active_record/associations/foreign_association.rb +1 -1
 - data/lib/active_record/associations/has_many_association.rb +21 -78
 - data/lib/active_record/associations/has_many_through_association.rb +6 -47
 - data/lib/active_record/associations/has_one_association.rb +12 -5
 - data/lib/active_record/associations/join_dependency.rb +38 -22
 - data/lib/active_record/associations/join_dependency/join_association.rb +15 -14
 - data/lib/active_record/associations/join_dependency/join_part.rb +2 -2
 - data/lib/active_record/associations/preloader.rb +14 -4
 - data/lib/active_record/associations/preloader/association.rb +52 -71
 - data/lib/active_record/associations/preloader/collection_association.rb +0 -7
 - data/lib/active_record/associations/preloader/has_many_through.rb +1 -1
 - data/lib/active_record/associations/preloader/has_one.rb +0 -8
 - data/lib/active_record/associations/preloader/singular_association.rb +0 -1
 - data/lib/active_record/associations/preloader/through_association.rb +36 -17
 - data/lib/active_record/associations/singular_association.rb +13 -1
 - data/lib/active_record/associations/through_association.rb +12 -4
 - data/lib/active_record/attribute.rb +69 -19
 - data/lib/active_record/attribute/user_provided_default.rb +28 -0
 - data/lib/active_record/attribute_assignment.rb +19 -140
 - data/lib/active_record/attribute_decorators.rb +6 -5
 - data/lib/active_record/attribute_methods.rb +69 -44
 - data/lib/active_record/attribute_methods/before_type_cast.rb +1 -1
 - data/lib/active_record/attribute_methods/dirty.rb +46 -86
 - data/lib/active_record/attribute_methods/primary_key.rb +16 -3
 - data/lib/active_record/attribute_methods/query.rb +2 -2
 - data/lib/active_record/attribute_methods/read.rb +31 -59
 - data/lib/active_record/attribute_methods/serialization.rb +13 -16
 - data/lib/active_record/attribute_methods/time_zone_conversion.rb +61 -14
 - data/lib/active_record/attribute_methods/write.rb +13 -37
 - data/lib/active_record/attribute_mutation_tracker.rb +70 -0
 - data/lib/active_record/attribute_set.rb +32 -3
 - data/lib/active_record/attribute_set/builder.rb +42 -16
 - data/lib/active_record/attributes.rb +199 -81
 - data/lib/active_record/autosave_association.rb +54 -17
 - data/lib/active_record/base.rb +32 -23
 - data/lib/active_record/callbacks.rb +39 -43
 - data/lib/active_record/coders/json.rb +1 -1
 - data/lib/active_record/coders/yaml_column.rb +20 -8
 - data/lib/active_record/collection_cache_key.rb +50 -0
 - data/lib/active_record/connection_adapters/abstract/connection_pool.rb +467 -189
 - data/lib/active_record/connection_adapters/abstract/database_limits.rb +3 -3
 - data/lib/active_record/connection_adapters/abstract/database_statements.rb +66 -62
 - data/lib/active_record/connection_adapters/abstract/query_cache.rb +39 -4
 - data/lib/active_record/connection_adapters/abstract/quoting.rb +86 -13
 - data/lib/active_record/connection_adapters/abstract/savepoints.rb +3 -3
 - data/lib/active_record/connection_adapters/abstract/schema_creation.rb +61 -39
 - data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +236 -188
 - data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +72 -17
 - data/lib/active_record/connection_adapters/abstract/schema_statements.rb +407 -156
 - data/lib/active_record/connection_adapters/abstract/transaction.rb +51 -34
 - data/lib/active_record/connection_adapters/abstract_adapter.rb +177 -71
 - data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +433 -399
 - data/lib/active_record/connection_adapters/column.rb +28 -43
 - data/lib/active_record/connection_adapters/connection_specification.rb +15 -27
 - data/lib/active_record/connection_adapters/determine_if_preparable_visitor.rb +22 -0
 - data/lib/active_record/connection_adapters/mysql/column.rb +50 -0
 - data/lib/active_record/connection_adapters/mysql/database_statements.rb +108 -0
 - data/lib/active_record/connection_adapters/mysql/explain_pretty_printer.rb +70 -0
 - data/lib/active_record/connection_adapters/mysql/quoting.rb +51 -0
 - data/lib/active_record/connection_adapters/mysql/schema_creation.rb +67 -0
 - data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +93 -0
 - data/lib/active_record/connection_adapters/mysql/schema_dumper.rb +54 -0
 - data/lib/active_record/connection_adapters/mysql/type_metadata.rb +32 -0
 - data/lib/active_record/connection_adapters/mysql2_adapter.rb +25 -166
 - data/lib/active_record/connection_adapters/postgresql/column.rb +33 -11
 - data/lib/active_record/connection_adapters/postgresql/database_statements.rb +18 -72
 - data/lib/active_record/connection_adapters/postgresql/explain_pretty_printer.rb +42 -0
 - data/lib/active_record/connection_adapters/postgresql/oid.rb +1 -6
 - data/lib/active_record/connection_adapters/postgresql/oid/array.rb +37 -57
 - data/lib/active_record/connection_adapters/postgresql/oid/bit.rb +3 -3
 - data/lib/active_record/connection_adapters/postgresql/oid/bytea.rb +2 -2
 - data/lib/active_record/connection_adapters/postgresql/oid/cidr.rb +3 -1
 - data/lib/active_record/connection_adapters/postgresql/oid/date_time.rb +7 -22
 - data/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +13 -3
 - data/lib/active_record/connection_adapters/postgresql/oid/json.rb +1 -26
 - data/lib/active_record/connection_adapters/postgresql/oid/jsonb.rb +2 -2
 - data/lib/active_record/connection_adapters/postgresql/oid/money.rb +0 -4
 - data/lib/active_record/connection_adapters/postgresql/oid/point.rb +4 -4
 - data/lib/active_record/connection_adapters/postgresql/oid/rails_5_1_point.rb +50 -0
 - data/lib/active_record/connection_adapters/postgresql/oid/range.rb +31 -17
 - data/lib/active_record/connection_adapters/postgresql/oid/specialized_string.rb +0 -4
 - data/lib/active_record/connection_adapters/postgresql/oid/uuid.rb +2 -2
 - data/lib/active_record/connection_adapters/postgresql/oid/vector.rb +1 -1
 - data/lib/active_record/connection_adapters/postgresql/oid/xml.rb +1 -1
 - data/lib/active_record/connection_adapters/postgresql/quoting.rb +56 -19
 - data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +29 -10
 - data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +107 -79
 - data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +47 -0
 - data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +250 -154
 - data/lib/active_record/connection_adapters/postgresql/type_metadata.rb +35 -0
 - data/lib/active_record/connection_adapters/postgresql/utils.rb +2 -2
 - data/lib/active_record/connection_adapters/postgresql_adapter.rb +264 -170
 - data/lib/active_record/connection_adapters/schema_cache.rb +36 -23
 - data/lib/active_record/connection_adapters/sql_type_metadata.rb +32 -0
 - data/lib/active_record/connection_adapters/sqlite3/explain_pretty_printer.rb +19 -0
 - data/lib/active_record/connection_adapters/sqlite3/quoting.rb +48 -0
 - data/lib/active_record/connection_adapters/sqlite3/schema_creation.rb +22 -0
 - data/lib/active_record/connection_adapters/sqlite3_adapter.rb +151 -194
 - data/lib/active_record/connection_adapters/statement_pool.rb +31 -12
 - data/lib/active_record/connection_handling.rb +37 -14
 - data/lib/active_record/core.rb +92 -108
 - data/lib/active_record/counter_cache.rb +13 -24
 - data/lib/active_record/dynamic_matchers.rb +1 -20
 - data/lib/active_record/enum.rb +116 -76
 - data/lib/active_record/errors.rb +87 -48
 - data/lib/active_record/explain.rb +20 -9
 - data/lib/active_record/explain_registry.rb +1 -1
 - data/lib/active_record/explain_subscriber.rb +1 -1
 - data/lib/active_record/fixture_set/file.rb +26 -5
 - data/lib/active_record/fixtures.rb +77 -41
 - data/lib/active_record/gem_version.rb +4 -4
 - data/lib/active_record/inheritance.rb +32 -40
 - data/lib/active_record/integration.rb +17 -14
 - data/lib/active_record/internal_metadata.rb +56 -0
 - data/lib/active_record/legacy_yaml_adapter.rb +18 -2
 - data/lib/active_record/locale/en.yml +3 -2
 - data/lib/active_record/locking/optimistic.rb +15 -15
 - data/lib/active_record/locking/pessimistic.rb +1 -1
 - data/lib/active_record/log_subscriber.rb +48 -24
 - data/lib/active_record/migration.rb +362 -111
 - data/lib/active_record/migration/command_recorder.rb +59 -18
 - data/lib/active_record/migration/compatibility.rb +126 -0
 - data/lib/active_record/model_schema.rb +270 -73
 - data/lib/active_record/nested_attributes.rb +58 -29
 - data/lib/active_record/no_touching.rb +4 -0
 - data/lib/active_record/null_relation.rb +16 -8
 - data/lib/active_record/persistence.rb +152 -90
 - data/lib/active_record/query_cache.rb +18 -23
 - data/lib/active_record/querying.rb +12 -11
 - data/lib/active_record/railtie.rb +23 -16
 - data/lib/active_record/railties/controller_runtime.rb +1 -1
 - data/lib/active_record/railties/databases.rake +52 -41
 - data/lib/active_record/readonly_attributes.rb +1 -1
 - data/lib/active_record/reflection.rb +302 -115
 - data/lib/active_record/relation.rb +187 -120
 - data/lib/active_record/relation/batches.rb +141 -36
 - data/lib/active_record/relation/batches/batch_enumerator.rb +67 -0
 - data/lib/active_record/relation/calculations.rb +92 -117
 - data/lib/active_record/relation/delegation.rb +8 -20
 - data/lib/active_record/relation/finder_methods.rb +173 -89
 - data/lib/active_record/relation/from_clause.rb +32 -0
 - data/lib/active_record/relation/merger.rb +16 -42
 - data/lib/active_record/relation/predicate_builder.rb +120 -107
 - data/lib/active_record/relation/predicate_builder/array_handler.rb +11 -16
 - data/lib/active_record/relation/predicate_builder/association_query_handler.rb +88 -0
 - data/lib/active_record/relation/predicate_builder/base_handler.rb +17 -0
 - data/lib/active_record/relation/predicate_builder/basic_object_handler.rb +17 -0
 - data/lib/active_record/relation/predicate_builder/class_handler.rb +27 -0
 - data/lib/active_record/relation/predicate_builder/polymorphic_array_handler.rb +57 -0
 - data/lib/active_record/relation/predicate_builder/range_handler.rb +33 -0
 - data/lib/active_record/relation/predicate_builder/relation_handler.rb +1 -1
 - data/lib/active_record/relation/query_attribute.rb +19 -0
 - data/lib/active_record/relation/query_methods.rb +308 -244
 - data/lib/active_record/relation/record_fetch_warning.rb +49 -0
 - data/lib/active_record/relation/spawn_methods.rb +4 -7
 - data/lib/active_record/relation/where_clause.rb +174 -0
 - data/lib/active_record/relation/where_clause_factory.rb +38 -0
 - data/lib/active_record/result.rb +11 -4
 - data/lib/active_record/runtime_registry.rb +1 -1
 - data/lib/active_record/sanitization.rb +105 -66
 - data/lib/active_record/schema.rb +26 -22
 - data/lib/active_record/schema_dumper.rb +54 -37
 - data/lib/active_record/schema_migration.rb +11 -14
 - data/lib/active_record/scoping.rb +34 -16
 - data/lib/active_record/scoping/default.rb +28 -10
 - data/lib/active_record/scoping/named.rb +59 -26
 - data/lib/active_record/secure_token.rb +38 -0
 - data/lib/active_record/serialization.rb +3 -5
 - data/lib/active_record/statement_cache.rb +17 -15
 - data/lib/active_record/store.rb +8 -3
 - data/lib/active_record/suppressor.rb +58 -0
 - data/lib/active_record/table_metadata.rb +69 -0
 - data/lib/active_record/tasks/database_tasks.rb +66 -49
 - data/lib/active_record/tasks/mysql_database_tasks.rb +6 -14
 - data/lib/active_record/tasks/postgresql_database_tasks.rb +12 -3
 - data/lib/active_record/tasks/sqlite_database_tasks.rb +5 -1
 - data/lib/active_record/timestamp.rb +20 -9
 - data/lib/active_record/touch_later.rb +63 -0
 - data/lib/active_record/transactions.rb +139 -57
 - data/lib/active_record/type.rb +66 -17
 - data/lib/active_record/type/adapter_specific_registry.rb +130 -0
 - data/lib/active_record/type/date.rb +2 -45
 - data/lib/active_record/type/date_time.rb +2 -49
 - data/lib/active_record/type/internal/abstract_json.rb +33 -0
 - data/lib/active_record/type/internal/timezone.rb +15 -0
 - data/lib/active_record/type/serialized.rb +15 -14
 - data/lib/active_record/type/time.rb +10 -16
 - data/lib/active_record/type/type_map.rb +4 -4
 - data/lib/active_record/type_caster.rb +7 -0
 - data/lib/active_record/type_caster/connection.rb +29 -0
 - data/lib/active_record/type_caster/map.rb +19 -0
 - data/lib/active_record/validations.rb +33 -32
 - data/lib/active_record/validations/absence.rb +23 -0
 - data/lib/active_record/validations/associated.rb +10 -3
 - data/lib/active_record/validations/length.rb +24 -0
 - data/lib/active_record/validations/presence.rb +11 -12
 - data/lib/active_record/validations/uniqueness.rb +33 -33
 - data/lib/rails/generators/active_record/migration.rb +15 -0
 - data/lib/rails/generators/active_record/migration/migration_generator.rb +8 -5
 - data/lib/rails/generators/active_record/migration/templates/create_table_migration.rb +8 -3
 - data/lib/rails/generators/active_record/migration/templates/migration.rb +8 -1
 - data/lib/rails/generators/active_record/model/model_generator.rb +33 -16
 - data/lib/rails/generators/active_record/model/templates/application_record.rb +5 -0
 - data/lib/rails/generators/active_record/model/templates/model.rb +3 -0
 - metadata +58 -34
 - data/lib/active_record/connection_adapters/mysql_adapter.rb +0 -498
 - data/lib/active_record/connection_adapters/postgresql/array_parser.rb +0 -93
 - data/lib/active_record/connection_adapters/postgresql/oid/date.rb +0 -11
 - data/lib/active_record/connection_adapters/postgresql/oid/float.rb +0 -21
 - data/lib/active_record/connection_adapters/postgresql/oid/infinity.rb +0 -13
 - data/lib/active_record/connection_adapters/postgresql/oid/integer.rb +0 -11
 - data/lib/active_record/connection_adapters/postgresql/oid/time.rb +0 -11
 - data/lib/active_record/serializers/xml_serializer.rb +0 -193
 - data/lib/active_record/type/big_integer.rb +0 -13
 - data/lib/active_record/type/binary.rb +0 -50
 - data/lib/active_record/type/boolean.rb +0 -31
 - data/lib/active_record/type/decimal.rb +0 -64
 - data/lib/active_record/type/decimal_without_scale.rb +0 -11
 - data/lib/active_record/type/decorator.rb +0 -14
 - data/lib/active_record/type/float.rb +0 -19
 - data/lib/active_record/type/integer.rb +0 -59
 - data/lib/active_record/type/mutable.rb +0 -16
 - data/lib/active_record/type/numeric.rb +0 -36
 - data/lib/active_record/type/string.rb +0 -40
 - data/lib/active_record/type/text.rb +0 -11
 - data/lib/active_record/type/time_value.rb +0 -38
 - data/lib/active_record/type/unsigned_integer.rb +0 -15
 - data/lib/active_record/type/value.rb +0 -110
 
| 
         @@ -16,15 +16,14 @@ module ActiveRecord 
     | 
|
| 
       16 
16 
     | 
    
         
             
                # Makes the adapter execute EXPLAIN for the tuples of queries and bindings.
         
     | 
| 
       17 
17 
     | 
    
         
             
                # Returns a formatted string ready to be logged.
         
     | 
| 
       18 
18 
     | 
    
         
             
                def exec_explain(queries) # :nodoc:
         
     | 
| 
       19 
     | 
    
         
            -
                  str = queries.map do |sql,  
     | 
| 
       20 
     | 
    
         
            -
                     
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
                       
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
                    end.join("\n")
         
     | 
| 
      
 19 
     | 
    
         
            +
                  str = queries.map do |sql, binds|
         
     | 
| 
      
 20 
     | 
    
         
            +
                    msg = "EXPLAIN for: #{sql}"
         
     | 
| 
      
 21 
     | 
    
         
            +
                    unless binds.empty?
         
     | 
| 
      
 22 
     | 
    
         
            +
                      msg << " "
         
     | 
| 
      
 23 
     | 
    
         
            +
                      msg << binds.map { |attr| render_bind(attr) }.inspect
         
     | 
| 
      
 24 
     | 
    
         
            +
                    end
         
     | 
| 
      
 25 
     | 
    
         
            +
                    msg << "\n"
         
     | 
| 
      
 26 
     | 
    
         
            +
                    msg << connection.explain(sql, binds)
         
     | 
| 
       28 
27 
     | 
    
         
             
                  end.join("\n")
         
     | 
| 
       29 
28 
     | 
    
         | 
| 
       30 
29 
     | 
    
         
             
                  # Overriding inspect to be more human readable, especially in the console.
         
     | 
| 
         @@ -34,5 +33,17 @@ module ActiveRecord 
     | 
|
| 
       34 
33 
     | 
    
         | 
| 
       35 
34 
     | 
    
         
             
                  str
         
     | 
| 
       36 
35 
     | 
    
         
             
                end
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
                private
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
                  def render_bind(attr)
         
     | 
| 
      
 40 
     | 
    
         
            +
                    value = if attr.type.binary? && attr.value
         
     | 
| 
      
 41 
     | 
    
         
            +
                      "<#{attr.value_for_database.to_s.bytesize} bytes of binary data>"
         
     | 
| 
      
 42 
     | 
    
         
            +
                    else
         
     | 
| 
      
 43 
     | 
    
         
            +
                      connection.type_cast(attr.value_for_database)
         
     | 
| 
      
 44 
     | 
    
         
            +
                    end
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
                    [attr.name, value]
         
     | 
| 
      
 47 
     | 
    
         
            +
                  end
         
     | 
| 
       37 
48 
     | 
    
         
             
              end
         
     | 
| 
       38 
49 
     | 
    
         
             
            end
         
     | 
| 
         @@ -7,7 +7,7 @@ module ActiveRecord 
     | 
|
| 
       7 
7 
     | 
    
         
             
              #
         
     | 
| 
       8 
8 
     | 
    
         
             
              # returns the collected queries local to the current thread.
         
     | 
| 
       9 
9 
     | 
    
         
             
              #
         
     | 
| 
       10 
     | 
    
         
            -
              # See the documentation of  
     | 
| 
      
 10 
     | 
    
         
            +
              # See the documentation of ActiveSupport::PerThreadRegistry
         
     | 
| 
       11 
11 
     | 
    
         
             
              # for further details.
         
     | 
| 
       12 
12 
     | 
    
         
             
              class ExplainRegistry # :nodoc:
         
     | 
| 
       13 
13 
     | 
    
         
             
                extend ActiveSupport::PerThreadRegistry
         
     | 
| 
         @@ -14,7 +14,7 @@ module ActiveRecord 
     | 
|
| 
       14 
14 
     | 
    
         
             
                end
         
     | 
| 
       15 
15 
     | 
    
         | 
| 
       16 
16 
     | 
    
         
             
                # SCHEMA queries cannot be EXPLAINed, also we do not want to run EXPLAIN on
         
     | 
| 
       17 
     | 
    
         
            -
                # our own EXPLAINs  
     | 
| 
      
 17 
     | 
    
         
            +
                # our own EXPLAINs no matter how loopingly beautiful that would be.
         
     | 
| 
       18 
18 
     | 
    
         
             
                #
         
     | 
| 
       19 
19 
     | 
    
         
             
                # On the other hand, we want to monitor the performance of our real database
         
     | 
| 
       20 
20 
     | 
    
         
             
                # queries, not the performance of the access to the query cache.
         
     | 
| 
         @@ -17,29 +17,50 @@ module ActiveRecord 
     | 
|
| 
       17 
17 
     | 
    
         | 
| 
       18 
18 
     | 
    
         
             
                  def initialize(file)
         
     | 
| 
       19 
19 
     | 
    
         
             
                    @file = file
         
     | 
| 
       20 
     | 
    
         
            -
                    @rows = nil
         
     | 
| 
       21 
20 
     | 
    
         
             
                  end
         
     | 
| 
       22 
21 
     | 
    
         | 
| 
       23 
22 
     | 
    
         
             
                  def each(&block)
         
     | 
| 
       24 
23 
     | 
    
         
             
                    rows.each(&block)
         
     | 
| 
       25 
24 
     | 
    
         
             
                  end
         
     | 
| 
       26 
25 
     | 
    
         | 
| 
      
 26 
     | 
    
         
            +
                  def model_class
         
     | 
| 
      
 27 
     | 
    
         
            +
                    config_row['model_class']
         
     | 
| 
      
 28 
     | 
    
         
            +
                  end
         
     | 
| 
       27 
29 
     | 
    
         | 
| 
       28 
30 
     | 
    
         
             
                  private
         
     | 
| 
       29 
31 
     | 
    
         
             
                    def rows
         
     | 
| 
       30 
     | 
    
         
            -
                       
     | 
| 
      
 32 
     | 
    
         
            +
                      @rows ||= raw_rows.reject { |fixture_name, _| fixture_name == '_fixture' }
         
     | 
| 
      
 33 
     | 
    
         
            +
                    end
         
     | 
| 
       31 
34 
     | 
    
         | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
      
 35 
     | 
    
         
            +
                    def config_row
         
     | 
| 
      
 36 
     | 
    
         
            +
                      @config_row ||= begin
         
     | 
| 
      
 37 
     | 
    
         
            +
                        row = raw_rows.find { |fixture_name, _| fixture_name == '_fixture' }
         
     | 
| 
      
 38 
     | 
    
         
            +
                        if row
         
     | 
| 
      
 39 
     | 
    
         
            +
                          row.last
         
     | 
| 
      
 40 
     | 
    
         
            +
                        else
         
     | 
| 
      
 41 
     | 
    
         
            +
                          {'model_class': nil}
         
     | 
| 
      
 42 
     | 
    
         
            +
                        end
         
     | 
| 
      
 43 
     | 
    
         
            +
                      end
         
     | 
| 
      
 44 
     | 
    
         
            +
                    end
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
                    def raw_rows
         
     | 
| 
      
 47 
     | 
    
         
            +
                      @raw_rows ||= begin
         
     | 
| 
       33 
48 
     | 
    
         
             
                        data = YAML.load(render(IO.read(@file)))
         
     | 
| 
      
 49 
     | 
    
         
            +
                        data ? validate(data).to_a : []
         
     | 
| 
       34 
50 
     | 
    
         
             
                      rescue ArgumentError, Psych::SyntaxError => error
         
     | 
| 
       35 
51 
     | 
    
         
             
                        raise Fixture::FormatError, "a YAML error occurred parsing #{@file}. Please note that YAML must be consistently indented using spaces. Tabs are not allowed. Please have a look at http://www.yaml.org/faq.html\nThe exact error was:\n  #{error.class}: #{error}", error.backtrace
         
     | 
| 
       36 
52 
     | 
    
         
             
                      end
         
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
      
 53 
     | 
    
         
            +
                    end
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
                    def prepare_erb(content)
         
     | 
| 
      
 56 
     | 
    
         
            +
                      erb = ERB.new(content)
         
     | 
| 
      
 57 
     | 
    
         
            +
                      erb.filename = @file
         
     | 
| 
      
 58 
     | 
    
         
            +
                      erb
         
     | 
| 
       38 
59 
     | 
    
         
             
                    end
         
     | 
| 
       39 
60 
     | 
    
         | 
| 
       40 
61 
     | 
    
         
             
                    def render(content)
         
     | 
| 
       41 
62 
     | 
    
         
             
                      context = ActiveRecord::FixtureSet::RenderContext.create_subclass.new
         
     | 
| 
       42 
     | 
    
         
            -
                       
     | 
| 
      
 63 
     | 
    
         
            +
                      prepare_erb(content).result(context.get_binding)
         
     | 
| 
       43 
64 
     | 
    
         
             
                    end
         
     | 
| 
       44 
65 
     | 
    
         | 
| 
       45 
66 
     | 
    
         
             
                    # Validate our unmarshalled data.
         
     | 
| 
         @@ -1,6 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'erb'
         
     | 
| 
       2 
2 
     | 
    
         
             
            require 'yaml'
         
     | 
| 
       3 
3 
     | 
    
         
             
            require 'zlib'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'set'
         
     | 
| 
       4 
5 
     | 
    
         
             
            require 'active_support/dependencies'
         
     | 
| 
       5 
6 
     | 
    
         
             
            require 'active_support/core_ext/digest/uuid'
         
     | 
| 
       6 
7 
     | 
    
         
             
            require 'active_record/fixture_set/file'
         
     | 
| 
         @@ -88,7 +89,7 @@ module ActiveRecord 
     | 
|
| 
       88 
89 
     | 
    
         
             
              #   end
         
     | 
| 
       89 
90 
     | 
    
         
             
              #
         
     | 
| 
       90 
91 
     | 
    
         
             
              # In order to use these methods to access fixtured data within your testcases, you must specify one of the
         
     | 
| 
       91 
     | 
    
         
            -
              # following in your  
     | 
| 
      
 92 
     | 
    
         
            +
              # following in your ActiveSupport::TestCase-derived class:
         
     | 
| 
       92 
93 
     | 
    
         
             
              #
         
     | 
| 
       93 
94 
     | 
    
         
             
              # - to fully enable instantiated fixtures (enable alternate methods #1 and #2 above)
         
     | 
| 
       94 
95 
     | 
    
         
             
              #     self.use_instantiated_fixtures = true
         
     | 
| 
         @@ -109,7 +110,7 @@ module ActiveRecord 
     | 
|
| 
       109 
110 
     | 
    
         
             
              #   <% 1.upto(1000) do |i| %>
         
     | 
| 
       110 
111 
     | 
    
         
             
              #   fix_<%= i %>:
         
     | 
| 
       111 
112 
     | 
    
         
             
              #     id: <%= i %>
         
     | 
| 
       112 
     | 
    
         
            -
              #     name: guy_<%=  
     | 
| 
      
 113 
     | 
    
         
            +
              #     name: guy_<%= i %>
         
     | 
| 
       113 
114 
     | 
    
         
             
              #   <% end %>
         
     | 
| 
       114 
115 
     | 
    
         
             
              #
         
     | 
| 
       115 
116 
     | 
    
         
             
              # This will create 1000 very simple fixtures.
         
     | 
| 
         @@ -123,7 +124,7 @@ module ActiveRecord 
     | 
|
| 
       123 
124 
     | 
    
         
             
              #
         
     | 
| 
       124 
125 
     | 
    
         
             
              # Helper methods defined in a fixture will not be available in other fixtures, to prevent against
         
     | 
| 
       125 
126 
     | 
    
         
             
              # unwanted inter-test dependencies. Methods used by multiple fixtures should be defined in a module
         
     | 
| 
       126 
     | 
    
         
            -
              # that is included in  
     | 
| 
      
 127 
     | 
    
         
            +
              # that is included in ActiveRecord::FixtureSet.context_class.
         
     | 
| 
       127 
128 
     | 
    
         
             
              #
         
     | 
| 
       128 
129 
     | 
    
         
             
              # - define a helper method in `test_helper.rb`
         
     | 
| 
       129 
130 
     | 
    
         
             
              #     module FixtureFileHelpers
         
     | 
| 
         @@ -131,20 +132,20 @@ module ActiveRecord 
     | 
|
| 
       131 
132 
     | 
    
         
             
              #         Digest::SHA2.hexdigest(File.read(Rails.root.join('test/fixtures', path)))
         
     | 
| 
       132 
133 
     | 
    
         
             
              #       end
         
     | 
| 
       133 
134 
     | 
    
         
             
              #     end
         
     | 
| 
       134 
     | 
    
         
            -
              #     ActiveRecord::FixtureSet.context_class. 
     | 
| 
      
 135 
     | 
    
         
            +
              #     ActiveRecord::FixtureSet.context_class.include FixtureFileHelpers
         
     | 
| 
       135 
136 
     | 
    
         
             
              #
         
     | 
| 
       136 
137 
     | 
    
         
             
              # - use the helper method in a fixture
         
     | 
| 
       137 
138 
     | 
    
         
             
              #     photo:
         
     | 
| 
       138 
139 
     | 
    
         
             
              #       name: kitten.png
         
     | 
| 
       139 
140 
     | 
    
         
             
              #       sha: <%= file_sha 'files/kitten.png' %>
         
     | 
| 
       140 
141 
     | 
    
         
             
              #
         
     | 
| 
       141 
     | 
    
         
            -
              # = Transactional  
     | 
| 
      
 142 
     | 
    
         
            +
              # = Transactional Tests
         
     | 
| 
       142 
143 
     | 
    
         
             
              #
         
     | 
| 
       143 
144 
     | 
    
         
             
              # Test cases can use begin+rollback to isolate their changes to the database instead of having to
         
     | 
| 
       144 
145 
     | 
    
         
             
              # delete+insert for every test case.
         
     | 
| 
       145 
146 
     | 
    
         
             
              #
         
     | 
| 
       146 
147 
     | 
    
         
             
              #   class FooTest < ActiveSupport::TestCase
         
     | 
| 
       147 
     | 
    
         
            -
              #     self. 
     | 
| 
      
 148 
     | 
    
         
            +
              #     self.use_transactional_tests = true
         
     | 
| 
       148 
149 
     | 
    
         
             
              #
         
     | 
| 
       149 
150 
     | 
    
         
             
              #     test "godzilla" do
         
     | 
| 
       150 
151 
     | 
    
         
             
              #       assert !Foo.all.empty?
         
     | 
| 
         @@ -158,14 +159,14 @@ module ActiveRecord 
     | 
|
| 
       158 
159 
     | 
    
         
             
              #   end
         
     | 
| 
       159 
160 
     | 
    
         
             
              #
         
     | 
| 
       160 
161 
     | 
    
         
             
              # If you preload your test database with all fixture data (probably in the rake task) and use
         
     | 
| 
       161 
     | 
    
         
            -
              # transactional  
     | 
| 
      
 162 
     | 
    
         
            +
              # transactional tests, then you may omit all fixtures declarations in your test cases since
         
     | 
| 
       162 
163 
     | 
    
         
             
              # all the data's already there and every case rolls back its changes.
         
     | 
| 
       163 
164 
     | 
    
         
             
              #
         
     | 
| 
       164 
165 
     | 
    
         
             
              # In order to use instantiated fixtures with preloaded data, set +self.pre_loaded_fixtures+ to
         
     | 
| 
       165 
166 
     | 
    
         
             
              # true. This will provide access to fixture data for every table that has been loaded through
         
     | 
| 
       166 
167 
     | 
    
         
             
              # fixtures (depending on the value of +use_instantiated_fixtures+).
         
     | 
| 
       167 
168 
     | 
    
         
             
              #
         
     | 
| 
       168 
     | 
    
         
            -
              # When *not* to use transactional  
     | 
| 
      
 169 
     | 
    
         
            +
              # When *not* to use transactional tests:
         
     | 
| 
       169 
170 
     | 
    
         
             
              #
         
     | 
| 
       170 
171 
     | 
    
         
             
              # 1. You're testing whether a transaction works correctly. Nested transactions don't commit until
         
     | 
| 
       171 
172 
     | 
    
         
             
              #    all parent transactions commit, particularly, the fixtures transaction which is begun in setup
         
     | 
| 
         @@ -394,6 +395,20 @@ module ActiveRecord 
     | 
|
| 
       394 
395 
     | 
    
         
             
              #     <<: *DEFAULTS
         
     | 
| 
       395 
396 
     | 
    
         
             
              #
         
     | 
| 
       396 
397 
     | 
    
         
             
              # Any fixture labeled "DEFAULTS" is safely ignored.
         
     | 
| 
      
 398 
     | 
    
         
            +
              #
         
     | 
| 
      
 399 
     | 
    
         
            +
              # == Configure the fixture model class
         
     | 
| 
      
 400 
     | 
    
         
            +
              #
         
     | 
| 
      
 401 
     | 
    
         
            +
              # It's possible to set the fixture's model class directly in the YAML file.
         
     | 
| 
      
 402 
     | 
    
         
            +
              # This is helpful when fixtures are loaded outside tests and
         
     | 
| 
      
 403 
     | 
    
         
            +
              # +set_fixture_class+ is not available (e.g.
         
     | 
| 
      
 404 
     | 
    
         
            +
              # when running <tt>rails db:fixtures:load</tt>).
         
     | 
| 
      
 405 
     | 
    
         
            +
              #
         
     | 
| 
      
 406 
     | 
    
         
            +
              #   _fixture:
         
     | 
| 
      
 407 
     | 
    
         
            +
              #     model_class: User
         
     | 
| 
      
 408 
     | 
    
         
            +
              #   david:
         
     | 
| 
      
 409 
     | 
    
         
            +
              #     name: David
         
     | 
| 
      
 410 
     | 
    
         
            +
              #
         
     | 
| 
      
 411 
     | 
    
         
            +
              # Any fixtures labeled "_fixture" are safely ignored.
         
     | 
| 
       397 
412 
     | 
    
         
             
              class FixtureSet
         
     | 
| 
       398 
413 
     | 
    
         
             
                #--
         
     | 
| 
       399 
414 
     | 
    
         
             
                # An instance of FixtureSet is normally stored in a single YAML file and
         
     | 
| 
         @@ -520,13 +535,17 @@ module ActiveRecord 
     | 
|
| 
       520 
535 
     | 
    
         | 
| 
       521 
536 
     | 
    
         
             
                      update_all_loaded_fixtures fixtures_map
         
     | 
| 
       522 
537 
     | 
    
         | 
| 
       523 
     | 
    
         
            -
                      connection.transaction(: 
     | 
| 
      
 538 
     | 
    
         
            +
                      connection.transaction(requires_new: true) do
         
     | 
| 
      
 539 
     | 
    
         
            +
                        deleted_tables = Hash.new { |h, k| h[k] = Set.new }
         
     | 
| 
       524 
540 
     | 
    
         
             
                        fixture_sets.each do |fs|
         
     | 
| 
       525 
541 
     | 
    
         
             
                          conn = fs.model_class.respond_to?(:connection) ? fs.model_class.connection : connection
         
     | 
| 
       526 
542 
     | 
    
         
             
                          table_rows = fs.table_rows
         
     | 
| 
       527 
543 
     | 
    
         | 
| 
       528 
544 
     | 
    
         
             
                          table_rows.each_key do |table|
         
     | 
| 
       529 
     | 
    
         
            -
                            conn. 
     | 
| 
      
 545 
     | 
    
         
            +
                            unless deleted_tables[conn].include? table
         
     | 
| 
      
 546 
     | 
    
         
            +
                              conn.delete "DELETE FROM #{conn.quote_table_name(table)}", "Fixture Delete"
         
     | 
| 
      
 547 
     | 
    
         
            +
                            end
         
     | 
| 
      
 548 
     | 
    
         
            +
                            deleted_tables[conn] << table
         
     | 
| 
       530 
549 
     | 
    
         
             
                          end
         
     | 
| 
       531 
550 
     | 
    
         | 
| 
       532 
551 
     | 
    
         
             
                          table_rows.each do |fixture_set_name, rows|
         
     | 
| 
         @@ -573,21 +592,16 @@ module ActiveRecord 
     | 
|
| 
       573 
592 
     | 
    
         
             
                  @name     = name
         
     | 
| 
       574 
593 
     | 
    
         
             
                  @path     = path
         
     | 
| 
       575 
594 
     | 
    
         
             
                  @config   = config
         
     | 
| 
       576 
     | 
    
         
            -
                  @model_class = nil
         
     | 
| 
       577 
595 
     | 
    
         | 
| 
       578 
     | 
    
         
            -
                   
     | 
| 
       579 
     | 
    
         
            -
             
     | 
| 
       580 
     | 
    
         
            -
                   
     | 
| 
       581 
     | 
    
         
            -
                    @model_class = class_name.safe_constantize if class_name
         
     | 
| 
       582 
     | 
    
         
            -
                  end
         
     | 
| 
      
 596 
     | 
    
         
            +
                  self.model_class = class_name
         
     | 
| 
      
 597 
     | 
    
         
            +
             
     | 
| 
      
 598 
     | 
    
         
            +
                  @fixtures = read_fixture_files(path)
         
     | 
| 
       583 
599 
     | 
    
         | 
| 
       584 
600 
     | 
    
         
             
                  @connection  = connection
         
     | 
| 
       585 
601 
     | 
    
         | 
| 
       586 
602 
     | 
    
         
             
                  @table_name = ( model_class.respond_to?(:table_name) ?
         
     | 
| 
       587 
603 
     | 
    
         
             
                                  model_class.table_name :
         
     | 
| 
       588 
604 
     | 
    
         
             
                                  self.class.default_fixture_table_name(name, config) )
         
     | 
| 
       589 
     | 
    
         
            -
             
     | 
| 
       590 
     | 
    
         
            -
                  @fixtures = read_fixture_files path, @model_class
         
     | 
| 
       591 
605 
     | 
    
         
             
                end
         
     | 
| 
       592 
606 
     | 
    
         | 
| 
       593 
607 
     | 
    
         
             
                def [](x)
         
     | 
| 
         @@ -610,7 +624,6 @@ module ActiveRecord 
     | 
|
| 
       610 
624 
     | 
    
         
             
                # a list of rows to insert to that table.
         
     | 
| 
       611 
625 
     | 
    
         
             
                def table_rows
         
     | 
| 
       612 
626 
     | 
    
         
             
                  now = config.default_timezone == :utc ? Time.now.utc : Time.now
         
     | 
| 
       613 
     | 
    
         
            -
                  now = now.to_s(:db)
         
     | 
| 
       614 
627 
     | 
    
         | 
| 
       615 
628 
     | 
    
         
             
                  # allow a standard key to be used for doing defaults in YAML
         
     | 
| 
       616 
629 
     | 
    
         
             
                  fixtures.delete('DEFAULTS')
         
     | 
| 
         @@ -639,6 +652,13 @@ module ActiveRecord 
     | 
|
| 
       639 
652 
     | 
    
         
             
                        row[primary_key_name] = ActiveRecord::FixtureSet.identify(label, primary_key_type)
         
     | 
| 
       640 
653 
     | 
    
         
             
                      end
         
     | 
| 
       641 
654 
     | 
    
         | 
| 
      
 655 
     | 
    
         
            +
                      # Resolve enums
         
     | 
| 
      
 656 
     | 
    
         
            +
                      model_class.defined_enums.each do |name, values|
         
     | 
| 
      
 657 
     | 
    
         
            +
                        if row.include?(name)
         
     | 
| 
      
 658 
     | 
    
         
            +
                          row[name] = values.fetch(row[name], row[name])
         
     | 
| 
      
 659 
     | 
    
         
            +
                        end
         
     | 
| 
      
 660 
     | 
    
         
            +
                      end
         
     | 
| 
      
 661 
     | 
    
         
            +
             
     | 
| 
       642 
662 
     | 
    
         
             
                      # If STI is used, find the correct subclass for association reflection
         
     | 
| 
       643 
663 
     | 
    
         
             
                      reflection_class =
         
     | 
| 
       644 
664 
     | 
    
         
             
                        if row.include?(inheritance_column_name)
         
     | 
| 
         @@ -659,7 +679,7 @@ module ActiveRecord 
     | 
|
| 
       659 
679 
     | 
    
         
             
                              row[association.foreign_type] = $1
         
     | 
| 
       660 
680 
     | 
    
         
             
                            end
         
     | 
| 
       661 
681 
     | 
    
         | 
| 
       662 
     | 
    
         
            -
                            fk_type = reflection_class. 
     | 
| 
      
 682 
     | 
    
         
            +
                            fk_type = reflection_class.type_for_attribute(fk_name).type
         
     | 
| 
       663 
683 
     | 
    
         
             
                            row[fk_name] = ActiveRecord::FixtureSet.identify(value, fk_type)
         
     | 
| 
       664 
684 
     | 
    
         
             
                          end
         
     | 
| 
       665 
685 
     | 
    
         
             
                        when :has_many
         
     | 
| 
         @@ -689,7 +709,7 @@ module ActiveRecord 
     | 
|
| 
       689 
709 
     | 
    
         
             
                  end
         
     | 
| 
       690 
710 
     | 
    
         | 
| 
       691 
711 
     | 
    
         
             
                  def primary_key_type
         
     | 
| 
       692 
     | 
    
         
            -
                    @association.klass. 
     | 
| 
      
 712 
     | 
    
         
            +
                    @association.klass.type_for_attribute(@association.klass.primary_key).type
         
     | 
| 
       693 
713 
     | 
    
         
             
                  end
         
     | 
| 
       694 
714 
     | 
    
         
             
                end
         
     | 
| 
       695 
715 
     | 
    
         | 
| 
         @@ -713,7 +733,7 @@ module ActiveRecord 
     | 
|
| 
       713 
733 
     | 
    
         
             
                  end
         
     | 
| 
       714 
734 
     | 
    
         | 
| 
       715 
735 
     | 
    
         
             
                  def primary_key_type
         
     | 
| 
       716 
     | 
    
         
            -
                    @primary_key_type ||= model_class && model_class. 
     | 
| 
      
 736 
     | 
    
         
            +
                    @primary_key_type ||= model_class && model_class.type_for_attribute(model_class.primary_key).type
         
     | 
| 
       717 
737 
     | 
    
         
             
                  end
         
     | 
| 
       718 
738 
     | 
    
         | 
| 
       719 
739 
     | 
    
         
             
                  def add_join_records(rows, row, association)
         
     | 
| 
         @@ -747,16 +767,28 @@ module ActiveRecord 
     | 
|
| 
       747 
767 
     | 
    
         
             
                  end
         
     | 
| 
       748 
768 
     | 
    
         | 
| 
       749 
769 
     | 
    
         
             
                  def column_names
         
     | 
| 
       750 
     | 
    
         
            -
                    @column_names ||= @connection.columns(@table_name).collect 
     | 
| 
      
 770 
     | 
    
         
            +
                    @column_names ||= @connection.columns(@table_name).collect(&:name)
         
     | 
| 
      
 771 
     | 
    
         
            +
                  end
         
     | 
| 
      
 772 
     | 
    
         
            +
             
     | 
| 
      
 773 
     | 
    
         
            +
                  def model_class=(class_name)
         
     | 
| 
      
 774 
     | 
    
         
            +
                    if class_name.is_a?(Class) # TODO: Should be an AR::Base type class, or any?
         
     | 
| 
      
 775 
     | 
    
         
            +
                      @model_class = class_name
         
     | 
| 
      
 776 
     | 
    
         
            +
                    else
         
     | 
| 
      
 777 
     | 
    
         
            +
                      @model_class = class_name.safe_constantize if class_name
         
     | 
| 
      
 778 
     | 
    
         
            +
                    end
         
     | 
| 
       751 
779 
     | 
    
         
             
                  end
         
     | 
| 
       752 
780 
     | 
    
         | 
| 
       753 
     | 
    
         
            -
                   
     | 
| 
      
 781 
     | 
    
         
            +
                  # Loads the fixtures from the YAML file at +path+.
         
     | 
| 
      
 782 
     | 
    
         
            +
                  # If the file sets the +model_class+ and current instance value is not set,
         
     | 
| 
      
 783 
     | 
    
         
            +
                  # it uses the file value.
         
     | 
| 
      
 784 
     | 
    
         
            +
                  def read_fixture_files(path)
         
     | 
| 
       754 
785 
     | 
    
         
             
                    yaml_files = Dir["#{path}/{**,*}/*.yml"].select { |f|
         
     | 
| 
       755 
786 
     | 
    
         
             
                      ::File.file?(f)
         
     | 
| 
       756 
787 
     | 
    
         
             
                    } + [yaml_file_path(path)]
         
     | 
| 
       757 
788 
     | 
    
         | 
| 
       758 
789 
     | 
    
         
             
                    yaml_files.each_with_object({}) do |file, fixtures|
         
     | 
| 
       759 
790 
     | 
    
         
             
                      FixtureSet::File.open(file) do |fh|
         
     | 
| 
      
 791 
     | 
    
         
            +
                        self.model_class ||= fh.model_class if fh.model_class
         
     | 
| 
       760 
792 
     | 
    
         
             
                        fh.each do |fixture_name, row|
         
     | 
| 
       761 
793 
     | 
    
         
             
                          fixtures[fixture_name] = ActiveRecord::Fixture.new(row, model_class)
         
     | 
| 
       762 
794 
     | 
    
         
             
                        end
         
     | 
| 
         @@ -770,12 +802,6 @@ module ActiveRecord 
     | 
|
| 
       770 
802 
     | 
    
         | 
| 
       771 
803 
     | 
    
         
             
              end
         
     | 
| 
       772 
804 
     | 
    
         | 
| 
       773 
     | 
    
         
            -
              #--
         
     | 
| 
       774 
     | 
    
         
            -
              # Deprecate 'Fixtures' in favor of 'FixtureSet'.
         
     | 
| 
       775 
     | 
    
         
            -
              #++
         
     | 
| 
       776 
     | 
    
         
            -
              # :nodoc:
         
     | 
| 
       777 
     | 
    
         
            -
              Fixtures = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('ActiveRecord::Fixtures', 'ActiveRecord::FixtureSet')
         
     | 
| 
       778 
     | 
    
         
            -
             
     | 
| 
       779 
805 
     | 
    
         
             
              class Fixture #:nodoc:
         
     | 
| 
       780 
806 
     | 
    
         
             
                include Enumerable
         
     | 
| 
       781 
807 
     | 
    
         | 
| 
         @@ -822,12 +848,12 @@ module ActiveRecord 
     | 
|
| 
       822 
848 
     | 
    
         
             
              module TestFixtures
         
     | 
| 
       823 
849 
     | 
    
         
             
                extend ActiveSupport::Concern
         
     | 
| 
       824 
850 
     | 
    
         | 
| 
       825 
     | 
    
         
            -
                def before_setup
         
     | 
| 
      
 851 
     | 
    
         
            +
                def before_setup # :nodoc:
         
     | 
| 
       826 
852 
     | 
    
         
             
                  setup_fixtures
         
     | 
| 
       827 
853 
     | 
    
         
             
                  super
         
     | 
| 
       828 
854 
     | 
    
         
             
                end
         
     | 
| 
       829 
855 
     | 
    
         | 
| 
       830 
     | 
    
         
            -
                def after_teardown
         
     | 
| 
      
 856 
     | 
    
         
            +
                def after_teardown # :nodoc:
         
     | 
| 
       831 
857 
     | 
    
         
             
                  super
         
     | 
| 
       832 
858 
     | 
    
         
             
                  teardown_fixtures
         
     | 
| 
       833 
859 
     | 
    
         
             
                end
         
     | 
| 
         @@ -836,19 +862,29 @@ module ActiveRecord 
     | 
|
| 
       836 
862 
     | 
    
         
             
                  class_attribute :fixture_path, :instance_writer => false
         
     | 
| 
       837 
863 
     | 
    
         
             
                  class_attribute :fixture_table_names
         
     | 
| 
       838 
864 
     | 
    
         
             
                  class_attribute :fixture_class_names
         
     | 
| 
      
 865 
     | 
    
         
            +
                  class_attribute :use_transactional_tests
         
     | 
| 
       839 
866 
     | 
    
         
             
                  class_attribute :use_transactional_fixtures
         
     | 
| 
       840 
867 
     | 
    
         
             
                  class_attribute :use_instantiated_fixtures # true, false, or :no_instances
         
     | 
| 
       841 
868 
     | 
    
         
             
                  class_attribute :pre_loaded_fixtures
         
     | 
| 
       842 
869 
     | 
    
         
             
                  class_attribute :config
         
     | 
| 
       843 
870 
     | 
    
         | 
| 
      
 871 
     | 
    
         
            +
                  singleton_class.deprecate 'use_transactional_fixtures=' => 'use use_transactional_tests= instead'
         
     | 
| 
      
 872 
     | 
    
         
            +
             
     | 
| 
       844 
873 
     | 
    
         
             
                  self.fixture_table_names = []
         
     | 
| 
       845 
     | 
    
         
            -
                  self.use_transactional_fixtures = true
         
     | 
| 
       846 
874 
     | 
    
         
             
                  self.use_instantiated_fixtures = false
         
     | 
| 
       847 
875 
     | 
    
         
             
                  self.pre_loaded_fixtures = false
         
     | 
| 
       848 
876 
     | 
    
         
             
                  self.config = ActiveRecord::Base
         
     | 
| 
       849 
877 
     | 
    
         | 
| 
       850 
     | 
    
         
            -
                  self.fixture_class_names =  
     | 
| 
       851 
     | 
    
         
            -
             
     | 
| 
      
 878 
     | 
    
         
            +
                  self.fixture_class_names = {}
         
     | 
| 
      
 879 
     | 
    
         
            +
             
     | 
| 
      
 880 
     | 
    
         
            +
                  silence_warnings do
         
     | 
| 
      
 881 
     | 
    
         
            +
                    define_singleton_method :use_transactional_tests do
         
     | 
| 
      
 882 
     | 
    
         
            +
                      if use_transactional_fixtures.nil?
         
     | 
| 
      
 883 
     | 
    
         
            +
                        true
         
     | 
| 
      
 884 
     | 
    
         
            +
                      else
         
     | 
| 
      
 885 
     | 
    
         
            +
                        use_transactional_fixtures
         
     | 
| 
      
 886 
     | 
    
         
            +
                      end
         
     | 
| 
      
 887 
     | 
    
         
            +
                    end
         
     | 
| 
       852 
888 
     | 
    
         
             
                  end
         
     | 
| 
       853 
889 
     | 
    
         
             
                end
         
     | 
| 
       854 
890 
     | 
    
         | 
| 
         @@ -870,7 +906,7 @@ module ActiveRecord 
     | 
|
| 
       870 
906 
     | 
    
         
             
                      fixture_set_names = Dir["#{fixture_path}/{**,*}/*.{yml}"]
         
     | 
| 
       871 
907 
     | 
    
         
             
                      fixture_set_names.map! { |f| f[(fixture_path.to_s.size + 1)..-5] }
         
     | 
| 
       872 
908 
     | 
    
         
             
                    else
         
     | 
| 
       873 
     | 
    
         
            -
                      fixture_set_names = fixture_set_names.flatten.map 
     | 
| 
      
 909 
     | 
    
         
            +
                      fixture_set_names = fixture_set_names.flatten.map(&:to_s)
         
     | 
| 
       874 
910 
     | 
    
         
             
                    end
         
     | 
| 
       875 
911 
     | 
    
         | 
| 
       876 
912 
     | 
    
         
             
                    self.fixture_table_names |= fixture_set_names
         
     | 
| 
         @@ -890,7 +926,7 @@ module ActiveRecord 
     | 
|
| 
       890 
926 
     | 
    
         
             
                          @fixture_cache[fs_name] ||= {}
         
     | 
| 
       891 
927 
     | 
    
         | 
| 
       892 
928 
     | 
    
         
             
                          instances = fixture_names.map do |f_name|
         
     | 
| 
       893 
     | 
    
         
            -
                            f_name = f_name.to_s
         
     | 
| 
      
 929 
     | 
    
         
            +
                            f_name = f_name.to_s if f_name.is_a?(Symbol)
         
     | 
| 
       894 
930 
     | 
    
         
             
                            @fixture_cache[fs_name].delete(f_name) if force_reload
         
     | 
| 
       895 
931 
     | 
    
         | 
| 
       896 
932 
     | 
    
         
             
                            if @loaded_fixtures[fs_name][f_name]
         
     | 
| 
         @@ -910,7 +946,7 @@ module ActiveRecord 
     | 
|
| 
       910 
946 
     | 
    
         | 
| 
       911 
947 
     | 
    
         
             
                  def uses_transaction(*methods)
         
     | 
| 
       912 
948 
     | 
    
         
             
                    @uses_transaction = [] unless defined?(@uses_transaction)
         
     | 
| 
       913 
     | 
    
         
            -
                    @uses_transaction.concat methods.map 
     | 
| 
      
 949 
     | 
    
         
            +
                    @uses_transaction.concat methods.map(&:to_s)
         
     | 
| 
       914 
950 
     | 
    
         
             
                  end
         
     | 
| 
       915 
951 
     | 
    
         | 
| 
       916 
952 
     | 
    
         
             
                  def uses_transaction?(method)
         
     | 
| 
         @@ -920,13 +956,13 @@ module ActiveRecord 
     | 
|
| 
       920 
956 
     | 
    
         
             
                end
         
     | 
| 
       921 
957 
     | 
    
         | 
| 
       922 
958 
     | 
    
         
             
                def run_in_transaction?
         
     | 
| 
       923 
     | 
    
         
            -
                   
     | 
| 
      
 959 
     | 
    
         
            +
                  use_transactional_tests &&
         
     | 
| 
       924 
960 
     | 
    
         
             
                    !self.class.uses_transaction?(method_name)
         
     | 
| 
       925 
961 
     | 
    
         
             
                end
         
     | 
| 
       926 
962 
     | 
    
         | 
| 
       927 
963 
     | 
    
         
             
                def setup_fixtures(config = ActiveRecord::Base)
         
     | 
| 
       928 
     | 
    
         
            -
                  if pre_loaded_fixtures && ! 
     | 
| 
       929 
     | 
    
         
            -
                    raise RuntimeError, 'pre_loaded_fixtures requires  
     | 
| 
      
 964 
     | 
    
         
            +
                  if pre_loaded_fixtures && !use_transactional_tests
         
     | 
| 
      
 965 
     | 
    
         
            +
                    raise RuntimeError, 'pre_loaded_fixtures requires use_transactional_tests'
         
     | 
| 
       930 
966 
     | 
    
         
             
                  end
         
     | 
| 
       931 
967 
     | 
    
         | 
| 
       932 
968 
     | 
    
         
             
                  @fixture_cache = {}
         
     |