1. 23 1月, 2014 1 次提交
  2. 19 1月, 2014 1 次提交
    • G
      Restore ActiveRecord states after a rollback for models w/o callbacks · 7386ffc7
      Godfrey Chan 提交于
      This fixes a regression (#13744) that was caused by 67d8bb96.
      
      In 67d8bb96, we introduced lazy rollback for records, such that the
      record's internal states and attributes are not restored immediately
      after a transaction rollback, but deferred until they are first
      accessed.
      
      This optimization is only performed when the model does not have any
      transactional callbacks (e.g. `after_commit` and `after_create`).
      
      Unfortunately, the models used to test the affected codepaths all
      comes with some sort of transactional callbacks. Therefore this
      codepath remains largely untested until now and as a result there are
      a few issues in the implementation that remains hidden until now.
      
      First, the `sync_with_transaction_state` (or more accurately,
      `update_attributes_from_transaction_state`) would perform the
      synchronization prematurely before a transaction is finalized (i.e.
      comitted or rolled back). As a result, when the actuall rollback
      happens, the record will incorrectly assumes that its internal states
      match the transaction state, and neglect to perform the restore.
      
      Second, `update_attributes_from_transaction_state` calls `committed!`
      in some cases. This in turns checks for the `destroyed?` state which
      also requires synchronization with the transaction stae, which causes
      an infnite recurrsion.
      
      This fix works by deferring the synchronization until the transaction
      has been finalized (addressing the first point), and also unrolled
      the `committed!` and `rolledback!` logic in-place (addressing the
      second point).
      
      It should be noted that the primary purpose of the `committed!` and
      `rolledback!` methods are to trigger the relevant transactional
      callbacks. Since this code path is only entered when there are no
      transactional callbacks on the model, this shouldn't be necessary. By
      unrolling the method calls, the intention here (to restore the states
      when necessary) becomes more clear.
      7386ffc7
  3. 10 1月, 2014 1 次提交
    • S
      Ensure Active Record connection consistency · 6cc03675
      schneems 提交于
      Currently Active Record can be configured via the environment variable `DATABASE_URL` or by manually injecting a hash of values which is what Rails does, reading in `database.yml` and setting Active Record appropriately. Active Record expects to be able to use `DATABASE_URL` without the use of Rails, and we cannot rip out this functionality without deprecating. This presents a problem though when both config is set, and a `DATABASE_URL` is present. Currently the `DATABASE_URL` should "win" and none of the values in `database.yml` are used. This is somewhat unexpected to me if I were to set values such as `pool` in the `production:` group of `database.yml` they are ignored.
      
      There are many ways that active record initiates a connection today:
      
      - Stand Alone (without rails)
        - `rake db:<tasks>`
        - ActiveRecord.establish_connection
       
      - With Rails
        - `rake db:<tasks>`
        - `rails <server> | <console>`
        - `rails dbconsole`
      
      
      We should make all of these behave exactly the same way. The best way to do this is to put all of this logic in one place so it is guaranteed to be used.
      
      Here is my prosed matrix of how this behavior should work:
      
      ```
      No database.yml
      No DATABASE_URL
      => Error
      ```
      
      ```
      database.yml present
      No DATABASE_URL
      => Use database.yml configuration
      ```
      
      ```
      No database.yml
      DATABASE_URL present
      => use DATABASE_URL configuration
      ```
      
      ```
      database.yml present
      DATABASE_URL present
      => Merged into `url` sub key. If both specify `url` sub key, the `database.yml` `url`
         sub key "wins". If other paramaters `adapter` or `database` are specified in YAML,
         they are discarded as the `url` sub key "wins".
      ```
      
      ### Implementation
      
      Current implementation uses `ActiveRecord::Base.configurations` to resolve and merge all connection information before returning. This is achieved through a utility class: `ActiveRecord::ConnectionHandling::MergeAndResolveDefaultUrlConfig`.
      
      To understand the exact behavior of this class, it is best to review the behavior in activerecord/test/cases/connection_adapters/connection_handler_test.rb though it should match the above proposal.
      6cc03675
  4. 02 1月, 2014 1 次提交
    • J
      Automatically maintain test database schema · ff7ab3bc
      Jon Leighton 提交于
      * Move check from generated helper to test_help.rb, so that all
        applications can benefit
      * Rather than just raising when the test schema has pending migrations,
        try to load in the schema and only raise if there are pending
        migrations afterwards
      * Opt out of the check by setting
        config.active_record.maintain_test_schema = false
      * Deprecate db:test:* tasks. The test helper is now fully responsible
        for maintaining the test schema, so we don't need rake tasks for this.
        This is also a speed improvement since we're no longer reloading the
        test database on every call to "rake test".
      ff7ab3bc
  5. 27 11月, 2013 1 次提交
  6. 10 11月, 2013 1 次提交
  7. 03 11月, 2013 1 次提交
  8. 28 9月, 2013 1 次提交
  9. 23 9月, 2013 1 次提交
  10. 22 9月, 2013 1 次提交
  11. 19 9月, 2013 3 次提交
  12. 11 9月, 2013 1 次提交
  13. 02 8月, 2013 2 次提交
  14. 24 7月, 2013 1 次提交
  15. 05 7月, 2013 2 次提交
  16. 03 7月, 2013 2 次提交
  17. 02 7月, 2013 1 次提交
  18. 29 6月, 2013 1 次提交
  19. 28 6月, 2013 1 次提交
  20. 20 6月, 2013 1 次提交
  21. 28 4月, 2013 1 次提交
  22. 16 4月, 2013 1 次提交
    • C
      Fix freeze applying to cloned objects · d5867a01
      Caleb Thompson 提交于
      Previously, freezing a cloned ActiveRecord object froze the original
      too. By cloning `@attributes` before freezing, we prevent cloned objects
      (which in Ruby share state of ivars) from being effected by `#freeze`.
      
      Resolves issue #4936, which has further information on this issue, as
      well as steps to reproduce.
      
      * Add a test case for `#freeze` not causing `cloned.frozen?` to be true.
      * Clone @attributes before freezing in `ActiveRecord::Core`, then
        reassign the cloned, frozen hash to the frozen model's `@attributes`
        ivar.
      
      /cc @steveklabnik
      d5867a01
  23. 13 4月, 2013 1 次提交
    • X
      removes calls to AR::Runtime.instance · 11c69738
      Xavier Noria 提交于
      Registries have class-level accessors to write clean code, let's
      use them. This makes style uniform also with existing usage in
      ScopeRegistry and InstrumentationRegistry.
      
      If performance of the method_missing callback was ever considered to
      be a concern, then we should stop using it altogether and probably
      remove the callback. But while we have the feature we should use it.
      11c69738
  24. 10 4月, 2013 1 次提交
  25. 06 4月, 2013 1 次提交
  26. 28 3月, 2013 1 次提交
  27. 27 3月, 2013 1 次提交
  28. 21 3月, 2013 1 次提交
  29. 19 3月, 2013 1 次提交
    • A
      Fix ActiveRecord locking column defaults not getting persisted · a240e526
      Aaron Pfeifer 提交于
      When partial inserts are enabled, overridden db defaults are ignored. This
      results in locking columns having a nil value for new records if the db default
      is null. This happens because the list of changed attributes for new records is
      always assumed to be empty.
      
      Solution: When a new record's default attributes are set, also initialize the
      list of changed attributes by comparing current values against what's stored as
      the column defaults in the database.
      a240e526
  30. 15 3月, 2013 1 次提交
  31. 10 3月, 2013 1 次提交
  32. 25 2月, 2013 1 次提交
  33. 20 2月, 2013 1 次提交
  34. 22 1月, 2013 1 次提交
  35. 21 1月, 2013 1 次提交