<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>vendor/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb</filename>
    </added>
    <added>
      <filename>vendor/activerecord/lib/active_record/dynamic_finder_match.rb</filename>
    </added>
    <added>
      <filename>vendor/activerecord/lib/active_record/i18n_interpolation_deprecation.rb</filename>
    </added>
    <added>
      <filename>vendor/activerecord/lib/active_record/locale/en.yml</filename>
    </added>
    <added>
      <filename>vendor/activerecord/test/cases/callbacks_observers_test.rb</filename>
    </added>
    <added>
      <filename>vendor/activerecord/test/cases/i18n_test.rb</filename>
    </added>
    <added>
      <filename>vendor/activerecord/test/cases/pooled_connections_test.rb</filename>
    </added>
    <added>
      <filename>vendor/activerecord/test/cases/reload_models_test.rb</filename>
    </added>
    <added>
      <filename>vendor/activerecord/test/cases/sanitize_test.rb</filename>
    </added>
    <added>
      <filename>vendor/activerecord/test/cases/validations_i18n_test.rb</filename>
    </added>
    <added>
      <filename>vendor/activerecord/test/fixtures/organizations.yml</filename>
    </added>
    <added>
      <filename>vendor/activerecord/test/migrations/broken/100_migration_that_raises_exception.rb</filename>
    </added>
    <added>
      <filename>vendor/activerecord/test/models/member_detail.rb</filename>
    </added>
    <added>
      <filename>vendor/activerecord/test/models/organization.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/cache/synchronized_memory_store.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/core_ext/file/atomic.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/core_ext/float/time.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/core_ext/hash/deep_merge.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/core_ext/integer/time.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/core_ext/module/synchronization.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/core_ext/object/metaclass.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/core_ext/string/behavior.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/core_ext/string/multibyte.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/locale/en.yml</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/memoizable.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/multibyte/exceptions.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/multibyte/unicode_database.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/rescuable.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/secure_random.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/testing/core_ext/test.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/testing/core_ext/test/unit/assertions.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/testing/performance.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n/backend/simple.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n/exceptions.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/memcache-client-1.5.1/memcache.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/data_timezone.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/data_timezone_info.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Algiers.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Cairo.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Casablanca.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Harare.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Johannesburg.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Monrovia.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Nairobi.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Argentina/Buenos_Aires.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Argentina/San_Juan.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Bogota.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Caracas.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Chicago.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Chihuahua.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Denver.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Godthab.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Guatemala.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Halifax.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Indiana/Indianapolis.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Juneau.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/La_Paz.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Lima.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Los_Angeles.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Mazatlan.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Mexico_City.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Monterrey.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/New_York.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Phoenix.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Regina.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Santiago.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Sao_Paulo.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/St_Johns.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Tijuana.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Almaty.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Baghdad.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Baku.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Bangkok.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Chongqing.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Colombo.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Dhaka.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Hong_Kong.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Irkutsk.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Jakarta.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Jerusalem.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kabul.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kamchatka.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Karachi.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Katmandu.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kolkata.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Krasnoyarsk.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kuala_Lumpur.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kuwait.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Magadan.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Muscat.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Novosibirsk.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Rangoon.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Riyadh.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Seoul.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Shanghai.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Singapore.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Taipei.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Tashkent.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Tbilisi.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Tehran.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Tokyo.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Ulaanbaatar.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Urumqi.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Vladivostok.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Yakutsk.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Yekaterinburg.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Yerevan.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Atlantic/Azores.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Atlantic/Cape_Verde.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Atlantic/South_Georgia.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Adelaide.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Brisbane.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Darwin.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Hobart.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Melbourne.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Perth.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Sydney.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Etc/UTC.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Amsterdam.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Athens.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Belgrade.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Berlin.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Bratislava.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Brussels.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Bucharest.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Budapest.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Copenhagen.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Dublin.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Helsinki.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Istanbul.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Kiev.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Lisbon.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Ljubljana.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/London.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Madrid.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Minsk.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Moscow.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Paris.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Prague.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Riga.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Rome.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Sarajevo.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Skopje.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Sofia.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Stockholm.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Tallinn.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Vienna.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Vilnius.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Warsaw.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Zagreb.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Auckland.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Fiji.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Guam.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Honolulu.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Majuro.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Midway.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Noumea.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Pago_Pago.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Port_Moresby.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Tongatapu.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/info_timezone.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/linked_timezone.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/linked_timezone_info.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/offset_rationals.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/ruby_core_support.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/time_or_datetime.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_definition.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_info.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_offset_info.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_period.rb</filename>
    </added>
    <added>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_transition_info.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -1,16 +1,49 @@
-*2.1.1 (September 4th, 2008)*
+*2.2 (November 21st, 2008)*
 
-* Set config.active_record.timestamped_migrations = false to have migrations with numeric prefix instead of UTC timestamp. #446. [Andrew Stone, Nik Wakelin]
+* Ensure indices don't flip order in schema.rb #1266 [Jordi Bunster]
 
-* Fixed that create database statements would always include &quot;DEFAULT NULL&quot; (Nick Sieger) [#334]
+* Fixed that serialized strings should never be type-casted (i.e. turning &quot;Yes&quot; to a boolean) #857 [Andreas Korth]
+
+* Skip collection ids reader optimization if using :finder_sql [Jeremy Kemper]
+
+* Add Model#delete instance method, similar to Model.delete class method. #1086 [Hongli Lai]
+
+* MySQL: cope with quirky default values for not-null text columns.  #1043 [Frederick Cheung]
+
+* Multiparameter attributes skip time zone conversion for time-only columns [#1030 state:resolved] [Geoff Buesing]
+
+* Base.skip_time_zone_conversion_for_attributes uses class_inheritable_accessor, so that subclasses don't overwrite Base [#346 state:resolved] [miloops]
+
+* Added find_last_by dynamic finder #762 [miloops]
+
+* Internal API: configurable association options and build_association method for reflections so plugins may extend and override.  #985 [Hongli Lai]
+
+* Changed benchmarks to be reported in milliseconds [DHH]
+
+* Connection pooling.  #936 [Nick Sieger]
+
+* Merge scoped :joins together instead of overwriting them. May expose scoping bugs in your code!  #501 [Andrew White]
+
+* before_save, before_validation and before_destroy callbacks that return false will now ROLLBACK the transaction.  Previously this would have been committed before the processing was aborted. #891 [Xavier Noria]
+
+* Transactional migrations for databases which support them.  #834 [divoxx, Adam Wiggins, Tarmo T&#228;nav]
+
+* Set config.active_record.timestamped_migrations = false to have migrations with numeric prefix instead of UTC timestamp. #446. [Andrew Stone, Nik Wakelin]
 
 * change_column_default preserves the not-null constraint.  #617 [Tarmo T&#228;nav]
 
+* Fixed that create database statements would always include &quot;DEFAULT NULL&quot; (Nick Sieger) [#334]
+
 * Add :tokenizer option to validates_length_of to specify how to split up the attribute string. #507. [David Lowenfels] Example :
 
   # Ensure essay contains at least 100 words.
   validates_length_of :essay, :minimum =&gt; 100, :too_short =&gt; &quot;Your essay must be at least %d words.&quot;), :tokenizer =&gt; lambda {|str| str.scan(/\w+/) }
 
+* Allow conditions on multiple tables to be specified using hash. [Pratik Naik]. Example:
+
+  User.all :joins =&gt; :items, :conditions =&gt; { :age =&gt; 10, :items =&gt; { :color =&gt; 'black' } }
+  Item.first :conditions =&gt; { :items =&gt; { :color =&gt; 'red' } }
+
 * Always treat integer :limit as byte length.  #420 [Tarmo T&#228;nav]
 
 * Partial updates don't update lock_version if nothing changed.  #426 [Daniel Morrison]</diff>
      <filename>vendor/activerecord/CHANGELOG</filename>
    </modified>
    <modified>
      <filename>vendor/activerecord/README</filename>
    </modified>
    <modified>
      <diff>@@ -5,7 +5,6 @@ require 'rake/rdoctask'
 require 'rake/packagetask'
 require 'rake/gempackagetask'
 require 'rake/contrib/sshpublisher'
-require 'rake/contrib/rubyforgepublisher'
 
 require File.join(File.dirname(__FILE__), 'lib', 'active_record', 'version')
 require File.expand_path(File.dirname(__FILE__)) + &quot;/test/config&quot;
@@ -31,7 +30,7 @@ desc 'Run mysql, sqlite, and postgresql tests by default'
 task :default =&gt; :test
 
 desc 'Run mysql, sqlite, and postgresql tests'
-task :test =&gt; %w(test_mysql test_sqlite test_sqlite3 test_postgresql)
+task :test =&gt; %w(test_mysql test_sqlite3 test_postgresql)
 
 for adapter in %w( mysql postgresql sqlite sqlite3 firebird db2 oracle sybase openbase frontbase )
   Rake::TestTask.new(&quot;test_#{adapter}&quot;) { |t|
@@ -172,7 +171,7 @@ spec = Gem::Specification.new do |s|
     s.files = s.files + Dir.glob( &quot;#{dir}/**/*&quot; ).delete_if { |item| item.include?( &quot;\.svn&quot; ) }
   end
 
-  s.add_dependency('activesupport', '= 2.1.1' + PKG_BUILD)
+  s.add_dependency('activesupport', '= 2.2.2' + PKG_BUILD)
 
   s.files.delete FIXTURES_ROOT + &quot;/fixture_database.sqlite&quot;
   s.files.delete FIXTURES_ROOT + &quot;/fixture_database_2.sqlite&quot;
@@ -226,8 +225,8 @@ end
 
 desc &quot;Publish the beta gem&quot;
 task :pgem =&gt; [:package] do
-  Rake::SshFilePublisher.new(&quot;david@greed.loudthinking.com&quot;, &quot;/u/sites/gems/gems&quot;, &quot;pkg&quot;, &quot;#{PKG_FILE_NAME}.gem&quot;).upload
-  `ssh david@greed.loudthinking.com '/u/sites/gems/gemupdate.sh'`
+  Rake::SshFilePublisher.new(&quot;gems.rubyonrails.org&quot;, &quot;/u/sites/gems/gems&quot;, &quot;pkg&quot;, &quot;#{PKG_FILE_NAME}.gem&quot;).upload
+  `ssh gems.rubyonrails.org '/u/sites/gems/gemupdate.sh'`
 end
 
 desc &quot;Publish the API documentation&quot;</diff>
      <filename>vendor/activerecord/Rakefile</filename>
    </modified>
    <modified>
      <diff>@@ -21,17 +21,14 @@
 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #++
 
-$:.unshift(File.dirname(__FILE__)) unless
-  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
-
-active_support_path = File.dirname(__FILE__) + &quot;/../../activesupport/lib&quot;
-if File.exist?(active_support_path)
-  $:.unshift active_support_path
-  require 'active_support'
-else
-  require 'rubygems'
-  gem 'activesupport'
+begin
   require 'active_support'
+rescue LoadError
+  activesupport_path = &quot;#{File.dirname(__FILE__)}/../../activesupport/lib&quot;
+  if File.directory?(activesupport_path)
+    $:.unshift activesupport_path
+    require 'active_support'
+  end
 end
 
 require 'active_record/base'
@@ -54,6 +51,7 @@ require 'active_record/calculations'
 require 'active_record/serialization'
 require 'active_record/attribute_methods'
 require 'active_record/dirty'
+require 'active_record/dynamic_finder_match'
 
 ActiveRecord::Base.class_eval do
   extend ActiveRecord::QueryCache
@@ -78,3 +76,6 @@ end
 require 'active_record/connection_adapters/abstract_adapter'
 
 require 'active_record/schema_dumper'
+
+require 'active_record/i18n_interpolation_deprecation'
+I18n.load_path &lt;&lt; File.dirname(__FILE__) + '/active_record/locale/en.yml'</diff>
      <filename>vendor/activerecord/lib/active_record.rb</filename>
    </modified>
    <modified>
      <diff>@@ -10,10 +10,10 @@ module ActiveRecord
       end unless self.new_record?
     end
 
-    # Active Record implements aggregation through a macro-like class method called +composed_of+ for representing attributes 
+    # Active Record implements aggregation through a macro-like class method called +composed_of+ for representing attributes
     # as value objects. It expresses relationships like &quot;Account [is] composed of Money [among other things]&quot; or &quot;Person [is]
-    # composed of [an] address&quot;. Each call to the macro adds a description of how the value objects are created from the 
-    # attributes of the entity object (when the entity is initialized either as a new object or from finding an existing object) 
+    # composed of [an] address&quot;. Each call to the macro adds a description of how the value objects are created from the
+    # attributes of the entity object (when the entity is initialized either as a new object or from finding an existing object)
     # and how it can be turned back into attributes (when the entity is saved to the database). Example:
     #
     #   class Customer &lt; ActiveRecord::Base
@@ -30,10 +30,10 @@ module ActiveRecord
     #  class Money
     #    include Comparable
     #    attr_reader :amount, :currency
-    #    EXCHANGE_RATES = { &quot;USD_TO_DKK&quot; =&gt; 6 }  
-    # 
-    #    def initialize(amount, currency = &quot;USD&quot;) 
-    #      @amount, @currency = amount, currency 
+    #    EXCHANGE_RATES = { &quot;USD_TO_DKK&quot; =&gt; 6 }
+    #
+    #    def initialize(amount, currency = &quot;USD&quot;)
+    #      @amount, @currency = amount, currency
     #    end
     #
     #    def exchange_to(other_currency)
@@ -56,26 +56,26 @@ module ActiveRecord
     #
     #  class Address
     #    attr_reader :street, :city
-    #    def initialize(street, city) 
-    #      @street, @city = street, city 
+    #    def initialize(street, city)
+    #      @street, @city = street, city
     #    end
     #
-    #    def close_to?(other_address) 
-    #      city == other_address.city 
+    #    def close_to?(other_address)
+    #      city == other_address.city
     #    end
     #
     #    def ==(other_address)
     #      city == other_address.city &amp;&amp; street == other_address.street
     #    end
     #  end
-    #  
+    #
     # Now it's possible to access attributes from the database through the value objects instead. If you choose to name the
     # composition the same as the attribute's name, it will be the only way to access that attribute. That's the case with our
     # +balance+ attribute. You interact with the value objects just like you would any other attribute, though:
     #
     #   customer.balance = Money.new(20)     # sets the Money value object and the attribute
     #   customer.balance                     # =&gt; Money value object
-    #   customer.balance.exchanged_to(&quot;DKK&quot;) # =&gt; Money.new(120, &quot;DKK&quot;)
+    #   customer.balance.exchange_to(&quot;DKK&quot;)  # =&gt; Money.new(120, &quot;DKK&quot;)
     #   customer.balance &gt; Money.new(10)     # =&gt; true
     #   customer.balance == Money.new(20)    # =&gt; true
     #   customer.balance &lt; Money.new(5)      # =&gt; false
@@ -87,8 +87,8 @@ module ActiveRecord
     #   customer.address_city   = &quot;Copenhagen&quot;
     #   customer.address        # =&gt; Address.new(&quot;Hyancintvej&quot;, &quot;Copenhagen&quot;)
     #   customer.address = Address.new(&quot;May Street&quot;, &quot;Chicago&quot;)
-    #   customer.address_street # =&gt; &quot;May Street&quot; 
-    #   customer.address_city   # =&gt; &quot;Chicago&quot; 
+    #   customer.address_street # =&gt; &quot;May Street&quot;
+    #   customer.address_city   # =&gt; &quot;Chicago&quot;
     #
     # == Writing value objects
     #
@@ -99,16 +99,55 @@ module ActiveRecord
     # relational unique identifiers (such as primary keys). Normal ActiveRecord::Base classes are entity objects.
     #
     # It's also important to treat the value objects as immutable. Don't allow the Money object to have its amount changed after
-    # creation. Create a new Money object with the new value instead. This is exemplified by the Money#exchanged_to method that
+    # creation. Create a new Money object with the new value instead. This is exemplified by the Money#exchange_to method that
     # returns a new value object instead of changing its own values. Active Record won't persist value objects that have been
     # changed through means other than the writer method.
     #
-    # The immutable requirement is enforced by Active Record by freezing any object assigned as a value object. Attempting to 
+    # The immutable requirement is enforced by Active Record by freezing any object assigned as a value object. Attempting to
     # change it afterwards will result in a ActiveSupport::FrozenObjectError.
-    # 
+    #
     # Read more about value objects on http://c2.com/cgi/wiki?ValueObject and on the dangers of not keeping value objects
     # immutable on http://c2.com/cgi/wiki?ValueObjectsShouldBeImmutable
     #
+    # == Custom constructors and converters
+    #
+    # By default value objects are initialized by calling the &lt;tt&gt;new&lt;/tt&gt; constructor of the value class passing each of the
+    # mapped attributes, in the order specified by the &lt;tt&gt;:mapping&lt;/tt&gt; option, as arguments. If the value class doesn't support
+    # this convention then +composed_of+ allows a custom constructor to be specified.
+    #
+    # When a new value is assigned to the value object the default assumption is that the new value is an instance of the value
+    # class. Specifying a custom converter allows the new value to be automatically converted to an instance of value class if
+    # necessary.
+    #
+    # For example, the NetworkResource model has +network_address+ and +cidr_range+ attributes that should be aggregated using the
+    # NetAddr::CIDR value class (http://netaddr.rubyforge.org). The constructor for the value class is called +create+ and it
+    # expects a CIDR address string as a parameter. New values can be assigned to the value object using either another
+    # NetAddr::CIDR object, a string or an array. The &lt;tt&gt;:constructor&lt;/tt&gt; and &lt;tt&gt;:converter&lt;/tt&gt; options can be used to
+    # meet these requirements:
+    #
+    #   class NetworkResource &lt; ActiveRecord::Base
+    #     composed_of :cidr,
+    #                 :class_name =&gt; 'NetAddr::CIDR',
+    #                 :mapping =&gt; [ %w(network_address network), %w(cidr_range bits) ],
+    #                 :allow_nil =&gt; true,
+    #                 :constructor =&gt; Proc.new { |network_address, cidr_range| NetAddr::CIDR.create(&quot;#{network_address}/#{cidr_range}&quot;) },
+    #                 :converter =&gt; Proc.new { |value| NetAddr::CIDR.create(value.is_a?(Array) ? value.join('/') : value) }
+    #   end
+    #
+    #   # This calls the :constructor
+    #   network_resource = NetworkResource.new(:network_address =&gt; '192.168.0.1', :cidr_range =&gt; 24)
+    #
+    #   # These assignments will both use the :converter
+    #   network_resource.cidr = [ '192.168.2.1', 8 ]
+    #   network_resource.cidr = '192.168.0.1/24'
+    #
+    #   # This assignment won't use the :converter as the value is already an instance of the value class
+    #   network_resource.cidr = NetAddr::CIDR.create('192.168.2.1/8')
+    #
+    #   # Saving and then reloading will use the :constructor on reload
+    #   network_resource.save
+    #   network_resource.reload
+    #
     # == Finding records by a value object
     #
     # Once a +composed_of+ relationship is specified for a model, records can be loaded from the database by specifying an instance
@@ -122,47 +161,71 @@ module ActiveRecord
       # &lt;tt&gt;composed_of :address&lt;/tt&gt; adds &lt;tt&gt;address&lt;/tt&gt; and &lt;tt&gt;address=(new_address)&lt;/tt&gt; methods.
       #
       # Options are:
-      # * &lt;tt&gt;:class_name&lt;/tt&gt;  - specify the class name of the association. Use it only if that name can't be inferred
+      # * &lt;tt&gt;:class_name&lt;/tt&gt; - Specifies the class name of the association. Use it only if that name can't be inferred
       #   from the part id. So &lt;tt&gt;composed_of :address&lt;/tt&gt; will by default be linked to the Address class, but
       #   if the real class name is CompanyAddress, you'll have to specify it with this option.
-      # * &lt;tt&gt;:mapping&lt;/tt&gt; - specifies a number of mapping arrays (attribute, parameter) that bind an attribute name
-      #   to a constructor parameter on the value class.
-      # * &lt;tt&gt;:allow_nil&lt;/tt&gt; - specifies that the aggregate object will not be instantiated when all mapped
-      #   attributes are +nil+.  Setting the aggregate class to +nil+ has the effect of writing +nil+ to all mapped attributes.
+      # * &lt;tt&gt;:mapping&lt;/tt&gt; - Specifies the mapping of entity attributes to attributes of the value object. Each mapping
+      #   is represented as an array where the first item is the name of the entity attribute and the second item is the
+      #   name the attribute in the value object. The order in which mappings are defined determine the order in which
+      #   attributes are sent to the value class constructor.
+      # * &lt;tt&gt;:allow_nil&lt;/tt&gt; - Specifies that the value object will not be instantiated when all mapped
+      #   attributes are +nil+.  Setting the value object to +nil+ has the effect of writing +nil+ to all mapped attributes.
       #   This defaults to +false+.
-      #
-      # An optional block can be passed to convert the argument that is passed to the writer method into an instance of
-      # &lt;tt&gt;:class_name&lt;/tt&gt;. The block will only be called if the argument is not already an instance of &lt;tt&gt;:class_name&lt;/tt&gt;.
+      # * &lt;tt&gt;:constructor&lt;/tt&gt; - A symbol specifying the name of the constructor method or a Proc that is called to
+      #   initialize the value object. The constructor is passed all of the mapped attributes, in the order that they
+      #   are defined in the &lt;tt&gt;:mapping option&lt;/tt&gt;, as arguments and uses them to instantiate a &lt;tt&gt;:class_name&lt;/tt&gt; object.
+      #   The default is &lt;tt&gt;:new&lt;/tt&gt;.
+      # * &lt;tt&gt;:converter&lt;/tt&gt; - A symbol specifying the name of a class method of &lt;tt&gt;:class_name&lt;/tt&gt; or a Proc that is
+      #   called when a new value is assigned to the value object. The converter is passed the single value that is used
+      #   in the assignment and is only called if the new value is not an instance of &lt;tt&gt;:class_name&lt;/tt&gt;.
       #
       # Option examples:
       #   composed_of :temperature, :mapping =&gt; %w(reading celsius)
-      #   composed_of(:balance, :class_name =&gt; &quot;Money&quot;, :mapping =&gt; %w(balance amount)) {|balance| balance.to_money }
+      #   composed_of :balance, :class_name =&gt; &quot;Money&quot;, :mapping =&gt; %w(balance amount), :converter =&gt; Proc.new { |balance| balance.to_money }
       #   composed_of :address, :mapping =&gt; [ %w(address_street street), %w(address_city city) ]
       #   composed_of :gps_location
       #   composed_of :gps_location, :allow_nil =&gt; true
+      #   composed_of :ip_address,
+      #               :class_name =&gt; 'IPAddr',
+      #               :mapping =&gt; %w(ip to_i),
+      #               :constructor =&gt; Proc.new { |ip| IPAddr.new(ip, Socket::AF_INET) },
+      #               :converter =&gt; Proc.new { |ip| ip.is_a?(Integer) ? IPAddr.new(ip, Socket::AF_INET) : IPAddr.new(ip.to_s) }
       #
       def composed_of(part_id, options = {}, &amp;block)
-        options.assert_valid_keys(:class_name, :mapping, :allow_nil)
+        options.assert_valid_keys(:class_name, :mapping, :allow_nil, :constructor, :converter)
 
         name        = part_id.id2name
-        class_name  = options[:class_name] || name.camelize
-        mapping     = options[:mapping]    || [ name, name ]
+        class_name  = options[:class_name]  || name.camelize
+        mapping     = options[:mapping]     || [ name, name ]
         mapping     = [ mapping ] unless mapping.first.is_a?(Array)
-        allow_nil   = options[:allow_nil]  || false
+        allow_nil   = options[:allow_nil]   || false
+        constructor = options[:constructor] || :new
+        converter   = options[:converter]   || block
+
+        ActiveSupport::Deprecation.warn('The conversion block has been deprecated, use the :converter option instead.', caller) if block_given?
+
+        reader_method(name, class_name, mapping, allow_nil, constructor)
+        writer_method(name, class_name, mapping, allow_nil, converter)
 
-        reader_method(name, class_name, mapping, allow_nil)
-        writer_method(name, class_name, mapping, allow_nil, block)
-        
         create_reflection(:composed_of, part_id, options, self)
       end
 
       private
-        def reader_method(name, class_name, mapping, allow_nil)
+        def reader_method(name, class_name, mapping, allow_nil, constructor)
           module_eval do
             define_method(name) do |*args|
               force_reload = args.first || false
               if (instance_variable_get(&quot;@#{name}&quot;).nil? || force_reload) &amp;&amp; (!allow_nil || mapping.any? {|pair| !read_attribute(pair.first).nil? })
-                instance_variable_set(&quot;@#{name}&quot;, class_name.constantize.new(*mapping.collect {|pair| read_attribute(pair.first)}))
+                attrs = mapping.collect {|pair| read_attribute(pair.first)}
+                object = case constructor
+                  when Symbol
+                    class_name.constantize.send(constructor, *attrs)
+                  when Proc, Method
+                    constructor.call(*attrs)
+                  else
+                    raise ArgumentError, 'Constructor must be a symbol denoting the constructor method to call or a Proc to be invoked.'
+                  end
+                instance_variable_set(&quot;@#{name}&quot;, object)
               end
               instance_variable_get(&quot;@#{name}&quot;)
             end
@@ -170,14 +233,23 @@ module ActiveRecord
 
         end
 
-        def writer_method(name, class_name, mapping, allow_nil, conversion)
+        def writer_method(name, class_name, mapping, allow_nil, converter)
           module_eval do
             define_method(&quot;#{name}=&quot;) do |part|
               if part.nil? &amp;&amp; allow_nil
                 mapping.each { |pair| self[pair.first] = nil }
                 instance_variable_set(&quot;@#{name}&quot;, nil)
               else
-                part = conversion.call(part) unless part.is_a?(class_name.constantize) || conversion.nil?
+                unless part.is_a?(class_name.constantize) || converter.nil?
+                  part = case converter
+                    when Symbol
+                     class_name.constantize.send(converter, part)
+                    when Proc, Method
+                      converter.call(part)
+                    else
+                      raise ArgumentError, 'Converter must be a symbol denoting the converter method to call or a Proc to be invoked.'
+                    end
+                end
                 mapping.each { |pair| self[pair.first] = part.send(pair.last) }
                 instance_variable_set(&quot;@#{name}&quot;, part.freeze)
               end</diff>
      <filename>vendor/activerecord/lib/active_record/aggregations.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,14 +1,88 @@
 module ActiveRecord
+  # See ActiveRecord::AssociationPreload::ClassMethods for documentation.
   module AssociationPreload #:nodoc:
     def self.included(base)
       base.extend(ClassMethods)
     end
 
+    # Implements the details of eager loading of ActiveRecord associations.
+    # Application developers should not use this module directly.
+    #
+    # ActiveRecord::Base is extended with this module. The source code in
+    # ActiveRecord::Base references methods defined in this module.
+    #
+    # Note that 'eager loading' and 'preloading' are actually the same thing.
+    # However, there are two different eager loading strategies.
+    #
+    # The first one is by using table joins. This was only strategy available
+    # prior to Rails 2.1. Suppose that you have an Author model with columns
+    # 'name' and 'age', and a Book model with columns 'name' and 'sales'. Using
+    # this strategy, ActiveRecord would try to retrieve all data for an author
+    # and all of its books via a single query:
+    #
+    #   SELECT * FROM authors
+    #   LEFT OUTER JOIN books ON authors.id = books.id
+    #   WHERE authors.name = 'Ken Akamatsu'
+    #
+    # However, this could result in many rows that contain redundant data. After
+    # having received the first row, we already have enough data to instantiate
+    # the Author object. In all subsequent rows, only the data for the joined
+    # 'books' table is useful; the joined 'authors' data is just redundant, and
+    # processing this redundant data takes memory and CPU time. The problem
+    # quickly becomes worse and worse as the level of eager loading increases
+    # (i.e. if ActiveRecord is to eager load the associations' assocations as
+    # well).
+    #
+    # The second strategy is to use multiple database queries, one for each
+    # level of association. Since Rails 2.1, this is the default strategy. In
+    # situations where a table join is necessary (e.g. when the +:conditions+
+    # option references an association's column), it will fallback to the table
+    # join strategy.
+    #
+    # See also ActiveRecord::Associations::ClassMethods, which explains eager
+    # loading in a more high-level (application developer-friendly) manner.
     module ClassMethods
-
-      # Loads the named associations for the activerecord record (or records) given
-      # preload_options is passed only one level deep: don't pass to the child associations when associations is a Hash
       protected
+      
+      # Eager loads the named associations for the given ActiveRecord record(s).
+      #
+      # In this description, 'association name' shall refer to the name passed
+      # to an association creation method. For example, a model that specifies
+      # &lt;tt&gt;belongs_to :author&lt;/tt&gt;, &lt;tt&gt;has_many :buyers&lt;/tt&gt; has association
+      # names +:author+ and +:buyers+.
+      #
+      # == Parameters
+      # +records+ is an array of ActiveRecord::Base. This array needs not be flat,
+      # i.e. +records+ itself may also contain arrays of records. In any case,
+      # +preload_associations+ will preload the associations all records by
+      # flattening +records+.
+      #
+      # +associations+ specifies one or more associations that you want to
+      # preload. It may be:
+      # - a Symbol or a String which specifies a single association name. For
+      #   example, specifiying +:books+ allows this method to preload all books
+      #   for an Author.
+      # - an Array which specifies multiple association names. This array
+      #   is processed recursively. For example, specifying &lt;tt&gt;[:avatar, :books]&lt;/tt&gt;
+      #   allows this method to preload an author's avatar as well as all of his
+      #   books.
+      # - a Hash which specifies multiple association names, as well as
+      #   association names for the to-be-preloaded association objects. For
+      #   example, specifying &lt;tt&gt;{ :author =&gt; :avatar }&lt;/tt&gt; will preload a
+      #   book's author, as well as that author's avatar.
+      #
+      # +:associations+ has the same format as the +:include+ option for
+      # &lt;tt&gt;ActiveRecord::Base.find&lt;/tt&gt;. So +associations+ could look like this:
+      #
+      #   :books
+      #   [ :books, :author ]
+      #   { :author =&gt; :avatar }
+      #   [ :books, { :author =&gt; :avatar } ]
+      #
+      # +preload_options+ contains options that will be passed to ActiveRecord#find
+      # (which is called under the hood for preloading records). But it is passed
+      # only one level deep in the +associations+ argument, i.e. it's not passed
+      # to the child associations when +associations+ is a Hash.
       def preload_associations(records, associations, preload_options={})
         records = [records].flatten.compact.uniq
         return if records.empty?
@@ -30,13 +104,19 @@ module ActiveRecord
 
       private
 
+      # Preloads a specific named association for the given records. This is
+      # called by +preload_associations+ as its base case.
       def preload_one_association(records, association, preload_options={})
         class_to_reflection = {}
         # Not all records have the same class, so group then preload
         # group on the reflection itself so that if various subclass share the same association then we do not split them
-        # unncessarily
+        # unnecessarily
         records.group_by {|record| class_to_reflection[record.class] ||= record.class.reflections[association]}.each do |reflection, records|
           raise ConfigurationError, &quot;Association named '#{ association }' was not found; perhaps you misspelled it?&quot; unless reflection
+          
+          # 'reflection.macro' can return 'belongs_to', 'has_many', etc. Thus,
+          # the following could call 'preload_belongs_to_association',
+          # 'preload_has_many_association', etc.
           send(&quot;preload_#{reflection.macro}_association&quot;, records, reflection, preload_options)
         end
       end
@@ -77,12 +157,17 @@ module ActiveRecord
         end
       end
 
-      def construct_id_map(records)
+      # Given a collection of ActiveRecord objects, constructs a Hash which maps
+      # the objects' IDs to the relevant objects. Returns a 2-tuple
+      # &lt;tt&gt;(id_to_record_map, ids)&lt;/tt&gt; where +id_to_record_map+ is the Hash,
+      # and +ids+ is an Array of record IDs.
+      def construct_id_map(records, primary_key=nil)
         id_to_record_map = {}
         ids = []
         records.each do |record|
-          ids &lt;&lt; record.id
-          mapped_records = (id_to_record_map[record.id.to_s] ||= [])
+          primary_key ||= record.class.primary_key
+          ids &lt;&lt; record[primary_key]
+          mapped_records = (id_to_record_map[ids.last.to_s] ||= [])
           mapped_records &lt;&lt; record
         end
         ids.uniq!
@@ -95,8 +180,8 @@ module ActiveRecord
         records.each {|record| record.send(reflection.name).loaded}
         options = reflection.options
 
-        conditions = &quot;t0.#{reflection.primary_key_name}  IN (?)&quot;
-        conditions &lt;&lt; append_conditions(options, preload_options)
+        conditions = &quot;t0.#{reflection.primary_key_name} #{in_or_equals_for_ids(ids)}&quot;
+        conditions &lt;&lt; append_conditions(reflection, preload_options)
 
         associated_records = reflection.klass.find(:all, :conditions =&gt; [conditions, ids],
         :include =&gt; options[:include],
@@ -108,6 +193,7 @@ module ActiveRecord
       end
 
       def preload_has_one_association(records, reflection, preload_options={})
+        return if records.first.send(&quot;loaded_#{reflection.name}?&quot;)
         id_to_record_map, ids = construct_id_map(records)        
         options = reflection.options
         records.each {|record| record.send(&quot;set_#{reflection.name}_target&quot;, nil)}
@@ -129,23 +215,25 @@ module ActiveRecord
       end
 
       def preload_has_many_association(records, reflection, preload_options={})
-        id_to_record_map, ids = construct_id_map(records)
-        records.each {|record| record.send(reflection.name).loaded}
+        return if records.first.send(reflection.name).loaded?
         options = reflection.options
 
+        primary_key_name = reflection.through_reflection_primary_key_name
+        id_to_record_map, ids = construct_id_map(records, primary_key_name)
+        records.each {|record| record.send(reflection.name).loaded}
+
         if options[:through]
           through_records = preload_through_records(records, reflection, options[:through])
           through_reflection = reflections[options[:through]]
-          through_primary_key = through_reflection.primary_key_name
           unless through_records.empty?
             source = reflection.source_reflection.name
-            #add conditions from reflection!
-            through_records.first.class.preload_associations(through_records, source, reflection.options)
+            through_records.first.class.preload_associations(through_records, source, options)
             through_records.each do |through_record|
-              add_preloaded_records_to_collection(id_to_record_map[through_record[through_primary_key].to_s],
-                                                 reflection.name, through_record.send(source))
+              through_record_id = through_record[reflection.through_reflection_primary_key].to_s
+              add_preloaded_records_to_collection(id_to_record_map[through_record_id], reflection.name, through_record.send(source))
             end
           end
+
         else
           set_association_collection_records(id_to_record_map, reflection.name, find_associated_records(ids, reflection, preload_options),
                                              reflection.primary_key_name)
@@ -185,6 +273,7 @@ module ActiveRecord
       end
 
       def preload_belongs_to_association(records, reflection, preload_options={})
+        return if records.first.send(&quot;loaded_#{reflection.name}?&quot;)
         options = reflection.options
         primary_key_name = reflection.primary_key_name
 
@@ -222,10 +311,8 @@ module ActiveRecord
 
           table_name = klass.quoted_table_name
           primary_key = klass.primary_key
-          conditions = &quot;#{table_name}.#{connection.quote_column_name(primary_key)} IN (?)&quot;
-          conditions &lt;&lt; append_conditions(options, preload_options)
           column_type = klass.columns.detect{|c| c.name == primary_key}.type
-          ids = id_map.keys.uniq.map do |id|
+          ids = id_map.keys.map do |id|
             if column_type == :integer
               id.to_i
             elsif column_type == :float
@@ -234,6 +321,8 @@ module ActiveRecord
               id
             end
           end
+          conditions = &quot;#{table_name}.#{connection.quote_column_name(primary_key)} #{in_or_equals_for_ids(ids)}&quot;
+          conditions &lt;&lt; append_conditions(reflection, preload_options)
           associated_records = klass.find(:all, :conditions =&gt; [conditions, ids],
                                           :include =&gt; options[:include],
                                           :select =&gt; options[:select],
@@ -248,13 +337,13 @@ module ActiveRecord
         table_name = reflection.klass.quoted_table_name
 
         if interface = reflection.options[:as]
-          conditions = &quot;#{reflection.klass.quoted_table_name}.#{connection.quote_column_name &quot;#{interface}_id&quot;} IN (?) and #{reflection.klass.quoted_table_name}.#{connection.quote_column_name &quot;#{interface}_type&quot;} = '#{self.base_class.sti_name}'&quot;
+          conditions = &quot;#{reflection.klass.quoted_table_name}.#{connection.quote_column_name &quot;#{interface}_id&quot;} #{in_or_equals_for_ids(ids)} and #{reflection.klass.quoted_table_name}.#{connection.quote_column_name &quot;#{interface}_type&quot;} = '#{self.base_class.sti_name}'&quot;
         else
           foreign_key = reflection.primary_key_name
-          conditions = &quot;#{reflection.klass.quoted_table_name}.#{foreign_key} IN (?)&quot;
+          conditions = &quot;#{reflection.klass.quoted_table_name}.#{foreign_key} #{in_or_equals_for_ids(ids)}&quot;
         end
 
-        conditions &lt;&lt; append_conditions(options, preload_options)
+        conditions &lt;&lt; append_conditions(reflection, preload_options)
 
         reflection.klass.find(:all,
                               :select =&gt; (preload_options[:select] || options[:select] || &quot;#{table_name}.*&quot;),
@@ -270,13 +359,16 @@ module ActiveRecord
         instance_eval(&quot;%@#{sql.gsub('@', '\@')}@&quot;)
       end
 
-      def append_conditions(options, preload_options)
+      def append_conditions(reflection, preload_options)
         sql = &quot;&quot;
-        sql &lt;&lt; &quot; AND (#{interpolate_sql_for_preload(sanitize_sql(options[:conditions]))})&quot; if options[:conditions]
+        sql &lt;&lt; &quot; AND (#{interpolate_sql_for_preload(reflection.sanitized_conditions)})&quot; if reflection.sanitized_conditions
         sql &lt;&lt; &quot; AND (#{sanitize_sql preload_options[:conditions]})&quot; if preload_options[:conditions]
         sql
       end
 
+      def in_or_equals_for_ids(ids)
+        ids.size &gt; 1 ? &quot;IN (?)&quot; : &quot;= ?&quot;
+      end
     end
   end
 end</diff>
      <filename>vendor/activerecord/lib/active_record/association_preload.rb</filename>
    </modified>
    <modified>
      <diff>@@ -73,6 +73,7 @@ module ActiveRecord
     end
   end
 
+  # See ActiveRecord::Associations::ClassMethods for documentation.
   module Associations # :nodoc:
     def self.included(base)
       base.extend(ClassMethods)
@@ -150,6 +151,7 @@ module ActiveRecord
     #   #others.destroy_all               |   X   |    X     |    X
     #   #others.find(*args)               |   X   |    X     |    X
     #   #others.find_first                |   X   |          |
+    #   #others.exist?                    |   X   |    X     |    X
     #   #others.uniq                      |   X   |    X     |    X
     #   #others.reset                     |   X   |    X     |    X
     #
@@ -505,6 +507,14 @@ module ActiveRecord
     #
     # will load posts and eager load the +approved_comments+ association, which contains only those comments that have been approved.
     #
+    # If you eager load an association with a specified &lt;tt&gt;:limit&lt;/tt&gt; option, it will be ignored, returning all the associated objects:
+    #
+    #   class Picture &lt; ActiveRecord::Base
+    #     has_many :most_recent_comments, :class_name =&gt; 'Comment', :order =&gt; 'id DESC', :limit =&gt; 10
+    #   end
+    #
+    #   Picture.find(:first, :include =&gt; :most_recent_comments).most_recent_comments # =&gt; returns all associated comments.
+    #
     # When eager loaded, conditions are interpolated in the context of the model class, not the model instance.  Conditions are lazily interpolated
     # before the actual model exists.
     #
@@ -582,12 +592,13 @@ module ActiveRecord
     #          has_many :clients
     #        end
     #
-    #       class Company &lt; ActiveRecord::Base; end
+    #       class Client &lt; ActiveRecord::Base; end
     #     end
     #   end
     #
-    # When Firm#clients is called, it will in turn call &lt;tt&gt;MyApplication::Business::Company.find(firm.id)&lt;/tt&gt;. If you want to associate
-    # with a class in another module scope, this can be done by specifying the complete class name.  Example:
+    # When &lt;tt&gt;Firm#clients&lt;/tt&gt; is called, it will in turn call &lt;tt&gt;MyApplication::Business::Client.find_all_by_firm_id(firm.id)&lt;/tt&gt;.
+    # If you want to associate with a class in another module scope, this can be done by specifying the complete class name.
+    # Example:
     #
     #   module MyApplication
     #     module Business
@@ -611,32 +622,55 @@ module ActiveRecord
     # All of the association macros can be specialized through options. This makes cases more complex than the simple and guessable ones
     # possible.
     module ClassMethods
-      # Adds the following methods for retrieval and query of collections of associated objects:
-      # +collection+ is replaced with the symbol passed as the first argument, so
-      # &lt;tt&gt;has_many :clients&lt;/tt&gt; would add among others &lt;tt&gt;clients.empty?&lt;/tt&gt;.
-      # * &lt;tt&gt;collection(force_reload = false)&lt;/tt&gt; - Returns an array of all the associated objects.
+      # Specifies a one-to-many association. The following methods for retrieval and query of
+      # collections of associated objects will be added:
+      #
+      # [collection(force_reload = false)]
+      #   Returns an array of all the associated objects.
       #   An empty array is returned if none are found.
-      # * &lt;tt&gt;collection&lt;&lt;(object, ...)&lt;/tt&gt; - Adds one or more objects to the collection by setting their foreign keys to the collection's primary key.
-      # * &lt;tt&gt;collection.delete(object, ...)&lt;/tt&gt; - Removes one or more objects from the collection by setting their foreign keys to +NULL+.
-      #   This will also destroy the objects if they're declared as +belongs_to+ and dependent on this model.
-      # * &lt;tt&gt;collection=objects&lt;/tt&gt; - Replaces the collections content by deleting and adding objects as appropriate.
-      # * &lt;tt&gt;collection_singular_ids&lt;/tt&gt; - Returns an array of the associated objects' ids
-      # * &lt;tt&gt;collection_singular_ids=ids&lt;/tt&gt; - Replace the collection with the objects identified by the primary keys in +ids+
-      # * &lt;tt&gt;collection.clear&lt;/tt&gt; - Removes every object from the collection. This destroys the associated objects if they
-      #   are associated with &lt;tt&gt;:dependent =&gt; :destroy&lt;/tt&gt;, deletes them directly from the database if &lt;tt&gt;:dependent =&gt; :delete_all&lt;/tt&gt;,
-      #   otherwise sets their foreign keys to +NULL+.
-      # * &lt;tt&gt;collection.empty?&lt;/tt&gt; - Returns +true+ if there are no associated objects.
-      # * &lt;tt&gt;collection.size&lt;/tt&gt; - Returns the number of associated objects.
-      # * &lt;tt&gt;collection.find&lt;/tt&gt; - Finds an associated object according to the same rules as Base.find.
-      # * &lt;tt&gt;collection.build(attributes = {}, ...)&lt;/tt&gt; - Returns one or more new objects of the collection type that have been instantiated
-      #   with +attributes+ and linked to this object through a foreign key, but have not yet been saved. *Note:* This only works if an
-      #   associated object already exists, not if it's +nil+!
-      # * &lt;tt&gt;collection.create(attributes = {})&lt;/tt&gt; - Returns a new object of the collection type that has been instantiated
-      #   with +attributes+, linked to this object through a foreign key, and that has already been saved (if it passed the validation).
-      #   *Note:* This only works if an associated object already exists, not if it's +nil+!
+      # [collection&lt;&lt;(object, ...)]
+      #   Adds one or more objects to the collection by setting their foreign keys to the collection's primary key.
+      # [collection.delete(object, ...)]
+      #   Removes one or more objects from the collection by setting their foreign keys to +NULL+.
+      #   Objects will be in addition destroyed if they're associated with &lt;tt&gt;:dependent =&gt; :destroy&lt;/tt&gt;,
+      #   and deleted if they're associated with &lt;tt&gt;:dependent =&gt; :delete_all&lt;/tt&gt;.
+      # [collection=objects]
+      #   Replaces the collections content by deleting and adding objects as appropriate.
+      # [collection_singular_ids]
+      #   Returns an array of the associated objects' ids
+      # [collection_singular_ids=ids]
+      #   Replace the collection with the objects identified by the primary keys in +ids+
+      # [collection.clear]
+      #   Removes every object from the collection. This destroys the associated objects if they
+      #   are associated with &lt;tt&gt;:dependent =&gt; :destroy&lt;/tt&gt;, deletes them directly from the
+      #   database if &lt;tt&gt;:dependent =&gt; :delete_all&lt;/tt&gt;, otherwise sets their foreign keys to +NULL+.
+      # [collection.empty?]
+      #   Returns +true+ if there are no associated objects.
+      # [collection.size]
+      #   Returns the number of associated objects.
+      # [collection.find(...)]
+      #   Finds an associated object according to the same rules as ActiveRecord::Base.find.
+      # [collection.exist?(...)]
+      #   Checks whether an associated object with the given conditions exists.
+      #   Uses the same rules as ActiveRecord::Base.exists?.
+      # [collection.build(attributes = {}, ...)]
+      #   Returns one or more new objects of the collection type that have been instantiated
+      #   with +attributes+ and linked to this object through a foreign key, but have not yet
+      #   been saved. &lt;b&gt;Note:&lt;/b&gt; This only works if an associated object already exists, not if
+      #   it's +nil+!
+      # [collection.create(attributes = {})]
+      #   Returns a new object of the collection type that has been instantiated
+      #   with +attributes+, linked to this object through a foreign key, and that has already
+      #   been saved (if it passed the validation). &lt;b&gt;Note:&lt;/b&gt; This only works if an associated
+      #   object already exists, not if it's +nil+!
+      #
+      # (*Note*: +collection+ is replaced with the symbol passed as the first argument, so
+      # &lt;tt&gt;has_many :clients&lt;/tt&gt; would add among others &lt;tt&gt;clients.empty?&lt;/tt&gt;.)
+      #
+      # === Example
       #
       # Example: A Firm class declares &lt;tt&gt;has_many :clients&lt;/tt&gt;, which will add:
-      # * &lt;tt&gt;Firm#clients&lt;/tt&gt; (similar to &lt;tt&gt;Clients.find :all, :conditions =&gt; &quot;firm_id = #{id}&quot;&lt;/tt&gt;)
+      # * &lt;tt&gt;Firm#clients&lt;/tt&gt; (similar to &lt;tt&gt;Clients.find :all, :conditions =&gt; [&quot;firm_id = ?&quot;, id]&lt;/tt&gt;)
       # * &lt;tt&gt;Firm#clients&lt;&lt;&lt;/tt&gt;
       # * &lt;tt&gt;Firm#clients.delete&lt;/tt&gt;
       # * &lt;tt&gt;Firm#clients=&lt;/tt&gt;
@@ -646,52 +680,74 @@ module ActiveRecord
       # * &lt;tt&gt;Firm#clients.empty?&lt;/tt&gt; (similar to &lt;tt&gt;firm.clients.size == 0&lt;/tt&gt;)
       # * &lt;tt&gt;Firm#clients.size&lt;/tt&gt; (similar to &lt;tt&gt;Client.count &quot;firm_id = #{id}&quot;&lt;/tt&gt;)
       # * &lt;tt&gt;Firm#clients.find&lt;/tt&gt; (similar to &lt;tt&gt;Client.find(id, :conditions =&gt; &quot;firm_id = #{id}&quot;)&lt;/tt&gt;)
+      # * &lt;tt&gt;Firm#clients.exist?(:name =&gt; 'ACME')&lt;/tt&gt; (similar to &lt;tt&gt;Client.exist?(:name =&gt; 'ACME', :firm_id =&gt; firm.id)&lt;/tt&gt;)
       # * &lt;tt&gt;Firm#clients.build&lt;/tt&gt; (similar to &lt;tt&gt;Client.new(&quot;firm_id&quot; =&gt; id)&lt;/tt&gt;)
       # * &lt;tt&gt;Firm#clients.create&lt;/tt&gt; (similar to &lt;tt&gt;c = Client.new(&quot;firm_id&quot; =&gt; id); c.save; c&lt;/tt&gt;)
       # The declaration can also include an options hash to specialize the behavior of the association.
       #
-      # Options are:
-      # * &lt;tt&gt;:class_name&lt;/tt&gt; - Specify the class name of the association. Use it only if that name can't be inferred
+      # === Supported options
+      # [:class_name]
+      #   Specify the class name of the association. Use it only if that name can't be inferred
       #   from the association name. So &lt;tt&gt;has_many :products&lt;/tt&gt; will by default be linked to the Product class, but
       #   if the real class name is SpecialProduct, you'll have to specify it with this option.
-      # * &lt;tt&gt;:conditions&lt;/tt&gt; - Specify the conditions that the associated objects must meet in order to be included as a +WHERE+
+      # [:conditions]
+      #   Specify the conditions that the associated objects must meet in order to be included as a +WHERE+
       #   SQL fragment, such as &lt;tt&gt;price &gt; 5 AND name LIKE 'B%'&lt;/tt&gt;.  Record creations from the association are scoped if a hash
       #   is used.  &lt;tt&gt;has_many :posts, :conditions =&gt; {:published =&gt; true}&lt;/tt&gt; will create published posts with &lt;tt&gt;@blog.posts.create&lt;/tt&gt;
       #   or &lt;tt&gt;@blog.posts.build&lt;/tt&gt;.
-      # * &lt;tt&gt;:order&lt;/tt&gt; - Specify the order in which the associated objects are returned as an &lt;tt&gt;ORDER BY&lt;/tt&gt; SQL fragment,
+      # [:order]
+      #   Specify the order in which the associated objects are returned as an &lt;tt&gt;ORDER BY&lt;/tt&gt; SQL fragment,
       #   such as &lt;tt&gt;last_name, first_name DESC&lt;/tt&gt;.
-      # * &lt;tt&gt;:foreign_key&lt;/tt&gt; - Specify the foreign key used for the association. By default this is guessed to be the name
+      # [:foreign_key]
+      #   Specify the foreign key used for the association. By default this is guessed to be the name
       #   of this class in lower-case and &quot;_id&quot; suffixed. So a Person class that makes a +has_many+ association will use &quot;person_id&quot;
       #   as the default &lt;tt&gt;:foreign_key&lt;/tt&gt;.
-      # * &lt;tt&gt;:dependent&lt;/tt&gt; - If set to &lt;tt&gt;:destroy&lt;/tt&gt; all the associated objects are destroyed
+      # [:primary_key]
+      #   Specify the method that returns the primary key used for the association. By default this is +id+.
+      # [:dependent]
+      #   If set to &lt;tt&gt;:destroy&lt;/tt&gt; all the associated objects are destroyed
       #   alongside this object by calling their +destroy+ method.  If set to &lt;tt&gt;:delete_all&lt;/tt&gt; all associated
       #   objects are deleted *without* calling their +destroy+ method.  If set to &lt;tt&gt;:nullify&lt;/tt&gt; all associated
       #   objects' foreign keys are set to +NULL+ *without* calling their +save+ callbacks. *Warning:* This option is ignored when also using
       #   the &lt;tt&gt;:through&lt;/tt&gt; option.
-      # * &lt;tt&gt;:finder_sql&lt;/tt&gt; - Specify a complete SQL statement to fetch the association. This is a good way to go for complex
+      # [:finder_sql]
+      #   Specify a complete SQL statement to fetch the association. This is a good way to go for complex
       #   associations that depend on multiple tables. Note: When this option is used, +find_in_collection+ is _not_ added.
-      # * &lt;tt&gt;:counter_sql&lt;/tt&gt; - Specify a complete SQL statement to fetch the size of the association. If &lt;tt&gt;:finder_sql&lt;/tt&gt; is
+      # [:counter_sql]
+      #   Specify a complete SQL statement to fetch the size of the association. If &lt;tt&gt;:finder_sql&lt;/tt&gt; is
       #   specified but not &lt;tt&gt;:counter_sql&lt;/tt&gt;, &lt;tt&gt;:counter_sql&lt;/tt&gt; will be generated by replacing &lt;tt&gt;SELECT ... FROM&lt;/tt&gt; with &lt;tt&gt;SELECT COUNT(*) FROM&lt;/tt&gt;.
-      # * &lt;tt&gt;:extend&lt;/tt&gt; - Specify a named module for extending the proxy. See &quot;Association extensions&quot;.
-      # * &lt;tt&gt;:include&lt;/tt&gt; - Specify second-order associations that should be eager loaded when the collection is loaded.
-      # * &lt;tt&gt;:group&lt;/tt&gt; - An attribute name by which the result should be grouped. Uses the &lt;tt&gt;GROUP BY&lt;/tt&gt; SQL-clause.
-      # * &lt;tt&gt;:limit&lt;/tt&gt; - An integer determining the limit on the number of rows that should be returned.
-      # * &lt;tt&gt;:offset&lt;/tt&gt; - An integer determining the offset from where the rows should be fetched. So at 5, it would skip the first 4 rows.
-      # * &lt;tt&gt;:select&lt;/tt&gt; - By default, this is &lt;tt&gt;*&lt;/tt&gt; as in &lt;tt&gt;SELECT * FROM&lt;/tt&gt;, but can be changed if you, for example, want to do a join
-      #   but not include the joined columns. Do not forget to include the primary and foreign keys, otherwise it will rise an error.
-      # * &lt;tt&gt;:as&lt;/tt&gt; - Specifies a polymorphic interface (See &lt;tt&gt;belongs_to&lt;/tt&gt;).
-      # * &lt;tt&gt;:through&lt;/tt&gt; - Specifies a Join Model through which to perform the query.  Options for &lt;tt&gt;:class_name&lt;/tt&gt; and &lt;tt&gt;:foreign_key&lt;/tt&gt;
+      # [:extend]
+      #   Specify a named module for extending the proxy. See &quot;Association extensions&quot;.
+      # [:include]
+      #   Specify second-order associations that should be eager loaded when the collection is loaded.
+      # [:group]
+      #   An attribute name by which the result should be grouped. Uses the &lt;tt&gt;GROUP BY&lt;/tt&gt; SQL-clause.
+      # [:limit]
+      #   An integer determining the limit on the number of rows that should be returned.
+      # [:offset]
+      #   An integer determining the offset from where the rows should be fetched. So at 5, it would skip the first 4 rows.
+      # [:select]
+      #   By default, this is &lt;tt&gt;*&lt;/tt&gt; as in &lt;tt&gt;SELECT * FROM&lt;/tt&gt;, but can be changed if you, for example, want to do a join
+      #   but not include the joined columns. Do not forget to include the primary and foreign keys, otherwise it will raise an error.
+      # [:as]
+      #   Specifies a polymorphic interface (See &lt;tt&gt;belongs_to&lt;/tt&gt;).
+      # [:through]
+      #   Specifies a Join Model through which to perform the query.  Options for &lt;tt&gt;:class_name&lt;/tt&gt; and &lt;tt&gt;:foreign_key&lt;/tt&gt;
       #   are ignored, as the association uses the source reflection. You can only use a &lt;tt&gt;:through&lt;/tt&gt; query through a &lt;tt&gt;belongs_to&lt;/tt&gt;
       #   or &lt;tt&gt;has_many&lt;/tt&gt; association on the join model.
-      # * &lt;tt&gt;:source&lt;/tt&gt; - Specifies the source association name used by &lt;tt&gt;has_many :through&lt;/tt&gt; queries.  Only use it if the name cannot be
+      # [:source]
+      #   Specifies the source association name used by &lt;tt&gt;has_many :through&lt;/tt&gt; queries.  Only use it if the name cannot be
       #   inferred from the association.  &lt;tt&gt;has_many :subscribers, :through =&gt; :subscriptions&lt;/tt&gt; will look for either &lt;tt&gt;:subscribers&lt;/tt&gt; or
       #   &lt;tt&gt;:subscriber&lt;/tt&gt; on Subscription, unless a &lt;tt&gt;:source&lt;/tt&gt; is given.
-      # * &lt;tt&gt;:source_type&lt;/tt&gt; - Specifies type of the source association used by &lt;tt&gt;has_many :through&lt;/tt&gt; queries where the source
+      # [:source_type]
+      #   Specifies type of the source association used by &lt;tt&gt;has_many :through&lt;/tt&gt; queries where the source
       #   association is a polymorphic +belongs_to+.
-      # * &lt;tt&gt;:uniq&lt;/tt&gt; - If true, duplicates will be omitted from the collection. Useful in conjunction with &lt;tt&gt;:through&lt;/tt&gt;.
-      # * &lt;tt&gt;:readonly&lt;/tt&gt; - If true, all the associated objects are readonly through the association.
-      # * &lt;tt&gt;:validate&lt;/tt&gt; - If false, don't validate the associated objects when saving the parent object. true by default.
-      #
+      # [:uniq]
+      #   If true, duplicates will be omitted from the collection. Useful in conjunction with &lt;tt&gt;:through&lt;/tt&gt;.
+      # [:readonly]
+      #   If true, all the associated objects are readonly through the association.
+      # [:validate]
+      #   If false, don't validate the associated objects when saving the parent object. true by default.
       # Option examples:
       #   has_many :comments, :order =&gt; &quot;posted_on&quot;
       #   has_many :comments, :include =&gt; :author
@@ -722,56 +778,89 @@ module ActiveRecord
         end
       end
 
-      # Adds the following methods for retrieval and query of a single associated object:
-      # +association+ is replaced with the symbol passed as the first argument, so
-      # &lt;tt&gt;has_one :manager&lt;/tt&gt; would add among others &lt;tt&gt;manager.nil?&lt;/tt&gt;.
-      # * &lt;tt&gt;association(force_reload = false)&lt;/tt&gt; - Returns the associated object. +nil+ is returned if none is found.
-      # * &lt;tt&gt;association=(associate)&lt;/tt&gt; - Assigns the associate object, extracts the primary key, sets it as the foreign key,
+      # Specifies a one-to-one association with another class. This method should only be used
+      # if the other class contains the foreign key. If the current class contains the foreign key,
+      # then you should use +belongs_to+ instead. See also ActiveRecord::Associations::ClassMethods's overview
+      # on when to use has_one and when to use belongs_to.
+      #
+      # The following methods for retrieval and query of a single associated object will be added:
+      #
+      # [association(force_reload = false)]
+      #   Returns the associated object. +nil+ is returned if none is found.
+      # [association=(associate)]
+      #   Assigns the associate object, extracts the primary key, sets it as the foreign key,
       #   and saves the associate object.
-      # * &lt;tt&gt;association.nil?&lt;/tt&gt; - Returns +true+ if there is no associated object.
-      # * &lt;tt&gt;build_association(attributes = {})&lt;/tt&gt; - Returns a new object of the associated type that has been instantiated
-      #   with +attributes+ and linked to this object through a foreign key, but has not yet been saved. Note: This ONLY works if
-      #   an association already exists. It will NOT work if the association is +nil+.
-      # * &lt;tt&gt;create_association(attributes = {})&lt;/tt&gt; - Returns a new object of the associated type that has been instantiated
-      #   with +attributes+, linked to this object through a foreign key, and that has already been saved (if it passed the validation).
+      # [association.nil?]
+      #   Returns +true+ if there is no associated object.
+      # [build_association(attributes = {})]
+      #   Returns a new object of the associated type that has been instantiated
+      #   with +attributes+ and linked to this object through a foreign key, but has not
+      #   yet been saved. &lt;b&gt;Note:&lt;/b&gt; This ONLY works if an association already exists.
+      #   It will NOT work if the association is +nil+.
+      # [create_association(attributes = {})]
+      #   Returns a new object of the associated type that has been instantiated
+      #   with +attributes+, linked to this object through a foreign key, and that
+      #   has already been saved (if it passed the validation).
       #
-      # Example: An Account class declares &lt;tt&gt;has_one :beneficiary&lt;/tt&gt;, which will add:
+      # (+association+ is replaced with the symbol passed as the first argument, so
+      # &lt;tt&gt;has_one :manager&lt;/tt&gt; would add among others &lt;tt&gt;manager.nil?&lt;/tt&gt;.)
+      #
+      # === Example
+      #
+      # An Account class declares &lt;tt&gt;has_one :beneficiary&lt;/tt&gt;, which will add:
       # * &lt;tt&gt;Account#beneficiary&lt;/tt&gt; (similar to &lt;tt&gt;Beneficiary.find(:first, :conditions =&gt; &quot;account_id = #{id}&quot;)&lt;/tt&gt;)
       # * &lt;tt&gt;Account#beneficiary=(beneficiary)&lt;/tt&gt; (similar to &lt;tt&gt;beneficiary.account_id = account.id; beneficiary.save&lt;/tt&gt;)
       # * &lt;tt&gt;Account#beneficiary.nil?&lt;/tt&gt;
       # * &lt;tt&gt;Account#build_beneficiary&lt;/tt&gt; (similar to &lt;tt&gt;Beneficiary.new(&quot;account_id&quot; =&gt; id)&lt;/tt&gt;)
       # * &lt;tt&gt;Account#create_beneficiary&lt;/tt&gt; (similar to &lt;tt&gt;b = Beneficiary.new(&quot;account_id&quot; =&gt; id); b.save; b&lt;/tt&gt;)
       #
+      # === Options
+      #
       # The declaration can also include an options hash to specialize the behavior of the association.
       #
       # Options are:
-      # * &lt;tt&gt;:class_name&lt;/tt&gt; - Specify the class name of the association. Use it only if that name can't be inferred
+      # [:class_name]
+      #   Specify the class name of the association. Use it only if that name can't be inferred
       #   from the association name. So &lt;tt&gt;has_one :manager&lt;/tt&gt; will by default be linked to the Manager class, but
       #   if the real class name is Person, you'll have to specify it with this option.
-      # * &lt;tt&gt;:conditions&lt;/tt&gt; - Specify the conditions that the associated object must meet in order to be included as a +WHERE+
+      # [:conditions]
+      #   Specify the conditions that the associated object must meet in order to be included as a +WHERE+
       #   SQL fragment, such as &lt;tt&gt;rank = 5&lt;/tt&gt;.
-      # * &lt;tt&gt;:order&lt;/tt&gt; - Specify the order in which the associated objects are returned as an &lt;tt&gt;ORDER BY&lt;/tt&gt; SQL fragment,
+      # [:order]
+      #   Specify the order in which the associated objects are returned as an &lt;tt&gt;ORDER BY&lt;/tt&gt; SQL fragment,
       #   such as &lt;tt&gt;last_name, first_name DESC&lt;/tt&gt;.
-      # * &lt;tt&gt;:dependent&lt;/tt&gt; - If set to &lt;tt&gt;:destroy&lt;/tt&gt;, the associated object is destroyed when this object is. If set to
+      # [:dependent]
+      #   If set to &lt;tt&gt;:destroy&lt;/tt&gt;, the associated object is destroyed when this object is. If set to
       #   &lt;tt&gt;:delete&lt;/tt&gt;, the associated object is deleted *without* calling its destroy method. If set to &lt;tt&gt;:nullify&lt;/tt&gt;, the associated
       #   object's foreign key is set to +NULL+. Also, association is assigned.
-      # * &lt;tt&gt;:foreign_key&lt;/tt&gt; - Specify the foreign key used for the association. By default this is guessed to be the name
+      # [:foreign_key]
+      #   Specify the foreign key used for the association. By default this is guessed to be the name
       #   of this class in lower-case and &quot;_id&quot; suffixed. So a Person class that makes a +has_one+ association will use &quot;person_id&quot;
       #   as the default &lt;tt&gt;:foreign_key&lt;/tt&gt;.
-      # * &lt;tt&gt;:include&lt;/tt&gt; - Specify second-order associations that should be eager loaded when this object is loaded.
-      # * &lt;tt&gt;:as&lt;/tt&gt; - Specifies a polymorphic interface (See &lt;tt&gt;belongs_to&lt;/tt&gt;).
-      # * &lt;tt&gt;:select&lt;/tt&gt; - By default, this is &lt;tt&gt;*&lt;/tt&gt; as in &lt;tt&gt;SELECT * FROM&lt;/tt&gt;, but can be changed if, for example, you want to do a join
+      # [:primary_key]
+      #   Specify the method that returns the primary key used for the association. By default this is +id+.
+      # [:include]
+      #   Specify second-order associations that should be eager loaded when this object is loaded.
+      # [:as]
+      #   Specifies a polymorphic interface (See &lt;tt&gt;belongs_to&lt;/tt&gt;).
+      # [:select]
+      #   By default, this is &lt;tt&gt;*&lt;/tt&gt; as in &lt;tt&gt;SELECT * FROM&lt;/tt&gt;, but can be changed if, for example, you want to do a join
       #   but not include the joined columns. Do not forget to include the primary and foreign keys, otherwise it will raise an error.
-      # * &lt;tt&gt;:through&lt;/tt&gt;: Specifies a Join Model through which to perform the query.  Options for &lt;tt&gt;:class_name&lt;/tt&gt; and &lt;tt&gt;:foreign_key&lt;/tt&gt;
+      # [:through]
+      #   Specifies a Join Model through which to perform the query.  Options for &lt;tt&gt;:class_name&lt;/tt&gt; and &lt;tt&gt;:foreign_key&lt;/tt&gt;
       #   are ignored, as the association uses the source reflection. You can only use a &lt;tt&gt;:through&lt;/tt&gt; query through a 
       #   &lt;tt&gt;has_one&lt;/tt&gt; or &lt;tt&gt;belongs_to&lt;/tt&gt; association on the join model.
-      # * &lt;tt&gt;:source&lt;/tt&gt; - Specifies the source association name used by &lt;tt&gt;has_one :through&lt;/tt&gt; queries.  Only use it if the name cannot be
+      # [:source]
+      #   Specifies the source association name used by &lt;tt&gt;has_one :through&lt;/tt&gt; queries.  Only use it if the name cannot be
       #   inferred from the association.  &lt;tt&gt;has_one :favorite, :through =&gt; :favorites&lt;/tt&gt; will look for a
       #   &lt;tt&gt;:favorite&lt;/tt&gt; on Favorite, unless a &lt;tt&gt;:source&lt;/tt&gt; is given.      
-      # * &lt;tt&gt;:source_type&lt;/tt&gt; - Specifies type of the source association used by &lt;tt&gt;has_one :through&lt;/tt&gt; queries where the source
+      # [:source_type]
+      #   Specifies type of the source association used by &lt;tt&gt;has_one :through&lt;/tt&gt; queries where the source
       #   association is a polymorphic +belongs_to+.      
-      # * &lt;tt&gt;:readonly&lt;/tt&gt; - If true, the associated object is readonly through the association.
-      # * &lt;tt&gt;:validate&lt;/tt&gt; - If false, don't validate the associated object when saving the parent object. +false+ by default.
+      # [:readonly]
+      #   If true, the associated object is readonly through the association.
+      # [:validate]
+      #   If false, don't validate the associated object when saving the parent object. +false+ by default.
       #
       # Option examples:
       #   has_one :credit_card, :dependent =&gt; :destroy  # destroys the associated credit card
@@ -793,10 +882,10 @@ module ActiveRecord
 
           method_name = &quot;has_one_after_save_for_#{reflection.name}&quot;.to_sym
           define_method(method_name) do
-            association = instance_variable_get(&quot;#{ivar}&quot;) if instance_variable_defined?(&quot;#{ivar}&quot;)
+            association = instance_variable_get(ivar) if instance_variable_defined?(ivar)
 
-            if !association.nil? &amp;&amp; (new_record? || association.new_record? || association[&quot;#{reflection.primary_key_name}&quot;] != id)
-              association[&quot;#{reflection.primary_key_name}&quot;] = id
+            if !association.nil? &amp;&amp; (new_record? || association.new_record? || association[reflection.primary_key_name] != id)
+              association[reflection.primary_key_name] = id
               association.save(true)
             end
           end
@@ -811,18 +900,34 @@ module ActiveRecord
         end
       end
 
-      # Adds the following methods for retrieval and query for a single associated object for which this object holds an id:
-      # +association+ is replaced with the symbol passed as the first argument, so
-      # &lt;tt&gt;belongs_to :author&lt;/tt&gt; would add among others &lt;tt&gt;author.nil?&lt;/tt&gt;.
-      # * &lt;tt&gt;association(force_reload = false)&lt;/tt&gt; - Returns the associated object. +nil+ is returned if none is found.
-      # * &lt;tt&gt;association=(associate)&lt;/tt&gt; - Assigns the associate object, extracts the primary key, and sets it as the foreign key.
-      # * &lt;tt&gt;association.nil?&lt;/tt&gt; - Returns +true+ if there is no associated object.
-      # * &lt;tt&gt;build_association(attributes = {})&lt;/tt&gt; - Returns a new object of the associated type that has been instantiated
+      # Specifies a one-to-one association with another class. This method should only be used
+      # if this class contains the foreign key. If the other class contains the foreign key,
+      # then you should use +has_one+ instead. See also ActiveRecord::Associations::ClassMethods's overview
+      # on when to use +has_one+ and when to use +belongs_to+.
+      #
+      # Methods will be added for retrieval and query for a single associated object, for which
+      # this object holds an id:
+      #
+      # [association(force_reload = false)]
+      #   Returns the associated object. +nil+ is returned if none is found.
+      # [association=(associate)]
+      #   Assigns the associate object, extracts the primary key, and sets it as the foreign key.
+      # [association.nil?]
+      #   Returns +true+ if there is no associated object.
+      # [build_association(attributes = {})]
+      #   Returns a new object of the associated type that has been instantiated
       #   with +attributes+ and linked to this object through a foreign key, but has not yet been saved.
-      # * &lt;tt&gt;create_association(attributes = {})&lt;/tt&gt; - Returns a new object of the associated type that has been instantiated
-      #   with +attributes+, linked to this object through a foreign key, and that has already been saved (if it passed the validation).
+      # [create_association(attributes = {})]
+      #   Returns a new object of the associated type that has been instantiated
+      #   with +attributes+, linked to this object through a foreign key, and that
+      #   has already been saved (if it passed the validation).
+      #
+      # (+association+ is replaced with the symbol passed as the first argument, so
+      # &lt;tt&gt;belongs_to :author&lt;/tt&gt; would add among others &lt;tt&gt;author.nil?&lt;/tt&gt;.)
+      #
+      # === Example
       #
-      # Example: A Post class declares &lt;tt&gt;belongs_to :author&lt;/tt&gt;, which will add:
+      # A Post class declares &lt;tt&gt;belongs_to :author&lt;/tt&gt;, which will add:
       # * &lt;tt&gt;Post#author&lt;/tt&gt; (similar to &lt;tt&gt;Author.find(author_id)&lt;/tt&gt;)
       # * &lt;tt&gt;Post#author=(author)&lt;/tt&gt; (similar to &lt;tt&gt;post.author_id = author.id&lt;/tt&gt;)
       # * &lt;tt&gt;Post#author?&lt;/tt&gt; (similar to &lt;tt&gt;post.author == some_author&lt;/tt&gt;)
@@ -831,36 +936,45 @@ module ActiveRecord
       # * &lt;tt&gt;Post#create_author&lt;/tt&gt; (similar to &lt;tt&gt;post.author = Author.new; post.author.save; post.author&lt;/tt&gt;)
       # The declaration can also include an options hash to specialize the behavior of the association.
       #
-      # Options are:
-      # * &lt;tt&gt;:class_name&lt;/tt&gt; - Specify the class name of the association. Use it only if that name can't be inferred
+      # === Options
+      #
+      # [:class_name]
+      #   Specify the class name of the association. Use it only if that name can't be inferred
       #   from the association name. So &lt;tt&gt;has_one :author&lt;/tt&gt; will by default be linked to the Author class, but
       #   if the real class name is Person, you'll have to specify it with this option.
-      # * &lt;tt&gt;:conditions&lt;/tt&gt; - Specify the conditions that the associated object must meet in order to be included as a +WHERE+
+      # [:conditions]
+      #   Specify the conditions that the associated object must meet in order to be included as a +WHERE+
       #   SQL fragment, such as &lt;tt&gt;authorized = 1&lt;/tt&gt;.
-      # * &lt;tt&gt;:select&lt;/tt&gt; - By default, this is &lt;tt&gt;*&lt;/tt&gt; as in &lt;tt&gt;SELECT * FROM&lt;/tt&gt;, but can be changed if, for example, you want to do a join
+      # [:select]
+      #   By default, this is &lt;tt&gt;*&lt;/tt&gt; as in &lt;tt&gt;SELECT * FROM&lt;/tt&gt;, but can be changed if, for example, you want to do a join
       #   but not include the joined columns. Do not forget to include the primary and foreign keys, otherwise it will raise an error.
-      # * &lt;tt&gt;:foreign_key&lt;/tt&gt; - Specify the foreign key used for the association. By default this is guessed to be the name
+      # [:foreign_key]
+      #   Specify the foreign key used for the association. By default this is guessed to be the name
       #   of the association with an &quot;_id&quot; suffix. So a class that defines a &lt;tt&gt;belongs_to :person&lt;/tt&gt; association will use
       #   &quot;person_id&quot; as the default &lt;tt&gt;:foreign_key&lt;/tt&gt;. Similarly, &lt;tt&gt;belongs_to :favorite_person, :class_name =&gt; &quot;Person&quot;&lt;/tt&gt;
       #   will use a foreign key of &quot;favorite_person_id&quot;.
-      # * &lt;tt&gt;:dependent&lt;/tt&gt; - If set to &lt;tt&gt;:destroy&lt;/tt&gt;, the associated object is destroyed when this object is. If set to
+      # [:dependent]
+      #   If set to &lt;tt&gt;:destroy&lt;/tt&gt;, the associated object is destroyed when this object is. If set to
       #   &lt;tt&gt;:delete&lt;/tt&gt;, the associated object is deleted *without* calling its destroy method. This option should not be specified when
       #   &lt;tt&gt;belongs_to&lt;/tt&gt; is used in conjunction with a &lt;tt&gt;has_many&lt;/tt&gt; relationship on another class because of the potential to leave
       #   orphaned records behind.
-      # * &lt;tt&gt;:counter_cache&lt;/tt&gt; - Caches the number of belonging objects on the associate class through the use of +increment_counter+
+      # [:counter_cache]
+      #   Caches the number of belonging objects on the associate class through the use of +increment_counter+
       #   and +decrement_counter+. The counter cache is incremented when an object of this class is created and decremented when it's
       #   destroyed. This requires that a column named &lt;tt&gt;#{table_name}_count&lt;/tt&gt; (such as +comments_count+ for a belonging Comment class)
       #   is used on the associate class (such as a Post class). You can also specify a custom counter cache column by providing
       #   a column name instead of a +true+/+false+ value to this option (e.g., &lt;tt&gt;:counter_cache =&gt; :my_custom_counter&lt;/tt&gt;.)
-      #   When creating a counter cache column, the database statement or migration must specify a default value of &lt;tt&gt;0&lt;/tt&gt;, failing to do 
-      #   this results in a counter with +NULL+ value, which will never increment.
       #   Note: Specifying a counter cache will add it to that model's list of readonly attributes using +attr_readonly+.
-      # * &lt;tt&gt;:include&lt;/tt&gt; - Specify second-order associations that should be eager loaded when this object is loaded.
-      # * &lt;tt&gt;:polymorphic&lt;/tt&gt; - Specify this association is a polymorphic association by passing +true+.
+      # [:include]
+      #   Specify second-order associations that should be eager loaded when this object is loaded.
+      # [:polymorphic]
+      #   Specify this association is a polymorphic association by passing +true+.
       #   Note: If you've enabled the counter cache, then you may want to add the counter cache attribute
       #   to the +attr_readonly+ list in the associated classes (e.g. &lt;tt&gt;class Post; attr_readonly :comments_count; end&lt;/tt&gt;).
-      # * &lt;tt&gt;:readonly&lt;/tt&gt; - If true, the associated object is readonly through the association.
-      # * &lt;tt&gt;:validate&lt;/tt&gt; - If false, don't validate the associated objects when saving the parent object. +false+ by default.
+      # [:readonly]
+      #   If true, the associated object is readonly through the association.
+      # [:validate]
+      #   If false, don't validate the associated objects when saving the parent object. +false+ by default.
       #
       # Option examples:
       #   belongs_to :firm, :foreign_key =&gt; &quot;client_of&quot;
@@ -880,7 +994,7 @@ module ActiveRecord
 
           method_name = &quot;polymorphic_belongs_to_before_save_for_#{reflection.name}&quot;.to_sym
           define_method(method_name) do
-            association = instance_variable_get(&quot;#{ivar}&quot;) if instance_variable_defined?(&quot;#{ivar}&quot;)
+            association = instance_variable_get(ivar) if instance_variable_defined?(ivar)
 
             if association &amp;&amp; association.target
               if association.new_record?
@@ -888,8 +1002,8 @@ module ActiveRecord
               end
 
               if association.updated?
-                self[&quot;#{reflection.primary_key_name}&quot;] = association.id
-                self[&quot;#{reflection.options[:foreign_type]}&quot;] = association.class.base_class.name.to_s
+                self[reflection.primary_key_name] = association.id
+                self[reflection.options[:foreign_type]] = association.class.base_class.name.to_s
               end
             end
           end
@@ -901,7 +1015,7 @@ module ActiveRecord
 
           method_name = &quot;belongs_to_before_save_for_#{reflection.name}&quot;.to_sym
           define_method(method_name) do
-            association = instance_variable_get(&quot;#{ivar}&quot;) if instance_variable_defined?(&quot;#{ivar}&quot;)
+            association = instance_variable_get(ivar) if instance_variable_defined?(ivar)
 
             if !association.nil?
               if association.new_record?
@@ -909,7 +1023,7 @@ module ActiveRecord
               end
 
               if association.updated?
-                self[&quot;#{reflection.primary_key_name}&quot;] = association.id
+                self[reflection.primary_key_name] = association.id
               end
             end
           end
@@ -919,20 +1033,20 @@ module ActiveRecord
         # Create the callbacks to update counter cache
         if options[:counter_cache]
           cache_column = options[:counter_cache] == true ?
-            &quot;#{self.to_s.underscore.pluralize}_count&quot; :
+            &quot;#{self.to_s.demodulize.underscore.pluralize}_count&quot; :
             options[:counter_cache]
 
           method_name = &quot;belongs_to_counter_cache_after_create_for_#{reflection.name}&quot;.to_sym
           define_method(method_name) do
-            association = send(&quot;#{reflection.name}&quot;)
-            association.class.increment_counter(&quot;#{cache_column}&quot;, send(&quot;#{reflection.primary_key_name}&quot;)) unless association.nil?
+            association = send(reflection.name)
+            association.class.increment_counter(cache_column, send(reflection.primary_key_name)) unless association.nil?
           end
           after_create method_name
 
           method_name = &quot;belongs_to_counter_cache_before_destroy_for_#{reflection.name}&quot;.to_sym
           define_method(method_name) do
-            association = send(&quot;#{reflection.name}&quot;)
-            association.class.decrement_counter(&quot;#{cache_column}&quot;, send(&quot;#{reflection.primary_key_name}&quot;)) unless association.nil?
+            association = send(reflection.name)
+            association.class.decrement_counter(cache_column, send(reflection.primary_key_name)) unless association.nil?
           end
           before_destroy method_name
 
@@ -946,8 +1060,9 @@ module ActiveRecord
         configure_dependency_for_belongs_to(reflection)
       end
 
-      # Associates two classes via an intermediate join table.  Unless the join table is explicitly specified as
-      # an option, it is guessed using the lexical order of the class names. So a join between Developer and Project
+      # Specifies a many-to-many relationship with another class. This associates two classes via an
+      # intermediate join table.  Unless the join table is explicitly specified as an option, it is
+      # guessed using the lexical order of the class names. So a join between Developer and Project
       # will give the default join table name of &quot;developers_projects&quot; because &quot;D&quot; outranks &quot;P&quot;.  Note that this precedence
       # is calculated using the &lt;tt&gt;&lt;&lt;/tt&gt; operator for String.  This means that if the strings are of different lengths,
       # and the strings are equal when compared up to the shortest length, then the longer string is considered of higher
@@ -962,28 +1077,48 @@ module ActiveRecord
       # associations with attributes to a real join model (see introduction).
       #
       # Adds the following methods for retrieval and query:
-      # +collection+ is replaced with the symbol passed as the first argument, so
-      # &lt;tt&gt;has_and_belongs_to_many :categories&lt;/tt&gt; would add among others &lt;tt&gt;categories.empty?&lt;/tt&gt;.
-      # * &lt;tt&gt;collection(force_reload = false)&lt;/tt&gt; - Returns an array of all the associated objects.
+      #
+      # [collection(force_reload = false)]
+      #   Returns an array of all the associated objects.
       #   An empty array is returned if none are found.
-      # * &lt;tt&gt;collection&lt;&lt;(object, ...)&lt;/tt&gt; - Adds one or more objects to the collection by creating associations in the join table
+      # [collection&lt;&lt;(object, ...)]
+      #   Adds one or more objects to the collection by creating associations in the join table
       #   (&lt;tt&gt;collection.push&lt;/tt&gt; and &lt;tt&gt;collection.concat&lt;/tt&gt; are aliases to this method).
-      # * &lt;tt&gt;collection.delete(object, ...)&lt;/tt&gt; - Removes one or more objects from the collection by removing their associations from the join table.
+      # [collection.delete(object, ...)]
+      #   Removes one or more objects from the collection by removing their associations from the join table.
       #   This does not destroy the objects.
-      # * &lt;tt&gt;collection=objects&lt;/tt&gt; - Replaces the collection's content by deleting and adding objects as appropriate.
-      # * &lt;tt&gt;collection_singular_ids&lt;/tt&gt; - Returns an array of the associated objects' ids.
-      # * &lt;tt&gt;collection_singular_ids=ids&lt;/tt&gt; - Replace the collection by the objects identified by the primary keys in +ids+.
-      # * &lt;tt&gt;collection.clear&lt;/tt&gt; - Removes every object from the collection. This does not destroy the objects.
-      # * &lt;tt&gt;collection.empty?&lt;/tt&gt; - Returns +true+ if there are no associated objects.
-      # * &lt;tt&gt;collection.size&lt;/tt&gt; - Returns the number of associated objects.
-      # * &lt;tt&gt;collection.find(id)&lt;/tt&gt; - Finds an associated object responding to the +id+ and that
+      # [collection=objects]
+      #   Replaces the collection's content by deleting and adding objects as appropriate.
+      # [collection_singular_ids]
+      #   Returns an array of the associated objects' ids.
+      # [collection_singular_ids=ids]
+      #   Replace the collection by the objects identified by the primary keys in +ids+.
+      # [collection.clear]
+      #   Removes every object from the collection. This does not destroy the objects.
+      # [collection.empty?]
+      #   Returns +true+ if there are no associated objects.
+      # [collection.size]
+      #   Returns the number of associated objects.
+      # [collection.find(id)]
+      #   Finds an associated object responding to the +id+ and that
       #   meets the condition that it has to be associated with this object.
-      # * &lt;tt&gt;collection.build(attributes = {})&lt;/tt&gt; - Returns a new object of the collection type that has been instantiated
+      #   Uses the same rules as ActiveRecord::Base.find.
+      # [collection.exist?(...)]
+      #   Checks whether an associated object with the given conditions exists.
+      #   Uses the same rules as ActiveRecord::Base.exists?.
+      # [collection.build(attributes = {})]
+      #   Returns a new object of the collection type that has been instantiated
       #   with +attributes+ and linked to this object through the join table, but has not yet been saved.
-      # * &lt;tt&gt;collection.create(attributes = {})&lt;/tt&gt; - Returns a new object of the collection type that has been instantiated
+      # [collection.create(attributes = {})]
+      #   Returns a new object of the collection type that has been instantiated
       #   with +attributes+, linked to this object through the join table, and that has already been saved (if it passed the validation).
       #
-      # Example: A Developer class declares &lt;tt&gt;has_and_belongs_to_many :projects&lt;/tt&gt;, which will add:
+      # (+collection+ is replaced with the symbol passed as the first argument, so
+      # &lt;tt&gt;has_and_belongs_to_many :categories&lt;/tt&gt; would add among others &lt;tt&gt;categories.empty?&lt;/tt&gt;.)
+      #
+      # === Example
+      #
+      # A Developer class declares &lt;tt&gt;has_and_belongs_to_many :projects&lt;/tt&gt;, which will add:
       # * &lt;tt&gt;Developer#projects&lt;/tt&gt;
       # * &lt;tt&gt;Developer#projects&lt;&lt;&lt;/tt&gt;
       # * &lt;tt&gt;Developer#projects.delete&lt;/tt&gt;
@@ -994,44 +1129,67 @@ module ActiveRecord
       # * &lt;tt&gt;Developer#projects.empty?&lt;/tt&gt;
       # * &lt;tt&gt;Developer#projects.size&lt;/tt&gt;
       # * &lt;tt&gt;Developer#projects.find(id)&lt;/tt&gt;
+      # * &lt;tt&gt;Developer#clients.exist?(...)&lt;/tt&gt;
       # * &lt;tt&gt;Developer#projects.build&lt;/tt&gt; (similar to &lt;tt&gt;Project.new(&quot;project_id&quot; =&gt; id)&lt;/tt&gt;)
       # * &lt;tt&gt;Developer#projects.create&lt;/tt&gt; (similar to &lt;tt&gt;c = Project.new(&quot;project_id&quot; =&gt; id); c.save; c&lt;/tt&gt;)
       # The declaration may include an options hash to specialize the behavior of the association.
       #
-      # Options are:
-      # * &lt;tt&gt;:class_name&lt;/tt&gt; - Specify the class name of the association. Use it only if that name can't be inferred
+      # === Options
+      #
+      # [:class_name]
+      #   Specify the class name of the association. Use it only if that name can't be inferred
       #   from the association name. So &lt;tt&gt;has_and_belongs_to_many :projects&lt;/tt&gt; will by default be linked to the
       #   Project class, but if the real class name is SuperProject, you'll have to specify it with this option.
-      # * &lt;tt&gt;:join_table&lt;/tt&gt; - Specify the name of the join table if the default based on lexical order isn't what you want.
-      #   WARNING: If you're overwriting the table name of either class, the +table_name+ method MUST be declared underneath any
-      #   +has_and_belongs_to_many+ declaration in order to work.
-      # * &lt;tt&gt;:foreign_key&lt;/tt&gt; - Specify the foreign key used for the association. By default this is guessed to be the name
+      # [:join_table]
+      #   Specify the name of the join table if the default based on lexical order isn't what you want.
+      #   &lt;b&gt;WARNING:&lt;/b&gt; If you're overwriting the table name of either class, the +table_name+ method
+      #   MUST be declared underneath any +has_and_belongs_to_many+ declaration in order to work.
+      # [:foreign_key]
+      #   Specify the foreign key used for the association. By default this is guessed to be the name
       #   of this class in lower-case and &quot;_id&quot; suffixed. So a Person class that makes a +has_and_belongs_to_many+ association
       #   will use &quot;person_id&quot; as the default &lt;tt&gt;:foreign_key&lt;/tt&gt;.
-      # * &lt;tt&gt;:association_foreign_key&lt;/tt&gt; - Specify the association foreign key used for the association. By default this is
+      # [:association_foreign_key]
+      #   Specify the association foreign key used for the association. By default this is
       #   guessed to be the name of the associated class in lower-case and &quot;_id&quot; suffixed. So if the associated class is Project,
       #   the +has_and_belongs_to_many+ association will use &quot;project_id&quot; as the default &lt;tt&gt;:association_foreign_key&lt;/tt&gt;.
-      # * &lt;tt&gt;:conditions&lt;/tt&gt; - Specify the conditions that the associated object must meet in order to be included as a +WHERE+
+      # [:conditions]
+      #   Specify the conditions that the associated object must meet in order to be included as a +WHERE+
       #   SQL fragment, such as &lt;tt&gt;authorized = 1&lt;/tt&gt;.  Record creations from the association are scoped if a hash is used.  
       #   &lt;tt&gt;has_many :posts, :conditions =&gt; {:published =&gt; true}&lt;/tt&gt; will create published posts with &lt;tt&gt;@blog.posts.create&lt;/tt&gt; 
       #   or &lt;tt&gt;@blog.posts.build&lt;/tt&gt;.
-      # * &lt;tt&gt;:order&lt;/tt&gt; - Specify the order in which the associated objects are returned as an &lt;tt&gt;ORDER BY&lt;/tt&gt; SQL fragment,
+      # [:order]
+      #   Specify the order in which the associated objects are returned as an &lt;tt&gt;ORDER BY&lt;/tt&gt; SQL fragment,
       #   such as &lt;tt&gt;last_name, first_name DESC&lt;/tt&gt;
-      # * &lt;tt&gt;:uniq&lt;/tt&gt; - If true, duplicate associated objects will be ignored by accessors and query methods.
-      # * &lt;tt&gt;:finder_sql&lt;/tt&gt; - Overwrite the default generated SQL statement used to fetch the association with a manual statement
-      # * &lt;tt&gt;:delete_sql&lt;/tt&gt; - Overwrite the default generated SQL statement used to remove links between the associated
+      # [:uniq]
+      #   If true, duplicate associated objects will be ignored by accessors and query methods.
+      # [:finder_sql]
+      #   Overwrite the default generated SQL statement used to fetch the association with a manual statement
+      # [:counter_sql]
+      #   Specify a complete SQL statement to fetch the size of the association. If &lt;tt&gt;:finder_sql&lt;/tt&gt; is
+      #   specified but not &lt;tt&gt;:counter_sql&lt;/tt&gt;, &lt;tt&gt;:counter_sql&lt;/tt&gt; will be generated by replacing &lt;tt&gt;SELECT ... FROM&lt;/tt&gt; with &lt;tt&gt;SELECT COUNT(*) FROM&lt;/tt&gt;.
+      # [:delete_sql]
+      #   Overwrite the default generated SQL statement used to remove links between the associated
       #   classes with a manual statement.
-      # * &lt;tt&gt;:insert_sql&lt;/tt&gt; - Overwrite the default generated SQL statement used to add links between the associated classes
+      # [:insert_sql]
+      #   Overwrite the default generated SQL statement used to add links between the associated classes
       #   with a manual statement.
-      # * &lt;tt&gt;:extend&lt;/tt&gt; - Anonymous module for extending the proxy, see &quot;Association extensions&quot;.
-      # * &lt;tt&gt;:include&lt;/tt&gt; - Specify second-order associations that should be eager loaded when the collection is loaded.
-      # * &lt;tt&gt;:group&lt;/tt&gt; - An attribute name by which the result should be grouped. Uses the &lt;tt&gt;GROUP BY&lt;/tt&gt; SQL-clause.
-      # * &lt;tt&gt;:limit&lt;/tt&gt; - An integer determining the limit on the number of rows that should be returned.
-      # * &lt;tt&gt;:offset&lt;/tt&gt; - An integer determining the offset from where the rows should be fetched. So at 5, it would skip the first 4 rows.
-      # * &lt;tt&gt;:select&lt;/tt&gt; - By default, this is &lt;tt&gt;*&lt;/tt&gt; as in &lt;tt&gt;SELECT * FROM&lt;/tt&gt;, but can be changed if, for example, you want to do a join
+      # [:extend]
+      #   Anonymous module for extending the proxy, see &quot;Association extensions&quot;.
+      # [:include]
+      #   Specify second-order associations that should be eager loaded when the collection is loaded.
+      # [:group]
+      #   An attribute name by which the result should be grouped. Uses the &lt;tt&gt;GROUP BY&lt;/tt&gt; SQL-clause.
+      # [:limit]
+      #   An integer determining the limit on the number of rows that should be returned.
+      # [:offset]
+      #   An integer determining the offset from where the rows should be fetched. So at 5, it would skip the first 4 rows.
+      # [:select]
+      #   By default, this is &lt;tt&gt;*&lt;/tt&gt; as in &lt;tt&gt;SELECT * FROM&lt;/tt&gt;, but can be changed if, for example, you want to do a join
       #   but not include the joined columns. Do not forget to include the primary and foreign keys, otherwise it will raise an error.
-      # * &lt;tt&gt;:readonly&lt;/tt&gt; - If true, all the associated objects are readonly through the association.
-      # * &lt;tt&gt;:validate&lt;/tt&gt; - If false, don't validate the associated objects when saving the parent object. +true+ by default.
+      # [:readonly]
+      #   If true, all the associated objects are readonly through the association.
+      # [:validate]
+      #   If false, don't validate the associated objects when saving the parent object. +true+ by default.
       #
       # Option examples:
       #   has_and_belongs_to_many :projects
@@ -1063,12 +1221,11 @@ module ActiveRecord
       end
 
       private
-        # Generate a join table name from two provided tables names.
-        # The order of names in join name is determined by lexical precedence.
-        #   join_table_name(&quot;members&quot;, &quot;clubs&quot;)
-        #   =&gt; &quot;clubs_members&quot;
-        #   join_table_name(&quot;members&quot;, &quot;special_clubs&quot;)
-        #   =&gt; &quot;members_special_clubs&quot;
+        # Generates a join table name from two provided table names.
+        # The names in the join table namesme end up in lexicographic order.
+        #
+        #   join_table_name(&quot;members&quot;, &quot;clubs&quot;)         # =&gt; &quot;clubs_members&quot;
+        #   join_table_name(&quot;members&quot;, &quot;special_clubs&quot;) # =&gt; &quot;members_special_clubs&quot;
         def join_table_name(first_table_name, second_table_name)
           if first_table_name &lt; second_table_name
             join_table = &quot;#{first_table_name}_#{second_table_name}&quot;
@@ -1100,6 +1257,11 @@ module ActiveRecord
             association.target.nil? ? nil : association
           end
 
+          define_method(&quot;loaded_#{reflection.name}?&quot;) do
+            association = instance_variable_get(ivar) if instance_variable_defined?(ivar)
+            association &amp;&amp; association.loaded?
+          end
+
           define_method(&quot;#{reflection.name}=&quot;) do |new_value|
             association = instance_variable_get(ivar) if instance_variable_defined?(ivar)
 
@@ -1142,7 +1304,11 @@ module ActiveRecord
           end
 
           define_method(&quot;#{reflection.name.to_s.singularize}_ids&quot;) do
-            send(reflection.name).map(&amp;:id)
+            if send(reflection.name).loaded? || reflection.options[:finder_sql]
+              send(reflection.name).map(&amp;:id)
+            else
+              send(reflection.name).all(:select =&gt; &quot;#{reflection.quoted_table_name}.#{reflection.klass.primary_key}&quot;).map(&amp;:id)
+            end
           end
         end
 
@@ -1163,19 +1329,19 @@ module ActiveRecord
             end
           end
         end
-        
+
         def add_single_associated_validation_callbacks(association_name)
           method_name = &quot;validate_associated_records_for_#{association_name}&quot;.to_sym
           define_method(method_name) do
             association = instance_variable_get(&quot;@#{association_name}&quot;)
             if !association.nil?
-              errors.add &quot;#{association_name}&quot; unless association.target.nil? || association.valid?
+              errors.add association_name unless association.target.nil? || association.valid?
             end
           end
-        
+
           validate method_name
         end
-        
+
         def add_multiple_associated_validation_callbacks(association_name)
           method_name = &quot;validate_associated_records_for_#{association_name}&quot;.to_sym
           ivar = &quot;@#{association_name}&quot;
@@ -1191,7 +1357,7 @@ module ActiveRecord
               else
                 association.target.select { |record| record.new_record? }
               end.each do |record|
-                errors.add &quot;#{association_name}&quot; unless record.valid?
+                errors.add association_name unless record.valid?
               end
             end
           end
@@ -1211,7 +1377,7 @@ module ActiveRecord
 
           method_name = &quot;after_create_or_update_associated_records_for_#{association_name}&quot;.to_sym
           define_method(method_name) do
-            association = instance_variable_get(&quot;#{ivar}&quot;) if instance_variable_defined?(&quot;#{ivar}&quot;)
+            association = instance_variable_get(ivar) if instance_variable_defined?(ivar)
 
             records_to_save = if @new_record_before_save
               association
@@ -1263,56 +1429,85 @@ module ActiveRecord
           []
         end
 
+        # Creates before_destroy callback methods that nullify, delete or destroy
+        # has_many associated objects, according to the defined :dependent rule.
+        #
         # See HasManyAssociation#delete_records.  Dependent associations
         # delete children, otherwise foreign key is set to NULL.
-        def configure_dependency_for_has_many(reflection)
+        #
+        # The +extra_conditions+ parameter, which is not used within the main
+        # Active Record codebase, is meant to allow plugins to define extra
+        # finder conditions.
+        def configure_dependency_for_has_many(reflection, extra_conditions = nil)
           if reflection.options.include?(:dependent)
             # Add polymorphic type if the :as option is present
             dependent_conditions = []
             dependent_conditions &lt;&lt; &quot;#{reflection.primary_key_name} = \#{record.quoted_id}&quot;
             dependent_conditions &lt;&lt; &quot;#{reflection.options[:as]}_type = '#{base_class.name}'&quot; if reflection.options[:as]
             dependent_conditions &lt;&lt; sanitize_sql(reflection.options[:conditions]) if reflection.options[:conditions]
+            dependent_conditions &lt;&lt; extra_conditions if extra_conditions
             dependent_conditions = dependent_conditions.collect {|where| &quot;(#{where})&quot; }.join(&quot; AND &quot;)
 
             case reflection.options[:dependent]
               when :destroy
                 method_name = &quot;has_many_dependent_destroy_for_#{reflection.name}&quot;.to_sym
                 define_method(method_name) do
-                  send(&quot;#{reflection.name}&quot;).each { |o| o.destroy }
+                  send(reflection.name).each { |o| o.destroy }
                 end
                 before_destroy method_name
               when :delete_all
-                module_eval &quot;before_destroy { |record| #{reflection.class_name}.delete_all(%(#{dependent_conditions})) }&quot;
+                module_eval %Q{
+                  before_destroy do |record|
+                    delete_all_has_many_dependencies(record,
+                      &quot;#{reflection.name}&quot;,
+                      #{reflection.class_name},
+                      &quot;#{dependent_conditions}&quot;)
+                  end
+                }
               when :nullify
-                module_eval &quot;before_destroy { |record| #{reflection.class_name}.update_all(%(#{reflection.primary_key_name} = NULL),  %(#{dependent_conditions})) }&quot;
+                module_eval %Q{
+                  before_destroy do |record|
+                    nullify_has_many_dependencies(record,
+                      &quot;#{reflection.name}&quot;,
+                      #{reflection.class_name},
+                      &quot;#{reflection.primary_key_name}&quot;,
+                      &quot;#{dependent_conditions}&quot;)
+                  end
+                }
               else
                 raise ArgumentError, &quot;The :dependent option expects either :destroy, :delete_all, or :nullify (#{reflection.options[:dependent].inspect})&quot;
             end
           end
         end
 
+        # Creates before_destroy callback methods that nullify, delete or destroy
+        # has_one associated objects, according to the defined :dependent rule.
         def configure_dependency_for_has_one(reflection)
           if reflection.options.include?(:dependent)
             case reflection.options[:dependent]
               when :destroy
                 method_name = &quot;has_one_dependent_destroy_for_#{reflection.name}&quot;.to_sym
                 define_method(method_name) do
-                  association = send(&quot;#{reflection.name}&quot;)
+                  association = send(reflection.name)
                   association.destroy unless association.nil?
                 end
                 before_destroy method_name
               when :delete
                 method_name = &quot;has_one_dependent_delete_for_#{reflection.name}&quot;.to_sym
                 define_method(method_name) do
-                  association = send(&quot;#{reflection.name}&quot;)
-                  association.class.delete(association.id) unless association.nil?
+                  # Retrieve the associated object and delete it. The retrieval
+                  # is necessary because there may be multiple associated objects
+                  # with foreign keys pointing to this object, and we only want
+                  # to delete the correct one, not all of them.
+                  association = send(reflection.name)
+                  association.delete unless association.nil?
                 end
                 before_destroy method_name
               when :nullify
                 method_name = &quot;has_one_dependent_nullify_for_#{reflection.name}&quot;.to_sym
                 define_method(method_name) do
-                  association = send(&quot;#{reflection.name}&quot;)
-                  association.update_attribute(&quot;#{reflection.primary_key_name}&quot;, nil) unless association.nil?
+                  association = send(reflection.name)
+                  association.update_attribute(reflection.primary_key_name, nil) unless association.nil?
                 end
                 before_destroy method_name
               else
@@ -1327,15 +1522,15 @@ module ActiveRecord
               when :destroy
                 method_name = &quot;belongs_to_dependent_destroy_for_#{reflection.name}&quot;.to_sym
                 define_method(method_name) do
-                  association = send(&quot;#{reflection.name}&quot;)
+                  association = send(reflection.name)
                   association.destroy unless association.nil?
                 end
                 before_destroy method_name
               when :delete
                 method_name = &quot;belongs_to_dependent_delete_for_#{reflection.name}&quot;.to_sym
                 define_method(method_name) do
-                  association = send(&quot;#{reflection.name}&quot;)
-                  association.class.delete(association.id) unless association.nil?
+                  association = send(reflection.name)
+                  association.delete unless association.nil?
                 end
                 before_destroy method_name
               else
@@ -1344,32 +1539,46 @@ module ActiveRecord
           end
         end
 
-        def create_has_many_reflection(association_id, options, &amp;extension)
-          options.assert_valid_keys(
-            :class_name, :table_name, :foreign_key,
-            :dependent,
-            :select, :conditions, :include, :order, :group, :limit, :offset,
-            :as, :through, :source, :source_type,
-            :uniq,
-            :finder_sql, :counter_sql,
-            :before_add, :after_add, :before_remove, :after_remove,
-            :extend, :readonly,
-            :validate
-          )
+        def delete_all_has_many_dependencies(record, reflection_name, association_class, dependent_conditions)
+          association_class.delete_all(dependent_conditions)
+        end
 
+        def nullify_has_many_dependencies(record, reflection_name, association_class, primary_key_name, dependent_conditions)
+          association_class.update_all(&quot;#{primary_key_name} = NULL&quot;, dependent_conditions)
+        end
+
+        mattr_accessor :valid_keys_for_has_many_association
+        @@valid_keys_for_has_many_association = [
+          :class_name, :table_name, :foreign_key, :primary_key,
+          :dependent,
+          :select, :conditions, :include, :order, :group, :limit, :offset,
+          :as, :through, :source, :source_type,
+          :uniq,
+          :finder_sql, :counter_sql,
+          :before_add, :after_add, :before_remove, :after_remove,
+          :extend, :readonly,
+          :validate
+        ]
+
+        def create_has_many_reflection(association_id, options, &amp;extension)
+          options.assert_valid_keys(valid_keys_for_has_many_association)
           options[:extend] = create_extension_modules(association_id, extension, options[:extend])
 
           create_reflection(:has_many, association_id, options, self)
         end
 
-        def create_has_one_reflection(association_id, options)
-          options.assert_valid_keys(
-            :class_name, :foreign_key, :remote, :select, :conditions, :order, :include, :dependent, :counter_cache, :extend, :as, :readonly, :validate
-          )
+        mattr_accessor :valid_keys_for_has_one_association
+        @@valid_keys_for_has_one_association = [
+          :class_name, :foreign_key, :remote, :select, :conditions, :order,
+          :include, :dependent, :counter_cache, :extend, :as, :readonly,
+          :validate, :primary_key
+        ]
 
+        def create_has_one_reflection(association_id, options)
+          options.assert_valid_keys(valid_keys_for_has_one_association)
           create_reflection(:has_one, association_id, options, self)
         end
-        
+
         def create_has_one_through_reflection(association_id, options)
           options.assert_valid_keys(
             :class_name, :foreign_key, :remote, :select, :conditions, :order, :include, :dependent, :counter_cache, :extend, :as, :through, :source, :source_type, :validate
@@ -1377,12 +1586,15 @@ module ActiveRecord
           create_reflection(:has_one, association_id, options, self)
         end
 
-        def create_belongs_to_reflection(association_id, options)
-          options.assert_valid_keys(
-            :class_name, :foreign_key, :foreign_type, :remote, :select, :conditions, :include, :dependent,
-            :counter_cache, :extend, :polymorphic, :readonly, :validate
-          )
+        mattr_accessor :valid_keys_for_belongs_to_association
+        @@valid_keys_for_belongs_to_association = [
+          :class_name, :foreign_key, :foreign_type, :remote, :select, :conditions,
+          :include, :dependent, :counter_cache, :extend, :polymorphic, :readonly,
+          :validate
+        ]
 
+        def create_belongs_to_reflection(association_id, options)
+          options.assert_valid_keys(valid_keys_for_belongs_to_association)
           reflection = create_reflection(:belongs_to, association_id, options, self)
 
           if options[:polymorphic]
@@ -1392,16 +1604,19 @@ module ActiveRecord
           reflection
         end
 
+        mattr_accessor :valid_keys_for_has_and_belongs_to_many_association
+        @@valid_keys_for_has_and_belongs_to_many_association = [
+          :class_name, :table_name, :join_table, :foreign_key, :association_foreign_key,
+          :select, :conditions, :include, :order, :group, :limit, :offset,
+          :uniq,
+          :finder_sql, :counter_sql, :delete_sql, :insert_sql,
+          :before_add, :after_add, :before_remove, :after_remove,
+          :extend, :readonly,
+          :validate
+        ]
+
         def create_has_and_belongs_to_many_reflection(association_id, options, &amp;extension)
-          options.assert_valid_keys(
-            :class_name, :table_name, :join_table, :foreign_key, :association_foreign_key,
-            :select, :conditions, :include, :order, :group, :limit, :offset,
-            :uniq,
-            :finder_sql, :delete_sql, :insert_sql,
-            :before_add, :after_add, :before_remove, :after_remove,
-            :extend, :readonly,
-            :validate
-          )
+          options.assert_valid_keys(valid_keys_for_has_and_belongs_to_many_association)
 
           options[:extend] = create_extension_modules(association_id, extension, options[:extend])
 
@@ -1437,7 +1652,7 @@ module ActiveRecord
           sql = &quot;SELECT #{column_aliases(join_dependency)} FROM #{(scope &amp;&amp; scope[:from]) || options[:from] || quoted_table_name} &quot;
           sql &lt;&lt; join_dependency.join_associations.collect{|join| join.association_join }.join
 
-          add_joins!(sql, options, scope)
+          add_joins!(sql, options[:joins], scope)
           add_conditions!(sql, options[:conditions], scope)
           add_limited_ids_condition!(sql, options, join_dependency) if !using_limitable_reflections?(join_dependency.reflections) &amp;&amp; ((scope &amp;&amp; scope[:limit]) || options[:limit])
 
@@ -1492,8 +1707,8 @@ module ActiveRecord
           sql &lt;&lt; &quot; FROM #{connection.quote_table_name table_name} &quot;
 
           if is_distinct
-            sql &lt;&lt; distinct_join_associations.collect(&amp;:association_join).join
-            add_joins!(sql, options, scope)
+            sql &lt;&lt; distinct_join_associations.collect { |assoc| assoc.association_join }.join
+            add_joins!(sql, options[:joins], scope)
           end
 
           add_conditions!(sql, options[:conditions], scope)
@@ -1581,12 +1796,12 @@ module ActiveRecord
 
         def create_extension_modules(association_id, block_extension, extensions)
           if block_extension
-            extension_module_name = &quot;#{self.to_s}#{association_id.to_s.camelize}AssociationExtension&quot;
+            extension_module_name = &quot;#{self.to_s.demodulize}#{association_id.to_s.camelize}AssociationExtension&quot;
 
             silence_warnings do
-              Object.const_set(extension_module_name, Module.new(&amp;block_extension))
+              self.parent.const_set(extension_module_name, Module.new(&amp;block_extension))
             end
-            Array(extensions).push(extension_module_name.constantize)
+            Array(extensions).push(&quot;#{self.parent}::#{extension_module_name}&quot;.constantize)
           else
             Array(extensions)
           end
@@ -1761,7 +1976,7 @@ module ActiveRecord
             end
 
             def aliased_primary_key
-              &quot;#{ aliased_prefix }_r0&quot;
+              &quot;#{aliased_prefix}_r0&quot;
             end
 
             def aliased_table_name
@@ -1773,7 +1988,7 @@ module ActiveRecord
                 @column_names_with_alias = []
 
                 ([primary_key] + (column_names - [primary_key])).each_with_index do |column_name, i|
-                  @column_names_with_alias &lt;&lt; [column_name, &quot;#{ aliased_prefix }_r#{ i }&quot;]
+                  @column_names_with_alias &lt;&lt; [column_name, &quot;#{aliased_prefix}_r#{i}&quot;]
                 end
               end
 
@@ -1810,11 +2025,11 @@ module ActiveRecord
               @aliased_prefix     = &quot;t#{ join_dependency.joins.size }&quot;
               @parent_table_name  = parent.active_record.table_name
               @aliased_table_name = aliased_table_name_for(table_name)
-              
+
               if reflection.macro == :has_and_belongs_to_many
                 @aliased_join_table_name = aliased_table_name_for(reflection.options[:join_table], &quot;_join&quot;)
               end
-        
+
               if [:has_many, :has_one].include?(reflection.macro) &amp;&amp; reflection.options[:through]
                 @aliased_join_table_name = aliased_table_name_for(reflection.through_reflection.klass.table_name, &quot;_join&quot;)
               end
@@ -1951,7 +2166,7 @@ module ActiveRecord
             end
 
             protected
-            
+
               def aliased_table_name_for(name, suffix = nil)
                 if !parent.table_joins.blank? &amp;&amp; parent.table_joins.to_s.downcase =~ %r{join(\s+\w+)?\s+#{name.downcase}\son}
                   @join_dependency.table_aliases[name] += 1
@@ -1969,7 +2184,7 @@ module ActiveRecord
 
                 name
               end
-              
+
               def pluralize(table_name)
                 ActiveRecord::Base.pluralize_table_names ? table_name.to_s.pluralize : table_name
               end</diff>
      <filename>vendor/activerecord/lib/active_record/associations.rb</filename>
    </modified>
    <modified>
      <diff>@@ -2,6 +2,19 @@ require 'set'
 
 module ActiveRecord
   module Associations
+    # AssociationCollection is an abstract class that provides common stuff to
+    # ease the implementation of association proxies that represent
+    # collections. See the class hierarchy in AssociationProxy.
+    #
+    # You need to be careful with assumptions regarding the target: The proxy
+    # does not fetch records from the database until it needs them, but new
+    # ones created with +build+ are added to the target. So, the target may be
+    # non-empty and still lack children waiting to be read from the database.
+    # If you look directly to the database you cannot assume that's the entire
+    # collection because new records may have beed added to the target, etc.
+    #
+    # If you need to work on all current children, new and existing records,
+    # +load_target+ and the +loaded+ flag are your friends.
     class AssociationCollection &lt; AssociationProxy #:nodoc:
       def initialize(owner, reflection)
         super
@@ -14,7 +27,7 @@ module ActiveRecord
         # If using a custom finder_sql, scan the entire collection.
         if @reflection.options[:finder_sql]
           expects_array = args.first.kind_of?(Array)
-          ids           = args.flatten.compact.uniq.map(&amp;:to_i)
+          ids           = args.flatten.compact.uniq.map { |arg| arg.to_i }
 
           if ids.size == 1
             id = ids.first
@@ -50,7 +63,7 @@ module ActiveRecord
       
       # Fetches the first one using SQL if possible.
       def first(*args)
-        if fetch_first_or_last_using_find? args
+        if fetch_first_or_last_using_find?(args)
           find(:first, *args)
         else
           load_target unless loaded?
@@ -60,7 +73,7 @@ module ActiveRecord
 
       # Fetches the last one using SQL if possible.
       def last(*args)
-        if fetch_first_or_last_using_find? args
+        if fetch_first_or_last_using_find?(args)
           find(:last, *args)
         else
           load_target unless loaded?
@@ -95,7 +108,7 @@ module ActiveRecord
         result = true
         load_target if @owner.new_record?
 
-        @owner.transaction do
+        transaction do
           flatten_deeper(records).each do |record|
             raise_on_type_mismatch(record)
             add_record_to_target_with_callbacks(record) do |r|
@@ -110,6 +123,21 @@ module ActiveRecord
       alias_method :push, :&lt;&lt;
       alias_method :concat, :&lt;&lt;
 
+      # Starts a transaction in the association class's database connection.
+      #
+      #   class Author &lt; ActiveRecord::Base
+      #     has_many :books
+      #   end
+      #
+      #   Author.find(:first).books.transaction do
+      #     # same effect as calling Book.transaction
+      #   end
+      def transaction(*args)
+        @reflection.klass.transaction(*args) do
+          yield
+        end
+      end
+
       # Remove all records from this association
       def delete_all
         load_target
@@ -126,12 +154,47 @@ module ActiveRecord
         end
       end
 
-      # Remove +records+ from this association.  Does not destroy +records+.
+      # Count all records using SQL. If the +:counter_sql+ option is set for the association, it will
+      # be used for the query. If no +:counter_sql+ was supplied, but +:finder_sql+ was set, the
+      # descendant's +construct_sql+ method will have set :counter_sql automatically.
+      # Otherwise, construct options and pass them with scope to the target class's +count+.
+      def count(*args)
+        if @reflection.options[:counter_sql]
+          @reflection.klass.count_by_sql(@counter_sql)
+        else
+          column_name, options = @reflection.klass.send(:construct_count_options_from_args, *args)
+          if @reflection.options[:uniq]
+            # This is needed because 'SELECT count(DISTINCT *)..' is not valid SQL.
+            column_name = &quot;#{@reflection.quoted_table_name}.#{@reflection.klass.primary_key}&quot; if column_name == :all
+            options.merge!(:distinct =&gt; true)
+          end
+
+          value = @reflection.klass.send(:with_scope, construct_scope) { @reflection.klass.count(column_name, options) }
+
+          limit  = @reflection.options[:limit]
+          offset = @reflection.options[:offset]
+
+          if limit || offset
+            [ [value - offset.to_i, 0].max, limit.to_i ].min
+          else
+            value
+          end
+        end
+      end
+
+
+      # Removes +records+ from this association calling +before_remove+ and
+      # +after_remove+ callbacks.
+      #
+      # This method is abstract in the sense that +delete_records+ has to be
+      # provided by descendants. Note this method does not imply the records
+      # are actually removed from the database, that depends precisely on
+      # +delete_records+. They are in any case removed from the collection.
       def delete(*records)
         records = flatten_deeper(records)
         records.each { |record| raise_on_type_mismatch(record) }
         
-        @owner.transaction do
+        transaction do
           records.each { |record| callback(:before_remove, record) }
           
           old_records = records.reject {|r| r.new_record? }
@@ -158,7 +221,7 @@ module ActiveRecord
       end
       
       def destroy_all
-        @owner.transaction do
+        transaction do
           each { |record| record.destroy }
         end
 
@@ -183,12 +246,21 @@ module ActiveRecord
         end
       end
 
-      # Returns the size of the collection by executing a SELECT COUNT(*) query if the collection hasn't been loaded and
-      # calling collection.size if it has. If it's more likely than not that the collection does have a size larger than zero
-      # and you need to fetch that collection afterwards, it'll take one less SELECT query if you use length.
+      # Returns the size of the collection by executing a SELECT COUNT(*)
+      # query if the collection hasn't been loaded, and calling
+      # &lt;tt&gt;collection.size&lt;/tt&gt; if it has.
+      #
+      # If the collection has been already loaded +size+ and +length+ are
+      # equivalent. If not and you are going to need the records anyway
+      # +length+ will take one less query. Otherwise +size+ is more efficient.
+      #
+      # This method is abstract in the sense that it relies on
+      # +count_records+, which is a method descendants have to provide.
       def size
         if @owner.new_record? || (loaded? &amp;&amp; !@reflection.options[:uniq])
           @target.size
+        elsif !loaded? &amp;&amp; @reflection.options[:group]
+          load_target.size
         elsif !loaded? &amp;&amp; !@reflection.options[:uniq] &amp;&amp; @target.is_a?(Array)
           unsaved_records = @target.select { |r| r.new_record? }
           unsaved_records.size + count_records
@@ -197,12 +269,18 @@ module ActiveRecord
         end
       end
 
-      # Returns the size of the collection by loading it and calling size on the array. If you want to use this method to check
-      # whether the collection is empty, use collection.length.zero? instead of collection.empty?
+      # Returns the size of the collection calling +size+ on the target.
+      #
+      # If the collection has been already loaded +length+ and +size+ are
+      # equivalent. If not and you are going to need the records anyway this
+      # method will take one less query. Otherwise +size+ is more efficient.
       def length
         load_target.size
       end
 
+      # Equivalent to &lt;tt&gt;collection.size.zero?&lt;/tt&gt;. If the collection has
+      # not been already loaded and you are going to fetch the records anyway
+      # it is better to check &lt;tt&gt;collection.length.zero?&lt;/tt&gt;.
       def empty?
         size.zero?
       end
@@ -235,7 +313,7 @@ module ActiveRecord
         other   = other_array.size &lt; 100 ? other_array : other_array.to_set
         current = @target.size &lt; 100 ? @target : @target.to_set
 
-        @owner.transaction do
+        transaction do
           delete(@target.select { |v| !other.include?(v) })
           concat(other_array.select { |v| !current.include?(v) })
         end
@@ -248,6 +326,10 @@ module ActiveRecord
         exists?(record)
       end
 
+      def proxy_respond_to?(method, include_private = false)
+        super || @reflection.klass.respond_to?(method, include_private)
+      end
+
       protected
         def construct_find_options!(options)
         end
@@ -316,7 +398,9 @@ module ActiveRecord
         def create_record(attrs)
           attrs.update(@reflection.options[:conditions]) if @reflection.options[:conditions].is_a?(Hash)
           ensure_owner_is_not_new
-          record = @reflection.klass.send(:with_scope, :create =&gt; construct_scope[:create]) { @reflection.klass.new(attrs) }
+          record = @reflection.klass.send(:with_scope, :create =&gt; construct_scope[:create]) do
+            @reflection.build_association(attrs)
+          end
           if block_given?
             add_record_to_target_with_callbacks(record) { |*block_args| yield(*block_args) }
           else
@@ -326,7 +410,7 @@ module ActiveRecord
 
         def build_record(attrs)
           attrs.update(@reflection.options[:conditions]) if @reflection.options[:conditions].is_a?(Hash)
-          record = @reflection.klass.new(attrs)
+          record = @reflection.build_association(attrs)
           if block_given?
             add_record_to_target_with_callbacks(record) { |*block_args| yield(*block_args) }
           else
@@ -361,7 +445,8 @@ module ActiveRecord
         end
 
         def fetch_first_or_last_using_find?(args)
-          args.first.kind_of?(Hash) || !(loaded? || @owner.new_record? || @reflection.options[:finder_sql] || !@target.blank? || args.first.kind_of?(Integer))
+          args.first.kind_of?(Hash) || !(loaded? || @owner.new_record? || @reflection.options[:finder_sql] ||
+                                         @target.any? { |record| record.new_record? } || args.first.kind_of?(Integer))
         end
     end
   end</diff>
      <filename>vendor/activerecord/lib/active_record/associations/association_collection.rb</filename>
    </modified>
    <modified>
      <diff>@@ -39,7 +39,7 @@ module ActiveRecord
     # though the object behind &lt;tt&gt;blog.posts&lt;/tt&gt; is not an Array, but an
     # ActiveRecord::Associations::HasManyAssociation.
     #
-    # The &lt;tt&gt;@target&lt;/tt&gt; object is not loaded until needed. For example,
+    # The &lt;tt&gt;@target&lt;/tt&gt; object is not \loaded until needed. For example,
     #
     #   blog.posts.count
     #
@@ -57,76 +57,109 @@ module ActiveRecord
         reset
       end
 
+      # Returns the owner of the proxy.
       def proxy_owner
         @owner
       end
 
+      # Returns the reflection object that represents the association handled
+      # by the proxy.
       def proxy_reflection
         @reflection
       end
 
+      # Returns the \target of the proxy, same as +target+.
       def proxy_target
         @target
       end
 
+      # Does the proxy or its \target respond to +symbol+?
       def respond_to?(*args)
         proxy_respond_to?(*args) || (load_target &amp;&amp; @target.respond_to?(*args))
       end
 
-      # Explicitly proxy === because the instance method removal above
-      # doesn't catch it.
+      # Forwards &lt;tt&gt;===&lt;/tt&gt; explicitly to the \target because the instance method
+      # removal above doesn't catch it. Loads the \target if needed.
       def ===(other)
         load_target
         other === @target
       end
 
+      # Returns the name of the table of the related class:
+      #
+      #   post.comments.aliased_table_name # =&gt; &quot;comments&quot;
+      #
       def aliased_table_name
         @reflection.klass.table_name
       end
 
+      # Returns the SQL string that corresponds to the &lt;tt&gt;:conditions&lt;/tt&gt;
+      # option of the macro, if given, or +nil+ otherwise.
       def conditions
-        @conditions ||= interpolate_sql(sanitize_sql(@reflection.options[:conditions])) if @reflection.options[:conditions]
+        @conditions ||= interpolate_sql(@reflection.sanitized_conditions) if @reflection.sanitized_conditions
       end
       alias :sql_conditions :conditions
 
+      # Resets the \loaded flag to +false+ and sets the \target to +nil+.
       def reset
         @loaded = false
         @target = nil
       end
 
+      # Reloads the \target and returns +self+ on success.
       def reload
         reset
         load_target
         self unless @target.nil?
       end
 
+      # Has the \target been already \loaded?
       def loaded?
         @loaded
       end
 
+      # Asserts the \target has been loaded setting the \loaded flag to +true+.
       def loaded
         @loaded = true
       end
 
+      # Returns the target of this proxy, same as +proxy_target+.
       def target
         @target
       end
 
+      # Sets the target of this proxy to &lt;tt&gt;\target&lt;/tt&gt;, and the \loaded flag to +true+.
       def target=(target)
         @target = target
         loaded
       end
 
+      # Forwards the call to the target. Loads the \target if needed.
       def inspect
         load_target
         @target.inspect
       end
 
+      def send(method, *args)
+        if proxy_respond_to?(method)
+          super
+        else
+          load_target
+          @target.send(method, *args)
+        end
+      end
+
       protected
+        # Does the association have a &lt;tt&gt;:dependent&lt;/tt&gt; option?
         def dependent?
           @reflection.options[:dependent]
         end
 
+        # Returns a string with the IDs of +records+ joined with a comma, quoted
+        # if needed. The result is ready to be inserted into a SQL IN clause.
+        #
+        #   quoted_record_ids(records) # =&gt; &quot;23,56,58,67&quot;
+        #
         def quoted_record_ids(records)
           records.map { |record| record.quoted_id }.join(',')
         end
@@ -135,10 +168,13 @@ module ActiveRecord
           @owner.send(:interpolate_sql, sql, record)
         end
 
+        # Forwards the call to the reflection class.
         def sanitize_sql(sql)
           @reflection.klass.send(:sanitize_sql, sql)
         end
 
+        # Assigns the ID of the owner to the corresponding foreign key in +record+.
+        # If the association is polymorphic the type of the owner is also set.
         def set_belongs_to_association_for(record)
           if @reflection.options[:as]
             record[&quot;#{@reflection.options[:as]}_id&quot;]   = @owner.id unless @owner.new_record?
@@ -148,6 +184,7 @@ module ActiveRecord
           end
         end
 
+        # Merges into +options+ the ones coming from the reflection.
         def merge_options_from_reflection!(options)
           options.reverse_merge!(
             :group   =&gt; @reflection.options[:group],
@@ -160,13 +197,17 @@ module ActiveRecord
           )
         end
 
+        # Forwards +with_scope+ to the reflection.
         def with_scope(*args, &amp;block)
           @reflection.klass.send :with_scope, *args, &amp;block
         end
 
       private
+        # Forwards any missing method call to the \target.
         def method_missing(method, *args)
           if load_target
+            raise NoMethodError unless @target.respond_to?(method)
+
             if block_given?
               @target.send(method, *args)  { |*block_args| yield(*block_args) }
             else
@@ -175,16 +216,16 @@ module ActiveRecord
           end
         end
 
-        # Loads the target if needed and returns it.
+        # Loads the \target if needed and returns it.
         #
         # This method is abstract in the sense that it relies on +find_target+,
         # which is expected to be provided by descendants.
         #
-        # If the target is already loaded it is just returned. Thus, you can call
-        # +load_target+ unconditionally to get the target.
+        # If the \target is already \loaded it is just returned. Thus, you can call
+        # +load_target+ unconditionally to get the \target.
         #
         # ActiveRecord::RecordNotFound is rescued within the method, and it is
-        # not reraised. The proxy is reset and +nil+ is the return value.
+        # not reraised. The proxy is \reset and +nil+ is the return value.
         def load_target
           return nil unless defined?(@loaded)
 
@@ -198,22 +239,33 @@ module ActiveRecord
           reset
         end
 
-        # Can be overwritten by associations that might have the foreign key available for an association without
-        # having the object itself (and still being a new record). Currently, only belongs_to presents this scenario.
+        # Can be overwritten by associations that might have the foreign key
+        # available for an association without having the object itself (and
+        # still being a new record). Currently, only +belongs_to+ presents
+        # this scenario (both vanilla and polymorphic).
         def foreign_key_present
           false
         end
 
+        # Raises ActiveRecord::AssociationTypeMismatch unless +record+ is of
+        # the kind of the class of the associated objects. Meant to be used as
+        # a sanity check when you are about to assign an associated record.
         def raise_on_type_mismatch(record)
-          unless record.is_a?(@reflection.klass)
+          unless record.is_a?(@reflection.klass) || record.is_a?(@reflection.class_name.constantize)
             message = &quot;#{@reflection.class_name}(##{@reflection.klass.object_id}) expected, got #{record.class}(##{record.class.object_id})&quot;
             raise ActiveRecord::AssociationTypeMismatch, message
           end
         end
 
-        # Array#flatten has problems with recursive arrays. Going one level deeper solves the majority of the problems.
+        # Array#flatten has problems with recursive arrays. Going one level
+        # deeper solves the majority of the problems.
         def flatten_deeper(array)
-          array.collect { |element| element.respond_to?(:flatten) ? element.flatten : element }.flatten
+          array.collect { |element| (element.respond_to?(:flatten) &amp;&amp; !element.is_a?(Hash)) ? element.flatten : element }.flatten
+        end
+
+        # Returns the ID of the owner, quoted if needed.
+        def owner_quoted_id
+          @owner.quoted_id
         end
     end
   end</diff>
      <filename>vendor/activerecord/lib/active_record/associations/association_proxy.rb</filename>
    </modified>
    <modified>
      <diff>@@ -2,11 +2,11 @@ module ActiveRecord
   module Associations
     class BelongsToAssociation &lt; AssociationProxy #:nodoc:
       def create(attributes = {})
-        replace(@reflection.klass.create(attributes))
+        replace(@reflection.create_association(attributes))
       end
 
       def build(attributes = {})
-        replace(@reflection.klass.new(attributes))
+        replace(@reflection.build_association(attributes))
       end
 
       def replace(record)</diff>
      <filename>vendor/activerecord/lib/active_record/associations/belongs_to_association.rb</filename>
    </modified>
    <modified>
      <filename>vendor/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb</filename>
    </modified>
    <modified>
      <diff>@@ -37,7 +37,7 @@ module ActiveRecord
             attributes = columns.inject({}) do |attrs, column|
               case column.name.to_s
                 when @reflection.primary_key_name.to_s
-                  attrs[column.name] = @owner.quoted_id
+                  attrs[column.name] = owner_quoted_id
                 when @reflection.association_foreign_key.to_s
                   attrs[column.name] = record.quoted_id
                 else
@@ -64,7 +64,7 @@ module ActiveRecord
             records.each { |record| @owner.connection.delete(interpolate_sql(sql, record)) }
           else
             ids = quoted_record_ids(records)
-            sql = &quot;DELETE FROM #{@owner.connection.quote_table_name @reflection.options[:join_table]} WHERE #{@reflection.primary_key_name} = #{@owner.quoted_id} AND #{@reflection.association_foreign_key} IN (#{ids})&quot;
+            sql = &quot;DELETE FROM #{@owner.connection.quote_table_name @reflection.options[:join_table]} WHERE #{@reflection.primary_key_name} = #{owner_quoted_id} AND #{@reflection.association_foreign_key} IN (#{ids})&quot;
             @owner.connection.delete(sql)
           end
         end
@@ -73,11 +73,21 @@ module ActiveRecord
           if @reflection.options[:finder_sql]
             @finder_sql = interpolate_sql(@reflection.options[:finder_sql])
           else
-            @finder_sql = &quot;#{@owner.connection.quote_table_name @reflection.options[:join_table]}.#{@reflection.primary_key_name} = #{@owner.quoted_id} &quot;
+            @finder_sql = &quot;#{@owner.connection.quote_table_name @reflection.options[:join_table]}.#{@reflection.primary_key_name} = #{owner_quoted_id} &quot;
             @finder_sql &lt;&lt; &quot; AND (#{conditions})&quot; if conditions
           end
 
           @join_sql = &quot;INNER JOIN #{@owner.connection.quote_table_name @reflection.options[:join_table]} ON #{@reflection.quoted_table_name}.#{@reflection.klass.primary_key} = #{@owner.connection.quote_table_name @reflection.options[:join_table]}.#{@reflection.association_foreign_key}&quot;
+
+          if @reflection.options[:counter_sql]
+            @counter_sql = interpolate_sql(@reflection.options[:counter_sql])
+          elsif @reflection.options[:finder_sql]
+            # replace the SELECT clause with COUNT(*), preserving any hints within /* ... */
+            @reflection.options[:counter_sql] = @reflection.options[:finder_sql].sub(/SELECT (\/\*.*?\*\/ )?(.*)\bFROM\b/im) { &quot;SELECT #{$1}COUNT(*) FROM&quot; }
+            @counter_sql = interpolate_sql(@reflection.options[:counter_sql])
+          else
+            @counter_sql = @finder_sql
+          end
         end
 
         def construct_scope</diff>
      <filename>vendor/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,33 +1,32 @@
 module ActiveRecord
   module Associations
+    # This is the proxy that handles a has many association.
+    #
+    # If the association has a &lt;tt&gt;:through&lt;/tt&gt; option further specialization
+    # is provided by its child HasManyThroughAssociation.
     class HasManyAssociation &lt; AssociationCollection #:nodoc:
-      # Count the number of associated records. All arguments are optional.
-      def count(*args)
-        if @reflection.options[:counter_sql]
-          @reflection.klass.count_by_sql(@counter_sql)
-        elsif @reflection.options[:finder_sql]
-          @reflection.klass.count_by_sql(@finder_sql)
-        else
-          column_name, options = @reflection.klass.send(:construct_count_options_from_args, *args)          
-          options[:conditions] = options[:conditions].blank? ?
-            @finder_sql :
-            @finder_sql + &quot; AND (#{sanitize_sql(options[:conditions])})&quot;
-          options[:include] ||= @reflection.options[:include]
-
-          value = @reflection.klass.count(column_name, options)
-
-          limit  = @reflection.options[:limit]
-          offset = @reflection.options[:offset]
-
-          if limit || offset
-            [ [value - offset.to_i, 0].max, limit.to_i ].min
+      protected
+        def owner_quoted_id
+          if @reflection.options[:primary_key]
+            quote_value(@owner.send(@reflection.options[:primary_key]))
           else
-            value
+            @owner.quoted_id
           end
         end
-      end
 
-      protected
+        # Returns the number of records in this collection.
+        #
+        # If the association has a counter cache it gets that value. Otherwise
+        # it will attempt to do a count via SQL, bounded to &lt;tt&gt;:limit&lt;/tt&gt; if
+        # there's one.  Some configuration options like :group make it impossible
+        # to do a SQL count, in those cases the array count will be used.
+        #
+        # That does not depend on whether the collection has already been loaded
+        # or not. The +size+ method is the one that takes the loaded flag into
+        # account and delegates to +count_records+ if needed.
+        #
+        # If the collection is empty the target is set to an empty array and
+        # the loaded flag is set to true as well.
         def count_records
           count = if has_cached_counter?
             @owner.send(:read_attribute, cached_counter_attribute_name)
@@ -62,17 +61,18 @@ module ActiveRecord
           record.save
         end
 
+        # Deletes the records according to the &lt;tt&gt;:dependent&lt;/tt&gt; option.
         def delete_records(records)
           case @reflection.options[:dependent]
             when :destroy
-              records.each(&amp;:destroy)
+              records.each { |r| r.destroy }
             when :delete_all
-              @reflection.klass.delete(records.map(&amp;:id))
+              @reflection.klass.delete(records.map { |record| record.id })
             else
               ids = quoted_record_ids(records)
               @reflection.klass.update_all(
                 &quot;#{@reflection.primary_key_name} = NULL&quot;, 
-                &quot;#{@reflection.primary_key_name} = #{@owner.quoted_id} AND #{@reflection.klass.primary_key} IN (#{ids})&quot;
+                &quot;#{@reflection.primary_key_name} = #{owner_quoted_id} AND #{@reflection.klass.primary_key} IN (#{ids})&quot;
               )
           end
         end
@@ -88,12 +88,12 @@ module ActiveRecord
 
             when @reflection.options[:as]
               @finder_sql = 
-                &quot;#{@reflection.quoted_table_name}.#{@reflection.options[:as]}_id = #{@owner.quoted_id} AND &quot; +
+                &quot;#{@reflection.quoted_table_name}.#{@reflection.options[:as]}_id = #{owner_quoted_id} AND &quot; +
                 &quot;#{@reflection.quoted_table_name}.#{@reflection.options[:as]}_type = #{@owner.class.quote_value(@owner.class.base_class.name.to_s)}&quot;
               @finder_sql &lt;&lt; &quot; AND (#{conditions})&quot; if conditions
             
             else
-              @finder_sql = &quot;#{@reflection.quoted_table_name}.#{@reflection.primary_key_name} = #{@owner.quoted_id}&quot;
+              @finder_sql = &quot;#{@reflection.quoted_table_name}.#{@reflection.primary_key_name} = #{owner_quoted_id}&quot;
               @finder_sql &lt;&lt; &quot; AND (#{conditions})&quot; if conditions
           end
 </diff>
      <filename>vendor/activerecord/lib/active_record/associations/has_many_association.rb</filename>
    </modified>
    <modified>
      <diff>@@ -9,15 +9,15 @@ module ActiveRecord
       alias_method :new, :build
 
       def create!(attrs = nil)
-        @reflection.klass.transaction do
-          self &lt;&lt; (object = attrs ? @reflection.klass.send(:with_scope, :create =&gt; attrs) { @reflection.klass.create! } : @reflection.klass.create!)
+        transaction do
+          self &lt;&lt; (object = attrs ? @reflection.klass.send(:with_scope, :create =&gt; attrs) { @reflection.create_association! } : @reflection.create_association!)
           object
         end
       end
 
       def create(attrs = nil)
-        @reflection.klass.transaction do
-          self &lt;&lt; (object = attrs ? @reflection.klass.send(:with_scope, :create =&gt; attrs) { @reflection.klass.create } : @reflection.klass.create)
+        transaction do
+          self &lt;&lt; (object = attrs ? @reflection.klass.send(:with_scope, :create =&gt; attrs) { @reflection.create_association } : @reflection.create_association)
           object
         end
       end
@@ -31,17 +31,15 @@ module ActiveRecord
         return count
       end
       
-      def count(*args)
-        column_name, options = @reflection.klass.send(:construct_count_options_from_args, *args)
-        if @reflection.options[:uniq]
-          # This is needed because 'SELECT count(DISTINCT *)..' is not valid SQL statement.
-          column_name = &quot;#{@reflection.quoted_table_name}.#{@reflection.klass.primary_key}&quot; if column_name == :all
-          options.merge!(:distinct =&gt; true) 
-        end
-        @reflection.klass.send(:with_scope, construct_scope) { @reflection.klass.count(column_name, options) } 
-      end
-
       protected
+        def target_reflection_has_associated_record?
+          if @reflection.through_reflection.macro == :belongs_to &amp;&amp; @owner[@reflection.through_reflection.primary_key_name].blank?
+            false
+          else
+            true
+          end
+        end
+
         def construct_find_options!(options)
           options[:select]  = construct_select(options[:select])
           options[:from]  ||= construct_from
@@ -57,8 +55,9 @@ module ActiveRecord
               return false unless record.save
             end
           end
-          klass = @reflection.through_reflection.klass
-          @owner.send(@reflection.through_reflection.name).proxy_target &lt;&lt; klass.send(:with_scope, :create =&gt; construct_join_attributes(record)) { klass.create! }
+          through_reflection = @reflection.through_reflection
+          klass = through_reflection.klass
+          @owner.send(@reflection.through_reflection.name).proxy_target &lt;&lt; klass.send(:with_scope, :create =&gt; construct_join_attributes(record)) { through_reflection.create_association! }
         end
 
         # TODO - add dependent option support
@@ -70,6 +69,7 @@ module ActiveRecord
         end
 
         def find_target
+          return [] unless target_reflection_has_associated_record?
           @reflection.klass.find(:all,
             :select     =&gt; construct_select,
             :conditions =&gt; construct_conditions,
@@ -107,12 +107,14 @@ module ActiveRecord
         # Associate attributes pointing to owner, quoted.
         def construct_quoted_owner_attributes(reflection)
           if as = reflection.options[:as]
-            { &quot;#{as}_id&quot; =&gt; @owner.quoted_id,
+            { &quot;#{as}_id&quot; =&gt; owner_quoted_id,
               &quot;#{as}_type&quot; =&gt; reflection.klass.quote_value(
                 @owner.class.base_class.name.to_s,
                 reflection.klass.columns_hash[&quot;#{as}_type&quot;]) }
+          elsif reflection.macro == :belongs_to
+            { reflection.klass.primary_key =&gt; @owner[reflection.primary_key_name] }
           else
-            { reflection.primary_key_name =&gt; @owner.quoted_id }
+            { reflection.primary_key_name =&gt; owner_quoted_id }
           end
         end
 
@@ -183,7 +185,7 @@ module ActiveRecord
             when @reflection.options[:finder_sql]
               @finder_sql = interpolate_sql(@reflection.options[:finder_sql])
 
-              @finder_sql = &quot;#{@reflection.quoted_table_name}.#{@reflection.primary_key_name} = #{@owner.quoted_id}&quot;
+              @finder_sql = &quot;#{@reflection.quoted_table_name}.#{@reflection.primary_key_name} = #{owner_quoted_id}&quot;
               @finder_sql &lt;&lt; &quot; AND (#{conditions})&quot; if conditions
             else
               @finder_sql = construct_conditions</diff>
      <filename>vendor/activerecord/lib/active_record/associations/has_many_through_association.rb</filename>
    </modified>
    <modified>
      <diff>@@ -7,15 +7,21 @@ module ActiveRecord
       end
 
       def create(attrs = {}, replace_existing = true)
-        new_record(replace_existing) { |klass| klass.create(attrs) }
+        new_record(replace_existing) do |reflection|
+          reflection.create_association(attrs)
+        end
       end
 
       def create!(attrs = {}, replace_existing = true)
-        new_record(replace_existing) { |klass| klass.create!(attrs) }
+        new_record(replace_existing) do |reflection|
+          reflection.create_association!(attrs)
+        end
       end
 
       def build(attrs = {}, replace_existing = true)
-        new_record(replace_existing) { |klass| klass.new(attrs) }
+        new_record(replace_existing) do |reflection|
+          reflection.build_association(attrs)
+        end
       end
 
       def replace(obj, dont_save = false)
@@ -47,7 +53,16 @@ module ActiveRecord
           return (obj.nil? ? nil : self)
         end
       end
-            
+
+      protected
+        def owner_quoted_id
+          if @reflection.options[:primary_key]
+            @owner.class.quote_value(@owner.send(@reflection.options[:primary_key]))
+          else
+            @owner.quoted_id
+          end
+        end
+
       private
         def find_target
           @reflection.klass.find(:first, 
@@ -63,10 +78,10 @@ module ActiveRecord
           case
             when @reflection.options[:as]
               @finder_sql = 
-                &quot;#{@reflection.quoted_table_name}.#{@reflection.options[:as]}_id = #{@owner.quoted_id} AND &quot; +
+                &quot;#{@reflection.quoted_table_name}.#{@reflection.options[:as]}_id = #{owner_quoted_id} AND &quot; +
                 &quot;#{@reflection.quoted_table_name}.#{@reflection.options[:as]}_type = #{@owner.class.quote_value(@owner.class.base_class.name.to_s)}&quot;
             else
-              @finder_sql = &quot;#{@reflection.quoted_table_name}.#{@reflection.primary_key_name} = #{@owner.quoted_id}&quot;
+              @finder_sql = &quot;#{@reflection.quoted_table_name}.#{@reflection.primary_key_name} = #{owner_quoted_id}&quot;
           end
           @finder_sql &lt;&lt; &quot; AND (#{conditions})&quot; if conditions
         end
@@ -82,7 +97,9 @@ module ActiveRecord
           # instance. Otherwise, if the target has not previously been loaded
           # elsewhere, the instance we create will get orphaned.
           load_target if replace_existing
-          record = @reflection.klass.send(:with_scope, :create =&gt; construct_scope[:create]) { yield @reflection.klass }
+          record = @reflection.klass.send(:with_scope, :create =&gt; construct_scope[:create]) do
+            yield @reflection
+          end
 
           if replace_existing
             replace(record, true) </diff>
      <filename>vendor/activerecord/lib/active_record/associations/has_one_association.rb</filename>
    </modified>
    <modified>
      <diff>@@ -8,11 +8,10 @@ module ActiveRecord
         current_object = @owner.send(@reflection.through_reflection.name)
         
         if current_object
-          klass.destroy(current_object)
-          @owner.clear_association_cache
+          current_object.update_attributes(construct_join_attributes(new_value))
+        else
+          @owner.send(@reflection.through_reflection.name,  klass.send(:create, construct_join_attributes(new_value)))
         end
-        
-        @owner.send(@reflection.through_reflection.name,  klass.send(:create, construct_join_attributes(new_value)))
       end
       
     private</diff>
      <filename>vendor/activerecord/lib/active_record/associations/has_one_through_association.rb</filename>
    </modified>
    <modified>
      <diff>@@ -10,7 +10,7 @@ module ActiveRecord
       base.attribute_types_cached_by_default = ATTRIBUTE_TYPES_CACHED_BY_DEFAULT
       base.cattr_accessor :time_zone_aware_attributes, :instance_writer =&gt; false
       base.time_zone_aware_attributes = false
-      base.cattr_accessor :skip_time_zone_conversion_for_attributes, :instance_writer =&gt; false
+      base.class_inheritable_accessor :skip_time_zone_conversion_for_attributes, :instance_writer =&gt; false
       base.skip_time_zone_conversion_for_attributes = []
     end
 
@@ -214,7 +214,7 @@ module ActiveRecord
             if logger
               logger.warn &quot;Exception occurred during reader method compilation.&quot;
               logger.warn &quot;Maybe #{attr_name} is not a valid Ruby identifier?&quot;
-              logger.warn &quot;#{err.message}&quot;
+              logger.warn err.message
             end
           end
         end
@@ -232,6 +232,10 @@ module ActiveRecord
     def method_missing(method_id, *args, &amp;block)
       method_name = method_id.to_s
 
+      if self.class.private_method_defined?(method_name)
+        raise NoMethodError.new(&quot;Attempt to call private method&quot;, method_name, args)
+      end
+
       # If we haven't generated any methods yet, generate them, then
       # see if we've created the method we're looking for.
       if !self.class.generated_methods?
@@ -330,14 +334,18 @@ module ActiveRecord
       end
     end
     
-    # A Person object with a name attribute can ask &lt;tt&gt;person.respond_to?(&quot;name&quot;)&lt;/tt&gt;,
-    # &lt;tt&gt;person.respond_to?(&quot;name=&quot;)&lt;/tt&gt;, and &lt;tt&gt;person.respond_to?(&quot;name?&quot;)&lt;/tt&gt;
+    # A Person object with a name attribute can ask &lt;tt&gt;person.respond_to?(:name)&lt;/tt&gt;,
+    # &lt;tt&gt;person.respond_to?(:name=)&lt;/tt&gt;, and &lt;tt&gt;person.respond_to?(:name?)&lt;/tt&gt;
     # which will all return +true+.
     alias :respond_to_without_attributes? :respond_to?
-    def respond_to?(method, include_priv = false)
+    def respond_to?(method, include_private_methods = false)
       method_name = method.to_s
       if super
         return true
+      elsif !include_private_methods &amp;&amp; super(method, true)
+        # If we're here than we haven't found among non-private methods
+        # but found among all methods. Which means that given method is private.
+        return false
       elsif !self.class.generated_methods?
         self.class.define_attribute_methods
         if self.class.generated_methods.include?(method_name)</diff>
      <filename>vendor/activerecord/lib/active_record/attribute_methods.rb</filename>
    </modified>
    <modified>
      <diff>@@ -6,7 +6,7 @@ module ActiveRecord #:nodoc:
   class ActiveRecordError &lt; StandardError
   end
 
-  # Raised when the single-table inheritance mechanism failes to locate the subclass
+  # Raised when the single-table inheritance mechanism fails to locate the subclass
   # (for example due to improper usage of column that +inheritance_column+ points to).
   class SubclassNotFound &lt; ActiveRecordError #:nodoc:
   end
@@ -83,8 +83,33 @@ module ActiveRecord #:nodoc:
   class ReadOnlyRecord &lt; ActiveRecordError
   end
 
-  # Used by Active Record transaction mechanism to distinguish rollback from other exceptional situations.
-  # You can use it to roll your transaction back explicitly in the block passed to +transaction+ method.
+  # ActiveRecord::Transactions::ClassMethods.transaction uses this exception
+  # to distinguish a deliberate rollback from other exceptional situations.
+  # Normally, raising an exception will cause the +transaction+ method to rollback
+  # the database transaction *and* pass on the exception. But if you raise an
+  # ActiveRecord::Rollback exception, then the database transaction will be rolled back,
+  # without passing on the exception.
+  #
+  # For example, you could do this in your controller to rollback a transaction:
+  #
+  #   class BooksController &lt; ActionController::Base
+  #     def create
+  #       Book.transaction do
+  #         book = Book.new(params[:book])
+  #         book.save!
+  #         if today_is_friday?
+  #           # The system must fail on Friday so that our support department
+  #           # won't be out of job. We silently rollback this transaction
+  #           # without telling the user.
+  #           raise ActiveRecord::Rollback, &quot;Call tech support!&quot;
+  #         end
+  #       end
+  #       # ActiveRecord::Rollback is the only exception that won't be passed on
+  #       # by ActiveRecord::Base.transaction, so this line will still be reached
+  #       # even on Friday.
+  #       redirect_to root_url
+  #     end
+  #   end
   class Rollback &lt; ActiveRecordError
   end
 
@@ -97,7 +122,11 @@ module ActiveRecord #:nodoc:
   class MissingAttributeError &lt; NoMethodError
   end
 
-  # Raised when an error occured while doing a mass assignment to an attribute through the
+  # Raised when unknown attributes are supplied via mass assignment.
+  class UnknownAttributeError &lt; NoMethodError
+  end
+
+  # Raised when an error occurred while doing a mass assignment to an attribute through the
   # &lt;tt&gt;attributes=&lt;/tt&gt; method. The exception has an +attribute+ property that is the name of the
   # offending attribute.
   class AttributeAssignmentError &lt; ActiveRecordError
@@ -245,7 +274,7 @@ module ActiveRecord #:nodoc:
   # == Dynamic attribute-based finders
   #
   # Dynamic attribute-based finders are a cleaner way of getting (and/or creating) objects by simple queries without turning to SQL. They work by
-  # appending the name of an attribute to &lt;tt&gt;find_by_&lt;/tt&gt; or &lt;tt&gt;find_all_by_&lt;/tt&gt;, so you get finders like &lt;tt&gt;Person.find_by_user_name&lt;/tt&gt;,
+  # appending the name of an attribute to &lt;tt&gt;find_by_&lt;/tt&gt;, &lt;tt&gt;find_last_by_&lt;/tt&gt;, or &lt;tt&gt;find_all_by_&lt;/tt&gt;, so you get finders like &lt;tt&gt;Person.find_by_user_name&lt;/tt&gt;,
   # &lt;tt&gt;Person.find_all_by_last_name&lt;/tt&gt;, and &lt;tt&gt;Payment.find_by_transaction_id&lt;/tt&gt;. So instead of writing
   # &lt;tt&gt;Person.find(:first, :conditions =&gt; [&quot;user_name = ?&quot;, user_name])&lt;/tt&gt;, you just do &lt;tt&gt;Person.find_by_user_name(user_name)&lt;/tt&gt;.
   # And instead of writing &lt;tt&gt;Person.find(:all, :conditions =&gt; [&quot;last_name = ?&quot;, last_name])&lt;/tt&gt;, you just do &lt;tt&gt;Person.find_all_by_last_name(last_name)&lt;/tt&gt;.
@@ -258,6 +287,7 @@ module ActiveRecord #:nodoc:
   # It's even possible to use all the additional parameters to find. For example, the full interface for &lt;tt&gt;Payment.find_all_by_amount&lt;/tt&gt;
   # is actually &lt;tt&gt;Payment.find_all_by_amount(amount, options)&lt;/tt&gt;. And the full interface to &lt;tt&gt;Person.find_by_user_name&lt;/tt&gt; is
   # actually &lt;tt&gt;Person.find_by_user_name(user_name, options)&lt;/tt&gt;. So you could call &lt;tt&gt;Payment.find_all_by_amount(50, :order =&gt; &quot;created_on&quot;)&lt;/tt&gt;.
+  # Also you may call &lt;tt&gt;Payment.find_last_by_amount(amount, options)&lt;/tt&gt; returning the last record matching that amount and options.
   #
   # The same dynamic finder style can be used to create the object if it doesn't already exist. This dynamic finder is called with
   # &lt;tt&gt;find_or_create_by_&lt;/tt&gt; and will return the object if it already exists and otherwise creates it, then returns it. Protected attributes won't be set unless they are given in a block. For example:
@@ -271,7 +301,7 @@ module ActiveRecord #:nodoc:
   #   # Now 'Bob' exist and is an 'admin'
   #   User.find_or_create_by_name('Bob', :age =&gt; 40) { |u| u.admin = true }
   #
-  # Use the &lt;tt&gt;find_or_initialize_by_&lt;/tt&gt; finder if you want to return a new record without saving it first. Protected attributes won't be setted unless they are given in a block. For example:
+  # Use the &lt;tt&gt;find_or_initialize_by_&lt;/tt&gt; finder if you want to return a new record without saving it first. Protected attributes won't be set unless they are given in a block. For example:
   #
   #   # No 'Winter' tag exists
   #   winter = Tag.find_or_initialize_by_name(&quot;Winter&quot;)
@@ -385,6 +415,31 @@ module ActiveRecord #:nodoc:
 
     @@subclasses = {}
 
+    # Contains the database configuration - as is typically stored in config/database.yml -
+    # as a Hash.
+    #
+    # For example, the following database.yml...
+    # 
+    #   development:
+    #     adapter: sqlite3
+    #     database: db/development.sqlite3
+    #   
+    #   production:
+    #     adapter: sqlite3
+    #     database: db/production.sqlite3
+    #
+    # ...would result in ActiveRecord::Base.configurations to look like this:
+    #
+    #   {
+    #      'development' =&gt; {
+    #         'adapter'  =&gt; 'sqlite3',
+    #         'database' =&gt; 'db/development.sqlite3'
+    #      },
+    #      'production' =&gt; {
+    #         'adapter'  =&gt; 'sqlite3',
+    #         'database' =&gt; 'db/production.sqlite3'
+    #      }
+    #   }
     cattr_accessor :configurations, :instance_writer =&gt; false
     @@configurations = {}
 
@@ -423,13 +478,6 @@ module ActiveRecord #:nodoc:
     cattr_accessor :default_timezone, :instance_writer =&gt; false
     @@default_timezone = :local
 
-    # Determines whether to use a connection for each thread, or a single shared connection for all threads.
-    # Defaults to false. If you're writing a threaded application, set to true
-    # and periodically call verify_active_connections! to clear out connections
-    # assigned to stale threads.
-    cattr_accessor :allow_concurrency, :instance_writer =&gt; false
-    @@allow_concurrency = false
-
     # Specifies the format to use when dumping the database schema with Rails'
     # Rakefile.  If :sql, the schema is dumped as (potentially database-
     # specific) SQL statements.  If :ruby, the schema is dumped as an
@@ -464,9 +512,9 @@ module ActiveRecord #:nodoc:
       #
       # All approaches accept an options hash as their last parameter.
       #
-      # ==== Attributes
+      # ==== Parameters
       #
-      # * &lt;tt&gt;:conditions&lt;/tt&gt; - An SQL fragment like &quot;administrator = 1&quot; or &lt;tt&gt;[ &quot;user_name = ?&quot;, username ]&lt;/tt&gt;. See conditions in the intro.
+      # * &lt;tt&gt;:conditions&lt;/tt&gt; - An SQL fragment like &quot;administrator = 1&quot;, &lt;tt&gt;[ &quot;user_name = ?&quot;, username ]&lt;/tt&gt;, or &lt;tt&gt;[&quot;user_name = :user_name&quot;, { :user_name =&gt; user_name }]&lt;/tt&gt;. See conditions in the intro.
       # * &lt;tt&gt;:order&lt;/tt&gt; - An SQL fragment like &quot;created_at DESC, name&quot;.
       # * &lt;tt&gt;:group&lt;/tt&gt; - An attribute name by which the result should be grouped. Uses the &lt;tt&gt;GROUP BY&lt;/tt&gt; SQL-clause.
       # * &lt;tt&gt;:limit&lt;/tt&gt; - An integer determining the limit on the number of rows that should be returned.
@@ -478,7 +526,7 @@ module ActiveRecord #:nodoc:
       # * &lt;tt&gt;:include&lt;/tt&gt; - Names associations that should be loaded alongside. The symbols named refer
       #   to already defined associations. See eager loading under Associations.
       # * &lt;tt&gt;:select&lt;/tt&gt; - By default, this is &quot;*&quot; as in &quot;SELECT * FROM&quot;, but can be changed if you, for example, want to do a join but not
-      #   include the joined columns.
+      #   include the joined columns. Takes a string with the SELECT SQL fragment (e.g. &quot;id, name&quot;).
       # * &lt;tt&gt;:from&lt;/tt&gt; - By default, this is the table name of the class, but can be changed to an alternate table name (or even the name
       #   of a database view).
       # * &lt;tt&gt;:readonly&lt;/tt&gt; - Mark the returned records read-only so they cannot be saved or updated.
@@ -503,6 +551,7 @@ module ActiveRecord #:nodoc:
       #   # find first
       #   Person.find(:first) # returns the first object fetched by SELECT * FROM people
       #   Person.find(:first, :conditions =&gt; [ &quot;user_name = ?&quot;, user_name])
+      #   Person.find(:first, :conditions =&gt; [ &quot;user_name = :u&quot;, { :u =&gt; user_name }])
       #   Person.find(:first, :order =&gt; &quot;created_on DESC&quot;, :offset =&gt; 5)
       #
       #   # find last
@@ -562,8 +611,8 @@ module ActiveRecord #:nodoc:
 
       # Executes a custom SQL query against your database and returns all the results.  The results will
       # be returned as an array with columns requested encapsulated as attributes of the model you call
-      # this method from.  If you call +Product.find_by_sql+ then the results will be returned in a Product
-      # object with the attributes you specified in the SQL query.
+      # this method from.  If you call &lt;tt&gt;Product.find_by_sql&lt;/tt&gt; then the results will be returned in
+      # a Product object with the attributes you specified in the SQL query.
       #
       # If you call a complicated SQL query which spans multiple tables the columns specified by the
       # SELECT will be attributes of the model, whether or not they are columns of the corresponding
@@ -572,7 +621,7 @@ module ActiveRecord #:nodoc:
       # The +sql+ parameter is a full SQL query as a string.  It will be called as is, there will be
       # no database agnostic conversions performed.  This should be a last resort because using, for example,
       # MySQL specific terms will lock you to using that particular database engine or require you to
-      # change your call if you switch engines
+      # change your call if you switch engines.
       #
       # ==== Examples
       #   # A simple SQL query spanning multiple tables
@@ -649,7 +698,7 @@ module ActiveRecord #:nodoc:
       # Updates an object (or multiple objects) and saves it to the database, if validations pass.
       # The resulting object is returned whether the object was saved successfully to the database or not.
       #
-      # ==== Attributes
+      # ==== Parameters
       #
       # * +id+ - This should be the id or an array of ids to be updated.
       # * +attributes+ - This should be a Hash of attributes to be set on the object, or an array of Hashes.
@@ -677,9 +726,10 @@ module ActiveRecord #:nodoc:
       # is executed on the database which means that no callbacks are fired off running this.  This is an efficient method
       # of deleting records that don't need cleaning up after or other actions to be taken.
       #
-      # Objects are _not_ instantiated with this method.
+      # Objects are _not_ instantiated with this method, and so +:dependent+ rules
+      # defined on associations are not honered.
       #
-      # ==== Attributes
+      # ==== Parameters
       #
       # * +id+ - Can be either an Integer or an Array of Integers.
       #
@@ -702,7 +752,7 @@ module ActiveRecord #:nodoc:
       # This essentially finds the object (or multiple objects) with the given id, creates a new object
       # from the attributes, and then calls destroy on it.
       #
-      # ==== Attributes
+      # ==== Parameters
       #
       # * +id+ - Can be either an Integer or an Array of Integers.
       #
@@ -723,14 +773,15 @@ module ActiveRecord #:nodoc:
       end
 
       # Updates all records with details given if they match a set of conditions supplied, limits and order can
-      # also be supplied.
+      # also be supplied. This method constructs a single SQL UPDATE statement and sends it straight to the
+      # database. It does not instantiate the involved models and it does not trigger Active Record callbacks.
       #
-      # ==== Attributes
+      # ==== Parameters
       #
-      # * +updates+ - A String of column and value pairs that will be set on any records that match conditions.
-      # * +conditions+ - An SQL fragment like &quot;administrator = 1&quot; or [ &quot;user_name = ?&quot;, username ].
-      #   See conditions in the intro for more info.
-      # * +options+ - Additional options are &lt;tt&gt;:limit&lt;/tt&gt; and/or &lt;tt&gt;:order&lt;/tt&gt;, see the examples for usage.
+      # * +updates+ - A string of column and value pairs that will be set on any records that match conditions.
+      #               What goes into the SET clause.
+      # * +conditions+ - An SQL fragment like &quot;administrator = 1&quot; or [ &quot;user_name = ?&quot;, username ]. See conditions in the intro for more info.
+      # * +options+ - Additional options are &lt;tt&gt;:limit&lt;/tt&gt; and &lt;tt&gt;:order&lt;/tt&gt;, see the examples for usage.
       #
       # ==== Examples
       #
@@ -745,46 +796,66 @@ module ActiveRecord #:nodoc:
       #                         :order =&gt; 'created_at', :limit =&gt; 5 )
       def update_all(updates, conditions = nil, options = {})
         sql  = &quot;UPDATE #{quoted_table_name} SET #{sanitize_sql_for_assignment(updates)} &quot;
+
         scope = scope(:find)
-        add_conditions!(sql, conditions, scope)
-        add_order!(sql, options[:order], nil)
-        add_limit!(sql, options, nil)
+
+        select_sql = &quot;&quot;
+        add_conditions!(select_sql, conditions, scope)
+
+        if options.has_key?(:limit) || (scope &amp;&amp; scope[:limit])
+          # Only take order from scope if limit is also provided by scope, this
+          # is useful for updating a has_many association with a limit.
+          add_order!(select_sql, options[:order], scope)
+
+          add_limit!(select_sql, options, scope)
+          sql.concat(connection.limited_update_conditions(select_sql, quoted_table_name, connection.quote_column_name(primary_key)))
+        else
+          add_order!(select_sql, options[:order], nil)
+          sql.concat(select_sql)
+        end
+
         connection.update(sql, &quot;#{name} Update&quot;)
       end
 
-      # Destroys the records matching +conditions+ by instantiating each record and calling the destroy method.
-      # This means at least 2*N database queries to destroy N records, so avoid destroy_all if you are deleting
+      # Destroys the records matching +conditions+ by instantiating each record and calling their +destroy+ method.
+      # This means at least 2*N database queries to destroy N records, so avoid +destroy_all+ if you are deleting
       # many records. If you want to simply delete records without worrying about dependent associations or
       # callbacks, use the much faster +delete_all+ method instead.
       #
-      # ==== Attributes
+      # ==== Parameters
       #
       # * +conditions+ - Conditions are specified the same way as with +find+ method.
       #
       # ==== Example
       #
-      #   Person.destroy_all &quot;last_login &lt; '2004-04-04'&quot;
+      #   Person.destroy_all(&quot;last_login &lt; '2004-04-04'&quot;)
       #
       # This loads and destroys each person one by one, including its dependent associations and before_ and
       # after_destroy callbacks.
+      #
+      # +conditions+ can be anything that +find+ also accepts:
+      #
+      #   Person.destroy_all(:last_login =&gt; 6.hours.ago)
       def destroy_all(conditions = nil)
         find(:all, :conditions =&gt; conditions).each { |object| object.destroy }
       end
 
       # Deletes the records matching +conditions+ without instantiating the records first, and hence not
-      # calling the destroy method and invoking callbacks. This is a single SQL query, much more efficient
-      # than destroy_all.
+      # calling the +destroy+ method nor invoking callbacks. This is a single SQL DELETE statement that
+      # goes straight to the database, much more efficient than +destroy_all+. Be careful with relations
+      # though, in particular &lt;tt&gt;:dependent&lt;/tt&gt; rules defined on associations are not honored.
       #
-      # ==== Attributes
+      # ==== Parameters
       #
       # * +conditions+ - Conditions are specified the same way as with +find+ method.
       #
       # ==== Example
       #
-      #   Post.delete_all &quot;person_id = 5 AND (category = 'Something' OR category = 'Else')&quot;
+      #   Post.delete_all(&quot;person_id = 5 AND (category = 'Something' OR category = 'Else')&quot;)
+      #   Post.delete_all([&quot;person_id = ? AND (category = ? OR category = ?)&quot;, 5, 'Something', 'Else'])
       #
-      # This deletes the affected posts all at once with a single DELETE query. If you need to destroy dependent
-      # associations or call your before_ or after_destroy callbacks, use the +destroy_all+ method instead.
+      # Both calls delete the affected posts all at once with a single DELETE statement. If you need to destroy dependent
+      # associations or call your &lt;tt&gt;before_*&lt;/tt&gt; or +after_destroy+ callbacks, use the +destroy_all+ method instead.
       def delete_all(conditions = nil)
         sql = &quot;DELETE FROM #{quoted_table_name} &quot;
         add_conditions!(sql, conditions, scope(:find))
@@ -795,7 +866,7 @@ module ActiveRecord #:nodoc:
       # The use of this method should be restricted to complicated SQL queries that can't be executed
       # using the ActiveRecord::Calculations class methods.  Look into those before using this.
       #
-      # ==== Attributes
+      # ==== Parameters
       #
       # * +sql+ - An SQL statement which should return a count query from the database, see the example below.
       #
@@ -813,7 +884,7 @@ module ActiveRecord #:nodoc:
       # with the given ID, altering the given hash of counters by the amount
       # given by the corresponding value:
       #
-      # ==== Attributes
+      # ==== Parameters
       #
       # * +id+ - The id of the object you wish to update a counter on.
       # * +counters+ - An Array of Hashes containing the names of the fields
@@ -843,7 +914,7 @@ module ActiveRecord #:nodoc:
       # For example, a DiscussionBoard may cache post_count and comment_count otherwise every time the board is
       # shown it would have to run an SQL query to find how many posts and comments there are.
       #
-      # ==== Attributes
+      # ==== Parameters
       #
       # * +counter_name+ - The name of the field that should be incremented.
       # * +id+ - The id of the object that should be incremented.
@@ -860,7 +931,7 @@ module ActiveRecord #:nodoc:
       #
       # This works the same as increment_counter but reduces the column value by 1 instead of increasing it.
       #
-      # ==== Attributes
+      # ==== Parameters
       #
       # * +counter_name+ - The name of the field that should be decremented.
       # * +id+ - The id of the object that should be decremented.
@@ -899,12 +970,12 @@ module ActiveRecord #:nodoc:
       # To start from an all-closed default and enable attributes as needed,
       # have a look at +attr_accessible+.
       def attr_protected(*attributes)
-        write_inheritable_attribute(&quot;attr_protected&quot;, Set.new(attributes.map(&amp;:to_s)) + (protected_attributes || []))
+        write_inheritable_attribute(:attr_protected, Set.new(attributes.map(&amp;:to_s)) + (protected_attributes || []))
       end
 
       # Returns an array of all the attributes that have been protected from mass-assignment.
       def protected_attributes # :nodoc:
-        read_inheritable_attribute(&quot;attr_protected&quot;)
+        read_inheritable_attribute(:attr_protected)
       end
 
       # Specifies a white list of model attributes that can be set via
@@ -932,22 +1003,22 @@ module ActiveRecord #:nodoc:
       #   customer.credit_rating = &quot;Average&quot;
       #   customer.credit_rating # =&gt; &quot;Average&quot;
       def attr_accessible(*attributes)
-        write_inheritable_attribute(&quot;attr_accessible&quot;, Set.new(attributes.map(&amp;:to_s)) + (accessible_attributes || []))
+        write_inheritable_attribute(:attr_accessible, Set.new(attributes.map(&amp;:to_s)) + (accessible_attributes || []))
       end
 
       # Returns an array of all the attributes that have been made accessible to mass-assignment.
       def accessible_attributes # :nodoc:
-        read_inheritable_attribute(&quot;attr_accessible&quot;)
+        read_inheritable_attribute(:attr_accessible)
       end
 
        # Attributes listed as readonly can be set for a new record, but will be ignored in database updates afterwards.
        def attr_readonly(*attributes)
-         write_inheritable_attribute(&quot;attr_readonly&quot;, Set.new(attributes.map(&amp;:to_s)) + (readonly_attributes || []))
+         write_inheritable_attribute(:attr_readonly, Set.new(attributes.map(&amp;:to_s)) + (readonly_attributes || []))
        end
 
        # Returns an array of all the attributes that have been specified as readonly.
        def readonly_attributes
-         read_inheritable_attribute(&quot;attr_readonly&quot;)
+         read_inheritable_attribute(:attr_readonly)
        end
 
       # If you have an attribute that needs to be saved to the database as an object, and retrieved as the same object,
@@ -955,7 +1026,7 @@ module ActiveRecord #:nodoc:
       # The serialization is done through YAML. If +class_name+ is specified, the serialized object must be of that
       # class on retrieval or SerializationTypeMismatch will be raised.
       #
-      # ==== Attributes
+      # ==== Parameters
       #
       # * +attr_name+ - The field name that should be serialized.
       # * +class_name+ - Optional, class name that the object type should be equal to.
@@ -971,7 +1042,7 @@ module ActiveRecord #:nodoc:
 
       # Returns a hash of all the attributes that have been specified for serialization as keys and their class restriction as values.
       def serialized_attributes
-        read_inheritable_attribute(&quot;attr_serialized&quot;) or write_inheritable_attribute(&quot;attr_serialized&quot;, {})
+        read_inheritable_attribute(:attr_serialized) or write_inheritable_attribute(:attr_serialized, {})
       end
 
 
@@ -1182,7 +1253,32 @@ module ActiveRecord #:nodoc:
         end
       end
 
-      # Resets all the cached information about columns, which will cause them to be reloaded on the next request.
+      # Resets all the cached information about columns, which will cause them
+      # to be reloaded on the next request.
+      #
+      # The most common usage pattern for this method is probably in a migration,
+      # when just after creating a table you want to populate it with some default
+      # values, eg:
+      #
+      #  class CreateJobLevels &lt; ActiveRecord::Migration
+      #    def self.up
+      #      create_table :job_levels do |t|
+      #        t.integer :id
+      #        t.string :name
+      #
+      #        t.timestamps
+      #      end
+      #
+      #      JobLevel.reset_column_information
+      #      %w{assistant executive manager director}.each do |type|
+      #        JobLevel.create(:name =&gt; type)
+      #      end
+      #    end
+      #
+      #    def self.down
+      #      drop_table :job_levels
+      #    end
+      #  end
       def reset_column_information
         generated_methods.each { |name| undef_method(name) }
         @column_names = @columns = @columns_hash = @content_columns = @dynamic_methods_hash = @generated_methods = @inheritance_column = nil
@@ -1192,11 +1288,46 @@ module ActiveRecord #:nodoc:
         subclasses.each { |klass| klass.reset_inheritable_attributes; klass.reset_column_information }
       end
 
+      def self_and_descendents_from_active_record#nodoc:
+        klass = self
+        classes = [klass]
+        while klass != klass.base_class  
+          classes &lt;&lt; klass = klass.superclass
+        end
+        classes
+      rescue
+        # OPTIMIZE this rescue is to fix this test: ./test/cases/reflection_test.rb:56:in `test_human_name_for_column'
+        # Appearantly the method base_class causes some trouble.
+        # It now works for sure.
+        [self]
+      end
+
       # Transforms attribute key names into a more humane format, such as &quot;First name&quot; instead of &quot;first_name&quot;. Example:
       #   Person.human_attribute_name(&quot;first_name&quot;) # =&gt; &quot;First name&quot;
-      # Deprecated in favor of just calling &quot;first_name&quot;.humanize
-      def human_attribute_name(attribute_key_name) #:nodoc:
-        attribute_key_name.humanize
+      # This used to be depricated in favor of humanize, but is now preferred, because it automatically uses the I18n
+      # module now.
+      # Specify +options+ with additional translating options.
+      def human_attribute_name(attribute_key_name, options = {})
+        defaults = self_and_descendents_from_active_record.map do |klass|
+          :&quot;#{klass.name.underscore}.#{attribute_key_name}&quot;
+        end
+        defaults &lt;&lt; options[:default] if options[:default]
+        defaults.flatten!
+        defaults &lt;&lt; attribute_key_name.humanize
+        options[:count] ||= 1
+        I18n.translate(defaults.shift, options.merge(:default =&gt; defaults, :scope =&gt; [:activerecord, :attributes]))
+      end
+
+      # Transform the modelname into a more humane format, using I18n.
+      # Defaults to the basic humanize method.
+      # Default scope of the translation is activerecord.models
+      # Specify +options+ with additional translating options.
+      def human_name(options = {})
+        defaults = self_and_descendents_from_active_record.map do |klass|
+          :&quot;#{klass.name.underscore}&quot;
+        end 
+        defaults &lt;&lt; self.name.humanize
+        I18n.translate(defaults.shift, {:scope =&gt; [:activerecord, :models], :count =&gt; 1, :default =&gt; defaults}.merge(options))
       end
 
       # True if this isn't a concrete subclass needing a STI type condition.
@@ -1254,7 +1385,7 @@ module ActiveRecord #:nodoc:
         if logger &amp;&amp; logger.level &lt;= log_level
           result = nil
           seconds = Benchmark.realtime { result = use_silence ? silence { yield } : yield }
-          logger.add(log_level, &quot;#{title} (#{'%.5f' % seconds})&quot;)
+          logger.add(log_level, &quot;#{title} (#{'%.1f' % (seconds * 1000)}ms)&quot;)
           result
         else
           yield
@@ -1291,8 +1422,8 @@ module ActiveRecord #:nodoc:
       end
 
       def respond_to?(method_id, include_private = false)
-        if match = matches_dynamic_finder?(method_id) || matches_dynamic_finder_with_initialize_or_create?(method_id)
-          return true if all_attributes_exists?(extract_attribute_names_from_match(match))
+        if match = DynamicFinderMatch.match(method_id)
+          return true if all_attributes_exists?(match.attribute_names)
         end
         super
       end
@@ -1301,6 +1432,20 @@ module ActiveRecord #:nodoc:
         store_full_sti_class ? name : name.demodulize
       end
 
+      # Merges conditions so that the result is a valid +condition+
+      def merge_conditions(*conditions)
+        segments = []
+
+        conditions.each do |condition|
+          unless condition.blank?
+            sql = sanitize_sql(condition)
+            segments &lt;&lt; sql unless sql.blank?
+          end
+        end
+
+        &quot;(#{segments.join(') AND (')})&quot; unless segments.empty?
+      end
+
       private
         def find_initial(options)
           options.update(:limit =&gt; 1)
@@ -1467,12 +1612,20 @@ module ActiveRecord #:nodoc:
           end
         end
 
+        def default_select(qualified)
+          if qualified
+            quoted_table_name + '.*'
+          else
+            '*'
+          end
+        end
+
         def construct_finder_sql(options)
           scope = scope(:find)
-          sql  = &quot;SELECT #{options[:select] || (scope &amp;&amp; scope[:select]) || ((options[:joins] || (scope &amp;&amp; scope[:joins])) &amp;&amp; quoted_table_name + '.*') || '*'} &quot;
+          sql  = &quot;SELECT #{options[:select] || (scope &amp;&amp; scope[:select]) || default_select(options[:joins] || (scope &amp;&amp; scope[:joins]))} &quot;
           sql &lt;&lt; &quot;FROM #{(scope &amp;&amp; scope[:from]) || options[:from] || quoted_table_name} &quot;
 
-          add_joins!(sql, options, scope)
+          add_joins!(sql, options[:joins], scope)
           add_conditions!(sql, options[:conditions], scope)
 
           add_group!(sql, options[:group], scope)
@@ -1488,18 +1641,20 @@ module ActiveRecord #:nodoc:
          (safe_to_array(first) + safe_to_array(second)).uniq
         end
 
-        # Merges conditions so that the result is a valid +condition+
-        def merge_conditions(*conditions)
-          segments = []
-
-          conditions.each do |condition|
-            unless condition.blank?
-              sql = sanitize_sql(condition)
-              segments &lt;&lt; sql unless sql.blank?
+        def merge_joins(*joins)
+          if joins.any?{|j| j.is_a?(String) || array_of_strings?(j) }
+            joins = joins.collect do |join|
+              join = [join] if join.is_a?(String)
+              unless array_of_strings?(join)
+                join_dependency = ActiveRecord::Associations::ClassMethods::InnerJoinDependency.new(self, join, nil)
+                join = join_dependency.join_associations.collect { |assoc| assoc.association_join }
+              end
+              join
             end
+            joins.flatten.uniq
+          else
+            joins.collect{|j| safe_to_array(j)}.flatten.uniq
           end
-
-          &quot;(#{segments.join(') AND (')})&quot; unless segments.empty?
         end
 
         # Object#to_a is deprecated, though it does have the desired behavior
@@ -1514,6 +1669,10 @@ module ActiveRecord #:nodoc:
           end
         end
 
+        def array_of_strings?(o)
+          o.is_a?(Array) &amp;&amp; o.all?{|obj| obj.is_a?(String)}
+        end
+
         def add_order!(sql, order, scope = :auto)
           scope = scope(:find) if :auto == scope
           scoped_order = scope[:order] if scope
@@ -1557,16 +1716,19 @@ module ActiveRecord #:nodoc:
         end
 
         # The optional scope argument is for the current &lt;tt&gt;:find&lt;/tt&gt; scope.
-        def add_joins!(sql, options, scope = :auto)
+        def add_joins!(sql, joins, scope = :auto)
           scope = scope(:find) if :auto == scope
-          [(scope &amp;&amp; scope[:joins]), options[:joins]].each do |join|
-            case join
-            when Symbol, Hash, Array
-              join_dependency = ActiveRecord::Associations::ClassMethods::InnerJoinDependency.new(self, join, nil)
-              sql &lt;&lt; &quot; #{join_dependency.join_associations.collect { |assoc| assoc.association_join }.join} &quot;
+          merged_joins = scope &amp;&amp; scope[:joins] &amp;&amp; joins ? merge_joins(scope[:joins], joins) : (joins || scope &amp;&amp; scope[:joins])
+          case merged_joins
+          when Symbol, Hash, Array
+            if array_of_strings?(merged_joins)
+              sql &lt;&lt; merged_joins.join(' ') + &quot; &quot;
             else
-              sql &lt;&lt; &quot; #{join} &quot;
+              join_dependency = ActiveRecord::Associations::ClassMethods::InnerJoinDependency.new(self, merged_joins, nil)
+              sql &lt;&lt; &quot; #{join_dependency.join_associations.collect { |assoc| assoc.association_join }.join} &quot;
             end
+          when String
+            sql &lt;&lt; &quot; #{merged_joins} &quot;
           end
         end
 
@@ -1610,89 +1772,68 @@ module ActiveRecord #:nodoc:
         #
         # Each dynamic finder or initializer/creator is also defined in the class after it is first invoked, so that future
         # attempts to use it do not run through method_missing.
-        def method_missing(method_id, *arguments)
-          if match = matches_dynamic_finder?(method_id)
-            finder = determine_finder(match)
-
-            attribute_names = extract_attribute_names_from_match(match)
+        def method_missing(method_id, *arguments, &amp;block)
+          if match = DynamicFinderMatch.match(method_id)
+            attribute_names = match.attribute_names
             super unless all_attributes_exists?(attribute_names)
-
-            self.class_eval %{
-              def self.#{method_id}(*args)
-                options = args.extract_options!
-                attributes = construct_attributes_from_arguments([:#{attribute_names.join(',:')}], args)
-                finder_options = { :conditions =&gt; attributes }
-                validate_find_options(options)
-                set_readonly_option!(options)
-
-                if options[:conditions]
-                  with_scope(:find =&gt; finder_options) do
-                    ActiveSupport::Deprecation.silence { send(:#{finder}, options) }
+            if match.finder?
+              finder = match.finder
+              bang = match.bang?
+              self.class_eval %{
+                def self.#{method_id}(*args)
+                  options = args.extract_options!
+                  attributes = construct_attributes_from_arguments([:#{attribute_names.join(',:')}], args)
+                  finder_options = { :conditions =&gt; attributes }
+                  validate_find_options(options)
+                  set_readonly_option!(options)
+
+                  #{'result = ' if bang}if options[:conditions]
+                    with_scope(:find =&gt; finder_options) do
+                      find(:#{finder}, options)
+                    end
+                  else
+                    find(:#{finder}, options.merge(finder_options))
                   end
-                else
-                  ActiveSupport::Deprecation.silence { send(:#{finder}, options.merge(finder_options)) }
-                end
-              end
-            }, __FILE__, __LINE__
-            send(method_id, *arguments)
-          elsif match = matches_dynamic_finder_with_initialize_or_create?(method_id)
-            instantiator = determine_instantiator(match)
-            attribute_names = extract_attribute_names_from_match(match)
-            super unless all_attributes_exists?(attribute_names)
-
-            self.class_eval %{
-              def self.#{method_id}(*args)
-                guard_protected_attributes = false
-
-                if args[0].is_a?(Hash)
-                  guard_protected_attributes = true
-                  attributes = args[0].with_indifferent_access
-                  find_attributes = attributes.slice(*[:#{attribute_names.join(',:')}])
-                else
-                  find_attributes = attributes = construct_attributes_from_arguments([:#{attribute_names.join(',:')}], args)
+                  #{'result || raise(RecordNotFound)' if bang}
                 end
+              }, __FILE__, __LINE__
+              send(method_id, *arguments)
+            elsif match.instantiator?
+              instantiator = match.instantiator
+              self.class_eval %{
+                def self.#{method_id}(*args)
+                  guard_protected_attributes = false
+
+                  if args[0].is_a?(Hash)
+                    guard_protected_attributes = true
+                    attributes = args[0].with_indifferent_access
+                    find_attributes = attributes.slice(*[:#{attribute_names.join(',:')}])
+                  else
+                    find_attributes = attributes = construct_attributes_from_arguments([:#{attribute_names.join(',:')}], args)
+                  end
 
-                options = { :conditions =&gt; find_attributes }
-                set_readonly_option!(options)
+                  options = { :conditions =&gt; find_attributes }
+                  set_readonly_option!(options)
 
-                record = find_initial(options)
+                  record = find(:first, options)
 
-                 if record.nil?
-                  record = self.new { |r| r.send(:attributes=, attributes, guard_protected_attributes) }
-                  #{'yield(record) if block_given?'}
-                  #{'record.save' if instantiator == :create}
-                  record
-                else
-                  record
+                  if record.nil?
+                    record = self.new { |r| r.send(:attributes=, attributes, guard_protected_attributes) }
+                    #{'yield(record) if block_given?'}
+                    #{'record.save' if instantiator == :create}
+                    record
+                  else
+                    record
+                  end
                 end
-              end
-            }, __FILE__, __LINE__
-            send(method_id, *arguments)
+              }, __FILE__, __LINE__
+              send(method_id, *arguments, &amp;block)
+            end
           else
             super
           end
         end
 
-        def matches_dynamic_finder?(method_id)
-          /^find_(all_by|by)_([_a-zA-Z]\w*)$/.match(method_id.to_s)
-        end
-
-        def matches_dynamic_finder_with_initialize_or_create?(method_id)
-          /^find_or_(initialize|create)_by_([_a-zA-Z]\w*)$/.match(method_id.to_s)
-        end
-
-        def determine_finder(match)
-          match.captures.first == 'all_by' ? :find_every : :find_initial
-        end
-
-        def determine_instantiator(match)
-          match.captures.first == 'initialize' ? :new : :create
-        end
-
-        def extract_attribute_names_from_match(match)
-          match.captures.last.split('_and_')
-        end
-
         def construct_attributes_from_arguments(attribute_names, arguments)
           attributes = {}
           attribute_names.each_with_index { |name, idx| attributes[name] = arguments[idx] }
@@ -1809,6 +1950,9 @@ module ActiveRecord #:nodoc:
         #       end
         #     end
         #   end
+        #
+        # *Note*: the +:find+ scope also has effect on update and deletion methods,
+        # like +update_all+ and +delete_all+.
         def with_scope(method_scoping = {}, action = :merge, &amp;block)
           method_scoping = method_scoping.method_scoping if method_scoping.respond_to?(:method_scoping)
 
@@ -1837,6 +1981,8 @@ module ActiveRecord #:nodoc:
                         hash[method][key] = merge_conditions(params[key], hash[method][key])
                       elsif key == :include &amp;&amp; merge
                         hash[method][key] = merge_includes(hash[method][key], params[key]).uniq
+                      elsif key == :joins &amp;&amp; merge
+                        hash[method][key] = merge_joins(params[key], hash[method][key])
                       else
                         hash[method][key] = hash[method][key] || params[key]
                       end
@@ -1884,20 +2030,8 @@ module ActiveRecord #:nodoc:
           end
         end
 
-        def thread_safe_scoped_methods #:nodoc:
-          scoped_methods = (Thread.current[:scoped_methods] ||= {})
-          scoped_methods[self] ||= []
-        end
-
-        def single_threaded_scoped_methods #:nodoc:
-          @scoped_methods ||= []
-        end
-
-        # pick up the correct scoped_methods version from @@allow_concurrency
-        if @@allow_concurrency
-          alias_method :scoped_methods, :thread_safe_scoped_methods
-        else
-          alias_method :scoped_methods, :single_threaded_scoped_methods
+        def scoped_methods #:nodoc:
+          Thread.current[:&quot;#{self}_scoped_methods&quot;] ||= []
         end
 
         def current_scoped_methods #:nodoc:
@@ -1908,10 +2042,12 @@ module ActiveRecord #:nodoc:
         # MyApp::Business::Account would appear as MyApp::Business::AccountSubclass.
         def compute_type(type_name)
           modularized_name = type_name_with_module(type_name)
-          begin
-            class_eval(modularized_name, __FILE__, __LINE__)
-          rescue NameError
-            class_eval(type_name, __FILE__, __LINE__)
+          silence_warnings do
+            begin
+              class_eval(modularized_name, __FILE__, __LINE__)
+            rescue NameError
+              class_eval(type_name, __FILE__, __LINE__)
+            end
           end
         end
 
@@ -2002,24 +2138,28 @@ module ActiveRecord #:nodoc:
         #     # =&gt; &quot;age BETWEEN 13 AND 18&quot;
         #   { 'other_records.id' =&gt; 7 }
         #     # =&gt; &quot;`other_records`.`id` = 7&quot;
+        #   { :other_records =&gt; { :id =&gt; 7 } }
+        #     # =&gt; &quot;`other_records`.`id` = 7&quot;
         # And for value objects on a composed_of relationship:
         #   { :address =&gt; Address.new(&quot;123 abc st.&quot;, &quot;chicago&quot;) }
         #     # =&gt; &quot;address_street='123 abc st.' and address_city='chicago'&quot;
-        def sanitize_sql_hash_for_conditions(attrs)
+        def sanitize_sql_hash_for_conditions(attrs, table_name = quoted_table_name)
           attrs = expand_hash_conditions_for_aggregates(attrs)
 
           conditions = attrs.map do |attr, value|
-            attr = attr.to_s
+            unless value.is_a?(Hash)
+              attr = attr.to_s
+
+              # Extract table name from qualified attribute names.
+              if attr.include?('.')
+                table_name, attr = attr.split('.', 2)
+                table_name = connection.quote_table_name(table_name)
+              end
 
-            # Extract table name from qualified attribute names.
-            if attr.include?('.')
-              table_name, attr = attr.split('.', 2)
-              table_name = connection.quote_table_name(table_name)
+              &quot;#{table_name}.#{connection.quote_column_name(attr)} #{attribute_condition(value)}&quot;
             else
-              table_name = quoted_table_name
+              sanitize_sql_hash_for_conditions(value, connection.quote_table_name(attr.to_s))
             end
-
-            &quot;#{table_name}.#{connection.quote_column_name(attr)} #{attribute_condition(value)}&quot;
           end.join(' AND ')
 
           replace_bind_variables(conditions, expand_range_bind_variables(attrs.values))
@@ -2073,6 +2213,8 @@ module ActiveRecord #:nodoc:
           expanded = []
 
           bind_vars.each do |var|
+            next if var.is_a?(Hash)
+
             if var.is_a?(Range)
               expanded &lt;&lt; var.first
               expanded &lt;&lt; var.last
@@ -2085,7 +2227,7 @@ module ActiveRecord #:nodoc:
         end
 
         def quote_bound_value(value) #:nodoc:
-          if value.respond_to?(:map) &amp;&amp; !value.is_a?(String)
+          if value.respond_to?(:map) &amp;&amp; !value.acts_like?(:string)
             if value.respond_to?(:empty?) &amp;&amp; value.empty?
               connection.quote(nil)
             else
@@ -2157,7 +2299,28 @@ module ActiveRecord #:nodoc:
 
       end
 
-      # Enables Active Record objects to be used as URL parameters in Action Pack automatically.
+      # Returns a String, which Action Pack uses for constructing an URL to this
+      # object. The default implementation returns this record's id as a String,
+      # or nil if this record's unsaved.
+      #
+      # For example, suppose that you have a Users model, and that you have a
+      # &lt;tt&gt;map.resources :users&lt;/tt&gt; route. Normally, +users_path+ will
+      # construct an URI with the user object's 'id' in it:
+      #
+      #   user = User.find_by_name('Phusion')
+      #   user_path(path)  # =&gt; &quot;/users/1&quot;
+      #
+      # You can override +to_param+ in your model to make +users_path+ construct
+      # an URI using the user's name instead of the user's id:
+      #
+      #   class User &lt; ActiveRecord::Base
+      #     def to_param  # overridden
+      #       name
+      #     end
+      #   end
+      #   
+      #   user = User.find_by_name('Phusion')
+      #   user_path(path)  # =&gt; &quot;/users/Phusion&quot;
       def to_param
         # We can't use alias_method here, because method 'id' optimizes itself on the fly.
         (id = self.id) ? id.to_s : nil # Be sure to stringify the id for routes
@@ -2173,11 +2336,11 @@ module ActiveRecord #:nodoc:
       def cache_key
         case
         when new_record?
-          &quot;#{self.class.name.tableize}/new&quot;
-        when self[:updated_at]
-          &quot;#{self.class.name.tableize}/#{id}-#{updated_at.to_s(:number)}&quot;
+          &quot;#{self.class.model_name.cache_key}/new&quot;
+        when timestamp = self[:updated_at]
+          &quot;#{self.class.model_name.cache_key}/#{id}-#{timestamp.to_s(:number)}&quot;
         else
-          &quot;#{self.class.name.tableize}/#{id}&quot;
+          &quot;#{self.class.model_name.cache_key}/#{id}&quot;
         end
       end
 
@@ -2199,32 +2362,66 @@ module ActiveRecord #:nodoc:
         defined?(@new_record) &amp;&amp; @new_record
       end
 
-      # * No record exists: Creates a new record with values matching those of the object attributes.
-      # * A record does exist: Updates the record with values matching those of the object attributes.
+      # :call-seq:
+      #   save(perform_validation = true)
+      #
+      # Saves the model.
       #
-      # Note: If your model specifies any validations then the method declaration dynamically
-      # changes to:
-      #   save(perform_validation=true)
-      # Calling save(false) saves the model without running validations.
-      # See ActiveRecord::Validations for more information.
+      # If the model is new a record gets created in the database, otherwise
+      # the existing record gets updated.
+      #
+      # If +perform_validation+ is true validations run. If any of them fail
+      # the action is cancelled and +save+ returns +false+. If the flag is
+      # false validations are bypassed altogether. See
+      # ActiveRecord::Validations for more information. 
+      #
+      # There's a series of callbacks associated with +save+. If any of the
+      # &lt;tt&gt;before_*&lt;/tt&gt; callbacks return +false+ the action is cancelled and
+      # +save+ returns +false+. See ActiveRecord::Callbacks for further
+      # details. 
       def save
         create_or_update
       end
 
-      # Attempts to save the record, but instead of just returning false if it couldn't happen, it raises a
-      # RecordNotSaved exception
+      # Saves the model.
+      #
+      # If the model is new a record gets created in the database, otherwise
+      # the existing record gets updated.
+      #
+      # With &lt;tt&gt;save!&lt;/tt&gt; validations always run. If any of them fail
+      # ActiveRecord::RecordInvalid gets raised. See ActiveRecord::Validations
+      # for more information. 
+      #
+      # There's a series of callbacks associated with &lt;tt&gt;save!&lt;/tt&gt;. If any of
+      # the &lt;tt&gt;before_*&lt;/tt&gt; callbacks return +false+ the action is cancelled
+      # and &lt;tt&gt;save!&lt;/tt&gt; raises ActiveRecord::RecordNotSaved. See
+      # ActiveRecord::Callbacks for further details. 
       def save!
         create_or_update || raise(RecordNotSaved)
       end
 
       # Deletes the record in the database and freezes this instance to reflect that no changes should
       # be made (since they can't be persisted).
+      #
+      # Unlike #destroy, this method doesn't run any +before_delete+ and +after_delete+
+      # callbacks, nor will it enforce any association +:dependent+ rules.
+      # 
+      # In addition to deleting this record, any defined +before_delete+ and +after_delete+
+      # callbacks are run, and +:dependent+ rules defined on associations are run.
+      def delete
+        self.class.delete(id) unless new_record?
+        freeze
+      end
+
+      # Deletes the record in the database and freezes this instance to reflect that no changes should
+      # be made (since they can't be persisted).
       def destroy
         unless new_record?
-          connection.delete &lt;&lt;-end_sql, &quot;#{self.class.name} Destroy&quot;
-            DELETE FROM #{self.class.quoted_table_name}
-            WHERE #{connection.quote_column_name(self.class.primary_key)} = #{quoted_id}
-          end_sql
+          connection.delete(
+            &quot;DELETE FROM #{self.class.quoted_table_name} &quot; +
+            &quot;WHERE #{connection.quote_column_name(self.class.primary_key)} = #{quoted_id}&quot;,
+            &quot;#{self.class.name} Destroy&quot;
+          )
         end
 
         freeze
@@ -2258,12 +2455,12 @@ module ActiveRecord #:nodoc:
         end
       end
 
-      # Updates a single attribute and saves the record. This is especially useful for boolean flags on existing records.
-      # Note: This method is overwritten by the Validation module that'll make sure that updates made with this method
-      # aren't subjected to validation checks. Hence, attributes can be updated even if the full object isn't valid.
+      # Updates a single attribute and saves the record without going through the normal validation procedure.
+      # This is especially useful for boolean flags on existing records. The regular +update_attribute+ method
+      # in Base is replaced with this when the validations module is mixed in, which it is by default.
       def update_attribute(name, value)
         send(name.to_s + '=', value)
-        save
+        save(false)
       end
 
       # Updates all the attributes from the passed-in Hash and saves the record. If the object is invalid, the saving will
@@ -2356,10 +2553,25 @@ module ActiveRecord #:nodoc:
       end
 
       # Allows you to set all the attributes at once by passing in a hash with keys
-      # matching the attribute names (which again matches the column names). Sensitive attributes can be protected
-      # from this form of mass-assignment by using the +attr_protected+ macro. Or you can alternatively
-      # specify which attributes *can* be accessed with the +attr_accessible+ macro. Then all the
+      # matching the attribute names (which again matches the column names).
+      #
+      # If +guard_protected_attributes+ is true (the default), then sensitive
+      # attributes can be protected from this form of mass-assignment by using
+      # the +attr_protected+ macro. Or you can alternatively specify which
+      # attributes *can* be accessed with the +attr_accessible+ macro. Then all the
       # attributes not included in that won't be allowed to be mass-assigned.
+      #
+      #   class User &lt; ActiveRecord::Base
+      #     attr_protected :is_admin
+      #   end
+      #   
+      #   user = User.new
+      #   user.attributes = { :username =&gt; 'Phusion', :is_admin =&gt; true }
+      #   user.username   # =&gt; &quot;Phusion&quot;
+      #   user.is_admin?  # =&gt; false
+      #   
+      #   user.send(:attributes=, { :username =&gt; 'Phusion', :is_admin =&gt; true }, false)
+      #   user.is_admin?  # =&gt; true
       def attributes=(new_attributes, guard_protected_attributes = true)
         return if new_attributes.nil?
         attributes = new_attributes.dup
@@ -2369,7 +2581,11 @@ module ActiveRecord #:nodoc:
         attributes = remove_attributes_protected_from_mass_assignment(attributes) if guard_protected_attributes
 
         attributes.each do |k, v|
-          k.include?(&quot;(&quot;) ? multi_parameter_attributes &lt;&lt; [ k, v ] : send(k + &quot;=&quot;, v)
+          if k.include?(&quot;(&quot;)
+            multi_parameter_attributes &lt;&lt; [ k, v ]
+          else
+            respond_to?(:&quot;#{k}=&quot;) ? send(:&quot;#{k}=&quot;, v) : raise(UnknownAttributeError, &quot;unknown attribute: #{k}&quot;)
+          end
         end
 
         assign_multiparameter_attributes(multi_parameter_attributes)
@@ -2532,11 +2748,14 @@ module ActiveRecord #:nodoc:
       end
 
       def convert_number_column_value(value)
-        case value
-          when FalseClass; 0
-          when TrueClass;  1
-          when '';         nil
-          else value
+        if value == false
+          0
+        elsif value == true
+          1
+        elsif value.is_a?(String) &amp;&amp; value.blank?
+          nil
+        else
+          value
         end
       end
 
@@ -2555,7 +2774,7 @@ module ActiveRecord #:nodoc:
         removed_attributes = attributes.keys - safe_attributes.keys
 
         if removed_attributes.any?
-          logger.debug &quot;WARNING: Can't mass-assign these protected attributes: #{removed_attributes.join(', ')}&quot;
+          log_protected_attribute_removal(removed_attributes)
         end
 
         safe_attributes
@@ -2570,6 +2789,10 @@ module ActiveRecord #:nodoc:
         end
       end
 
+      def log_protected_attribute_removal(*attributes)
+        logger.debug &quot;WARNING: Can't mass-assign these protected attributes: #{attributes.join(', ')}&quot;
+      end
+
       # The primary key and inheritance column can never be set by mass-assignment for security reasons.
       def attributes_protected_by_default
         default = [ self.class.primary_key, self.class.inheritance_column ]
@@ -2632,7 +2855,7 @@ module ActiveRecord #:nodoc:
       end
 
       def instantiate_time_object(name, values)
-        if self.class.time_zone_aware_attributes &amp;&amp; !self.class.skip_time_zone_conversion_for_attributes.include?(name.to_sym)
+        if self.class.send(:create_time_zone_conversion_attribute?, name, column_for_attribute(name))
           Time.zone.local(*values)
         else
           Time.time_with_datetime_fallback(@@default_timezone, *values)
@@ -2723,7 +2946,7 @@ module ActiveRecord #:nodoc:
       end
 
       def object_from_yaml(string)
-        return string unless string.is_a?(String)
+        return string unless string.is_a?(String) &amp;&amp; string =~ /^---/
         YAML::load(string) rescue string
       end
 </diff>
      <filename>vendor/activerecord/lib/active_record/base.rb</filename>
    </modified>
    <modified>
      <diff>@@ -14,7 +14,7 @@ module ActiveRecord
       #
       # The third approach, count using options, accepts an option hash as the only parameter. The options are:
       #
-      # * &lt;tt&gt;:conditions&lt;/tt&gt;: An SQL fragment like &quot;administrator = 1&quot; or [ &quot;user_name = ?&quot;, username ]. See conditions in the intro.
+      # * &lt;tt&gt;:conditions&lt;/tt&gt;: An SQL fragment like &quot;administrator = 1&quot; or [ &quot;user_name = ?&quot;, username ]. See conditions in the intro to ActiveRecord::Base.
       # * &lt;tt&gt;:joins&lt;/tt&gt;: Either an SQL fragment for additional joins like &quot;LEFT JOIN comments ON comments.post_id = id&quot; (rarely needed)
       #   or named associations in the same form used for the &lt;tt&gt;:include&lt;/tt&gt; option, which will perform an INNER JOIN on the associated table(s).
       #   If the value is a string, then the records will be returned read-only since they will have attributes that do not correspond to the table's columns.
@@ -98,7 +98,7 @@ module ActiveRecord
       #       end
       #
       # Options:
-      # * &lt;tt&gt;:conditions&lt;/tt&gt; - An SQL fragment like &quot;administrator = 1&quot; or [ &quot;user_name = ?&quot;, username ]. See conditions in the intro.
+      # * &lt;tt&gt;:conditions&lt;/tt&gt; - An SQL fragment like &quot;administrator = 1&quot; or [ &quot;user_name = ?&quot;, username ]. See conditions in the intro to ActiveRecord::Base.
       # * &lt;tt&gt;:include&lt;/tt&gt;: Eager loading, see Associations for details.  Since calculations don't load anything, the purpose of this is to access fields on joined tables in your conditions, order, or group clauses.
       # * &lt;tt&gt;:joins&lt;/tt&gt; - An SQL fragment for additional joins like &quot;LEFT JOIN comments ON comments.post_id = id&quot;. (Rarely needed).
       #   The records will be returned read-only since they will have attributes that do not correspond to the table's columns.
@@ -188,7 +188,7 @@ module ActiveRecord
           end
 
           joins = &quot;&quot;
-          add_joins!(joins, options, scope)
+          add_joins!(joins, options[:joins], scope)
 
           if merged_includes.any?
             join_dependency = ActiveRecord::Associations::ClassMethods::JoinDependency.new(self, merged_includes, joins)
@@ -217,7 +217,7 @@ module ActiveRecord
 
           sql &lt;&lt; &quot; ORDER BY #{options[:order]} &quot;       if options[:order]
           add_limit!(sql, options, scope)
-          sql &lt;&lt; ') AS #{aggregate_alias}_subquery' if use_workaround
+          sql &lt;&lt; &quot;) #{aggregate_alias}_subquery&quot; if use_workaround
           sql
         end
 
@@ -266,7 +266,14 @@ module ActiveRecord
         #   column_alias_for(&quot;count(*)&quot;)                 # =&gt; &quot;count_all&quot;
         #   column_alias_for(&quot;count&quot;, &quot;id&quot;)              # =&gt; &quot;count_id&quot;
         def column_alias_for(*keys)
-          connection.table_alias_for(keys.join(' ').downcase.gsub(/\*/, 'all').gsub(/\W+/, ' ').strip.gsub(/ +/, '_'))
+          table_name = keys.join(' ')
+          table_name.downcase!
+          table_name.gsub!(/\*/, 'all')
+          table_name.gsub!(/\W+/, ' ')
+          table_name.strip!
+          table_name.gsub!(/ +/, '_')
+
+          connection.table_alias_for(table_name)
         end
 
         def column_for(field)
@@ -278,11 +285,15 @@ module ActiveRecord
           operation = operation.to_s.downcase
           case operation
             when 'count' then value.to_i
-            when 'sum'   then value =~ /\./ ? value.to_f : value.to_i
-            when 'avg'   then value &amp;&amp; value.to_f
-            else column ? column.type_cast(value) : value
+            when 'sum'   then type_cast_using_column(value || '0', column)
+            when 'avg'   then value &amp;&amp; (value.is_a?(Fixnum) ? value.to_f : value).to_d
+            else type_cast_using_column(value, column)
           end
         end
+
+        def type_cast_using_column(value, column)
+          column ? column.type_cast(value) : value
+        end
     end
   end
 end</diff>
      <filename>vendor/activerecord/lib/active_record/calculations.rb</filename>
    </modified>
    <modified>
      <diff>@@ -3,9 +3,9 @@ require 'observer'
 module ActiveRecord
   # Callbacks are hooks into the lifecycle of an Active Record object that allow you to trigger logic
   # before or after an alteration of the object state. This can be used to make sure that associated and
-  # dependent objects are deleted when destroy is called (by overwriting +before_destroy+) or to massage attributes
+  # dependent objects are deleted when +destroy+ is called (by overwriting +before_destroy+) or to massage attributes
   # before they're validated (by overwriting +before_validation+). As an example of the callbacks initiated, consider
-  # the &lt;tt&gt;Base#save&lt;/tt&gt; call:
+  # the &lt;tt&gt;Base#save&lt;/tt&gt; call for a new record:
   #
   # * (-) &lt;tt&gt;save&lt;/tt&gt;
   # * (-) &lt;tt&gt;valid&lt;/tt&gt;
@@ -22,7 +22,8 @@ module ActiveRecord
   # * (8) &lt;tt&gt;after_save&lt;/tt&gt;
   #
   # That's a total of eight callbacks, which gives you immense power to react and prepare for each state in the
-  # Active Record lifecycle.
+  # Active Record lifecycle. The sequence for calling &lt;tt&gt;Base#save&lt;/tt&gt; an existing record is similar, except that each 
+  # &lt;tt&gt;_on_create&lt;/tt&gt; callback is replaced by the corresponding &lt;tt&gt;_on_update&lt;/tt&gt; callback.
   #
   # Examples:
   #   class CreditCard &lt; ActiveRecord::Base
@@ -50,7 +51,7 @@ module ActiveRecord
   #
   # == Inheritable callback queues
   #
-  # Besides the overwriteable callback methods, it's also possible to register callbacks through the use of the callback macros.
+  # Besides the overwritable callback methods, it's also possible to register callbacks through the use of the callback macros.
   # Their main advantage is that the macros add behavior into a callback queue that is kept intact down through an inheritance
   # hierarchy. Example:
   #
@@ -161,7 +162,7 @@ module ActiveRecord
   # == &lt;tt&gt;before_validation*&lt;/tt&gt; returning statements
   #
   # If the returning value of a +before_validation+ callback can be evaluated to +false+, the process will be aborted and &lt;tt&gt;Base#save&lt;/tt&gt; will return +false+.
-  # If Base#save! is called it will raise a RecordNotSaved exception.
+  # If Base#save! is called it will raise a ActiveRecord::RecordInvalid exception.
   # Nothing will be appended to the errors object.
   #
   # == Canceling callbacks
@@ -169,6 +170,18 @@ module ActiveRecord
   # If a &lt;tt&gt;before_*&lt;/tt&gt; callback returns +false+, all the later callbacks and the associated action are cancelled. If an &lt;tt&gt;after_*&lt;/tt&gt; callback returns
   # +false+, all the later callbacks are cancelled. Callbacks are generally run in the order they are defined, with the exception of callbacks
   # defined as methods on the model, which are called last.
+  #
+  # == Transactions
+  #
+  # The entire callback chain of a +save+, &lt;tt&gt;save!&lt;/tt&gt;, or +destroy+ call runs
+  # within a transaction. That includes &lt;tt&gt;after_*&lt;/tt&gt; hooks. If everything
+  # goes fine a COMMIT is executed once the chain has been completed.
+  #
+  # If a &lt;tt&gt;before_*&lt;/tt&gt; callback cancels the action a ROLLBACK is issued. You
+  # can also trigger a ROLLBACK raising an exception in any of the callbacks,
+  # including &lt;tt&gt;after_*&lt;/tt&gt; hooks. Note, however, that in that case the client
+  # needs to be aware of it because an ordinary +save+ will raise such exception
+  # instead of quietly returning +false+.
   module Callbacks
     CALLBACKS = %w(
       after_find after_initialize before_save after_save before_create after_create before_update after_update before_validation
@@ -197,6 +210,8 @@ module ActiveRecord
     def before_save() end
 
     # Is called _after_ &lt;tt&gt;Base.save&lt;/tt&gt; (regardless of whether it's a +create+ or +update+ save).
+    # Note that this callback is still wrapped in the transaction around +save+. For example, if you
+    # invoke an external indexer at this point it won't see the changes in the database.
     #
     #  class Contact &lt; ActiveRecord::Base
     #    after_save { logger.info( 'New contact saved!' ) }
@@ -214,6 +229,8 @@ module ActiveRecord
     def before_create() end
 
     # Is called _after_ &lt;tt&gt;Base.save&lt;/tt&gt; on new objects that haven't been saved yet (no record exists).
+    # Note that this callback is still wrapped in the transaction around +save+. For example, if you
+    # invoke an external indexer at this point it won't see the changes in the database.
     def after_create() end
     def create_with_callbacks #:nodoc:
       return false if callback(:before_create) == false
@@ -227,6 +244,8 @@ module ActiveRecord
     def before_update() end
 
     # Is called _after_ &lt;tt&gt;Base.save&lt;/tt&gt; on existing objects that have a record.
+    # Note that this callback is still wrapped in the transaction around +save+. For example, if you
+    # invoke an external indexer at this point it won't see the changes in the database.
     def after_update() end
 
     def update_with_callbacks(*args) #:nodoc:
@@ -262,7 +281,7 @@ module ActiveRecord
     def valid_with_callbacks? #:nodoc:
       return false if callback(:before_validation) == false
       if new_record? then result = callback(:before_validation_on_create) else result = callback(:before_validation_on_update) end
-      return false if result == false
+      return false if false == result
 
       result = valid_without_callbacks?
 
@@ -293,14 +312,14 @@ module ActiveRecord
 
     private
       def callback(method)
-        notify(method)
-
-        result = run_callbacks(method) { |result, object| result == false }
+        result = run_callbacks(method) { |result, object| false == result }
 
         if result != false &amp;&amp; respond_to_without_attributes?(method)
           result = send(method)
         end
 
+        notify(method)
+
         return result
       end
 </diff>
      <filename>vendor/activerecord/lib/active_record/callbacks.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,5 +1,3 @@
-require 'set'
-
 module ActiveRecord
   class Base
     class ConnectionSpecification #:nodoc:
@@ -9,163 +7,9 @@ module ActiveRecord
       end
     end
 
-    # Check for activity after at least +verification_timeout+ seconds.
-    # Defaults to 0 (always check.)
-    cattr_accessor :verification_timeout, :instance_writer =&gt; false
-    @@verification_timeout = 0
-
-    # The class -&gt; [adapter_method, config] map
-    @@defined_connections = {}
-
-    # The class -&gt; thread id -&gt; adapter cache. (class -&gt; adapter if not allow_concurrency)
-    @@active_connections = {}
-
-    class &lt;&lt; self
-      # Retrieve the connection cache.
-      def thread_safe_active_connections #:nodoc:
-        @@active_connections[Thread.current.object_id] ||= {}
-      end
-     
-      def single_threaded_active_connections #:nodoc:
-        @@active_connections
-      end
-     
-      # pick up the right active_connection method from @@allow_concurrency
-      if @@allow_concurrency
-        alias_method :active_connections, :thread_safe_active_connections
-      else
-        alias_method :active_connections, :single_threaded_active_connections
-      end
-     
-      # set concurrency support flag (not thread safe, like most of the methods in this file)
-      def allow_concurrency=(threaded) #:nodoc:
-        logger.debug &quot;allow_concurrency=#{threaded}&quot; if logger
-        return if @@allow_concurrency == threaded
-        clear_all_cached_connections!
-        @@allow_concurrency = threaded
-        method_prefix = threaded ? &quot;thread_safe&quot; : &quot;single_threaded&quot;
-        sing = (class &lt;&lt; self; self; end)
-        [:active_connections, :scoped_methods].each do |method|
-          sing.send(:alias_method, method, &quot;#{method_prefix}_#{method}&quot;)
-        end
-        log_connections if logger
-      end
-      
-      def active_connection_name #:nodoc:
-        @active_connection_name ||=
-           if active_connections[name] || @@defined_connections[name]
-             name
-           elsif self == ActiveRecord::Base
-             nil
-           else
-             superclass.active_connection_name
-           end
-      end
-
-      def clear_active_connection_name #:nodoc:
-        @active_connection_name = nil
-        subclasses.each { |klass| klass.clear_active_connection_name }
-      end
-
-      # Returns the connection currently associated with the class. This can
-      # also be used to &quot;borrow&quot; the connection to do database work unrelated
-      # to any of the specific Active Records.
-      def connection
-        if defined?(@active_connection_name) &amp;&amp; (conn = active_connections[@active_connection_name])
-          conn
-        else
-          # retrieve_connection sets the cache key.
-          conn = retrieve_connection
-          active_connections[@active_connection_name] = conn
-        end
-      end
-
-      # Clears the cache which maps classes to connections.
-      def clear_active_connections!
-        clear_cache!(@@active_connections) do |name, conn|
-          conn.disconnect!
-        end
-      end
-      
-      # Clears the cache which maps classes 
-      def clear_reloadable_connections!
-        if @@allow_concurrency
-          # With concurrent connections @@active_connections is
-          # a hash keyed by thread id.
-          @@active_connections.each do |thread_id, conns|
-            conns.each do |name, conn|
-              if conn.requires_reloading?
-                conn.disconnect!
-                @@active_connections[thread_id].delete(name)
-              end
-            end
-          end
-        else
-          @@active_connections.each do |name, conn|
-            if conn.requires_reloading?
-              conn.disconnect!
-              @@active_connections.delete(name)
-            end
-          end
-        end
-      end
-
-      # Verify active connections.
-      def verify_active_connections! #:nodoc:
-        if @@allow_concurrency
-          remove_stale_cached_threads!(@@active_connections) do |name, conn|
-            conn.disconnect!
-          end
-        end
-        
-        active_connections.each_value do |connection|
-          connection.verify!(@@verification_timeout)
-        end
-      end
-
-      private
-        def clear_cache!(cache, thread_id = nil, &amp;block)
-          if cache
-            if @@allow_concurrency
-              thread_id ||= Thread.current.object_id
-              thread_cache, cache = cache, cache[thread_id]
-              return unless cache
-            end
-
-            cache.each(&amp;block) if block_given?
-            cache.clear
-          end
-        ensure
-          if thread_cache &amp;&amp; @@allow_concurrency
-            thread_cache.delete(thread_id)
-          end
-        end
-
-        # Remove stale threads from the cache.
-        def remove_stale_cached_threads!(cache, &amp;block)
-          stale = Set.new(cache.keys)
-
-          Thread.list.each do |thread|
-            stale.delete(thread.object_id) if thread.alive?
-          end
-
-          stale.each do |thread_id|
-            clear_cache!(cache, thread_id, &amp;block)
-          end
-        end
-        
-        def clear_all_cached_connections!
-          if @@allow_concurrency
-            @@active_connections.each_value do |connection_hash_for_thread|
-              connection_hash_for_thread.each_value {|conn| conn.disconnect! }
-              connection_hash_for_thread.clear
-            end
-          else
-            @@active_connections.each_value {|conn| conn.disconnect! }
-          end
-          @@active_connections.clear          
-        end
-    end
+    # The connection handler
+    cattr_accessor :connection_handler, :instance_writer =&gt; false
+    @@connection_handler = ConnectionAdapters::ConnectionHandler.new
 
     # Returns the connection currently associated with the class. This can
     # also be used to &quot;borrow&quot; the connection to do database work that isn't
@@ -208,9 +52,7 @@ module ActiveRecord
           raise AdapterNotSpecified unless defined? RAILS_ENV
           establish_connection(RAILS_ENV)
         when ConnectionSpecification
-          clear_active_connection_name
-          @active_connection_name = name
-          @@defined_connections[name] = spec
+          @@connection_handler.establish_connection(name, spec)
         when Symbol, String
           if configuration = configurations[spec.to_s]
             establish_connection(configuration)
@@ -243,67 +85,52 @@ module ActiveRecord
       end
     end
 
-    # Locate the connection of the nearest super class. This can be an
-    # active or defined connection: if it is the latter, it will be
-    # opened and set as the active connection for the class it was defined
-    # for (not necessarily the current class).
-    def self.retrieve_connection #:nodoc:
-      # Name is nil if establish_connection hasn't been called for
-      # some class along the inheritance chain up to AR::Base yet.
-      if name = active_connection_name
-        if conn = active_connections[name]
-          # Verify the connection.
-          conn.verify!(@@verification_timeout)
-        elsif spec = @@defined_connections[name]
-          # Activate this connection specification.
-          klass = name.constantize
-          klass.connection = spec
-          conn = active_connections[name]
-        end
+    class &lt;&lt; self
+      # Deprecated and no longer has any effect.
+      def allow_concurrency
+        ActiveSupport::Deprecation.warn(&quot;ActiveRecord::Base.allow_concurrency has been deprecated and no longer has any effect. Please remove all references to allow_concurrency.&quot;)
       end
 
-      conn or raise ConnectionNotEstablished
-    end
+      # Deprecated and no longer has any effect.
+      def allow_concurrency=(flag)
+        ActiveSupport::Deprecation.warn(&quot;ActiveRecord::Base.allow_concurrency= has been deprecated and no longer has any effect. Please remove all references to allow_concurrency=.&quot;)
+      end
 
-    # Returns true if a connection that's accessible to this class has already been opened.
-    def self.connected?
-      active_connections[active_connection_name] ? true : false
-    end
+      # Deprecated and no longer has any effect.
+      def verification_timeout
+        ActiveSupport::Deprecation.warn(&quot;ActiveRecord::Base.verification_timeout has been deprecated and no longer has any effect. Please remove all references to verification_timeout.&quot;)
+      end
 
-    # Remove the connection for this class. This will close the active
-    # connection and the defined connection (if they exist). The result
-    # can be used as an argument for establish_connection, for easily
-    # re-establishing the connection.
-    def self.remove_connection(klass=self)
-      spec = @@defined_connections[klass.name]
-      konn = active_connections[klass.name]
-      @@defined_connections.delete_if { |key, value| value == spec }
-      active_connections.delete_if { |key, value| value == konn }
-      konn.disconnect! if konn
-      spec.config if spec
-    end
+      # Deprecated and no longer has any effect.
+      def verification_timeout=(flag)
+        ActiveSupport::Deprecation.warn(&quot;ActiveRecord::Base.verification_timeout= has been deprecated and no longer has any effect. Please remove all references to verification_timeout=.&quot;)
+      end
 
-    # Set the connection for the class.
-    def self.connection=(spec) #:nodoc:
-      if spec.kind_of?(ActiveRecord::ConnectionAdapters::AbstractAdapter)
-        active_connections[name] = spec
-      elsif spec.kind_of?(ConnectionSpecification)
-        config = spec.config.reverse_merge(:allow_concurrency =&gt; @@allow_concurrency)
-        self.connection = self.send(spec.adapter_method, config)
-      elsif spec.nil?
-        raise ConnectionNotEstablished
-      else
-        establish_connection spec
+      # Returns the connection currently associated with the class. This can
+      # also be used to &quot;borrow&quot; the connection to do database work unrelated
+      # to any of the specific Active Records.
+      def connection
+        retrieve_connection
       end
-    end
 
-    # connection state logging
-    def self.log_connections #:nodoc:
-      if logger
-        logger.info &quot;Defined connections: #{@@defined_connections.inspect}&quot;
-        logger.info &quot;Active connections: #{active_connections.inspect}&quot;
-        logger.info &quot;Active connection name: #{@active_connection_name}&quot;
+      def connection_pool
+        connection_handler.retrieve_connection_pool(self)
       end
+
+      def retrieve_connection
+        connection_handler.retrieve_connection(self)
+      end
+
+      def connected?
+        connection_handler.connected?(self)
+      end
+
+      def remove_connection(klass = self)
+        connection_handler.remove_connection(klass)
+      end
+
+      delegate :clear_active_connections!, :clear_reloadable_connections!,
+        :clear_all_connections!,:verify_active_connections!, :to =&gt; :connection_handler
     end
   end
 end</diff>
      <filename>vendor/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb</filename>
    </modified>
    <modified>
      <diff>@@ -98,8 +98,14 @@ module ActiveRecord
         add_limit_offset!(sql, options) if options
       end
 
-      # Appends +LIMIT+ and +OFFSET+ options to an SQL statement.
+      # Appends +LIMIT+ and +OFFSET+ options to an SQL statement, or some SQL
+      # fragment that has the same semantics as LIMIT and OFFSET.
+      #
+      # +options+ must be a Hash which contains a +:limit+ option (required)
+      # and an +:offset+ option (optional).
+      #
       # This method *modifies* the +sql+ parameter.
+      #
       # ===== Examples
       #  add_limit_offset!('SELECT * FROM suppliers', {:limit =&gt; 10, :offset =&gt; 50})
       # generates
@@ -114,10 +120,6 @@ module ActiveRecord
         sql
       end
 
-      def sanitize_limit(limit)
-        limit.to_s[/,/] ? limit.split(',').map{ |i| i.to_i }.join(',') : limit.to_i
-      end
-
       # Appends a locking clause to an SQL statement.
       # This method *modifies* the +sql+ parameter.
       #   # SELECT * FROM suppliers FOR UPDATE
@@ -149,6 +151,14 @@ module ActiveRecord
         &quot;INSERT INTO #{quote_table_name(table_name)} VALUES(DEFAULT)&quot;
       end
 
+      def case_sensitive_equality_operator
+        &quot;=&quot;
+      end
+
+      def limited_update_conditions(where_sql, quoted_table_name, quoted_primary_key)
+        &quot;WHERE #{quoted_primary_key} IN (SELECT #{quoted_primary_key} FROM #{quoted_table_name} #{where_sql})&quot;
+      end
+
       protected
         # Returns an array of record hashes with the column names as keys and
         # column values as values.
@@ -171,6 +181,21 @@ module ActiveRecord
         def delete_sql(sql, name = nil)
           update_sql(sql, name)
         end
+
+        # Sanitizes the given LIMIT parameter in order to prevent SQL injection.
+        #
+        # +limit+ may be anything that can evaluate to a string via #to_s. It
+        # should look like an integer, or a comma-delimited list of integers.
+        #
+        # Returns the sanitized limit parameter, either as an integer, or as a
+        # string which contains a comma-delimited list of integers.
+        def sanitize_limit(limit)
+          if limit.to_s =~ /,/
+            limit.to_s.split(',').map{ |i| i.to_i }.join(',')
+          else
+            limit.to_i
+          end
+        end
     end
   end
 end</diff>
      <filename>vendor/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb</filename>
    </modified>
    <modified>
      <diff>@@ -4,7 +4,6 @@ module ActiveRecord
       class &lt;&lt; self
         def included(base)
           base.class_eval do
-            attr_accessor :query_cache_enabled
             alias_method_chain :columns, :query_cache
             alias_method_chain :select_all, :query_cache
           end
@@ -26,6 +25,8 @@ module ActiveRecord
         end
       end
 
+      attr_reader :query_cache, :query_cache_enabled
+
       # Enable the query cache within the block.
       def cache
         old, @query_cache_enabled = @query_cache_enabled, true</diff>
      <filename>vendor/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,4 +1,5 @@
 require 'date'
+require 'set'
 require 'bigdecimal'
 require 'bigdecimal/util'
 
@@ -6,6 +7,8 @@ module ActiveRecord
   module ConnectionAdapters #:nodoc:
     # An abstract definition of a column in a table.
     class Column
+      TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE'].to_set
+
       module Format
         ISO_DATE = /\A(\d{4})-(\d\d)-(\d\d)\z/
         ISO_DATETIME = /\A(\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)(\.\d+)?\z/
@@ -30,11 +33,15 @@ module ActiveRecord
       end
 
       def text?
-        [:string, :text].include? type
+        type == :string || type == :text
       end
 
       def number?
-        [:float, :integer, :decimal].include? type
+        type == :integer || type == :float || type == :decimal
+      end
+
+      def has_default?
+        !default.nil?
       end
 
       # Returns the Ruby class that corresponds to the abstract data type.
@@ -135,10 +142,10 @@ module ActiveRecord
 
         # convert something to a boolean
         def value_to_boolean(value)
-          if value == true || value == false
-            value
+          if value.is_a?(String) &amp;&amp; value.blank?
+            nil
           else
-            %w(true t 1).include?(value.to_s.downcase)
+            TRUE_VALUES.include?(value)
           end
         end
 
@@ -249,6 +256,10 @@ module ActiveRecord
     class IndexDefinition &lt; Struct.new(:table, :name, :unique, :columns) #:nodoc:
     end
 
+    # Abstract representation of a column definition. Instances of this type
+    # are typically created by methods in TableDefinition, and added to the
+    # +columns+ attribute of said TableDefinition object, in order to be used
+    # for generating a number of table creation or table changing SQL statements.
     class ColumnDefinition &lt; Struct.new(:base, :name, :type, :limit, :precision, :scale, :default, :null) #:nodoc:
 
       def sql_type
@@ -272,9 +283,29 @@ module ActiveRecord
         end
     end
 
-    # Represents a SQL table in an abstract way.
-    # Columns are stored as a ColumnDefinition in the +columns+ attribute.
+    # Represents the schema of an SQL table in an abstract way. This class
+    # provides methods for manipulating the schema representation.
+    #
+    # Inside migration files, the +t+ object in +create_table+ and
+    # +change_table+ is actually of this type:
+    #
+    #   class SomeMigration &lt; ActiveRecord::Migration
+    #     def self.up
+    #       create_table :foo do |t|
+    #         puts t.class  # =&gt; &quot;ActiveRecord::ConnectionAdapters::TableDefinition&quot;
+    #       end
+    #     end
+    #     
+    #     def self.down
+    #       ...
+    #     end
+    #   end
+    #
+    # The table definitions
+    # The Columns are stored as a ColumnDefinition in the +columns+ attribute.
     class TableDefinition
+      # An array of ColumnDefinition objects, representing the column changes
+      # that have been defined.
       attr_accessor :columns
 
       def initialize(base)
@@ -318,6 +349,12 @@ module ActiveRecord
       # * &lt;tt&gt;:scale&lt;/tt&gt; -
       #   Specifies the scale for a &lt;tt&gt;:decimal&lt;/tt&gt; column.
       #
+      # For clarity's sake: the precision is the number of significant digits,
+      # while the scale is the number of digits that can be stored following
+      # the decimal point. For example, the number 123.45 has a precision of 5
+      # and a scale of 2. A decimal with a precision of 5 and a scale of 2 can
+      # range from -999.99 to 999.99.
+      #
       # Please be aware of different RDBMS implementations behavior with
       # &lt;tt&gt;:decimal&lt;/tt&gt; columns:
       # * The SQL standard says the default scale should be 0, &lt;tt&gt;:scale&lt;/tt&gt; &lt;=
@@ -371,6 +408,10 @@ module ActiveRecord
       #  td.column(:huge_integer, :decimal, :precision =&gt; 30)
       #  # =&gt; huge_integer DECIMAL(30)
       #
+      #  # Defines a column with a database-specific type.
+      #  td.column(:foo, 'polygon')
+      #  # =&gt; foo polygon
+      #
       # == Short-hand examples
       #
       # Instead of calling +column+ directly, you can also work with the short-hand definitions for the default types.</diff>
      <filename>vendor/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb</filename>
    </modified>
    <modified>
      <diff>@@ -31,19 +31,25 @@ module ActiveRecord
       # See the concrete implementation for details on the expected parameter values.
       def columns(table_name, name = nil) end
 
-      # Creates a new table
+      # Creates a new table with the name +table_name+. +table_name+ may either
+      # be a String or a Symbol.
+      #
       # There are two ways to work with +create_table+.  You can use the block
       # form or the regular form, like this:
       #
       # === Block form
-      #  # create_table() yields a TableDefinition instance
+      #  # create_table() passes a TableDefinition object to the block.
+      #  # This form will not only create the table, but also columns for the
+      #  # table.
       #  create_table(:suppliers) do |t|
       #    t.column :name, :string, :limit =&gt; 60
       #    # Other fields here
       #  end
       #
       # === Regular form
+      #  # Creates a table called 'suppliers' with no columns.
       #  create_table(:suppliers)
+      #  # Add a column to 'suppliers'.
       #  add_column(:suppliers, :name, :string, {:limit =&gt; 60})
       #
       # The +options+ hash can include the following keys:
@@ -356,7 +362,7 @@ module ActiveRecord
 
       def type_to_sql(type, limit = nil, precision = nil, scale = nil) #:nodoc:
         if native = native_database_types[type]
-          column_type_sql = native.is_a?(Hash) ? native[:name] : native
+          column_type_sql = (native.is_a?(Hash) ? native[:name] : native).dup
 
           if type == :decimal # ignore limit, use precision and scale
             scale ||= native[:scale]
@@ -371,7 +377,7 @@ module ActiveRecord
               raise ArgumentError, &quot;Error adding decimal column: precision cannot be empty if scale if specified&quot;
             end
 
-          elsif limit ||= native.is_a?(Hash) &amp;&amp; native[:limit]
+          elsif (type != :primary_key) &amp;&amp; (limit ||= native.is_a?(Hash) &amp;&amp; native[:limit])
             column_type_sql &lt;&lt; &quot;(#{limit})&quot;
           end
 </diff>
      <filename>vendor/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb</filename>
    </modified>
    <modified>
      <diff>@@ -7,23 +7,31 @@ require 'active_record/connection_adapters/abstract/schema_definitions'
 require 'active_record/connection_adapters/abstract/schema_statements'
 require 'active_record/connection_adapters/abstract/database_statements'
 require 'active_record/connection_adapters/abstract/quoting'
+require 'active_record/connection_adapters/abstract/connection_pool'
 require 'active_record/connection_adapters/abstract/connection_specification'
 require 'active_record/connection_adapters/abstract/query_cache'
 
 module ActiveRecord
   module ConnectionAdapters # :nodoc:
+    # ActiveRecord supports multiple database systems. AbstractAdapter and
+    # related classes form the abstraction layer which makes this possible.
+    # An AbstractAdapter represents a connection to a database, and provides an
+    # abstract interface for database-specific functionality such as establishing
+    # a connection, escaping values, building the right SQL fragments for ':offset'
+    # and ':limit' options, etc.
+    #
     # All the concrete database adapters follow the interface laid down in this class.
-    # You can use this interface directly by borrowing the database connection from the Base with
-    # Base.connection.
+    # ActiveRecord::Base.connection returns an AbstractAdapter object, which
+    # you can use.
     #
-    # Most of the methods in the adapter are useful during migrations.  Most
-    # notably, SchemaStatements#create_table, SchemaStatements#drop_table,
-    # SchemaStatements#add_index, SchemaStatements#remove_index,
-    # SchemaStatements#add_column, SchemaStatements#change_column and
-    # SchemaStatements#remove_column are very useful.
+    # Most of the methods in the adapter are useful during migrations. Most
+    # notably, the instance methods provided by SchemaStatement are very useful.
     class AbstractAdapter
       include Quoting, DatabaseStatements, SchemaStatements
       include QueryCache
+      include ActiveSupport::Callbacks
+      define_callbacks :checkout, :checkin
+
       @@row_even = true
 
       def initialize(connection, logger = nil) #:nodoc:
@@ -51,6 +59,13 @@ module ActiveRecord
         true
       end
 
+      # Does this adapter support DDL rollbacks in transactions?  That is, would
+      # CREATE TABLE or ALTER TABLE get rolled back by a transaction?  PostgreSQL,
+      # SQL Server, and others support this.  MySQL and others do not.
+      def supports_ddl_transactions?
+        false
+      end
+
       # Should primary key values be selected from their corresponding
       # sequence before the insert statement?  If true, next_sequence_value
       # is called before each insert to set the record's primary key.
@@ -80,48 +95,74 @@ module ActiveRecord
 
       # CONNECTION MANAGEMENT ====================================
 
-      # Is this connection active and ready to perform queries?
+      # Checks whether the connection to the database is still active. This includes
+      # checking whether the database is actually capable of responding, i.e. whether
+      # the connection isn't stale.
       def active?
         @active != false
       end
 
-      # Close this connection and open a new one in its place.
+      # Disconnects from the database if already connected, and establishes a
+      # new connection with the database.
       def reconnect!
         @active = true
       end
 
-      # Close this connection
+      # Disconnects from the database if already connected. Otherwise, this
+      # method does nothing.
       def disconnect!
         @active = false
       end
 
+      # Reset the state of this connection, directing the DBMS to clear
+      # transactions and other connection-related server-side state. Usually a
+      # database-dependent operation.
+      #
+      # The default implementation does nothing; the implementation should be
+      # overridden by concrete adapters.
+      def reset!
+        # this should be overridden by concrete adapters
+      end
+
       # Returns true if its safe to reload the connection between requests for development mode.
-      # This is not the case for Ruby/MySQL and it's not necessary for any adapters except SQLite.
       def requires_reloading?
-        false
+        true
       end
 
-      # Lazily verify this connection, calling &lt;tt&gt;active?&lt;/tt&gt; only if it hasn't
-      # been called for +timeout+ seconds.
-      def verify!(timeout)
-        now = Time.now.to_i
-        if (now - @last_verification) &gt; timeout
-          reconnect! unless active?
-          @last_verification = now
-        end
+      # Checks whether the connection to the database is still active (i.e. not stale).
+      # This is done under the hood by calling &lt;tt&gt;active?&lt;/tt&gt;. If the connection
+      # is no longer active, then this method will reconnect to the database.
+      def verify!(*ignored)
+        reconnect! unless active?
       end
 
-      # Provides access to the underlying database connection. Useful for
-      # when you need to call a proprietary method such as postgresql's lo_*
-      # methods
+      # Provides access to the underlying database driver for this adapter. For
+      # example, this method returns a Mysql object in case of MysqlAdapter,
+      # and a PGconn object in case of PostgreSQLAdapter.
+      #
+      # This is useful for when you need to call a proprietary method such as
+      # PostgreSQL's lo_* methods.
       def raw_connection
         @connection
       end
 
-      def log_info(sql, name, runtime)
+      def open_transactions
+        @open_transactions ||= 0
+      end
+
+      def increment_open_transactions
+        @open_transactions ||= 0
+        @open_transactions += 1
+      end
+
+      def decrement_open_transactions
+        @open_transactions -= 1
+      end
+
+      def log_info(sql, name, seconds)
         if @logger &amp;&amp; @logger.debug?
-          name = &quot;#{name.nil? ? &quot;SQL&quot; : name} (#{sprintf(&quot;%f&quot;, runtime)})&quot;
-          @logger.debug format_log_entry(name, sql.squeeze(' '))
+          name = &quot;#{name.nil? ? &quot;SQL&quot; : name} (#{sprintf(&quot;%.1f&quot;, seconds * 1000)}ms)&quot;
+          @logger.debug(format_log_entry(name, sql.squeeze(' ')))
         end
       end
 </diff>
      <filename>vendor/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb</filename>
    </modified>
    <modified>
      <diff>@@ -42,27 +42,6 @@ end
 
 module ActiveRecord
   class Base
-    def self.require_mysql
-      # Include the MySQL driver if one hasn't already been loaded
-      unless defined? Mysql
-        begin
-          require_library_or_gem 'mysql'
-        rescue LoadError =&gt; cannot_require_mysql
-          # Use the bundled Ruby/MySQL driver if no driver is already in place
-          begin
-            ActiveSupport::Deprecation.warn &quot;You're using the Ruby-based MySQL library that ships with Rails. This library will be REMOVED FROM RAILS 2.2. Please switch to the offical mysql gem: `gem install mysql`&quot;, caller
-
-            require 'active_record/vendor/mysql'
-          rescue LoadError
-            raise cannot_require_mysql
-          end
-        end
-      end
-
-      # Define Mysql::Result.all_hashes
-      MysqlCompat.define_all_hashes_method!
-    end
-
     # Establishes a connection to the database that's used by all Active Record objects.
     def self.mysql_connection(config) # :nodoc:
       config = config.symbolize_keys
@@ -78,9 +57,19 @@ module ActiveRecord
         raise ArgumentError, &quot;No database specified. Missing argument: database.&quot;
       end
 
-      require_mysql
+      # Require the MySQL driver and define Mysql::Result.all_hashes
+      unless defined? Mysql
+        begin
+          require_library_or_gem('mysql')
+        rescue LoadError
+          $stderr.puts '!!! The bundled mysql.rb driver has been removed from Rails 2.2. Please install the mysql gem and try again: gem install mysql.'
+          raise
+        end
+      end
+      MysqlCompat.define_all_hashes_method!
+
       mysql = Mysql.init
-      mysql.ssl_set(config[:sslkey], config[:sslcert], config[:sslca], config[:sslcapath], config[:sslcipher]) if config[:sslkey]
+      mysql.ssl_set(config[:sslkey], config[:sslcert], config[:sslca], config[:sslcapath], config[:sslcipher]) if config[:sslca] || config[:sslkey]
 
       ConnectionAdapters::MysqlAdapter.new(mysql, logger, [host, username, password, database, port, socket], config)
     end
@@ -91,7 +80,7 @@ module ActiveRecord
       def extract_default(default)
         if type == :binary || type == :text
           if default.blank?
-            nil
+            return null ? nil : ''
           else
             raise ArgumentError, &quot;#{type} columns cannot have a default value: #{default.inspect}&quot;
           end
@@ -102,6 +91,11 @@ module ActiveRecord
         end
       end
 
+      def has_default?
+        return false if type == :binary || type == :text #mysql forbids defaults on blob and text columns
+        super
+      end
+
       private
         def simplified_type(field_type)
           return :boolean if MysqlAdapter.emulate_booleans &amp;&amp; field_type.downcase.index(&quot;tinyint(1)&quot;)
@@ -156,6 +150,7 @@ module ActiveRecord
     # * &lt;tt&gt;:password&lt;/tt&gt; - Defaults to nothing.
     # * &lt;tt&gt;:database&lt;/tt&gt; - The name of the database. No default, must be provided.
     # * &lt;tt&gt;:encoding&lt;/tt&gt; - (Optional) Sets the client encoding by executing &quot;SET NAMES &lt;encoding&gt;&quot; after connection.
+    # * &lt;tt&gt;:sslca&lt;/tt&gt; - Necessary to use MySQL with an SSL connection.
     # * &lt;tt&gt;:sslkey&lt;/tt&gt; - Necessary to use MySQL with an SSL connection.
     # * &lt;tt&gt;:sslcert&lt;/tt&gt; - Necessary to use MySQL with an SSL connection.
     # * &lt;tt&gt;:sslcapath&lt;/tt&gt; - Necessary to use MySQL with an SSL connection.
@@ -168,8 +163,10 @@ module ActiveRecord
     #
     #   ActiveRecord::ConnectionAdapters::MysqlAdapter.emulate_booleans = false
     class MysqlAdapter &lt; AbstractAdapter
-      @@emulate_booleans = true
       cattr_accessor :emulate_booleans
+      self.emulate_booleans = true
+
+      ADAPTER_NAME = 'MySQL'.freeze
 
       LOST_CONNECTION_ERROR_MESSAGES = [
         &quot;Server shutdown in progress&quot;,
@@ -177,7 +174,22 @@ module ActiveRecord
         &quot;Lost connection to MySQL server during query&quot;,
         &quot;MySQL server has gone away&quot; ]
 
-      QUOTED_TRUE, QUOTED_FALSE = '1', '0'
+      QUOTED_TRUE, QUOTED_FALSE = '1'.freeze, '0'.freeze
+
+      NATIVE_DATABASE_TYPES = {
+        :primary_key =&gt; &quot;int(11) DEFAULT NULL auto_increment PRIMARY KEY&quot;.freeze,
+        :string      =&gt; { :name =&gt; &quot;varchar&quot;, :limit =&gt; 255 },
+        :text        =&gt; { :name =&gt; &quot;text&quot; },
+        :integer     =&gt; { :name =&gt; &quot;int&quot;, :limit =&gt; 4 },
+        :float       =&gt; { :name =&gt; &quot;float&quot; },
+        :decimal     =&gt; { :name =&gt; &quot;decimal&quot; },
+        :datetime    =&gt; { :name =&gt; &quot;datetime&quot; },
+        :timestamp   =&gt; { :name =&gt; &quot;datetime&quot; },
+        :time        =&gt; { :name =&gt; &quot;time&quot; },
+        :date        =&gt; { :name =&gt; &quot;date&quot; },
+        :binary      =&gt; { :name =&gt; &quot;blob&quot; },
+        :boolean     =&gt; { :name =&gt; &quot;tinyint&quot;, :limit =&gt; 1 }
+      }
 
       def initialize(connection, logger, connection_options, config)
         super(connection, logger)
@@ -187,7 +199,7 @@ module ActiveRecord
       end
 
       def adapter_name #:nodoc:
-        'MySQL'
+        ADAPTER_NAME
       end
 
       def supports_migrations? #:nodoc:
@@ -195,20 +207,7 @@ module ActiveRecord
       end
 
       def native_database_types #:nodoc:
-        {
-          :primary_key =&gt; &quot;int(11) DEFAULT NULL auto_increment PRIMARY KEY&quot;.freeze,
-          :string      =&gt; { :name =&gt; &quot;varchar&quot;, :limit =&gt; 255 },
-          :text        =&gt; { :name =&gt; &quot;text&quot; },
-          :integer     =&gt; { :name =&gt; &quot;int&quot;, :limit =&gt; 4 },
-          :float       =&gt; { :name =&gt; &quot;float&quot; },
-          :decimal     =&gt; { :name =&gt; &quot;decimal&quot; },
-          :datetime    =&gt; { :name =&gt; &quot;datetime&quot; },
-          :timestamp   =&gt; { :name =&gt; &quot;datetime&quot; },
-          :time        =&gt; { :name =&gt; &quot;time&quot; },
-          :date        =&gt; { :name =&gt; &quot;date&quot; },
-          :binary      =&gt; { :name =&gt; &quot;blob&quot; },
-          :boolean     =&gt; { :name =&gt; &quot;tinyint&quot;, :limit =&gt; 1 }
-        }
+        NATIVE_DATABASE_TYPES
       end
 
 
@@ -219,7 +218,7 @@ module ActiveRecord
           s = column.class.string_to_binary(value).unpack(&quot;H*&quot;)[0]
           &quot;x'#{s}'&quot;
         elsif value.kind_of?(BigDecimal)
-          &quot;'#{value.to_s(&quot;F&quot;)}'&quot;
+          value.to_s(&quot;F&quot;)
         else
           super
         end
@@ -286,6 +285,14 @@ module ActiveRecord
         @connection.close rescue nil
       end
 
+      def reset!
+        if @connection.respond_to?(:change_user)
+          # See http://bugs.mysql.com/bug.php?id=33540 -- the workaround way to
+          # reset the connection is to change the user to the same user.
+          @connection.change_user(@config[:username], @config[:password], @config[:database])
+          configure_connection
+        end
+      end
 
       # DATABASE STATEMENTS ======================================
 
@@ -364,9 +371,9 @@ module ActiveRecord
         end
       end
 
-      def recreate_database(name) #:nodoc:
+      def recreate_database(name, options = {}) #:nodoc:
         drop_database(name)
-        create_database(name)
+        create_database(name, options)
       end
 
       # Create a new MySQL database with optional &lt;tt&gt;:charset&lt;/tt&gt; and &lt;tt&gt;:collation&lt;/tt&gt;.
@@ -517,14 +524,33 @@ module ActiveRecord
         keys.length == 1 ? [keys.first, nil] : nil
       end
 
+      def case_sensitive_equality_operator
+        &quot;= BINARY&quot;
+      end
+
+      def limited_update_conditions(where_sql, quoted_table_name, quoted_primary_key)
+        where_sql
+      end
+
       private
         def connect
+          @connection.reconnect = true if @connection.respond_to?(:reconnect=)
+
           encoding = @config[:encoding]
           if encoding
             @connection.options(Mysql::SET_CHARSET_NAME, encoding) rescue nil
           end
-          @connection.ssl_set(@config[:sslkey], @config[:sslcert], @config[:sslca], @config[:sslcapath], @config[:sslcipher]) if @config[:sslkey]
+
+          if @config[:sslca] || @config[:sslkey]
+            @connection.ssl_set(@config[:sslkey], @config[:sslcert], @config[:sslca], @config[:sslcapath], @config[:sslcipher])
+          end
+
           @connection.real_connect(*@connection_options)
+          configure_connection
+        end
+
+        def configure_connection
+          encoding = @config[:encoding]
           execute(&quot;SET NAMES '#{encoding}'&quot;) if encoding
 
           # By default, MySQL 'where id is null' selects the last inserted id.</diff>
      <filename>vendor/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb</filename>
    </modified>
    <modified>
      <diff>@@ -68,72 +68,6 @@ module ActiveRecord
           super
         end
   
-        # Escapes binary strings for bytea input to the database.
-        def self.string_to_binary(value)
-          if PGconn.respond_to?(:escape_bytea)
-            self.class.module_eval do
-              define_method(:string_to_binary) do |value|
-                PGconn.escape_bytea(value) if value
-              end
-            end
-          else
-            self.class.module_eval do
-              define_method(:string_to_binary) do |value|
-                if value
-                  result = ''
-                  value.each_byte { |c| result &lt;&lt; sprintf('\\\\%03o', c) }
-                  result
-                end
-              end
-            end
-          end
-          self.class.string_to_binary(value)
-        end
-  
-        # Unescapes bytea output from a database to the binary string it represents.
-        def self.binary_to_string(value)
-          # In each case, check if the value actually is escaped PostgreSQL bytea output
-          # or an unescaped Active Record attribute that was just written.
-          if PGconn.respond_to?(:unescape_bytea)
-            self.class.module_eval do
-              define_method(:binary_to_string) do |value|
-                if value =~ /\\\d{3}/
-                  PGconn.unescape_bytea(value)
-                else
-                  value
-                end
-              end
-            end
-          else
-            self.class.module_eval do
-              define_method(:binary_to_string) do |value|
-                if value =~ /\\\d{3}/
-                  result = ''
-                  i, max = 0, value.size
-                  while i &lt; max
-                    char = value[i]
-                    if char == ?\\
-                      if value[i+1] == ?\\
-                        char = ?\\
-                        i += 1
-                      else
-                        char = value[i+1..i+3].oct
-                        i += 3
-                      end
-                    end
-                    result &lt;&lt; char
-                    i += 1
-                  end
-                  result
-                else
-                  value
-                end
-              end
-            end
-          end
-          self.class.binary_to_string(value)
-        end  
-  
         # Maps PostgreSQL-specific data types to logical Rails types.
         def simplified_type(field_type)
           case field_type
@@ -246,9 +180,26 @@ module ActiveRecord
     # * &lt;tt&gt;:min_messages&lt;/tt&gt; - An optional client min messages that is used in a &lt;tt&gt;SET client_min_messages TO &lt;min_messages&gt;&lt;/tt&gt; call on the connection.
     # * &lt;tt&gt;:allow_concurrency&lt;/tt&gt; - If true, use async query methods so Ruby threads don't deadlock; otherwise, use blocking query methods.
     class PostgreSQLAdapter &lt; AbstractAdapter
+      ADAPTER_NAME = 'PostgreSQL'.freeze
+
+      NATIVE_DATABASE_TYPES = {
+        :primary_key =&gt; &quot;serial primary key&quot;.freeze,
+        :string      =&gt; { :name =&gt; &quot;character varying&quot;, :limit =&gt; 255 },
+        :text        =&gt; { :name =&gt; &quot;text&quot; },
+        :integer     =&gt; { :name =&gt; &quot;integer&quot; },
+        :float       =&gt; { :name =&gt; &quot;float&quot; },
+        :decimal     =&gt; { :name =&gt; &quot;decimal&quot; },
+        :datetime    =&gt; { :name =&gt; &quot;timestamp&quot; },
+        :timestamp   =&gt; { :name =&gt; &quot;timestamp&quot; },
+        :time        =&gt; { :name =&gt; &quot;time&quot; },
+        :date        =&gt; { :name =&gt; &quot;date&quot; },
+        :binary      =&gt; { :name =&gt; &quot;bytea&quot; },
+        :boolean     =&gt; { :name =&gt; &quot;boolean&quot; }
+      }
+
       # Returns 'PostgreSQL' as adapter name for identification purposes.
       def adapter_name
-        'PostgreSQL'
+        ADAPTER_NAME
       end
 
       # Initializes and connects a PostgreSQL adapter.
@@ -290,20 +241,7 @@ module ActiveRecord
       end
 
       def native_database_types #:nodoc:
-        {
-          :primary_key =&gt; &quot;serial primary key&quot;,
-          :string      =&gt; { :name =&gt; &quot;character varying&quot;, :limit =&gt; 255 },
-          :text        =&gt; { :name =&gt; &quot;text&quot; },
-          :integer     =&gt; { :name =&gt; &quot;integer&quot; },
-          :float       =&gt; { :name =&gt; &quot;float&quot; },
-          :decimal     =&gt; { :name =&gt; &quot;decimal&quot; },
-          :datetime    =&gt; { :name =&gt; &quot;timestamp&quot; },
-          :timestamp   =&gt; { :name =&gt; &quot;timestamp&quot; },
-          :time        =&gt; { :name =&gt; &quot;time&quot; },
-          :date        =&gt; { :name =&gt; &quot;date&quot; },
-          :binary      =&gt; { :name =&gt; &quot;bytea&quot; },
-          :boolean     =&gt; { :name =&gt; &quot;boolean&quot; }
-        }
+        NATIVE_DATABASE_TYPES
       end
 
       # Does PostgreSQL support migrations?
@@ -331,6 +269,10 @@ module ActiveRecord
         postgresql_version &gt;= 80200
       end
 
+      def supports_ddl_transactions?
+        true
+      end
+
       # Returns the configured supported identifier length supported by PostgreSQL,
       # or report the default of 63 on PostgreSQL 7.x.
       def table_alias_length
@@ -339,10 +281,78 @@ module ActiveRecord
 
       # QUOTING ==================================================
 
+      # Escapes binary strings for bytea input to the database.
+      def escape_bytea(value)
+        if PGconn.respond_to?(:escape_bytea)
+          self.class.instance_eval do
+            define_method(:escape_bytea) do |value|
+              PGconn.escape_bytea(value) if value
+            end
+          end
+        else
+          self.class.instance_eval do
+            define_method(:escape_bytea) do |value|
+              if value
+                result = ''
+                value.each_byte { |c| result &lt;&lt; sprintf('\\\\%03o', c) }
+                result
+              end
+            end
+          end
+        end
+        escape_bytea(value)
+      end
+
+      # Unescapes bytea output from a database to the binary string it represents.
+      # NOTE: This is NOT an inverse of escape_bytea! This is only to be used
+      #       on escaped binary output from database drive.
+      def unescape_bytea(value)
+        # In each case, check if the value actually is escaped PostgreSQL bytea output
+        # or an unescaped Active Record attribute that was just written.
+        if PGconn.respond_to?(:unescape_bytea)
+          self.class.instance_eval do
+            define_method(:unescape_bytea) do |value|
+              if value =~ /\\\d{3}/
+                PGconn.unescape_bytea(value)
+              else
+                value
+              end
+            end
+          end
+        else
+          self.class.instance_eval do
+            define_method(:unescape_bytea) do |value|
+              if value =~ /\\\d{3}/
+                result = ''
+                i, max = 0, value.size
+                while i &lt; max
+                  char = value[i]
+                  if char == ?\\
+                    if value[i+1] == ?\\
+                      char = ?\\
+                      i += 1
+                    else
+                      char = value[i+1..i+3].oct
+                      i += 3
+                    end
+                  end
+                  result &lt;&lt; char
+                  i += 1
+                end
+                result
+              else
+                value
+              end
+            end
+          end
+        end
+        unescape_bytea(value)
+      end
+
       # Quotes PostgreSQL-specific data types for SQL input.
       def quote(value, column = nil) #:nodoc:
         if value.kind_of?(String) &amp;&amp; column &amp;&amp; column.type == :binary
-          &quot;#{quoted_string_prefix}'#{column.class.string_to_binary(value)}'&quot;
+          &quot;#{quoted_string_prefix}'#{escape_bytea(value)}'&quot;
         elsif value.kind_of?(String) &amp;&amp; column &amp;&amp; column.sql_type =~ /^xml$/
           &quot;xml '#{quote_string(value)}'&quot;
         elsif value.kind_of?(Numeric) &amp;&amp; column &amp;&amp; column.sql_type =~ /^money$/
@@ -455,11 +465,20 @@ module ActiveRecord
 
       # create a 2D array representing the result set
       def result_as_array(res) #:nodoc:
+        # check if we have any binary column and if they need escaping
+        unescape_col = []
+        for j in 0...res.nfields do
+          # unescape string passed BYTEA field (OID == 17)
+          unescape_col &lt;&lt; ( res.ftype(j)==17 )
+        end
+
         ary = []
         for i in 0...res.ntuples do
           ary &lt;&lt; []
           for j in 0...res.nfields do
-            ary[i] &lt;&lt; res.getvalue(i,j)
+            data = res.getvalue(i,j)
+            data = unescape_bytea(data) if unescape_col[j] and data.is_a?(String)
+            ary[i] &lt;&lt; data
           end
         end
         return ary
@@ -510,6 +529,45 @@ module ActiveRecord
         execute &quot;ROLLBACK&quot;
       end
 
+      # ruby-pg defines Ruby constants for transaction status,
+      # ruby-postgres does not.
+      PQTRANS_IDLE = defined?(PGconn::PQTRANS_IDLE) ? PGconn::PQTRANS_IDLE : 0
+
+      # Check whether a transaction is active.
+      def transaction_active?
+        @connection.transaction_status != PQTRANS_IDLE
+      end
+
+      # Wrap a block in a transaction.  Returns result of block.
+      def transaction(start_db_transaction = true)
+        transaction_open = false
+        begin
+          if block_given?
+            if start_db_transaction
+              begin_db_transaction
+              transaction_open = true
+            end
+            yield
+          end
+        rescue Exception =&gt; database_transaction_rollback
+          if transaction_open &amp;&amp; transaction_active?
+            transaction_open = false
+            rollback_db_transaction
+          end
+          raise unless database_transaction_rollback.is_a? ActiveRecord::Rollback
+        end
+      ensure
+        if transaction_open &amp;&amp; transaction_active?
+          begin
+            commit_db_transaction
+          rescue Exception =&gt; database_transaction_rollback
+            rollback_db_transaction
+            raise
+          end
+        end
+      end
+
+
       # SCHEMA STATEMENTS ========================================
 
       def recreate_database(name) #:nodoc:
@@ -618,6 +676,19 @@ module ActiveRecord
         end
       end
 
+      # Returns the current database name.
+      def current_database
+        query('select current_database()')[0][0]
+      end
+
+      # Returns the current database encoding format.
+      def encoding
+        query(&lt;&lt;-end_sql)[0][0]
+          SELECT pg_encoding_to_char(pg_database.encoding) FROM pg_database
+          WHERE pg_database.datname LIKE '#{current_database}'
+        end_sql
+      end
+
       # Sets the schema search path to a string of comma-separated schema names.
       # Names beginning with $ have to be quoted (e.g. $user =&gt; '$user').
       # See: http://www.postgresql.org/docs/current/static/ddl-schemas.html
@@ -851,7 +922,7 @@ module ActiveRecord
         end
 
       private
-        # The internal PostgreSQL identifer of the money data type.
+        # The internal PostgreSQL identifier of the money data type.
         MONEY_COLUMN_TYPE_OID = 790 #:nodoc:
 
         # Connects to a PostgreSQL server and sets up the adapter depending on the</diff>
      <filename>vendor/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb</filename>
    </modified>
    <modified>
      <diff>@@ -34,8 +34,10 @@ module ActiveRecord
   #   person.name &lt;&lt; 'by'
   #   person.name_change    # =&gt; ['uncle bob', 'uncle bobby']
   module Dirty
+    DIRTY_SUFFIXES = ['_changed?', '_change', '_will_change!', '_was']
+
     def self.included(base)
-      base.attribute_method_suffix '_changed?', '_change', '_will_change!', '_was'
+      base.attribute_method_suffix *DIRTY_SUFFIXES
       base.alias_method_chain :write_attribute, :dirty
       base.alias_method_chain :save,            :dirty
       base.alias_method_chain :save!,           :dirty
@@ -44,6 +46,8 @@ module ActiveRecord
 
       base.superclass_delegating_accessor :partial_updates
       base.partial_updates = true
+
+      base.send(:extend, ClassMethods)
     end
 
     # Do any attributes have unsaved changes?
@@ -62,7 +66,7 @@ module ActiveRecord
       changed_attributes.keys
     end
 
-    # Map of changed attrs =&gt; [original value, new value]
+    # Map of changed attrs =&gt; [original value, new value].
     #   person.changes # =&gt; {}
     #   person.name = 'bob'
     #   person.changes # =&gt; { 'name' =&gt; ['bill', 'bob'] }
@@ -93,27 +97,27 @@ module ActiveRecord
     end
 
     private
-      # Map of change attr =&gt; original value.
+      # Map of change &lt;tt&gt;attr =&gt; original value&lt;/tt&gt;.
       def changed_attributes
         @changed_attributes ||= {}
       end
 
-      # Handle *_changed? for method_missing.
+      # Handle &lt;tt&gt;*_changed?&lt;/tt&gt; for +method_missing+.
       def attribute_changed?(attr)
         changed_attributes.include?(attr)
       end
 
-      # Handle *_change for method_missing.
+      # Handle &lt;tt&gt;*_change&lt;/tt&gt; for +method_missing+.
       def attribute_change(attr)
         [changed_attributes[attr], __send__(attr)] if attribute_changed?(attr)
       end
 
-      # Handle *_was for method_missing.
+      # Handle &lt;tt&gt;*_was&lt;/tt&gt; for +method_missing+.
       def attribute_was(attr)
         attribute_changed?(attr) ? changed_attributes[attr] : __send__(attr)
       end
 
-      # Handle *_will_change! for method_missing.
+      # Handle &lt;tt&gt;*_will_change!&lt;/tt&gt; for +method_missing+.
       def attribute_will_change!(attr)
         changed_attributes[attr] = clone_attribute_value(:read_attribute, attr)
       end
@@ -161,5 +165,19 @@ module ActiveRecord
         old != value
       end
 
+    module ClassMethods
+      def self.extended(base)
+        base.metaclass.alias_method_chain(:alias_attribute, :dirty)
+      end
+
+      def alias_attribute_with_dirty(new_name, old_name)
+        alias_attribute_without_dirty(new_name, old_name)
+        DIRTY_SUFFIXES.each do |suffix|
+          module_eval &lt;&lt;-STR, __FILE__, __LINE__+1
+            def #{new_name}#{suffix}; self.#{old_name}#{suffix}; end
+          STR
+        end
+      end
+    end
   end
 end</diff>
      <filename>vendor/activerecord/lib/active_record/dirty.rb</filename>
    </modified>
    <modified>
      <diff>@@ -515,7 +515,7 @@ class Fixtures &lt; (RUBY_VERSION &lt; '1.9' ? YAML::Omap : Hash)
 
           all_loaded_fixtures.update(fixtures_map)
 
-          connection.transaction(Thread.current['open_transactions'].to_i == 0) do
+          connection.transaction(connection.open_transactions.zero?) do
             fixtures.reverse.each { |fixture| fixture.delete_existing_fixtures }
             fixtures.each { |fixture| fixture.insert_fixtures }
 
@@ -541,13 +541,14 @@ class Fixtures &lt; (RUBY_VERSION &lt; '1.9' ? YAML::Omap : Hash)
     label.to_s.hash.abs
   end
 
-  attr_reader :table_name
+  attr_reader :table_name, :name
 
   def initialize(connection, table_name, class_name, fixture_path, file_filter = DEFAULT_FILTER_RE)
     @connection, @table_name, @fixture_path, @file_filter = connection, table_name, fixture_path, file_filter
+    @name = table_name # preserve fixture base name
     @class_name = class_name ||
                   (ActiveRecord::Base.pluralize_table_names ? @table_name.singularize.camelize : @table_name.camelize)
-    @table_name = ActiveRecord::Base.table_name_prefix + @table_name + ActiveRecord::Base.table_name_suffix
+    @table_name = &quot;#{ActiveRecord::Base.table_name_prefix}#{@table_name}#{ActiveRecord::Base.table_name_suffix}&quot;
     @table_name = class_name.table_name if class_name.respond_to?(:table_name)
     @connection = class_name.connection if class_name.respond_to?(:connection)
     read_fixture_files
@@ -929,7 +930,7 @@ module Test #:nodoc:
             load_fixtures
             @@already_loaded_fixtures[self.class] = @loaded_fixtures
           end
-          ActiveRecord::Base.send :increment_open_transactions
+          ActiveRecord::Base.connection.increment_open_transactions
           ActiveRecord::Base.connection.begin_db_transaction
         # Load fixtures for every test.
         else
@@ -950,11 +951,11 @@ module Test #:nodoc:
         end
 
         # Rollback changes if a transaction is active.
-        if use_transactional_fixtures? &amp;&amp; Thread.current['open_transactions'] != 0
+        if use_transactional_fixtures? &amp;&amp; ActiveRecord::Base.connection.open_transactions != 0
           ActiveRecord::Base.connection.rollback_db_transaction
-          Thread.current['open_transactions'] = 0
+          ActiveRecord::Base.connection.decrement_open_transactions
         end
-        ActiveRecord::Base.verify_active_connections!
+        ActiveRecord::Base.clear_active_connections!
       end
 
       private
@@ -963,9 +964,9 @@ module Test #:nodoc:
           fixtures = Fixtures.create_fixtures(fixture_path, fixture_table_names, fixture_class_names)
           unless fixtures.nil?
             if fixtures.instance_of?(Fixtures)
-              @loaded_fixtures[fixtures.table_name] = fixtures
+              @loaded_fixtures[fixtures.name] = fixtures
             else
-              fixtures.each { |f| @loaded_fixtures[f.table_name] = f }
+              fixtures.each { |f| @loaded_fixtures[f.name] = f }
             end
           end
         end</diff>
      <filename>vendor/activerecord/lib/active_record/fixtures.rb</filename>
    </modified>
    <modified>
      <diff>@@ -349,6 +349,27 @@ module ActiveRecord
     end
   end
 
+  # MigrationProxy is used to defer loading of the actual migration classes
+  # until they are needed
+  class MigrationProxy
+
+    attr_accessor :name, :version, :filename
+
+    delegate :migrate, :announce, :write, :to=&gt;:migration
+
+    private
+
+      def migration
+        @migration ||= load_migration
+      end
+
+      def load_migration
+        load(filename)
+        name.constantize
+      end
+
+  end
+
   class Migrator#:nodoc:
     class &lt;&lt; self
       def migrate(migrations_path, target_version = nil)
@@ -443,17 +464,25 @@ module ActiveRecord
       runnable.pop if down? &amp;&amp; !target.nil?
       
       runnable.each do |migration|
-        Base.logger.info &quot;Migrating to #{migration} (#{migration.version})&quot;
+        Base.logger.info &quot;Migrating to #{migration.name} (#{migration.version})&quot;
 
         # On our way up, we skip migrating the ones we've already migrated
-        # On our way down, we skip reverting the ones we've never migrated
         next if up? &amp;&amp; migrated.include?(migration.version.to_i)
 
+        # On our way down, we skip reverting the ones we've never migrated
         if down? &amp;&amp; !migrated.include?(migration.version.to_i)
           migration.announce 'never migrated, skipping'; migration.write
-        else
-          migration.migrate(@direction)
-          record_version_state_after_migrating(migration.version)
+          next
+        end
+
+        begin
+          ddl_transaction do
+            migration.migrate(@direction)
+            record_version_state_after_migrating(migration.version)
+          end
+        rescue =&gt; e
+          canceled_msg = Base.connection.supports_ddl_transactions? ? &quot;this and &quot; : &quot;&quot;
+          raise StandardError, &quot;An error has occurred, #{canceled_msg}all later migrations canceled:\n\n#{e}&quot;, e.backtrace
         end
       end
     end
@@ -476,11 +505,10 @@ module ActiveRecord
             raise DuplicateMigrationNameError.new(name.camelize) 
           end
           
-          load(file)
-          
-          klasses &lt;&lt; returning(name.camelize.constantize) do |klass|
-            class &lt;&lt; klass; attr_accessor :version end
-            klass.version = version
+          klasses &lt;&lt; returning(MigrationProxy.new) do |migration|
+            migration.name     = name.camelize
+            migration.version  = version
+            migration.filename = file
           end
         end
         
@@ -519,5 +547,14 @@ module ActiveRecord
       def down?
         @direction == :down
       end
+
+      # Wrap the migration in a transaction only if supported by the adapter.
+      def ddl_transaction(&amp;block)
+        if Base.connection.supports_ddl_transactions?
+          Base.transaction { block.call }
+        else
+          block.call
+        end
+      end
   end
 end</diff>
      <filename>vendor/activerecord/lib/active_record/migration.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,10 +1,10 @@
 module ActiveRecord
   module NamedScope
-    # All subclasses of ActiveRecord::Base have two named_scopes:
-    # * &lt;tt&gt;all&lt;/tt&gt;, which is similar to a &lt;tt&gt;find(:all)&lt;/tt&gt; query, and
-    # * &lt;tt&gt;scoped&lt;/tt&gt;, which allows for the creation of anonymous scopes, on the fly: &lt;tt&gt;Shirt.scoped(:conditions =&gt; {:color =&gt; 'red'}).scoped(:include =&gt; :washing_instructions)&lt;/tt&gt;
+    # All subclasses of ActiveRecord::Base have two named \scopes:
+    # * &lt;tt&gt;all&lt;/tt&gt; - which is similar to a &lt;tt&gt;find(:all)&lt;/tt&gt; query, and
+    # * &lt;tt&gt;scoped&lt;/tt&gt; - which allows for the creation of anonymous \scopes, on the fly: &lt;tt&gt;Shirt.scoped(:conditions =&gt; {:color =&gt; 'red'}).scoped(:include =&gt; :washing_instructions)&lt;/tt&gt;
     #
-    # These anonymous scopes tend to be useful when procedurally generating complex queries, where passing
+    # These anonymous \scopes tend to be useful when procedurally generating complex queries, where passing
     # intermediate values (scopes) around as first-class objects is convenient.
     def self.included(base)
       base.class_eval do
@@ -26,20 +26,20 @@ module ActiveRecord
       #     named_scope :dry_clean_only, :joins =&gt; :washing_instructions, :conditions =&gt; ['washing_instructions.dry_clean_only = ?', true]
       #   end
       # 
-      # The above calls to &lt;tt&gt;named_scope&lt;/tt&gt; define class methods &lt;tt&gt;Shirt.red&lt;/tt&gt; and &lt;tt&gt;Shirt.dry_clean_only&lt;/tt&gt;. &lt;tt&gt;Shirt.red&lt;/tt&gt;, 
+      # The above calls to &lt;tt&gt;named_scope&lt;/tt&gt; define class methods Shirt.red and Shirt.dry_clean_only. Shirt.red, 
       # in effect, represents the query &lt;tt&gt;Shirt.find(:all, :conditions =&gt; {:color =&gt; 'red'})&lt;/tt&gt;.
       #
-      # Unlike Shirt.find(...), however, the object returned by &lt;tt&gt;Shirt.red&lt;/tt&gt; is not an Array; it resembles the association object
+      # Unlike &lt;tt&gt;Shirt.find(...)&lt;/tt&gt;, however, the object returned by Shirt.red is not an Array; it resembles the association object
       # constructed by a &lt;tt&gt;has_many&lt;/tt&gt; declaration. For instance, you can invoke &lt;tt&gt;Shirt.red.find(:first)&lt;/tt&gt;, &lt;tt&gt;Shirt.red.count&lt;/tt&gt;,
       # &lt;tt&gt;Shirt.red.find(:all, :conditions =&gt; {:size =&gt; 'small'})&lt;/tt&gt;. Also, just
-      # as with the association objects, name scopes acts like an Array, implementing Enumerable; &lt;tt&gt;Shirt.red.each(&amp;block)&lt;/tt&gt;,
-      # &lt;tt&gt;Shirt.red.first&lt;/tt&gt;, and &lt;tt&gt;Shirt.red.inject(memo, &amp;block)&lt;/tt&gt; all behave as if Shirt.red really were an Array.
+      # as with the association objects, named \scopes act like an Array, implementing Enumerable; &lt;tt&gt;Shirt.red.each(&amp;block)&lt;/tt&gt;,
+      # &lt;tt&gt;Shirt.red.first&lt;/tt&gt;, and &lt;tt&gt;Shirt.red.inject(memo, &amp;block)&lt;/tt&gt; all behave as if Shirt.red really was an Array.
       #
-      # These named scopes are composable. For instance, &lt;tt&gt;Shirt.red.dry_clean_only&lt;/tt&gt; will produce all shirts that are both red and dry clean only.
+      # These named \scopes are composable. For instance, &lt;tt&gt;Shirt.red.dry_clean_only&lt;/tt&gt; will produce all shirts that are both red and dry clean only.
       # Nested finds and calculations also work with these compositions: &lt;tt&gt;Shirt.red.dry_clean_only.count&lt;/tt&gt; returns the number of garments
       # for which these criteria obtain. Similarly with &lt;tt&gt;Shirt.red.dry_clean_only.average(:thread_count)&lt;/tt&gt;.
       #
-      # All scopes are available as class methods on the ActiveRecord::Base descendent upon which the scopes were defined. But they are also available to
+      # All \scopes are available as class methods on the ActiveRecord::Base descendent upon which the \scopes were defined. But they are also available to
       # &lt;tt&gt;has_many&lt;/tt&gt; associations. If,
       #
       #   class Person &lt; ActiveRecord::Base
@@ -49,7 +49,7 @@ module ActiveRecord
       # then &lt;tt&gt;elton.shirts.red.dry_clean_only&lt;/tt&gt; will return all of Elton's red, dry clean
       # only shirts.
       #
-      # Named scopes can also be procedural.
+      # Named \scopes can also be procedural:
       #
       #   class Shirt &lt; ActiveRecord::Base
       #     named_scope :colored, lambda { |color|
@@ -59,7 +59,7 @@ module ActiveRecord
       #
       # In this example, &lt;tt&gt;Shirt.colored('puce')&lt;/tt&gt; finds all puce shirts.
       #
-      # Named scopes can also have extensions, just as with &lt;tt&gt;has_many&lt;/tt&gt; declarations:
+      # Named \scopes can also have extensions, just as with &lt;tt&gt;has_many&lt;/tt&gt; declarations:
       #
       #   class Shirt &lt; ActiveRecord::Base
       #     named_scope :red, :conditions =&gt; {:color =&gt; 'red'} do
@@ -70,7 +70,7 @@ module ActiveRecord
       #   end
       #
       #
-      # For testing complex named scopes, you can examine the scoping options using the
+      # For testing complex named \scopes, you can examine the scoping options using the
       # &lt;tt&gt;proxy_options&lt;/tt&gt; method on the proxy itself.
       #
       #   class Shirt &lt; ActiveRecord::Base
@@ -101,9 +101,9 @@ module ActiveRecord
     
     class Scope
       attr_reader :proxy_scope, :proxy_options
-
+      NON_DELEGATE_METHODS = %w(nil? send object_id class extend find size count sum average maximum minimum paginate first last empty? any? respond_to?).to_set
       [].methods.each do |m|
-        unless m =~ /(^__|^nil\?|^send|^object_id$|class|extend|^find$|count|sum|average|maximum|minimum|paginate|first|last|empty\?|respond_to\?)/
+        unless m =~ /^__/ || NON_DELEGATE_METHODS.include?(m.to_s)
           delegate m, :to =&gt; :proxy_found
         end
       end
@@ -136,6 +136,10 @@ module ActiveRecord
         end
       end
 
+      def size
+        @found ? @found.length : count
+      end
+
       def empty?
         @found ? @found.empty? : count.zero?
       end
@@ -144,6 +148,14 @@ module ActiveRecord
         super || @proxy_scope.respond_to?(method, include_private)
       end
 
+      def any?
+        if block_given?
+          proxy_found.any? { |*block_args| yield(*block_args) }
+        else
+          !empty?
+        end
+      end
+
       protected
       def proxy_found
         @found || load_found
@@ -154,7 +166,8 @@ module ActiveRecord
         if scopes.include?(method)
           scopes[method].call(self, *args)
         else
-          with_scope :find =&gt; proxy_options do
+          with_scope :find =&gt; proxy_options, :create =&gt; proxy_options[:conditions].is_a?(Hash) ?  proxy_options[:conditions] : {} do
+            method = :new if method == :build
             proxy_scope.send(method, *args, &amp;block)
           end
         end</diff>
      <filename>vendor/activerecord/lib/active_record/named_scope.rb</filename>
    </modified>
    <modified>
      <diff>@@ -13,14 +13,15 @@ module ActiveRecord
       def create_reflection(macro, name, options, active_record)
         case macro
           when :has_many, :belongs_to, :has_one, :has_and_belongs_to_many
-            reflection = AssociationReflection.new(macro, name, options, active_record)
+            klass = options[:through] ? ThroughReflection : AssociationReflection
+            reflection = klass.new(macro, name, options, active_record)
           when :composed_of
             reflection = AggregateReflection.new(macro, name, options, active_record)
         end
         write_inheritable_hash :reflections, name =&gt; reflection
         reflection
       end
-      
+
       # Returns a hash containing all AssociationReflection objects for the current class
       # Example:
       #
@@ -30,7 +31,7 @@ module ActiveRecord
       def reflections
         read_inheritable_attribute(:reflections) || write_inheritable_attribute(:reflections, {})
       end
-       
+
       # Returns an array of AggregateReflection objects for all the aggregations in the class.
       def reflect_on_all_aggregations
         reflections.values.select { |reflection| reflection.is_a?(AggregateReflection) }
@@ -109,7 +110,16 @@ module ActiveRecord
       # Returns +true+ if +self+ and +other_aggregation+ have the same +name+ attribute, +active_record+ attribute,
       # and +other_aggregation+ has an options hash assigned to it.
       def ==(other_aggregation)
-        name == other_aggregation.name &amp;&amp; other_aggregation.options &amp;&amp; active_record == other_aggregation.active_record
+        other_aggregation.kind_of?(self.class) &amp;&amp; name == other_aggregation.name &amp;&amp; other_aggregation.options &amp;&amp; active_record == other_aggregation.active_record
+      end
+
+      def sanitized_conditions #:nodoc:
+        @sanitized_conditions ||= klass.send(:sanitize_sql, options[:conditions]) if options[:conditions]
+      end
+
+      # Returns +true+ if +self+ is a +belongs_to+ reflection.
+      def belongs_to?
+        macro == :belongs_to
       end
 
       private
@@ -125,10 +135,45 @@ module ActiveRecord
 
     # Holds all the meta-data about an association as it was specified in the Active Record class.
     class AssociationReflection &lt; MacroReflection #:nodoc:
+      # Returns the target association's class:
+      #
+      #   class Author &lt; ActiveRecord::Base
+      #     has_many :books
+      #   end
+      #
+      #   Author.reflect_on_association(:books).klass
+      #   # =&gt; Book
+      #
+      # &lt;b&gt;Note:&lt;/b&gt; do not call +klass.new+ or +klass.create+ to instantiate
+      # a new association object. Use +build_association+ or +create_association+
+      # instead. This allows plugins to hook into association object creation.
       def klass
         @klass ||= active_record.send(:compute_type, class_name)
       end
 
+      # Returns a new, unsaved instance of the associated class. +options+ will
+      # be passed to the class's constructor.
+      def build_association(*options)
+        klass.new(*options)
+      end
+
+      # Creates a new instance of the associated class, and immediates saves it
+      # with ActiveRecord::Base#save. +options+ will be passed to the class's
+      # creation method. Returns the newly created object.
+      def create_association(*options)
+        klass.create(*options)
+      end
+
+      # Creates a new instance of the associated class, and immediates saves it
+      # with ActiveRecord::Base#save!. +options+ will be passed to the class's
+      # creation method. If the created record doesn't pass validations, then an
+      # exception will be raised.
+      #
+      # Returns the newly created object.
+      def create_association!(*options)
+        klass.create!(*options)
+      end
+
       def table_name
         @table_name ||= klass.table_name
       end
@@ -153,6 +198,52 @@ module ActiveRecord
         end
       end
 
+      def check_validity!
+      end
+
+      def through_reflection
+        false
+      end
+
+      def through_reflection_primary_key_name
+      end
+
+      def source_reflection
+        nil
+      end
+
+      private
+        def derive_class_name
+          class_name = name.to_s.camelize
+          class_name = class_name.singularize if [ :has_many, :has_and_belongs_to_many ].include?(macro)
+          class_name
+        end
+
+        def derive_primary_key_name
+          if belongs_to?
+            &quot;#{name}_id&quot;
+          elsif options[:as]
+            &quot;#{options[:as]}_id&quot;
+          else
+            active_record.name.foreign_key
+          end
+        end
+    end
+
+    # Holds all the meta-data about a :through association as it was specified in the Active Record class.
+    class ThroughReflection &lt; AssociationReflection #:nodoc:
+      # Gets the source of the through reflection.  It checks both a singularized and pluralized form for &lt;tt&gt;:belongs_to&lt;/tt&gt; or &lt;tt&gt;:has_many&lt;/tt&gt;.
+      # (The &lt;tt&gt;:tags&lt;/tt&gt; association on Tagging below.)
+      #
+      #   class Post &lt; ActiveRecord::Base
+      #     has_many :taggings
+      #     has_many :tags, :through =&gt; :taggings
+      #   end
+      #
+      def source_reflection
+        @source_reflection ||= source_reflection_names.collect { |name| through_reflection.klass.reflect_on_association(name) }.compact.first
+      end
+
       # Returns the AssociationReflection object specified in the &lt;tt&gt;:through&lt;/tt&gt; option
       # of a HasManyThrough or HasOneThrough association. Example:
       #
@@ -165,7 +256,7 @@ module ActiveRecord
       #   taggings_reflection = tags_reflection.through_reflection
       #
       def through_reflection
-        @through_reflection ||= options[:through] ? active_record.reflect_on_association(options[:through]) : false
+        @through_reflection ||= active_record.reflect_on_association(options[:through])
       end
 
       # Gets an array of possible &lt;tt&gt;:through&lt;/tt&gt; source reflection names:
@@ -176,63 +267,40 @@ module ActiveRecord
         @source_reflection_names ||= (options[:source] ? [options[:source]] : [name.to_s.singularize, name]).collect { |n| n.to_sym }
       end
 
-      # Gets the source of the through reflection.  It checks both a singularized and pluralized form for &lt;tt&gt;:belongs_to&lt;/tt&gt; or &lt;tt&gt;:has_many&lt;/tt&gt;.
-      # (The &lt;tt&gt;:tags&lt;/tt&gt; association on Tagging below.)
-      # 
-      #   class Post &lt; ActiveRecord::Base
-      #     has_many :taggings
-      #     has_many :tags, :through =&gt; :taggings
-      #   end
-      #
-      def source_reflection
-        return nil unless through_reflection
-        @source_reflection ||= source_reflection_names.collect { |name| through_reflection.klass.reflect_on_association(name) }.compact.first
-      end
-
       def check_validity!
-        if options[:through]
-          if through_reflection.nil?
-            raise HasManyThroughAssociationNotFoundError.new(active_record.name, self)
-          end
-          
-          if source_reflection.nil?
-            raise HasManyThroughSourceAssociationNotFoundError.new(self)
-          end
+        if through_reflection.nil?
+          raise HasManyThroughAssociationNotFoundError.new(active_record.name, self)
+        end
 
-          if options[:source_type] &amp;&amp; source_reflection.options[:polymorphic].nil?
-            raise HasManyThroughAssociationPointlessSourceTypeError.new(active_record.name, self, source_reflection)
-          end
-          
-          if source_reflection.options[:polymorphic] &amp;&amp; options[:source_type].nil?
-            raise HasManyThroughAssociationPolymorphicError.new(active_record.name, self, source_reflection)
-          end
-          
-          unless [:belongs_to, :has_many].include?(source_reflection.macro) &amp;&amp; source_reflection.options[:through].nil?
-            raise HasManyThroughSourceAssociationMacroError.new(self)
-          end
+        if source_reflection.nil?
+          raise HasManyThroughSourceAssociationNotFoundError.new(self)
+        end
+
+        if options[:source_type] &amp;&amp; source_reflection.options[:polymorphic].nil?
+          raise HasManyThroughAssociationPointlessSourceTypeError.new(active_record.name, self, source_reflection)
+        end
+
+        if source_reflection.options[:polymorphic] &amp;&amp; options[:source_type].nil?
+          raise HasManyThroughAssociationPolymorphicError.new(active_record.name, self, source_reflection)
         end
+
+        unless [:belongs_to, :has_many].include?(source_reflection.macro) &amp;&amp; source_reflection.options[:through].nil?
+          raise HasManyThroughSourceAssociationMacroError.new(self)
+        end
+      end
+
+      def through_reflection_primary_key
+        through_reflection.belongs_to? ? through_reflection.klass.primary_key : through_reflection.primary_key_name
+      end
+
+      def through_reflection_primary_key_name
+        through_reflection.primary_key_name if through_reflection.belongs_to?
       end
 
       private
         def derive_class_name
           # get the class_name of the belongs_to association of the through reflection
-          if through_reflection
-            options[:source_type] || source_reflection.class_name
-          else
-            class_name = name.to_s.camelize
-            class_name = class_name.singularize if [ :has_many, :has_and_belongs_to_many ].include?(macro)
-            class_name
-          end
-        end
-
-        def derive_primary_key_name
-          if macro == :belongs_to
-            &quot;#{name}_id&quot;
-          elsif options[:as]
-            &quot;#{options[:as]}_id&quot;
-          else
-            active_record.name.foreign_key
-          end
+          options[:source_type] || source_reflection.class_name
         end
     end
   end</diff>
      <filename>vendor/activerecord/lib/active_record/reflection.rb</filename>
    </modified>
    <modified>
      <diff>@@ -102,7 +102,7 @@ HEADER
             spec[:precision] = column.precision.inspect if !column.precision.nil?
             spec[:scale]     = column.scale.inspect if !column.scale.nil?
             spec[:null]      = 'false' if !column.null
-            spec[:default]   = default_string(column.default) if !column.default.nil?
+            spec[:default]   = default_string(column.default) if column.has_default?
             (spec.keys - [:name, :type]).each{ |k| spec[k].insert(0, &quot;#{k.inspect} =&gt; &quot;)}
             spec
           end.compact
@@ -159,13 +159,19 @@ HEADER
       end
       
       def indexes(table, stream)
-        indexes = @connection.indexes(table)
-        indexes.each do |index|
-          stream.print &quot;  add_index #{index.table.inspect}, #{index.columns.inspect}, :name =&gt; #{index.name.inspect}&quot;
-          stream.print &quot;, :unique =&gt; true&quot; if index.unique
+        if (indexes = @connection.indexes(table)).any?
+          add_index_statements = indexes.map do |index|
+            statment_parts = [ ('add_index ' + index.table.inspect) ]
+            statment_parts &lt;&lt; index.columns.inspect
+            statment_parts &lt;&lt; (':name =&gt; ' + index.name.inspect)
+            statment_parts &lt;&lt; ':unique =&gt; true' if index.unique
+
+            '  ' + statment_parts.join(', ')
+          end
+
+          stream.puts add_index_statements.sort.join(&quot;\n&quot;)
           stream.puts
         end
-        stream.puts unless indexes.empty?
       end
   end
-end
+end
\ No newline at end of file</diff>
      <filename>vendor/activerecord/lib/active_record/schema_dumper.rb</filename>
    </modified>
    <modified>
      <diff>@@ -11,11 +11,9 @@ module ActiveRecord
     end
 
     def assert_date_from_db(expected, actual, message = nil)
-      # SQL Server doesn't have a separate column type just for dates,
+      # SybaseAdapter doesn't have a separate column type just for dates,
       # so the time is in the string and incorrectly formatted
-      if current_adapter?(:SQLServerAdapter)
-        assert_equal expected.strftime(&quot;%Y/%m/%d 00:00:00&quot;), actual.strftime(&quot;%Y/%m/%d 00:00:00&quot;)
-      elsif current_adapter?(:SybaseAdapter)
+      if current_adapter?(:SybaseAdapter)
         assert_equal expected.to_s, actual.to_date.to_s, message
       else
         assert_equal expected.to_s, actual.to_s, message
@@ -37,11 +35,26 @@ module ActiveRecord
       $queries_executed = []
       yield
     ensure
-      assert_equal num, $queries_executed.size, &quot;#{$queries_executed.size} instead of #{num} queries were executed.&quot;
+      assert_equal num, $queries_executed.size, &quot;#{$queries_executed.size} instead of #{num} queries were executed.#{$queries_executed.size == 0 ? '' : &quot;\nQueries:\n#{$queries_executed.join(&quot;\n&quot;)}&quot;}&quot;
     end
 
     def assert_no_queries(&amp;block)
       assert_queries(0, &amp;block)
     end
+
+    def self.use_concurrent_connections
+      setup :connection_allow_concurrency_setup
+      teardown :connection_allow_concurrency_teardown
+    end
+
+    def connection_allow_concurrency_setup
+      @connection = ActiveRecord::Base.remove_connection
+      ActiveRecord::Base.establish_connection(@connection.merge({:allow_concurrency =&gt; true}))
+    end
+
+    def connection_allow_concurrency_teardown
+      ActiveRecord::Base.clear_all_connections!
+      ActiveRecord::Base.establish_connection(@connection)
+    end
   end
 end</diff>
      <filename>vendor/activerecord/lib/active_record/test_case.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,7 +1,8 @@
 require 'thread'
 
 module ActiveRecord
-  module Transactions # :nodoc:
+  # See ActiveRecord::Transactions::ClassMethods for documentation.
+  module Transactions
     class TransactionError &lt; ActiveRecordError # :nodoc:
     end
 
@@ -15,26 +16,33 @@ module ActiveRecord
       end
     end
 
-    # Transactions are protective blocks where SQL statements are only permanent if they can all succeed as one atomic action.
-    # The classic example is a transfer between two accounts where you can only have a deposit if the withdrawal succeeded and
-    # vice versa. Transactions enforce the integrity of the database and guard the data against program errors or database break-downs.
-    # So basically you should use transaction blocks whenever you have a number of statements that must be executed together or
-    # not at all. Example:
+    # Transactions are protective blocks where SQL statements are only permanent
+    # if they can all succeed as one atomic action. The classic example is a
+    # transfer between two accounts where you can only have a deposit if the
+    # withdrawal succeeded and vice versa. Transactions enforce the integrity of
+    # the database and guard the data against program errors or database
+    # break-downs. So basically you should use transaction blocks whenever you
+    # have a number of statements that must be executed together or not at all.
+    # Example:
     #
-    #   transaction do
+    #   ActiveRecord::Base.transaction do
     #     david.withdrawal(100)
     #     mary.deposit(100)
     #   end
     #
-    # This example will only take money from David and give to Mary if neither +withdrawal+ nor +deposit+ raises an exception.
-    # Exceptions will force a ROLLBACK that returns the database to the state before the transaction was begun. Be aware, though,
-    # that the objects will _not_ have their instance data returned to their pre-transactional state.
+    # This example will only take money from David and give to Mary if neither
+    # +withdrawal+ nor +deposit+ raises an exception. Exceptions will force a
+    # ROLLBACK that returns the database to the state before the transaction was
+    # begun. Be aware, though, that the objects will _not_ have their instance
+    # data returned to their pre-transactional state.
     #
     # == Different Active Record classes in a single transaction
     #
     # Though the transaction class method is called on some Active Record class,
     # the objects within the transaction block need not all be instances of
-    # that class.
+    # that class. This is because transactions are per-database connection, not
+    # per-model.
+    #
     # In this example a &lt;tt&gt;Balance&lt;/tt&gt; record is transactionally saved even
     # though &lt;tt&gt;transaction&lt;/tt&gt; is called on the &lt;tt&gt;Account&lt;/tt&gt; class:
     #
@@ -43,6 +51,14 @@ module ActiveRecord
     #     account.save!
     #   end
     #
+    # Note that the +transaction+ method is also available as a model instance
+    # method. For example, you can also do this:
+    #
+    #   balance.transaction do
+    #     balance.save!
+    #     account.save!
+    #   end
+    #
     # == Transactions are not distributed across database connections
     #
     # A transaction acts on a single database connection.  If you have
@@ -62,48 +78,72 @@ module ActiveRecord
     #
     # == Save and destroy are automatically wrapped in a transaction
     #
-    # Both Base#save and Base#destroy come wrapped in a transaction that ensures that whatever you do in validations or callbacks
-    # will happen under the protected cover of a transaction. So you can use validations to check for values that the transaction
-    # depends on or you can raise exceptions in the callbacks to rollback.
+    # Both Base#save and Base#destroy come wrapped in a transaction that ensures
+    # that whatever you do in validations or callbacks will happen under the
+    # protected cover of a transaction. So you can use validations to check for
+    # values that the transaction depends on or you can raise exceptions in the
+    # callbacks to rollback, including &lt;tt&gt;after_*&lt;/tt&gt; callbacks.
+    #
+    # == Exception handling and rolling back
+    #
+    # Also have in mind that exceptions thrown within a transaction block will
+    # be propagated (after triggering the ROLLBACK), so you should be ready to
+    # catch those in your application code.
+    #
+    # One exception is the ActiveRecord::Rollback exception, which will trigger
+    # a ROLLBACK when raised, but not be re-raised by the transaction block.
+    #
+    # *Warning*: one should not catch ActiveRecord::StatementInvalid exceptions
+    # inside a transaction block. StatementInvalid exceptions indicate that an
+    # error occurred at the database level, for example when a unique constraint
+    # is violated. On some database systems, such as PostgreSQL, database errors
+    # inside a transaction causes the entire transaction to become unusable
+    # until it's restarted from the beginning. Here is an example which
+    # demonstrates the problem:
     #
-    # == Exception handling
+    #   # Suppose that we have a Number model with a unique column called 'i'.
+    #   Number.transaction do
+    #     Number.create(:i =&gt; 0)
+    #     begin
+    #       # This will raise a unique constraint error...
+    #       Number.create(:i =&gt; 0)
+    #     rescue ActiveRecord::StatementInvalid
+    #       # ...which we ignore.
+    #     end
+    #     
+    #     # On PostgreSQL, the transaction is now unusable. The following
+    #     # statement will cause a PostgreSQL error, even though the unique
+    #     # constraint is no longer violated:
+    #     Number.create(:i =&gt; 1)
+    #     # =&gt; &quot;PGError: ERROR:  current transaction is aborted, commands
+    #     #     ignored until end of transaction block&quot;
+    #   end
     #
-    # Also have in mind that exceptions thrown within a transaction block will be propagated (after triggering the ROLLBACK), so you
-    # should be ready to catch those in your application code. One exception is the ActiveRecord::Rollback exception, which will
-    # trigger a ROLLBACK when raised, but not be re-raised by the transaction block.
+    # One should restart the entire transaction if a StatementError occurred.
     module ClassMethods
+      # See ActiveRecord::Transactions::ClassMethods for detailed documentation.
       def transaction(&amp;block)
-        increment_open_transactions
+        connection.increment_open_transactions
 
         begin
-          connection.transaction(Thread.current['start_db_transaction'], &amp;block)
+          connection.transaction(connection.open_transactions == 1, &amp;block)
         ensure
-          decrement_open_transactions
+          connection.decrement_open_transactions
         end
       end
-
-      private
-        def increment_open_transactions #:nodoc:
-          open = Thread.current['open_transactions'] ||= 0
-          Thread.current['start_db_transaction'] = open.zero?
-          Thread.current['open_transactions'] = open + 1
-        end
-
-        def decrement_open_transactions #:nodoc:
-          Thread.current['open_transactions'] -= 1
-        end
     end
 
+    # See ActiveRecord::Transactions::ClassMethods for detailed documentation.
     def transaction(&amp;block)
       self.class.transaction(&amp;block)
     end
 
     def destroy_with_transactions #:nodoc:
-      transaction { destroy_without_transactions }
+      with_transaction_returning_status(:destroy_without_transactions)
     end
 
     def save_with_transactions(perform_validation = true) #:nodoc:
-      rollback_active_record_state! { transaction { save_without_transactions(perform_validation) } }
+      rollback_active_record_state! { with_transaction_returning_status(:save_without_transactions, perform_validation) }
     end
 
     def save_with_transactions! #:nodoc:
@@ -126,5 +166,20 @@ module ActiveRecord
       end
       raise
     end
+
+    # Executes +method+ within a transaction and captures its return value as a
+    # status flag. If the status is true the transaction is committed, otherwise
+    # a ROLLBACK is issued. In any case the status flag is returned.
+    #
+    # This method is available within the context of an ActiveRecord::Base
+    # instance.
+    def with_transaction_returning_status(method, *args)
+      status = nil
+      transaction do
+        status = send(method, *args)
+        raise ActiveRecord::Rollback unless status
+      end
+      status
+    end
   end
 end</diff>
      <filename>vendor/activerecord/lib/active_record/transactions.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,5 +1,5 @@
 module ActiveRecord
-  # Raised by save! and create! when the record is invalid.  Use the
+  # Raised by &lt;tt&gt;save!&lt;/tt&gt; and &lt;tt&gt;create!&lt;/tt&gt; when the record is invalid.  Use the
   # +record+ method to retrieve the record which did not validate.
   #   begin
   #     complex_operation_that_calls_save!_internally
@@ -18,70 +18,97 @@ module ActiveRecord
   # determine whether the object is in a valid state to be saved. See usage example in Validations.
   class Errors
     include Enumerable
+    
+    class &lt;&lt; self
+      def default_error_messages
+        ActiveSupport::Deprecation.warn(&quot;ActiveRecord::Errors.default_error_messages has been deprecated. Please use I18n.translate('activerecord.errors.messages').&quot;)
+        I18n.translate 'activerecord.errors.messages'
+      end
+    end
 
     def initialize(base) # :nodoc:
       @base, @errors = base, {}
     end
 
-    @@default_error_messages = {
-      :inclusion =&gt; &quot;is not included in the list&quot;,
-      :exclusion =&gt; &quot;is reserved&quot;,
-      :invalid =&gt; &quot;is invalid&quot;,
-      :confirmation =&gt; &quot;doesn't match confirmation&quot;,
-      :accepted  =&gt; &quot;must be accepted&quot;,
-      :empty =&gt; &quot;can't be empty&quot;,
-      :blank =&gt; &quot;can't be blank&quot;,
-      :too_long =&gt; &quot;is too long (maximum is %d characters)&quot;,
-      :too_short =&gt; &quot;is too short (minimum is %d characters)&quot;,
-      :wrong_length =&gt; &quot;is the wrong length (should be %d characters)&quot;,
-      :taken =&gt; &quot;has already been taken&quot;,
-      :not_a_number =&gt; &quot;is not a number&quot;,
-      :greater_than =&gt; &quot;must be greater than %d&quot;,
-      :greater_than_or_equal_to =&gt; &quot;must be greater than or equal to %d&quot;,
-      :equal_to =&gt; &quot;must be equal to %d&quot;,
-      :less_than =&gt; &quot;must be less than %d&quot;,
-      :less_than_or_equal_to =&gt; &quot;must be less than or equal to %d&quot;,
-      :odd =&gt; &quot;must be odd&quot;,
-      :even =&gt; &quot;must be even&quot;
-    }
-
-    # Holds a hash with all the default error messages that can be replaced by your own copy or localizations.
-    cattr_accessor :default_error_messages
-
-
     # Adds an error to the base object instead of any particular attribute. This is used
     # to report errors that don't tie to any specific attribute, but rather to the object
     # as a whole. These error messages don't get prepended with any field name when iterating
-    # with each_full, so they should be complete sentences.
+    # with +each_full+, so they should be complete sentences.
     def add_to_base(msg)
       add(:base, msg)
     end
 
-    # Adds an error message (+msg+) to the +attribute+, which will be returned on a call to &lt;tt&gt;on(attribute)&lt;/tt&gt;
+    # Adds an error message (+messsage+) to the +attribute+, which will be returned on a call to &lt;tt&gt;on(attribute)&lt;/tt&gt;
     # for the same attribute and ensure that this error object returns false when asked if &lt;tt&gt;empty?&lt;/tt&gt;. More than one
     # error can be added to the same +attribute+ in which case an array will be returned on a call to &lt;tt&gt;on(attribute)&lt;/tt&gt;.
-    # If no +msg+ is supplied, &quot;invalid&quot; is assumed.
-    def add(attribute, msg = @@default_error_messages[:invalid])
-      @errors[attribute.to_s] = [] if @errors[attribute.to_s].nil?
-      @errors[attribute.to_s] &lt;&lt; msg
+    # If no +messsage+ is supplied, :invalid is assumed.
+    # If +message+ is a Symbol, it will be translated, using the appropriate scope (see translate_error).
+    def add(attribute, message = nil, options = {})
+      message ||= :invalid
+      message = generate_message(attribute, message, options) if message.is_a?(Symbol)
+      @errors[attribute.to_s] ||= []
+      @errors[attribute.to_s] &lt;&lt; message
     end
 
     # Will add an error message to each of the attributes in +attributes+ that is empty.
-    def add_on_empty(attributes, msg = @@default_error_messages[:empty])
+    def add_on_empty(attributes, custom_message = nil)
       for attr in [attributes].flatten
         value = @base.respond_to?(attr.to_s) ? @base.send(attr.to_s) : @base[attr.to_s]
-        is_empty = value.respond_to?(&quot;empty?&quot;) ? value.empty? : false
-        add(attr, msg) unless !value.nil? &amp;&amp; !is_empty
+        is_empty = value.respond_to?(:empty?) ? value.empty? : false
+        add(attr, :empty, :default =&gt; custom_message) unless !value.nil? &amp;&amp; !is_empty
       end
     end
 
     # Will add an error message to each of the attributes in +attributes+ that is blank (using Object#blank?).
-    def add_on_blank(attributes, msg = @@default_error_messages[:blank])
+    def add_on_blank(attributes, custom_message = nil)
       for attr in [attributes].flatten
         value = @base.respond_to?(attr.to_s) ? @base.send(attr.to_s) : @base[attr.to_s]
-        add(attr, msg) if value.blank?
+        add(attr, :blank, :default =&gt; custom_message) if value.blank?
       end
     end
+    
+    # Translates an error message in it's default scope (&lt;tt&gt;activerecord.errrors.messages&lt;/tt&gt;).
+    # Error messages are first looked up in &lt;tt&gt;models.MODEL.attributes.ATTRIBUTE.MESSAGE&lt;/tt&gt;, if it's not there, 
+    # it's looked up in &lt;tt&gt;models.MODEL.MESSAGE&lt;/tt&gt; and if that is not there it returns the translation of the 
+    # default message (e.g. &lt;tt&gt;activerecord.errors.messages.MESSAGE&lt;/tt&gt;). The translated model name, 
+    # translated attribute name and the value are available for interpolation.
+    #
+    # When using inheritence in your models, it will check all the inherited models too, but only if the model itself
+    # hasn't been found. Say you have &lt;tt&gt;class Admin &lt; User; end&lt;/tt&gt; and you wanted the translation for the &lt;tt&gt;:blank&lt;/tt&gt;
+    # error +message+ for the &lt;tt&gt;title&lt;/tt&gt; +attribute+, it looks for these translations:
+    # 
+    # &lt;ol&gt;
+    # &lt;li&gt;&lt;tt&gt;activerecord.errors.models.admin.attributes.title.blank&lt;/tt&gt;&lt;/li&gt;
+    # &lt;li&gt;&lt;tt&gt;activerecord.errors.models.admin.blank&lt;/tt&gt;&lt;/li&gt;
+    # &lt;li&gt;&lt;tt&gt;activerecord.errors.models.user.attributes.title.blank&lt;/tt&gt;&lt;/li&gt;
+    # &lt;li&gt;&lt;tt&gt;activerecord.errors.models.user.blank&lt;/tt&gt;&lt;/li&gt;
+    # &lt;li&gt;&lt;tt&gt;activerecord.errors.messages.blank&lt;/tt&gt;&lt;/li&gt;
+    # &lt;li&gt;any default you provided through the +options+ hash (in the activerecord.errors scope)&lt;/li&gt;
+    # &lt;/ol&gt;
+    def generate_message(attribute, message = :invalid, options = {})
+
+      message, options[:default] = options[:default], message if options[:default].is_a?(Symbol)
+
+      defaults = @base.class.self_and_descendents_from_active_record.map do |klass| 
+        [ :&quot;models.#{klass.name.underscore}.attributes.#{attribute}.#{message}&quot;, 
+          :&quot;models.#{klass.name.underscore}.#{message}&quot; ]
+      end
+      
+      defaults &lt;&lt; options.delete(:default)
+      defaults = defaults.compact.flatten &lt;&lt; :&quot;messages.#{message}&quot;
+
+      key = defaults.shift
+      value = @base.respond_to?(attribute) ? @base.send(attribute) : nil
+
+      options = { :default =&gt; defaults,
+        :model =&gt; @base.class.human_name,
+        :attribute =&gt; @base.class.human_attribute_name(attribute.to_s),
+        :value =&gt; value,
+        :scope =&gt; [:activerecord, :errors]
+      }.merge(options)
+
+      I18n.translate(key, options)
+    end
 
     # Returns true if the specified +attribute+ has errors associated with it.
     #
@@ -97,7 +124,7 @@ module ActiveRecord
       !@errors[attribute.to_s].nil?
     end
 
-    # Returns nil, if no errors are associated with the specified +attribute+.
+    # Returns +nil+, if no errors are associated with the specified +attribute+.
     # Returns the error message, if one error is associated with the specified +attribute+.
     # Returns an array of error messages, if more than one error is associated with the specified +attribute+.
     #
@@ -118,7 +145,7 @@ module ActiveRecord
 
     alias :[] :on
 
-    # Returns errors assigned to the base object through add_to_base according to the normal rules of on(attribute).
+    # Returns errors assigned to the base object through +add_to_base+ according to the normal rules of &lt;tt&gt;on(attribute)&lt;/tt&gt;.
     def on_base
       on(:base)
     end
@@ -131,15 +158,15 @@ module ActiveRecord
     #   end
     #
     #   company = Company.create(:address =&gt; '123 First St.')
-    #   company.errors.each{|attr,msg| puts &quot;#{attr} - #{msg}&quot; } # =&gt;
-    #     name - is too short (minimum is 5 characters)
-    #     name - can't be blank
-    #     address - can't be blank
+    #   company.errors.each{|attr,msg| puts &quot;#{attr} - #{msg}&quot; }
+    #   # =&gt; name - is too short (minimum is 5 characters)
+    #   #    name - can't be blank
+    #   #    address - can't be blank
     def each
       @errors.each_key { |attr| @errors[attr].each { |msg| yield attr, msg } }
     end
 
-    # Yields each full error message added. So Person.errors.add(&quot;first_name&quot;, &quot;can't be empty&quot;) will be returned
+    # Yields each full error message added. So &lt;tt&gt;Person.errors.add(&quot;first_name&quot;, &quot;can't be empty&quot;)&lt;/tt&gt; will be returned
     # through iteration as &quot;First name can't be empty&quot;.
     #
     #   class Company &lt; ActiveRecord::Base
@@ -148,10 +175,10 @@ module ActiveRecord
     #   end
     #
     #   company = Company.create(:address =&gt; '123 First St.')
-    #   company.errors.each_full{|msg| puts msg } # =&gt;
-    #     Name is too short (minimum is 5 characters)
-    #     Name can't be blank
-    #     Address can't be blank
+    #   company.errors.each_full{|msg| puts msg }
+    #   # =&gt; Name is too short (minimum is 5 characters)
+    #   #    Name can't be blank
+    #   #    Address can't be blank
     def each_full
       full_messages.each { |msg| yield msg }
     end
@@ -166,22 +193,24 @@ module ActiveRecord
     #   company = Company.create(:address =&gt; '123 First St.')
     #   company.errors.full_messages # =&gt;
     #     [&quot;Name is too short (minimum is 5 characters)&quot;, &quot;Name can't be blank&quot;, &quot;Address can't be blank&quot;]
-    def full_messages
+    def full_messages(options = {})
       full_messages = []
 
       @errors.each_key do |attr|
-        @errors[attr].each do |msg|
-          next if msg.nil?
+        @errors[attr].each do |message|
+          next unless message
 
           if attr == &quot;base&quot;
-            full_messages &lt;&lt; msg
+            full_messages &lt;&lt; message
           else
-            full_messages &lt;&lt; @base.class.human_attribute_name(attr) + &quot; &quot; + msg
+            #key = :&quot;activerecord.att.#{@base.class.name.underscore.to_sym}.#{attr}&quot; 
+            attr_name = @base.class.human_attribute_name(attr)
+            full_messages &lt;&lt; attr_name + ' ' + message
           end
         end
       end
       full_messages
-    end
+    end 
 
     # Returns true if no errors have been added.
     def empty?
@@ -209,13 +238,13 @@ module ActiveRecord
     #   end
     #
     #   company = Company.create(:address =&gt; '123 First St.')
-    #   company.errors.to_xml # =&gt;
-    #     &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
-    #     &lt;errors&gt;
-    #       &lt;error&gt;Name is too short (minimum is 5 characters)&lt;/error&gt;
-    #       &lt;error&gt;Name can't be blank&lt;/error&gt;
-    #       &lt;error&gt;Address can't be blank&lt;/error&gt;
-    #     &lt;/errors&gt;
+    #   company.errors.to_xml
+    #   # =&gt;  &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
+    #   #     &lt;errors&gt;
+    #   #       &lt;error&gt;Name is too short (minimum is 5 characters)&lt;/error&gt;
+    #   #       &lt;error&gt;Name can't be blank&lt;/error&gt;
+    #   #       &lt;error&gt;Address can't be blank&lt;/error&gt;
+    #   #     &lt;/errors&gt;
     def to_xml(options={})
       options[:root] ||= &quot;errors&quot;
       options[:indent] ||= 2
@@ -226,9 +255,12 @@ module ActiveRecord
         full_messages.each { |msg| e.error(msg) }
       end
     end
+    
   end
 
 
+  # Please do have a look at ActiveRecord::Validations::ClassMethods for a higher level of validations.
+  #
   # Active Records implement validation by overwriting Base#validate (or the variations, +validate_on_create+ and
   # +validate_on_update+). Each of these methods can inspect the state of the object, which usually means ensuring
   # that a number of attributes have a certain value (such as not empty, within a given range, matching a certain regular expression).
@@ -261,14 +293,12 @@ module ActiveRecord
   #   person.errors.on &quot;phone_number&quot;     # =&gt; &quot;has invalid format&quot;
   #   person.errors.each_full { |msg| puts msg }
   #                                       # =&gt; &quot;Last name can't be empty\n&quot; +
-  #                                            &quot;Phone number has invalid format&quot;
+  #                                       #    &quot;Phone number has invalid format&quot;
   #
   #   person.attributes = { &quot;last_name&quot; =&gt; &quot;Heinemeier&quot;, &quot;phone_number&quot; =&gt; &quot;555-555&quot; }
   #   person.save # =&gt; true (and person is now saved in the database)
   #
   # An Errors object is automatically created for every Active Record.
-  #
-  # Please do have a look at ActiveRecord::Validations::ClassMethods for a higher level of validations.
   module Validations
     VALIDATIONS = %w( validate validate_on_create validate_on_update )
 
@@ -277,16 +307,56 @@ module ActiveRecord
       base.class_eval do
         alias_method_chain :save, :validation
         alias_method_chain :save!, :validation
-        alias_method_chain :update_attribute, :validation_skipping
       end
 
       base.send :include, ActiveSupport::Callbacks
       base.define_callbacks *VALIDATIONS
     end
 
-    # All of the following validations are defined in the class scope of the model that you're interested in validating.
-    # They offer a more declarative way of specifying when the model is valid and when it is not. It is recommended to use
-    # these over the low-level calls to +validate+ and +validate_on_create+ when possible.
+    # Active Record classes can implement validations in several ways. The highest level, easiest to read,
+    # and recommended approach is to use the declarative &lt;tt&gt;validates_..._of&lt;/tt&gt; class methods (and
+    # +validates_associated+) documented below. These are sufficient for most model validations.
+    #
+    # Slightly lower level is +validates_each+. It provides some of the same options as the purely declarative
+    # validation methods, but like all the lower-level approaches it requires manually adding to the errors collection
+    # when the record is invalid.
+    #
+    # At a yet lower level, a model can use the class methods +validate+, +validate_on_create+ and +validate_on_update+
+    # to add validation methods or blocks. These are ActiveSupport::Callbacks and follow the same rules of inheritance
+    # and chaining.
+    #
+    # The lowest level style is to define the instance methods +validate+, +validate_on_create+ and +validate_on_update+
+    # as documented in ActiveRecord::Validations.
+    #
+    # == +validate+, +validate_on_create+ and +validate_on_update+ Class Methods
+    #
+    # Calls to these methods add a validation method or block to the class. Again, this approach is recommended
+    # only when the higher-level methods documented below (&lt;tt&gt;validates_..._of&lt;/tt&gt; and +validates_associated+) are
+    # insufficient to handle the required validation.
+    #
+    # This can be done with a symbol pointing to a method:
+    #
+    #   class Comment &lt; ActiveRecord::Base
+    #     validate :must_be_friends
+    #
+    #     def must_be_friends
+    #       errors.add_to_base(&quot;Must be friends to leave a comment&quot;) unless commenter.friend_of?(commentee)
+    #     end
+    #   end
+    #
+    # Or with a block which is passed the current record to be validated:
+    #
+    #   class Comment &lt; ActiveRecord::Base
+    #     validate do |comment|
+    #       comment.must_be_friends
+    #     end
+    #
+    #     def must_be_friends
+    #       errors.add_to_base(&quot;Must be friends to leave a comment&quot;) unless commenter.friend_of?(commentee)
+    #     end
+    #   end
+    #
+    # This usage applies to +validate_on_create+ and +validate_on_update+ as well.
     module ClassMethods
       DEFAULT_VALIDATION_OPTIONS = {
         :on =&gt; :save,
@@ -300,34 +370,6 @@ module ActiveRecord
                                   :equal_to =&gt; '==', :less_than =&gt; '&lt;', :less_than_or_equal_to =&gt; '&lt;=',
                                   :odd =&gt; 'odd?', :even =&gt; 'even?' }.freeze
 
-      # Adds a validation method or block to the class. This is useful when
-      # overriding the +validate+ instance method becomes too unwieldly and
-      # you're looking for more descriptive declaration of your validations.
-      #
-      # This can be done with a symbol pointing to a method:
-      #
-      #   class Comment &lt; ActiveRecord::Base
-      #     validate :must_be_friends
-      #
-      #     def must_be_friends
-      #       errors.add_to_base(&quot;Must be friends to leave a comment&quot;) unless commenter.friend_of?(commentee)
-      #     end
-      #   end
-      #
-      # Or with a block which is passed the current record to be validated:
-      #
-      #   class Comment &lt; ActiveRecord::Base
-      #     validate do |comment|
-      #       comment.must_be_friends
-      #     end
-      #
-      #     def must_be_friends
-      #       errors.add_to_base(&quot;Must be friends to leave a comment&quot;) unless commenter.friend_of?(commentee)
-      #     end
-      #   end
-      #
-      # This usage applies to +validate_on_create+ and +validate_on_update+ as well.
-
       # Validates each attribute against a block.
       #
       #   class Person &lt; ActiveRecord::Base
@@ -389,13 +431,15 @@ module ActiveRecord
       #   not occur (e.g. &lt;tt&gt;:unless =&gt; :skip_validation&lt;/tt&gt;, or &lt;tt&gt;:unless =&gt; Proc.new { |user| user.signup_step &lt;= 2 }&lt;/tt&gt;).  The
       #   method, proc or string should return or evaluate to a true or false value.
       def validates_confirmation_of(*attr_names)
-        configuration = { :message =&gt; ActiveRecord::Errors.default_error_messages[:confirmation], :on =&gt; :save }
+        configuration = { :on =&gt; :save }
         configuration.update(attr_names.extract_options!)
 
         attr_accessor(*(attr_names.map { |n| &quot;#{n}_confirmation&quot; }))
 
         validates_each(attr_names, configuration) do |record, attr_name, value|
-          record.errors.add(attr_name, configuration[:message]) unless record.send(&quot;#{attr_name}_confirmation&quot;).nil? or value == record.send(&quot;#{attr_name}_confirmation&quot;)
+          unless record.send(&quot;#{attr_name}_confirmation&quot;).nil? or value == record.send(&quot;#{attr_name}_confirmation&quot;)
+            record.errors.add(attr_name, :confirmation, :default =&gt; configuration[:message]) 
+          end
         end
       end
 
@@ -423,19 +467,21 @@ module ActiveRecord
       #   not occur (e.g. &lt;tt&gt;:unless =&gt; :skip_validation&lt;/tt&gt;, or &lt;tt&gt;:unless =&gt; Proc.new { |user| user.signup_step &lt;= 2 }&lt;/tt&gt;).  The
       #   method, proc or string should return or evaluate to a true or false value.
       def validates_acceptance_of(*attr_names)
-        configuration = { :message =&gt; ActiveRecord::Errors.default_error_messages[:accepted], :on =&gt; :save, :allow_nil =&gt; true, :accept =&gt; &quot;1&quot; }
+        configuration = { :on =&gt; :save, :allow_nil =&gt; true, :accept =&gt; &quot;1&quot; }
         configuration.update(attr_names.extract_options!)
 
         db_cols = begin
           column_names
-        rescue ActiveRecord::StatementInvalid
+        rescue Exception # To ignore both statement and connection errors
           []
         end
         names = attr_names.reject { |name| db_cols.include?(name.to_s) }
         attr_accessor(*names)
 
         validates_each(attr_names,configuration) do |record, attr_name, value|
-          record.errors.add(attr_name, configuration[:message]) unless value == configuration[:accept]
+          unless value == configuration[:accept]
+            record.errors.add(attr_name, :accepted, :default =&gt; configuration[:message]) 
+          end
         end
       end
 
@@ -462,7 +508,7 @@ module ActiveRecord
       #   method, proc or string should return or evaluate to a true or false value.
       #
       def validates_presence_of(*attr_names)
-        configuration = { :message =&gt; ActiveRecord::Errors.default_error_messages[:blank], :on =&gt; :save }
+        configuration = { :on =&gt; :save }
         configuration.update(attr_names.extract_options!)
 
         # can't use validates_each here, because it cannot cope with nonexistent attributes,
@@ -476,13 +522,13 @@ module ActiveRecord
       #
       #   class Person &lt; ActiveRecord::Base
       #     validates_length_of :first_name, :maximum=&gt;30
-      #     validates_length_of :last_name, :maximum=&gt;30, :message=&gt;&quot;less than %d if you don't mind&quot;
+      #     validates_length_of :last_name, :maximum=&gt;30, :message=&gt;&quot;less than {{count}} if you don't mind&quot;
       #     validates_length_of :fax, :in =&gt; 7..32, :allow_nil =&gt; true
       #     validates_length_of :phone, :in =&gt; 7..32, :allow_blank =&gt; true
       #     validates_length_of :user_name, :within =&gt; 6..20, :too_long =&gt; &quot;pick a shorter name&quot;, :too_short =&gt; &quot;pick a longer name&quot;
-      #     validates_length_of :fav_bra_size, :minimum =&gt; 1, :too_short =&gt; &quot;please enter at least %d character&quot;
-      #     validates_length_of :smurf_leader, :is =&gt; 4, :message =&gt; &quot;papa is spelled with %d characters... don't play me.&quot;
-      #     validates_length_of :essay, :minimum =&gt; 100, :too_short =&gt; &quot;Your essay must be at least %d words.&quot;), :tokenizer =&gt; lambda {|str| str.scan(/\w+/) }
+      #     validates_length_of :fav_bra_size, :minimum =&gt; 1, :too_short =&gt; &quot;please enter at least {{count}} character&quot;
+      #     validates_length_of :smurf_leader, :is =&gt; 4, :message =&gt; &quot;papa is spelled with {{count}} characters... don't play me.&quot;
+      #     validates_length_of :essay, :minimum =&gt; 100, :too_short =&gt; &quot;Your essay must be at least {{count}} words.&quot;), :tokenizer =&gt; lambda {|str| str.scan(/\w+/) }
       #   end
       #
       # Configuration options:
@@ -493,9 +539,9 @@ module ActiveRecord
       # * &lt;tt&gt;:in&lt;/tt&gt; - A synonym(or alias) for &lt;tt&gt;:within&lt;/tt&gt;.
       # * &lt;tt&gt;:allow_nil&lt;/tt&gt; - Attribute may be +nil+; skip validation.
       # * &lt;tt&gt;:allow_blank&lt;/tt&gt; - Attribute may be blank; skip validation.
-      # * &lt;tt&gt;:too_long&lt;/tt&gt; - The error message if the attribute goes over the maximum (default is: &quot;is too long (maximum is %d characters)&quot;).
-      # * &lt;tt&gt;:too_short&lt;/tt&gt; - The error message if the attribute goes under the minimum (default is: &quot;is too short (min is %d characters)&quot;).
-      # * &lt;tt&gt;:wrong_length&lt;/tt&gt; - The error message if using the &lt;tt&gt;:is&lt;/tt&gt; method and the attribute is the wrong size (default is: &quot;is the wrong length (should be %d characters)&quot;).
+      # * &lt;tt&gt;:too_long&lt;/tt&gt; - The error message if the attribute goes over the maximum (default is: &quot;is too long (maximum is {{count}} characters)&quot;).
+      # * &lt;tt&gt;:too_short&lt;/tt&gt; - The error message if the attribute goes under the minimum (default is: &quot;is too short (min is {{count}} characters)&quot;).
+      # * &lt;tt&gt;:wrong_length&lt;/tt&gt; - The error message if using the &lt;tt&gt;:is&lt;/tt&gt; method and the attribute is the wrong size (default is: &quot;is the wrong length (should be {{count}} characters)&quot;).
       # * &lt;tt&gt;:message&lt;/tt&gt; - The error message to use for a &lt;tt&gt;:minimum&lt;/tt&gt;, &lt;tt&gt;:maximum&lt;/tt&gt;, or &lt;tt&gt;:is&lt;/tt&gt; violation.  An alias of the appropriate &lt;tt&gt;too_long&lt;/tt&gt;/&lt;tt&gt;too_short&lt;/tt&gt;/&lt;tt&gt;wrong_length&lt;/tt&gt; message.
       # * &lt;tt&gt;:on&lt;/tt&gt; - Specifies when this validation is active (default is &lt;tt&gt;:save&lt;/tt&gt;, other options &lt;tt&gt;:create&lt;/tt&gt;, &lt;tt&gt;:update&lt;/tt&gt;).
       # * &lt;tt&gt;:if&lt;/tt&gt; - Specifies a method, proc or string to call to determine if the validation should
@@ -510,10 +556,7 @@ module ActiveRecord
       def validates_length_of(*attrs)
         # Merge given options with defaults.
         options = {
-          :too_long     =&gt; ActiveRecord::Errors.default_error_messages[:too_long],
-          :too_short    =&gt; ActiveRecord::Errors.default_error_messages[:too_short],
-          :wrong_length =&gt; ActiveRecord::Errors.default_error_messages[:wrong_length],
-          :tokenizer    =&gt; lambda {|value| value.split(//)}
+          :tokenizer =&gt; lambda {|value| value.split(//)}
         }.merge(DEFAULT_VALIDATION_OPTIONS)
         options.update(attrs.extract_options!.symbolize_keys)
 
@@ -536,15 +579,12 @@ module ActiveRecord
           when :within, :in
             raise ArgumentError, &quot;:#{option} must be a Range&quot; unless option_value.is_a?(Range)
 
-            too_short = options[:too_short] % option_value.begin
-            too_long  = options[:too_long]  % option_value.end
-
             validates_each(attrs, options) do |record, attr, value|
               value = options[:tokenizer].call(value) if value.kind_of?(String)
               if value.nil? or value.size &lt; option_value.begin
-                record.errors.add(attr, too_short)
+                record.errors.add(attr, :too_short, :default =&gt; options[:too_short], :count =&gt; option_value.begin)
               elsif value.size &gt; option_value.end
-                record.errors.add(attr, too_long)
+                record.errors.add(attr, :too_long, :default =&gt; options[:too_long], :count =&gt; option_value.end)
               end
             end
           when :is, :minimum, :maximum
@@ -554,11 +594,13 @@ module ActiveRecord
             validity_checks = { :is =&gt; &quot;==&quot;, :minimum =&gt; &quot;&gt;=&quot;, :maximum =&gt; &quot;&lt;=&quot; }
             message_options = { :is =&gt; :wrong_length, :minimum =&gt; :too_short, :maximum =&gt; :too_long }
 
-            message = (options[:message] || options[message_options[option]]) % option_value
-
             validates_each(attrs, options) do |record, attr, value|
               value = options[:tokenizer].call(value) if value.kind_of?(String)
-              record.errors.add(attr, message) unless !value.nil? and value.size.method(validity_checks[option])[option_value]
+              unless !value.nil? and value.size.method(validity_checks[option])[option_value]
+                key = message_options[option]
+                custom_message = options[:message] || options[key]
+                record.errors.add(attr, key, :default =&gt; custom_message, :count =&gt; option_value) 
+              end
             end
         end
       end
@@ -583,14 +625,10 @@ module ActiveRecord
       # When the record is created, a check is performed to make sure that no record exists in the database with the given value for the specified
       # attribute (that maps to a column). When the record is updated, the same check is made but disregarding the record itself.
       #
-      # Because this check is performed outside the database there is still a chance that duplicate values
-      # will be inserted in two parallel transactions.  To guarantee against this you should create a
-      # unique index on the field. See +add_index+ for more information.
-      #
       # Configuration options:
       # * &lt;tt&gt;:message&lt;/tt&gt; - Specifies a custom error message (default is: &quot;has already been taken&quot;).
       # * &lt;tt&gt;:scope&lt;/tt&gt; - One or more columns by which to limit the scope of the uniqueness constraint.
-      # * &lt;tt&gt;:case_sensitive&lt;/tt&gt; - Looks for an exact match.  Ignored by non-text columns (+false+ by default).
+      # * &lt;tt&gt;:case_sensitive&lt;/tt&gt; - Looks for an exact match. Ignored by non-text columns (+true+ by default).
       # * &lt;tt&gt;:allow_nil&lt;/tt&gt; - If set to true, skips this validation if the attribute is +nil+ (default is +false+).
       # * &lt;tt&gt;:allow_blank&lt;/tt&gt; - If set to true, skips this validation if the attribute is blank (default is +false+).
       # * &lt;tt&gt;:if&lt;/tt&gt; - Specifies a method, proc or string to call to determine if the validation should
@@ -599,8 +637,72 @@ module ActiveRecord
       # * &lt;tt&gt;:unless&lt;/tt&gt; - Specifies a method, proc or string to call to determine if the validation should
       #   not occur (e.g. &lt;tt&gt;:unless =&gt; :skip_validation&lt;/tt&gt;, or &lt;tt&gt;:unless =&gt; Proc.new { |user| user.signup_step &lt;= 2 }&lt;/tt&gt;).  The
       #   method, proc or string should return or evaluate to a true or false value.
+      #
+      # === Concurrency and integrity
+      #
+      # Using this validation method in conjunction with ActiveRecord::Base#save
+      # does not guarantee the absence of duplicate record insertions, because
+      # uniqueness checks on the application level are inherently prone to race
+      # conditions. For example, suppose that two users try to post a Comment at
+      # the same time, and a Comment's title must be unique. At the database-level,
+      # the actions performed by these users could be interleaved in the following manner:
+      #
+      #               User 1                 |               User 2
+      #  ------------------------------------+--------------------------------------
+      #  # User 1 checks whether there's     |
+      #  # already a comment with the title  |
+      #  # 'My Post'. This is not the case.  |
+      #  SELECT * FROM comments              |
+      #  WHERE title = 'My Post'             |
+      #                                      |
+      #                                      | # User 2 does the same thing and also
+      #                                      | # infers that his title is unique.
+      #                                      | SELECT * FROM comments
+      #                                      | WHERE title = 'My Post'
+      #                                      |
+      #  # User 1 inserts his comment.       |
+      #  INSERT INTO comments                |
+      #  (title, content) VALUES             |
+      #  ('My Post', 'hi!')                  |
+      #                                      |
+      #                                      | # User 2 does the same thing.
+      #                                      | INSERT INTO comments
+      #                                      | (title, content) VALUES
+      #                                      | ('My Post', 'hello!')
+      #                                      |
+      #                                      | # ^^^^^^
+      #                                      | # Boom! We now have a duplicate
+      #                                      | # title!
+      #
+      # This could even happen if you use transactions with the 'serializable'
+      # isolation level. There are several ways to get around this problem:
+      # - By locking the database table before validating, and unlocking it after
+      #   saving. However, table locking is very expensive, and thus not
+      #   recommended.
+      # - By locking a lock file before validating, and unlocking it after saving.
+      #   This does not work if you've scaled your Rails application across
+      #   multiple web servers (because they cannot share lock files, or cannot
+      #   do that efficiently), and thus not recommended.
+      # - Creating a unique index on the field, by using
+      #   ActiveRecord::ConnectionAdapters::SchemaStatements#add_index. In the
+      #   rare case that a race condition occurs, the database will guarantee
+      #   the field's uniqueness.
+      #   
+      #   When the database catches such a duplicate insertion,
+      #   ActiveRecord::Base#save will raise an ActiveRecord::StatementInvalid
+      #   exception. You can either choose to let this error propagate (which
+      #   will result in the default Rails exception page being shown), or you
+      #   can catch it and restart the transaction (e.g. by telling the user
+      #   that the title already exists, and asking him to re-enter the title).
+      #   This technique is also known as optimistic concurrency control:
+      #   http://en.wikipedia.org/wiki/Optimistic_concurrency_control
+      #   
+      #   Active Record currently provides no way to distinguish unique
+      #   index constraint errors from other types of database errors, so you
+      #   will have to parse the (database-specific) exception message to detect
+      #   such a case.
       def validates_uniqueness_of(*attr_names)
-        configuration = { :message =&gt; ActiveRecord::Errors.default_error_messages[:taken], :case_sensitive =&gt; true }
+        configuration = { :case_sensitive =&gt; true }
         configuration.update(attr_names.extract_options!)
 
         validates_each(attr_names,configuration) do |record, attr_name, value|
@@ -620,18 +722,23 @@ module ActiveRecord
 
           is_text_column = finder_class.columns_hash[attr_name.to_s].text?
 
-          if !value.nil? &amp;&amp; is_text_column
+          if value.nil?
+            comparison_operator = &quot;IS ?&quot;
+          elsif is_text_column
+            comparison_operator = &quot;#{connection.case_sensitive_equality_operator} ?&quot;
             value = value.to_s
+          else
+            comparison_operator = &quot;= ?&quot;
           end
 
+          sql_attribute = &quot;#{record.class.quoted_table_name}.#{connection.quote_column_name(attr_name)}&quot;
+
           if value.nil? || (configuration[:case_sensitive] || !is_text_column)
-            condition_sql = &quot;#{record.class.quoted_table_name}.#{attr_name} #{attribute_condition(value)}&quot;
+            condition_sql = &quot;#{sql_attribute} #{comparison_operator}&quot;
             condition_params = [value]
           else
-            # sqlite has case sensitive SELECT query, while MySQL/Postgresql don't.
-            # Hence, this is needed only for sqlite.
-            condition_sql = &quot;LOWER(#{record.class.quoted_table_name}.#{attr_name}) #{attribute_condition(value)}&quot;
-            condition_params = [value.chars.downcase]
+            condition_sql = &quot;LOWER(#{sql_attribute}) #{comparison_operator}&quot;
+            condition_params = [value.mb_chars.downcase]
           end
 
           if scope = configuration[:scope]
@@ -647,26 +754,10 @@ module ActiveRecord
             condition_params &lt;&lt; record.send(:id)
           end
 
-          results = finder_class.with_exclusive_scope do
-            connection.select_all(
-              construct_finder_sql(
-                :select     =&gt; &quot;#{connection.quote_column_name(attr_name)}&quot;,
-                :from       =&gt; &quot;#{finder_class.quoted_table_name}&quot;,
-                :conditions =&gt; [condition_sql, *condition_params]
-              )
-            )
-          end
-
-          unless results.length.zero?
-            found = true
-
-            # As MySQL/Postgres don't have case sensitive SELECT queries, we try to find duplicate
-            # column in ruby when case sensitive option
-            if configuration[:case_sensitive] &amp;&amp; finder_class.columns_hash[attr_name.to_s].text?
-              found = results.any? { |a| a[attr_name.to_s] == value }
+          finder_class.with_exclusive_scope do
+            if finder_class.exists?([condition_sql, *condition_params])
+              record.errors.add(attr_name, :taken, :default =&gt; configuration[:message], :value =&gt; value)
             end
-
-            record.errors.add(attr_name, configuration[:message]) if found
           end
         end
       end
@@ -696,13 +787,15 @@ module ActiveRecord
       #   not occur (e.g. &lt;tt&gt;:unless =&gt; :skip_validation&lt;/tt&gt;, or &lt;tt&gt;:unless =&gt; Proc.new { |user| user.signup_step &lt;= 2 }&lt;/tt&gt;).  The
       #   method, proc or string should return or evaluate to a true or false value.
       def validates_format_of(*attr_names)
-        configuration = { :message =&gt; ActiveRecord::Errors.default_error_messages[:invalid], :on =&gt; :save, :with =&gt; nil }
+        configuration = { :on =&gt; :save, :with =&gt; nil }
         configuration.update(attr_names.extract_options!)
 
         raise(ArgumentError, &quot;A regular expression must be supplied as the :with option of the configuration hash&quot;) unless configuration[:with].is_a?(Regexp)
 
         validates_each(attr_names, configuration) do |record, attr_name, value|
-          record.errors.add(attr_name, configuration[:message] % value) unless value.to_s =~ configuration[:with]
+          unless value.to_s =~ configuration[:with]
+            record.errors.add(attr_name, :invalid, :default =&gt; configuration[:message], :value =&gt; value) 
+          end
         end
       end
 
@@ -711,7 +804,7 @@ module ActiveRecord
       #   class Person &lt; ActiveRecord::Base
       #     validates_inclusion_of :gender, :in =&gt; %w( m f ), :message =&gt; &quot;woah! what are you then!??!!&quot;
       #     validates_inclusion_of :age, :in =&gt; 0..99
-      #     validates_inclusion_of :format, :in =&gt; %w( jpg gif png ), :message =&gt; &quot;extension %s is not included in the list&quot;
+      #     validates_inclusion_of :format, :in =&gt; %w( jpg gif png ), :message =&gt; &quot;extension {{value}} is not included in the list&quot;
       #   end
       #
       # Configuration options:
@@ -726,15 +819,17 @@ module ActiveRecord
       #   not occur (e.g. &lt;tt&gt;:unless =&gt; :skip_validation&lt;/tt&gt;, or &lt;tt&gt;:unless =&gt; Proc.new { |user| user.signup_step &lt;= 2 }&lt;/tt&gt;).  The
       #   method, proc or string should return or evaluate to a true or false value.
       def validates_inclusion_of(*attr_names)
-        configuration = { :message =&gt; ActiveRecord::Errors.default_error_messages[:inclusion], :on =&gt; :save }
+        configuration = { :on =&gt; :save }
         configuration.update(attr_names.extract_options!)
 
         enum = configuration[:in] || configuration[:within]
 
-        raise(ArgumentError, &quot;An object with the method include? is required must be supplied as the :in option of the configuration hash&quot;) unless enum.respond_to?(&quot;include?&quot;)
+        raise(ArgumentError, &quot;An object with the method include? is required must be supplied as the :in option of the configuration hash&quot;) unless enum.respond_to?(:include?)
 
         validates_each(attr_names, configuration) do |record, attr_name, value|
-          record.errors.add(attr_name, configuration[:message] % value) unless enum.include?(value)
+          unless enum.include?(value)
+            record.errors.add(attr_name, :inclusion, :default =&gt; configuration[:message], :value =&gt; value) 
+          end
         end
       end
 
@@ -743,7 +838,7 @@ module ActiveRecord
       #   class Person &lt; ActiveRecord::Base
       #     validates_exclusion_of :username, :in =&gt; %w( admin superuser ), :message =&gt; &quot;You don't belong here&quot;
       #     validates_exclusion_of :age, :in =&gt; 30..60, :message =&gt; &quot;This site is only for under 30 and over 60&quot;
-      #     validates_exclusion_of :format, :in =&gt; %w( mov avi ), :message =&gt; &quot;extension %s is not allowed&quot;
+      #     validates_exclusion_of :format, :in =&gt; %w( mov avi ), :message =&gt; &quot;extension {{value}} is not allowed&quot;
       #   end
       #
       # Configuration options:
@@ -758,15 +853,17 @@ module ActiveRecord
       #   not occur (e.g. &lt;tt&gt;:unless =&gt; :skip_validation&lt;/tt&gt;, or &lt;tt&gt;:unless =&gt; Proc.new { |user| user.signup_step &lt;= 2 }&lt;/tt&gt;).  The
       #   method, proc or string should return or evaluate to a true or false value.
       def validates_exclusion_of(*attr_names)
-        configuration = { :message =&gt; ActiveRecord::Errors.default_error_messages[:exclusion], :on =&gt; :save }
+        configuration = { :on =&gt; :save }
         configuration.update(attr_names.extract_options!)
 
         enum = configuration[:in] || configuration[:within]
 
-        raise(ArgumentError, &quot;An object with the method include? is required must be supplied as the :in option of the configuration hash&quot;) unless enum.respond_to?(&quot;include?&quot;)
+        raise(ArgumentError, &quot;An object with the method include? is required must be supplied as the :in option of the configuration hash&quot;) unless enum.respond_to?(:include?)
 
         validates_each(attr_names, configuration) do |record, attr_name, value|
-          record.errors.add(attr_name, configuration[:message] % value) if enum.include?(value)
+          if enum.include?(value)
+            record.errors.add(attr_name, :exclusion, :default =&gt; configuration[:message], :value =&gt; value) 
+          end
         end
       end
 
@@ -802,12 +899,13 @@ module ActiveRecord
       #   not occur (e.g. &lt;tt&gt;:unless =&gt; :skip_validation&lt;/tt&gt;, or &lt;tt&gt;:unless =&gt; Proc.new { |user| user.signup_step &lt;= 2 }&lt;/tt&gt;).  The
       #   method, proc or string should return or evaluate to a true or false value.
       def validates_associated(*attr_names)
-        configuration = { :message =&gt; ActiveRecord::Errors.default_error_messages[:invalid], :on =&gt; :save }
+        configuration = { :on =&gt; :save }
         configuration.update(attr_names.extract_options!)
 
         validates_each(attr_names, configuration) do |record, attr_name, value|
-          record.errors.add(attr_name, configuration[:message]) unless
-            (value.is_a?(Array) ? value : [value]).inject(true) { |v, r| (r.nil? || r.valid?) &amp;&amp; v }
+          unless (value.is_a?(Array) ? value : [value]).inject(true) { |v, r| (r.nil? || r.valid?) &amp;&amp; v }
+            record.errors.add(attr_name, :invalid, :default =&gt; configuration[:message], :value =&gt; value)
+          end
         end
       end
 
@@ -855,15 +953,15 @@ module ActiveRecord
 
           if configuration[:only_integer]
             unless raw_value.to_s =~ /\A[+-]?\d+\Z/
-              record.errors.add(attr_name, configuration[:message] || ActiveRecord::Errors.default_error_messages[:not_a_number])
+              record.errors.add(attr_name, :not_a_number, :value =&gt; raw_value, :default =&gt; configuration[:message])
               next
             end
             raw_value = raw_value.to_i
           else
-           begin
+            begin
               raw_value = Kernel.Float(raw_value)
             rescue ArgumentError, TypeError
-              record.errors.add(attr_name, configuration[:message] || ActiveRecord::Errors.default_error_messages[:not_a_number])
+              record.errors.add(attr_name, :not_a_number, :value =&gt; raw_value, :default =&gt; configuration[:message])
               next
             end
           end
@@ -871,11 +969,11 @@ module ActiveRecord
           numericality_options.each do |option|
             case option
               when :odd, :even
-                record.errors.add(attr_name, configuration[:message] || ActiveRecord::Errors.default_error_messages[option]) unless raw_value.to_i.method(ALL_NUMERICALITY_CHECKS[option])[]
+                unless raw_value.to_i.method(ALL_NUMERICALITY_CHECKS[option])[]
+                  record.errors.add(attr_name, option, :value =&gt; raw_value, :default =&gt; configuration[:message]) 
+                end
               else
-                message = configuration[:message] || ActiveRecord::Errors.default_error_messages[option]
-                message = message % configuration[option] if configuration[option]
-                record.errors.add(attr_name, message) unless raw_value.method(ALL_NUMERICALITY_CHECKS[option])[configuration[option]]
+                record.errors.add(attr_name, option, :default =&gt; configuration[:message], :value =&gt; raw_value, :count =&gt; configuration[option]) unless raw_value.method(ALL_NUMERICALITY_CHECKS[option])[configuration[option]]
             end
           end
         end
@@ -924,14 +1022,6 @@ module ActiveRecord
       end
     end
 
-    # Updates a single attribute and saves the record without going through the normal validation procedure.
-    # This is especially useful for boolean flags on existing records. The regular +update_attribute+ method
-    # in Base is replaced with this when the validations module is mixed in, which it is by default.
-    def update_attribute_with_validation_skipping(name, value)
-      send(name.to_s + '=', value)
-      save(false)
-    end
-
     # Runs +validate+ and +validate_on_create+ or +validate_on_update+ and returns true if no errors were added otherwise false.
     def valid?
       errors.clear</diff>
      <filename>vendor/activerecord/lib/active_record/validations.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,8 +1,8 @@
 module ActiveRecord
   module VERSION #:nodoc:
     MAJOR = 2
-    MINOR = 1
-    TINY  = 1
+    MINOR = 2
+    TINY  = 2
 
     STRING = [MAJOR, MINOR, TINY].join('.')
   end</diff>
      <filename>vendor/activerecord/lib/active_record/version.rb</filename>
    </modified>
    <modified>
      <diff>@@ -25,6 +25,11 @@ class ActiveSchemaTest &lt; ActiveRecord::TestCase
       assert_equal &quot;CREATE DATABASE `aimonetti` DEFAULT CHARACTER SET `latin1`&quot;, create_database(:aimonetti, {:charset =&gt; 'latin1'})
       assert_equal &quot;CREATE DATABASE `matt_aimonetti` DEFAULT CHARACTER SET `big5` COLLATE `big5_chinese_ci`&quot;, create_database(:matt_aimonetti, {:charset =&gt; :big5, :collation =&gt; :big5_chinese_ci})
     end
+
+    def test_recreate_mysql_database_with_encoding
+      create_database(:luca, {:charset =&gt; 'latin1'})
+      assert_equal &quot;CREATE DATABASE `luca` DEFAULT CHARACTER SET `latin1`&quot;, recreate_database(:luca, {:charset =&gt; 'latin1'})
+    end
   end
 
   def test_add_column</diff>
      <filename>vendor/activerecord/test/cases/active_schema_test_mysql.rb</filename>
    </modified>
    <modified>
      <diff>@@ -65,6 +65,12 @@ class AdapterTest &lt; ActiveRecord::TestCase
     end
   end
 
+  if current_adapter?(:PostgreSQLAdapter)
+    def test_encoding
+      assert_not_nil @connection.encoding
+    end
+  end
+
   def test_table_alias
     def @connection.test_table_alias_length() 10; end
     class &lt;&lt; @connection</diff>
      <filename>vendor/activerecord/test/cases/adapter_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -107,6 +107,45 @@ class AggregationsTest &lt; ActiveRecord::TestCase
     customers(:david).gps_location = nil
     assert_equal nil, customers(:david).gps_location
   end
+
+  def test_custom_constructor
+    assert_equal 'Barney GUMBLE', customers(:barney).fullname.to_s
+    assert_kind_of Fullname, customers(:barney).fullname
+  end
+
+  def test_custom_converter
+    customers(:barney).fullname = 'Barnoit Gumbleau'
+    assert_equal 'Barnoit GUMBLEAU', customers(:barney).fullname.to_s
+    assert_kind_of Fullname, customers(:barney).fullname
+  end
+end
+
+class DeprecatedAggregationsTest &lt; ActiveRecord::TestCase
+  class Person &lt; ActiveRecord::Base; end
+
+  def test_conversion_block_is_deprecated
+    assert_deprecated 'conversion block has been deprecated' do
+      Person.composed_of(:balance, :class_name =&gt; &quot;Money&quot;, :mapping =&gt; %w(balance amount)) { |balance| balance.to_money }
+    end
+  end
+
+  def test_conversion_block_used_when_converter_option_is_nil
+    assert_deprecated 'conversion block has been deprecated' do
+      Person.composed_of(:balance, :class_name =&gt; &quot;Money&quot;, :mapping =&gt; %w(balance amount)) { |balance| balance.to_money }
+    end
+    assert_raise(NoMethodError) { Person.new.balance = 5 }
+  end
+
+  def test_converter_option_overrides_conversion_block
+    assert_deprecated 'conversion block has been deprecated' do
+      Person.composed_of(:balance, :class_name =&gt; &quot;Money&quot;, :mapping =&gt; %w(balance amount), :converter =&gt; Proc.new { |balance| Money.new(balance) }) { |balance| balance.to_money }
+    end
+
+    person = Person.new
+    assert_nothing_raised { person.balance = 5 }
+    assert_equal 5, person.balance.amount
+    assert_kind_of Money, person.balance
+  end
 end
 
 class OverridingAggregationsTest &lt; ActiveRecord::TestCase</diff>
      <filename>vendor/activerecord/test/cases/aggregations_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -428,4 +428,14 @@ class BelongsToAssociationsTest &lt; ActiveRecord::TestCase
     assert log.valid?
     assert log.save
   end
+
+  def test_belongs_to_proxy_should_not_respond_to_private_methods
+    assert_raises(NoMethodError) { companies(:first_firm).private_method }
+    assert_raises(NoMethodError) { companies(:second_client).firm.private_method }
+  end
+
+  def test_belongs_to_proxy_should_respond_to_private_methods_via_send
+    companies(:first_firm).send(:private_method)
+    companies(:second_client).firm.send(:private_method)
+  end
 end</diff>
      <filename>vendor/activerecord/test/cases/associations/belongs_to_associations_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,5 +1,20 @@
 require 'cases/helper'
 
+module Remembered
+  def self.included(base)
+    base.extend ClassMethods
+    base.class_eval do
+      after_create :remember
+    protected
+      def remember; self.class.remembered &lt;&lt; self; end
+    end
+  end
+
+  module ClassMethods
+    def remembered; @@remembered ||= []; end
+    def rand; @@remembered.rand; end
+  end
+end
 
 class ShapeExpression &lt; ActiveRecord::Base
   belongs_to :shape, :polymorphic =&gt; true
@@ -8,26 +23,33 @@ end
 
 class Circle &lt; ActiveRecord::Base
   has_many :shape_expressions, :as =&gt; :shape
+  include Remembered
 end
 class Square &lt; ActiveRecord::Base
   has_many :shape_expressions, :as =&gt; :shape
+  include Remembered
 end
 class Triangle &lt; ActiveRecord::Base
   has_many :shape_expressions, :as =&gt; :shape
+  include Remembered
 end
 class PaintColor  &lt; ActiveRecord::Base
   has_many   :shape_expressions, :as =&gt; :paint
   belongs_to :non_poly, :foreign_key =&gt; &quot;non_poly_one_id&quot;, :class_name =&gt; &quot;NonPolyOne&quot;
+  include Remembered
 end
 class PaintTexture &lt; ActiveRecord::Base
   has_many   :shape_expressions, :as =&gt; :paint
   belongs_to :non_poly, :foreign_key =&gt; &quot;non_poly_two_id&quot;, :class_name =&gt; &quot;NonPolyTwo&quot;
+  include Remembered
 end
 class NonPolyOne &lt; ActiveRecord::Base
   has_many :paint_colors
+  include Remembered
 end
 class NonPolyTwo &lt; ActiveRecord::Base
   has_many :paint_textures
+  include Remembered
 end
 
 
@@ -49,23 +71,19 @@ class EagerLoadPolyAssocsTest &lt; ActiveRecord::TestCase
   end
 
 
-  # meant to be supplied as an ID, never returns 0
-  def rand_simple
-    val = (NUM_SIMPLE_OBJS * rand).round
-    val == 0 ? 1 : val
-  end
-
   def generate_test_object_graphs
     1.upto(NUM_SIMPLE_OBJS) do
       [Circle, Square, Triangle, NonPolyOne, NonPolyTwo].map(&amp;:create!)
     end
-    1.upto(NUM_SIMPLE_OBJS) do |i|
-      PaintColor.create!(:non_poly_one_id =&gt; rand_simple)
-      PaintTexture.create!(:non_poly_two_id =&gt; rand_simple)
+    1.upto(NUM_SIMPLE_OBJS) do
+      PaintColor.create!(:non_poly_one_id =&gt; NonPolyOne.rand.id)
+      PaintTexture.create!(:non_poly_two_id =&gt; NonPolyTwo.rand.id)
     end
-    1.upto(NUM_SHAPE_EXPRESSIONS) do |i|
-      ShapeExpression.create!(:shape_type =&gt; [Circle, Square, Triangle].rand.to_s, :shape_id =&gt; rand_simple,
-                              :paint_type =&gt; [PaintColor, PaintTexture].rand.to_s, :paint_id =&gt; rand_simple)
+    1.upto(NUM_SHAPE_EXPRESSIONS) do
+      shape_type = [Circle, Square, Triangle].rand
+      paint_type = [PaintColor, PaintTexture].rand
+      ShapeExpression.create!(:shape_type =&gt; shape_type.to_s, :shape_id =&gt; shape_type.rand.id,
+                              :paint_type =&gt; paint_type.to_s, :paint_id =&gt; paint_type.rand.id)
     end
   end
 </diff>
      <filename>vendor/activerecord/test/cases/associations/eager_load_nested_include_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -18,7 +18,7 @@ require 'models/developer'
 require 'models/project'
 
 class EagerAssociationTest &lt; ActiveRecord::TestCase
-  fixtures :posts, :comments, :authors, :categories, :categories_posts,
+  fixtures :posts, :comments, :authors, :author_addresses, :categories, :categories_posts,
             :companies, :accounts, :tags, :taggings, :people, :readers,
             :owners, :pets, :author_favorites, :jobs, :references, :subscribers, :subscriptions, :books,
             :developers, :projects, :developers_projects
@@ -111,11 +111,58 @@ class EagerAssociationTest &lt; ActiveRecord::TestCase
     end
   end
 
+  def test_finding_with_includes_on_has_many_association_with_same_include_includes_only_once
+    author_id = authors(:david).id
+    author = assert_queries(3) { Author.find(author_id, :include =&gt; {:posts_with_comments =&gt; :comments}) } # find the author, then find the posts, then find the comments
+    author.posts_with_comments.each do |post_with_comments|
+      assert_equal post_with_comments.comments.length, post_with_comments.comments.count
+      assert_equal nil, post_with_comments.comments.uniq!
+    end
+  end
+
+  def test_finding_with_includes_on_has_one_assocation_with_same_include_includes_only_once
+    author = authors(:david)
+    post = author.post_about_thinking_with_last_comment
+    last_comment = post.last_comment
+    author = assert_queries(3) { Author.find(author.id, :include =&gt; {:post_about_thinking_with_last_comment =&gt; :last_comment})} # find the author, then find the posts, then find the comments
+    assert_no_queries do
+      assert_equal post, author.post_about_thinking_with_last_comment
+      assert_equal last_comment, author.post_about_thinking_with_last_comment.last_comment
+    end
+  end
+
+  def test_finding_with_includes_on_belongs_to_association_with_same_include_includes_only_once
+    post = posts(:welcome)
+    author = post.author
+    author_address = author.author_address
+    post = assert_queries(3) { Post.find(post.id, :include =&gt; {:author_with_address =&gt; :author_address}) } # find the post, then find the author, then find the address
+    assert_no_queries do
+      assert_equal author, post.author_with_address
+      assert_equal author_address, post.author_with_address.author_address
+    end
+  end
+
+  def test_finding_with_includes_on_null_belongs_to_association_with_same_include_includes_only_once
+    post = posts(:welcome)
+    post.update_attributes!(:author =&gt; nil)
+    post = assert_queries(2) { Post.find(post.id, :include =&gt; {:author_with_address =&gt; :author_address}) } # find the post, then find the author which is null so no query for the address
+    assert_no_queries do
+      assert_equal nil, post.author_with_address
+    end
+  end
+
   def test_loading_from_an_association
     posts = authors(:david).posts.find(:all, :include =&gt; :comments, :order =&gt; &quot;posts.id&quot;)
     assert_equal 2, posts.first.comments.size
   end
 
+  def test_loading_from_an_association_that_has_a_hash_of_conditions
+    assert_nothing_raised do
+      Author.find(:all, :include =&gt; :hello_posts_with_hash_conditions)
+    end
+    assert !Author.find(authors(:david).id, :include =&gt; :hello_posts_with_hash_conditions).hello_posts.empty?
+  end
+
   def test_loading_with_no_associations
     assert_nil Post.find(posts(:authorless).id, :include =&gt; :author).author
   end
@@ -260,14 +307,23 @@ class EagerAssociationTest &lt; ActiveRecord::TestCase
   end
 
   def test_eager_with_has_many_through
-    posts_with_comments = people(:michael).posts.find(:all, :include =&gt; :comments)
-    posts_with_author = people(:michael).posts.find(:all, :include =&gt; :author )
-    posts_with_comments_and_author = people(:michael).posts.find(:all, :include =&gt; [ :comments, :author ])
+    posts_with_comments = people(:michael).posts.find(:all, :include =&gt; :comments, :order =&gt; 'posts.id')
+    posts_with_author = people(:michael).posts.find(:all, :include =&gt; :author, :order =&gt; 'posts.id')
+    posts_with_comments_and_author = people(:michael).posts.find(:all, :include =&gt; [ :comments, :author ], :order =&gt; 'posts.id')
     assert_equal 2, posts_with_comments.inject(0) { |sum, post| sum += post.comments.size }
     assert_equal authors(:david), assert_no_queries { posts_with_author.first.author }
     assert_equal authors(:david), assert_no_queries { posts_with_comments_and_author.first.author }
   end
 
+  def test_eager_with_has_many_through_a_belongs_to_association
+    author = authors(:mary)
+    post = Post.create!(:author =&gt; author, :title =&gt; &quot;TITLE&quot;, :body =&gt; &quot;BODY&quot;)
+    author.author_favorites.create(:favorite_author_id =&gt; 1)
+    author.author_favorites.create(:favorite_author_id =&gt; 2)
+    posts_with_author_favorites = author.posts.find(:all, :include =&gt; :author_favorites)
+    assert_no_queries { posts_with_author_favorites.first.author_favorites.first.author_id }
+  end
+
   def test_eager_with_has_many_through_an_sti_join_model
     author = Author.find(:first, :include =&gt; :special_post_comments, :order =&gt; 'authors.id')
     assert_equal [comments(:does_it_hurt)], assert_no_queries { author.special_post_comments }
@@ -611,7 +667,7 @@ class EagerAssociationTest &lt; ActiveRecord::TestCase
   end
 
   def test_count_with_include
-    if current_adapter?(:SQLServerAdapter, :SybaseAdapter)
+    if current_adapter?(:SybaseAdapter)
       assert_equal 3, authors(:david).posts_with_comments.count(:conditions =&gt; &quot;len(comments.body) &gt; 15&quot;)
     elsif current_adapter?(:OpenBaseAdapter)
       assert_equal 3, authors(:david).posts_with_comments.count(:conditions =&gt; &quot;length(FETCHBLOB(comments.body)) &gt; 15&quot;)</diff>
      <filename>vendor/activerecord/test/cases/associations/eager_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -3,6 +3,7 @@ require 'models/post'
 require 'models/comment'
 require 'models/project'
 require 'models/developer'
+require 'models/company_in_module'
 
 class AssociationsExtensionsTest &lt; ActiveRecord::TestCase
   fixtures :projects, :developers, :developers_projects, :comments, :posts
@@ -44,4 +45,18 @@ class AssociationsExtensionsTest &lt; ActiveRecord::TestCase
     david = Marshal.load(Marshal.dump(david))
     assert_equal projects(:action_controller), david.projects_extended_by_name.find_most_recent
   end
+
+
+	def test_extension_name
+	  extension = Proc.new {}
+	  name = :association_name
+
+	  assert_equal 'DeveloperAssociationNameAssociationExtension', Developer.send(:create_extension_modules, name, extension, []).first.name
+	  assert_equal 'MyApplication::Business::DeveloperAssociationNameAssociationExtension',
+MyApplication::Business::Developer.send(:create_extension_modules, name, extension, []).first.name
+    assert_equal 'MyApplication::Business::DeveloperAssociationNameAssociationExtension', MyApplication::Business::Developer.send(:create_extension_modules, name, extension, []).first.name
+    assert_equal 'MyApplication::Business::DeveloperAssociationNameAssociationExtension', MyApplication::Business::Developer.send(:create_extension_modules, name, extension, []).first.name
+  end
+
+
 end</diff>
      <filename>vendor/activerecord/test/cases/associations/extension_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -68,6 +68,16 @@ class DeveloperWithSymbolsForKeys &lt; ActiveRecord::Base
     :foreign_key =&gt; &quot;developer_id&quot;
 end
 
+class DeveloperWithCounterSQL &lt; ActiveRecord::Base
+  set_table_name 'developers'
+  has_and_belongs_to_many :projects,
+    :class_name =&gt; &quot;DeveloperWithCounterSQL&quot;,
+    :join_table =&gt; &quot;developers_projects&quot;,
+    :association_foreign_key =&gt; &quot;project_id&quot;,
+    :foreign_key =&gt; &quot;developer_id&quot;,
+    :counter_sql =&gt; 'SELECT COUNT(*) AS count_all FROM projects INNER JOIN developers_projects ON projects.id = developers_projects.project_id WHERE developers_projects.developer_id =#{id}'
+end
+
 class HasAndBelongsToManyAssociationsTest &lt; ActiveRecord::TestCase
   fixtures :accounts, :companies, :categories, :posts, :categories_posts, :developers, :projects, :developers_projects,
            :parrots, :pirates, :treasures, :price_estimates, :tags, :taggings
@@ -223,10 +233,10 @@ class HasAndBelongsToManyAssociationsTest &lt; ActiveRecord::TestCase
     devel = Developer.find(1)
     proj = assert_no_queries { devel.projects.build(&quot;name&quot; =&gt; &quot;Projekt&quot;) }
     assert !devel.projects.loaded?
-    
+
     assert_equal devel.projects.last, proj
     assert devel.projects.loaded?
-    
+
     assert proj.new_record?
     devel.save
     assert !proj.new_record?
@@ -251,10 +261,10 @@ class HasAndBelongsToManyAssociationsTest &lt; ActiveRecord::TestCase
     devel = Developer.find(1)
     proj = devel.projects.create(&quot;name&quot; =&gt; &quot;Projekt&quot;)
     assert !devel.projects.loaded?
-    
+
     assert_equal devel.projects.last, proj
-    assert devel.projects.loaded?
-    
+    assert !devel.projects.loaded?
+
     assert !proj.new_record?
     assert_equal Developer.find(1).projects.sort_by(&amp;:id).last, proj  # prove join table is updated
   end
@@ -274,10 +284,10 @@ class HasAndBelongsToManyAssociationsTest &lt; ActiveRecord::TestCase
 
   def test_creation_respects_hash_condition
     post = categories(:general).post_with_conditions.build(:body =&gt; '')
-    
+
     assert        post.save
     assert_equal  'Yet Another Testing Title', post.title
-    
+
     another_post = categories(:general).post_with_conditions.create(:body =&gt; '')
 
     assert        !another_post.new_record?
@@ -288,7 +298,7 @@ class HasAndBelongsToManyAssociationsTest &lt; ActiveRecord::TestCase
     dev = developers(:jamis)
     dev.projects &lt;&lt; projects(:active_record)
     dev.projects &lt;&lt; projects(:active_record)
-    
+
     assert_equal 3, dev.projects.size
     assert_equal 1, dev.projects.uniq.size
   end
@@ -415,13 +425,13 @@ class HasAndBelongsToManyAssociationsTest &lt; ActiveRecord::TestCase
     project.developers.class # force load target
 
     developer = project.developers.first
-    
+
     assert_no_queries do
       assert project.developers.loaded?
       assert project.developers.include?(developer)
     end
   end
-  
+
   def test_include_checks_if_record_exists_if_target_not_loaded
     project = projects(:active_record)
     developer = project.developers.first
@@ -636,11 +646,39 @@ class HasAndBelongsToManyAssociationsTest &lt; ActiveRecord::TestCase
     assert_equal 3, Developer.find(:all, :include =&gt; {:projects =&gt; :developers}, :conditions =&gt; 'developers_projects_join.joined_on IS NOT NULL', :group =&gt; group.join(&quot;,&quot;)).size
   end
 
+  def test_find_grouped
+    all_posts_from_category1 = Post.find(:all, :conditions =&gt; &quot;category_id = 1&quot;, :joins =&gt; :categories)
+    grouped_posts_of_category1 = Post.find(:all, :conditions =&gt; &quot;category_id = 1&quot;, :group =&gt; &quot;author_id&quot;, :select =&gt; 'count(posts.id) as posts_count', :joins =&gt; :categories)
+    assert_equal 4, all_posts_from_category1.size
+    assert_equal 1, grouped_posts_of_category1.size
+  end
+
+  def test_find_scoped_grouped
+    assert_equal 4, categories(:general).posts_gruoped_by_title.size
+    assert_equal 1, categories(:technology).posts_gruoped_by_title.size
+  end
+
   def test_get_ids
     assert_equal projects(:active_record, :action_controller).map(&amp;:id).sort, developers(:david).project_ids.sort
     assert_equal [projects(:active_record).id], developers(:jamis).project_ids
   end
 
+  def test_get_ids_for_loaded_associations
+    developer = developers(:david)
+    developer.projects(true)
+    assert_queries(0) do
+      developer.project_ids
+      developer.project_ids
+    end
+  end
+
+  def test_get_ids_for_unloaded_associations_does_not_load_them
+    developer = developers(:david)
+    assert !developer.projects.loaded?
+    assert_equal projects(:active_record, :action_controller).map(&amp;:id).sort, developer.project_ids.sort
+    assert !developer.projects.loaded?
+  end
+
   def test_assign_ids
     developer = Developer.new(&quot;name&quot; =&gt; &quot;Joe&quot;)
     developer.project_ids = projects(:active_record, :action_controller).map(&amp;:id)
@@ -703,4 +741,33 @@ class HasAndBelongsToManyAssociationsTest &lt; ActiveRecord::TestCase
     # due to Unknown column 'authors.id'
     assert Category.find(1).posts_with_authors_sorted_by_author_id.find_by_title('Welcome to the weblog')
   end
+
+  def test_counting_on_habtm_association_and_not_array
+    david = Developer.find(1)
+    # Extra parameter just to make sure we aren't falling back to
+    # Array#count in Ruby &gt;=1.8.7, which would raise an ArgumentError
+    assert_nothing_raised { david.projects.count(:all, :conditions =&gt; '1=1') }
+  end
+
+  def test_count
+    david = Developer.find(1)
+    assert_equal 2, david.projects.count
+  end
+
+  def test_count_with_counter_sql
+    developer  = DeveloperWithCounterSQL.create(:name =&gt; 'tekin')
+    developer.project_ids = [projects(:active_record).id]
+    developer.save
+    developer.reload
+    assert_equal 1, developer.projects.count
+  end
+
+  uses_mocha 'mocking Post.transaction' do
+    def test_association_proxy_transaction_method_starts_transaction_in_association_class
+      Post.expects(:transaction)
+      Category.find(:first).posts.transaction do
+        # nothing
+      end
+    end
+  end
 end</diff>
      <filename>vendor/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -135,6 +135,10 @@ class HasManyAssociationsTest &lt; ActiveRecord::TestCase
     assert_equal &quot;Microsoft&quot;, Firm.find(:first).clients_like_ms_with_hash_conditions.first.name
   end
 
+  def test_finding_using_primary_key
+    assert_equal &quot;Summit&quot;, Firm.find(:first).clients_using_primary_key.first.name
+  end
+
   def test_finding_using_sql
     firm = Firm.find(:first)
     first_client = firm.clients_using_sql.first
@@ -244,6 +248,13 @@ class HasManyAssociationsTest &lt; ActiveRecord::TestCase
     assert_equal 1, grouped_clients_of_firm1.size
   end
 
+  def test_find_scoped_grouped
+    assert_equal 1, companies(:first_firm).clients_grouped_by_firm_id.size
+    assert_equal 1, companies(:first_firm).clients_grouped_by_firm_id.length
+    assert_equal 2, companies(:first_firm).clients_grouped_by_name.size
+    assert_equal 2, companies(:first_firm).clients_grouped_by_name.length
+  end
+
   def test_adding
     force_signal37_to_load_all_clients_of_firm
     natural = Client.new(&quot;name&quot; =&gt; &quot;Natural Company&quot;)
@@ -380,7 +391,7 @@ class HasManyAssociationsTest &lt; ActiveRecord::TestCase
     company = companies(:first_firm)
     new_client = assert_no_queries { company.clients_of_firm.build(&quot;name&quot; =&gt; &quot;Another Client&quot;) }
     assert !company.clients_of_firm.loaded?
-    
+
     assert_equal &quot;Another Client&quot;, new_client.name
     assert new_client.new_record?
     assert_equal new_client, company.clients_of_firm.last
@@ -412,7 +423,7 @@ class HasManyAssociationsTest &lt; ActiveRecord::TestCase
   def test_build_many
     company = companies(:first_firm)
     new_clients = assert_no_queries { company.clients_of_firm.build([{&quot;name&quot; =&gt; &quot;Another Client&quot;}, {&quot;name&quot; =&gt; &quot;Another Client II&quot;}]) }
-    
+
     assert_equal 2, new_clients.size
     company.name += '-changed'
     assert_queries(3) { assert company.save }
@@ -651,10 +662,10 @@ class HasManyAssociationsTest &lt; ActiveRecord::TestCase
 
   def test_creation_respects_hash_condition
     ms_client = companies(:first_firm).clients_like_ms_with_hash_conditions.build
-    
+
     assert        ms_client.save
     assert_equal  'Microsoft', ms_client.name
-    
+
     another_ms_client = companies(:first_firm).clients_like_ms_with_hash_conditions.create
 
     assert        !another_ms_client.new_record?
@@ -826,6 +837,29 @@ class HasManyAssociationsTest &lt; ActiveRecord::TestCase
     assert_equal [companies(:first_client).id, companies(:second_client).id], companies(:first_firm).client_ids
   end
 
+  def test_get_ids_for_loaded_associations
+    company = companies(:first_firm)
+    company.clients(true)
+    assert_queries(0) do
+      company.client_ids
+      company.client_ids
+    end
+  end
+
+  def test_get_ids_for_unloaded_associations_does_not_load_them
+    company = companies(:first_firm)
+    assert !company.clients.loaded?
+    assert_equal [companies(:first_client).id, companies(:second_client).id], company.client_ids
+    assert !company.clients.loaded?
+  end
+
+  def test_get_ids_for_unloaded_finder_sql_associations_loads_them
+    company = companies(:first_firm)
+    assert !company.clients_using_sql.loaded?
+    assert_equal [companies(:second_client).id], company.clients_using_sql_ids
+    assert company.clients_using_sql.loaded?
+  end
+
   def test_assign_ids
     firm = Firm.new(&quot;name&quot; =&gt; &quot;Apple&quot;)
     firm.client_ids = [companies(:first_client).id, companies(:second_client).id]
@@ -896,7 +930,7 @@ class HasManyAssociationsTest &lt; ActiveRecord::TestCase
     assert_equal 4, authors(:david).limited_comments.find(:all, :conditions =&gt; &quot;comments.type = 'SpecialComment'&quot;, :limit =&gt; 9_000).length
     assert_equal 4, authors(:david).limited_comments.find_all_by_type('SpecialComment', :limit =&gt; 9_000).length
   end
-  
+
   def test_find_all_include_over_the_same_table_for_through
     assert_equal 2, people(:michael).posts.find(:all, :include =&gt; :people).length
   end
@@ -933,13 +967,13 @@ class HasManyAssociationsTest &lt; ActiveRecord::TestCase
   def test_include_loads_collection_if_target_uses_finder_sql
     firm = companies(:first_firm)
     client = firm.clients_using_sql.first
-    
+
     firm.reload
     assert ! firm.clients_using_sql.loaded?
     assert firm.clients_using_sql.include?(client)
     assert firm.clients_using_sql.loaded?
   end
-  
+
 
   def test_include_returns_false_for_non_matching_record_to_verify_scoping
     firm = companies(:first_firm)
@@ -982,6 +1016,19 @@ class HasManyAssociationsTest &lt; ActiveRecord::TestCase
     assert firm.clients.loaded?
   end
 
+  def test_calling_first_or_last_on_existing_record_with_create_should_not_load_association
+    firm = companies(:first_firm)
+    firm.clients.create(:name =&gt; 'Foo')
+    assert !firm.clients.loaded?
+
+    assert_queries 2 do
+      firm.clients.first
+      firm.clients.last
+    end
+
+    assert !firm.clients.loaded?
+  end
+
   def test_calling_first_or_last_on_new_record_should_not_run_queries
     firm = Firm.new
 
@@ -1031,4 +1078,24 @@ class HasManyAssociationsTest &lt; ActiveRecord::TestCase
     ActiveRecord::Base.store_full_sti_class = old
   end
 
+  uses_mocha 'mocking Comment.transaction' do
+    def test_association_proxy_transaction_method_starts_transaction_in_association_class
+      Comment.expects(:transaction)
+      Post.find(:first).comments.transaction do
+        # nothing
+      end
+    end
+  end
+
+  def test_sending_new_to_association_proxy_should_have_same_effect_as_calling_new
+    client_association = companies(:first_firm).clients
+    assert_equal client_association.new.attributes, client_association.send(:new).attributes
+  end
+
+  def test_respond_to_private_class_methods
+    client_association = companies(:first_firm).clients
+    assert !client_association.respond_to?(:private_method)
+    assert client_association.respond_to?(:private_method, true)
+  end
 end
+</diff>
      <filename>vendor/activerecord/test/cases/associations/has_many_associations_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -2,15 +2,18 @@ require &quot;cases/helper&quot;
 require 'models/post'
 require 'models/person'
 require 'models/reader'
+require 'models/comment'
 
 class HasManyThroughAssociationsTest &lt; ActiveRecord::TestCase
-  fixtures :posts, :readers, :people
+  fixtures :posts, :readers, :people, :comments, :authors
 
   def test_associate_existing
     assert_queries(2) { posts(:thinking);people(:david) }
-    
+
+    posts(:thinking).people
+
     assert_queries(1) do
-       posts(:thinking).people &lt;&lt; people(:david)
+      posts(:thinking).people &lt;&lt; people(:david)
     end
     
     assert_queries(1) do
@@ -197,4 +200,48 @@ class HasManyThroughAssociationsTest &lt; ActiveRecord::TestCase
   def test_count_with_include_should_alias_join_table
     assert_equal 2, people(:michael).posts.count(:include =&gt; :readers)
   end
+
+  def test_get_ids
+    assert_equal [posts(:welcome).id, posts(:authorless).id].sort, people(:michael).post_ids.sort
+  end
+
+  def test_get_ids_for_loaded_associations
+    person = people(:michael)
+    person.posts(true)
+    assert_queries(0) do
+      person.post_ids
+      person.post_ids
+    end
+  end
+
+  def test_get_ids_for_unloaded_associations_does_not_load_them
+    person = people(:michael)
+    assert !person.posts.loaded?
+    assert_equal [posts(:welcome).id, posts(:authorless).id].sort, person.post_ids.sort
+    assert !person.posts.loaded?
+  end
+
+  uses_mocha 'mocking Tag.transaction' do
+    def test_association_proxy_transaction_method_starts_transaction_in_association_class
+      Tag.expects(:transaction)
+      Post.find(:first).tags.transaction do
+        # nothing
+      end
+    end
+  end
+
+  def test_has_many_association_through_a_belongs_to_association_where_the_association_doesnt_exist
+    author = authors(:mary)
+    post = Post.create!(:title =&gt; &quot;TITLE&quot;, :body =&gt; &quot;BODY&quot;)
+    assert_equal [], post.author_favorites
+  end
+
+  def test_has_many_association_through_a_belongs_to_association
+    author = authors(:mary)
+    post = Post.create!(:author =&gt; author, :title =&gt; &quot;TITLE&quot;, :body =&gt; &quot;BODY&quot;)
+    author.author_favorites.create(:favorite_author_id =&gt; 1)
+    author.author_favorites.create(:favorite_author_id =&gt; 2)
+    author.author_favorites.create(:favorite_author_id =&gt; 3)
+    assert_equal post.author.author_favorites, post.author_favorites
+  end
 end</diff>
      <filename>vendor/activerecord/test/cases/associations/has_many_through_associations_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -29,6 +29,13 @@ class HasOneAssociationsTest &lt; ActiveRecord::TestCase
     assert_equal Firm.find(1, :include =&gt; :account_with_select).account_with_select.attributes.size, 2
   end
 
+  def test_finding_using_primary_key
+    firm = companies(:first_firm)
+    assert_equal Account.find_by_firm_id(firm.id), firm.account
+    firm.firm_id = companies(:rails_core).id
+    assert_equal accounts(:rails_core_account), firm.account_using_primary_key
+  end
+
   def test_can_marshal_has_one_association_with_nil_target
     firm = Firm.new
     assert_nothing_raised do
@@ -342,4 +349,14 @@ class HasOneAssociationsTest &lt; ActiveRecord::TestCase
     assert companies(:first_firm).readonly_account.readonly?
   end
 
+  def test_has_one_proxy_should_not_respond_to_private_methods
+    assert_raises(NoMethodError) { accounts(:signals37).private_method }
+    assert_raises(NoMethodError) { companies(:first_firm).account.private_method }
+  end
+
+  def test_has_one_proxy_should_respond_to_private_methods_via_send
+    accounts(:signals37).send(:private_method)
+    companies(:first_firm).account.send(:private_method)
+  end
+
 end</diff>
      <filename>vendor/activerecord/test/cases/associations/has_one_associations_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -3,9 +3,11 @@ require 'models/club'
 require 'models/member'
 require 'models/membership'
 require 'models/sponsor'
+require 'models/organization'
+require 'models/member_detail'
 
 class HasOneThroughAssociationsTest &lt; ActiveRecord::TestCase
-  fixtures :members, :clubs, :memberships, :sponsors
+  fixtures :members, :clubs, :memberships, :sponsors, :organizations
   
   def setup
     @member = members(:groucho)
@@ -110,4 +112,50 @@ class HasOneThroughAssociationsTest &lt; ActiveRecord::TestCase
     new_member.club = new_club = Club.create(:name =&gt; &quot;LRUG&quot;)
     assert_equal new_club, new_member.club.target
   end
+
+  def test_has_one_through_proxy_should_not_respond_to_private_methods
+    assert_raises(NoMethodError) { clubs(:moustache_club).private_method }
+    assert_raises(NoMethodError) { @member.club.private_method }
+  end
+
+  def test_has_one_through_proxy_should_respond_to_private_methods_via_send
+    clubs(:moustache_club).send(:private_method)
+    @member.club.send(:private_method)
+  end
+
+  def test_assigning_to_has_one_through_preserves_decorated_join_record
+    @organization = organizations(:nsa)
+    assert_difference 'MemberDetail.count', 1 do
+      @member_detail = MemberDetail.new(:extra_data =&gt; 'Extra')
+      @member.member_detail = @member_detail
+      @member.organization = @organization
+    end
+    assert_equal @organization, @member.organization
+    assert @organization.members.include?(@member)
+    assert_equal 'Extra', @member.member_detail.extra_data
+  end
+
+  def test_reassigning_has_one_through
+    @organization = organizations(:nsa)
+    @new_organization = organizations(:discordians)
+
+    assert_difference 'MemberDetail.count', 1 do
+      @member_detail = MemberDetail.new(:extra_data =&gt; 'Extra')
+      @member.member_detail = @member_detail
+      @member.organization = @organization
+    end
+    assert_equal @organization, @member.organization
+    assert_equal 'Extra', @member.member_detail.extra_data
+    assert @organization.members.include?(@member)
+    assert !@new_organization.members.include?(@member)
+
+    assert_no_difference 'MemberDetail.count' do
+      @member.organization = @new_organization
+    end
+    assert_equal @new_organization, @member.organization
+    assert_equal 'Extra', @member.member_detail.extra_data
+    assert !@organization.members.include?(@member)
+    assert @new_organization.members.include?(@member)
+  end
+
 end</diff>
      <filename>vendor/activerecord/test/cases/associations/has_one_through_associations_test.rb</filename>
    </modified>
    <modified>
      <filename>vendor/activerecord/test/cases/associations_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,5 +1,6 @@
 require &quot;cases/helper&quot;
 require 'models/topic'
+require 'models/minimalistic'
 
 class AttributeMethodsTest &lt; ActiveRecord::TestCase
   fixtures :topics
@@ -57,19 +58,19 @@ class AttributeMethodsTest &lt; ActiveRecord::TestCase
 
   def test_kernel_methods_not_implemented_in_activerecord
     %w(test name display y).each do |method|
-      assert_equal false, ActiveRecord::Base.instance_method_already_implemented?(method), &quot;##{method} is defined&quot;
+      assert !ActiveRecord::Base.instance_method_already_implemented?(method), &quot;##{method} is defined&quot;
     end
   end
 
   def test_primary_key_implemented
-    assert_equal true, Class.new(ActiveRecord::Base).instance_method_already_implemented?('id')
+    assert Class.new(ActiveRecord::Base).instance_method_already_implemented?('id')
   end
 
   def test_defined_kernel_methods_implemented_in_model
     %w(test name display y).each do |method|
       klass = Class.new ActiveRecord::Base
       klass.class_eval &quot;def #{method}() 'defined #{method}' end&quot;
-      assert_equal true, klass.instance_method_already_implemented?(method), &quot;##{method} is not defined&quot;
+      assert klass.instance_method_already_implemented?(method), &quot;##{method} is not defined&quot;
     end
   end
 
@@ -79,7 +80,7 @@ class AttributeMethodsTest &lt; ActiveRecord::TestCase
       abstract.class_eval &quot;def #{method}() 'defined #{method}' end&quot;
       abstract.abstract_class = true
       klass = Class.new abstract
-      assert_equal true, klass.instance_method_already_implemented?(method), &quot;##{method} is not defined&quot;
+      assert klass.instance_method_already_implemented?(method), &quot;##{method} is not defined&quot;
     end
   end
 
@@ -219,6 +220,51 @@ class AttributeMethodsTest &lt; ActiveRecord::TestCase
     end
   end
 
+  def test_setting_time_zone_conversion_for_attributes_should_write_value_on_class_variable
+    Topic.skip_time_zone_conversion_for_attributes = [:field_a]
+    Minimalistic.skip_time_zone_conversion_for_attributes = [:field_b]
+    
+    assert_equal [:field_a], Topic.skip_time_zone_conversion_for_attributes 
+    assert_equal [:field_b], Minimalistic.skip_time_zone_conversion_for_attributes 
+  end
+
+  def test_read_attributes_respect_access_control
+    privatize(&quot;title&quot;)
+
+    topic = @target.new(:title =&gt; &quot;The pros and cons of programming naked.&quot;)
+    assert !topic.respond_to?(:title)
+    exception = assert_raise(NoMethodError) { topic.title }
+    assert_equal &quot;Attempt to call private method&quot;, exception.message
+    assert_equal &quot;I'm private&quot;, topic.send(:title)
+  end
+
+  def test_write_attributes_respect_access_control
+    privatize(&quot;title=(value)&quot;)
+
+    topic = @target.new
+    assert !topic.respond_to?(:title=)
+    exception = assert_raise(NoMethodError) { topic.title = &quot;Pants&quot;}
+    assert_equal &quot;Attempt to call private method&quot;, exception.message
+    topic.send(:title=, &quot;Very large pants&quot;)
+  end
+
+  def test_question_attributes_respect_access_control
+    privatize(&quot;title?&quot;)
+
+    topic = @target.new(:title =&gt; &quot;Isaac Newton's pants&quot;)
+    assert !topic.respond_to?(:title?)
+    exception = assert_raise(NoMethodError) { topic.title? }
+    assert_equal &quot;Attempt to call private method&quot;, exception.message
+    assert topic.send(:title?)
+  end
+
+  def test_bulk_update_respects_access_control
+    privatize(&quot;title=(value)&quot;)
+
+    assert_raise(ActiveRecord::UnknownAttributeError) { topic = @target.new(:title =&gt; &quot;Rants about pants&quot;) }
+    assert_raise(ActiveRecord::UnknownAttributeError) { @target.new.attributes = { :title =&gt; &quot;Ants in pants&quot; } }
+  end
+
   private
   def time_related_columns_on_topic
     Topic.columns.select{|c| [:time, :date, :datetime, :timestamp].include?(c.type)}.map(&amp;:name)
@@ -235,4 +281,13 @@ class AttributeMethodsTest &lt; ActiveRecord::TestCase
     Time.zone = old_zone
     ActiveRecord::Base.time_zone_aware_attributes = old_tz
   end
+
+  def privatize(method_signature)
+    @target.class_eval &lt;&lt;-private_method
+      private
+      def #{method_signature}
+        &quot;I'm private&quot;
+      end
+    private_method
+  end
 end</diff>
      <filename>vendor/activerecord/test/cases/attribute_methods_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -76,7 +76,7 @@ class TopicWithProtectedContentAndAccessibleAuthorName &lt; ActiveRecord::Base
 end
 
 class BasicsTest &lt; ActiveRecord::TestCase
-  fixtures :topics, :companies, :developers, :projects, :computers, :accounts, :minimalistics, 'warehouse-things', :authors, :categorizations, :categories
+  fixtures :topics, :companies, :developers, :projects, :computers, :accounts, :minimalistics, 'warehouse-things', :authors, :categorizations, :categories, :posts
 
   def test_table_exists
     assert !NonExistentTable.table_exists?
@@ -138,7 +138,7 @@ class BasicsTest &lt; ActiveRecord::TestCase
   if current_adapter?(:MysqlAdapter)
     def test_read_attributes_before_type_cast_on_boolean
       bool = Booleantest.create({ &quot;value&quot; =&gt; false })
-      assert_equal 0, bool.attributes_before_type_cast[&quot;value&quot;]
+      assert_equal &quot;0&quot;, bool.reload.attributes_before_type_cast[&quot;value&quot;]
     end
   end
 
@@ -428,9 +428,6 @@ class BasicsTest &lt; ActiveRecord::TestCase
   end
 
   def test_preserving_date_objects
-    # SQL Server doesn't have a separate column type just for dates, so all are returned as time
-    return true if current_adapter?(:SQLServerAdapter)
-
     if current_adapter?(:SybaseAdapter, :OracleAdapter)
       # Sybase ctlib does not (yet?) support the date type; use datetime instead.
       # Oracle treats all dates/times as Time.
@@ -472,6 +469,18 @@ class BasicsTest &lt; ActiveRecord::TestCase
     assert topic.instance_variable_get(&quot;@custom_approved&quot;)
   end
 
+  def test_delete
+    topic = Topic.find(1)
+    assert_equal topic, topic.delete, 'topic.delete did not return self'
+    assert topic.frozen?, 'topic not frozen after delete'
+    assert_raise(ActiveRecord::RecordNotFound) { Topic.find(topic.id) }
+  end
+
+  def test_delete_doesnt_run_callbacks
+    Topic.find(1).delete
+    assert_not_nil Topic.find(2)
+  end
+
   def test_destroy
     topic = Topic.find(1)
     assert_equal topic, topic.destroy, 'topic.destroy did not return self'
@@ -664,10 +673,21 @@ class BasicsTest &lt; ActiveRecord::TestCase
     end
   end
 
-  def test_update_all_ignores_order_limit_from_association
-    author = Author.find(1)
+  def test_update_all_ignores_order_without_limit_from_association
+    author = authors(:david)
+    assert_nothing_raised do
+      assert_equal author.posts_with_comments_and_categories.length, author.posts_with_comments_and_categories.update_all([ &quot;body = ?&quot;, &quot;bulk update!&quot; ])
+    end
+  end
+
+  def test_update_all_with_order_and_limit_updates_subset_only
+    author = authors(:david)
     assert_nothing_raised do
-      assert_equal author.posts_with_comments_and_categories.length, author.posts_with_comments_and_categories.update_all(&quot;body = 'bulk update!'&quot;)
+      assert_equal 1, author.posts_sorted_by_id_limited.size
+      assert_equal 2, author.posts_sorted_by_id_limited.find(:all, :limit =&gt; 2).size
+      assert_equal 1, author.posts_sorted_by_id_limited.update_all([ &quot;body = ?&quot;, &quot;bulk update!&quot; ])
+      assert_equal &quot;bulk update!&quot;, posts(:welcome).body
+      assert_not_equal &quot;bulk update!&quot;, posts(:thinking).body
     end
   end
 
@@ -754,8 +774,8 @@ class BasicsTest &lt; ActiveRecord::TestCase
     end
   end
 
-  # Oracle, SQLServer, and Sybase do not have a TIME datatype.
-  unless current_adapter?(:SQLServerAdapter, :OracleAdapter, :SybaseAdapter)
+  # Oracle, and Sybase do not have a TIME datatype.
+  unless current_adapter?(:OracleAdapter, :SybaseAdapter)
     def test_utc_as_time_zone
       Topic.default_timezone = :utc
       attributes = { &quot;bonus_time&quot; =&gt; &quot;5:42:00AM&quot; }
@@ -809,6 +829,20 @@ class BasicsTest &lt; ActiveRecord::TestCase
     assert_equal [ Topic.find(1) ], [ Topic.find(2).topic ] &amp; [ Topic.find(1) ]
   end
 
+  def test_delete_new_record
+    client = Client.new
+    client.delete
+    assert client.frozen?
+  end
+
+  def test_delete_record_with_associations
+    client = Client.find(3)
+    client.delete
+    assert client.frozen?
+    assert_kind_of Firm, client.firm
+    assert_raises(ActiveSupport::FrozenObjectError) { client.name = &quot;something else&quot; }
+  end
+
   def test_destroy_new_record
     client = Client.new
     client.destroy
@@ -880,7 +914,7 @@ class BasicsTest &lt; ActiveRecord::TestCase
 
   def test_mass_assignment_protection_against_class_attribute_writers
     [:logger, :configurations, :primary_key_prefix_type, :table_name_prefix, :table_name_suffix, :pluralize_table_names, :colorize_logging,
-      :default_timezone, :allow_concurrency, :schema_format, :verification_timeout, :lock_optimistically, :record_timestamps].each do |method|
+      :default_timezone, :schema_format, :lock_optimistically, :record_timestamps].each do |method|
       assert  Task.respond_to?(method)
       assert  Task.respond_to?(&quot;#{method}=&quot;)
       assert  Task.new.respond_to?(method)
@@ -904,6 +938,14 @@ class BasicsTest &lt; ActiveRecord::TestCase
     assert_nil keyboard.id
   end
 
+  def test_mass_assigning_invalid_attribute
+    firm = Firm.new
+
+    assert_raises(ActiveRecord::UnknownAttributeError) do
+      firm.attributes = { &quot;id&quot; =&gt; 5, &quot;type&quot; =&gt; &quot;Client&quot;, &quot;i_dont_even_exist&quot; =&gt; 20 }
+    end
+  end
+
   def test_mass_assignment_protection_on_defaults
     firm = Firm.new
     firm.attributes = { &quot;id&quot; =&gt; 5, &quot;type&quot; =&gt; &quot;Client&quot; }
@@ -1065,6 +1107,24 @@ class BasicsTest &lt; ActiveRecord::TestCase
     Time.zone = nil
     Topic.skip_time_zone_conversion_for_attributes = []
   end
+  
+  def test_multiparameter_attributes_on_time_only_column_with_time_zone_aware_attributes_does_not_do_time_zone_conversion
+    ActiveRecord::Base.time_zone_aware_attributes = true
+    ActiveRecord::Base.default_timezone = :utc
+    Time.zone = ActiveSupport::TimeZone[-28800]
+    attributes = {
+      &quot;bonus_time(1i)&quot; =&gt; &quot;2000&quot;, &quot;bonus_time(2i)&quot; =&gt; &quot;1&quot;, &quot;bonus_time(3i)&quot; =&gt; &quot;1&quot;,
+      &quot;bonus_time(4i)&quot; =&gt; &quot;16&quot;, &quot;bonus_time(5i)&quot; =&gt; &quot;24&quot;
+    }
+    topic = Topic.find(1)
+    topic.attributes = attributes
+    assert_equal Time.utc(2000, 1, 1, 16, 24, 0), topic.bonus_time
+    assert topic.bonus_time.utc?
+  ensure
+    ActiveRecord::Base.time_zone_aware_attributes = false
+    ActiveRecord::Base.default_timezone = :local
+    Time.zone = nil
+  end
 
   def test_multiparameter_attributes_on_time_with_empty_seconds
     attributes = {
@@ -1094,8 +1154,8 @@ class BasicsTest &lt; ActiveRecord::TestCase
   end
 
   def test_attributes_on_dummy_time
-    # Oracle, SQL Server, and Sybase do not have a TIME datatype.
-    return true if current_adapter?(:SQLServerAdapter, :OracleAdapter, :SybaseAdapter)
+    # Oracle, and Sybase do not have a TIME datatype.
+    return true if current_adapter?(:OracleAdapter, :SybaseAdapter)
 
     attributes = {
       &quot;bonus_time&quot; =&gt; &quot;5:42:00AM&quot;
@@ -1106,11 +1166,15 @@ class BasicsTest &lt; ActiveRecord::TestCase
   end
 
   def test_boolean
+    b_nil = Booleantest.create({ &quot;value&quot; =&gt; nil })
+    nil_id = b_nil.id
     b_false = Booleantest.create({ &quot;value&quot; =&gt; false })
     false_id = b_false.id
     b_true = Booleantest.create({ &quot;value&quot; =&gt; true })
     true_id = b_true.id
 
+    b_nil = Booleantest.find(nil_id)
+    assert_nil b_nil.value
     b_false = Booleantest.find(false_id)
     assert !b_false.value?
     b_true = Booleantest.find(true_id)
@@ -1118,11 +1182,15 @@ class BasicsTest &lt; ActiveRecord::TestCase
   end
 
   def test_boolean_cast_from_string
+    b_blank = Booleantest.create({ &quot;value&quot; =&gt; &quot;&quot; })
+    blank_id = b_blank.id
     b_false = Booleantest.create({ &quot;value&quot; =&gt; &quot;0&quot; })
     false_id = b_false.id
     b_true = Booleantest.create({ &quot;value&quot; =&gt; &quot;1&quot; })
     true_id = b_true.id
 
+    b_blank = Booleantest.find(blank_id)
+    assert_nil b_blank.value
     b_false = Booleantest.find(false_id)
     assert !b_false.value?
     b_true = Booleantest.find(true_id)
@@ -1358,6 +1426,12 @@ class BasicsTest &lt; ActiveRecord::TestCase
     topic = Topic.create(&quot;content&quot; =&gt; myobj).reload
     assert_equal(myobj, topic.content)
   end
+  
+  def test_serialized_string_attribute
+    myobj = &quot;Yes&quot;
+    topic = Topic.create(&quot;content&quot; =&gt; myobj).reload
+    assert_equal(myobj, topic.content)
+  end
 
   def test_nil_serialized_attribute_with_class_constraint
     myobj = MyObject.new('value1', 'value2')
@@ -1393,15 +1467,17 @@ class BasicsTest &lt; ActiveRecord::TestCase
 
   if RUBY_VERSION &lt; '1.9'
     def test_quote_chars
-      str = 'The Narrator'
-      topic = Topic.create(:author_name =&gt; str)
-      assert_equal str, topic.author_name
+      with_kcode('UTF8') do
+        str = 'The Narrator'
+        topic = Topic.create(:author_name =&gt; str)
+        assert_equal str, topic.author_name
 
-      assert_kind_of ActiveSupport::Multibyte::Chars, str.chars
-      topic = Topic.find_by_author_name(str.chars)
+        assert_kind_of ActiveSupport::Multibyte.proxy_class, str.mb_chars
+        topic = Topic.find_by_author_name(str.mb_chars)
 
-      assert_kind_of Topic, topic
-      assert_equal str, topic.author_name, &quot;The right topic should have been found by name even with name passed as Chars&quot;
+        assert_kind_of Topic, topic
+        assert_equal str, topic.author_name, &quot;The right topic should have been found by name even with name passed as Chars&quot;
+      end
     end
   end
 
@@ -1795,7 +1871,7 @@ class BasicsTest &lt; ActiveRecord::TestCase
     assert_equal &quot;integer&quot;, xml.elements[&quot;//parent-id&quot;].attributes['type']
     assert_equal &quot;true&quot;, xml.elements[&quot;//parent-id&quot;].attributes['nil']
 
-    if current_adapter?(:SybaseAdapter, :SQLServerAdapter, :OracleAdapter)
+    if current_adapter?(:SybaseAdapter, :OracleAdapter)
       assert_equal last_read_in_current_timezone, xml.elements[&quot;//last-read&quot;].text
       assert_equal &quot;datetime&quot; , xml.elements[&quot;//last-read&quot;].attributes['type']
     else
@@ -1994,4 +2070,18 @@ class BasicsTest &lt; ActiveRecord::TestCase
   ensure
     ActiveRecord::Base.logger = original_logger
   end
+
+  private
+    def with_kcode(kcode)
+      if RUBY_VERSION &lt; '1.9'
+        orig_kcode, $KCODE = $KCODE, kcode
+        begin
+          yield
+        ensure
+          $KCODE = orig_kcode
+        end
+      else
+        yield
+      end
+    end
 end</diff>
      <filename>vendor/activerecord/test/cases/base_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,13 +1,9 @@
 require &quot;cases/helper&quot;
 
 # Without using prepared statements, it makes no sense to test
-# BLOB data with SQL Server, because the length of a statement is
-# limited to 8KB.
-#
-# Without using prepared statements, it makes no sense to test
 # BLOB data with DB2 or Firebird, because the length of a statement
 # is limited to 32KB.
-unless current_adapter?(:SQLServerAdapter, :SybaseAdapter, :DB2Adapter, :FirebirdAdapter)
+unless current_adapter?(:SybaseAdapter, :DB2Adapter, :FirebirdAdapter)
   require 'models/binary'
 
   class BinaryTest &lt; ActiveRecord::TestCase</diff>
      <filename>vendor/activerecord/test/cases/binary_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -18,13 +18,18 @@ class CalculationsTest &lt; ActiveRecord::TestCase
 
   def test_should_average_field
     value = Account.average(:credit_limit)
-    assert_kind_of Float, value
-    assert_in_delta 53.0, value, 0.001
+    assert_kind_of BigDecimal, value
+    assert_equal BigDecimal.new('53.0'), value
   end
 
   def test_should_return_nil_as_average
     assert_nil NumericData.average(:bank_balance)
   end
+  
+  def test_type_cast_calculated_value_should_convert_db_averages_of_fixnum_class_to_decimal
+    assert_equal 0, NumericData.send(:type_cast_calculated_value, 0, nil, 'avg')
+    assert_equal 53.0, NumericData.send(:type_cast_calculated_value, 53, nil, 'avg')
+  end
 
   def test_should_get_maximum_of_field
     assert_equal 60, Account.maximum(:credit_limit)
@@ -273,7 +278,7 @@ class CalculationsTest &lt; ActiveRecord::TestCase
   end
 
   def test_should_sum_expression
-    assert_equal 636, Account.sum(&quot;2 * credit_limit&quot;)
+    assert_equal '636', Account.sum(&quot;2 * credit_limit&quot;)
   end
 
   def test_count_with_from_option</diff>
      <filename>vendor/activerecord/test/cases/calculations_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -24,7 +24,7 @@ class MysqlConnectionTest &lt; ActiveRecord::TestCase
     assert @connection.active?
     @connection.update('set @@wait_timeout=1')
     sleep 2
-    @connection.verify!(0)
+    @connection.verify!
     assert @connection.active?
   end
 end</diff>
      <filename>vendor/activerecord/test/cases/connection_test_mysql.rb</filename>
    </modified>
    <modified>
      <diff>@@ -19,6 +19,37 @@ class DefaultTest &lt; ActiveRecord::TestCase
   end
 
   if current_adapter?(:MysqlAdapter)
+
+    #MySQL 5 and higher is quirky with not null text/blob columns.
+    #With MySQL Text/blob columns cannot have defaults. If the column is not null MySQL will report that the column has a null default
+    #but it behaves as though the column had a default of ''
+    def test_mysql_text_not_null_defaults
+      klass = Class.new(ActiveRecord::Base)
+      klass.table_name = 'test_mysql_text_not_null_defaults'
+      klass.connection.create_table klass.table_name do |t|
+        t.column :non_null_text, :text, :null =&gt; false
+        t.column :non_null_blob, :blob, :null =&gt; false
+        t.column :null_text, :text, :null =&gt; true
+        t.column :null_blob, :blob, :null =&gt; true
+      end
+      assert_equal '', klass.columns_hash['non_null_blob'].default
+      assert_equal '', klass.columns_hash['non_null_text'].default
+
+      assert_equal nil, klass.columns_hash['null_blob'].default
+      assert_equal nil, klass.columns_hash['null_text'].default
+
+      assert_nothing_raised do
+        instance = klass.create!
+        assert_equal '', instance.non_null_text
+        assert_equal '', instance.non_null_blob
+        assert_nil instance.null_text
+        assert_nil instance.null_blob
+      end
+    ensure
+      klass.connection.drop_table(klass.table_name) rescue nil
+    end
+
+
     # MySQL uses an implicit default 0 rather than NULL unless in strict mode.
     # We use an implicit NULL so schema.rb is compatible with other databases.
     def test_mysql_integer_not_null_defaults
@@ -47,7 +78,7 @@ class DefaultTest &lt; ActiveRecord::TestCase
     end
   end
 
-  if current_adapter?(:PostgreSQLAdapter, :SQLServerAdapter, :FirebirdAdapter, :OpenBaseAdapter, :OracleAdapter)
+  if current_adapter?(:PostgreSQLAdapter, :FirebirdAdapter, :OpenBaseAdapter, :OracleAdapter)
     def test_default_integers
       default = Default.new
       assert_instance_of Fixnum, default.positive_integer</diff>
      <filename>vendor/activerecord/test/cases/defaults_test.rb</filename>
    </modified>
    <modified>
      <filename>vendor/activerecord/test/cases/deprecated_finder_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -45,6 +45,19 @@ class DirtyTest &lt; ActiveRecord::TestCase
     assert_nil pirate.catchphrase_change
   end
 
+  def test_aliased_attribute_changes
+    # the actual attribute here is name, title is an
+    # alias setup via alias_attribute
+    parrot = Parrot.new
+    assert !parrot.title_changed?
+    assert_nil parrot.title_change
+
+    parrot.name = 'Sam'
+    assert parrot.title_changed?
+    assert_nil parrot.title_was
+    assert_equal parrot.name_change, parrot.title_change
+  end
+
   def test_nullable_integer_not_marked_as_changed_if_new_value_is_blank
     pirate = Pirate.new
 </diff>
      <filename>vendor/activerecord/test/cases/dirty_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -12,6 +12,57 @@ require 'models/customer'
 require 'models/job'
 require 'models/categorization'
 
+class DynamicFinderMatchTest &lt; ActiveRecord::TestCase
+  def test_find_no_match
+    assert_nil ActiveRecord::DynamicFinderMatch.match(&quot;not_a_finder&quot;)
+  end
+
+  def test_find_by
+    match = ActiveRecord::DynamicFinderMatch.match(&quot;find_by_age_and_sex_and_location&quot;)
+    assert_not_nil match
+    assert match.finder?
+    assert_equal :first, match.finder
+    assert_equal %w(age sex location), match.attribute_names
+  end
+
+  def find_by_bang
+    match = ActiveRecord::DynamicFinderMatch.match(&quot;find_by_age_and_sex_and_location!&quot;)
+    assert_not_nil match
+    assert match.finder?
+    assert match.bang?
+    assert_equal :first, match.finder
+    assert_equal %w(age sex location), match.attribute_names
+  end
+
+  def test_find_all_by
+    match = ActiveRecord::DynamicFinderMatch.match(&quot;find_all_by_age_and_sex_and_location&quot;)
+    assert_not_nil match
+    assert match.finder?
+    assert_equal :all, match.finder
+    assert_equal %w(age sex location), match.attribute_names
+  end
+
+  def test_find_or_initialize_by
+    match = ActiveRecord::DynamicFinderMatch.match(&quot;find_or_initialize_by_age_and_sex_and_location&quot;)
+    assert_not_nil match
+    assert !match.finder?
+    assert match.instantiator?
+    assert_equal :first, match.finder
+    assert_equal :new, match.instantiator
+    assert_equal %w(age sex location), match.attribute_names
+  end
+
+  def test_find_or_create_by
+    match = ActiveRecord::DynamicFinderMatch.match(&quot;find_or_create_by_age_and_sex_and_location&quot;)
+    assert_not_nil match
+    assert !match.finder?
+    assert match.instantiator?
+    assert_equal :first, match.finder
+    assert_equal :create, match.instantiator
+    assert_equal %w(age sex location), match.attribute_names
+  end
+end
+
 class FinderTest &lt; ActiveRecord::TestCase
   fixtures :companies, :topics, :entrants, :developers, :developers_projects, :posts, :comments, :accounts, :authors, :customers
 
@@ -118,6 +169,12 @@ class FinderTest &lt; ActiveRecord::TestCase
     assert_equal(&quot;fixture_3&quot;, developers.first.name)
   end
 
+  def test_find_with_group
+    developers =  Developer.find(:all, :group =&gt; &quot;salary&quot;, :select =&gt; &quot;salary&quot;)
+    assert_equal 4, developers.size
+    assert_equal 4, developers.map(&amp;:salary).uniq.size
+  end
+
   def test_find_with_entire_select_statement
     topics = Topic.find_by_sql &quot;SELECT * FROM topics WHERE author_name = 'Mary'&quot;
 
@@ -146,11 +203,11 @@ class FinderTest &lt; ActiveRecord::TestCase
     first = Topic.find(:first, :conditions =&gt; &quot;title = 'The First Topic!'&quot;)
     assert_nil(first)
   end
-  
+
   def test_first
     assert_equal topics(:second).title, Topic.first(:conditions =&gt; &quot;title = 'The Second Topic of the day'&quot;).title
   end
-  
+
   def test_first_failing
     assert_nil Topic.first(:conditions =&gt; &quot;title = 'The Second Topic of the day!'&quot;)
   end
@@ -200,6 +257,23 @@ class FinderTest &lt; ActiveRecord::TestCase
     assert_raises(ActiveRecord::RecordNotFound) { Topic.find(1, :conditions =&gt; { 'topics.approved' =&gt; true }) }
   end
 
+  def test_find_on_hash_conditions_with_hashed_table_name
+    assert Topic.find(1, :conditions =&gt; {:topics =&gt; { :approved =&gt; false }})
+    assert_raises(ActiveRecord::RecordNotFound) { Topic.find(1, :conditions =&gt; {:topics =&gt; { :approved =&gt; true }}) }
+  end
+
+  def test_find_with_hash_conditions_on_joined_table
+    firms = Firm.all :joins =&gt; :account, :conditions =&gt; {:accounts =&gt; { :credit_limit =&gt; 50 }}
+    assert_equal 1, firms.size
+    assert_equal companies(:first_firm), firms.first
+  end
+
+  def test_find_with_hash_conditions_on_joined_table_and_with_range
+    firms = DependentFirm.all :joins =&gt; :account, :conditions =&gt; {:name =&gt; 'RailsCore', :accounts =&gt; { :credit_limit =&gt; 55..60 }}
+    assert_equal 1, firms.size
+    assert_equal companies(:rails_core), firms.first
+  end
+
   def test_find_on_hash_conditions_with_explicit_table_name_and_aggregate
     david = customers(:david)
     assert Customer.find(david.id, :conditions =&gt; { 'customers.name' =&gt; david.name, :address =&gt; david.address })
@@ -229,7 +303,6 @@ class FinderTest &lt; ActiveRecord::TestCase
     assert_raises(ActiveRecord::RecordNotFound) { Topic.find(1, :conditions =&gt; { :author_name =&gt; &quot;David&quot;, :title =&gt; &quot;The First Topic&quot;, :replies_count =&gt; 1, :approved =&gt; true }) }
   end
 
-
   def test_condition_interpolation
     assert_kind_of Firm, Company.find(:first, :conditions =&gt; [&quot;name = '%s'&quot;, &quot;37signals&quot;])
     assert_nil Company.find(:first, :conditions =&gt; [&quot;name = '%s'&quot;, &quot;37signals!&quot;])
@@ -324,7 +397,7 @@ class FinderTest &lt; ActiveRecord::TestCase
       Company.find(:first, :conditions =&gt; [&quot;id=? AND name = ?&quot;, 2])
     }
     assert_raises(ActiveRecord::PreparedStatementInvalid) {
-	   Company.find(:first, :conditions =&gt; [&quot;id=?&quot;, 2, 3, 4])
+     Company.find(:first, :conditions =&gt; [&quot;id=?&quot;, 2, 3, 4])
     }
   end
 
@@ -350,7 +423,7 @@ class FinderTest &lt; ActiveRecord::TestCase
   def test_named_bind_variables
     assert_equal '1', bind(':a', :a =&gt; 1) # ' ruby-mode
     assert_equal '1 1', bind(':a :a', :a =&gt; 1)  # ' ruby-mode
-    
+
     assert_nothing_raised { bind(&quot;'+00:00'&quot;, :foo =&gt; &quot;bar&quot;) }
 
     assert_kind_of Firm, Company.find(:first, :conditions =&gt; [&quot;name = :name&quot;, { :name =&gt; &quot;37signals&quot; }])
@@ -387,6 +460,15 @@ class FinderTest &lt; ActiveRecord::TestCase
     assert_equal ActiveRecord::Base.connection.quote(''), bind('?', '')
   end
 
+  def test_bind_chars
+    quoted_bambi = ActiveRecord::Base.connection.quote(&quot;Bambi&quot;)
+    quoted_bambi_and_thumper = ActiveRecord::Base.connection.quote(&quot;Bambi\nand\nThumper&quot;)
+    assert_equal &quot;name=#{quoted_bambi}&quot;, bind('name=?', &quot;Bambi&quot;)
+    assert_equal &quot;name=#{quoted_bambi_and_thumper}&quot;, bind('name=?', &quot;Bambi\nand\nThumper&quot;)
+    assert_equal &quot;name=#{quoted_bambi}&quot;, bind('name=?', &quot;Bambi&quot;.mb_chars)
+    assert_equal &quot;name=#{quoted_bambi_and_thumper}&quot;, bind('name=?', &quot;Bambi\nand\nThumper&quot;.mb_chars)
+  end
+
   def test_bind_record
     o = Struct.new(:quoted_id).new(1)
     assert_equal '1', bind('?', o)
@@ -418,11 +500,33 @@ class FinderTest &lt; ActiveRecord::TestCase
     assert_equal(2, Entrant.count_by_sql([&quot;SELECT COUNT(*) FROM entrants WHERE id &gt; ?&quot;, 1]))
   end
 
+  uses_mocha('test_dynamic_finder_should_go_through_the_find_class_method') do
+    def test_dynamic_finders_should_go_through_the_find_class_method
+      Topic.expects(:find).with(:first, :conditions =&gt; { :title =&gt; 'The First Topic!' })
+      Topic.find_by_title(&quot;The First Topic!&quot;)
+
+      Topic.expects(:find).with(:last, :conditions =&gt; { :title =&gt; 'The Last Topic!' })
+      Topic.find_last_by_title(&quot;The Last Topic!&quot;)
+
+      Topic.expects(:find).with(:all, :conditions =&gt; { :title =&gt; 'A Topic.' })
+      Topic.find_all_by_title(&quot;A Topic.&quot;)
+
+      Topic.expects(:find).with(:first, :conditions =&gt; { :title =&gt; 'Does not exist yet for sure!' }).times(2)
+      Topic.find_or_initialize_by_title('Does not exist yet for sure!')
+      Topic.find_or_create_by_title('Does not exist yet for sure!')
+    end
+  end
+
   def test_find_by_one_attribute
     assert_equal topics(:first), Topic.find_by_title(&quot;The First Topic&quot;)
     assert_nil Topic.find_by_title(&quot;The First Topic!&quot;)
   end
 
+  def test_find_by_one_attribute_bang
+    assert_equal topics(:first), Topic.find_by_title!(&quot;The First Topic&quot;)
+    assert_raises(ActiveRecord::RecordNotFound) { Topic.find_by_title!(&quot;The First Topic!&quot;) }
+  end
+
   def test_find_by_one_attribute_caches_dynamic_finder
     # ensure this test can run independently of order
     class &lt;&lt; Topic; self; end.send(:remove_method, :find_by_title) if Topic.public_methods.any? { |m| m.to_s == 'find_by_title' }
@@ -516,6 +620,38 @@ class FinderTest &lt; ActiveRecord::TestCase
     assert_nil Topic.find_by_title_and_author_name(&quot;The First Topic&quot;, &quot;Mary&quot;)
   end
 
+  def test_find_last_by_one_attribute
+    assert_equal Topic.last, Topic.find_last_by_title(Topic.last.title)
+    assert_nil Topic.find_last_by_title(&quot;A title with no matches&quot;)
+  end
+
+  def test_find_last_by_one_attribute_caches_dynamic_finder
+    # ensure this test can run independently of order
+    class &lt;&lt; Topic; self; end.send(:remove_method, :find_last_by_title) if Topic.public_methods.any? { |m| m.to_s == 'find_last_by_title' }
+    assert !Topic.public_methods.any? { |m| m.to_s == 'find_last_by_title' }
+    t = Topic.find_last_by_title(Topic.last.title)
+    assert Topic.public_methods.any? { |m| m.to_s == 'find_last_by_title' }
+  end
+
+  def test_find_last_by_invalid_method_syntax
+    assert_raises(NoMethodError) { Topic.fail_to_find_last_by_title(&quot;The First Topic&quot;) }
+    assert_raises(NoMethodError) { Topic.find_last_by_title?(&quot;The First Topic&quot;) }
+  end
+
+  def test_find_last_by_one_attribute_with_several_options
+    assert_equal accounts(:signals37), Account.find_last_by_credit_limit(50, :order =&gt; 'id DESC', :conditions =&gt; ['id != ?', 3])
+  end
+
+  def test_find_last_by_one_missing_attribute
+    assert_raises(NoMethodError) { Topic.find_last_by_undertitle(&quot;The Last Topic!&quot;) }
+  end
+
+  def test_find_last_by_two_attributes
+    topic = Topic.last
+    assert_equal topic, Topic.find_last_by_title_and_author_name(topic.title, topic.author_name)
+    assert_nil Topic.find_last_by_title_and_author_name(topic.title, &quot;Anonymous&quot;)
+  end
+
   def test_find_all_by_one_attribute
     topics = Topic.find_all_by_content(&quot;Have a nice day&quot;)
     assert_equal 2, topics.size
@@ -709,7 +845,18 @@ class FinderTest &lt; ActiveRecord::TestCase
     assert c.valid?
     assert !c.new_record?
   end
-  
+
+  def test_find_or_create_should_work_with_block_on_first_call
+	  class &lt;&lt; Company
+		undef_method(:find_or_create_by_name) if method_defined?(:find_or_create_by_name)
+	  end
+    c = Company.find_or_create_by_name(:name =&gt; &quot;Fortune 1000&quot;) { |f| f.rating = 1000 }
+    assert_equal &quot;Fortune 1000&quot;, c.name
+    assert_equal 1000.to_f, c.rating.to_f
+    assert c.valid?
+    assert !c.new_record?
+  end
+
   def test_dynamic_find_or_initialize_from_one_attribute_caches_method
     class &lt;&lt; Company; self; end.send(:remove_method, :find_or_initialize_by_name) if Company.public_methods.any? { |m| m.to_s == 'find_or_initialize_by_name' }
     assert !Company.public_methods.any? { |m| m.to_s == 'find_or_initialize_by_name' }
@@ -816,6 +963,17 @@ class FinderTest &lt; ActiveRecord::TestCase
     assert_equal 1, first.id
   end
 
+  def test_joins_with_string_array
+    person_with_reader_and_post = Post.find(
+      :all,
+      :joins =&gt; [
+        &quot;INNER JOIN categorizations ON categorizations.post_id = posts.id&quot;,
+        &quot;INNER JOIN categories ON categories.id = categorizations.category_id AND categories.type = 'SpecialCategory'&quot;
+      ]
+    )
+    assert_equal 1, person_with_reader_and_post.size
+  end
+
   def test_find_by_id_with_conditions_with_or
     assert_nothing_raised do
       Post.find([1,2,3],</diff>
      <filename>vendor/activerecord/test/cases/finder_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -15,6 +15,7 @@ require 'models/pirate'
 require 'models/treasure'
 require 'models/matey'
 require 'models/ship'
+require 'models/book'
 
 class FixturesTest &lt; ActiveRecord::TestCase
   self.use_instantiated_fixtures = true
@@ -373,6 +374,34 @@ class CheckSetTableNameFixturesTest &lt; ActiveRecord::TestCase
   end
 end
 
+class FixtureNameIsNotTableNameFixturesTest &lt; ActiveRecord::TestCase
+  set_fixture_class :items =&gt; Book
+  fixtures :items
+  # Set to false to blow away fixtures cache and ensure our fixtures are loaded 
+  # and thus takes into account our set_fixture_class
+  self.use_transactional_fixtures = false
+
+  def test_named_accessor
+    assert_kind_of Book, items(:dvd)
+  end
+end
+
+class FixtureNameIsNotTableNameMultipleFixturesTest &lt; ActiveRecord::TestCase
+  set_fixture_class :items =&gt; Book, :funny_jokes =&gt; Joke
+  fixtures :items, :funny_jokes
+  # Set to false to blow away fixtures cache and ensure our fixtures are loaded 
+  # and thus takes into account our set_fixture_class
+  self.use_transactional_fixtures = false
+
+  def test_named_accessor_of_differently_named_fixture
+    assert_kind_of Book, items(:dvd)
+  end
+
+  def test_named_accessor_of_same_named_fixture
+    assert_kind_of Joke, funny_jokes(:a_joke)
+  end
+end
+
 class CustomConnectionFixturesTest &lt; ActiveRecord::TestCase
   set_fixture_class :courses =&gt; Course
   fixtures :courses
@@ -432,11 +461,11 @@ class FixturesBrokenRollbackTest &lt; ActiveRecord::TestCase
   alias_method :teardown, :blank_teardown
 
   def test_no_rollback_in_teardown_unless_transaction_active
-    assert_equal 0, Thread.current['open_transactions']
+    assert_equal 0, ActiveRecord::Base.connection.open_transactions
     assert_raise(RuntimeError) { ar_setup_fixtures }
-    assert_equal 0, Thread.current['open_transactions']
+    assert_equal 0, ActiveRecord::Base.connection.open_transactions
     assert_nothing_raised { ar_teardown_fixtures }
-    assert_equal 0, Thread.current['open_transactions']
+    assert_equal 0, ActiveRecord::Base.connection.open_transactions
   end
 
   private</diff>
      <filename>vendor/activerecord/test/cases/fixtures_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,4 +1,5 @@
 $:.unshift(File.dirname(__FILE__) + '/../../lib')
+$:.unshift(File.dirname(__FILE__) + '/../../../activesupport/lib')
 
 require 'config'
 require 'test/unit'
@@ -45,3 +46,17 @@ end
 class &lt;&lt; ActiveRecord::Base
   public :with_scope, :with_exclusive_scope
 end
+
+unless ENV['FIXTURE_DEBUG']
+  module Test #:nodoc:
+    module Unit #:nodoc:
+      class &lt;&lt; TestCase #:nodoc:
+        def try_to_load_dependency_with_silence(*args)
+          ActiveRecord::Base.logger.silence { try_to_load_dependency_without_silence(*args)}
+        end
+
+        alias_method_chain :try_to_load_dependency, :silence
+      end
+    end
+  end
+end
\ No newline at end of file</diff>
      <filename>vendor/activerecord/test/cases/helper.rb</filename>
    </modified>
    <modified>
      <diff>@@ -59,13 +59,13 @@ class InheritanceTest &lt; ActiveRecord::TestCase
 
   def test_a_bad_type_column
     #SQLServer need to turn Identity Insert On before manually inserting into the Identity column
-    if current_adapter?(:SQLServerAdapter, :SybaseAdapter)
+    if current_adapter?(:SybaseAdapter)
       Company.connection.execute &quot;SET IDENTITY_INSERT companies ON&quot;
     end
     Company.connection.insert &quot;INSERT INTO companies (id, #{QUOTED_TYPE}, name) VALUES(100, 'bad_class!', 'Not happening')&quot;
 
     #We then need to turn it back Off before continuing.
-    if current_adapter?(:SQLServerAdapter, :SybaseAdapter)
+    if current_adapter?(:SybaseAdapter)
       Company.connection.execute &quot;SET IDENTITY_INSERT companies OFF&quot;
     end
     assert_raises(ActiveRecord::SubclassNotFound) { Company.find(100) }
@@ -193,7 +193,7 @@ class InheritanceTest &lt; ActiveRecord::TestCase
 
   def test_eager_load_belongs_to_primary_key_quoting
     con = Account.connection
-    assert_sql(/\(#{con.quote_table_name('companies')}.#{con.quote_column_name('id')} IN \(1\)\)/) do
+    assert_sql(/\(#{con.quote_table_name('companies')}.#{con.quote_column_name('id')} = 1\)/) do
       Account.find(1, :include =&gt; :firm)
     end
   end</diff>
      <filename>vendor/activerecord/test/cases/inheritance_test.rb</filename>
    </modified>
    <modified>
      <filename>vendor/activerecord/test/cases/lifecycle_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -200,9 +200,9 @@ end
 # blocks, so separate script called by Kernel#system is needed.
 # (See exec vs. async_exec in the PostgreSQL adapter.)
 
-# TODO: The SQL Server, Sybase, and OpenBase adapters currently have no support for pessimistic locking
+# TODO: The Sybase, and OpenBase adapters currently have no support for pessimistic locking
 
-unless current_adapter?(:SQLServerAdapter, :SybaseAdapter, :OpenBaseAdapter)
+unless current_adapter?(:SybaseAdapter, :OpenBaseAdapter)
   class PessimisticLockingTest &lt; ActiveRecord::TestCase
     self.use_transactional_fixtures = false
     fixtures :people, :readers
@@ -210,13 +210,6 @@ unless current_adapter?(:SQLServerAdapter, :SybaseAdapter, :OpenBaseAdapter)
     def setup
       # Avoid introspection queries during tests.
       Person.columns; Reader.columns
-
-      @allow_concurrency = ActiveRecord::Base.allow_concurrency
-      ActiveRecord::Base.allow_concurrency = true
-    end
-
-    def teardown
-      ActiveRecord::Base.allow_concurrency = @allow_concurrency
     end
 
     # Test typical find.
@@ -264,6 +257,8 @@ unless current_adapter?(:SQLServerAdapter, :SybaseAdapter, :OpenBaseAdapter)
     end
 
     if current_adapter?(:PostgreSQLAdapter, :OracleAdapter)
+      use_concurrent_connections
+
       def test_no_locks_no_wait
         first, second = duel { Person.find 1 }
         assert first.end &gt; second.end</diff>
      <filename>vendor/activerecord/test/cases/locking_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,4 +1,5 @@
 require &quot;cases/helper&quot;
+require 'models/author'
 require 'models/developer'
 require 'models/project'
 require 'models/comment'
@@ -6,7 +7,7 @@ require 'models/post'
 require 'models/category'
 
 class MethodScopingTest &lt; ActiveRecord::TestCase
-  fixtures :developers, :projects, :comments, :posts, :developers_projects
+  fixtures :authors, :developers, :projects, :comments, :posts, :developers_projects
 
   def test_set_conditions
     Developer.with_scope(:find =&gt; { :conditions =&gt; 'just a test...' }) do
@@ -97,6 +98,76 @@ class MethodScopingTest &lt; ActiveRecord::TestCase
     assert_equal developers(:david).attributes, scoped_developers.first.attributes
   end
 
+  def test_scoped_find_using_new_style_joins
+    scoped_developers = Developer.with_scope(:find =&gt; { :joins =&gt; :projects }) do
+      Developer.find(:all, :conditions =&gt; 'projects.id = 2')
+    end
+    assert scoped_developers.include?(developers(:david))
+    assert !scoped_developers.include?(developers(:jamis))
+    assert_equal 1, scoped_developers.size
+    assert_equal developers(:david).attributes, scoped_developers.first.attributes
+  end
+
+  def test_scoped_find_merges_old_style_joins
+    scoped_authors = Author.with_scope(:find =&gt; { :joins =&gt; 'INNER JOIN posts ON authors.id = posts.author_id ' }) do
+      Author.find(:all, :select =&gt; 'DISTINCT authors.*', :joins =&gt; 'INNER JOIN comments ON posts.id = comments.post_id', :conditions =&gt; 'comments.id = 1')
+    end
+    assert scoped_authors.include?(authors(:david))
+    assert !scoped_authors.include?(authors(:mary))
+    assert_equal 1, scoped_authors.size
+    assert_equal authors(:david).attributes, scoped_authors.first.attributes
+  end
+
+  def test_scoped_find_merges_new_style_joins
+    scoped_authors = Author.with_scope(:find =&gt; { :joins =&gt; :posts }) do
+      Author.find(:all, :select =&gt; 'DISTINCT authors.*', :joins =&gt; :comments, :conditions =&gt; 'comments.id = 1')
+    end
+    assert scoped_authors.include?(authors(:david))
+    assert !scoped_authors.include?(authors(:mary))
+    assert_equal 1, scoped_authors.size
+    assert_equal authors(:david).attributes, scoped_authors.first.attributes
+  end
+
+  def test_scoped_find_merges_new_and_old_style_joins
+    scoped_authors = Author.with_scope(:find =&gt; { :joins =&gt; :posts }) do
+      Author.find(:all, :select =&gt; 'DISTINCT authors.*', :joins =&gt; 'JOIN comments ON posts.id = comments.post_id', :conditions =&gt; 'comments.id = 1')
+    end
+    assert scoped_authors.include?(authors(:david))
+    assert !scoped_authors.include?(authors(:mary))
+    assert_equal 1, scoped_authors.size
+    assert_equal authors(:david).attributes, scoped_authors.first.attributes
+  end
+
+  def test_scoped_find_merges_string_array_style_and_string_style_joins
+    scoped_authors = Author.with_scope(:find =&gt; { :joins =&gt; [&quot;INNER JOIN posts ON posts.author_id = authors.id&quot;]}) do
+      Author.find(:all, :select =&gt; 'DISTINCT authors.*', :joins =&gt; 'INNER JOIN comments ON posts.id = comments.post_id', :conditions =&gt; 'comments.id = 1')
+    end
+    assert scoped_authors.include?(authors(:david))
+    assert !scoped_authors.include?(authors(:mary))
+    assert_equal 1, scoped_authors.size
+    assert_equal authors(:david).attributes, scoped_authors.first.attributes
+  end
+
+  def test_scoped_find_merges_string_array_style_and_hash_style_joins
+    scoped_authors = Author.with_scope(:find =&gt; { :joins =&gt; :posts}) do
+      Author.find(:all, :select =&gt; 'DISTINCT authors.*', :joins =&gt; ['INNER JOIN comments ON posts.id = comments.post_id'], :conditions =&gt; 'comments.id = 1')
+    end
+    assert scoped_authors.include?(authors(:david))
+    assert !scoped_authors.include?(authors(:mary))
+    assert_equal 1, scoped_authors.size
+    assert_equal authors(:david).attributes, scoped_authors.first.attributes
+  end
+
+  def test_scoped_find_merges_joins_and_eliminates_duplicate_string_joins
+    scoped_authors = Author.with_scope(:find =&gt; { :joins =&gt; 'INNER JOIN posts ON posts.author_id = authors.id'}) do
+      Author.find(:all, :select =&gt; 'DISTINCT authors.*', :joins =&gt; [&quot;INNER JOIN posts ON posts.author_id = authors.id&quot;, &quot;INNER JOIN comments ON posts.id = comments.post_id&quot;], :conditions =&gt; 'comments.id = 1')
+    end
+    assert scoped_authors.include?(authors(:david))
+    assert !scoped_authors.include?(authors(:mary))
+    assert_equal 1, scoped_authors.size
+    assert_equal authors(:david).attributes, scoped_authors.first.attributes
+  end
+
   def test_scoped_count_include
     # with the include, will retrieve only developers for the given project
     Developer.with_scope(:find =&gt; { :include =&gt; :projects }) do
@@ -152,7 +223,7 @@ class MethodScopingTest &lt; ActiveRecord::TestCase
 end
 
 class NestedScopingTest &lt; ActiveRecord::TestCase
-  fixtures :developers, :projects, :comments, :posts
+  fixtures :authors, :developers, :projects, :comments, :posts
 
   def test_merge_options
     Developer.with_scope(:find =&gt; { :conditions =&gt; 'salary = 80000' }) do
@@ -357,6 +428,42 @@ class NestedScopingTest &lt; ActiveRecord::TestCase
       assert_equal scoped_methods, Developer.instance_eval('current_scoped_methods')
     end
   end
+
+  def test_nested_scoped_find_merges_old_style_joins
+    scoped_authors = Author.with_scope(:find =&gt; { :joins =&gt; 'INNER JOIN posts ON authors.id = posts.author_id' }) do
+      Author.with_scope(:find =&gt; { :joins =&gt; 'INNER JOIN comments ON posts.id = comments.post_id' }) do
+        Author.find(:all, :select =&gt; 'DISTINCT authors.*', :conditions =&gt; 'comments.id = 1')
+      end
+    end
+    assert scoped_authors.include?(authors(:david))
+    assert !scoped_authors.include?(authors(:mary))
+    assert_equal 1, scoped_authors.size
+    assert_equal authors(:david).attributes, scoped_authors.first.attributes
+  end
+
+  def test_nested_scoped_find_merges_new_style_joins
+    scoped_authors = Author.with_scope(:find =&gt; { :joins =&gt; :posts }) do
+      Author.with_scope(:find =&gt; { :joins =&gt; :comments }) do
+        Author.find(:all, :select =&gt; 'DISTINCT authors.*', :conditions =&gt; 'comments.id = 1')
+      end
+    end
+    assert scoped_authors.include?(authors(:david))
+    assert !scoped_authors.include?(authors(:mary))
+    assert_equal 1, scoped_authors.size
+    assert_equal authors(:david).attributes, scoped_authors.first.attributes
+  end
+
+  def test_nested_scoped_find_merges_new_and_old_style_joins
+    scoped_authors = Author.with_scope(:find =&gt; { :joins =&gt; :posts }) do
+      Author.with_scope(:find =&gt; { :joins =&gt; 'INNER JOIN comments ON posts.id = comments.post_id' }) do
+        Author.find(:all, :select =&gt; 'DISTINCT authors.*', :joins =&gt; '', :conditions =&gt; 'comments.id = 1')
+      end
+    end
+    assert scoped_authors.include?(authors(:david))
+    assert !scoped_authors.include?(authors(:mary))
+    assert_equal 1, scoped_authors.size
+    assert_equal authors(:david).attributes, scoped_authors.first.attributes
+  end
 end
 
 class HasManyScopingTest&lt; ActiveRecord::TestCase</diff>
      <filename>vendor/activerecord/test/cases/method_scoping_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -271,9 +271,9 @@ if ActiveRecord::Base.connection.supports_migrations?
       Person.connection.drop_table table_name rescue nil
     end
 
-    # SQL Server, Sybase, and SQLite3 will not allow you to add a NOT NULL
+    # Sybase, and SQLite3 will not allow you to add a NOT NULL
     # column to a table without a default value.
-    unless current_adapter?(:SQLServerAdapter, :SybaseAdapter, :SQLiteAdapter)
+    unless current_adapter?(:SybaseAdapter, :SQLiteAdapter)
       def test_add_column_not_null_without_default
         Person.connection.create_table :testings do |t|
           t.column :foo, :string
@@ -410,7 +410,7 @@ if ActiveRecord::Base.connection.supports_migrations?
       assert_equal Fixnum, bob.age.class
       assert_equal Time, bob.birthday.class
 
-      if current_adapter?(:SQLServerAdapter, :OracleAdapter, :SybaseAdapter)
+      if current_adapter?(:OracleAdapter, :SybaseAdapter)
         # Sybase, and Oracle don't differentiate between date/time
         assert_equal Time, bob.favorite_day.class
       else
@@ -851,10 +851,6 @@ if ActiveRecord::Base.connection.supports_migrations?
         # - SQLite3 stores a float, in violation of SQL
         assert_kind_of BigDecimal, b.value_of_e
         assert_equal BigDecimal(&quot;2.71828182845905&quot;), b.value_of_e
-      elsif current_adapter?(:SQLServer)
-        # - SQL Server rounds instead of truncating
-        assert_kind_of Fixnum, b.value_of_e
-        assert_equal 3, b.value_of_e
       else
         # - SQL standard is an integer
         assert_kind_of Fixnum, b.value_of_e
@@ -934,6 +930,21 @@ if ActiveRecord::Base.connection.supports_migrations?
       assert_equal(0, ActiveRecord::Migrator.current_version)
     end
 
+    if current_adapter?(:PostgreSQLAdapter)
+      def test_migrator_one_up_with_exception_and_rollback
+        assert !Person.column_methods_hash.include?(:last_name)
+
+        e = assert_raises(StandardError) do
+          ActiveRecord::Migrator.up(MIGRATIONS_ROOT + &quot;/broken&quot;, 100)
+        end
+
+        assert_equal &quot;An error has occurred, this and all later migrations canceled:\n\nSomething broke&quot;, e.message
+
+        Person.reset_column_information
+        assert !Person.column_methods_hash.include?(:last_name)
+      end
+    end
+
     def test_finds_migrations
       migrations = ActiveRecord::Migrator.new(:up, MIGRATIONS_ROOT + &quot;/valid&quot;).migrations
       [['1', 'people_have_last_names'],
@@ -952,6 +963,26 @@ if ActiveRecord::Base.connection.supports_migrations?
       migrations[0].name    == 'innocent_jointable'
     end
 
+    def test_only_loads_pending_migrations
+      # migrate up to 1
+      ActiveRecord::Migrator.up(MIGRATIONS_ROOT + &quot;/valid&quot;, 1)
+
+      # now unload the migrations that have been defined
+      PeopleHaveLastNames.unloadable
+      ActiveSupport::Dependencies.remove_unloadable_constants!
+
+      ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + &quot;/valid&quot;, nil)
+
+      assert !defined? PeopleHaveLastNames
+
+      %w(WeNeedReminders, InnocentJointable).each do |migration|
+        assert defined? migration
+      end
+
+    ensure
+      load(MIGRATIONS_ROOT + &quot;/valid/1_people_have_last_names.rb&quot;)
+    end
+
     def test_migrator_interleaved_migrations
       ActiveRecord::Migrator.up(MIGRATIONS_ROOT + &quot;/interleaved/pass_1&quot;)
 
@@ -1098,7 +1129,11 @@ if ActiveRecord::Base.connection.supports_migrations?
       columns = Person.connection.columns(:binary_testings)
       data_column = columns.detect { |c| c.name == &quot;data&quot; }
 
-      assert_nil data_column.default
+      if current_adapter?(:MysqlAdapter)
+        assert_equal '', data_column.default
+      else
+        assert_nil data_column.default
+      end
 
       Person.connection.drop_table :binary_testings rescue nil
     end</diff>
      <filename>vendor/activerecord/test/cases/migration_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -57,4 +57,29 @@ class MultipleDbTest &lt; ActiveRecord::TestCase
 
     assert Course.connection
   end
+
+  def test_transactions_across_databases
+    c1 = Course.find(1)
+    e1 = Entrant.find(1)
+
+    begin
+      Course.transaction do
+        Entrant.transaction do
+          c1.name = &quot;Typo&quot;
+          e1.name = &quot;Typo&quot;
+          c1.save
+          e1.save
+          raise &quot;No I messed up.&quot;
+        end
+      end
+    rescue
+      # Yup caught it
+    end
+
+    assert_equal &quot;Typo&quot;, c1.name
+    assert_equal &quot;Typo&quot;, e1.name
+
+    assert_equal &quot;Ruby Development&quot;, Course.find(1).name
+    assert_equal &quot;Ruby Developer&quot;, Entrant.find(1).name
+  end
 end</diff>
      <filename>vendor/activerecord/test/cases/multiple_db_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -77,6 +77,10 @@ class NamedScopeTest &lt; ActiveRecord::TestCase
     assert_equal Topic.replied.approved, Topic.replied.approved_as_string
   end
 
+  def test_scopes_can_be_specified_with_deep_hash_conditions
+    assert_equal Topic.replied.approved, Topic.replied.approved_as_hash_condition
+  end
+
   def test_scopes_are_composable
     assert_equal (approved = Topic.find(:all, :conditions =&gt; {:approved =&gt; true})), Topic.approved
     assert_equal (replied = Topic.find(:all, :conditions =&gt; 'replies_count &gt; 0')), Topic.replied
@@ -192,6 +196,55 @@ class NamedScopeTest &lt; ActiveRecord::TestCase
     end
   end
 
+  def test_any_should_not_load_results
+    topics = Topic.base
+    assert_queries(2) do
+      topics.any?    # use count query
+      topics.collect # force load
+      topics.any?    # use loaded (no query)
+    end
+  end
+
+  def test_any_should_call_proxy_found_if_using_a_block
+    topics = Topic.base
+    assert_queries(1) do
+      topics.expects(:empty?).never
+      topics.any? { true }
+    end
+  end
+
+  def test_any_should_not_fire_query_if_named_scope_loaded
+    topics = Topic.base
+    topics.collect # force load
+    assert_no_queries { assert topics.any? }
+  end
+
+  def test_should_build_with_proxy_options
+    topic = Topic.approved.build({})
+    assert topic.approved
+  end
+
+  def test_should_build_new_with_proxy_options
+    topic = Topic.approved.new
+    assert topic.approved
+  end
+
+  def test_should_create_with_proxy_options
+    topic = Topic.approved.create({})
+    assert topic.approved
+  end
+
+  def test_should_create_with_bang_with_proxy_options
+    topic = Topic.approved.create!({})
+    assert topic.approved
+  end
+  
+  def test_should_build_with_proxy_options_chained
+    topic = Topic.approved.by_lifo.build({})
+    assert topic.approved
+    assert_equal 'lifo', topic.author_name
+  end
+
   def test_find_all_should_behave_like_select
     assert_equal Topic.base.select(&amp;:approved), Topic.base.find_all(&amp;:approved)
   end
@@ -203,4 +256,25 @@ class NamedScopeTest &lt; ActiveRecord::TestCase
   def test_should_use_where_in_query_for_named_scope
     assert_equal Developer.find_all_by_name('Jamis'), Developer.find_all_by_id(Developer.jamises)
   end
+
+  def test_size_should_use_count_when_results_are_not_loaded
+    topics = Topic.base
+    assert_queries(1) do
+      assert_sql(/COUNT/i) { topics.size }
+    end
+  end
+
+  def test_size_should_use_length_when_results_are_loaded
+    topics = Topic.base
+    topics.reload # force load
+    assert_no_queries do
+      topics.size # use loaded (no query)
+    end
+  end
+
+  def test_chaining_with_duplicate_joins
+    join = &quot;INNER JOIN comments ON comments.post_id = posts.id&quot;
+    post = Post.find(1)
+    assert_equal post.comments.size, Post.scoped(:joins =&gt; join).scoped(:joins =&gt; join, :conditions =&gt; &quot;posts.id = #{post.id}&quot;).size
+  end
 end</diff>
      <filename>vendor/activerecord/test/cases/named_scope_test.rb</filename>
    </modified>
    <modified>
      <filename>vendor/activerecord/test/cases/readonly_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -160,12 +160,20 @@ class ReflectionTest &lt; ActiveRecord::TestCase
 
   def test_reflection_of_all_associations
     # FIXME these assertions bust a lot
-    assert_equal 22, Firm.reflect_on_all_associations.size
-    assert_equal 17, Firm.reflect_on_all_associations(:has_many).size
-    assert_equal 5, Firm.reflect_on_all_associations(:has_one).size
+    assert_equal 26, Firm.reflect_on_all_associations.size
+    assert_equal 20, Firm.reflect_on_all_associations(:has_many).size
+    assert_equal 6, Firm.reflect_on_all_associations(:has_one).size
     assert_equal 0, Firm.reflect_on_all_associations(:belongs_to).size
   end
 
+  def test_reflection_should_not_raise_error_when_compared_to_other_object
+    assert_nothing_raised { Firm.reflections[:clients] == Object.new }
+  end
+
+  def test_has_many_through_reflection
+    assert_kind_of ActiveRecord::Reflection::ThroughReflection, Subscriber.reflect_on_association(:books)
+  end
+
   private
     def assert_reflection(klass, association, options)
       assert reflection = klass.reflect_on_association(association)</diff>
      <filename>vendor/activerecord/test/cases/reflection_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -18,8 +18,8 @@ class SchemaAuthorizationTest &lt; ActiveRecord::TestCase
     @connection.execute &quot;SET search_path TO '$user',public&quot;
     set_session_auth
     USERS.each do |u|
-      @connection.execute &quot;CREATE USER #{u}&quot;
-      @connection.execute &quot;CREATE SCHEMA AUTHORIZATION #{u}&quot;
+      @connection.execute &quot;CREATE USER #{u}&quot; rescue nil
+      @connection.execute &quot;CREATE SCHEMA AUTHORIZATION #{u}&quot; rescue nil
       set_session_auth u
       @connection.execute &quot;CREATE TABLE #{TABLE_NAME} (#{COLUMNS.join(',')})&quot;
       @connection.execute &quot;INSERT INTO #{TABLE_NAME} (name) VALUES ('#{u}')&quot;</diff>
      <filename>vendor/activerecord/test/cases/schema_authorization_test_postgresql.rb</filename>
    </modified>
    <modified>
      <diff>@@ -2,6 +2,7 @@ require &quot;cases/helper&quot;
 require 'models/topic'
 require 'models/reply'
 require 'models/developer'
+require 'models/book'
 
 class TransactionTest &lt; ActiveRecord::TestCase
   self.use_transactional_fixtures = false
@@ -86,8 +87,7 @@ class TransactionTest &lt; ActiveRecord::TestCase
     assert Topic.find(2).approved?, &quot;Second should still be approved&quot;
   end
 
-
-  def test_callback_rollback_in_save
+  def test_raising_exception_in_callback_rollbacks_in_save
     add_exception_raising_after_save_callback_to_topic
 
     begin
@@ -102,6 +102,54 @@ class TransactionTest &lt; ActiveRecord::TestCase
     end
   end
 
+  def test_cancellation_from_before_destroy_rollbacks_in_destroy
+    add_cancelling_before_destroy_with_db_side_effect_to_topic
+    begin
+      nbooks_before_destroy = Book.count
+      status = @first.destroy
+      assert !status
+      assert_nothing_raised(ActiveRecord::RecordNotFound) { @first.reload }
+      assert_equal nbooks_before_destroy, Book.count
+    ensure
+      remove_cancelling_before_destroy_with_db_side_effect_to_topic
+    end
+  end
+
+  def test_cancellation_from_before_filters_rollbacks_in_save
+    %w(validation save).each do |filter|
+      send(&quot;add_cancelling_before_#{filter}_with_db_side_effect_to_topic&quot;)
+      begin
+        nbooks_before_save = Book.count
+        original_author_name = @first.author_name
+        @first.author_name += '_this_should_not_end_up_in_the_db'
+        status = @first.save
+        assert !status
+        assert_equal original_author_name, @first.reload.author_name
+        assert_equal nbooks_before_save, Book.count
+      ensure
+        send(&quot;remove_cancelling_before_#{filter}_with_db_side_effect_to_topic&quot;)
+      end
+    end
+  end
+
+  def test_cancellation_from_before_filters_rollbacks_in_save!
+    %w(validation save).each do |filter|
+      send(&quot;add_cancelling_before_#{filter}_with_db_side_effect_to_topic&quot;)
+      begin
+        nbooks_before_save = Book.count
+        original_author_name = @first.author_name
+        @first.author_name += '_this_should_not_end_up_in_the_db'
+        @first.save!
+        flunk
+      rescue =&gt; e
+        assert_equal original_author_name, @first.reload.author_name
+        assert_equal nbooks_before_save, Book.count
+      ensure
+        send(&quot;remove_cancelling_before_#{filter}_with_db_side_effect_to_topic&quot;)
+      end
+    end
+  end
+
   def test_callback_rollback_in_create
     new_topic = Topic.new(
       :title =&gt; &quot;A new topic&quot;,
@@ -168,6 +216,7 @@ class TransactionTest &lt; ActiveRecord::TestCase
   uses_mocha 'mocking connection.commit_db_transaction' do
     def test_rollback_when_commit_raises
       Topic.connection.expects(:begin_db_transaction)
+      Topic.connection.expects(:transaction_active?).returns(true) if current_adapter?(:PostgreSQLAdapter)
       Topic.connection.expects(:commit_db_transaction).raises('OH NOES')
       Topic.connection.expects(:rollback_db_transaction)
 
@@ -221,20 +270,21 @@ class TransactionTest &lt; ActiveRecord::TestCase
     def remove_exception_raising_after_create_callback_to_topic
       Topic.class_eval { remove_method :after_create }
     end
+
+    %w(validation save destroy).each do |filter|
+      define_method(&quot;add_cancelling_before_#{filter}_with_db_side_effect_to_topic&quot;) do
+        Topic.class_eval &quot;def before_#{filter}() Book.create; false end&quot;
+      end
+
+      define_method(&quot;remove_cancelling_before_#{filter}_with_db_side_effect_to_topic&quot;) do
+        Topic.class_eval &quot;remove_method :before_#{filter}&quot;
+      end
+    end
 end
 
 if current_adapter?(:PostgreSQLAdapter)
   class ConcurrentTransactionTest &lt; TransactionTest
-    def setup
-      @allow_concurrency = ActiveRecord::Base.allow_concurrency
-      ActiveRecord::Base.allow_concurrency = true
-      super
-    end
-
-    def teardown
-      super
-      ActiveRecord::Base.allow_concurrency = @allow_concurrency
-    end
+    use_concurrent_connections
 
     # This will cause transactions to overlap and fail unless they are performed on
     # separate database connections.</diff>
      <filename>vendor/activerecord/test/cases/transactions_test.rb</filename>
    </modified>
    <modified>
      <filename>vendor/activerecord/test/cases/unconnected_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -364,6 +364,13 @@ class ValidationsTest &lt; ActiveRecord::TestCase
     assert t2.save, &quot;Should now save t2 as unique&quot;
   end
 
+  def test_validates_uniquness_with_newline_chars
+    Topic.validates_uniqueness_of(:title, :case_sensitive =&gt; false)
+
+    t = Topic.new(&quot;title&quot; =&gt; &quot;new\nline&quot;)
+    assert t.save, &quot;Should save t as unique&quot;
+  end
+
   def test_validate_uniqueness_with_scope
     Reply.validates_uniqueness_of(:content, :scope =&gt; &quot;parent_id&quot;)
 
@@ -489,6 +496,15 @@ class ValidationsTest &lt; ActiveRecord::TestCase
     assert_not_equal &quot;has already been taken&quot;, t3.errors.on(:title)
   end
 
+  def test_validate_case_sensitive_uniqueness_with_attribute_passed_as_integer
+    Topic.validates_uniqueness_of(:title, :case_sensitve =&gt; true)
+    t = Topic.create!('title' =&gt; 101)
+
+    t2 = Topic.new('title' =&gt; 101)
+    assert !t2.valid?
+    assert t2.errors.on(:title)
+  end
+
   def test_validate_uniqueness_with_non_standard_table_names
     i1 = WarehouseThing.create(:value =&gt; 1000)
     assert !i1.valid?, &quot;i1 should not be valid&quot;
@@ -596,7 +612,7 @@ class ValidationsTest &lt; ActiveRecord::TestCase
   end
 
   def test_validate_format_with_formatted_message
-    Topic.validates_format_of(:title, :with =&gt; /^Valid Title$/, :message =&gt; &quot;can't be %s&quot;)
+    Topic.validates_format_of(:title, :with =&gt; /^Valid Title$/, :message =&gt; &quot;can't be {{value}}&quot;)
     t = Topic.create(:title =&gt; 'Invalid title')
     assert_equal &quot;can't be Invalid title&quot;, t.errors.on(:title)
   end
@@ -657,7 +673,7 @@ class ValidationsTest &lt; ActiveRecord::TestCase
   end
 
   def test_validates_inclusion_of_with_formatted_message
-    Topic.validates_inclusion_of( :title, :in =&gt; %w( a b c d e f g ), :message =&gt; &quot;option %s is not in the list&quot; )
+    Topic.validates_inclusion_of( :title, :in =&gt; %w( a b c d e f g ), :message =&gt; &quot;option {{value}} is not in the list&quot; )
 
     assert Topic.create(&quot;title&quot; =&gt; &quot;a&quot;, &quot;content&quot; =&gt; &quot;abc&quot;).valid?
 
@@ -682,7 +698,7 @@ class ValidationsTest &lt; ActiveRecord::TestCase
   end
 
   def test_validates_exclusion_of_with_formatted_message
-    Topic.validates_exclusion_of( :title, :in =&gt; %w( abe monkey ), :message =&gt; &quot;option %s is restricted&quot; )
+    Topic.validates_exclusion_of( :title, :in =&gt; %w( abe monkey ), :message =&gt; &quot;option {{value}} is restricted&quot; )
 
     assert Topic.create(&quot;title&quot; =&gt; &quot;something&quot;, &quot;content&quot; =&gt; &quot;abc&quot;)
 
@@ -782,7 +798,7 @@ class ValidationsTest &lt; ActiveRecord::TestCase
   end
 
   def test_optionally_validates_length_of_using_within_on_create
-    Topic.validates_length_of :title, :content, :within =&gt; 5..10, :on =&gt; :create, :too_long =&gt; &quot;my string is too long: %d&quot;
+    Topic.validates_length_of :title, :content, :within =&gt; 5..10, :on =&gt; :create, :too_long =&gt; &quot;my string is too long: {{count}}&quot;
 
     t = Topic.create(&quot;title&quot; =&gt; &quot;thisisnotvalid&quot;, &quot;content&quot; =&gt; &quot;whatever&quot;)
     assert !t.save
@@ -803,7 +819,7 @@ class ValidationsTest &lt; ActiveRecord::TestCase
   end
 
   def test_optionally_validates_length_of_using_within_on_update
-    Topic.validates_length_of :title, :content, :within =&gt; 5..10, :on =&gt; :update, :too_short =&gt; &quot;my string is too short: %d&quot;
+    Topic.validates_length_of :title, :content, :within =&gt; 5..10, :on =&gt; :update, :too_short =&gt; &quot;my string is too short: {{count}}&quot;
 
     t = Topic.create(&quot;title&quot; =&gt; &quot;vali&quot;, &quot;content&quot; =&gt; &quot;whatever&quot;)
     assert !t.save
@@ -865,7 +881,9 @@ class ValidationsTest &lt; ActiveRecord::TestCase
   end
 
   def test_validates_length_with_globally_modified_error_message
-    ActiveRecord::Errors.default_error_messages[:too_short] = 'tu est trops petit hombre %d'
+    ActiveSupport::Deprecation.silence do
+      ActiveRecord::Errors.default_error_messages[:too_short] = 'tu est trops petit hombre {{count}}'
+    end
     Topic.validates_length_of :title, :minimum =&gt; 10
     t = Topic.create(:title =&gt; 'too short')
     assert !t.valid?
@@ -908,7 +926,7 @@ class ValidationsTest &lt; ActiveRecord::TestCase
   end
 
   def test_validates_length_of_custom_errors_for_minimum_with_message
-    Topic.validates_length_of( :title, :minimum=&gt;5, :message=&gt;&quot;boo %d&quot; )
+    Topic.validates_length_of( :title, :minimum=&gt;5, :message=&gt;&quot;boo {{count}}&quot; )
     t = Topic.create(&quot;title&quot; =&gt; &quot;uhoh&quot;, &quot;content&quot; =&gt; &quot;whatever&quot;)
     assert !t.valid?
     assert t.errors.on(:title)
@@ -916,7 +934,7 @@ class ValidationsTest &lt; ActiveRecord::TestCase
   end
 
   def test_validates_length_of_custom_errors_for_minimum_with_too_short
-    Topic.validates_length_of( :title, :minimum=&gt;5, :too_short=&gt;&quot;hoo %d&quot; )
+    Topic.validates_length_of( :title, :minimum=&gt;5, :too_short=&gt;&quot;hoo {{count}}&quot; )
     t = Topic.create(&quot;title&quot; =&gt; &quot;uhoh&quot;, &quot;content&quot; =&gt; &quot;whatever&quot;)
     assert !t.valid?
     assert t.errors.on(:title)
@@ -924,7 +942,7 @@ class ValidationsTest &lt; ActiveRecord::TestCase
   end
 
   def test_validates_length_of_custom_errors_for_maximum_with_message
-    Topic.validates_length_of( :title, :maximum=&gt;5, :message=&gt;&quot;boo %d&quot; )
+    Topic.validates_length_of( :title, :maximum=&gt;5, :message=&gt;&quot;boo {{count}}&quot; )
     t = Topic.create(&quot;title&quot; =&gt; &quot;uhohuhoh&quot;, &quot;content&quot; =&gt; &quot;whatever&quot;)
     assert !t.valid?
     assert t.errors.on(:title)
@@ -932,7 +950,7 @@ class ValidationsTest &lt; ActiveRecord::TestCase
   end
 
   def test_validates_length_of_custom_errors_for_maximum_with_too_long
-    Topic.validates_length_of( :title, :maximum=&gt;5, :too_long=&gt;&quot;hoo %d&quot; )
+    Topic.validates_length_of( :title, :maximum=&gt;5, :too_long=&gt;&quot;hoo {{count}}&quot; )
     t = Topic.create(&quot;title&quot; =&gt; &quot;uhohuhoh&quot;, &quot;content&quot; =&gt; &quot;whatever&quot;)
     assert !t.valid?
     assert t.errors.on(:title)
@@ -940,7 +958,7 @@ class ValidationsTest &lt; ActiveRecord::TestCase
   end
 
   def test_validates_length_of_custom_errors_for_is_with_message
-    Topic.validates_length_of( :title, :is=&gt;5, :message=&gt;&quot;boo %d&quot; )
+    Topic.validates_length_of( :title, :is=&gt;5, :message=&gt;&quot;boo {{count}}&quot; )
     t = Topic.create(&quot;title&quot; =&gt; &quot;uhohuhoh&quot;, &quot;content&quot; =&gt; &quot;whatever&quot;)
     assert !t.valid?
     assert t.errors.on(:title)
@@ -948,7 +966,7 @@ class ValidationsTest &lt; ActiveRecord::TestCase
   end
 
   def test_validates_length_of_custom_errors_for_is_with_wrong_length
-    Topic.validates_length_of( :title, :is=&gt;5, :wrong_length=&gt;&quot;hoo %d&quot; )
+    Topic.validates_length_of( :title, :is=&gt;5, :wrong_length=&gt;&quot;hoo {{count}}&quot; )
     t = Topic.create(&quot;title&quot; =&gt; &quot;uhohuhoh&quot;, &quot;content&quot; =&gt; &quot;whatever&quot;)
     assert !t.valid?
     assert t.errors.on(:title)
@@ -1014,7 +1032,7 @@ class ValidationsTest &lt; ActiveRecord::TestCase
 
   def test_optionally_validates_length_of_using_within_on_create_utf8
     with_kcode('UTF8') do
-      Topic.validates_length_of :title, :within =&gt; 5..10, :on =&gt; :create, :too_long =&gt; &quot;&#38263;&#12377;&#12366;&#12414;&#12377;: %d&quot;
+      Topic.validates_length_of :title, :within =&gt; 5..10, :on =&gt; :create, :too_long =&gt; &quot;&#38263;&#12377;&#12366;&#12414;&#12377;: {{count}}&quot;
 
       t = Topic.create(&quot;title&quot; =&gt; &quot;&#19968;&#20108;&#19977;&#22235;&#20116;&#20845;&#19971;&#20843;&#20061;&#21313;A&quot;, &quot;content&quot; =&gt; &quot;whatever&quot;)
       assert !t.save
@@ -1037,7 +1055,7 @@ class ValidationsTest &lt; ActiveRecord::TestCase
 
   def test_optionally_validates_length_of_using_within_on_update_utf8
     with_kcode('UTF8') do
-      Topic.validates_length_of :title, :within =&gt; 5..10, :on =&gt; :update, :too_short =&gt; &quot;&#30701;&#12377;&#12366;&#12414;&#12377;: %d&quot;
+      Topic.validates_length_of :title, :within =&gt; 5..10, :on =&gt; :update, :too_short =&gt; &quot;&#30701;&#12377;&#12366;&#12414;&#12377;: {{count}}&quot;
 
       t = Topic.create(&quot;title&quot; =&gt; &quot;&#19968;&#20108;&#19977;4&quot;, &quot;content&quot; =&gt; &quot;whatever&quot;)
       assert !t.save
@@ -1072,7 +1090,7 @@ class ValidationsTest &lt; ActiveRecord::TestCase
   end
 
   def test_validates_length_of_with_block
-    Topic.validates_length_of :content, :minimum =&gt; 5, :too_short=&gt;&quot;Your essay must be at least %d words.&quot;, 
+    Topic.validates_length_of :content, :minimum =&gt; 5, :too_short=&gt;&quot;Your essay must be at least {{count}} words.&quot;,
                                         :tokenizer =&gt; lambda {|str| str.scan(/\w+/) }
     t = Topic.create!(:content =&gt; &quot;this content should be long enough&quot;)
     assert t.valid?
@@ -1223,7 +1241,7 @@ class ValidationsTest &lt; ActiveRecord::TestCase
 
   def test_if_validation_using_method_true
     # When the method returns true
-    Topic.validates_length_of( :title, :maximum=&gt;5, :too_long=&gt;&quot;hoo %d&quot;, :if =&gt; :condition_is_true )
+    Topic.validates_length_of( :title, :maximum=&gt;5, :too_long=&gt;&quot;hoo {{count}}&quot;, :if =&gt; :condition_is_true )
     t = Topic.create(&quot;title&quot; =&gt; &quot;uhohuhoh&quot;, &quot;content&quot; =&gt; &quot;whatever&quot;)
     assert !t.valid?
     assert t.errors.on(:title)
@@ -1232,7 +1250,7 @@ class ValidationsTest &lt; ActiveRecord::TestCase
 
   def test_unless_validation_using_method_true
     # When the method returns true
-    Topic.validates_length_of( :title, :maximum=&gt;5, :too_long=&gt;&quot;hoo %d&quot;, :unless =&gt; :condition_is_true )
+    Topic.validates_length_of( :title, :maximum=&gt;5, :too_long=&gt;&quot;hoo {{count}}&quot;, :unless =&gt; :condition_is_true )
     t = Topic.create(&quot;title&quot; =&gt; &quot;uhohuhoh&quot;, &quot;content&quot; =&gt; &quot;whatever&quot;)
     assert t.valid?
     assert !t.errors.on(:title)
@@ -1240,7 +1258,7 @@ class ValidationsTest &lt; ActiveRecord::TestCase
 
   def test_if_validation_using_method_false
     # When the method returns false
-    Topic.validates_length_of( :title, :maximum=&gt;5, :too_long=&gt;&quot;hoo %d&quot;, :if =&gt; :condition_is_true_but_its_not )
+    Topic.validates_length_of( :title, :maximum=&gt;5, :too_long=&gt;&quot;hoo {{count}}&quot;, :if =&gt; :condition_is_true_but_its_not )
     t = Topic.create(&quot;title&quot; =&gt; &quot;uhohuhoh&quot;, &quot;content&quot; =&gt; &quot;whatever&quot;)
     assert t.valid?
     assert !t.errors.on(:title)
@@ -1248,7 +1266,7 @@ class ValidationsTest &lt; ActiveRecord::TestCase
 
   def test_unless_validation_using_method_false
     # When the method returns false
-    Topic.validates_length_of( :title, :maximum=&gt;5, :too_long=&gt;&quot;hoo %d&quot;, :unless =&gt; :condition_is_true_but_its_not )
+    Topic.validates_length_of( :title, :maximum=&gt;5, :too_long=&gt;&quot;hoo {{count}}&quot;, :unless =&gt; :condition_is_true_but_its_not )
     t = Topic.create(&quot;title&quot; =&gt; &quot;uhohuhoh&quot;, &quot;content&quot; =&gt; &quot;whatever&quot;)
     assert !t.valid?
     assert t.errors.on(:title)
@@ -1257,7 +1275,7 @@ class ValidationsTest &lt; ActiveRecord::TestCase
 
   def test_if_validation_using_string_true
     # When the evaluated string returns true
-    Topic.validates_length_of( :title, :maximum=&gt;5, :too_long=&gt;&quot;hoo %d&quot;, :if =&gt; &quot;a = 1; a == 1&quot; )
+    Topic.validates_length_of( :title, :maximum=&gt;5, :too_long=&gt;&quot;hoo {{count}}&quot;, :if =&gt; &quot;a = 1; a == 1&quot; )
     t = Topic.create(&quot;title&quot; =&gt; &quot;uhohuhoh&quot;, &quot;content&quot; =&gt; &quot;whatever&quot;)
     assert !t.valid?
     assert t.errors.on(:title)
@@ -1266,7 +1284,7 @@ class ValidationsTest &lt; ActiveRecord::TestCase
 
   def test_unless_validation_using_string_true
     # When the evaluated string returns true
-    Topic.validates_length_of( :title, :maximum=&gt;5, :too_long=&gt;&quot;hoo %d&quot;, :unless =&gt; &quot;a = 1; a == 1&quot; )
+    Topic.validates_length_of( :title, :maximum=&gt;5, :too_long=&gt;&quot;hoo {{count}}&quot;, :unless =&gt; &quot;a = 1; a == 1&quot; )
     t = Topic.create(&quot;title&quot; =&gt; &quot;uhohuhoh&quot;, &quot;content&quot; =&gt; &quot;whatever&quot;)
     assert t.valid?
     assert !t.errors.on(:title)
@@ -1274,7 +1292,7 @@ class ValidationsTest &lt; ActiveRecord::TestCase
 
   def test_if_validation_using_string_false
     # When the evaluated string returns false
-    Topic.validates_length_of( :title, :maximum=&gt;5, :too_long=&gt;&quot;hoo %d&quot;, :if =&gt; &quot;false&quot;)
+    Topic.validates_length_of( :title, :maximum=&gt;5, :too_long=&gt;&quot;hoo {{count}}&quot;, :if =&gt; &quot;false&quot;)
     t = Topic.create(&quot;title&quot; =&gt; &quot;uhohuhoh&quot;, &quot;content&quot; =&gt; &quot;whatever&quot;)
     assert t.valid?
     assert !t.errors.on(:title)
@@ -1282,7 +1300,7 @@ class ValidationsTest &lt; ActiveRecord::TestCase
 
   def test_unless_validation_using_string_false
     # When the evaluated string returns false
-    Topic.validates_length_of( :title, :maximum=&gt;5, :too_long=&gt;&quot;hoo %d&quot;, :unless =&gt; &quot;false&quot;)
+    Topic.validates_length_of( :title, :maximum=&gt;5, :too_long=&gt;&quot;hoo {{count}}&quot;, :unless =&gt; &quot;false&quot;)
     t = Topic.create(&quot;title&quot; =&gt; &quot;uhohuhoh&quot;, &quot;content&quot; =&gt; &quot;whatever&quot;)
     assert !t.valid?
     assert t.errors.on(:title)
@@ -1291,7 +1309,7 @@ class ValidationsTest &lt; ActiveRecord::TestCase
 
   def test_if_validation_using_block_true
     # When the block returns true
-    Topic.validates_length_of( :title, :maximum=&gt;5, :too_long=&gt;&quot;hoo %d&quot;,
+    Topic.validates_length_of( :title, :maximum=&gt;5, :too_long=&gt;&quot;hoo {{count}}&quot;,
       :if =&gt; Proc.new { |r| r.content.size &gt; 4 } )
     t = Topic.create(&quot;title&quot; =&gt; &quot;uhohuhoh&quot;, &quot;content&quot; =&gt; &quot;whatever&quot;)
     assert !t.valid?
@@ -1301,7 +1319,7 @@ class ValidationsTest &lt; ActiveRecord::TestCase
 
   def test_unless_validation_using_block_true
     # When the block returns true
-    Topic.validates_length_of( :title, :maximum=&gt;5, :too_long=&gt;&quot;hoo %d&quot;,
+    Topic.validates_length_of( :title, :maximum=&gt;5, :too_long=&gt;&quot;hoo {{count}}&quot;,
       :unless =&gt; Proc.new { |r| r.content.size &gt; 4 } )
     t = Topic.create(&quot;title&quot; =&gt; &quot;uhohuhoh&quot;, &quot;content&quot; =&gt; &quot;whatever&quot;)
     assert t.valid?
@@ -1310,7 +1328,7 @@ class ValidationsTest &lt; ActiveRecord::TestCase
 
   def test_if_validation_using_block_false
     # When the block returns false
-    Topic.validates_length_of( :title, :maximum=&gt;5, :too_long=&gt;&quot;hoo %d&quot;,
+    Topic.validates_length_of( :title, :maximum=&gt;5, :too_long=&gt;&quot;hoo {{count}}&quot;,
       :if =&gt; Proc.new { |r| r.title != &quot;uhohuhoh&quot;} )
     t = Topic.create(&quot;title&quot; =&gt; &quot;uhohuhoh&quot;, &quot;content&quot; =&gt; &quot;whatever&quot;)
     assert t.valid?
@@ -1319,7 +1337,7 @@ class ValidationsTest &lt; ActiveRecord::TestCase
 
   def test_unless_validation_using_block_false
     # When the block returns false
-    Topic.validates_length_of( :title, :maximum=&gt;5, :too_long=&gt;&quot;hoo %d&quot;,
+    Topic.validates_length_of( :title, :maximum=&gt;5, :too_long=&gt;&quot;hoo {{count}}&quot;,
       :unless =&gt; Proc.new { |r| r.title != &quot;uhohuhoh&quot;} )
     t = Topic.create(&quot;title&quot; =&gt; &quot;uhohuhoh&quot;, &quot;content&quot; =&gt; &quot;whatever&quot;)
     assert !t.valid?
@@ -1421,8 +1439,8 @@ class ValidatesNumericalityTest &lt; ActiveRecord::TestCase
   def test_validates_numericality_of_with_nil_allowed
     Topic.validates_numericality_of :approved, :allow_nil =&gt; true
 
-    invalid!(BLANK + JUNK)
-    valid!(NIL + FLOATS + INTEGERS + BIGDECIMAL + INFINITY)
+    invalid!(JUNK)
+    valid!(NIL + BLANK + FLOATS + INTEGERS + BIGDECIMAL + INFINITY)
   end
 
   def test_validates_numericality_of_with_integer_only
@@ -1435,8 +1453,8 @@ class ValidatesNumericalityTest &lt; ActiveRecord::TestCase
   def test_validates_numericality_of_with_integer_only_and_nil_allowed
     Topic.validates_numericality_of :approved, :only_integer =&gt; true, :allow_nil =&gt; true
 
-    invalid!(BLANK + JUNK + FLOATS + BIGDECIMAL + INFINITY)
-    valid!(NIL + INTEGERS)
+    invalid!(JUNK + FLOATS + BIGDECIMAL + INFINITY)
+    valid!(NIL + BLANK + INTEGERS)
   end
 
   def test_validates_numericality_with_greater_than
@@ -1496,13 +1514,13 @@ class ValidatesNumericalityTest &lt; ActiveRecord::TestCase
   end
 
   def test_validates_numericality_with_numeric_message
-    Topic.validates_numericality_of :approved, :less_than =&gt; 4, :message =&gt; &quot;smaller than %d&quot;
+    Topic.validates_numericality_of :approved, :less_than =&gt; 4, :message =&gt; &quot;smaller than {{count}}&quot;
     topic = Topic.new(&quot;title&quot; =&gt; &quot;numeric test&quot;, &quot;approved&quot; =&gt; 10)
 
     assert !topic.valid?
     assert_equal &quot;smaller than 4&quot;, topic.errors.on(:approved)
 
-    Topic.validates_numericality_of :approved, :greater_than =&gt; 4, :message =&gt; &quot;greater than %d&quot;
+    Topic.validates_numericality_of :approved, :greater_than =&gt; 4, :message =&gt; &quot;greater than {{count}}&quot;
     topic = Topic.new(&quot;title&quot; =&gt; &quot;numeric test&quot;, &quot;approved&quot; =&gt; 1)
 
     assert !topic.valid?</diff>
      <filename>vendor/activerecord/test/cases/validations_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -2,9 +2,7 @@ print &quot;Using native MySQL\n&quot;
 require_dependency 'models/course'
 require 'logger'
 
-RAILS_DEFAULT_LOGGER = Logger.new('debug.log')
-RAILS_DEFAULT_LOGGER.level = Logger::DEBUG
-ActiveRecord::Base.logger = RAILS_DEFAULT_LOGGER
+ActiveRecord::Base.logger = Logger.new(&quot;debug.log&quot;)
 
 # GRANT ALL PRIVILEGES ON activerecord_unittest.* to 'rails'@'localhost';
 # GRANT ALL PRIVILEGES ON activerecord_unittest2.* to 'rails'@'localhost';</diff>
      <filename>vendor/activerecord/test/connections/native_mysql/connection.rb</filename>
    </modified>
    <modified>
      <diff>@@ -5,6 +5,7 @@ first_client:
   client_of: 2
   name: Summit
   ruby_type: Client
+  firm_name: 37signals
 
 first_firm:
   id: 1</diff>
      <filename>vendor/activerecord/test/fixtures/companies.yml</filename>
    </modified>
    <modified>
      <diff>@@ -6,7 +6,7 @@ david:
   address_city: Scary Town
   address_country: Loony Land
   gps_location: 35.544623640962634x-105.9309951055148
-  
+
 zaphod:
   id: 2
   name: Zaphod
@@ -14,4 +14,13 @@ zaphod:
   address_street: Avenue Road
   address_city: Hamlet Town
   address_country: Nation Land
+  gps_location: NULL
+
+barney:
+  id: 3
+  name: Barney Gumble
+  balance: 1
+  address_street: Quiet Road
+  address_city: Peaceful Town
+  address_country: Tranquil Land
   gps_location: NULL
\ No newline at end of file</diff>
      <filename>vendor/activerecord/test/fixtures/customers.yml</filename>
    </modified>
    <modified>
      <diff></diff>
      <filename>vendor/activerecord/test/fixtures/fixture_database.sqlite3</filename>
    </modified>
    <modified>
      <diff></diff>
      <filename>vendor/activerecord/test/fixtures/fixture_database_2.sqlite3</filename>
    </modified>
    <modified>
      <diff>@@ -2,6 +2,7 @@ class Author &lt; ActiveRecord::Base
   has_many :posts
   has_many :posts_with_comments, :include =&gt; :comments, :class_name =&gt; &quot;Post&quot;
   has_many :posts_with_comments_sorted_by_comment_id, :include =&gt; :comments, :class_name =&gt; &quot;Post&quot;, :order =&gt; 'comments.id'
+  has_many :posts_sorted_by_id_limited, :class_name =&gt; &quot;Post&quot;, :order =&gt; 'posts.id', :limit =&gt; 1
   has_many :posts_with_categories, :include =&gt; :categories, :class_name =&gt; &quot;Post&quot;
   has_many :posts_with_comments_and_categories, :include =&gt; [ :comments, :categories ], :order =&gt; &quot;posts.id&quot;, :class_name =&gt; &quot;Post&quot;
   has_many :posts_containing_the_letter_a, :class_name =&gt; &quot;Post&quot;
@@ -16,6 +17,8 @@ class Author &lt; ActiveRecord::Base
       proxy_target
     end
   end
+  has_one  :post_about_thinking, :class_name =&gt; 'Post', :conditions =&gt; &quot;posts.title like '%thinking%'&quot;
+  has_one  :post_about_thinking_with_last_comment, :class_name =&gt; 'Post', :conditions =&gt; &quot;posts.title like '%thinking%'&quot;, :include =&gt; :last_comment
   has_many :comments, :through =&gt; :posts
   has_many :comments_containing_the_letter_e, :through =&gt; :posts, :source =&gt; :comments
   has_many :comments_with_order_and_conditions, :through =&gt; :posts, :source =&gt; :comments, :order =&gt; 'comments.body', :conditions =&gt; &quot;comments.body like 'Thank%'&quot;</diff>
      <filename>vendor/activerecord/test/models/author.rb</filename>
    </modified>
    <modified>
      <diff>@@ -13,6 +13,9 @@ class Category &lt; ActiveRecord::Base
   has_and_belongs_to_many :post_with_conditions,
                           :class_name =&gt; 'Post',
                           :conditions =&gt; { :title =&gt; 'Yet Another Testing Title' }
+
+  has_and_belongs_to_many :posts_gruoped_by_title, :class_name =&gt; &quot;Post&quot;, :group =&gt; &quot;title&quot;, :select =&gt; &quot;title&quot;
+
   def self.what_are_you
     'a category...'
   end</diff>
      <filename>vendor/activerecord/test/models/category.rb</filename>
    </modified>
    <modified>
      <diff>@@ -4,4 +4,10 @@ class Club &lt; ActiveRecord::Base
   has_many :current_memberships
   has_one :sponsor
   has_one :sponsored_member, :through =&gt; :sponsor, :source =&gt; :sponsorable, :source_type =&gt; &quot;Member&quot;
+
+  private
+
+  def private_method
+    &quot;I'm sorry sir, this is a *private* club, not a *pirate* club&quot;
+  end
 end
\ No newline at end of file</diff>
      <filename>vendor/activerecord/test/models/club.rb</filename>
    </modified>
    <modified>
      <diff>@@ -13,6 +13,12 @@ class Company &lt; AbstractCompany
   def arbitrary_method
     &quot;I am Jack's profound disappointment&quot;
   end
+
+  private
+
+  def private_method
+    &quot;I am Jack's innermost fears and aspirations&quot;
+  end
 end
 
 module Namespaced
@@ -53,11 +59,16 @@ class Firm &lt; Company
   has_many :clients_using_finder_sql, :class_name =&gt; &quot;Client&quot;, :finder_sql =&gt; 'SELECT * FROM companies WHERE 1=1'
   has_many :plain_clients, :class_name =&gt; 'Client'
   has_many :readonly_clients, :class_name =&gt; 'Client', :readonly =&gt; true
+  has_many :clients_using_primary_key, :class_name =&gt; 'Client',
+           :primary_key =&gt; 'name', :foreign_key =&gt; 'firm_name'
+  has_many :clients_grouped_by_firm_id, :class_name =&gt; &quot;Client&quot;, :group =&gt; &quot;firm_id&quot;, :select =&gt; &quot;firm_id&quot;
+  has_many :clients_grouped_by_name, :class_name =&gt; &quot;Client&quot;, :group =&gt; &quot;name&quot;, :select =&gt; &quot;name&quot;
 
   has_one :account, :foreign_key =&gt; &quot;firm_id&quot;, :dependent =&gt; :destroy, :validate =&gt; true
   has_one :unvalidated_account, :foreign_key =&gt; &quot;firm_id&quot;, :class_name =&gt; 'Account', :validate =&gt; false
   has_one :account_with_select, :foreign_key =&gt; &quot;firm_id&quot;, :select =&gt; &quot;id, firm_id&quot;, :class_name=&gt;'Account'
   has_one :readonly_account, :foreign_key =&gt; &quot;firm_id&quot;, :class_name =&gt; &quot;Account&quot;, :readonly =&gt; true
+  has_one :account_using_primary_key, :primary_key =&gt; &quot;firm_id&quot;, :class_name =&gt; &quot;Account&quot;
 end
 
 class DependentFirm &lt; Company
@@ -101,6 +112,14 @@ class Client &lt; Company
   def rating?
     query_attribute :rating
   end
+
+  class &lt;&lt; self
+    private
+
+    def private_method
+      &quot;darkness&quot;
+    end
+  end
 end
 
 
@@ -124,9 +143,14 @@ class Account &lt; ActiveRecord::Base
     true
   end
 
-
   protected
     def validate
       errors.add_on_empty &quot;credit_limit&quot;
     end
+
+  private
+
+  def private_method
+    &quot;Sir, yes sir!&quot;
+  end
 end</diff>
      <filename>vendor/activerecord/test/models/company.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,7 +1,8 @@
 class Customer &lt; ActiveRecord::Base
   composed_of :address, :mapping =&gt; [ %w(address_street street), %w(address_city city), %w(address_country country) ], :allow_nil =&gt; true
-  composed_of(:balance, :class_name =&gt; &quot;Money&quot;, :mapping =&gt; %w(balance amount)) { |balance| balance.to_money }
+  composed_of :balance, :class_name =&gt; &quot;Money&quot;, :mapping =&gt; %w(balance amount), :converter =&gt; Proc.new { |balance| balance.to_money }
   composed_of :gps_location, :allow_nil =&gt; true
+  composed_of :fullname, :mapping =&gt; %w(name to_s), :constructor =&gt; Proc.new { |name| Fullname.parse(name) }, :converter =&gt; :parse
 end
 
 class Address
@@ -53,3 +54,20 @@ class GpsLocation
     self.latitude == other.latitude &amp;&amp; self.longitude == other.longitude
   end
 end
+
+class Fullname
+  attr_reader :first, :last
+
+  def self.parse(str)
+    return nil unless str
+    new(*str.to_s.split)
+  end
+
+  def initialize(first, last = nil)
+    @first, @last = first, last
+  end
+
+  def to_s
+    &quot;#{first} #{last.upcase}&quot;
+  end
+end
\ No newline at end of file</diff>
      <filename>vendor/activerecord/test/models/customer.rb</filename>
    </modified>
    <modified>
      <diff>@@ -6,4 +6,6 @@ class Member &lt; ActiveRecord::Base
   has_one :favourite_club, :through =&gt; :memberships, :conditions =&gt; [&quot;memberships.favourite = ?&quot;, true], :source =&gt; :club
   has_one :sponsor, :as =&gt; :sponsorable
   has_one :sponsor_club, :through =&gt; :sponsor
+  has_one :member_detail
+  has_one :organization, :through =&gt; :member_detail
 end
\ No newline at end of file</diff>
      <filename>vendor/activerecord/test/models/member.rb</filename>
    </modified>
    <modified>
      <diff>@@ -3,6 +3,7 @@ class Parrot &lt; ActiveRecord::Base
   has_and_belongs_to_many :pirates
   has_and_belongs_to_many :treasures
   has_many :loots, :as =&gt; :looter
+  alias_attribute :title, :name
 end
 
 class LiveParrot &lt; Parrot</diff>
      <filename>vendor/activerecord/test/models/parrot.rb</filename>
    </modified>
    <modified>
      <diff>@@ -13,6 +13,7 @@ class Post &lt; ActiveRecord::Base
   end
 
   belongs_to :author_with_posts, :class_name =&gt; &quot;Author&quot;, :foreign_key =&gt; :author_id, :include =&gt; :posts
+  belongs_to :author_with_address, :class_name =&gt; &quot;Author&quot;, :foreign_key =&gt; :author_id, :include =&gt; :author_address
 
   has_one :last_comment, :class_name =&gt; 'Comment', :order =&gt; 'id desc'
 
@@ -22,6 +23,8 @@ class Post &lt; ActiveRecord::Base
     end
   end
 
+  has_many :author_favorites, :through =&gt; :author
+
   has_many :comments_with_interpolated_conditions, :class_name =&gt; 'Comment',
       :conditions =&gt; ['#{&quot;#{aliased_table_name}.&quot; rescue &quot;&quot;}body = ?', 'Thank you for the welcome']
 </diff>
      <filename>vendor/activerecord/test/models/post.rb</filename>
    </modified>
    <modified>
      <filename>vendor/activerecord/test/models/reply.rb</filename>
    </modified>
    <modified>
      <diff>@@ -4,6 +4,9 @@ class Topic &lt; ActiveRecord::Base
     { :conditions =&gt; ['written_on &lt; ?', time] }
   }
   named_scope :approved, :conditions =&gt; {:approved =&gt; true}
+  named_scope :by_lifo, :conditions =&gt; {:author_name =&gt; 'lifo'}
+  
+  named_scope :approved_as_hash_condition, :conditions =&gt; {:topics =&gt; {:approved =&gt; true}}
   named_scope 'approved_as_string', :conditions =&gt; {:approved =&gt; true}
   named_scope :replied, :conditions =&gt; ['replies_count &gt; 0']
   named_scope :anonymous_extension do</diff>
      <filename>vendor/activerecord/test/models/topic.rb</filename>
    </modified>
    <modified>
      <diff>@@ -60,7 +60,7 @@ ActiveRecord::Schema.define do
   end
 
   create_table :booleantests, :force =&gt; true do |t|
-    t.integer :value
+    t.boolean :value
   end
 
   create_table :categories, :force =&gt; true do |t|
@@ -103,6 +103,7 @@ ActiveRecord::Schema.define do
     t.string  :type
     t.string  :ruby_type
     t.integer :firm_id
+    t.string  :firm_name
     t.string  :name
     t.integer :client_of
     t.integer :rating, :default =&gt; 1
@@ -196,6 +197,12 @@ ActiveRecord::Schema.define do
     t.string :name
   end
 
+  create_table :member_details, :force =&gt; true do |t|
+    t.integer :member_id
+    t.integer :organization_id
+    t.string :extra_data
+  end
+
   create_table :memberships, :force =&gt; true do |t|
     t.datetime :joined_on
     t.integer :club_id, :member_id
@@ -248,6 +255,10 @@ ActiveRecord::Schema.define do
     t.integer :shipping_customer_id
   end
 
+  create_table :organizations, :force =&gt; true do |t|
+    t.string :name
+  end
+
   create_table :owners, :primary_key =&gt; :owner_id ,:force =&gt; true do |t|
     t.string :name
   end</diff>
      <filename>vendor/activerecord/test/schema/schema.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,12 +1,76 @@
-*2.1.1 (September 4th, 2008)*
+*2.2 (November 21st, 2008)*
 
-* Fix Ruby's Time marshaling bug in pre-1.9 versions of Ruby: utc instances are now correctly unmarshaled with a utc zone instead of the system local zone [#900 state:resolved]:activesupport/CHANGELOG
+* TimeZone offset tests: use current_period, to ensure TimeZone#utc_offset is up-to-date [Geoff Buesing]
 
-* TimeWithZone: when crossing DST boundary, treat Durations of days, months or years as variable-length, and all other values as absolute length. A time + 24.hours will advance exactly 24 hours, but a time + 1.day will advance 23-25 hours, depending on the day. Ensure consistent behavior across all advancing methods [Geoff Buesing]
+* Update bundled TZInfo to 0.3.12 [Geoff Buesing]
+
+* Increment the version of our altered memcache-client to prevent confusion caused when the 1.5.0 gem is installed.
+
+* Fixed the option merging in Array#to_xml #1126 [Rudolf Gavlas]
+
+* Make I18n::Backend::Simple reload its translations in development mode [DHH/Sven Fuchs]
+
+* TimeWithZone#freeze: preload instance variables so that we can actually freeze [Geoff Buesing]
+
+* Fix Brasilia timezone #1180 [Marcus Derencius, Kane]
+
+* Time#advance recognizes fractional days and weeks. Deprecate Durations of fractional months and years #970 [Tom Lea]
+
+* Add ActiveSupport::Rescuable module abstracting ActionController::Base rescue_from features. [Norbert Crombach, Pratik]
+
+* Switch from String#chars to String#mb_chars for the unicode proxy.  [Manfred Stienstra]
+
+  This helps with 1.8.7 compatibility and also improves performance for some operations by reducing indirection.
+
+* TimeWithZone #wday, #yday and #to_date avoid trip through #method_missing [Geoff Buesing]
+
+* Added Time, Date, DateTime and TimeWithZone #past?, #future? and #today? #720 [Clemens Kofler, Geoff Buesing]
+
+* Fixed Sri Jayawardenepura time zone to map to Asia/Colombo [Jamis Buck]
+
+* Added Inflector#parameterize for easy slug generation (&quot;Donald E. Knuth&quot;.parameterize =&gt; &quot;donald-e-knuth&quot;) #713 [Matt Darby]
+
+* Changed cache benchmarking to be reported in milliseconds [DHH]
+
+* Fix Ruby's Time marshaling bug in pre-1.9 versions of Ruby: utc instances are now correctly unmarshaled with a utc zone instead of the system local zone [#900 state:resolved] [Luca Guidi, Geoff Buesing]
+
+* Add Array#in_groups which splits or iterates over the array in specified number of groups. #579. [Adrian Mugnolo] Example:
+  
+  a = (1..10).to_a
+  a.in_groups(3)        #=&gt; [[1, 2, 3, 4], [5, 6, 7, nil], [8, 9, 10, nil]]
+  a.in_groups(3, false) #=&gt; [[1, 2, 3, 4], [5, 6, 7], [8, 9, 10]]
 
 * Fix TimeWithZone unmarshaling: coerce unmarshaled Time instances to utc, because Ruby's marshaling of Time instances doesn't respect the zone [Geoff Buesing]
 
-* Added StringQuestioneer for doing things like StringQuestioneer.new(&quot;production&quot;).production? # =&gt; true and StringQuestioneer.new(&quot;production&quot;).development? # =&gt; false [DHH]
+* Added Memoizable mixin for caching simple lazy loaded attributes [Josh Peek]
+
+* Move the test related core_ext stuff out of core_ext so it's only loaded by the test helpers.  [Michael Koziarski]
+
+* Add Inflection rules for String#humanize. #535 [dcmanges]
+
+  ActiveSupport::Inflector.inflections do |inflect|
+    inflect.human(/_cnt$/i, '\1_count')
+  end
+
+  'jargon_cnt'.humanize # =&gt; 'Jargon count'
+
+* TimeWithZone: when crossing DST boundary, treat Durations of days, months or years as variable-length, and all other values as absolute length. A time + 24.hours will advance exactly 24 hours, but a time + 1.day will advance 23-25 hours, depending on the day. Ensure consistent behavior across all advancing methods [Geoff Buesing]
+
+* Added TimeZone #=~, to support matching zones by regex in time_zone_select. #195 [Ernie Miller]
+
+* Added Array#second through Array#fifth as aliases for Array#[1] through Array#[4] + Array#forty_two as alias for Array[41] [DHH]
+
+* Added test/do declaration style testing to ActiveSupport::TestCase [DHH via Jay Fields]
+
+* Added Object#present? which is equivalent to !Object#blank? [DHH]
+
+* Added Enumberable#many? to encapsulate collection.size &gt; 1 [DHH/Damian Janowski]
+
+* Add more standard Hash methods to ActiveSupport::OrderedHash [Steve Purcell]
+
+* Namespace Inflector, Dependencies, OrderedOptions, and TimeZone under ActiveSupport [Josh Peek]
+
+* Added StringInquirer for doing things like StringInquirer.new(&quot;production&quot;).production? # =&gt; true and StringInquirer.new(&quot;production&quot;).development? # =&gt; false [DHH]
 
 * Fixed Date#end_of_quarter to not blow up on May 31st [#289 state:resolved] (Danger)
 </diff>
      <filename>vendor/activesupport/CHANGELOG</filename>
    </modified>
    <modified>
      <diff>@@ -21,8 +21,6 @@
 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #++
 
-$:.unshift(File.dirname(__FILE__))
-
 require 'active_support/vendor'
 require 'active_support/basic_object'
 require 'active_support/inflector'
@@ -30,7 +28,6 @@ require 'active_support/callbacks'
 
 require 'active_support/core_ext'
 
-require 'active_support/clean_logger'
 require 'active_support/buffered_logger'
 
 require 'active_support/gzip'
@@ -43,6 +40,7 @@ require 'active_support/ordered_hash'
 require 'active_support/ordered_options'
 require 'active_support/option_merger'
 
+require 'active_support/memoizable'
 require 'active_support/string_inquirer'
 
 require 'active_support/values/time_zone'
@@ -56,6 +54,8 @@ require 'active_support/base64'
 
 require 'active_support/time_with_zone'
 
-Inflector = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('Inflector', 'ActiveSupport::Inflector')
-Dependencies = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('Dependencies', 'ActiveSupport::Dependencies')
-TimeZone = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('TimeZone', 'ActiveSupport::TimeZone')
+require 'active_support/secure_random'
+
+require 'active_support/rescuable'
+
+I18n.load_path &lt;&lt; File.dirname(__FILE__) + '/active_support/locale/en.yml'</diff>
      <filename>vendor/activesupport/lib/active_support.rb</filename>
    </modified>
    <modified>
      <diff>@@ -7,13 +7,24 @@ module ActiveSupport
   if defined? ::Base64
     Base64 = ::Base64
   else
-    # Ruby 1.9 doesn't provide base64, so we wrap this here
+    # Base64 provides utility methods for encoding and de-coding binary data 
+    # using a base 64 representation. A base 64 representation of binary data
+    # consists entirely of printable US-ASCII characters. The Base64 module
+    # is included in Ruby 1.8, but has been removed in Ruby 1.9.
     module Base64
-
+      # Encodes a string to its base 64 representation. Each 60 characters of
+      # output is separated by a newline character.
+      #
+      #  ActiveSupport::Base64.encode64(&quot;Original unencoded string&quot;) 
+      #  # =&gt; &quot;T3JpZ2luYWwgdW5lbmNvZGVkIHN0cmluZw==\n&quot;
       def self.encode64(data)
         [data].pack(&quot;m&quot;)
       end
 
+      # Decodes a base 64 encoded string to its original representation.
+      #
+      #  ActiveSupport::Base64.decode64(&quot;T3JpZ2luYWwgdW5lbmNvZGVkIHN0cmluZw==&quot;) 
+      #  # =&gt; &quot;Original unencoded string&quot;
       def self.decode64(data)
         data.unpack(&quot;m&quot;).first
       end</diff>
      <filename>vendor/activesupport/lib/active_support/base64.rb</filename>
    </modified>
    <modified>
      <diff>@@ -7,7 +7,7 @@
 # barebones base class that emulates Builder::BlankSlate while still relying on
 # Ruby 1.9's BasicObject in Ruby 1.9.
 module ActiveSupport
-  if RUBY_VERSION &gt;= '1.9'
+  if defined? ::BasicObject
     class BasicObject &lt; ::BasicObject
       undef_method :==
       undef_method :equal?</diff>
      <filename>vendor/activesupport/lib/active_support/basic_object.rb</filename>
    </modified>
    <modified>
      <diff>@@ -33,13 +33,12 @@ module ActiveSupport
 
     attr_accessor :level
     attr_reader :auto_flushing
-    attr_reader :buffer
 
     def initialize(log, level = DEBUG)
       @level         = level
-      @buffer        = []
+      @buffer        = {}
       @auto_flushing = 1
-      @no_block = false
+      @guard = Mutex.new
 
       if log.respond_to?(:write)
         @log = log
@@ -54,12 +53,6 @@ module ActiveSupport
       end
     end
 
-    def set_non_blocking_io
-      if !RUBY_PLATFORM.match(/java|mswin/) &amp;&amp; !(@log == STDOUT) &amp;&amp; @log.respond_to?(:write_nonblock)
-        @no_block = true
-      end
-    end
-
     def add(severity, message = nil, progname = nil, &amp;block)
       return if @level &gt; severity
       message = (message || (block &amp;&amp; block.call) || progname).to_s
@@ -98,11 +91,11 @@ module ActiveSupport
     end
 
     def flush
-      unless buffer.empty?
-        if @no_block
-          @log.write_nonblock(buffer.slice!(0..-1).join)
-        else
-          @log.write(buffer.slice!(0..-1).join)
+      @guard.synchronize do
+        unless buffer.empty?
+          old_buffer = buffer
+          clear_buffer
+          @log.write(old_buffer.join)
         end
       end
     end
@@ -117,5 +110,13 @@ module ActiveSupport
       def auto_flush
         flush if buffer.size &gt;= @auto_flushing
       end
+
+      def buffer
+        @buffer[Thread.current] ||= []
+      end
+
+      def clear_buffer
+        @buffer.delete(Thread.current)
+      end
   end
 end</diff>
      <filename>vendor/activesupport/lib/active_support/buffered_logger.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,7 +1,33 @@
 require 'benchmark'
 
 module ActiveSupport
+  # See ActiveSupport::Cache::Store for documentation.
   module Cache
+    # Creates a new CacheStore object according to the given options.
+    #
+    # If no arguments are passed to this method, then a new
+    # ActiveSupport::Cache::MemoryStore object will be returned.
+    #
+    # If you pass a Symbol as the first argument, then a corresponding cache
+    # store class under the ActiveSupport::Cache namespace will be created.
+    # For example:
+    #
+    #   ActiveSupport::Cache.lookup_store(:memory_store)
+    #   # =&gt; returns a new ActiveSupport::Cache::MemoryStore object
+    #   
+    #   ActiveSupport::Cache.lookup_store(:drb_store)
+    #   # =&gt; returns a new ActiveSupport::Cache::DRbStore object
+    #
+    # Any additional arguments will be passed to the corresponding cache store
+    # class's constructor:
+    #
+    #   ActiveSupport::Cache.lookup_store(:file_store, &quot;/tmp/cache&quot;)
+    #   # =&gt; same as: ActiveSupport::Cache::FileStore.new(&quot;/tmp/cache&quot;)
+    #
+    # If the first argument is not a Symbol, then it will simply be returned:
+    #
+    #   ActiveSupport::Cache.lookup_store(MyOwnCacheStore.new)
+    #   # =&gt; returns MyOwnCacheStore.new
     def self.lookup_store(*store_option)
       store, *parameters = *([ store_option ].flatten)
 
@@ -21,37 +47,84 @@ module ActiveSupport
       expanded_cache_key = namespace ? &quot;#{namespace}/&quot; : &quot;&quot;
 
       if ENV[&quot;RAILS_CACHE_ID&quot;] || ENV[&quot;RAILS_APP_VERSION&quot;]
-        expanded_cache_key &lt;&lt; &quot;#{ENV[&quot;RAILS_CACHE_ID&quot;] || ENV[&quot;RAILS_APP_VERSION&quot;]}/&quot; 
+        expanded_cache_key &lt;&lt; &quot;#{ENV[&quot;RAILS_CACHE_ID&quot;] || ENV[&quot;RAILS_APP_VERSION&quot;]}/&quot;
       end
 
       expanded_cache_key &lt;&lt; case
-      when key.respond_to?(:cache_key)
-        key.cache_key
-      when key.is_a?(Array)
-        key.collect { |element| expand_cache_key(element) }.to_param
-      when key.respond_to?(:to_param)
-        key.to_param
-      else
-        key.to_s
-      end
+        when key.respond_to?(:cache_key)
+          key.cache_key
+        when key.is_a?(Array)
+          key.collect { |element| expand_cache_key(element) }.to_param
+        when key
+          key.to_param
+        end.to_s
 
       expanded_cache_key
     end
 
-
+    # An abstract cache store class. There are multiple cache store
+    # implementations, each having its own additional features. See the classes
+    # under the ActiveSupport::Cache module, e.g.
+    # ActiveSupport::Cache::MemCacheStore. MemCacheStore is currently the most
+    # popular cache store for large production websites.
+    #
+    # ActiveSupport::Cache::Store is meant for caching strings. Some cache
+    # store implementations, like MemoryStore, are able to cache arbitrary
+    # Ruby objects, but don't count on every cache store to be able to do that.
+    #
+    #   cache = ActiveSupport::Cache::MemoryStore.new
+    #   
+    #   cache.read(&quot;city&quot;)   # =&gt; nil
+    #   cache.write(&quot;city&quot;, &quot;Duckburgh&quot;)
+    #   cache.read(&quot;city&quot;)   # =&gt; &quot;Duckburgh&quot;
     class Store
       cattr_accessor :logger
 
-      def initialize
-      end
-
-      def threadsafe!
-        @mutex = Mutex.new
-        self.class.send :include, ThreadSafety
+      def silence!
+        @silence = true
         self
       end
 
-      # Pass &lt;tt&gt;:force =&gt; true&lt;/tt&gt; to force a cache miss.
+      # Fetches data from the cache, using the given key. If there is data in
+      # the cache with the given key, then that data is returned.
+      #
+      # If there is no such data in the cache (a cache miss occurred), then
+      # then nil will be returned. However, if a block has been passed, then
+      # that block will be run in the event of a cache miss. The return value
+      # of the block will be written to the cache under the given cache key,
+      # and that return value will be returned.
+      #
+      #   cache.write(&quot;today&quot;, &quot;Monday&quot;)
+      #   cache.fetch(&quot;today&quot;)  # =&gt; &quot;Monday&quot;
+      #   
+      #   cache.fetch(&quot;city&quot;)   # =&gt; nil
+      #   cache.fetch(&quot;city&quot;) do
+      #     &quot;Duckburgh&quot;
+      #   end
+      #   cache.fetch(&quot;city&quot;)   # =&gt; &quot;Duckburgh&quot;
+      #
+      # You may also specify additional options via the +options+ argument.
+      # Setting &lt;tt&gt;:force =&gt; true&lt;/tt&gt; will force a cache miss:
+      #
+      #   cache.write(&quot;today&quot;, &quot;Monday&quot;)
+      #   cache.fetch(&quot;today&quot;, :force =&gt; true)  # =&gt; nil
+      #
+      # Other options will be handled by the specific cache store implementation.
+      # Internally, #fetch calls #read, and calls #write on a cache miss.
+      # +options+ will be passed to the #read and #write calls.
+      #
+      # For example, MemCacheStore's #write method supports the +:expires_in+
+      # option, which tells the memcached server to automatically expire the
+      # cache item after a certain period. We can use this option with #fetch
+      # too:
+      #
+      #   cache = ActiveSupport::Cache::MemCacheStore.new
+      #   cache.fetch(&quot;foo&quot;, :force =&gt; true, :expires_in =&gt; 5.seconds) do
+      #     &quot;bar&quot;
+      #   end
+      #   cache.fetch(&quot;foo&quot;)  # =&gt; &quot;bar&quot;
+      #   sleep(6)
+      #   cache.fetch(&quot;foo&quot;)  # =&gt; nil
       def fetch(key, options = {})
         @logger_off = true
         if !options[:force] &amp;&amp; value = read(key, options)
@@ -69,16 +142,38 @@ module ActiveSupport
           write(key, value, options)
           @logger_off = false
 
-          log(&quot;write (will save #{'%.5f' % seconds})&quot;, key, nil)
+          log(&quot;write (will save #{'%.2f' % (seconds * 1000)}ms)&quot;, key, nil)
 
           value
         end
       end
 
+      # Fetches data from the cache, using the given key. If there is data in
+      # the cache with the given key, then that data is returned. Otherwise,
+      # nil is returned.
+      #
+      # You may also specify additional options via the +options+ argument.
+      # The specific cache store implementation will decide what to do with
+      # +options+.
       def read(key, options = nil)
         log(&quot;read&quot;, key, options)
       end
 
+      # Writes the given value to the cache, with the given key.
+      #
+      # You may also specify additional options via the +options+ argument.
+      # The specific cache store implementation will decide what to do with
+      # +options+.
+      # 
+      # For example, MemCacheStore supports the +:expires_in+ option, which
+      # tells the memcached server to automatically expire the cache item after
+      # a certain period:
+      #
+      #   cache = ActiveSupport::Cache::MemCacheStore.new
+      #   cache.write(&quot;foo&quot;, &quot;bar&quot;, :expires_in =&gt; 5.seconds)
+      #   cache.read(&quot;foo&quot;)  # =&gt; &quot;bar&quot;
+      #   sleep(6)
+      #   cache.read(&quot;foo&quot;)  # =&gt; nil
       def write(key, value, options = nil)
         log(&quot;write&quot;, key, options)
       end
@@ -112,31 +207,12 @@ module ActiveSupport
           nil
         end
       end
-      
+
       private
         def log(operation, key, options)
-          logger.debug(&quot;Cache #{operation}: #{key}#{options ? &quot; (#{options.inspect})&quot; : &quot;&quot;}&quot;) if logger &amp;&amp; !@logger_off
+          logger.debug(&quot;Cache #{operation}: #{key}#{options ? &quot; (#{options.inspect})&quot; : &quot;&quot;}&quot;) if logger &amp;&amp; !@silence &amp;&amp; !@logger_off
         end
     end
-
-
-    module ThreadSafety #:nodoc:
-      def read(key, options = nil) #:nodoc:
-        @mutex.synchronize { super }
-      end
-
-      def write(key, value, options = nil) #:nodoc:
-        @mutex.synchronize { super }
-      end
-
-      def delete(key, options = nil) #:nodoc:
-        @mutex.synchronize { super }
-      end
-
-      def delete_matched(matcher, options = nil) #:nodoc:
-        @mutex.synchronize { super }
-      end
-    end
   end
 end
 </diff>
      <filename>vendor/activesupport/lib/active_support/cache.rb</filename>
    </modified>
    <modified>
      <diff>@@ -3,12 +3,17 @@ module ActiveSupport
     class CompressedMemCacheStore &lt; MemCacheStore
       def read(name, options = nil)
         if value = super(name, (options || {}).merge(:raw =&gt; true))
-          Marshal.load(ActiveSupport::Gzip.decompress(value))
+          if raw?(options)
+            value
+          else
+            Marshal.load(ActiveSupport::Gzip.decompress(value))
+          end
         end
       end
 
       def write(name, value, options = nil)
-        super(name, ActiveSupport::Gzip.compress(Marshal.dump(value)), (options || {}).merge(:raw =&gt; true))
+        value = ActiveSupport::Gzip.compress(Marshal.dump(value)) unless raw?(options)
+        super(name, value, (options || {}).merge(:raw =&gt; true))
       end
     end
   end</diff>
      <filename>vendor/activesupport/lib/active_support/cache/compressed_mem_cache_store.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,5 +1,6 @@
 module ActiveSupport
   module Cache
+    # A cache store implementation which stores everything on the filesystem.
     class FileStore &lt; Store
       attr_reader :cache_path
 
@@ -9,15 +10,16 @@ module ActiveSupport
 
       def read(name, options = nil)
         super
-        File.open(real_file_path(name), 'rb') { |f| f.read } rescue nil
+        File.open(real_file_path(name), 'rb') { |f| Marshal.load(f) } rescue nil
       end
 
       def write(name, value, options = nil)
         super
         ensure_cache_path(File.dirname(real_file_path(name)))
-        File.open(real_file_path(name), &quot;wb+&quot;) { |f| f.write(value) }
+        File.atomic_write(real_file_path(name), cache_path) { |f| Marshal.dump(value, f) }
+        value
       rescue =&gt; e
-        RAILS_DEFAULT_LOGGER.error &quot;Couldn't create cache directory: #{name} (#{e.message})&quot; if RAILS_DEFAULT_LOGGER
+        logger.error &quot;Couldn't create cache directory: #{name} (#{e.message})&quot; if logger
       end
 
       def delete(name, options = nil)
@@ -65,6 +67,6 @@ module ActiveSupport
             end
           end
         end
-      end
+    end
   end
-end
\ No newline at end of file
+end</diff>
      <filename>vendor/activesupport/lib/active_support/cache/file_store.rb</filename>
    </modified>
    <modified>
      <diff>@@ -2,8 +2,19 @@ require 'memcache'
 
 module ActiveSupport
   module Cache
+    # A cache store implementation which stores data in Memcached:
+    # http://www.danga.com/memcached/
+    #
+    # This is currently the most popular cache store for production websites.
+    #
+    # Special features:
+    # - Clustering and load balancing. One can specify multiple memcached servers,
+    #   and MemCacheStore will load balance between all available servers. If a
+    #   server goes down, then MemCacheStore will ignore it until it goes back
+    #   online.
+    # - Time-based expiry support. See #write and the +:expires_in+ option.
     class MemCacheStore &lt; Store
-      module Response
+      module Response # :nodoc:
         STORED      = &quot;STORED\r\n&quot;
         NOT_STORED  = &quot;NOT_STORED\r\n&quot;
         EXISTS      = &quot;EXISTS\r\n&quot;
@@ -13,6 +24,14 @@ module ActiveSupport
 
       attr_reader :addresses
 
+      # Creates a new MemCacheStore object, with the given memcached server
+      # addresses. Each address is either a host name, or a host-with-port string
+      # in the form of &quot;host_name:port&quot;. For example:
+      #
+      #   ActiveSupport::Cache::MemCacheStore.new(&quot;localhost&quot;, &quot;server-downstairs.localnetwork:8229&quot;)
+      #
+      # If no addresses are specified, then MemCacheStore will connect to
+      # localhost port 11211 (the default memcached port).
       def initialize(*addresses)
         addresses = addresses.flatten
         options = addresses.extract_options!
@@ -21,7 +40,7 @@ module ActiveSupport
         @data = MemCache.new(addresses, options)
       end
 
-      def read(key, options = nil)
+      def read(key, options = nil) # :nodoc:
         super
         @data.get(key, raw?(options))
       rescue MemCache::MemCacheError =&gt; e
@@ -29,11 +48,19 @@ module ActiveSupport
         nil
       end
 
-      # Set key = value. Pass :unless_exist =&gt; true if you don't 
-      # want to update the cache if the key is already set. 
+      # Writes a value to the cache.
+      #
+      # Possible options:
+      # - +:unless_exist+ - set to true if you don't want to update the cache
+      #   if the key is already set.
+      # - +:expires_in+ - the number of seconds that this value may stay in
+      #   the cache. See ActiveSupport::Cache::Store#write for an example.
       def write(key, value, options = nil)
         super
         method = options &amp;&amp; options[:unless_exist] ? :add : :set
+        # memcache-client will break the connection if you send it an integer
+        # in raw mode, so we convert it to a string to be sure it continues working.
+        value = value.to_s if raw?(options)
         response = @data.send(method, key, value, expires_in(options), raw?(options))
         response == Response::STORED
       rescue MemCache::MemCacheError =&gt; e
@@ -41,7 +68,7 @@ module ActiveSupport
         false
       end
 
-      def delete(key, options = nil)
+      def delete(key, options = nil) # :nodoc:
         super
         response = @data.delete(key, expires_in(options))
         response == Response::DELETED
@@ -50,39 +77,39 @@ module ActiveSupport
         false
       end
 
-      def exist?(key, options = nil)
+      def exist?(key, options = nil) # :nodoc:
         # Doesn't call super, cause exist? in memcache is in fact a read
         # But who cares? Reading is very fast anyway
         !read(key, options).nil?
       end
 
-      def increment(key, amount = 1)       
+      def increment(key, amount = 1) # :nodoc:
         log(&quot;incrementing&quot;, key, amount)
-        
-        response = @data.incr(key, amount)  
+
+        response = @data.incr(key, amount)
         response == Response::NOT_FOUND ? nil : response
-      rescue MemCache::MemCacheError 
+      rescue MemCache::MemCacheError
         nil
       end
 
-      def decrement(key, amount = 1)
+      def decrement(key, amount = 1) # :nodoc:
         log(&quot;decrement&quot;, key, amount)
-        
-        response = data.decr(key, amount) 
+
+        response = @data.decr(key, amount)
         response == Response::NOT_FOUND ? nil : response
-      rescue MemCache::MemCacheError 
+      rescue MemCache::MemCacheError
         nil
-      end        
-      
-      def delete_matched(matcher, options = nil)
+      end
+
+      def delete_matched(matcher, options = nil) # :nodoc:
         super
         raise &quot;Not supported by Memcache&quot;
-      end        
-      
+      end
+
       def clear
         @data.flush_all
-      end        
-      
+      end
+
       def stats
         @data.stats
       end</diff>
      <filename>vendor/activesupport/lib/active_support/cache/mem_cache_store.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,5 +1,19 @@
 module ActiveSupport
   module Cache
+    # A cache store implementation which stores everything into memory in the
+    # same process. If you're running multiple Ruby on Rails server processes
+    # (which is the case if you're using mongrel_cluster or Phusion Passenger),
+    # then this means that your Rails server process instances won't be able
+    # to share cache data with each other. If your application never performs
+    # manual cache item expiry (e.g. when you're using generational cache keys),
+    # then using MemoryStore is ok. Otherwise, consider carefully whether you
+    # should be using this cache store.
+    #
+    # MemoryStore is not only able to store strings, but also arbitrary Ruby
+    # objects.
+    #
+    # MemoryStore is not thread-safe. Use SynchronizedMemoryStore instead
+    # if you need thread-safety.
     class MemoryStore &lt; Store
       def initialize
         @data = {}
@@ -12,7 +26,7 @@ module ActiveSupport
 
       def write(name, value, options = nil)
         super
-        @data[name] = value
+        @data[name] = value.freeze
       end
 
       def delete(name, options = nil)
@@ -35,4 +49,4 @@ module ActiveSupport
       end
     end
   end
-end
\ No newline at end of file
+end</diff>
      <filename>vendor/activesupport/lib/active_support/cache/memory_store.rb</filename>
    </modified>
    <modified>
      <diff>@@ -96,15 +96,12 @@ module ActiveSupport
         end
       end
 
-      def |(chain)
-        if chain.is_a?(CallbackChain)
-          chain.each { |callback| self | callback }
+      # TODO: Decompose into more Array like behavior
+      def replace_or_append!(chain)
+        if index = index(chain)
+          self[index] = chain
         else
-          if (found_callback = find(chain)) &amp;&amp; (index = index(chain))
-            self[index] = chain
-          else
-            self &lt;&lt; chain
-          end
+          self &lt;&lt; chain
         end
         self
       end
@@ -157,6 +154,14 @@ module ActiveSupport
         self.class.new(@kind, @method, @options.dup)
       end
 
+      def hash
+        if @identifier
+          @identifier.hash
+        else
+          @method.hash
+        end
+      end
+
       def call(*args, &amp;block)
         evaluate_method(method, *args, &amp;block) if should_run_callback?(*args)
       rescue LocalJumpError
@@ -183,7 +188,7 @@ module ActiveSupport
                   &quot;Callbacks must be a symbol denoting the method to call, a string to be evaluated, &quot; +
                   &quot;a block to be invoked, or an object responding to the callback method.&quot;
               end
-            end
+          end
         end
 
         def should_run_callback?(*args)</diff>
      <filename>vendor/activesupport/lib/active_support/callbacks.rb</filename>
    </modified>
    <modified>
      <diff>@@ -8,6 +8,7 @@ module ActiveSupport #:nodoc:
         #   %w( a b c d ).from(0)  # =&gt; %w( a b c d )
         #   %w( a b c d ).from(2)  # =&gt; %w( c d )
         #   %w( a b c d ).from(10) # =&gt; nil
+        #   %w().from(0)           # =&gt; nil
         def from(position)
           self[position..-1]
         end
@@ -17,9 +18,35 @@ module ActiveSupport #:nodoc:
         #   %w( a b c d ).to(0)  # =&gt; %w( a )
         #   %w( a b c d ).to(2)  # =&gt; %w( a b c )
         #   %w( a b c d ).to(10) # =&gt; %w( a b c d )
+        #   %w().to(0)           # =&gt; %w()
         def to(position)
           self[0..position]
         end
+
+        # Equal to &lt;tt&gt;self[1]&lt;/tt&gt;.
+        def second
+          self[1]
+        end
+
+        # Equal to &lt;tt&gt;self[2]&lt;/tt&gt;.
+        def third
+          self[2]
+        end
+
+        # Equal to &lt;tt&gt;self[3]&lt;/tt&gt;.
+        def fourth
+          self[3]
+        end
+
+        # Equal to &lt;tt&gt;self[4]&lt;/tt&gt;.
+        def fifth
+          self[4]
+        end
+
+        # Equal to &lt;tt&gt;self[41]&lt;/tt&gt;. Also known as accessing &quot;the reddit&quot;.
+        def forty_two
+          self[41]
+        end
       end
     end
   end</diff>
      <filename>vendor/activesupport/lib/active_support/core_ext/array/access.rb</filename>
    </modified>
    <modified>
      <diff>@@ -6,10 +6,13 @@ module ActiveSupport #:nodoc:
       module Conversions
         # Converts the array to a comma-separated sentence where the last element is joined by the connector word. Options:
         # * &lt;tt&gt;:connector&lt;/tt&gt; - The word used to join the last element in arrays with two or more elements (default: &quot;and&quot;)
-        # * &lt;tt&gt;:skip_last_comma&lt;/tt&gt; - Set to true to return &quot;a, b and c&quot; instead of &quot;a, b, and c&quot;.
-        def to_sentence(options = {})
-          options.assert_valid_keys(:connector, :skip_last_comma)
-          options.reverse_merge! :connector =&gt; 'and', :skip_last_comma =&gt; false
+        # * &lt;tt&gt;:skip_last_comma&lt;/tt&gt; - Set to true to return &quot;a, b and c&quot; instead of &quot;a, b, and c&quot;.        
+        def to_sentence(options = {})          
+          options.assert_valid_keys(:connector, :skip_last_comma, :locale)
+          
+          default = I18n.translate(:'support.array.sentence_connector', :locale =&gt; options[:locale])
+          default_skip_last_comma = I18n.translate(:'support.array.skip_last_comma', :locale =&gt; options[:locale])
+          options.reverse_merge! :connector =&gt; default, :skip_last_comma =&gt; default_skip_last_comma
           options[:connector] = &quot;#{options[:connector]} &quot; unless options[:connector].nil? || options[:connector].strip == ''
 
           case length
@@ -23,11 +26,12 @@ module ActiveSupport #:nodoc:
               &quot;#{self[0...-1].join(', ')}#{options[:skip_last_comma] ? '' : ','} #{options[:connector]}#{self[-1]}&quot;
           end
         end
+        
 
         # Calls &lt;tt&gt;to_param&lt;/tt&gt; on all its elements and joins the result with
         # slashes. This is used by &lt;tt&gt;url_for&lt;/tt&gt; in Action Pack. 
         def to_param
-          map(&amp;:to_param).join '/'
+          collect { |e| e.to_param }.join '/'
         end
 
         # Converts an array into a string suitable for use as a URL query string,
@@ -35,7 +39,8 @@ module ActiveSupport #:nodoc:
         #
         #   ['Rails', 'coding'].to_query('hobbies') # =&gt; &quot;hobbies%5B%5D=Rails&amp;hobbies%5B%5D=coding&quot;
         def to_query(key)
-          collect { |value| value.to_query(&quot;#{key}[]&quot;) } * '&amp;'
+          prefix = &quot;#{key}[]&quot;
+          collect { |value| value.to_query(prefix) }.join '&amp;'
         end
 
         def self.included(base) #:nodoc:
@@ -167,7 +172,7 @@ module ActiveSupport #:nodoc:
           else
             xml.tag!(root, options[:skip_types] ? {} : {:type =&gt; &quot;array&quot;}) {
               yield xml if block_given?
-              each { |e| e.to_xml(opts.merge!({ :skip_instruct =&gt; true })) }
+              each { |e| e.to_xml(opts.merge({ :skip_instruct =&gt; true })) }
             }
           end
         end</diff>
      <filename>vendor/activesupport/lib/active_support/core_ext/array/conversions.rb</filename>
    </modified>
    <modified>
      <diff>@@ -4,22 +4,22 @@ module ActiveSupport #:nodoc:
   module CoreExtensions #:nodoc:
     module Array #:nodoc:
       module Grouping
-        # Iterates over the array in groups of size +number+, padding any remaining 
-        # slots with +fill_with+ unless it is +false+.
+        # Splits or iterates over the array in groups of size +number+,
+        # padding any remaining slots with +fill_with+ unless it is +false+.
         # 
-        #   %w(1 2 3 4 5 6 7).in_groups_of(3) {|g| p g}
+        #   %w(1 2 3 4 5 6 7).in_groups_of(3) {|group| p group}
         #   [&quot;1&quot;, &quot;2&quot;, &quot;3&quot;]
         #   [&quot;4&quot;, &quot;5&quot;, &quot;6&quot;]
         #   [&quot;7&quot;, nil, nil]
         #
-        #   %w(1 2 3).in_groups_of(2, '&amp;nbsp;') {|g| p g}
+        #   %w(1 2 3).in_groups_of(2, '&amp;nbsp;') {|group| p group}
         #   [&quot;1&quot;, &quot;2&quot;]
         #   [&quot;3&quot;, &quot;&amp;nbsp;&quot;]
         #
-        #   %w(1 2 3).in_groups_of(2, false) {|g| p g}
+        #   %w(1 2 3).in_groups_of(2, false) {|group| p group}
         #   [&quot;1&quot;, &quot;2&quot;]
         #   [&quot;3&quot;]
-        def in_groups_of(number, fill_with = nil, &amp;block)
+        def in_groups_of(number, fill_with = nil)
           if fill_with == false
             collection = self
           else
@@ -31,7 +31,7 @@ module ActiveSupport #:nodoc:
           end
 
           if block_given?
-            collection.each_slice(number, &amp;block)
+            collection.each_slice(number) { |slice| yield(slice) }
           else
             returning [] do |groups|
               collection.each_slice(number) { |group| groups &lt;&lt; group }
@@ -39,16 +39,59 @@ module ActiveSupport #:nodoc:
           end
         end
 
+        # Splits or iterates over the array in +number+ of groups, padding any
+        # remaining slots with +fill_with+ unless it is +false+.
+        #
+        #   %w(1 2 3 4 5 6 7 8 9 10).in_groups(3) {|group| p group}
+        #   [&quot;1&quot;, &quot;2&quot;, &quot;3&quot;, &quot;4&quot;]
+        #   [&quot;5&quot;, &quot;6&quot;, &quot;7&quot;, nil]
+        #   [&quot;8&quot;, &quot;9&quot;, &quot;10&quot;, nil]
+        #
+        #   %w(1 2 3 4 5 6 7).in_groups(3, '&amp;nbsp;') {|group| p group}
+        #   [&quot;1&quot;, &quot;2&quot;, &quot;3&quot;]
+        #   [&quot;4&quot;, &quot;5&quot;, &quot;&amp;nbsp;&quot;]
+        #   [&quot;6&quot;, &quot;7&quot;, &quot;&amp;nbsp;&quot;]
+        #
+        #   %w(1 2 3 4 5 6 7).in_groups(3, false) {|group| p group}
+        #   [&quot;1&quot;, &quot;2&quot;, &quot;3&quot;]
+        #   [&quot;4&quot;, &quot;5&quot;]
+        #   [&quot;6&quot;, &quot;7&quot;]
+        def in_groups(number, fill_with = nil)
+          # size / number gives minor group size;
+          # size % number gives how many objects need extra accomodation;
+          # each group hold either division or division + 1 items.
+          division = size / number
+          modulo = size % number
+
+          # create a new array avoiding dup
+          groups = []
+          start = 0
+
+          number.times do |index|
+            length = division + (modulo &gt; 0 &amp;&amp; modulo &gt; index ? 1 : 0)
+            padding = fill_with != false &amp;&amp;
+              modulo &gt; 0 &amp;&amp; length == division ? 1 : 0
+            groups &lt;&lt; slice(start, length).concat([fill_with] * padding)
+            start += length
+          end
+
+          if block_given?
+            groups.each{|g| yield(g) }
+          else
+            groups
+          end
+        end
+
         # Divides the array into one or more subarrays based on a delimiting +value+
         # or the result of an optional block.
         #
         #   [1, 2, 3, 4, 5].split(3)                # =&gt; [[1, 2], [4, 5]]
         #   (1..10).to_a.split { |i| i % 3 == 0 }   # =&gt; [[1, 2], [4, 5], [7, 8], [10]]
-        def split(value = nil, &amp;block)
-          block ||= Proc.new { |e| e == value }
+        def split(value = nil)
+          using_block = block_given?
 
           inject([[]]) do |results, element|
-            if block.call(element)
+            if (using_block &amp;&amp; yield(element)) || (value == element)
               results &lt;&lt; []
             else
               results.last &lt;&lt; element</diff>
      <filename>vendor/activesupport/lib/active_support/core_ext/array/grouping.rb</filename>
    </modified>
    <modified>
      <diff>@@ -4,6 +4,9 @@ module ActiveSupport #:nodoc:
       module Encoding
         # Encodes the value as base64 without the newline breaks. This makes the base64 encoding readily usable as URL parameters 
         # or memcache keys without further processing.
+        #
+        #  ActiveSupport::Base64.encode64s(&quot;Original unencoded string&quot;) 
+        #  # =&gt; &quot;T3JpZ2luYWwgdW5lbmNvZGVkIHN0cmluZw==&quot;
         def encode64s(value)
           encode64(value).gsub(/\n/, '')
         end</diff>
      <filename>vendor/activesupport/lib/active_support/core_ext/base64/encoding.rb</filename>
    </modified>
    <modified>
      <diff>@@ -4,35 +4,31 @@ module ActiveSupport #:nodoc:
   module CoreExtensions #:nodoc:
     module BigDecimal #:nodoc:
       module Conversions
+        DEFAULT_STRING_FORMAT = 'F'.freeze
+        YAML_TAG = 'tag:yaml.org,2002:float'.freeze
+        YAML_MAPPING = { 'Infinity' =&gt; '.Inf', '-Infinity' =&gt; '-.Inf', 'NaN' =&gt; '.NaN' }
+
         def self.included(base) #:nodoc:
-          base.instance_eval do
+          base.class_eval do
             alias_method :_original_to_s, :to_s
             alias_method :to_s, :to_formatted_s
+
+            yaml_as YAML_TAG
           end
         end
-        
-        def to_formatted_s(format=&quot;F&quot;)
+
+        def to_formatted_s(format = DEFAULT_STRING_FORMAT)
           _original_to_s(format)
         end
-        
-        yaml_as &quot;tag:yaml.org,2002:float&quot;
-        def to_yaml( opts = {} )
-          YAML::quick_emit( nil, opts ) do |out|
-            # This emits the number without any scientific notation.
-            # I prefer it to using self.to_f.to_s, which would lose precision.
-            #
-            # Note that YAML allows that when reconsituting floats
-            # to native types, some precision may get lost.
-            # There is no full precision real YAML tag that I am aware of.
-            str = self.to_s
-            if str == &quot;Infinity&quot;
-              str = &quot;.Inf&quot;
-            elsif str == &quot;-Infinity&quot;
-              str = &quot;-.Inf&quot;
-            elsif str == &quot;NaN&quot;
-              str = &quot;.NaN&quot;
-            end
-            out.scalar( &quot;tag:yaml.org,2002:float&quot;, str, :plain )
+
+        # This emits the number without any scientific notation.
+        # This is better than self.to_f.to_s since it doesn't lose precision.
+        #
+        # Note that reconstituting YAML floats to native floats may lose precision.
+        def to_yaml(opts = {})
+          YAML.quick_emit(nil, opts) do |out|
+            string = to_s
+            out.scalar(YAML_TAG, YAML_MAPPING[string] || string, :plain)
           end
         end
       end</diff>
      <filename>vendor/activesupport/lib/active_support/core_ext/bigdecimal/conversions.rb</filename>
    </modified>
    <modified>
      <diff>@@ -12,6 +12,11 @@ class Object
   def blank?
     respond_to?(:empty?) ? empty? : !self
   end
+    
+  # An object is present if it's not blank.
+  def present?
+    !blank?
+  end
 end
 
 class NilClass #:nodoc:</diff>
      <filename>vendor/activesupport/lib/active_support/core_ext/blank.rb</filename>
    </modified>
    <modified>
      <diff>@@ -91,14 +91,14 @@ class Class # :nodoc:
   def inheritable_attributes
     @inheritable_attributes ||= EMPTY_INHERITABLE_ATTRIBUTES
   end
-  
+
   def write_inheritable_attribute(key, value)
     if inheritable_attributes.equal?(EMPTY_INHERITABLE_ATTRIBUTES)
       @inheritable_attributes = {}
     end
     inheritable_attributes[key] = value
   end
-  
+
   def write_inheritable_array(key, elements)
     write_inheritable_attribute(key, []) if read_inheritable_attribute(key).nil?
     write_inheritable_attribute(key, read_inheritable_attribute(key) + elements)
@@ -112,7 +112,7 @@ class Class # :nodoc:
   def read_inheritable_attribute(key)
     inheritable_attributes[key]
   end
-  
+
   def reset_inheritable_attributes
     @inheritable_attributes = EMPTY_INHERITABLE_ATTRIBUTES
   end
@@ -123,7 +123,7 @@ class Class # :nodoc:
 
     def inherited_with_inheritable_attributes(child)
       inherited_without_inheritable_attributes(child) if respond_to?(:inherited_without_inheritable_attributes)
-      
+
       if inheritable_attributes.equal?(EMPTY_INHERITABLE_ATTRIBUTES)
         new_inheritable_attributes = EMPTY_INHERITABLE_ATTRIBUTES
       else
@@ -131,7 +131,7 @@ class Class # :nodoc:
           memo.update(key =&gt; value.duplicable? ? value.dup : value)
         end
       end
-      
+
       child.instance_variable_set('@inheritable_attributes', new_inheritable_attributes)
     end
 </diff>
      <filename>vendor/activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,3 +1,5 @@
+require 'date'
+
 module ActiveSupport #:nodoc:
   module CoreExtensions #:nodoc:
     module Date #:nodoc:
@@ -10,6 +12,7 @@ module ActiveSupport #:nodoc:
 
         # Date memoizes some instance methods using metaprogramming to wrap
         # the methods with one that caches the result in an instance variable.
+        #
         # If a Date is frozen but the memoized method hasn't been called, the
         # first call will result in a frozen object error since the memo
         # instance variable is uninitialized.</diff>
      <filename>vendor/activesupport/lib/active_support/core_ext/date/behavior.rb</filename>
    </modified>
    <modified>
      <diff>@@ -20,18 +20,33 @@ module ActiveSupport #:nodoc:
           def yesterday
             ::Date.today.yesterday
           end
-          
+
           # Returns a new Date representing the date 1 day after today (i.e. tomorrow's date).
           def tomorrow
             ::Date.today.tomorrow
           end
-          
+
           # Returns Time.zone.today when config.time_zone is set, otherwise just returns Date.today.
           def current
             ::Time.zone_default ? ::Time.zone.today : ::Date.today
           end
         end
-        
+
+        # Tells whether the Date object's date lies in the past
+        def past?
+          self &lt; ::Date.current
+        end
+
+        # Tells whether the Date object's date is today
+        def today?
+          self.to_date == ::Date.current # we need the to_date because of DateTime
+        end
+
+        # Tells whether the Date object's date lies in the future
+        def future?
+          self &gt; ::Date.current
+        end
+
         # Converts Date to a Time (or DateTime if necessary) with the time portion set to the beginning of the day (0:00)
         # and then subtracts the specified number of seconds
         def ago(seconds)
@@ -57,7 +72,7 @@ module ActiveSupport #:nodoc:
         def end_of_day
           to_time.end_of_day
         end
-        
+
         def plus_with_duration(other) #:nodoc:
           if ActiveSupport::Duration === other
             other.since(self)
@@ -65,7 +80,7 @@ module ActiveSupport #:nodoc:
             plus_without_duration(other)
           end
         end
-        
+
         def minus_with_duration(other) #:nodoc:
           if ActiveSupport::Duration === other
             plus_with_duration(-other)
@@ -73,8 +88,8 @@ module ActiveSupport #:nodoc:
             minus_without_duration(other)
           end
         end
-        
-        # Provides precise Date calculations for years, months, and days.  The +options+ parameter takes a hash with 
+
+        # Provides precise Date calculations for years, months, and days.  The +options+ parameter takes a hash with
         # any of these keys: &lt;tt&gt;:years&lt;/tt&gt;, &lt;tt&gt;:months&lt;/tt&gt;, &lt;tt&gt;:weeks&lt;/tt&gt;, &lt;tt&gt;:days&lt;/tt&gt;.
         def advance(options)
           d = self
@@ -98,7 +113,7 @@ module ActiveSupport #:nodoc:
             options[:day]   || self.day
           )
         end
-        
+
         # Returns a new Date/DateTime representing the time a number of specified months ago
         def months_ago(months)
           advance(:months =&gt; -months)
@@ -161,7 +176,7 @@ module ActiveSupport #:nodoc:
           days_into_week = { :monday =&gt; 0, :tuesday =&gt; 1, :wednesday =&gt; 2, :thursday =&gt; 3, :friday =&gt; 4, :saturday =&gt; 5, :sunday =&gt; 6}
           result = (self + 7).beginning_of_week + days_into_week[day]
           self.acts_like?(:time) ? result.change(:hour =&gt; 0) : result
-        end          
+        end
 
         # Returns a new ; DateTime objects will have time set to 0:00DateTime representing the start of the month (1st of the month; DateTime objects will have time set to 0:00)
         def beginning_of_month</diff>
      <filename>vendor/activesupport/lib/active_support/core_ext/date/calculations.rb</filename>
    </modified>
    <modified>
      <diff>@@ -7,7 +7,7 @@ module ActiveSupport #:nodoc:
       module Calculations
         def self.included(base) #:nodoc:
           base.extend ClassMethods
-          
+
           base.class_eval do
             alias_method :compare_without_coercion, :&lt;=&gt;
             alias_method :&lt;=&gt;, :compare_with_coercion
@@ -19,6 +19,20 @@ module ActiveSupport #:nodoc:
           def local_offset
             ::Time.local(2007).utc_offset.to_r / 86400
           end
+
+          def current
+            ::Time.zone_default ? ::Time.zone.now.to_datetime : ::Time.now.to_datetime
+          end
+        end
+
+        # Tells whether the DateTime object's datetime lies in the past
+        def past?
+          self &lt; ::DateTime.current
+        end
+
+        # Tells whether the DateTime object's datetime lies in the future
+        def future?
+          self &gt; ::DateTime.current
         end
 
         # Seconds since midnight: DateTime.now.seconds_since_midnight
@@ -78,7 +92,7 @@ module ActiveSupport #:nodoc:
         def end_of_day
           change(:hour =&gt; 23, :min =&gt; 59, :sec =&gt; 59)
         end
-        
+
         # Adjusts DateTime to UTC by adding its offset value; offset is set to 0
         #
         # Example:
@@ -89,17 +103,17 @@ module ActiveSupport #:nodoc:
           new_offset(0)
         end
         alias_method :getutc, :utc
-        
+
         # Returns true if offset == 0
         def utc?
           offset == 0
         end
-        
+
         # Returns the offset value in seconds
         def utc_offset
           (offset * 86400).to_i
         end
-        
+
         # Layers additional behavior on DateTime#&lt;=&gt; so that Time and ActiveSupport::TimeWithZone instances can be compared with a DateTime
         def compare_with_coercion(other)
           other = other.comparable_time if other.respond_to?(:comparable_time)</diff>
      <filename>vendor/activesupport/lib/active_support/core_ext/date_time/calculations.rb</filename>
    </modified>
    <modified>
      <diff>@@ -35,3 +35,9 @@ class Numeric #:nodoc:
     false
   end
 end
+
+class Class #:nodoc:
+  def duplicable?
+    false
+  end
+end</diff>
      <filename>vendor/activesupport/lib/active_support/core_ext/duplicable.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,3 +1,5 @@
+require 'active_support/ordered_hash'
+
 module Enumerable
   # Ruby 1.8.7 introduces group_by, but the result isn't ordered. Override it.
   remove_method(:group_by) if [].respond_to?(:group_by) &amp;&amp; RUBY_VERSION &lt; '1.9'
@@ -18,10 +20,19 @@ module Enumerable
   #   &quot;2006-02-24 -&gt; Transcript, Transcript&quot;
   #   &quot;2006-02-23 -&gt; Transcript&quot;
   def group_by
-    inject ActiveSupport::OrderedHash.new do |grouped, element|
-      (grouped[yield(element)] ||= []) &lt;&lt; element
-      grouped
+    assoc = ActiveSupport::OrderedHash.new
+
+    each do |element|
+      key = yield(element)
+
+      if assoc.has_key?(key)
+        assoc[key] &lt;&lt; element
+      else
+        assoc[key] = [element]
+      end
     end
+
+    assoc
   end unless [].respond_to?(:group_by)
 
   # Calculates a sum from the elements. Examples:
@@ -53,8 +64,28 @@ module Enumerable
     end
   end
 
+  # Iterates over a collection, passing the current element *and* the
+  # +memo+ to the block. Handy for building up hashes or
+  # reducing collections down to one object. Examples:
+  #
+  #   %w(foo bar).each_with_object({}) { |str, hsh| hsh[str] = str.upcase } #=&gt; {'foo' =&gt; 'FOO', 'bar' =&gt; 'BAR'}
+  #
+  # *Note* that you can't use immutable objects like numbers, true or false as
+  # the memo. You would think the following returns 120, but since the memo is
+  # never changed, it does not.
+  #
+  #   (1..5).each_with_object(1) { |value, memo| memo *= value } # =&gt; 1
+  #
+  def each_with_object(memo, &amp;block)
+    returning memo do |m|
+      each do |element|
+        block.call(element, m)
+      end
+    end
+  end unless [].respond_to?(:each_with_object)
+
   # Convert an enumerable to a hash. Examples:
-  # 
+  #
   #   people.index_by(&amp;:login)
   #     =&gt; { &quot;nextangle&quot; =&gt; &lt;Person ...&gt;, &quot;chade-&quot; =&gt; &lt;Person ...&gt;, ...}
   #   people.index_by { |person| &quot;#{person.first_name} #{person.last_name}&quot; }
@@ -66,4 +97,11 @@ module Enumerable
       accum
     end
   end
+  
+  # Returns true if the collection has more than 1 element. Functionally equivalent to collection.size &gt; 1.
+  # Works with a block too ala any?, so people.many? { |p| p.age &gt; 26 } # =&gt; returns true if more than 1 person is over 26.
+  def many?(&amp;block)
+    size = block_given? ? select(&amp;block).size : self.size
+    size &gt; 1
+  end
 end</diff>
      <filename>vendor/activesupport/lib/active_support/core_ext/enumerable.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,21 +1,5 @@
-require 'tempfile'
+require 'active_support/core_ext/file/atomic'
 
-# Write to a file atomically.  Useful for situations where you don't
-# want other processes or threads to see half-written files.
-#
-#   File.atomic_write(&quot;important.file&quot;) do |file|
-#     file.write(&quot;hello&quot;)
-#   end
-#
-# If your temp directory is not on the same filesystem as the file you're 
-# trying to write, you can provide a different temporary directory.
-# 
-#   File.atomic_write(&quot;/data/something.important&quot;, &quot;/data/tmp&quot;) do |f|
-#     file.write(&quot;hello&quot;)
-#   end
-def File.atomic_write(file_name, temp_dir = Dir.tmpdir)
-  temp_file = Tempfile.new(File.basename(file_name), temp_dir)
-  yield temp_file
-  temp_file.close
-  File.rename(temp_file.path, file_name)
-end
\ No newline at end of file
+class File #:nodoc:
+  extend ActiveSupport::CoreExtensions::File::Atomic
+end</diff>
      <filename>vendor/activesupport/lib/active_support/core_ext/file.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,5 +1,7 @@
 require 'active_support/core_ext/float/rounding'
+require 'active_support/core_ext/float/time'
 
 class Float #:nodoc:
   include ActiveSupport::CoreExtensions::Float::Rounding
+  include ActiveSupport::CoreExtensions::Float::Time
 end</diff>
      <filename>vendor/activesupport/lib/active_support/core_ext/float.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,10 +1,11 @@
-%w(keys indifferent_access reverse_merge conversions diff slice except).each do |ext|
+%w(keys indifferent_access deep_merge reverse_merge conversions diff slice except).each do |ext|
   require &quot;active_support/core_ext/hash/#{ext}&quot;
 end
 
 class Hash #:nodoc:
   include ActiveSupport::CoreExtensions::Hash::Keys
   include ActiveSupport::CoreExtensions::Hash::IndifferentAccess
+  include ActiveSupport::CoreExtensions::Hash::DeepMerge
   include ActiveSupport::CoreExtensions::Hash::ReverseMerge
   include ActiveSupport::CoreExtensions::Hash::Conversions
   include ActiveSupport::CoreExtensions::Hash::Diff</diff>
      <filename>vendor/activesupport/lib/active_support/core_ext/hash.rb</filename>
    </modified>
    <modified>
      <diff>@@ -156,7 +156,7 @@ module ActiveSupport #:nodoc:
                       XML_FORMATTING[type_name] ? XML_FORMATTING[type_name].call(value) : value,
                       attributes
                     )
-                end
+                  end
               end
             end
             </diff>
      <filename>vendor/activesupport/lib/active_support/core_ext/hash/conversions.rb</filename>
    </modified>
    <modified>
      <diff>@@ -10,10 +10,10 @@ module ActiveSupport #:nodoc:
       module Except
         # Returns a new hash without the given keys.
         def except(*keys)
-          clone.except!(*keys)
+          dup.except!(*keys)
         end
 
-        # Replaces the hash without only the given keys.
+        # Replaces the hash without the given keys.
         def except!(*keys)
           keys.map! { |key| convert_key(key) } if respond_to?(:convert_key)
           keys.each { |key| delete(key) }</diff>
      <filename>vendor/activesupport/lib/active_support/core_ext/hash/except.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,21 +1,28 @@
 module ActiveSupport #:nodoc:
   module CoreExtensions #:nodoc:
     module Hash #:nodoc:
-      # Allows for reverse merging where its the keys in the calling hash that wins over those in the &lt;tt&gt;other_hash&lt;/tt&gt;.
-      # This is particularly useful for initializing an incoming option hash with default values:
+      # Allows for reverse merging two hashes where the keys in the calling hash take precedence over those
+      # in the &lt;tt&gt;other_hash&lt;/tt&gt;. This is particularly useful for initializing an option hash with default values:
       #
       #   def setup(options = {})
       #     options.reverse_merge! :size =&gt; 25, :velocity =&gt; 10
       #   end
       #
-      # The default &lt;tt&gt;:size&lt;/tt&gt; and &lt;tt&gt;:velocity&lt;/tt&gt; is only set if the +options+ passed in doesn't already have those keys set.
+      # Using &lt;tt&gt;merge&lt;/tt&gt;, the above example would look as follows:
+      #
+      #   def setup(options = {})
+      #     { :size =&gt; 25, :velocity =&gt; 10 }.merge(options)
+      #   end
+      #
+      # The default &lt;tt&gt;:size&lt;/tt&gt; and &lt;tt&gt;:velocity&lt;/tt&gt; are only set if the +options+ hash passed in doesn't already
+      # have the respective key.
       module ReverseMerge
-        # Performs the opposite of merge, with the keys and values from the first hash taking precedence over the second.
+        # Performs the opposite of &lt;tt&gt;merge&lt;/tt&gt;, with the keys and values from the first hash taking precedence over the second.
         def reverse_merge(other_hash)
           other_hash.merge(self)
         end
 
-        # Performs the opposite of merge, with the keys and values from the first hash taking precedence over the second.
+        # Performs the opposite of &lt;tt&gt;merge&lt;/tt&gt;, with the keys and values from the first hash taking precedence over the second.
         # Modifies the receiver in place.
         def reverse_merge!(other_hash)
           replace(reverse_merge(other_hash))</diff>
      <filename>vendor/activesupport/lib/active_support/core_ext/hash/reverse_merge.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,5 +1,3 @@
-require 'set'
-
 module ActiveSupport #:nodoc:
   module CoreExtensions #:nodoc:
     module Hash #:nodoc:
@@ -11,12 +9,17 @@ module ActiveSupport #:nodoc:
       #   end
       #
       #   search(options.slice(:mass, :velocity, :time))
+      #
+      # If you have an array of keys you want to limit to, you should splat them:
+      #
+      #   valid_keys = [:mass, :velocity, :time]
+      #   search(options.slice(*valid_keys))
       module Slice
         # Returns a new hash with only the given keys.
         def slice(*keys)
-          allowed = Set.new(respond_to?(:convert_key) ? keys.map { |key| convert_key(key) } : keys)
-          hash = {}
-          allowed.each { |k| hash[k] = self[k] if has_key?(k) }
+          keys = keys.map! { |key| convert_key(key) } if respond_to?(:convert_key)
+          hash = self.class.new
+          keys.each { |k| hash[k] = self[k] if has_key?(k) }
           hash
         end
 </diff>
      <filename>vendor/activesupport/lib/active_support/core_ext/hash/slice.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,7 +1,9 @@
 require 'active_support/core_ext/integer/even_odd'
 require 'active_support/core_ext/integer/inflections'
+require 'active_support/core_ext/integer/time'
 
 class Integer #:nodoc:
   include ActiveSupport::CoreExtensions::Integer::EvenOdd
   include ActiveSupport::CoreExtensions::Integer::Inflections
+  include ActiveSupport::CoreExtensions::Integer::Time
 end</diff>
      <filename>vendor/activesupport/lib/active_support/core_ext/integer.rb</filename>
    </modified>
    <modified>
      <diff>@@ -2,12 +2,12 @@ module Kernel
   unless respond_to?(:debugger)
     # Starts a debugging session if ruby-debug has been loaded (call script/server --debugger to do load it).
     def debugger
-      RAILS_DEFAULT_LOGGER.info &quot;\n***** Debugger requested, but was not available: Start server with --debugger to enable *****\n&quot;
+      Rails.logger.info &quot;\n***** Debugger requested, but was not available: Start server with --debugger to enable *****\n&quot;
     end
   end
-  
+
   def breakpoint
-    RAILS_DEFAULT_LOGGER.info &quot;\n***** The 'breakpoint' command has been renamed 'debugger' -- please change *****\n&quot;
+    Rails.logger.info &quot;\n***** The 'breakpoint' command has been renamed 'debugger' -- please change *****\n&quot;
     debugger
   end
-end
\ No newline at end of file
+end</diff>
      <filename>vendor/activesupport/lib/active_support/core_ext/kernel/debugger.rb</filename>
    </modified>
    <modified>
      <diff>@@ -12,5 +12,132 @@ class Logger
     end_eval
   end
   [:debug, :info, :error, :fatal].each {|level| define_around_helper(level) }
+end
 
-end
\ No newline at end of file
+
+require 'logger'
+
+# Extensions to the built in Ruby logger.
+#
+# If you want to use the default log formatter as defined in the Ruby core, then you
+# will need to set the formatter for the logger as in:
+#
+#   logger.formatter = Formatter.new
+#
+# You can then specify the datetime format, for example:
+#
+#   logger.datetime_format = &quot;%Y-%m-%d&quot;
+#
+# Note: This logger is deprecated in favor of ActiveSupport::BufferedLogger
+class Logger
+  # Set to false to disable the silencer
+  cattr_accessor :silencer
+  self.silencer = true
+
+  # Silences the logger for the duration of the block.
+  def silence(temporary_level = Logger::ERROR)
+    if silencer
+      begin
+        old_logger_level, self.level = level, temporary_level
+        yield self
+      ensure
+        self.level = old_logger_level
+      end
+    else
+      yield self
+    end
+  end
+
+  alias :old_datetime_format= :datetime_format=
+  # Logging date-time format (string passed to +strftime+). Ignored if the formatter
+  # does not respond to datetime_format=.
+  def datetime_format=(datetime_format)
+    formatter.datetime_format = datetime_format if formatter.respond_to?(:datetime_format=)
+  end
+
+  alias :old_datetime_format :datetime_format
+  # Get the logging datetime format. Returns nil if the formatter does not support
+  # datetime formatting.
+  def datetime_format
+    formatter.datetime_format if formatter.respond_to?(:datetime_format)
+  end
+
+  alias :old_formatter :formatter if method_defined?(:formatter)
+  # Get the current formatter. The default formatter is a SimpleFormatter which only
+  # displays the log message
+  def formatter
+    @formatter ||= SimpleFormatter.new
+  end
+
+  unless const_defined? :Formatter
+    class Formatter
+      Format = &quot;%s, [%s#%d] %5s -- %s: %s\n&quot;
+
+      attr_accessor :datetime_format
+
+      def initialize
+        @datetime_format = nil
+      end
+
+      def call(severity, time, progname, msg)
+        Format % [severity[0..0], format_datetime(time), $$, severity, progname,
+        msg2str(msg)]
+      end
+
+      private
+        def format_datetime(time)
+          if @datetime_format.nil?
+            time.strftime(&quot;%Y-%m-%dT%H:%M:%S.&quot;) &lt;&lt; &quot;%06d &quot; % time.usec
+          else
+            time.strftime(@datetime_format)
+          end
+        end
+
+        def msg2str(msg)
+          case msg
+          when ::String
+            msg
+          when ::Exception
+            &quot;#{ msg.message } (#{ msg.class })\n&quot; &lt;&lt;
+            (msg.backtrace || []).join(&quot;\n&quot;)
+          else
+            msg.inspect
+          end
+        end
+    end
+  end
+
+  # Simple formatter which only displays the message.
+  class SimpleFormatter &lt; Logger::Formatter
+    # This method is invoked when a log event occurs
+    def call(severity, timestamp, progname, msg)
+      &quot;#{String === msg ? msg : msg.inspect}\n&quot;
+    end
+  end
+
+  private
+    alias old_format_message format_message
+
+    # Ruby 1.8.3 transposed the msg and progname arguments to format_message.
+    # We can't test RUBY_VERSION because some distributions don't keep Ruby
+    # and its standard library in sync, leading to installations of Ruby 1.8.2
+    # with Logger from 1.8.3 and vice versa.
+    if method_defined?(:formatter=)
+      def format_message(severity, timestamp, progname, msg)
+        formatter.call(severity, timestamp, progname, msg)
+      end
+    else
+      def format_message(severity, timestamp, msg, progname)
+        formatter.call(severity, timestamp, progname, msg)
+      end
+
+      attr_writer :formatter
+      public :formatter=
+
+      alias old_format_datetime format_datetime
+      def format_datetime(datetime) datetime end
+
+      alias old_msg2str msg2str
+      def msg2str(msg) msg end
+    end
+end</diff>
      <filename>vendor/activesupport/lib/active_support/core_ext/logger.rb</filename>
    </modified>
    <modified>
      <diff>@@ -7,7 +7,17 @@ require 'active_support/core_ext/module/introspection'
 require 'active_support/core_ext/module/loading'
 require 'active_support/core_ext/module/aliasing'
 require 'active_support/core_ext/module/model_naming'
+require 'active_support/core_ext/module/synchronization'
+
+module ActiveSupport
+  module CoreExtensions
+    # Various extensions for the Ruby core Module class.
+    module Module
+      # Nothing here. Only defined for API documentation purposes.
+    end
+  end
+end
 
 class Module
-  include ActiveSupport::CoreExt::Module::ModelNaming
+  include ActiveSupport::CoreExtensions::Module
 end</diff>
      <filename>vendor/activesupport/lib/active_support/core_ext/module.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,70 +1,74 @@
-class Module
-  # Encapsulates the common pattern of:
-  #
-  #   alias_method :foo_without_feature, :foo
-  #   alias_method :foo, :foo_with_feature
-  #
-  # With this, you simply do:
-  #
-  #   alias_method_chain :foo, :feature
-  #
-  # And both aliases are set up for you.
-  #
-  # Query and bang methods (foo?, foo!) keep the same punctuation:
-  #
-  #   alias_method_chain :foo?, :feature
-  #
-  # is equivalent to
-  #
-  #   alias_method :foo_without_feature?, :foo?
-  #   alias_method :foo?, :foo_with_feature?
-  #
-  # so you can safely chain foo, foo?, and foo! with the same feature.
-  def alias_method_chain(target, feature)
-    # Strip out punctuation on predicates or bang methods since
-    # e.g. target?_without_feature is not a valid method name.
-    aliased_target, punctuation = target.to_s.sub(/([?!=])$/, ''), $1
-    yield(aliased_target, punctuation) if block_given?
-    
-    with_method, without_method = &quot;#{aliased_target}_with_#{feature}#{punctuation}&quot;, &quot;#{aliased_target}_without_#{feature}#{punctuation}&quot;
-    
-    alias_method without_method, target
-    alias_method target, with_method
-    
-    case
-      when public_method_defined?(without_method)
-        public target
-      when protected_method_defined?(without_method)
-        protected target
-      when private_method_defined?(without_method)
-        private target
-    end
-  end
+module ActiveSupport
+  module CoreExtensions
+    module Module
+      # Encapsulates the common pattern of:
+      #
+      #   alias_method :foo_without_feature, :foo
+      #   alias_method :foo, :foo_with_feature
+      #
+      # With this, you simply do:
+      #
+      #   alias_method_chain :foo, :feature
+      #
+      # And both aliases are set up for you.
+      #
+      # Query and bang methods (foo?, foo!) keep the same punctuation:
+      #
+      #   alias_method_chain :foo?, :feature
+      #
+      # is equivalent to
+      #
+      #   alias_method :foo_without_feature?, :foo?
+      #   alias_method :foo?, :foo_with_feature?
+      #
+      # so you can safely chain foo, foo?, and foo! with the same feature.
+      def alias_method_chain(target, feature)
+        # Strip out punctuation on predicates or bang methods since
+        # e.g. target?_without_feature is not a valid method name.
+        aliased_target, punctuation = target.to_s.sub(/([?!=])$/, ''), $1
+        yield(aliased_target, punctuation) if block_given?
+
+        with_method, without_method = &quot;#{aliased_target}_with_#{feature}#{punctuation}&quot;, &quot;#{aliased_target}_without_#{feature}#{punctuation}&quot;
 
-  # Allows you to make aliases for attributes, which includes 
-  # getter, setter, and query methods.
-  #
-  # Example:
-  #
-  #   class Content &lt; ActiveRecord::Base
-  #     # has a title attribute
-  #   end
-  #
-  #   class Email &lt; Content
-  #     alias_attribute :subject, :title
-  #   end
-  #
-  #   e = Email.find(1)
-  #   e.title    # =&gt; &quot;Superstars&quot;
-  #   e.subject  # =&gt; &quot;Superstars&quot;
-  #   e.subject? # =&gt; true
-  #   e.subject = &quot;Megastars&quot;
-  #   e.title    # =&gt; &quot;Megastars&quot;
-  def alias_attribute(new_name, old_name)
-    module_eval &lt;&lt;-STR, __FILE__, __LINE__+1
-      def #{new_name}; self.#{old_name}; end
-      def #{new_name}?; self.#{old_name}?; end
-      def #{new_name}=(v); self.#{old_name} = v; end
-    STR
+        alias_method without_method, target
+        alias_method target, with_method
+
+        case
+          when public_method_defined?(without_method)
+            public target
+          when protected_method_defined?(without_method)
+            protected target
+          when private_method_defined?(without_method)
+            private target
+        end
+      end
+
+      # Allows you to make aliases for attributes, which includes
+      # getter, setter, and query methods.
+      #
+      # Example:
+      #
+      #   class Content &lt; ActiveRecord::Base
+      #     # has a title attribute
+      #   end
+      #
+      #   class Email &lt; Content
+      #     alias_attribute :subject, :title
+      #   end
+      #
+      #   e = Email.find(1)
+      #   e.title    # =&gt; &quot;Superstars&quot;
+      #   e.subject  # =&gt; &quot;Superstars&quot;
+      #   e.subject? # =&gt; true
+      #   e.subject = &quot;Megastars&quot;
+      #   e.title    # =&gt; &quot;Megastars&quot;
+      def alias_attribute(new_name, old_name)
+        module_eval &lt;&lt;-STR, __FILE__, __LINE__+1
+          def #{new_name}; self.#{old_name}; end
+          def #{new_name}?; self.#{old_name}?; end
+          def #{new_name}=(v); self.#{old_name} = v; end
+        STR
+      end
+    end
   end
 end</diff>
      <filename>vendor/activesupport/lib/active_support/core_ext/module/aliasing.rb</filename>
    </modified>
    <modified>
      <diff>@@ -47,15 +47,46 @@ class Module
   #   Foo.new.min # =&gt; 4
   #   Foo.new.max # =&gt; 11
   #
+  # Delegates can optionally be prefixed using the &lt;tt&gt;:prefix&lt;/tt&gt; option. If the value
+  # is &lt;tt&gt;true&lt;/tt&gt;, the delegate methods are prefixed with the name of the object being
+  # delegated to.
+  #
+  #   Person = Struct.new(:name, :address)
+  #
+  #   class Invoice &lt; Struct.new(:client)
+  #     delegate :name, :address, :to =&gt; :client, :prefix =&gt; true
+  #   end
+  #
+  #   john_doe = Person.new(&quot;John Doe&quot;, &quot;Vimmersvej 13&quot;)
+  #   invoice = Invoice.new(john_doe)
+  #   invoice.client_name    # =&gt; &quot;John Doe&quot;
+  #   invoice.client_address # =&gt; &quot;Vimmersvej 13&quot;
+  #
+  # It is also possible to supply a custom prefix.
+  #
+  #   class Invoice &lt; Struct.new(:client)
+  #     delegate :name, :address, :to =&gt; :client, :prefix =&gt; :customer
+  #   end
+  #
+  #   invoice = Invoice.new(john_doe)
+  #   invoice.customer_name    # =&gt; &quot;John Doe&quot;
+  #   invoice.customer_address # =&gt; &quot;Vimmersvej 13&quot;
+  #
   def delegate(*methods)
     options = methods.pop
     unless options.is_a?(Hash) &amp;&amp; to = options[:to]
       raise ArgumentError, &quot;Delegation needs a target. Supply an options hash with a :to key as the last argument (e.g. delegate :hello, :to =&gt; :greeter).&quot;
     end
 
+    if options[:prefix] == true &amp;&amp; options[:to].to_s =~ /^[^a-z_]/
+      raise ArgumentError, &quot;Can only automatically set the delegation prefix when delegating to a method.&quot;
+    end
+
+    prefix = options[:prefix] &amp;&amp; &quot;#{options[:prefix] == true ? to : options[:prefix]}_&quot;
+
     methods.each do |method|
       module_eval(&lt;&lt;-EOS, &quot;(__DELEGATION__)&quot;, 1)
-        def #{method}(*args, &amp;block)
+        def #{prefix}#{method}(*args, &amp;block)
           #{to}.__send__(#{method.inspect}, *args, &amp;block)
         end
       EOS</diff>
      <filename>vendor/activesupport/lib/active_support/core_ext/module/delegation.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,75 +1,90 @@
-class Module
-  # Returns the module which contains this one according to its name.
-  #
-  #   module M
-  #     module N
-  #     end
-  #   end
-  #   X = M::N
-  #   
-  #   p M::N.parent # =&gt; M
-  #   p X.parent    # =&gt; M
-  #
-  # The parent of top-level and anonymous modules is Object.
-  #
-  #   p M.parent          # =&gt; Object
-  #   p Module.new.parent # =&gt; Object
-  #
-  def parent
-    parent_name = name.split('::')[0..-2] * '::'
-    parent_name.empty? ? Object : parent_name.constantize
-  end
+module ActiveSupport
+  module CoreExtensions
+    module Module
+      # Returns the name of the module containing this one.
+      #
+      #   p M::N.parent_name # =&gt; &quot;M&quot;
+      def parent_name
+        unless defined? @parent_name
+          @parent_name = name =~ /::[^:]+\Z/ ? $`.freeze : nil
+        end
+        @parent_name
+      end
 
-  # Returns all the parents of this module according to its name, ordered from
-  # nested outwards. The receiver is not contained within the result.
-  #
-  #   module M
-  #     module N
-  #     end
-  #   end
-  #   X = M::N
-  #   
-  #   p M.parents    # =&gt; [Object]
-  #   p M::N.parents # =&gt; [M, Object]
-  #   p X.parents    # =&gt; [M, Object]
-  #
-  def parents
-    parents = []
-    parts = name.split('::')[0..-2]
-    until parts.empty?
-      parents &lt;&lt; (parts * '::').constantize
-      parts.pop
-    end
-    parents &lt;&lt; Object unless parents.include? Object
-    parents
-  end
+      # Returns the module which contains this one according to its name.
+      #
+      #   module M
+      #     module N
+      #     end
+      #   end
+      #   X = M::N
+      #
+      #   p M::N.parent # =&gt; M
+      #   p X.parent    # =&gt; M
+      #
+      # The parent of top-level and anonymous modules is Object.
+      #
+      #   p M.parent          # =&gt; Object
+      #   p Module.new.parent # =&gt; Object
+      #
+      def parent
+        parent_name ? parent_name.constantize : Object
+      end
 
-  if RUBY_VERSION &lt; '1.9'
-    # Returns the constants that have been defined locally by this object and
-    # not in an ancestor. This method is exact if running under Ruby 1.9. In
-    # previous versions it may miss some constants if their definition in some
-    # ancestor is identical to their definition in the receiver.
-    def local_constants
-      inherited = {}
+      # Returns all the parents of this module according to its name, ordered from
+      # nested outwards. The receiver is not contained within the result.
+      #
+      #   module M
+      #     module N
+      #     end
+      #   end
+      #   X = M::N
+      #
+      #   p M.parents    # =&gt; [Object]
+      #   p M::N.parents # =&gt; [M, Object]
+      #   p X.parents    # =&gt; [M, Object]
+      #
+      def parents
+        parents = []
+        if parent_name
+          parts = parent_name.split('::')
+          until parts.empty?
+            parents &lt;&lt; (parts * '::').constantize
+            parts.pop
+          end
+        end
+        parents &lt;&lt; Object unless parents.include? Object
+        parents
+      end
 
-      ancestors.each do |anc|
-        next if anc == self
-        anc.constants.each { |const| inherited[const] = anc.const_get(const) }
+      if RUBY_VERSION &lt; '1.9'
+        # Returns the constants that have been defined locally by this object and
+        # not in an ancestor. This method is exact if running under Ruby 1.9. In
+        # previous versions it may miss some constants if their definition in some
+        # ancestor is identical to their definition in the receiver.
+        def local_constants
+          inherited = {}
+
+          ancestors.each do |anc|
+            next if anc == self
+            anc.constants.each { |const| inherited[const] = anc.const_get(const) }
+          end
+
+          constants.select do |const|
+            !inherited.key?(const) || inherited[const].object_id != const_get(const).object_id
+          end
+        end
+      else
+        def local_constants #:nodoc:
+          constants(false)
+        end
       end
 
-      constants.select do |const|
-        !inherited.key?(const) || inherited[const].object_id != const_get(const).object_id
+      # Returns the names of the constants defined locally rather than the
+      # constants themselves. See &lt;tt&gt;local_constants&lt;/tt&gt;.
+      def local_constant_names
+        local_constants.map { |c| c.to_s }
       end
     end
-  else
-    def local_constants #:nodoc:
-      constants(false)
-    end
-  end
-
-  # Returns the names of the constants defined locally rather than the
-  # constants themselves. See &lt;tt&gt;local_constants&lt;/tt&gt;.
-  def local_constant_names
-    local_constants.map(&amp;:to_s)
   end
 end</diff>
      <filename>vendor/activesupport/lib/active_support/core_ext/module/introspection.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,21 +1,22 @@
 module ActiveSupport
   class ModelName &lt; String
-    attr_reader :singular, :plural, :partial_path
+    attr_reader :singular, :plural, :cache_key, :partial_path
 
     def initialize(name)
       super
       @singular = underscore.tr('/', '_').freeze
       @plural = @singular.pluralize.freeze
-      @partial_path = &quot;#{tableize}/#{demodulize.underscore}&quot;.freeze
+      @cache_key = tableize.freeze
+      @partial_path = &quot;#{@cache_key}/#{demodulize.underscore}&quot;.freeze
     end
   end
 
-  module CoreExt
+  module CoreExtensions
     module Module
-      module ModelNaming
-        def model_name
-          @model_name ||= ModelName.new(name)
-        end
+      # Returns an ActiveSupport::ModelName object for module. It can be
+      # used to retrieve all kinds of naming-related information.
+      def model_name
+        @model_name ||= ModelName.new(name)
       end
     end
   end</diff>
      <filename>vendor/activesupport/lib/active_support/core_ext/module/model_naming.rb</filename>
    </modified>
    <modified>
      <diff>@@ -60,16 +60,6 @@ module ActiveSupport #:nodoc:
         end
         alias :fortnight :fortnights
         
-        def months
-          ActiveSupport::Duration.new(self * 30.days, [[:months, self]])
-        end
-        alias :month :months
-
-        def years
-          ActiveSupport::Duration.new(self * 365.25.days, [[:years, self]])
-        end
-        alias :year :years
-
         # Reads best without arguments:  10.minutes.ago
         def ago(time = ::Time.now)
           time - self</diff>
      <filename>vendor/activesupport/lib/active_support/core_ext/numeric/time.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,4 +1,5 @@
 require 'active_support/core_ext/object/conversions'
 require 'active_support/core_ext/object/extending'
 require 'active_support/core_ext/object/instance_variables'
+require 'active_support/core_ext/object/metaclass'
 require 'active_support/core_ext/object/misc'</diff>
      <filename>vendor/activesupport/lib/active_support/core_ext/object.rb</filename>
    </modified>
    <modified>
      <diff>@@ -3,22 +3,43 @@ class Object
     Class.remove_class(*subclasses_of(*superclasses))
   end
 
-  # Exclude this class unless it's a subclass of our supers and is defined.
-  # We check defined? in case we find a removed class that has yet to be
-  # garbage collected. This also fails for anonymous classes -- please
-  # submit a patch if you have a workaround.
-  def subclasses_of(*superclasses) #:nodoc:
-    subclasses = []
-
-    superclasses.each do |sup|
-      ObjectSpace.each_object(class &lt;&lt; sup; self; end) do |k|
-        if k != sup &amp;&amp; (k.name.blank? || eval(&quot;defined?(::#{k}) &amp;&amp; ::#{k}.object_id == k.object_id&quot;))
-          subclasses &lt;&lt; k
+  begin
+    ObjectSpace.each_object(Class.new) {}
+
+    # Exclude this class unless it's a subclass of our supers and is defined.
+    # We check defined? in case we find a removed class that has yet to be
+    # garbage collected. This also fails for anonymous classes -- please
+    # submit a patch if you have a workaround.
+    def subclasses_of(*superclasses) #:nodoc:
+      subclasses = []
+
+      superclasses.each do |sup|
+        ObjectSpace.each_object(class &lt;&lt; sup; self; end) do |k|
+          if k != sup &amp;&amp; (k.name.blank? || eval(&quot;defined?(::#{k}) &amp;&amp; ::#{k}.object_id == k.object_id&quot;))
+            subclasses &lt;&lt; k
+          end
         end
       end
+
+      subclasses
     end
+  rescue RuntimeError
+    # JRuby and any implementations which cannot handle the objectspace traversal
+    # above fall back to this implementation
+    def subclasses_of(*superclasses) #:nodoc:
+      subclasses = []
 
-    subclasses
+      superclasses.each do |sup|
+        ObjectSpace.each_object(Class) do |k|
+          if superclasses.any? { |superclass| k &lt; superclass } &amp;&amp;
+            (k.name.blank? || eval(&quot;defined?(::#{k}) &amp;&amp; ::#{k}.object_id == k.object_id&quot;))
+            subclasses &lt;&lt; k
+          end
+        end
+        subclasses.uniq!
+      end
+      subclasses
+    end
   end
 
   def extended_by #:nodoc:</diff>
      <filename>vendor/activesupport/lib/active_support/core_ext/object/extending.rb</filename>
    </modified>
    <modified>
      <diff>@@ -35,7 +35,7 @@ class Object
   #   C.new(0, 1).instance_variable_names # =&gt; [&quot;@y&quot;, &quot;@x&quot;]
   if RUBY_VERSION &gt;= '1.9'
     def instance_variable_names
-      instance_variables.map(&amp;:to_s)
+      instance_variables.map { |var| var.to_s }
     end
   else
     alias_method :instance_variable_names, :instance_variables</diff>
      <filename>vendor/activesupport/lib/active_support/core_ext/object/instance_variables.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,35 +1,50 @@
 class Object
-  unless respond_to?(:send!)
-    # Anticipating Ruby 1.9 neutering send
-    alias send! send
-  end
-
-  # A Ruby-ized realization of the K combinator, courtesy of Mikael Brockman.
+  # Returns +value+ after yielding +value+ to the block. This simplifies the
+  # process of constructing an object, performing work on the object, and then
+  # returning the object from a method. It is a Ruby-ized realization of the K
+  # combinator, courtesy of Mikael Brockman.
   #
-  #   def foo
-  #     returning values = [] do
-  #       values &lt;&lt; 'bar'
-  #       values &lt;&lt; 'baz'
-  #     end
-  #   end
+  # ==== Examples
   #
-  #   foo # =&gt; ['bar', 'baz']
+  #  # Without returning
+  #  def foo
+  #    values = []
+  #    values &lt;&lt; &quot;bar&quot;
+  #    values &lt;&lt; &quot;baz&quot;
+  #    return values
+  #  end
   #
-  #   def foo
-  #     returning [] do |values|
-  #       values &lt;&lt; 'bar'
-  #       values &lt;&lt; 'baz'
-  #     end
-  #   end
+  #  foo # =&gt; ['bar', 'baz']
   #
-  #   foo # =&gt; ['bar', 'baz']
+  #  # returning with a local variable
+  #  def foo
+  #    returning values = [] do
+  #      values &lt;&lt; 'bar'
+  #      values &lt;&lt; 'baz'
+  #    end
+  #  end
   #
+  #  foo # =&gt; ['bar', 'baz']
+  #  
+  #  # returning with a block argument
+  #  def foo
+  #    returning [] do |values|
+  #      values &lt;&lt; 'bar'
+  #      values &lt;&lt; 'baz'
+  #    end
+  #  end
+  #  
+  #  foo # =&gt; ['bar', 'baz']
   def returning(value)
     yield(value)
     value
   end
 
-  # An elegant way to refactor out common options
+  # An elegant way to factor duplication out of options passed to a series of
+  # method calls. Each method called in the block, with the block variable as
+  # the receiver, will have its options merged with the default +options+ hash
+  # provided. Each method called on the block variable must take an options
+  # hash as its final argument.
   # 
   #   with_options :order =&gt; 'created_at', :class_name =&gt; 'Comment' do |post|
   #     post.has_many :comments, :conditions =&gt; ['approved = ?', true], :dependent =&gt; :delete_all</diff>
      <filename>vendor/activesupport/lib/active_support/core_ext/object/misc.rb</filename>
    </modified>
    <modified>
      <diff>@@ -5,7 +5,8 @@ require 'rexml/entity'
 # http://www.ruby-lang.org/en/news/2008/08/23/dos-vulnerability-in-rexml/
 # This fix is identical to rexml-expansion-fix version 1.0.1
 
-unless REXML::VERSION &gt; &quot;3.1.7.2&quot;
+# Earlier versions of rexml defined REXML::Version, newer ones REXML::VERSION
+unless REXML::Document.respond_to?(:entity_expansion_limit=)
   module REXML
     class Entity &lt; Child
       undef_method :unnormalized</diff>
      <filename>vendor/activesupport/lib/active_support/core_ext/rexml.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,11 +1,14 @@
+# encoding: utf-8
+
 require 'active_support/core_ext/string/inflections'
 require 'active_support/core_ext/string/conversions'
 require 'active_support/core_ext/string/access'
 require 'active_support/core_ext/string/starts_ends_with'
 require 'active_support/core_ext/string/iterators'
-require 'active_support/core_ext/string/unicode'
+require 'active_support/core_ext/string/multibyte'
 require 'active_support/core_ext/string/xchar'
 require 'active_support/core_ext/string/filters'
+require 'active_support/core_ext/string/behavior'
 
 class String #:nodoc:
   include ActiveSupport::CoreExtensions::String::Access
@@ -14,5 +17,6 @@ class String #:nodoc:
   include ActiveSupport::CoreExtensions::String::Inflections
   include ActiveSupport::CoreExtensions::String::StartsEndsWith
   include ActiveSupport::CoreExtensions::String::Iterators
-  include ActiveSupport::CoreExtensions::String::Unicode
+  include ActiveSupport::CoreExtensions::String::Behavior
+  include ActiveSupport::CoreExtensions::String::Multibyte
 end</diff>
      <filename>vendor/activesupport/lib/active_support/core_ext/string.rb</filename>
    </modified>
    <modified>
      <diff>@@ -11,7 +11,7 @@ module ActiveSupport #:nodoc:
           #   &quot;hello&quot;.at(4)  # =&gt; &quot;o&quot;
           #   &quot;hello&quot;.at(10) # =&gt; nil
           def at(position)
-            chars[position, 1].to_s
+            mb_chars[position, 1].to_s
           end
           
           # Returns the remaining of the string from the +position+ treating the string as an array (where 0 is the first character).
@@ -21,7 +21,7 @@ module ActiveSupport #:nodoc:
           #   &quot;hello&quot;.from(2)  # =&gt; &quot;llo&quot;
           #   &quot;hello&quot;.from(10) # =&gt; nil
           def from(position)
-            chars[position..-1].to_s
+            mb_chars[position..-1].to_s
           end
           
           # Returns the beginning of the string up to the +position+ treating the string as an array (where 0 is the first character).
@@ -31,7 +31,7 @@ module ActiveSupport #:nodoc:
           #   &quot;hello&quot;.to(2)  # =&gt; &quot;hel&quot;
           #   &quot;hello&quot;.to(10) # =&gt; &quot;hello&quot;
           def to(position)
-            chars[0..position].to_s
+            mb_chars[0..position].to_s
           end
 
           # Returns the first character of the string or the first +limit+ characters.
@@ -41,7 +41,7 @@ module ActiveSupport #:nodoc:
           #   &quot;hello&quot;.first(2)  # =&gt; &quot;he&quot;
           #   &quot;hello&quot;.first(10) # =&gt; &quot;hello&quot;
           def first(limit = 1)
-            chars[0..(limit - 1)].to_s
+            mb_chars[0..(limit - 1)].to_s
           end
           
           # Returns the last character of the string or the last +limit+ characters.
@@ -51,7 +51,7 @@ module ActiveSupport #:nodoc:
           #   &quot;hello&quot;.last(2)  # =&gt; &quot;lo&quot;
           #   &quot;hello&quot;.last(10) # =&gt; &quot;hello&quot;
           def last(limit = 1)
-            (chars[(-limit)..-1] || self).to_s
+            (mb_chars[(-limit)..-1] || self).to_s
           end
         end
       else</diff>
      <filename>vendor/activesupport/lib/active_support/core_ext/string/access.rb</filename>
    </modified>
    <modified>
      <diff>@@ -24,8 +24,8 @@ module ActiveSupport #:nodoc:
         #
         #   &quot;posts&quot;.singularize            # =&gt; &quot;post&quot;
         #   &quot;octopi&quot;.singularize           # =&gt; &quot;octopus&quot;
-        #   &quot;sheep&quot;.singluarize            # =&gt; &quot;sheep&quot;
-        #   &quot;word&quot;.singluarize             # =&gt; &quot;word&quot;
+        #   &quot;sheep&quot;.singularize            # =&gt; &quot;sheep&quot;
+        #   &quot;word&quot;.singularize             # =&gt; &quot;word&quot;
         #   &quot;the blue mailmen&quot;.singularize # =&gt; &quot;the blue mailman&quot;
         #   &quot;CamelOctopi&quot;.singularize      # =&gt; &quot;CamelOctopus&quot;
         def singularize
@@ -87,6 +87,25 @@ module ActiveSupport #:nodoc:
           Inflector.demodulize(self)
         end
 
+        # Replaces special characters in a string so that it may be used as part of a 'pretty' URL.
+        # 
+        # ==== Examples
+        #
+        #   class Person
+        #     def to_param
+        #       &quot;#{id}-#{name.parameterize}&quot;
+        #     end
+        #   end
+        # 
+        #   @person = Person.find(1)
+        #   # =&gt; #&lt;Person id: 1, name: &quot;Donald E. Knuth&quot;&gt;
+        # 
+        #   &lt;%= link_to(@person.name, person_path %&gt;
+        #   # =&gt; &lt;a href=&quot;/person/1-donald-e-knuth&quot;&gt;Donald E. Knuth&lt;/a&gt;
+        def parameterize
+          Inflector.parameterize(self)
+        end
+
         # Creates the name of a table like Rails does for models to table names. This method
         # uses the +pluralize+ method on the last word in the string.
         #</diff>
      <filename>vendor/activesupport/lib/active_support/core_ext/string/inflections.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,3 +1,5 @@
+require 'active_support/duration'
+
 module ActiveSupport #:nodoc:
   module CoreExtensions #:nodoc:
     module Time #:nodoc:
@@ -9,13 +11,13 @@ module ActiveSupport #:nodoc:
           base.class_eval do
             alias_method :plus_without_duration, :+
             alias_method :+, :plus_with_duration
-            
+
             alias_method :minus_without_duration, :-
             alias_method :-, :minus_with_duration
-            
+
             alias_method :minus_without_coercion, :-
             alias_method :-, :minus_with_coercion
-            
+
             alias_method :compare_without_coercion, :&lt;=&gt;
             alias_method :&lt;=&gt;, :compare_with_coercion
           end
@@ -28,9 +30,9 @@ module ActiveSupport #:nodoc:
           def ===(other)
             other.is_a?(::Time)
           end
-          
-          # Return the number of days in the given month. 
-          # If no year is specified, it will use the current year. 
+
+          # Return the number of days in the given month.
+          # If no year is specified, it will use the current year.
           def days_in_month(month, year = now.year)
             return 29 if month == 2 &amp;&amp; ::Date.gregorian_leap?(year)
             COMMON_YEAR_DAYS_IN_MONTH[month]
@@ -57,6 +59,21 @@ module ActiveSupport #:nodoc:
           end
         end
 
+        # Tells whether the Time object's time lies in the past
+        def past?
+          self &lt; ::Time.current
+        end
+
+        # Tells whether the Time object's time is today
+        def today?
+          self.to_date == ::Date.current
+        end
+
+        # Tells whether the Time object's time lies in the future
+        def future?
+          self &gt; ::Time.current
+        end
+
         # Seconds since midnight: Time.now.seconds_since_midnight
         def seconds_since_midnight
           self.to_i - self.change(:hour =&gt; 0).to_i + (self.usec/1.0e+6)
@@ -83,6 +100,16 @@ module ActiveSupport #:nodoc:
         # &lt;tt&gt;:months&lt;/tt&gt;, &lt;tt&gt;:weeks&lt;/tt&gt;, &lt;tt&gt;:days&lt;/tt&gt;, &lt;tt&gt;:hours&lt;/tt&gt;,
         # &lt;tt&gt;:minutes&lt;/tt&gt;, &lt;tt&gt;:seconds&lt;/tt&gt;.
         def advance(options)
+          unless options[:weeks].nil?
+            options[:weeks], partial_weeks = options[:weeks].divmod(1)
+            options[:days] = (options[:days] || 0) + 7 * partial_weeks
+          end
+          
+          unless options[:days].nil?
+            options[:days], partial_days = options[:days].divmod(1)
+            options[:hours] = (options[:hours] || 0) + 24 * partial_days
+          end
+          
           d = to_date.advance(options)
           time_advanced_by_date = change(:year =&gt; d.year, :month =&gt; d.month, :day =&gt; d.day)
           seconds_to_advance = (options[:seconds] || 0) + (options[:minutes] || 0) * 60 + (options[:hours] || 0) * 3600
@@ -106,7 +133,7 @@ module ActiveSupport #:nodoc:
             (seconds.abs &gt;= 86400 &amp;&amp; initial_dst != final_dst) ? f + (initial_dst - final_dst).hours : f
           end
         rescue
-          self.to_datetime.since(seconds)          
+          self.to_datetime.since(seconds)
         end
         alias :in :since
 
@@ -199,7 +226,7 @@ module ActiveSupport #:nodoc:
           change(:day =&gt; last_day, :hour =&gt; 23, :min =&gt; 59, :sec =&gt; 59, :usec =&gt; 0)
         end
         alias :at_end_of_month :end_of_month
-		
+
         # Returns  a new Time representing the start of the quarter (1st of january, april, july, october, 0:00)
         def beginning_of_quarter
           beginning_of_month.change(:month =&gt; [10, 7, 4, 1].detect { |m| m &lt;= self.month })
@@ -208,7 +235,7 @@ module ActiveSupport #:nodoc:
 
         # Returns a new Time representing the end of the quarter (last day of march, june, september, december, 23:59:59)
         def end_of_quarter
-          change(:month =&gt; [3, 6, 9, 12].detect { |m| m &gt;= self.month }).end_of_month
+          beginning_of_month.change(:month =&gt; [3, 6, 9, 12].detect { |m| m &gt;= self.month }).end_of_month
         end
         alias :at_end_of_quarter :end_of_quarter
 
@@ -249,7 +276,7 @@ module ActiveSupport #:nodoc:
             minus_without_duration(other)
           end
         end
-        
+
         # Time#- can also be used to determine the number of seconds between two Time instances.
         # We're layering on additional behavior so that ActiveSupport::TimeWithZone instances
         # are coerced into values that Time#- will recognize
@@ -257,11 +284,11 @@ module ActiveSupport #:nodoc:
           other = other.comparable_time if other.respond_to?(:comparable_time)
           minus_without_coercion(other)
         end
-        
+
         # Layers additional behavior on Time#&lt;=&gt; so that DateTime and ActiveSupport::TimeWithZone instances
         # can be chronologically compared with a Time
         def compare_with_coercion(other)
-          # if other is an ActiveSupport::TimeWithZone, coerce a Time instance from it so we can do &lt;=&gt; comparision
+          # if other is an ActiveSupport::TimeWithZone, coerce a Time instance from it so we can do &lt;=&gt; comparison
           other = other.comparable_time if other.respond_to?(:comparable_time)
           if other.acts_like?(:date)
             # other is a Date/DateTime, so coerce self #to_datetime and hand off to DateTime#&lt;=&gt;</diff>
      <filename>vendor/activesupport/lib/active_support/core_ext/time/calculations.rb</filename>
    </modified>
    <modified>
      <diff>@@ -30,6 +30,7 @@ module ActiveSupport #:nodoc:
         #   time.to_s(:time)                    # =&gt; &quot;06:10:17&quot;
         #
         #   time.to_formatted_s(:db)            # =&gt; &quot;2007-01-18 06:10:17&quot;
+        #   time.to_formatted_s(:number)        # =&gt; &quot;20070118061017&quot;
         #   time.to_formatted_s(:short)         # =&gt; &quot;18 Jan 06:10&quot;
         #   time.to_formatted_s(:long)          # =&gt; &quot;January 18, 2007 06:10&quot;
         #   time.to_formatted_s(:long_ordinal)  # =&gt; &quot;January 18th, 2007 06:10&quot;</diff>
      <filename>vendor/activesupport/lib/active_support/core_ext/time/conversions.rb</filename>
    </modified>
    <modified>
      <diff>@@ -78,7 +78,7 @@ module ActiveSupport #:nodoc:
         #
         #   Time.utc(2000).in_time_zone('Alaska')  # =&gt; Fri, 31 Dec 1999 15:00:00 AKST -09:00
         def in_time_zone(zone = ::Time.zone)
-          ActiveSupport::TimeWithZone.new(utc? ? self : getutc, ::Time.send!(:get_zone, zone))
+          ActiveSupport::TimeWithZone.new(utc? ? self : getutc, ::Time.__send__(:get_zone, zone))
         end
       end
     end</diff>
      <filename>vendor/activesupport/lib/active_support/core_ext/time/zones.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,8 +1,3 @@
-require 'set'
-require 'active_support/core_ext/module/attribute_accessors'
-require 'active_support/core_ext/load_error'
-require 'active_support/core_ext/kernel'
-
 module ActiveSupport #:nodoc:
   module Dependencies #:nodoc:
     extend self
@@ -44,6 +39,10 @@ module ActiveSupport #:nodoc:
     mattr_accessor :explicitly_unloadable_constants
     self.explicitly_unloadable_constants = []
 
+    # The logger is used for generating information on the action run-time (including benchmarking) if available.
+    # Can be set to nil for no logging. Compatible with both Ruby's own Logger and Log4r loggers.
+    mattr_accessor :logger
+
     # Set to true to enable logging of const_missing and file loads
     mattr_accessor :log_activity
     self.log_activity = false
@@ -52,6 +51,167 @@ module ActiveSupport #:nodoc:
     mattr_accessor :constant_watch_stack
     self.constant_watch_stack = []
 
+    # Module includes this module
+    module ModuleConstMissing #:nodoc:
+      def self.included(base) #:nodoc:
+        base.class_eval do
+          unless defined? const_missing_without_dependencies
+            alias_method_chain :const_missing, :dependencies
+          end
+        end
+      end
+
+      def self.excluded(base) #:nodoc:
+        base.class_eval do
+          if defined? const_missing_without_dependencies
+            undef_method :const_missing
+            alias_method :const_missing, :const_missing_without_dependencies
+            undef_method :const_missing_without_dependencies
+          end
+        end
+      end
+
+      # Use const_missing to autoload associations so we don't have to
+      # require_association when using single-table inheritance.
+      def const_missing_with_dependencies(class_id)
+        ActiveSupport::Dependencies.load_missing_constant self, class_id
+      end
+
+      def unloadable(const_desc = self)
+        super(const_desc)
+      end
+    end
+
+    # Class includes this module
+    module ClassConstMissing #:nodoc:
+      def const_missing(const_name)
+        if [Object, Kernel].include?(self) || parent == self
+          super
+        else
+          begin
+            begin
+              Dependencies.load_missing_constant self, const_name
+            rescue NameError
+              parent.send :const_missing, const_name
+            end
+          rescue NameError =&gt; e
+            # Make sure that the name we are missing is the one that caused the error
+            parent_qualified_name = Dependencies.qualified_name_for parent, const_name
+            raise unless e.missing_name? parent_qualified_name
+            qualified_name = Dependencies.qualified_name_for self, const_name
+            raise NameError.new(&quot;uninitialized constant #{qualified_name}&quot;).copy_blame!(e)
+          end
+        end
+      end
+    end
+
+    # Object includes this module
+    module Loadable #:nodoc:
+      def self.included(base) #:nodoc:
+        base.class_eval do
+          unless defined? load_without_new_constant_marking
+            alias_method_chain :load, :new_constant_marking
+          end
+        end
+      end
+
+      def self.excluded(base) #:nodoc:
+        base.class_eval do
+          if defined? load_without_new_constant_marking
+            undef_method :load
+            alias_method :load, :load_without_new_constant_marking
+            undef_method :load_without_new_constant_marking
+          end
+        end
+      end
+
+      def require_or_load(file_name)
+        Dependencies.require_or_load(file_name)
+      end
+
+      def require_dependency(file_name)
+        Dependencies.depend_on(file_name)
+      end
+
+      def require_association(file_name)
+        Dependencies.associate_with(file_name)
+      end
+
+      def load_with_new_constant_marking(file, *extras) #:nodoc:
+        if Dependencies.load?
+          Dependencies.new_constants_in(Object) { load_without_new_constant_marking(file, *extras) }
+        else
+          load_without_new_constant_marking(file, *extras)
+        end
+      rescue Exception =&gt; exception  # errors from loading file
+        exception.blame_file! file
+        raise
+      end
+
+      def require(file, *extras) #:nodoc:
+        if Dependencies.load?
+          Dependencies.new_constants_in(Object) { super }
+        else
+          super
+        end
+      rescue Exception =&gt; exception  # errors from required file
+        exception.blame_file! file
+        raise
+      end
+
+      # Mark the given constant as unloadable. Unloadable constants are removed each
+      # time dependencies are cleared.
+      #
+      # Note that marking a constant for unloading need only be done once. Setup
+      # or init scripts may list each unloadable constant that may need unloading;
+      # each constant will be removed for every subsequent clear, as opposed to for
+      # the first clear.
+      #
+      # The provided constant descriptor may be a (non-anonymous) module or class,
+      # or a qualified constant name as a string or symbol.
+      #
+      # Returns true if the constant was not previously marked for unloading, false
+      # otherwise.
+      def unloadable(const_desc)
+        Dependencies.mark_for_unload const_desc
+      end
+    end
+
+    # Exception file-blaming
+    module Blamable #:nodoc:
+      def blame_file!(file)
+        (@blamed_files ||= []).unshift file
+      end
+
+      def blamed_files
+        @blamed_files ||= []
+      end
+
+      def describe_blame
+        return nil if blamed_files.empty?
+        &quot;This error occurred while loading the following files:\n   #{blamed_files.join &quot;\n   &quot;}&quot;
+      end
+
+      def copy_blame!(exc)
+        @blamed_files = exc.blamed_files.clone
+        self
+      end
+    end
+
+    def hook!
+      Object.instance_eval { include Loadable }
+      Module.instance_eval { include ModuleConstMissing }
+      Class.instance_eval { include ClassConstMissing }
+      Exception.instance_eval { include Blamable }
+      true
+    end
+
+    def unhook!
+      ModuleConstMissing.excluded(Module)
+      Loadable.excluded(Object)
+      true
+    end
+
     def load?
       mechanism == :load
     end
@@ -153,6 +313,12 @@ module ActiveSupport #:nodoc:
         nesting = expanded_path[(expanded_root.size)..-1]
         nesting = nesting[1..-1] if nesting &amp;&amp; nesting[0] == ?/
         next if nesting.blank?
+        nesting_camel = nesting.camelize
+        begin
+          qualified_const_defined?(nesting_camel)
+        rescue NameError
+          next
+        end
 
         [
           nesting.camelize,
@@ -339,7 +505,7 @@ module ActiveSupport #:nodoc:
           initial_constants = if qualified_const_defined?(mod_name)
             mod_name.constantize.local_constant_names
           else
-           []
+            []
           end
         else
           raise Argument, &quot;#{desc.inspect} does not describe a module!&quot;
@@ -387,7 +553,7 @@ module ActiveSupport #:nodoc:
     ensure
       # Remove the stack frames that we added.
       if defined?(watch_frames) &amp;&amp; ! watch_frames.blank?
-        frame_ids = watch_frames.collect(&amp;:object_id)
+        frame_ids = watch_frames.collect { |frame| frame.object_id }
         constant_watch_stack.delete_if do |watch_frame|
           frame_ids.include? watch_frame.object_id
         end
@@ -436,8 +602,8 @@ module ActiveSupport #:nodoc:
 
     protected
       def log_call(*args)
-        if defined?(RAILS_DEFAULT_LOGGER) &amp;&amp; RAILS_DEFAULT_LOGGER &amp;&amp; log_activity
-          arg_str = args.collect(&amp;:inspect) * ', '
+        if logger &amp;&amp; log_activity
+          arg_str = args.collect { |arg| arg.inspect } * ', '
           /in `([a-z_\?\!]+)'/ =~ caller(1).first
           selector = $1 || '&lt;unknown&gt;'
           log &quot;called #{selector}(#{arg_str})&quot;
@@ -445,109 +611,11 @@ module ActiveSupport #:nodoc:
       end
 
       def log(msg)
-        if defined?(RAILS_DEFAULT_LOGGER) &amp;&amp; RAILS_DEFAULT_LOGGER &amp;&amp; log_activity
-          RAILS_DEFAULT_LOGGER.debug &quot;Dependencies: #{msg}&quot;
+        if logger &amp;&amp; log_activity
+          logger.debug &quot;Dependencies: #{msg}&quot;
         end
       end
   end
 end
 
-Object.instance_eval do
-  define_method(:require_or_load)     { |file_name| ActiveSupport::Dependencies.require_or_load(file_name) } unless Object.respond_to?(:require_or_load)
-  define_method(:require_dependency)  { |file_name| ActiveSupport::Dependencies.depend_on(file_name) }       unless Object.respond_to?(:require_dependency)
-  define_method(:require_association) { |file_name| ActiveSupport::Dependencies.associate_with(file_name) }  unless Object.respond_to?(:require_association)
-end
-
-class Module #:nodoc:
-  # Rename the original handler so we can chain it to the new one
-  alias :rails_original_const_missing :const_missing
-
-  # Use const_missing to autoload associations so we don't have to
-  # require_association when using single-table inheritance.
-  def const_missing(class_id)
-    ActiveSupport::Dependencies.load_missing_constant self, class_id
-  end
-
-  def unloadable(const_desc = self)
-    super(const_desc)
-  end
-
-end
-
-class Class
-  def const_missing(const_name)
-    if [Object, Kernel].include?(self) || parent == self
-      super
-    else
-      begin
-        begin
-          ActiveSupport::Dependencies.load_missing_constant self, const_name
-        rescue NameError
-          parent.send :const_missing, const_name
-        end
-      rescue NameError =&gt; e
-        # Make sure that the name we are missing is the one that caused the error
-        parent_qualified_name = ActiveSupport::Dependencies.qualified_name_for parent, const_name
-        raise unless e.missing_name? parent_qualified_name
-        qualified_name = ActiveSupport::Dependencies.qualified_name_for self, const_name
-        raise NameError.new(&quot;uninitialized constant #{qualified_name}&quot;).copy_blame!(e)
-      end
-    end
-  end
-end
-
-class Object
-  alias_method :load_without_new_constant_marking, :load
-
-  def load(file, *extras) #:nodoc:
-    ActiveSupport::Dependencies.new_constants_in(Object) { super }
-  rescue Exception =&gt; exception  # errors from loading file
-    exception.blame_file! file
-    raise
-  end
-
-  def require(file, *extras) #:nodoc:
-    ActiveSupport::Dependencies.new_constants_in(Object) { super }
-  rescue Exception =&gt; exception  # errors from required file
-    exception.blame_file! file
-    raise
-  end
-
-  # Mark the given constant as unloadable. Unloadable constants are removed each
-  # time dependencies are cleared.
-  #
-  # Note that marking a constant for unloading need only be done once. Setup
-  # or init scripts may list each unloadable constant that may need unloading;
-  # each constant will be removed for every subsequent clear, as opposed to for
-  # the first clear.
-  #
-  # The provided constant descriptor may be a (non-anonymous) module or class,
-  # or a qualified constant name as a string or symbol.
-  #
-  # Returns true if the constant was not previously marked for unloading, false
-  # otherwise.
-  def unloadable(const_desc)
-    ActiveSupport::Dependencies.mark_for_unload const_desc
-  end
-end
-
-# Add file-blaming to exceptions
-class Exception #:nodoc:
-  def blame_file!(file)
-    (@blamed_files ||= []).unshift file
-  end
-
-  def blamed_files
-    @blamed_files ||= []
-  end
-
-  def describe_blame
-    return nil if blamed_files.empty?
-    &quot;This error occurred while loading the following files:\n   #{blamed_files.join &quot;\n   &quot;}&quot;
-  end
-
-  def copy_blame!(exc)
-    @blamed_files = exc.blamed_files.clone
-    self
-  end
-end
+ActiveSupport::Dependencies.hook!</diff>
      <filename>vendor/activesupport/lib/active_support/dependencies.rb</filename>
    </modified>
    <modified>
      <diff>@@ -51,8 +51,8 @@ module ActiveSupport
 
       private
         def deprecation_message(callstack, message = nil)
-          message ||= &quot;You are using deprecated behavior which will be removed from Rails 2.0.&quot;
-          &quot;DEPRECATION WARNING: #{message}  See http://www.rubyonrails.org/deprecation for details. #{deprecation_caller_message(callstack)}&quot;
+          message ||= &quot;You are using deprecated behavior which will be removed from the next major or minor release.&quot;
+          &quot;DEPRECATION WARNING: #{message}. #{deprecation_caller_message(callstack)}&quot;
         end
 
         def deprecation_caller_message(callstack)
@@ -92,7 +92,7 @@ module ActiveSupport
             class_eval(&lt;&lt;-EOS, __FILE__, __LINE__)
               def #{target}_with_deprecation#{punctuation}(*args, &amp;block)
                 ::ActiveSupport::Deprecation.warn(self.class.deprecated_method_warning(:#{method_name}, #{options[method_name].inspect}), caller)
-                send(:#{target}_without_deprecation#{punctuation}, *args, &amp;block)
+                #{target}_without_deprecation#{punctuation}(*args, &amp;block)
               end
             EOS
           end
@@ -109,7 +109,7 @@ module ActiveSupport
       end
 
       def deprecation_horizon
-        '2.2'
+        '2.3'
       end
     end
 
@@ -162,6 +162,22 @@ module ActiveSupport
         end
     end
 
+    class DeprecatedObjectProxy &lt; DeprecationProxy
+      def initialize(object, message)
+        @object = object
+        @message = message
+      end
+
+      private
+        def target
+          @object
+        end
+
+        def warn(callstack, called, args)
+          ActiveSupport::Deprecation.warn(@message, callstack)
+        end
+    end
+
     # Stand-in for &lt;tt&gt;@request&lt;/tt&gt;, &lt;tt&gt;@attributes&lt;/tt&gt;, &lt;tt&gt;@params&lt;/tt&gt;, etc.
     # which emits deprecation warnings on any method call (except +inspect+).
     class DeprecatedInstanceVariableProxy &lt; DeprecationProxy #:nodoc:
@@ -185,6 +201,10 @@ module ActiveSupport
         @new_const = new_const
       end
 
+      def class
+        target.class
+      end
+
       private
         def target
           @new_const.to_s.constantize</diff>
      <filename>vendor/activesupport/lib/active_support/deprecation.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,4 +1,6 @@
+# encoding: utf-8
 require 'singleton'
+require 'iconv'
 
 module ActiveSupport
   # The Inflector transforms words from singular to plural, class names to table names, modularized class names to ones without,
@@ -10,10 +12,12 @@ module ActiveSupport
   # If you discover an incorrect inflection and require it for your application, you'll need
   # to correct it yourself (explained below).
   module Inflector
+    extend self
+
     # A singleton instance of this class is yielded by Inflector.inflections, which can then be used to specify additional
     # inflection rules. Examples:
     #
-    #   Inflector.inflections do |inflect|
+    #   ActiveSupport::Inflector.inflections do |inflect|
     #     inflect.plural /^(ox)$/i, '\1\2en'
     #     inflect.singular /^(ox)en/i, '\1'
     #
@@ -28,21 +32,25 @@ module ActiveSupport
     class Inflections
       include Singleton
 
-      attr_reader :plurals, :singulars, :uncountables
+      attr_reader :plurals, :singulars, :uncountables, :humans
 
       def initialize
-        @plurals, @singulars, @uncountables = [], [], []
+        @plurals, @singulars, @uncountables, @humans = [], [], [], []
       end
 
       # Specifies a new pluralization rule and its replacement. The rule can either be a string or a regular expression.
       # The replacement should always be a string that may include references to the matched data from the rule.
       def plural(rule, replacement)
+        @uncountables.delete(rule) if rule.is_a?(String)
+        @uncountables.delete(replacement)
         @plurals.insert(0, [rule, replacement])
       end
 
       # Specifies a new singularization rule and its replacement. The rule can either be a string or a regular expression.
       # The replacement should always be a string that may include references to the matched data from the rule.
       def singular(rule, replacement)
+        @uncountables.delete(rule) if rule.is_a?(String)
+        @uncountables.delete(replacement)
         @singulars.insert(0, [rule, replacement])
       end
 
@@ -53,6 +61,8 @@ module ActiveSupport
       #   irregular 'octopus', 'octopi'
       #   irregular 'person', 'people'
       def irregular(singular, plural)
+        @uncountables.delete(singular)
+        @uncountables.delete(plural)
         if singular[0,1].upcase == plural[0,1].upcase
           plural(Regexp.new(&quot;(#{singular[0,1]})#{singular[1..-1]}$&quot;, &quot;i&quot;), '\1' + plural[1..-1])
           singular(Regexp.new(&quot;(#{plural[0,1]})#{plural[1..-1]}$&quot;, &quot;i&quot;), '\1' + singular[1..-1])
@@ -74,9 +84,20 @@ module ActiveSupport
         (@uncountables &lt;&lt; words).flatten!
       end
 
+      # Specifies a humanized form of a string by a regular expression rule or by a string mapping.
+      # When using a regular expression based replacement, the normal humanize formatting is called after the replacement.
+      # When a string is used, the human form should be specified as desired (example: 'The name', not 'the_name')
+      #
+      # Examples:
+      #   human /_cnt$/i, '\1_count'
+      #   human &quot;legacy_col_person_name&quot;, &quot;Name&quot;
+      def human(rule, replacement)
+        @humans.insert(0, [rule, replacement])
+      end
+
       # Clears the loaded inflections within a given scope (default is &lt;tt&gt;:all&lt;/tt&gt;).
       # Give the scope as a symbol of the inflection type, the options are: &lt;tt&gt;:plurals&lt;/tt&gt;,
-      # &lt;tt&gt;:singulars&lt;/tt&gt;, &lt;tt&gt;:uncountables&lt;/tt&gt;.
+      # &lt;tt&gt;:singulars&lt;/tt&gt;, &lt;tt&gt;:uncountables&lt;/tt&gt;, &lt;tt&gt;:humans&lt;/tt&gt;.
       #
       # Examples:
       #   clear :all
@@ -91,13 +112,11 @@ module ActiveSupport
       end
     end
 
-    extend self
-
     # Yields a singleton instance of Inflector::Inflections so you can specify additional
     # inflector rules.
     #
     # Example:
-    #   Inflector.inflections do |inflect|
+    #   ActiveSupport::Inflector.inflections do |inflect|
     #     inflect.uncountable &quot;rails&quot;
     #   end
     def inflections
@@ -115,7 +134,6 @@ module ActiveSupport
     #   &quot;octopus&quot;.pluralize          # =&gt; &quot;octopi&quot;
     #   &quot;sheep&quot;.pluralize            # =&gt; &quot;sheep&quot;
     #   &quot;words&quot;.pluralize            # =&gt; &quot;words&quot;
-    #   &quot;the blue mailman&quot;.pluralize # =&gt; &quot;the blue mailmen&quot;
     #   &quot;CamelOctopus&quot;.pluralize     # =&gt; &quot;CamelOctopi&quot;
     def pluralize(word)
       result = word.to_s.dup
@@ -134,8 +152,7 @@ module ActiveSupport
     #   &quot;posts&quot;.singularize            # =&gt; &quot;post&quot;
     #   &quot;octopi&quot;.singularize           # =&gt; &quot;octopus&quot;
     #   &quot;sheep&quot;.singluarize            # =&gt; &quot;sheep&quot;
-    #   &quot;word&quot;.singluarize             # =&gt; &quot;word&quot;
-    #   &quot;the blue mailmen&quot;.singularize # =&gt; &quot;the blue mailman&quot;
+    #   &quot;word&quot;.singularize             # =&gt; &quot;word&quot;
     #   &quot;CamelOctopi&quot;.singularize      # =&gt; &quot;CamelOctopus&quot;
     def singularize(word)
       result = word.to_s.dup
@@ -162,7 +179,7 @@ module ActiveSupport
       if first_letter_in_uppercase
         lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { &quot;::#{$1.upcase}&quot; }.gsub(/(?:^|_)(.)/) { $1.upcase }
       else
-        lower_case_and_underscored_word.first + camelize(lower_case_and_underscored_word)[1..-1]
+        lower_case_and_underscored_word.first.downcase + camelize(lower_case_and_underscored_word)[1..-1]
       end
     end
 
@@ -209,7 +226,10 @@ module ActiveSupport
     #   &quot;employee_salary&quot; # =&gt; &quot;Employee salary&quot;
     #   &quot;author_id&quot;       # =&gt; &quot;Author&quot;
     def humanize(lower_case_and_underscored_word)
-      lower_case_and_underscored_word.to_s.gsub(/_id$/, &quot;&quot;).gsub(/_/, &quot; &quot;).capitalize
+      result = lower_case_and_underscored_word.to_s.dup
+
+      inflections.humans.each { |(rule, replacement)| break if result.gsub!(rule, replacement) }
+      result.gsub(/_id$/, &quot;&quot;).gsub(/_/, &quot; &quot;).capitalize
     end
 
     # Removes the module part from the expression in the string.
@@ -221,6 +241,50 @@ module ActiveSupport
       class_name_in_module.to_s.gsub(/^.*::/, '')
     end
 
+    # Replaces special characters in a string so that it may be used as part of a 'pretty' URL.
+    #
+    # ==== Examples
+    #
+    #   class Person
+    #     def to_param
+    #       &quot;#{id}-#{name.parameterize}&quot;
+    #     end
+    #   end
+    #
+    #   @person = Person.find(1)
+    #   # =&gt; #&lt;Person id: 1, name: &quot;Donald E. Knuth&quot;&gt;
+    #
+    #   &lt;%= link_to(@person.name, person_path %&gt;
+    #   # =&gt; &lt;a href=&quot;/person/1-donald-e-knuth&quot;&gt;Donald E. Knuth&lt;/a&gt;
+    def parameterize(string, sep = '-')
+      re_sep = Regexp.escape(sep)
+      # replace accented chars with ther ascii equivalents
+      parameterized_string = transliterate(string)
+      # Turn unwanted chars into the seperator
+      parameterized_string.gsub!(/[^a-z0-9\-_\+]+/i, sep)
+      # No more than one of the separator in a row.
+      parameterized_string.squeeze!(sep)
+      # Remove leading/trailing separator.
+      parameterized_string.gsub!(/^#{re_sep}|#{re_sep}$/i, '')
+      parameterized_string.downcase
+    end
+
+
+    # Replaces accented characters with their ascii equivalents.
+    def transliterate(string)
+      Iconv.iconv('ascii//ignore//translit', 'utf-8', string).to_s
+    end
+
+    # The iconv transliteration code doesn't function correctly
+    # on some platforms, but it's very fast where it does function.
+    if &quot;foo&quot; != Inflector.transliterate(&quot;f&#246;&#246;&quot;)
+      undef_method :transliterate
+      def transliterate(string)
+        string.mb_chars.normalize(:kd). # Decompose accented characters
+          gsub(/[^\x00-\x7F]+/, '')     # Remove anything non-ASCII entirely (e.g. diacritics).
+      end
+    end
+
     # Create the name of a table like Rails does for models to table names. This method
     # uses the +pluralize+ method on the last word in the string.
     #
@@ -259,32 +323,47 @@ module ActiveSupport
       underscore(demodulize(class_name)) + (separate_class_name_and_id_with_underscore ? &quot;_id&quot; : &quot;id&quot;)
     end
 
-    # Tries to find a constant with the name specified in the argument string:
-    #
-    #   &quot;Module&quot;.constantize     # =&gt; Module
-    #   &quot;Test::Unit&quot;.constantize # =&gt; Test::Unit
-    #
-    # The name is assumed to be the one of a top-level constant, no matter whether
-    # it starts with &quot;::&quot; or not. No lexical context is taken into account:
-    #
-    #   C = 'outside'
-    #   module M
-    #     C = 'inside'
-    #     C               # =&gt; 'inside'
-    #     &quot;C&quot;.constantize # =&gt; 'outside', same as ::C
-    #   end
-    #
-    # NameError is raised when the name is not in CamelCase or the constant is
-    # unknown.
-    def constantize(camel_cased_word)
-      names = camel_cased_word.split('::')
-      names.shift if names.empty? || names.first.empty?
-
-      constant = Object
-      names.each do |name|
-        constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
+    # Ruby 1.9 introduces an inherit argument for Module#const_get and
+    # #const_defined? and changes their default behavior.
+    if Module.method(:const_get).arity == 1
+      # Tries to find a constant with the name specified in the argument string:
+      #
+      #   &quot;Module&quot;.constantize     # =&gt; Module
+      #   &quot;Test::Unit&quot;.constantize # =&gt; Test::Unit
+      #
+      # The name is assumed to be the one of a top-level constant, no matter whether
+      # it starts with &quot;::&quot; or not. No lexical context is taken into account:
+      #
+      #   C = 'outside'
+      #   module M
+      #     C = 'inside'
+      #     C               # =&gt; 'inside'
+      #     &quot;C&quot;.constantize # =&gt; 'outside', same as ::C
+      #   end
+      #
+      # NameError is raised when the name is not in CamelCase or the constant is
+      # unknown.
+      def constantize(camel_cased_word)
+        names = camel_cased_word.split('::')
+        names.shift if names.empty? || names.first.empty?
+
+        constant = Object
+        names.each do |name|
+          constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
+        end
+        constant
+      end
+    else
+      def constantize(camel_cased_word) #:nodoc:
+        names = camel_cased_word.split('::')
+        names.shift if names.empty? || names.first.empty?
+
+        constant = Object
+        names.each do |name|
+          constant = constant.const_get(name, false) || constant.const_missing(name)
+        end
+        constant
       end
-      constant
     end
 
     # Turns a number into an ordinal string used to denote the position in an
@@ -310,4 +389,9 @@ module ActiveSupport
   end
 end
 
-require File.dirname(__FILE__) + '/inflections'
+# in case active_support/inflector is required without the rest of active_support
+require 'active_support/inflections'
+require 'active_support/core_ext/string/inflections'
+unless String.included_modules.include?(ActiveSupport::CoreExtensions::String::Inflections)
+  String.send :include, ActiveSupport::CoreExtensions::String::Inflections
+end</diff>
      <filename>vendor/activesupport/lib/active_support/inflector.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,5 +1,5 @@
 module ActiveSupport
-  # If true, use ISO 8601 format for dates and times.  Otherwise, fall back to the Active Support legacy format.
+  # If true, use ISO 8601 format for dates and times. Otherwise, fall back to the Active Support legacy format.
   mattr_accessor :use_standard_json_time_format
 
   class &lt;&lt; self</diff>
      <filename>vendor/activesupport/lib/active_support/json.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,7 +1,14 @@
 class Date
-  # Returns a JSON string representing the date.
+  # Returns a JSON string representing the date. If ActiveSupport.use_standard_json_time_format is set to true, the
+  # ISO 8601 format is used.
   #
-  # ==== Example:
+  # ==== Examples:
+  #
+  #   # With ActiveSupport.use_standard_json_time_format = true
+  #   Date.new(2005,2,1).to_json
+  #   # =&gt; &quot;2005-02-01&quot;
+  #
+  #   # With ActiveSupport.use_standard_json_time_format = false
   #   Date.new(2005,2,1).to_json
   #   # =&gt; &quot;2005/02/01&quot;
   def to_json(options = nil)</diff>
      <filename>vendor/activesupport/lib/active_support/json/encoders/date.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,7 +1,14 @@
 class DateTime
-  # Returns a JSON string representing the datetime.
+  # Returns a JSON string representing the datetime. If ActiveSupport.use_standard_json_time_format is set to true, the
+  # ISO 8601 format is used.
   #
-  # ==== Example:
+  # ==== Examples:
+  #
+  #   # With ActiveSupport.use_standard_json_time_format = true
+  #   DateTime.civil(2005,2,1,15,15,10).to_json
+  #   # =&gt; &quot;2005-02-01T15:15:10+00:00&quot;
+  #
+  #   # With ActiveSupport.use_standard_json_time_format = false
   #   DateTime.civil(2005,2,1,15,15,10).to_json
   #   # =&gt; &quot;2005/02/01 15:15:10 +0000&quot;
   def to_json(options = nil)</diff>
      <filename>vendor/activesupport/lib/active_support/json/encoders/date_time.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,9 +1,16 @@
 class Time
-  # Returns a JSON string representing the time.
+  # Returns a JSON string representing the time. If ActiveSupport.use_standard_json_time_format is set to true, the
+  # ISO 8601 format is used.
   #
-  # ==== Example:
+  # ==== Examples:
+  #
+  #   # With ActiveSupport.use_standard_json_time_format = true
+  #   Time.utc(2005,2,1,15,15,10).to_json
+  #   # =&gt; &quot;2005-02-01T15:15:10Z&quot;
+  #
+  #   # With ActiveSupport.use_standard_json_time_format = false
   #   Time.utc(2005,2,1,15,15,10).to_json
-  #   # =&gt; 2005/02/01 15:15:10 +0000&quot;
+  #   # =&gt; &quot;2005/02/01 15:15:10 +0000&quot;
   def to_json(options = nil)
     if ActiveSupport.use_standard_json_time_format
       xmlschema.inspect</diff>
      <filename>vendor/activesupport/lib/active_support/json/encoders/time.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,9 +1,33 @@
-module ActiveSupport
-  module Multibyte #:nodoc:
-    DEFAULT_NORMALIZATION_FORM = :kc
-    NORMALIZATIONS_FORMS = [:c, :kc, :d, :kd]
-    UNICODE_VERSION = '5.0.0'
-  end
-end
+# encoding: utf-8
 
 require 'active_support/multibyte/chars'
+require 'active_support/multibyte/exceptions'
+require 'active_support/multibyte/unicode_database'
+
+module ActiveSupport #:nodoc:
+  module Multibyte
+    # A list of all available normalization forms. See http://www.unicode.org/reports/tr15/tr15-29.html for more
+    # information about normalization.
+    NORMALIZATION_FORMS = [:c, :kc, :d, :kd]
+
+    # The Unicode version that is supported by the implementation
+    UNICODE_VERSION = '5.1.0'
+
+    # The default normalization used for operations that require normalization. It can be set to any of the
+    # normalizations in NORMALIZATION_FORMS.
+    #
+    # Example:
+    #   ActiveSupport::Multibyte.default_normalization_form = :c
+    mattr_accessor :default_normalization_form
+    self.default_normalization_form = :kc
+
+    # The proxy class returned when calling mb_chars. You can use this accessor to configure your own proxy
+    # class so you can support other encodings. See the ActiveSupport::Multibyte::Chars implementation for
+    # an example how to do this.
+    #
+    # Example:
+    #   ActiveSupport::Multibyte.proxy_class = CharsForUTF32
+    mattr_accessor :proxy_class
+    self.proxy_class = ActiveSupport::Multibyte::Chars
+  end
+end</diff>
      <filename>vendor/activesupport/lib/active_support/multibyte.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,137 +1,679 @@
-require 'active_support/multibyte/handlers/utf8_handler'
-require 'active_support/multibyte/handlers/passthru_handler'
-
-# Encapsulates all the functionality related to the Chars proxy.
-module ActiveSupport::Multibyte #:nodoc:
-  # Chars enables you to work transparently with multibyte encodings in the Ruby String class without having extensive
-  # knowledge about the encoding. A Chars object accepts a string upon initialization and proxies String methods in an
-  # encoding safe manner. All the normal String methods are also implemented on the proxy.
-  #
-  # String methods are proxied through the Chars object, and can be accessed through the +chars+ method. Methods
-  # which would normally return a String object now return a Chars object so methods can be chained.
-  #
-  #   &quot;The Perfect String  &quot;.chars.downcase.strip.normalize # =&gt; &quot;the perfect string&quot;
-  #
-  # Chars objects are perfectly interchangeable with String objects as long as no explicit class checks are made.
-  # If certain methods do explicitly check the class, call +to_s+ before you pass chars objects to them.
-  #
-  #   bad.explicit_checking_method &quot;T&quot;.chars.downcase.to_s
-  #
-  # The actual operations on the string are delegated to handlers. Theoretically handlers can be implemented for
-  # any encoding, but the default handler handles UTF-8. This handler is set during initialization, if you want to
-  # use you own handler, you can set it on the Chars class. Look at the UTF8Handler source for an example how to
-  # implement your own handler. If you your own handler to work on anything but UTF-8 you probably also
-  # want to override Chars#handler.
-  #
-  #   ActiveSupport::Multibyte::Chars.handler = MyHandler
-  #
-  # Note that a few methods are defined on Chars instead of the handler because they are defined on Object or Kernel
-  # and method_missing can't catch them.
-  class Chars
-    
-    attr_reader :string # The contained string
-    alias_method :to_s, :string
-    
-    include Comparable
-    
-    # The magic method to make String and Chars comparable
-    def to_str
-      # Using any other ways of overriding the String itself will lead you all the way from infinite loops to
-      # core dumps. Don't go there.
-      @string
-    end
+# encoding: utf-8
+
+module ActiveSupport #:nodoc:
+  module Multibyte #:nodoc:
+    # Chars enables you to work transparently with UTF-8 encoding in the Ruby String class without having extensive
+    # knowledge about the encoding. A Chars object accepts a string upon initialization and proxies String methods in an
+    # encoding safe manner. All the normal String methods are also implemented on the proxy.
+    #
+    # String methods are proxied through the Chars object, and can be accessed through the +mb_chars+ method. Methods
+    # which would normally return a String object now return a Chars object so methods can be chained.
+    #
+    #   &quot;The Perfect String  &quot;.mb_chars.downcase.strip.normalize #=&gt; &quot;the perfect string&quot;
+    #
+    # Chars objects are perfectly interchangeable with String objects as long as no explicit class checks are made.
+    # If certain methods do explicitly check the class, call +to_s+ before you pass chars objects to them.
+    #
+    #   bad.explicit_checking_method &quot;T&quot;.mb_chars.downcase.to_s
+    #
+    # The default Chars implementation assumes that the encoding of the string is UTF-8, if you want to handle different
+    # encodings you can write your own multibyte string handler and configure it through 
+    # ActiveSupport::Multibyte.proxy_class.
+    #
+    #   class CharsForUTF32
+    #     def size
+    #       @wrapped_string.size / 4
+    #     end
+    #
+    #     def self.accepts?(string)
+    #       string.length % 4 == 0
+    #     end
+    #   end
+    #
+    #   ActiveSupport::Multibyte.proxy_class = CharsForUTF32
+    class Chars
+      # Hangul character boundaries and properties
+      HANGUL_SBASE = 0xAC00
+      HANGUL_LBASE = 0x1100
+      HANGUL_VBASE = 0x1161
+      HANGUL_TBASE = 0x11A7
+      HANGUL_LCOUNT = 19
+      HANGUL_VCOUNT = 21
+      HANGUL_TCOUNT = 28
+      HANGUL_NCOUNT = HANGUL_VCOUNT * HANGUL_TCOUNT
+      HANGUL_SCOUNT = 11172
+      HANGUL_SLAST = HANGUL_SBASE + HANGUL_SCOUNT
+      HANGUL_JAMO_FIRST = 0x1100
+      HANGUL_JAMO_LAST = 0x11FF
+
+      # All the unicode whitespace
+      UNICODE_WHITESPACE = [
+        (0x0009..0x000D).to_a, # White_Space # Cc   [5] &lt;control-0009&gt;..&lt;control-000D&gt;
+        0x0020,                # White_Space # Zs       SPACE
+        0x0085,                # White_Space # Cc       &lt;control-0085&gt;
+        0x00A0,                # White_Space # Zs       NO-BREAK SPACE
+        0x1680,                # White_Space # Zs       OGHAM SPACE MARK
+        0x180E,                # White_Space # Zs       MONGOLIAN VOWEL SEPARATOR
+        (0x2000..0x200A).to_a, # White_Space # Zs  [11] EN QUAD..HAIR SPACE
+        0x2028,                # White_Space # Zl       LINE SEPARATOR
+        0x2029,                # White_Space # Zp       PARAGRAPH SEPARATOR
+        0x202F,                # White_Space # Zs       NARROW NO-BREAK SPACE
+        0x205F,                # White_Space # Zs       MEDIUM MATHEMATICAL SPACE
+        0x3000,                # White_Space # Zs       IDEOGRAPHIC SPACE
+      ].flatten.freeze
+
+      # BOM (byte order mark) can also be seen as whitespace, it's a non-rendering character used to distinguish
+      # between little and big endian. This is not an issue in utf-8, so it must be ignored.
+      UNICODE_LEADERS_AND_TRAILERS = UNICODE_WHITESPACE + [65279] # ZERO-WIDTH NO-BREAK SPACE aka BOM
+
+      # Returns a regular expression pattern that matches the passed Unicode codepoints
+      def self.codepoints_to_pattern(array_of_codepoints) #:nodoc:
+        array_of_codepoints.collect{ |e| [e].pack 'U*' }.join('|')
+      end
+      UNICODE_TRAILERS_PAT = /(#{codepoints_to_pattern(UNICODE_LEADERS_AND_TRAILERS)})+\Z/
+      UNICODE_LEADERS_PAT = /\A(#{codepoints_to_pattern(UNICODE_LEADERS_AND_TRAILERS)})+/
+
+      # Borrowed from the Kconv library by Shinji KONO - (also as seen on the W3C site)
+      UTF8_PAT = /\A(?:
+                     [\x00-\x7f]                                     |
+                     [\xc2-\xdf] [\x80-\xbf]                         |
+                     \xe0        [\xa0-\xbf] [\x80-\xbf]             |
+                     [\xe1-\xef] [\x80-\xbf] [\x80-\xbf]             |
+                     \xf0        [\x90-\xbf] [\x80-\xbf] [\x80-\xbf] |
+                     [\xf1-\xf3] [\x80-\xbf] [\x80-\xbf] [\x80-\xbf] |
+                     \xf4        [\x80-\x8f] [\x80-\xbf] [\x80-\xbf]
+                    )*\z/xn
+
+      attr_reader :wrapped_string
+      alias to_s wrapped_string
+      alias to_str wrapped_string
+
+      if '1.9'.respond_to?(:force_encoding)
+        # Creates a new Chars instance by wrapping _string_.
+        def initialize(string)
+          @wrapped_string = string
+          @wrapped_string.force_encoding(Encoding::UTF_8) unless @wrapped_string.frozen?
+        end
+      else
+        def initialize(string) #:nodoc:
+          @wrapped_string = string
+        end
+      end
+
+      # Forward all undefined methods to the wrapped string.
+      def method_missing(method, *args, &amp;block)
+        if method.to_s =~ /!$/
+          @wrapped_string.__send__(method, *args, &amp;block)
+          self
+        else
+          result = @wrapped_string.__send__(method, *args, &amp;block)
+          result.kind_of?(String) ? chars(result) : result
+        end
+      end
 
-    # Make duck-typing with String possible
-    def respond_to?(method, include_priv = false)
-      super || @string.respond_to?(method, include_priv) ||
-        handler.respond_to?(method, include_priv) ||
-        (method.to_s =~ /(.*)!/ &amp;&amp; handler.respond_to?($1, include_priv)) ||
+      # Returns +true+ if _obj_ responds to the given method. Private methods are included in the search
+      # only if the optional second parameter evaluates to +true+.
+      def respond_to?(method, include_private=false)
+        super || @wrapped_string.respond_to?(method, include_private) || false
+      end
+
+      # Enable more predictable duck-typing on String-like classes. See Object#acts_like?.
+      def acts_like_string?
+        true
+      end
+
+      # Returns +true+ if the Chars class can and should act as a proxy for the string _string_. Returns
+      # +false+ otherwise.
+      def self.wants?(string)
+        $KCODE == 'UTF8' &amp;&amp; consumes?(string)
+      end
+
+      # Returns +true+ when the proxy class can handle the string. Returns +false+ otherwise.
+      def self.consumes?(string)
+        # Unpack is a little bit faster than regular expressions.
+        string.unpack('U*')
+        true
+      rescue ArgumentError
         false
-    end
+      end
 
-    # Create a new Chars instance.
-    def initialize(str)
-      @string = str.respond_to?(:string) ? str.string : str
-    end
-    
-    # Returns -1, 0 or +1 depending on whether the Chars object is to be sorted before, equal or after the
-    # object on the right side of the operation. It accepts any object that implements +to_s+. See String.&lt;=&gt;
-    # for more details.
-    def &lt;=&gt;(other); @string &lt;=&gt; other.to_s; end
-    
-    # Works just like String#split, with the exception that the items in the resulting list are Chars
-    # instances instead of String. This makes chaining methods easier.
-    def split(*args)
-      @string.split(*args).map { |i| i.chars }
-    end
-    
-    # Gsub works exactly the same as gsub on a normal string.
-    def gsub(*a, &amp;b); @string.gsub(*a, &amp;b).chars; end
-    
-    # Like String.=~ only it returns the character offset (in codepoints) instead of the byte offset.
-    def =~(other)
-      handler.translate_offset(@string, @string =~ other)
-    end
-    
-    # Try to forward all undefined methods to the handler, when a method is not defined on the handler, send it to
-    # the contained string. Method_missing is also responsible for making the bang! methods destructive.
-    def method_missing(m, *a, &amp;b)
-      begin
-        # Simulate methods with a ! at the end because we can't touch the enclosed string from the handlers.
-        if m.to_s =~ /^(.*)\!$/ &amp;&amp; handler.respond_to?($1)
-          result = handler.send($1, @string, *a, &amp;b)
-          if result == @string
-            result = nil
+      include Comparable
+
+      # Returns &lt;tt&gt;-1&lt;/tt&gt;, &lt;tt&gt;0&lt;/tt&gt; or &lt;tt&gt;+1&lt;/tt&gt; depending on whether the Chars object is to be sorted before,
+      # equal or after the object on the right side of the operation. It accepts any object that implements +to_s+.
+      # See &lt;tt&gt;String#&lt;=&gt;&lt;/tt&gt; for more details.
+      #
+      # Example:
+      #   '&#233;'.mb_chars &lt;=&gt; '&#252;'.mb_chars #=&gt; -1
+      def &lt;=&gt;(other)
+        @wrapped_string &lt;=&gt; other.to_s
+      end
+
+      # Returns a new Chars object containing the _other_ object concatenated to the string.
+      #
+      # Example:
+      #   ('Caf&#233;'.mb_chars + ' p&#233;rifer&#244;l').to_s #=&gt; &quot;Caf&#233; p&#233;rifer&#244;l&quot;
+      def +(other)
+        self &lt;&lt; other
+      end
+
+      # Like &lt;tt&gt;String#=~&lt;/tt&gt; only it returns the character offset (in codepoints) instead of the byte offset.
+      #
+      # Example:
+      #   'Caf&#233; p&#233;rifer&#244;l'.mb_chars =~ /&#244;/ #=&gt; 12
+      def =~(other)
+        translate_offset(@wrapped_string =~ other)
+      end
+
+      # Works just like &lt;tt&gt;String#split&lt;/tt&gt;, with the exception that the items in the resulting list are Chars
+      # instances instead of String. This makes chaining methods easier.
+      #
+      # Example:
+      #   'Caf&#233; p&#233;rifer&#244;l'.mb_chars.split(/&#233;/).map { |part| part.upcase.to_s } #=&gt; [&quot;CAF&quot;, &quot; P&quot;, &quot;RIFER&#212;L&quot;]
+      def split(*args)
+        @wrapped_string.split(*args).map { |i| i.mb_chars }
+      end
+
+      # Inserts the passed string at specified codepoint offsets.
+      #
+      # Example:
+      #   'Caf&#233;'.mb_chars.insert(4, ' p&#233;rifer&#244;l').to_s #=&gt; &quot;Caf&#233; p&#233;rifer&#244;l&quot;
+      def insert(offset, fragment)
+        unpacked = self.class.u_unpack(@wrapped_string)
+        unless offset &gt; unpacked.length
+          @wrapped_string.replace(
+            self.class.u_unpack(@wrapped_string).insert(offset, *self.class.u_unpack(fragment)).pack('U*')
+          )
+        else
+          raise IndexError, &quot;index #{offset} out of string&quot;
+        end
+        self
+      end
+
+      # Returns +true+ if contained string contains _other_. Returns +false+ otherwise.
+      #
+      # Example:
+      #   'Caf&#233;'.mb_chars.include?('&#233;') #=&gt; true
+      def include?(other)
+        # We have to redefine this method because Enumerable defines it.
+        @wrapped_string.include?(other)
+      end
+
+      # Returns the position _needle_ in the string, counting in codepoints. Returns +nil+ if _needle_ isn't found.
+      #
+      # Example:
+      #   'Caf&#233; p&#233;rifer&#244;l'.mb_chars.index('&#244;') #=&gt; 12
+      #   'Caf&#233; p&#233;rifer&#244;l'.mb_chars.index(/\w/u) #=&gt; 0
+      def index(needle, offset=0)
+        index = @wrapped_string.index(needle, offset)
+        index ? (self.class.u_unpack(@wrapped_string.slice(0...index)).size) : nil
+      end
+
+      # Like &lt;tt&gt;String#[]=&lt;/tt&gt;, except instead of byte offsets you specify character offsets.
+      #
+      # Example:
+      #
+      #   s = &quot;M&#252;ller&quot;
+      #   s.mb_chars[2] = &quot;e&quot; # Replace character with offset 2
+      #   s
+      #   #=&gt; &quot;M&#252;eler&quot;
+      #
+      #   s = &quot;M&#252;ller&quot;
+      #   s.mb_chars[1, 2] = &quot;&#246;&quot; # Replace 2 characters at character offset 1
+      #   s
+      #   #=&gt; &quot;M&#246;ler&quot;
+      def []=(*args)
+        replace_by = args.pop
+        # Indexed replace with regular expressions already works
+        if args.first.is_a?(Regexp)
+          @wrapped_string[*args] = replace_by
+        else
+          result = self.class.u_unpack(@wrapped_string)
+          if args[0].is_a?(Fixnum)
+            raise IndexError, &quot;index #{args[0]} out of string&quot; if args[0] &gt;= result.length
+            min = args[0]
+            max = args[1].nil? ? min : (min + args[1] - 1)
+            range = Range.new(min, max)
+            replace_by = [replace_by].pack('U') if replace_by.is_a?(Fixnum)
+          elsif args.first.is_a?(Range)
+            raise RangeError, &quot;#{args[0]} out of range&quot; if args[0].min &gt;= result.length
+            range = args[0]
           else
-            @string.replace result
+            needle = args[0].to_s
+            min = index(needle)
+            max = min + self.class.u_unpack(needle).length - 1
+            range = Range.new(min, max)
           end
-        elsif handler.respond_to?(m)
-          result = handler.send(m, @string, *a, &amp;b)
-        else
-          result = @string.send(m, *a, &amp;b)
+          result[range] = self.class.u_unpack(replace_by)
+          @wrapped_string.replace(result.pack('U*'))
         end
-      rescue Handlers::EncodingError
-        @string.replace handler.tidy_bytes(@string)
-        retry
       end
-      
-      if result.kind_of?(String)
-        result.chars
-      else
-        result
+
+      # Works just like &lt;tt&gt;String#rjust&lt;/tt&gt;, only integer specifies characters instead of bytes.
+      #
+      # Example:
+      #
+      #   &quot;&#190; cup&quot;.mb_chars.rjust(8).to_s
+      #   #=&gt; &quot;   &#190; cup&quot;
+      #
+      #   &quot;&#190; cup&quot;.mb_chars.rjust(8, &quot;&#160;&quot;).to_s # Use non-breaking whitespace
+      #   #=&gt; &quot;&#160;&#160;&#160;&#190; cup&quot;
+      def rjust(integer, padstr=' ')
+        justify(integer, :right, padstr)
       end
-    end
-    
-    # Set the handler class for the Char objects.
-    def self.handler=(klass)
-      @@handler = klass
-    end
 
-    # Returns the proper handler for the contained string depending on $KCODE and the encoding of the string. This
-    # method is used internally to always redirect messages to the proper classes depending on the context.
-    def handler
-      if utf8_pragma?
-        @@handler
-      else
-        ActiveSupport::Multibyte::Handlers::PassthruHandler
+      # Works just like &lt;tt&gt;String#ljust&lt;/tt&gt;, only integer specifies characters instead of bytes.
+      #
+      # Example:
+      #
+      #   &quot;&#190; cup&quot;.mb_chars.rjust(8).to_s
+      #   #=&gt; &quot;&#190; cup   &quot;
+      #
+      #   &quot;&#190; cup&quot;.mb_chars.rjust(8, &quot;&#160;&quot;).to_s # Use non-breaking whitespace
+      #   #=&gt; &quot;&#190; cup&#160;&#160;&#160;&quot;
+      def ljust(integer, padstr=' ')
+        justify(integer, :left, padstr)
+      end
+
+      # Works just like &lt;tt&gt;String#center&lt;/tt&gt;, only integer specifies characters instead of bytes.
+      #
+      # Example:
+      #
+      #   &quot;&#190; cup&quot;.mb_chars.center(8).to_s
+      #   #=&gt; &quot; &#190; cup  &quot;
+      #
+      #   &quot;&#190; cup&quot;.mb_chars.center(8, &quot;&#160;&quot;).to_s # Use non-breaking whitespace
+      #   #=&gt; &quot;&#160;&#190; cup&#160;&#160;&quot;
+      def center(integer, padstr=' ')
+        justify(integer, :center, padstr)
       end
-    end
 
-    private
+      # Strips entire range of Unicode whitespace from the right of the string.
+      def rstrip
+        chars(@wrapped_string.gsub(UNICODE_TRAILERS_PAT, ''))
+      end
       
-      # +utf8_pragma+ checks if it can send this string to the handlers. It makes sure @string isn't nil and $KCODE is
-      # set to 'UTF8'.
-      def utf8_pragma?
-        !@string.nil? &amp;&amp; ($KCODE == 'UTF8')
+      # Strips entire range of Unicode whitespace from the left of the string.
+      def lstrip
+        chars(@wrapped_string.gsub(UNICODE_LEADERS_PAT, ''))
       end
-  end
-end
+      
+      # Strips entire range of Unicode whitespace from the right and left of the string.
+      def strip
+        rstrip.lstrip
+      end
+      
+      # Returns the number of codepoints in the string
+      def size
+        self.class.u_unpack(@wrapped_string).size
+      end
+      alias_method :length, :size
+      
+      # Reverses all characters in the string.
+      #
+      # Example:
+      #   'Caf&#233;'.mb_chars.reverse.to_s #=&gt; '&#233;faC'
+      def reverse
+        chars(self.class.u_unpack(@wrapped_string).reverse.pack('U*'))
+      end
+      
+      # Implements Unicode-aware slice with codepoints. Slicing on one point returns the codepoints for that
+      # character.
+      #
+      # Example:
+      #   '&#12371;&#12435;&#12395;&#12385;&#12399;'.mb_chars.slice(2..3).to_s #=&gt; &quot;&#12395;&#12385;&quot;
+      def slice(*args)
+        if args.size &gt; 2
+          raise ArgumentError, &quot;wrong number of arguments (#{args.size} for 1)&quot; # Do as if we were native
+        elsif (args.size == 2 &amp;&amp; !(args.first.is_a?(Numeric) || args.first.is_a?(Regexp)))
+          raise TypeError, &quot;cannot convert #{args.first.class} into Integer&quot; # Do as if we were native
+        elsif (args.size == 2 &amp;&amp; !args[1].is_a?(Numeric))
+          raise TypeError, &quot;cannot convert #{args[1].class} into Integer&quot; # Do as if we were native
+        elsif args[0].kind_of? Range
+          cps = self.class.u_unpack(@wrapped_string).slice(*args)
+          result = cps.nil? ? nil : cps.pack('U*')
+        elsif args[0].kind_of? Regexp
+          result = @wrapped_string.slice(*args)
+        elsif args.size == 1 &amp;&amp; args[0].kind_of?(Numeric)
+          character = self.class.u_unpack(@wrapped_string)[args[0]]
+          result = character.nil? ? nil : [character].pack('U')
+        else
+          result = self.class.u_unpack(@wrapped_string).slice(*args).pack('U*')
+        end
+        result.nil? ? nil : chars(result)
+      end
+      alias_method :[], :slice
+
+      # Convert characters in the string to uppercase.
+      #
+      # Example:
+      #   'Laurent, &#242;u sont les tests?'.mb_chars.upcase.to_s #=&gt; &quot;LAURENT, &#210;U SONT LES TESTS?&quot;
+      def upcase
+        apply_mapping :uppercase_mapping
+      end
+
+      # Convert characters in the string to lowercase.
+      #
+      # Example:
+      #   'V&#282;DA A V&#221;ZKUM'.mb_chars.downcase.to_s #=&gt; &quot;v&#283;da a v&#253;zkum&quot;
+      def downcase
+        apply_mapping :lowercase_mapping
+      end
+
+      # Converts the first character to uppercase and the remainder to lowercase.
+      #
+      # Example:
+      #  '&#252;ber'.mb_chars.capitalize.to_s #=&gt; &quot;&#220;ber&quot;
+      def capitalize
+        (slice(0) || chars('')).upcase + (slice(1..-1) || chars('')).downcase
+      end
+
+      # Returns the KC normalization of the string by default. NFKC is considered the best normalization form for
+      # passing strings to databases and validations.
+      #
+      # * &lt;tt&gt;str&lt;/tt&gt; - The string to perform normalization on.
+      # * &lt;tt&gt;form&lt;/tt&gt; - The form you want to normalize in. Should be one of the following:
+      #   &lt;tt&gt;:c&lt;/tt&gt;, &lt;tt&gt;:kc&lt;/tt&gt;, &lt;tt&gt;:d&lt;/tt&gt;, or &lt;tt&gt;:kd&lt;/tt&gt;. Default is
+      #   ActiveSupport::Multibyte.default_normalization_form
+      def normalize(form=ActiveSupport::Multibyte.default_normalization_form)
+        # See http://www.unicode.org/reports/tr15, Table 1
+        codepoints = self.class.u_unpack(@wrapped_string)
+        chars(case form
+          when :d
+            self.class.reorder_characters(self.class.decompose_codepoints(:canonical, codepoints))
+          when :c
+            self.class.compose_codepoints(self.class.reorder_characters(self.class.decompose_codepoints(:canonical, codepoints)))
+          when :kd
+            self.class.reorder_characters(self.class.decompose_codepoints(:compatability, codepoints))
+          when :kc
+            self.class.compose_codepoints(self.class.reorder_characters(self.class.decompose_codepoints(:compatability, codepoints)))
+          else
+            raise ArgumentError, &quot;#{form} is not a valid normalization variant&quot;, caller
+        end.pack('U*'))
+      end
+
+      # Performs canonical decomposition on all the characters.
+      #
+      # Example:
+      #   '&#233;'.length #=&gt; 2
+      #   '&#233;'.mb_chars.decompose.to_s.length #=&gt; 3
+      def decompose
+        chars(self.class.decompose_codepoints(:canonical, self.class.u_unpack(@wrapped_string)).pack('U*'))
+      end
+
+      # Performs composition on all the characters.
+      #
+      # Example:
+      #   '&#233;'.length #=&gt; 3
+      #   '&#233;'.mb_chars.compose.to_s.length #=&gt; 2
+      def compose
+        chars(self.class.compose_codepoints(self.class.u_unpack(@wrapped_string)).pack('U*'))
+      end
+
+      # Returns the number of grapheme clusters in the string.
+      #
+      # Example:
+      #   '&#2325;&#2381;&#2359;&#2367;'.mb_chars.length #=&gt; 4
+      #   '&#2325;&#2381;&#2359;&#2367;'.mb_chars.g_length #=&gt; 3
+      def g_length
+        self.class.g_unpack(@wrapped_string).length
+      end
+
+      # Replaces all ISO-8859-1 or CP1252 characters by their UTF-8 equivalent resulting in a valid UTF-8 string.
+      def tidy_bytes
+        chars(self.class.tidy_bytes(@wrapped_string))
+      end
+
+      %w(lstrip rstrip strip reverse upcase downcase slice tidy_bytes capitalize).each do |method|
+        define_method(&quot;#{method}!&quot;) do |*args|
+          unless args.nil?
+            @wrapped_string = send(method, *args).to_s
+          else
+            @wrapped_string = send(method).to_s
+          end
+          self
+        end
+      end
+
+      class &lt;&lt; self
+
+        # Unpack the string at codepoints boundaries. Raises an EncodingError when the encoding of the string isn't
+        # valid UTF-8.
+        #
+        # Example:
+        #   Chars.u_unpack('Caf&#233;') #=&gt; [67, 97, 102, 233]
+        def u_unpack(string)
+          begin
+            string.unpack 'U*'
+          rescue ArgumentError
+            raise EncodingError, 'malformed UTF-8 character'
+          end
+        end
+
+        # Detect whether the codepoint is in a certain character class. Returns +true+ when it's in the specified
+        # character class and +false+ otherwise. Valid character classes are: &lt;tt&gt;:cr&lt;/tt&gt;, &lt;tt&gt;:lf&lt;/tt&gt;, &lt;tt&gt;:l&lt;/tt&gt;,
+        # &lt;tt&gt;:v&lt;/tt&gt;, &lt;tt&gt;:lv&lt;/tt&gt;, &lt;tt&gt;:lvt&lt;/tt&gt; and &lt;tt&gt;:t&lt;/tt&gt;.
+        #
+        # Primarily used by the grapheme cluster support.
+        def in_char_class?(codepoint, classes)
+          classes.detect { |c| UCD.boundary[c] === codepoint } ? true : false
+        end
 
-# When we can load the utf8proc library, override normalization with the faster methods
-begin
-  require 'utf8proc_native'
-  require 'active_support/multibyte/handlers/utf8_handler_proc'
-  ActiveSupport::Multibyte::Chars.handler = ActiveSupport::Multibyte::Handlers::UTF8HandlerProc
-rescue LoadError
-  ActiveSupport::Multibyte::Chars.handler = ActiveSupport::Multibyte::Handlers::UTF8Handler
+        # Unpack the string at grapheme boundaries. Returns a list of character lists.
+        #
+        # Example:
+        #   Chars.g_unpack('&#2325;&#2381;&#2359;&#2367;') #=&gt; [[2325, 2381], [2359], [2367]]
+        #   Chars.g_unpack('Caf&#233;') #=&gt; [[67], [97], [102], [233]]
+        def g_unpack(string)
+          codepoints = u_unpack(string)
+          unpacked = []
+          pos = 0
+          marker = 0
+          eoc = codepoints.length
+          while(pos &lt; eoc)
+            pos += 1
+            previous = codepoints[pos-1]
+            current = codepoints[pos]
+            if (
+                # CR X LF
+                one = ( previous == UCD.boundary[:cr] and current == UCD.boundary[:lf] ) or
+                # L X (L|V|LV|LVT)
+                two = ( UCD.boundary[:l] === previous and in_char_class?(current, [:l,:v,:lv,:lvt]) ) or
+                # (LV|V) X (V|T)
+                three = ( in_char_class?(previous, [:lv,:v]) and in_char_class?(current, [:v,:t]) ) or
+                # (LVT|T) X (T)
+                four = ( in_char_class?(previous, [:lvt,:t]) and UCD.boundary[:t] === current ) or
+                # X Extend
+                five = (UCD.boundary[:extend] === current)
+              )
+            else
+              unpacked &lt;&lt; codepoints[marker..pos-1]
+              marker = pos
+            end
+          end 
+          unpacked
+        end
+
+        # Reverse operation of g_unpack.
+        #
+        # Example:
+        #   Chars.g_pack(Chars.g_unpack('&#2325;&#2381;&#2359;&#2367;')) #=&gt; '&#2325;&#2381;&#2359;&#2367;'
+        def g_pack(unpacked)
+          (unpacked.flatten).pack('U*')
+        end
+
+        def padding(padsize, padstr=' ') #:nodoc:
+          if padsize != 0
+            new(padstr * ((padsize / u_unpack(padstr).size) + 1)).slice(0, padsize)
+          else
+            ''
+          end
+        end
+
+        # Re-order codepoints so the string becomes canonical.
+        def reorder_characters(codepoints)
+          length = codepoints.length- 1
+          pos = 0
+          while pos &lt; length do
+            cp1, cp2 = UCD.codepoints[codepoints[pos]], UCD.codepoints[codepoints[pos+1]]
+            if (cp1.combining_class &gt; cp2.combining_class) &amp;&amp; (cp2.combining_class &gt; 0)
+              codepoints[pos..pos+1] = cp2.code, cp1.code
+              pos += (pos &gt; 0 ? -1 : 1)
+            else
+              pos += 1
+            end
+          end
+          codepoints
+        end
+
+        # Decompose composed characters to the decomposed form.
+        def decompose_codepoints(type, codepoints)
+          codepoints.inject([]) do |decomposed, cp|
+            # if it's a hangul syllable starter character
+            if HANGUL_SBASE &lt;= cp and cp &lt; HANGUL_SLAST
+              sindex = cp - HANGUL_SBASE
+              ncp = [] # new codepoints
+              ncp &lt;&lt; HANGUL_LBASE + sindex / HANGUL_NCOUNT
+              ncp &lt;&lt; HANGUL_VBASE + (sindex % HANGUL_NCOUNT) / HANGUL_TCOUNT
+              tindex = sindex % HANGUL_TCOUNT
+              ncp &lt;&lt; (HANGUL_TBASE + tindex) unless tindex == 0
+              decomposed.concat ncp
+            # if the codepoint is decomposable in with the current decomposition type
+            elsif (ncp = UCD.codepoints[cp].decomp_mapping) and (!UCD.codepoints[cp].decomp_type || type == :compatability)
+              decomposed.concat decompose_codepoints(type, ncp.dup)
+            else
+              decomposed &lt;&lt; cp
+            end
+          end
+        end
+
+        # Compose decomposed characters to the composed form.
+        def compose_codepoints(codepoints)
+          pos = 0
+          eoa = codepoints.length - 1
+          starter_pos = 0
+          starter_char = codepoints[0]
+          previous_combining_class = -1
+          while pos &lt; eoa
+            pos += 1
+            lindex = starter_char - HANGUL_LBASE
+            # -- Hangul
+            if 0 &lt;= lindex and lindex &lt; HANGUL_LCOUNT
+              vindex = codepoints[starter_pos+1] - HANGUL_VBASE rescue vindex = -1
+              if 0 &lt;= vindex and vindex &lt; HANGUL_VCOUNT
+                tindex = codepoints[starter_pos+2] - HANGUL_TBASE rescue tindex = -1
+                if 0 &lt;= tindex and tindex &lt; HANGUL_TCOUNT
+                  j = starter_pos + 2
+                  eoa -= 2
+                else
+                  tindex = 0
+                  j = starter_pos + 1
+                  eoa -= 1
+                end
+                codepoints[starter_pos..j] = (lindex * HANGUL_VCOUNT + vindex) * HANGUL_TCOUNT + tindex + HANGUL_SBASE
+              end
+              starter_pos += 1
+              starter_char = codepoints[starter_pos]
+            # -- Other characters
+            else
+              current_char = codepoints[pos]
+              current = UCD.codepoints[current_char]
+              if current.combining_class &gt; previous_combining_class
+                if ref = UCD.composition_map[starter_char]
+                  composition = ref[current_char]
+                else
+                  composition = nil
+                end
+                unless composition.nil?
+                  codepoints[starter_pos] = composition
+                  starter_char = composition
+                  codepoints.delete_at pos
+                  eoa -= 1
+                  pos -= 1
+                  previous_combining_class = -1
+                else
+                  previous_combining_class = current.combining_class
+                end
+              else
+                previous_combining_class = current.combining_class
+              end
+              if current.combining_class == 0
+                starter_pos = pos
+                starter_char = codepoints[pos]
+              end
+            end
+          end
+          codepoints
+        end
+
+        # Replaces all ISO-8859-1 or CP1252 characters by their UTF-8 equivalent resulting in a valid UTF-8 string.
+        def tidy_bytes(string)
+          string.split(//u).map do |c|
+            if !UTF8_PAT.match(c)
+              n = c.unpack('C')[0]
+              n &lt; 128 ? n.chr :
+              n &lt; 160 ? [UCD.cp1252[n] || n].pack('U') :
+              n &lt; 192 ? &quot;\xC2&quot; + n.chr : &quot;\xC3&quot; + (n-64).chr
+            else
+              c
+            end
+          end.join
+        end
+      end
+
+      protected
+
+        def translate_offset(byte_offset) #:nodoc:
+          return nil if byte_offset.nil?
+          return 0   if @wrapped_string == ''
+          chunk = @wrapped_string[0..byte_offset]
+          begin
+            begin
+              chunk.unpack('U*').length - 1
+            rescue ArgumentError =&gt; e
+              chunk = @wrapped_string[0..(byte_offset+=1)]
+              # Stop retrying at the end of the string
+              raise e unless byte_offset &lt; chunk.length 
+              # We damaged a character, retry
+              retry
+            end
+          # Catch the ArgumentError so we can throw our own
+          rescue ArgumentError 
+            raise EncodingError, 'malformed UTF-8 character'
+          end
+        end
+
+        def justify(integer, way, padstr=' ') #:nodoc:
+          raise ArgumentError, &quot;zero width padding&quot; if padstr.length == 0
+          padsize = integer - size
+          padsize = padsize &gt; 0 ? padsize : 0
+          case way
+          when :right
+            result = @wrapped_string.dup.insert(0, self.class.padding(padsize, padstr))
+          when :left
+            result = @wrapped_string.dup.insert(-1, self.class.padding(padsize, padstr))
+          when :center
+            lpad = self.class.padding((padsize / 2.0).floor, padstr)
+            rpad = self.class.padding((padsize / 2.0).ceil, padstr)
+            result = @wrapped_string.dup.insert(0, lpad).insert(-1, rpad)
+          end
+          chars(result)
+        end
+
+        def apply_mapping(mapping) #:nodoc:
+          chars(self.class.u_unpack(@wrapped_string).map do |codepoint|
+            cp = UCD.codepoints[codepoint]
+            if cp and (ncp = cp.send(mapping)) and ncp &gt; 0
+              ncp
+            else
+              codepoint
+            end
+          end.pack('U*'))
+        end
+
+        def chars(string) #:nodoc:
+          self.class.new(string)
+        end
+    end
+  end
 end</diff>
      <filename>vendor/activesupport/lib/active_support/multibyte/chars.rb</filename>
    </modified>
    <modified>
      <diff>@@ -10,16 +10,8 @@ module ActiveSupport
 
     private
       def method_missing(method, *arguments, &amp;block)
-        merge_argument_options! arguments
-        @context.send!(method, *arguments, &amp;block)
-      end
-
-      def merge_argument_options!(arguments)
-        arguments &lt;&lt; if arguments.last.respond_to? :to_hash
-          @options.merge(arguments.pop)
-        else
-          @options.dup
-        end
+        arguments &lt;&lt; (arguments.last.respond_to?(:to_hash) ? @options.deep_merge(arguments.pop) : @options.dup)
+        @context.__send__(method, *arguments, &amp;block)
       end
   end
 end</diff>
      <filename>vendor/activesupport/lib/active_support/option_merger.rb</filename>
    </modified>
    <modified>
      <diff>@@ -12,6 +12,7 @@ module ActiveSupport
         else
           self &lt;&lt; [key, value]
         end
+        value
       end
 
       def [](key)
@@ -38,6 +39,20 @@ module ActiveSupport
           each { |array| hash[array[0]] = array[1] }
         end
       end
+
+      def has_key?(k)
+        !assoc(k).nil?
+      end
+
+      alias_method :key?, :has_key?
+      alias_method :include?, :has_key?
+      alias_method :member?, :has_key?
+
+      def has_value?(v)
+        any? { |key, value| value == v }
+      end
+
+      alias_method :value?, :has_value?
     end
   end
 end</diff>
      <filename>vendor/activesupport/lib/active_support/ordered_hash.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,7 +1,17 @@
 module ActiveSupport
+  # Wrapping a string in this class gives you a prettier way to test
+  # for equality. The value returned by &lt;tt&gt;Rails.env&lt;/tt&gt; is wrapped
+  # in a StringInquirer object so instead of calling this:
+  #
+  #   Rails.env == &quot;production&quot;
+  #
+  # you can call this:
+  #
+  #   Rails.env.production?
+  #
   class StringInquirer &lt; String
     def method_missing(method_name, *arguments)
-      if method_name.to_s.ends_with?(&quot;?&quot;)
+      if method_name.to_s[-1,1] == &quot;?&quot;
         self == method_name.to_s[0..-2]
       else
         super</diff>
      <filename>vendor/activesupport/lib/active_support/string_inquirer.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,13 +1,24 @@
 require 'test/unit/testcase'
-require 'active_support/testing/setup_and_teardown'
 require 'active_support/testing/default'
+require 'active_support/testing/core_ext/test'
 
-# TODO: move to core_ext
-class Test::Unit::TestCase #:nodoc:
-  include ActiveSupport::Testing::SetupAndTeardown
-end
 
 module ActiveSupport
   class TestCase &lt; Test::Unit::TestCase
+    # test &quot;verify something&quot; do
+    #   ...
+    # end
+    def self.test(name, &amp;block)
+      test_name = &quot;test_#{name.gsub(/\s+/,'_')}&quot;.to_sym
+      defined = instance_method(test_name) rescue false
+      raise &quot;#{test_name} is already defined in #{self}&quot; if defined
+      if block_given?
+        define_method(test_name, &amp;block)
+      else
+        define_method(test_name) do
+          flunk &quot;No implementation provided for #{name}&quot;
+        end
+      end
+    end
   end
 end</diff>
      <filename>vendor/activesupport/lib/active_support/test_case.rb</filename>
    </modified>
    <modified>
      <diff>@@ -10,19 +10,46 @@ module ActiveSupport
         end
 
       def self.included(base)
-        base.send :include, ActiveSupport::Callbacks
-        base.define_callbacks :setup, :teardown
+        base.class_eval do
+          include ActiveSupport::Callbacks
+          define_callbacks :setup, :teardown
 
+          if defined?(::Mini)
+            undef_method :run
+            alias_method :run, :run_with_callbacks_and_miniunit
+          else
+            begin
+              require 'mocha'
+              undef_method :run
+              alias_method :run, :run_with_callbacks_and_mocha
+            rescue LoadError
+              undef_method :run
+              alias_method :run, :run_with_callbacks_and_testunit
+            end
+          end
+        end
+      end
+
+      def run_with_callbacks_and_miniunit(runner)
+        result = '.'
         begin
-          require 'mocha'
-          base.alias_method_chain :run, :callbacks_and_mocha
-        rescue LoadError
-          base.alias_method_chain :run, :callbacks
+          run_callbacks :setup
+          result = super
+        rescue Exception =&gt; e
+          result = runner.puke(self.class, self.name, e)
+        ensure
+          begin
+            teardown
+            run_callbacks :teardown, :enumerator =&gt; :reverse_each
+          rescue Exception =&gt; e
+            result = runner.puke(self.class, self.name, e)
+          end
         end
+        result
       end
 
       # This redefinition is unfortunate but test/unit shows us no alternative.
-      def run_with_callbacks(result) #:nodoc:
+      def run_with_callbacks_and_testunit(result) #:nodoc:
         return if @method_name.to_s == &quot;default_test&quot;
 
         yield(Test::Unit::TestCase::STARTED, name)</diff>
      <filename>vendor/activesupport/lib/active_support/testing/setup_and_teardown.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,6 @@
 require 'tzinfo'
 module ActiveSupport
-  # A Time-like class that can represent a time in any time zone. Necessary because standard Ruby Time instances are 
+  # A Time-like class that can represent a time in any time zone. Necessary because standard Ruby Time instances are
   # limited to UTC and the system's &lt;tt&gt;ENV['TZ']&lt;/tt&gt; zone.
   #
   # You shouldn't ever need to create a TimeWithZone instance directly via &lt;tt&gt;new&lt;/tt&gt; -- instead, Rails provides the methods
@@ -32,12 +32,12 @@ module ActiveSupport
   class TimeWithZone
     include Comparable
     attr_reader :time_zone
-  
+
     def initialize(utc_time, time_zone, local_time = nil, period = nil)
       @utc, @time_zone, @time = utc_time, time_zone, local_time
       @period = @utc ? period : get_period_and_ensure_valid_local_time
     end
-  
+
     # Returns a Time or DateTime instance that represents the time in +time_zone+.
     def time
       @time ||= period.to_local(@utc)
@@ -51,7 +51,7 @@ module ActiveSupport
     alias_method :getgm, :utc
     alias_method :getutc, :utc
     alias_method :gmtime, :utc
-  
+
     # Returns the underlying TZInfo::TimezonePeriod.
     def period
       @period ||= time_zone.period_for_utc(@utc)
@@ -62,38 +62,38 @@ module ActiveSupport
       return self if time_zone == new_zone
       utc.in_time_zone(new_zone)
     end
-  
+
     # Returns a &lt;tt&gt;Time.local()&lt;/tt&gt; instance of the simultaneous time in your system's &lt;tt&gt;ENV['TZ']&lt;/tt&gt; zone
     def localtime
       utc.getlocal
     end
     alias_method :getlocal, :localtime
-  
+
     def dst?
       period.dst?
     end
     alias_method :isdst, :dst?
-  
+
     def utc?
       time_zone.name == 'UTC'
     end
     alias_method :gmt?, :utc?
-  
+
     def utc_offset
       period.utc_total_offset
     end
     alias_method :gmt_offset, :utc_offset
     alias_method :gmtoff, :utc_offset
-  
+
     def formatted_offset(colon = true, alternate_utc_string = nil)
       utc? &amp;&amp; alternate_utc_string || utc_offset.to_utc_offset_s(colon)
     end
-  
+
     # Time uses +zone+ to display the time zone abbreviation, so we're duck-typing it.
     def zone
       period.zone_identifier.to_s
     end
-  
+
     def inspect
       &quot;#{time.strftime('%a, %d %b %Y %H:%M:%S')} #{zone} #{formatted_offset}&quot;
     end
@@ -102,7 +102,19 @@ module ActiveSupport
       &quot;#{time.strftime(&quot;%Y-%m-%dT%H:%M:%S&quot;)}#{formatted_offset(true, 'Z')}&quot;
     end
     alias_method :iso8601, :xmlschema
-  
+
+    # Returns a JSON string representing the TimeWithZone. If ActiveSupport.use_standard_json_time_format is set to
+    # true, the ISO 8601 format is used.
+    #
+    # ==== Examples:
+    #
+    #   # With ActiveSupport.use_standard_json_time_format = true
+    #   Time.utc(2005,2,1,15,15,10).in_time_zone.to_json
+    #   # =&gt; &quot;2005-02-01T15:15:10Z&quot;
+    #
+    #   # With ActiveSupport.use_standard_json_time_format = false
+    #   Time.utc(2005,2,1,15,15,10).in_time_zone.to_json
+    #   # =&gt; &quot;2005/02/01 15:15:10 +0000&quot;
     def to_json(options = nil)
       if ActiveSupport.use_standard_json_time_format
         xmlschema.inspect
@@ -110,7 +122,7 @@ module ActiveSupport
         %(&quot;#{time.strftime(&quot;%Y/%m/%d %H:%M:%S&quot;)} #{formatted_offset(false)}&quot;)
       end
     end
-    
+
     def to_yaml(options = {})
       if options.kind_of?(YAML::Emitter)
         utc.to_yaml(options)
@@ -118,19 +130,19 @@ module ActiveSupport
         time.to_yaml(options).gsub('Z', formatted_offset(true, 'Z'))
       end
     end
-    
+
     def httpdate
       utc.httpdate
     end
-  
+
     def rfc2822
       to_s(:rfc822)
     end
     alias_method :rfc822, :rfc2822
-  
+
     # &lt;tt&gt;:db&lt;/tt&gt; format outputs time in UTC; all others output time in local.
     # Uses TimeWithZone's +strftime+, so &lt;tt&gt;%Z&lt;/tt&gt; and &lt;tt&gt;%z&lt;/tt&gt; work correctly.
-    def to_s(format = :default) 
+    def to_s(format = :default)
       return utc.to_s(format) if format == :db
       if formatter = ::Time::DATE_FORMATS[format]
         formatter.respond_to?(:call) ? formatter.call(self).to_s : strftime(formatter)
@@ -138,27 +150,39 @@ module ActiveSupport
         &quot;#{time.strftime(&quot;%Y-%m-%d %H:%M:%S&quot;)} #{formatted_offset(false, 'UTC')}&quot; # mimicking Ruby 1.9 Time#to_s format
       end
     end
-    
+
     # Replaces &lt;tt&gt;%Z&lt;/tt&gt; and &lt;tt&gt;%z&lt;/tt&gt; directives with +zone+ and +formatted_offset+, respectively, before passing to
     # Time#strftime, so that zone information is correct
     def strftime(format)
       format = format.gsub('%Z', zone).gsub('%z', formatted_offset(false))
       time.strftime(format)
     end
-  
+
     # Use the time in UTC for comparisons.
     def &lt;=&gt;(other)
       utc &lt;=&gt; other
     end
-    
+
     def between?(min, max)
       utc.between?(min, max)
     end
-    
+
+    def past?
+      utc.past?
+    end
+
+    def today?
+      time.today?
+    end
+
+    def future?
+      utc.future?
+    end
+
     def eql?(other)
       utc == other
     end
-    
+
     def +(other)
       # If we're adding a Duration of variable length (i.e., years, months, days), move forward from #time,
       # otherwise move forward from #utc, for accuracy when moving across DST boundaries
@@ -182,7 +206,7 @@ module ActiveSupport
         result.in_time_zone(time_zone)
       end
     end
-    
+
     def since(other)
       # If we're adding a Duration of variable length (i.e., years, months, days), move forward from #time,
       # otherwise move forward from #utc, for accuracy when moving across DST boundaries
@@ -192,7 +216,7 @@ module ActiveSupport
         utc.since(other).in_time_zone(time_zone)
       end
     end
-    
+
     def ago(other)
       since(-other)
     end
@@ -206,64 +230,64 @@ module ActiveSupport
         utc.advance(options).in_time_zone(time_zone)
       end
     end
-    
-    %w(year mon month day mday hour min sec).each do |method_name|
+
+    %w(year mon month day mday wday yday hour min sec to_date).each do |method_name|
       class_eval &lt;&lt;-EOV
         def #{method_name}
           time.#{method_name}
         end
       EOV
     end
-    
+
     def usec
       time.respond_to?(:usec) ? time.usec : 0
     end
-    
+
     def to_a
       [time.sec, time.min, time.hour, time.day, time.mon, time.year, time.wday, time.yday, dst?, zone]
     end
-    
+
     def to_f
       utc.to_f
-    end    
-    
+    end
+
     def to_i
       utc.to_i
     end
     alias_method :hash, :to_i
     alias_method :tv_sec, :to_i
-  
+
     # A TimeWithZone acts like a Time, so just return +self+.
     def to_time
       self
     end
-    
+
     def to_datetime
       utc.to_datetime.new_offset(Rational(utc_offset, 86_400))
     end
-    
+
     # So that +self+ &lt;tt&gt;acts_like?(:time)&lt;/tt&gt;.
     def acts_like_time?
       true
     end
-  
+
     # Say we're a Time to thwart type checking.
     def is_a?(klass)
       klass == ::Time || super
     end
     alias_method :kind_of?, :is_a?
-  
-    # Neuter freeze because freezing can cause problems with lazy loading of attributes.
+
     def freeze
-      self
+      period; utc; time # preload instance variables before freezing
+      super
     end
 
     def marshal_dump
       [utc, time_zone.name, time]
     end
-    
+
     def marshal_load(variables)
-      initialize(variables[0].utc, ::Time.send!(:get_zone, variables[1]), variables[2].utc)
+      initialize(variables[0].utc, ::Time.__send__(:get_zone, variables[1]), variables[2].utc)
     end
 
     # Ensure proxy class responds to all methods that underlying time instance responds to.
@@ -278,10 +302,10 @@ module ActiveSupport
       result = time.__send__(sym, *args, &amp;block)
       result.acts_like?(:time) ? self.class.new(nil, time_zone, result) : result
     end
-    
-    private      
+
+    private
       def get_period_and_ensure_valid_local_time
-        # we don't want a Time.local instance enforcing its own DST rules as well, 
+        # we don't want a Time.local instance enforcing its own DST rules as well,
         # so transfer time values to a utc constructor if necessary
         @time = transfer_time_values_to_utc_constructor(@time) unless @time.utc?
         begin
@@ -292,11 +316,11 @@ module ActiveSupport
           retry
         end
       end
-      
+
       def transfer_time_values_to_utc_constructor(time)
         ::Time.utc_time(time.year, time.month, time.day, time.hour, time.min, time.sec, time.respond_to?(:usec) ? time.usec : 0)
       end
-      
+
       def duration_of_variable_length?(obj)
         ActiveSupport::Duration === obj &amp;&amp; obj.parts.flatten.detect {|p| [:years, :months, :days].include? p }
       end</diff>
      <filename>vendor/activesupport/lib/active_support/time_with_zone.rb</filename>
    </modified>
    <modified>
      <diff>@@ -51,7 +51,7 @@ module ActiveSupport
         &quot;La Paz&quot;                       =&gt; &quot;America/La_Paz&quot;,
         &quot;Santiago&quot;                     =&gt; &quot;America/Santiago&quot;,
         &quot;Newfoundland&quot;                 =&gt; &quot;America/St_Johns&quot;,
-        &quot;Brasilia&quot;                     =&gt; &quot;America/Argentina/Buenos_Aires&quot;,
+        &quot;Brasilia&quot;                     =&gt; &quot;America/Sao_Paulo&quot;,
         &quot;Buenos Aires&quot;                 =&gt; &quot;America/Argentina/Buenos_Aires&quot;,
         &quot;Georgetown&quot;                   =&gt; &quot;America/Argentina/San_Juan&quot;,
         &quot;Greenland&quot;                    =&gt; &quot;America/Godthab&quot;,
@@ -124,7 +124,7 @@ module ActiveSupport
         &quot;Kathmandu&quot;                    =&gt; &quot;Asia/Katmandu&quot;,
         &quot;Astana&quot;                       =&gt; &quot;Asia/Dhaka&quot;,
         &quot;Dhaka&quot;                        =&gt; &quot;Asia/Dhaka&quot;,
-        &quot;Sri Jayawardenepura&quot;          =&gt; &quot;Asia/Dhaka&quot;,
+        &quot;Sri Jayawardenepura&quot;          =&gt; &quot;Asia/Colombo&quot;,
         &quot;Almaty&quot;                       =&gt; &quot;Asia/Almaty&quot;,
         &quot;Novosibirsk&quot;                  =&gt; &quot;Asia/Novosibirsk&quot;,
         &quot;Rangoon&quot;                      =&gt; &quot;Asia/Rangoon&quot;,
@@ -201,6 +201,12 @@ module ActiveSupport
       result
     end
 
+    # Compare #name and TZInfo identifier to a supplied regexp, returning true
+    # if a match is found.
+    def =~(re)
+      return true if name =~ re || MAPPING[name] =~ re
+    end
+
     # Returns a textual representation of this time zone.
     def to_s
       &quot;(GMT#{formatted_offset}) #{name}&quot;
@@ -298,7 +304,8 @@ module ActiveSupport
                  &quot;Mexico City&quot;, &quot;Monterrey&quot;, &quot;Central America&quot; ],
        [-18_000, &quot;Eastern Time (US &amp; Canada)&quot;, &quot;Indiana (East)&quot;, &quot;Bogota&quot;,
                  &quot;Lima&quot;, &quot;Quito&quot; ],
-       [-14_400, &quot;Atlantic Time (Canada)&quot;, &quot;Caracas&quot;, &quot;La Paz&quot;, &quot;Santiago&quot; ],
+       [-16_200, &quot;Caracas&quot; ],
+       [-14_400, &quot;Atlantic Time (Canada)&quot;, &quot;La Paz&quot;, &quot;Santiago&quot; ],
        [-12_600, &quot;Newfoundland&quot; ],
        [-10_800, &quot;Brasilia&quot;, &quot;Buenos Aires&quot;, &quot;Georgetown&quot;, &quot;Greenland&quot; ],
        [ -7_200, &quot;Mid-Atlantic&quot; ],
@@ -319,9 +326,9 @@ module ActiveSupport
        [ 14_400, &quot;Abu Dhabi&quot;, &quot;Muscat&quot;, &quot;Baku&quot;, &quot;Tbilisi&quot;, &quot;Yerevan&quot; ],
        [ 16_200, &quot;Kabul&quot; ],
        [ 18_000, &quot;Ekaterinburg&quot;, &quot;Islamabad&quot;, &quot;Karachi&quot;, &quot;Tashkent&quot; ],
-       [ 19_800, &quot;Chennai&quot;, &quot;Kolkata&quot;, &quot;Mumbai&quot;, &quot;New Delhi&quot; ],
+       [ 19_800, &quot;Chennai&quot;, &quot;Kolkata&quot;, &quot;Mumbai&quot;, &quot;New Delhi&quot;, &quot;Sri Jayawardenepura&quot; ],
        [ 20_700, &quot;Kathmandu&quot; ],
-       [ 21_600, &quot;Astana&quot;, &quot;Dhaka&quot;, &quot;Sri Jayawardenepura&quot;, &quot;Almaty&quot;,
+       [ 21_600, &quot;Astana&quot;, &quot;Dhaka&quot;, &quot;Almaty&quot;,
                  &quot;Novosibirsk&quot; ],
        [ 23_400, &quot;Rangoon&quot; ],
        [ 25_200, &quot;Bangkok&quot;, &quot;Hanoi&quot;, &quot;Jakarta&quot;, &quot;Krasnoyarsk&quot; ],</diff>
      <filename>vendor/activesupport/lib/active_support/values/time_zone.rb</filename>
    </modified>
    <modified>
      <diff></diff>
      <filename>vendor/activesupport/lib/active_support/values/unicode_tables.dat</filename>
    </modified>
    <modified>
      <diff>@@ -14,13 +14,21 @@ rescue Gem::LoadError
 end
 
 begin
-  gem 'memcache-client', '~&gt; 1.5.0'
+  gem 'memcache-client', '~&gt; 1.5.1'
 rescue Gem::LoadError
-  $:.unshift &quot;#{File.dirname(__FILE__)}/vendor/memcache-client-1.5.0&quot;
+  $:.unshift &quot;#{File.dirname(__FILE__)}/vendor/memcache-client-1.5.1&quot;
 end
 
 begin
-  gem 'tzinfo', '~&gt; 0.3.9'
+  gem 'tzinfo', '~&gt; 0.3.12'
 rescue Gem::LoadError
-  $:.unshift &quot;#{File.dirname(__FILE__)}/vendor/tzinfo-0.3.9&quot;
-end
\ No newline at end of file
+  $:.unshift &quot;#{File.dirname(__FILE__)}/vendor/tzinfo-0.3.12&quot;
+end
+
+# TODO I18n gem has not been released yet
+# begin
+#   gem 'i18n', '~&gt; 0.0.1'
+# rescue Gem::LoadError
+  $:.unshift &quot;#{File.dirname(__FILE__)}/vendor/i18n-0.0.1&quot;
+  require 'i18n'
+# end
\ No newline at end of file</diff>
      <filename>vendor/activesupport/lib/active_support/vendor.rb</filename>
    </modified>
    <modified>
      <diff>@@ -20,7 +20,7 @@ module Builder
   # markup.
   #
   # Usage:
-  #   xe = Builder::XmlEvents.new(hander)
+  #   xe = Builder::XmlEvents.new(handler)
   #   xe.title(&quot;HI&quot;)    # Sends start_tag/end_tag/text messages to the handler.
   #
   # Indentation may also be selected by providing value for the</diff>
      <filename>vendor/activesupport/lib/active_support/vendor/builder-2.1.2/builder/xmlevents.rb</filename>
    </modified>
    <modified>
      <diff>@@ -121,7 +121,7 @@ class XmlSimple
   # Create a &quot;global&quot; cache.
   @@cache = Cache.new
 
-  # Creates and intializes a new XmlSimple object.
+  # Creates and initializes a new XmlSimple object.
   # 
   # defaults::
   #   Default values for options.
@@ -497,7 +497,7 @@ class XmlSimple
       }
     end
     
-    # Fold Hases containing a single anonymous Array up into just the Array.
+    # Fold Hashes containing a single anonymous Array up into just the Array.
     if count == 1 
       anonymoustag = @options['anonymoustag']
       if result.has_key?(anonymoustag) &amp;&amp; result[anonymoustag].instance_of?(Array)
@@ -907,7 +907,7 @@ class XmlSimple
   # Thanks to Norbert Gawor for a bugfix.
   #
   # value::
-  #   Value to be checked for emptyness.
+  #   Value to be checked for emptiness.
   def empty(value)
     case value
       when Hash</diff>
      <filename>vendor/activesupport/lib/active_support/vendor/xml-simple-1.0.11/xmlsimple.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,8 +1,8 @@
 module ActiveSupport
   module VERSION #:nodoc:
     MAJOR = 2
-    MINOR = 1
-    TINY  = 1
+    MINOR = 2
+    TINY  = 2
 
     STRING = [MAJOR, MINOR, TINY].join('.')
   end</diff>
      <filename>vendor/activesupport/lib/active_support/version.rb</filename>
    </modified>
  </modified>
  <removed type="array">
    <removed>
      <filename>vendor/activerecord/lib/active_record/vendor/mysql.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activerecord/test/cases/adapter_test_sqlserver.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activerecord/test/cases/table_name_test_sqlserver.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activerecord/test/cases/threaded_connections_test.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activerecord/test/debug.log</filename>
    </removed>
    <removed>
      <filename>vendor/activerecord/test/schema/sqlserver_specific_schema.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/clean_logger.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/core_ext/string/unicode.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/core_ext/test.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/core_ext/test/unit/assertions.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/multibyte/generators/generate_tables.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/multibyte/handlers/passthru_handler.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/multibyte/handlers/utf8_handler.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/multibyte/handlers/utf8_handler_proc.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/memcache-client-1.5.0/memcache.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/data_timezone.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/data_timezone_info.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Africa/Algiers.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Africa/Cairo.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Africa/Casablanca.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Africa/Harare.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Africa/Johannesburg.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Africa/Monrovia.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Africa/Nairobi.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/America/Argentina/Buenos_Aires.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/America/Argentina/San_Juan.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/America/Bogota.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/America/Caracas.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/America/Chicago.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/America/Chihuahua.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/America/Denver.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/America/Godthab.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/America/Guatemala.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/America/Halifax.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/America/Indiana/Indianapolis.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/America/Juneau.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/America/La_Paz.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/America/Lima.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/America/Los_Angeles.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/America/Mazatlan.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/America/Mexico_City.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/America/Monterrey.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/America/New_York.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/America/Phoenix.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/America/Regina.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/America/Santiago.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/America/St_Johns.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/America/Tijuana.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Asia/Almaty.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Asia/Baghdad.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Asia/Baku.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Asia/Bangkok.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Asia/Chongqing.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Asia/Dhaka.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Asia/Hong_Kong.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Asia/Irkutsk.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Asia/Jakarta.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Asia/Jerusalem.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Asia/Kabul.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Asia/Kamchatka.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Asia/Karachi.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Asia/Katmandu.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Asia/Kolkata.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Asia/Krasnoyarsk.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Asia/Kuala_Lumpur.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Asia/Kuwait.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Asia/Magadan.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Asia/Muscat.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Asia/Novosibirsk.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Asia/Rangoon.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Asia/Riyadh.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Asia/Seoul.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Asia/Shanghai.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Asia/Singapore.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Asia/Taipei.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Asia/Tashkent.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Asia/Tbilisi.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Asia/Tehran.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Asia/Tokyo.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Asia/Ulaanbaatar.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Asia/Urumqi.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Asia/Vladivostok.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Asia/Yakutsk.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Asia/Yekaterinburg.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Asia/Yerevan.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Atlantic/Azores.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Atlantic/Cape_Verde.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Atlantic/South_Georgia.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Australia/Adelaide.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Australia/Brisbane.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Australia/Darwin.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Australia/Hobart.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Australia/Melbourne.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Australia/Perth.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Australia/Sydney.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Etc/UTC.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Europe/Amsterdam.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Europe/Athens.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Europe/Belgrade.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Europe/Berlin.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Europe/Bratislava.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Europe/Brussels.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Europe/Bucharest.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Europe/Budapest.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Europe/Copenhagen.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Europe/Dublin.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Europe/Helsinki.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Europe/Istanbul.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Europe/Kiev.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Europe/Lisbon.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Europe/Ljubljana.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Europe/London.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Europe/Madrid.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Europe/Minsk.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Europe/Moscow.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Europe/Paris.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Europe/Prague.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Europe/Riga.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Europe/Rome.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Europe/Sarajevo.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Europe/Skopje.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Europe/Sofia.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Europe/Stockholm.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Europe/Tallinn.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Europe/Vienna.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Europe/Vilnius.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Europe/Warsaw.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Europe/Zagreb.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Pacific/Auckland.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Pacific/Fiji.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Pacific/Guam.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Pacific/Honolulu.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Pacific/Majuro.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Pacific/Midway.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Pacific/Noumea.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Pacific/Pago_Pago.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Pacific/Port_Moresby.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Pacific/Tongatapu.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/info_timezone.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/linked_timezone.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/linked_timezone_info.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/offset_rationals.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/time_or_datetime.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/timezone.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/timezone_definition.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/timezone_info.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/timezone_offset_info.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/timezone_period.rb</filename>
    </removed>
    <removed>
      <filename>vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/timezone_transition_info.rb</filename>
    </removed>
  </removed>
  <parents type="array">
    <parent>
      <id>d87d99e0a8f313ec76f9d00a689b2905c69562a9</id>
    </parent>
  </parents>
  <author>
    <name>Aaron Bedra</name>
    <email>aaron@thinkrelevance.com</email>
  </author>
  <url>http://github.com/relevance/castronaut/commit/9c6a164c86ca4bfd97367523620ee94b50038dd7</url>
  <id>9c6a164c86ca4bfd97367523620ee94b50038dd7</id>
  <committed-date>2009-01-24T10:54:08-08:00</committed-date>
  <authored-date>2009-01-24T10:54:08-08:00</authored-date>
  <message>upgrading activerecord and activesupport</message>
  <tree>28f2a9d74a3810e884b145f7c6bfd76d815e20de</tree>
  <committer>
    <name>Aaron Bedra</name>
    <email>aaron@thinkrelevance.com</email>
  </committer>
</commit>
