aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/CHANGELOG.md1739
-rw-r--r--activesupport/lib/active_support.rb3
-rw-r--r--activesupport/lib/active_support/cache/file_store.rb7
-rw-r--r--activesupport/lib/active_support/cache/mem_cache_store.rb53
-rw-r--r--activesupport/lib/active_support/callbacks.rb5
-rw-r--r--activesupport/lib/active_support/concurrency/latch.rb27
-rw-r--r--activesupport/lib/active_support/core_ext/date.rb5
-rw-r--r--activesupport/lib/active_support/core_ext/date/calculations.rb184
-rw-r--r--activesupport/lib/active_support/core_ext/date_and_time/calculations.rb213
-rw-r--r--activesupport/lib/active_support/core_ext/date_time.rb4
-rw-r--r--activesupport/lib/active_support/core_ext/date_time/calculations.rb9
-rw-r--r--activesupport/lib/active_support/core_ext/file/atomic.rb32
-rw-r--r--activesupport/lib/active_support/core_ext/object/to_param.rb7
-rw-r--r--activesupport/lib/active_support/core_ext/object/try.rb17
-rw-r--r--activesupport/lib/active_support/core_ext/string.rb1
-rw-r--r--activesupport/lib/active_support/core_ext/string/indent.rb43
-rw-r--r--activesupport/lib/active_support/core_ext/string/inflections.rb22
-rw-r--r--activesupport/lib/active_support/core_ext/string/output_safety.rb13
-rw-r--r--activesupport/lib/active_support/core_ext/time.rb5
-rw-r--r--activesupport/lib/active_support/core_ext/time/calculations.rb211
-rw-r--r--activesupport/lib/active_support/core_ext/time/zones.rb11
-rw-r--r--activesupport/lib/active_support/dependencies.rb53
-rw-r--r--activesupport/lib/active_support/dependencies/autoload.rb60
-rw-r--r--activesupport/lib/active_support/duration.rb2
-rw-r--r--activesupport/lib/active_support/hash_with_indifferent_access.rb121
-rw-r--r--activesupport/lib/active_support/inflections.rb2
-rw-r--r--activesupport/lib/active_support/inflector/inflections.rb23
-rw-r--r--activesupport/lib/active_support/inflector/methods.rb22
-rw-r--r--activesupport/lib/active_support/json/encoding.rb64
-rw-r--r--activesupport/lib/active_support/json/variable.rb17
-rw-r--r--activesupport/lib/active_support/locale/en.yml10
-rw-r--r--activesupport/lib/active_support/notifications/fanout.rb6
-rw-r--r--activesupport/lib/active_support/number_helper.rb161
-rw-r--r--activesupport/lib/active_support/rails.rb27
-rw-r--r--activesupport/lib/active_support/railtie.rb2
-rw-r--r--activesupport/lib/active_support/string_inquirer.rb18
-rw-r--r--activesupport/lib/active_support/test_case.rb29
-rw-r--r--activesupport/lib/active_support/testing/declarative.rb40
-rw-r--r--activesupport/lib/active_support/time_with_zone.rb3
-rw-r--r--activesupport/test/abstract_unit.rb10
-rw-r--r--activesupport/test/autoload_test.rb (renamed from activesupport/test/autoload.rb)12
-rw-r--r--activesupport/test/autoloading_fixtures/circular1.rb6
-rw-r--r--activesupport/test/autoloading_fixtures/circular2.rb4
-rw-r--r--activesupport/test/autoloading_fixtures/class_folder/class_folder_subclass.rb2
-rw-r--r--activesupport/test/caching_test.rb102
-rw-r--r--activesupport/test/core_ext/date_and_time_behavior.rb186
-rw-r--r--activesupport/test/core_ext/date_ext_test.rb173
-rw-r--r--activesupport/test/core_ext/date_time_ext_test.rb143
-rw-r--r--activesupport/test/core_ext/file_test.rb2
-rw-r--r--activesupport/test/core_ext/hash_ext_test.rb23
-rw-r--r--activesupport/test/core_ext/module/qualified_const_test.rb29
-rw-r--r--activesupport/test/core_ext/object_and_class_ext_test.rb30
-rw-r--r--activesupport/test/core_ext/string_ext_test.rb60
-rw-r--r--activesupport/test/core_ext/time_ext_test.rb182
-rw-r--r--activesupport/test/dependencies_test.rb8
-rw-r--r--activesupport/test/inflector_test.rb35
-rw-r--r--activesupport/test/json/encoding_test.rb7
-rw-r--r--activesupport/test/multibyte_chars_test.rb2
-rw-r--r--activesupport/test/notifications/evented_notification_test.rb20
-rw-r--r--activesupport/test/number_helper_i18n_test.rb42
-rw-r--r--activesupport/test/number_helper_test.rb7
-rw-r--r--activesupport/test/ordered_hash_test.rb6
-rw-r--r--activesupport/test/string_inquirer_test.rb14
-rw-r--r--activesupport/test/tagged_logging_test.rb5
-rw-r--r--activesupport/test/transliterate_test.rb3
65 files changed, 1478 insertions, 2906 deletions
diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md
index df144dd00b..761780fb8b 100644
--- a/activesupport/CHANGELOG.md
+++ b/activesupport/CHANGELOG.md
@@ -1,5 +1,46 @@
## Rails 4.0.0 (unreleased) ##
+* An optional block can be passed to `HashWithIndifferentAccess#update` and `#merge`.
+ The block will be invoked for each duplicated key, and used to resolve the conflict,
+ thus replicating the behaviour of the corresponding methods on the `Hash` class.
+
+ *Leo Cassarani*
+
+* Remove `j` alias for `ERB::Util#json_escape`.
+ The `j` alias is already used for `ActionView::Helpers::JavaScriptHelper#escape_javascript`
+ and both modules are included in the view context that would confuse the developers.
+
+ *Akira Matsuda*
+
+* Replace deprecated `memcache-client` gem with `dalli` in ActiveSupport::Cache::MemCacheStore
+
+ *Guillermo Iguaran*
+
+* Add default values to all `ActiveSupport::NumberHelper` methods, to avoid
+ errors with empty locales or missing values.
+
+ *Carlos Antonio da Silva*
+
+* ActiveSupport::JSON::Variable is deprecated. Define your own #as_json and
+ #encode_json methods for custom JSON string literals.
+
+ *Erich Menge*
+
+* Add String#indent. *fxn & Ace Suares*
+
+* Inflections can now be defined per locale. `singularize` and `pluralize`
+ accept locale as an extra argument.
+
+ *David Celis*
+
+* `Object#try` will now return nil instead of raise a NoMethodError if the
+ receiving object does not implement the method, but you can still get the
+ old behavior by using the new `Object#try!`.
+
+ *DHH*
+
+* `ERB::Util.html_escape` now escapes single quotes. *Santiago Pastorino*
+
* `Time#change` now works with time values with offsets other than UTC or the local time zone. *Andrew White*
* `ActiveSupport::Callbacks`: deprecate usage of filter object with `#before` and `#after` methods as `around` callback. *Bogdan Gusiev*
@@ -79,1700 +120,4 @@
* Remove deprecated ActiveSupport::JSON::Variable. *Erich Menge*
-
-## Rails 3.2.5 (Jun 1, 2012) ##
-
-* ActiveSupport::JSON::Variable is deprecated. Define your own #as_json and #encode_json methods
- for custom JSON string literals. *Erich Menge*
-
-
-## Rails 3.2.4 (May 31, 2012) ##
-
-* Added #beginning_of_hour and #end_of_hour to Time and DateTime core
- extensions. *Mark J. Titorenko*
-
-
-## Rails 3.2.3 (March 30, 2012) ##
-
-* No changes.
-
-
-## Rails 3.2.2 (March 1, 2012) ##
-
-* No changes.
-
-
-## Rails 3.2.1 (January 26, 2012) ##
-
-* Documentation fixes and improvements.
-
-* Update time zone offset information. *Ravil Bayramgalin*
-
-* The deprecated `ActiveSupport::Base64.decode64` calls `::Base64.decode64`
- now. *Jonathan Viney*
-
-* Fixes uninitialized constant `ActiveSupport::TaggedLogging::ERROR`. *kennyj*
-
-
-## Rails 3.2.0 (January 20, 2012) ##
-
-* ActiveSupport::Base64 is deprecated in favor of ::Base64. *Sergey Nartimov*
-
-* Module#synchronize is deprecated with no replacement. Please use `monitor`
- from ruby's standard library.
-
-* (Date|DateTime|Time)#beginning_of_week accept an optional argument to
- be able to set the day at which weeks are assumed to start.
-
-* Deprecated ActiveSupport::MessageEncryptor#encrypt and decrypt. *José Valim*
-
-* ActiveSupport::Notifications.subscribed provides subscriptions to events while a block runs. *fxn*
-
-* Module#qualified_const_(defined?|get|set) are analogous to the corresponding methods
- in the standard API, but accept qualified constant names. *fxn*
-
-* Added inflection #deconstantize which complements #demodulize. This inflection
- removes the righmost segment in a qualified constant name. *fxn*
-
-* Added ActiveSupport:TaggedLogging that can wrap any standard Logger class to provide tagging capabilities *DHH*
-
- Logger = ActiveSupport::TaggedLogging.new(Logger.new(STDOUT))
- Logger.tagged("BCX") { Logger.info "Stuff" } # Logs "[BCX] Stuff"
- Logger.tagged("BCX", "Jason") { Logger.info "Stuff" } # Logs "[BCX] [Jason] Stuff"
- Logger.tagged("BCX") { Logger.tagged("Jason") { Logger.info "Stuff" } } # Logs "[BCX] [Jason] Stuff"
-
-* Added safe_constantize that constantizes a string but returns nil instead of an exception if the constant (or part of it) does not exist *Ryan Oblak*
-
-* ActiveSupport::OrderedHash is now marked as extractable when using Array#extract_options! *Prem Sichanugrist*
-
-* Added Array#prepend as an alias for Array#unshift and Array#append as an alias for Array#<< *DHH*
-
-* The definition of blank string for Ruby 1.9 has been extended to Unicode whitespace.
- Also, in 1.8 the ideographic space U+3000 is considered to be whitespace. *Akira Matsuda, Damien Mathieu*
-
-* The inflector understands acronyms. *dlee*
-
-* Deprecated ActiveSupport::Memoizable in favor of Ruby memoization pattern *José Valim*
-
-* Added Time#all_day/week/quarter/year as a way of generating ranges (example: Event.where(created_at: Time.now.all_week)) *DHH*
-
-* Added instance_accessor: false as an option to Class#cattr_accessor and friends *DHH*
-
-* Removed ActiveSupport::SecureRandom in favor of SecureRandom from the standard library *Jon Leighton*
-
-* ActiveSupport::OrderedHash now has different behavior for #each and
- \#each_pair when given a block accepting its parameters with a splat. *Andrew Radev*
-
-* ActiveSupport::BufferedLogger#silence is deprecated. If you want to squelch
- logs for a certain block, change the log level for that block.
-
-* ActiveSupport::BufferedLogger#open_log is deprecated. This method should
- not have been public in the first place.
-
-* ActiveSupport::BufferedLogger's behavior of automatically creating the
- directory for your log file is deprecated. Please make sure to create the
- directory for your log file before instantiating.
-
-* ActiveSupport::BufferedLogger#auto_flushing is deprecated. Either set the
- sync level on the underlying file handle like this:
-
- f = File.open('foo.log', 'w')
- f.sync = true
- ActiveSupport::BufferedLogger.new f
-
- Or tune your filesystem. The FS cache is now what controls flushing.
-
-* ActiveSupport::BufferedLogger#flush is deprecated. Set sync on your
- filehandle, or tune your filesystem.
-
-
-## Rails 3.1.4 (March 1, 2012) ##
-
-* No changes
-
-
-## Rails 3.1.3 (November 20, 2011) ##
-
-* No changes
-
-
-## Rails 3.1.2 (November 18, 2011) ##
-
-* No changes
-
-
-## Rails 3.1.1 (October 7, 2011) ##
-
-* ruby193: String#prepend is also unsafe *Akira Matsuda*
-
-* Fix obviously breakage of Time.=== for Time subclasses *jeremyevans*
-
-* Added fix so that file store does not raise an exception when cache dir does
- not exist yet. This can happen if a delete_matched is called before anything
- is saved in the cache. *Philippe Huibonhoa*
-
-* Fixed performance issue where TimeZone lookups would require tzinfo each time *Tim Lucas*
-
-* ActiveSupport::OrderedHash is now marked as extractable when using Array#extract_options! *Prem Sichanugrist*
-
-
-## Rails 3.1.0 (August 30, 2011) ##
-
-* ActiveSupport::Dependencies#load and ActiveSupport::Dependencies#require now
- return the value from `super` *Aaron Patterson*
-
-* Fixed ActiveSupport::Gzip to work properly in Ruby 1.8 *Guillermo Iguaran*
-
-* Kernel.require_library_or_gem was deprecated and will be removed in Rails 3.2.0 *Josh Kalderimis*
-
-* ActiveSupport::Duration#duplicable? was fixed for Ruby 1.8 *thedarkone*
-
-* ActiveSupport::BufferedLogger set log encoding to BINARY, but still use text
- mode to output portable newlines. *fxn*
-
-* ActiveSupport::Dependencies now raises NameError if it finds an existing constant in load_missing_constant. This better reflects the nature of the error which is usually caused by calling constantize on a nested constant. *Andrew White*
-
-* Deprecated ActiveSupport::SecureRandom in favour of SecureRandom from the standard library *Jon Leighton*
-
-* New reporting method Kernel#quietly. *fxn*
-
-* Add String#inquiry as a convenience method for turning a string into a StringInquirer object *DHH*
-
-* Add Object#in? to test if an object is included in another object *Prem Sichanugrist, Brian Morearty, John Reitano*
-
-* LocalCache strategy is now a real middleware class, not an anonymous class
- posing for pictures.
-
-* ActiveSupport::Dependencies::ClassCache class has been introduced for
- holding references to reloadable classes.
-
-* ActiveSupport::Dependencies::Reference has been refactored to take direct
- advantage of the new ClassCache.
-
-* Backports Range#cover? as an alias for Range#include? in Ruby 1.8 *Diego Carrion, fxn*
-
-* Added weeks_ago and prev_week to Date/DateTime/Time. *Rob Zolkos, fxn*
-
-* Added before_remove_const callback to ActiveSupport::Dependencies.remove_unloadable_constants! *Andrew White*
-
-* JSON decoding now uses the multi_json gem which also vendors a json engine called OkJson. The yaml backend has been removed in favor of OkJson as a default engine for 1.8.x, while the built in 1.9.x json implementation will be used by default. *Josh Kalderimis*
-
-
-## Rails 3.0.12 (March 1, 2012) ##
-
-* No changes.
-
-
-## Rails 3.0.11 (November 18, 2011) ##
-
-* No changes.
-
-
-## Rails 3.0.10 (August 16, 2011) ##
-
-* Delayed backtrace scrubbing in `load_missing_constant` until we actually
- raise the exception
-
-
-## Rails 3.0.9 (June 16, 2011) ##
-
-* No changes.
-
-
-## Rails 3.0.8 (June 7, 2011) ##
-
-* No changes.
-
-
-## Rails 3.0.7 (April 18, 2011) ##
-
-* Hash.from_xml no longer loses attributes on tags containing only whitespace *André Arko*
-
-
-## Rails 3.0.6 (April 5, 2011) ##
-
-* No changes.
-
-
-## Rails 3.0.5 (February 26, 2011) ##
-
-* No changes.
-
-
-## Rails 3.0.4 (February 8, 2011) ##
-
-* No changes.
-
-
-## Rails 3.0.3 (November 16, 2010) ##
-
-* No changes.
-
-
-## Rails 3.0.2 (November 15, 2010) ##
-
-* Added before_remove_const callback to ActiveSupport::Dependencies.remove_unloadable_constants! *Andrew White*
-
-
-## Rails 3.0.1 (October 15, 2010) ##
-
-* No Changes, just a version bump.
-
-
-## Rails 3.0.0 (August 29, 2010) ##
-
-* Implemented String#strip_heredoc. *fxn*
-
-* Pluggable cache stores: setting config.cache_store = "custom_store" will require 'active_support/cache/custom_store' and look for the CustomStore constant. #5486 *Mike Perham*
-
-* Removed Object#returning, Object#tap should be used instead. *Santiago Pastorino*
-
-* Deprecation behavior is no longer hardcoded to the name of the environment.
- Instead, it is set via config.active_support.deprecation and can be one
- of :log, :stderr or :notify. :notify is a new style that sends the warning
- via ActiveSupport::Notifications, and is the new default for production
- *Yehuda Katz*
-
-* Renamed ActiveSupport::Dependecies.load_(once_)paths to autoload_(once_)paths. *fxn*
-
-* Added ActiveSupport::FileUpdateChecker to execute a block only if a set of files changed, used by Router and I18n locale files. *José Valim*
-
-* Added ActiveSupport::DescendantsTracker to track descendants with support to constants reloading. *José Valim*
-
-* ActiveSupport::OrderedHash#merge and #merge! accept a block. #4838 *Paul Mucur, fxn*
-
-* Date#since, #ago, #beginning_of_day, #end_of_day, and #xmlschema honor now the user time zone if set. *Geoff Buesing*
-
-* Extracted String#truncate from TextHelper#truncate *DHH*
-
-* Ruby 1.9: support UTF-8 case folding. #4595 *Norman Clarke*
-
-* Removes Array#rand and backports Array#sample from Ruby 1.9, thanks to Marc-Andre Lafortune. *fxn*
-
-* Ruby 1.9: Renames last_(month|year) to prev_(month|year) in Date and Time. *fxn*
-
-* Aliases Date#sunday to Date#end_of_week. *fxn*
-
-* Backports Date#>> from 1.9 so that calculations do the right thing around the calendar reform. *fxn*
-
-* Date#to_time handles properly years in the range 0..138. *fxn*
-
-* Deprecate {{}} as interpolation syntax for I18n in favor of %{} *José Valim*
-
-* Array#to_xml is more powerful and able to handle the same types as Hash#to_xml #4490 *Neeraj Singh*
-
-* Harmonize the caching API and refactor the backends. #4452 *Brian Durand*
- All caches:
- * Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
- * Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
- * Add support for a :namespace option. This can be used to set a global prefix for cache entries.
- * Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
- * Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
- * Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
- * Nil values can now be stored in the cache and are distinct from cache misses for fetch.
- * Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
- * Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
- * Increase test coverage.
- * Document methods which are provided as convenience but which may not be universally available.
-
- MemoryStore:
- * MemoryStore can now safely be used as the cache for single server sites.
- * Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
- * Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
- * Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
- * Deprecated SynchronizedMemoryStore since it isn't needed anymore.
-
- FileStore:
- * Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
- * Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
- * FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
- * Add cleanup method to keep the disk from filling up with expired entries.
- * Fix increment and decrement to use file system locks so they are consistent between processes.
-
- MemCacheStore:
- * Support all keys. Previously keys with spaces in them would fail
- * Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
-
-* JSON: encode objects that don't have a native JSON representation using to_hash, if available, instead of instance_values (the old fallback) or to_s (other encoders' default). Encode BigDecimal and Regexp encode as strings to conform with other encoders. Try to transcode non-UTF-8 strings. *Jeremy Kemper*
-
-* HashWithIndifferentAccess: remove inherited symbolize_keys! since its keys are always strings. *Santiago Pastorino*
-
-* Improve transliteration quality. #4374 *Norman Clarke*
-
-* Speed up and add Ruby 1.9 support for ActiveSupport::Multibyte::Chars#tidy_bytes. #4350 *Norman Clarke*
-
-* Reduced load time by deferring configuration of classes using
- ActiveSupport::on_load(:component_name) *YK*
-
-* Rename #metaclass to #singleton_class now that ruby-core has decided *JK*
-
-* New assertions assert_blank and assert_present. #4299 *Juanjo Bazan*
-
-* Use Object#singleton_class instead of #metaclass. Prefer Ruby's choice. *Jeremy Kemper*
-
-* JSON backend for YAJL. Preferred if available. #2666 *Brian Lopez*
-
-* Introduce class_attribute to declare inheritable class attributes. Writing an attribute on a subclass behaves just like overriding the superclass reader method. Unifies and replaces most usage of cattr_accessor, class_inheritable_attribute, superclass_delegating_attribute, and extlib_inheritable_attribute. *Jeremy Kemper, Yehuda Katz*
-
-* Time#- with a DateTime argument behaves the same as with a Time argument, i.e. returns the difference between self and arg as a Float #3476 *Geoff Buesing*
-
-* YAML serialization for OrderedHash. #3608 *Gregor Schmidt*
-
-* Update bundled TZInfo to v0.3.16 *Geoff Buesing*
-
-* Georgetown TimeZone is now mapped to "America/Guyana" instead of "America/Argentina/San_Juan" #1821 *Geoff Buesing, Reuben Sivan*
-
-* Changed the default ActiveSupport.use_standard_json_time_format from false to true and
- ActiveSupport.escape_html_entities_in_json from true to false to match previously announced Rails 3 defaults *DHH*
-
-* Added Object#presence that returns the object if it's #present? otherwise returns nil *DHH/Colin Kelley*
-
-* Add Enumerable#exclude? to bring parity to Enumerable#include? and avoid if !x.include?/else calls *DHH*
-
-* Update Edinburgh TimeZone to use "Europe/London" instead of "Europe/Dublin" #3310 *Phil Ross*
-
-* Update bundled TZInfo to v0.3.15 *Geoff Buesing*
-
-* JSON: +Object#to_json+ calls +as_json+ to coerce itself into something natively encodable like +Hash+, +Integer+, or +String+. Override +as_json+ instead of +to_json+ so you're JSON library agnostic. *Jeremy Kemper*
-
-* String #to_time and #to_datetime: handle fractional seconds #864 *Jason Frey*
-
-* Update bundled TZInfo to v0.3.13 *Geoff Buesing*
-
-* Allow MemCacheStore to be initialized with a MemCache-like object instead of addresses and options *Bryan Helmkamp*
-
-* Change spelling of Kyev timezone to Kyiv #2613 *Alexander Dymo*
-
-* Add ActiveSupport.parse_json_times to disable time parsing in JSON backends that don't support it or don't need it. *rick*
-
-* Add pluggable JSON backends with support for the JSON gem. *rick*
- Example: ActiveSupport::JSON.backend = "JSONGem"
-
- All internal Rails JSON encoding is now handled by ActiveSupport::JSON.encode(). Use of #to_json is not recommended, as it may clash with other libraries that overwrite it. However, you can recover Rails specific functionality
- if you really want to use #to_json.
-
- gem 'json'
- ActiveSupport::JSON.backend = "JSONGem"
-
- class ActiveRecord::Base
- alias to_json rails_to_json
- end
-
-* require 'active_support' no longer orders the whole menu of core extensions. Ask for just what you need: e.g. require 'active_support/core/time' to use timezones, durations, and stdlib date/time extensions. *Jeremy Kemper*
-
-* Removed rarely-used DRb cache store. *Jeremy Kemper*
-
-* TimeWithZone.name returns 'Time', to further thwart type checking *Geoff Buesing*
-
-* Time.local instances: Adding 24.hours across the DST boundary adds 24 hours instead of one day #2066 *Michael Curtis*
-
-
-## 2.3.2 Final (March 15, 2009) ##
-
-* XmlMini supports LibXML and Nokogiri backends. #2084, #2190 *Bart ten Brinke, Aaron Patterson*
- Example: XmlMini.backend = 'Nokogiri'
-
-* Vendorize i18n 0.1.3 gem (fixes issues with incompatible character encodings in Ruby 1.9) #2038 *Akira Matsuda*
-
-* Update bundled memcache-client from 1.5.0.5 to 1.6.4.99. See http://www.mikeperham.com/2009/02/15/memcache-client-performance/ *Mike Perham*
-
-* Ruby 1.9.1p0 fix: URI.unescape can decode multibyte chars. #2033 *MOROHASHI Kyosuke*
-
-* Time#to_s(:rfc822) uses #formatted_offset instead of unreliable and non-standard %z directive #1899 *Zachary Zolton*
-
-* Make TimeWithZone#to_formatted_s an alias to TimeWithZone#to_s #1796 *Levin Alexander*
-
-* Introduce Array.wrap(foo) to wrap the argument in an array unless it's already an array. Wraps nil as an empty array. Use instead of Array(foo) and foo.to_a since they treat String as Enumerable. *Jeremy Kemper*
-
-* TimeWithZone#xmlschema accepts optional fraction_digits argument [#1725 state:resolved] *Nicholas Dainty*
-
-* Object#tap shim for Ruby < 1.8.7. Similar to Object#returning, tap yields self then returns self. *Jeremy Kemper*
- array.select { ... }.tap(&:inspect).map { ... }
-
-* TimeWithZone#- gives correct result with wrapped DateTime, and with DateTime argument *Geoff Buesing*
-
-* Updated i18n gem to version 0.1.1 #1635 *Yaroslav Markin*
-
-* Add :allow_nil option to delegate. #1127 *Sergio Gil*
-
-* Add Benchmark.ms convenience method to benchmark realtime in milliseconds. *Jeremy Kemper*
-
-* Updated included memcache-client to the 1.5.0.5 version which includes fixes from fiveruns and 37signals to deal with failover and timeouts #1535 *Joshua Sierles*
-
-* Multibyte: add multibyte-safe Chars#ord rather than falling back to String#ord. #1483 *Jason Cheow*
-
-* I18n support for Array#to_sentence. Introduces support.array.words_connector, .two_words_connector, and .last_word_connector translation keys. #1397 *Akira Matsuda*
-
-* Added ActiveSupport::OrderedHash#each_key and ActiveSupport::OrderedHash#each_value #1410 *Christoffer Sawicki*
-
-* Added ActiveSupport::MessageVerifier and MessageEncryptor to aid users who need to store signed and/or encrypted messages. *Michael Koziarski*
-
-* Added ActiveSupport::BacktraceCleaner to cut down on backtrace noise according to filters and silencers *David Heinemeier Hansson*
-
-* Added Object#try. ( Taken from http://ozmm.org/posts/try.html ) *Chris Wanstrath*
-
-* Added Enumerable#none? to check that none of the elements match the block #1408 *Damian Janowski*
-
-* TimeZone offset tests: use current_period, to ensure TimeZone#utc_offset is up-to-date *Geoff Buesing*
-
-* Update bundled TZInfo to 0.3.12 *Geoff Buesing*
-
-* Added lambda merging to OptionMerger (especially useful with named_scope and with_options) #726 *Paweł Kondzior*
-
-
-## 2.2.1 RC2 (November 14th, 2008) ##
-
-* 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 *David Heinemeier Hansson/Sven Fuchs*
-
-
-## 2.2.0 RC1 (October 24th, 2008) ##
-
-* 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 Naik*
-
-* 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 ("Donald E. Knuth".parameterize => "donald-e-knuth") #713 *Matt Darby*
-
-* Changed cache benchmarking to be reported in milliseconds *David Heinemeier Hansson*
-
-* 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) # => [[1, 2, 3, 4], [5, 6, 7, nil], [8, 9, 10, nil]]
- a.in_groups(3, false) # => [[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 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 *Dan Manges*
-
- ActiveSupport::Inflector.inflections do |inflect|
- inflect.human(/_cnt$/i, '\1_count')
- end
-
- 'jargon_cnt'.humanize # => '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] *David Heinemeier Hansson*
-
-* Added test/do declaration style testing to ActiveSupport::TestCase *DHH via Jay Fields*
-
-* Added Object#present? which is equivalent to !Object#blank? *David Heinemeier Hansson*
-
-* Added Enumberable#many? to encapsulate collection.size > 1 *David Heinemeier Hansson/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("production").production? # => true and StringInquirer.new("production").development? # => false *David Heinemeier Hansson*
-
-* Fixed Date#end_of_quarter to not blow up on May 31st [#289 state:resolved] (Danger)
-
-
-## 2.1.0 (May 31st, 2008) ##
-
-* TimeZone#to_s shows offset as GMT instead of UTC, because GMT will be more familiar to end users (see time zone selects used by Windows OS, google.com and yahoo.com.) Reverts [8370] *Geoff Buesing*
-
-* Hash.from_xml: datetime xml types overflow to Ruby DateTime class when out of range of Time. Adding tests for utc offsets *Geoff Buesing*
-
-* TimeWithZone #+ and #- : ensure overflow to DateTime with Numeric arg *Geoff Buesing*
-
-* Time#to_json: don't convert to utc before encoding. References #175 *Geoff Buesing*
-
-* Remove unused JSON::RESERVED_WORDS, JSON.valid_identifier? and JSON.reserved_word? methods. Resolves #164. *Cheah Chu Yeow*
-
-* Adding Date.current, which returns Time.zone.today if config.time_zone is set; otherwise returns Date.today *Geoff Buesing*
-
-* TimeWithZone: date part getter methods (#year #mon #day etc) are defined on class; no longer relying on method_missing *Geoff Buesing*
-
-* Time.zone.parse return nil for strings with no date information *Geoff Buesing*
-
-* Time.zone.parse respects offset information in string. Resolves #105. *Scott Fleckenstein, Geoff Buesing*
-
-* Added Ruby 1.8 implementation of Process.daemon
-
-* Duration #since and #ago with no argument (e.g., 5.days.ago) return TimeWithZone when config.time_zone is set. Introducing Time.current, which returns Time.zone.now if config.time_zone is set, otherwise just returns Time.now *Geoff Buesing*
-
-* Time#since behaves correctly when passed a Duration. Closes #11527 *kemiller*
-
-* Add #getutc alias for DateTime#utc *Geoff Buesing*
-
-* Refactor TimeWithZone: don't send #since, #ago, #+, #-, #advance through method_missing *Geoff Buesing*
-
-* TimeWithZone respects config.active_support.use_standard_json_time_format *Geoff Buesing*
-
-* Add config.active_support.escape_html_entities_in_json to allow disabling of html entity escaping. *Rick Olson*
-
-* Improve documentation. *Xavier Noria*
-
-* Modified ActiveSupport::Callbacks::Callback#call to accept multiple arguments.
-
-* Time #yesterday and #tomorrow behave correctly crossing DST boundary. Closes #7399 *sblackstone*
-
-* TimeWithZone: Adding tests for dst and leap day edge cases when advancing time *Geoff Buesing*
-
-* TimeWithZone#method_missing: send to utc to advance with dst correctness, otherwise send to time. Adding tests for time calculations methods *Geoff Buesing*
-
-* Add config.active_support.use_standard_json_time_format setting so that Times and Dates export to ISO 8601 dates. *Rick Olson*
-
-* TZInfo: Removing unneeded TimezoneProxy class *Geoff Buesing*
-
-* TZInfo: Removing unneeded TimezoneIndexDefinition, since we're not including Indexes::Timezones *Geoff Buesing*
-
-* Removing unnecessary uses_tzinfo helper from tests, given that TZInfo is now bundled *Geoff Buesing*
-
-* Bundling abbreviated version of TZInfo gem 0.3.8: only the classes and zone definitions required to support Rails time zone features are included. If a recent version of the full TZInfo gem is installed, this will take precedence over the bundled version *Geoff Buesing*
-
-* TimeWithZone#marshal_load does zone lookup via Time.get_zone, so that tzinfo/Olson identifiers are handled *Geoff Buesing*
-
-* Time.zone= accepts TZInfo::Timezone instances and Olson identifiers; wraps result in TimeZone instance *Geoff Buesing*
-
-* TimeWithZone time conversions don't need to be wrapped in TimeOrDateTime, because TZInfo does this internally *Geoff Buesing*
-
-* TimeWithZone#usec returns 0 instead of error when DateTime is wrapped *Geoff Buesing*
-
-* Improve documentation. *Ryan Bigg, Jan De Poorter, Cheah Chu Yeow, Xavier Shay, Jack Danger Canty, Emilio Tagua, Xavier Noria, Sunny Ripert*
-
-* Ensure that TimeWithZone#to_yaml works when passed a YAML::Emitter. *Rick Olson*
-
-* Ensure correct TimeWithZone#to_date *Geoff Buesing*
-
-* Make TimeWithZone work with tzinfo 0.2.x: use TZInfo::Timezone#zone_identifier alias for #abbreviation, silence warnings on tests. Raise LoadError when TZInfo version is < 0.2 by sniffing for TZInfo::TimeOrDateTime constant. Move all tzinfo-dependent TimeZone tests into uses_tzinfo block *Geoff Buesing*
-
-* Time, DateTime and TimeWithZone #in_time_zone defaults to Time.zone. Removing now unneeded #in_current_time_zone *Geoff Buesing*
-
-* TZInfo caches Timezone instances in its own internal hash cache, so TimeZone::MAPPING doesn't need to cache them as well *Geoff Buesing*
-
-* Adding TimeZone#parse *Geoff Buesing*
-
-* Adding TimeZone#at and DateTime#to_f *Geoff Buesing*
-
-* TimeWithZone responds to Ruby 1.9 weekday-named query methods *Geoff Buesing*
-
-* TimeWithZone caches TZInfo::TimezonePeriod used for time conversion so that it can be reused, and enforces DST rules correctly when instance is created from a local time *Geoff Buesing*
-
-* Fixed that BufferedLogger should create its own directory if one doesn't already exist #11285 *lotswholetime*
-
-* Fix Numeric time tests broken by DST change by anchoring them to fixed times instead of Time.now. Anchor TimeZone#now DST test to time specified with Time.at instead of Time.local to work around platform differences with Time.local and DST representation *Geoff Buesing*
-
-* Removing unneeded #change_time_zone method from Time, DateTime and TimeWithZone *Geoff Buesing*
-
-* TimeZone #local and #now correctly enforce DST rules *Geoff Buesing*
-
-* TimeWithZone instances correctly enforce DST rules. Adding TimeZone#period_for_utc *Geoff Buesing*
-
-* test_time_with_datetime_fallback expects DateTime.local_offset instead of DateTime.now.offset *Geoff Buesing*
-
-* Adding TimeWithZone #marshal_dump and #marshal_load *Geoff Buesing*
-
-* Add OrderedHash#to_hash *Josh Peek*
-
-* Adding Time#end_of_day, _quarter, _week, and _year. #9312 *Juanjo Bazan, Tarmo Tänav, BigTitus*
-
-* Adding TimeWithZone#between? *Geoff Buesing*
-
-* Time.=== returns true for TimeWithZone instances *Geoff Buesing*
-
-* TimeWithZone #+ and #- behave consistently with numeric arguments regardless of whether wrapped time is a Time or DateTime; consistenty answers false to #acts_like?(:date) *Geoff Buesing*
-
-* Add String#squish and String#squish! to remove consecutive chunks of whitespace. #11123 *Jordi Bunster, Henrik N*
-
-* Serialize BigDecimals as Floats when using to_yaml. #8746 *Ernesto Jimenez*
-
-* Adding TimeWithZone #to_yaml, #to_datetime, #eql? and method aliases for duck-typing compatibility with Time *Geoff Buesing*
-
-* TimeWithZone #in_time_zone returns +self+ if zone argument is the same as #time_zone *Geoff Buesing*
-
-* Adding TimeWithZone #to_a, #to_f, #to_i, #httpdate, #rfc2822 *Geoff Buesing*
-
-* Pruning unneeded TimeWithZone#change_time_zone_to_current *Geoff Buesing*
-
-* Time#zone=, #in_time_zone and #change_time_zone accept a Duration *Geoff Buesing*
-
-* Time#in_time_zone handles Time.local instances correctly *Geoff Buesing*
-
-* Pruning unneeded Time#change_time_zone_to_current. Enhanced docs to #change_time_zone to explain the difference between this method and #in_time_zone *Geoff Buesing*
-
-* TimeZone#new method renamed #local; when used with Time.zone, constructor now reads: Time.zone.local() *Geoff Buesing*
-
-* Added Base64.encode64s to encode values in base64 without the newlines. This makes the values immediately usable as URL parameters or memcache keys without further processing *David Heinemeier Hansson*
-
-* Remove :nodoc: entries around the ActiveSupport test/unit assertions. #10946 *dancroak, jamesh*
-
-* Add Time.zone_default accessor for setting the default time zone. Rails::Configuration.time_zone sets this. #10982 *Geoff Buesing*
-
-* cache.fetch(key, :force => true) to force a cache miss. *Jeremy Kemper*
-
-* Support retrieving TimeZones with a Duration. TimeZone[-28800] == TimeZone[-480.minutes]. *Rick Olson*
-
-* TimeWithZone#- added, so that #- can handle a Time or TimeWithZone argument correctly *Geoff Buesing*
-
-* with_timezone test helper renamed with_env_tz, to distinguish between setting ENV['TZ'] and setting Time.zone in tests *Geoff Buesing*
-
-* Time#- coerces TimeWithZone argument to a Time instance so that difference in seconds can be calculated. Closes #10914 *Geoff Buesing, yyyc514*
-
-* Adding UTC zone to TimeZone; TimeWithZone no longer has to fake UTC zone with nil *Geoff Buesing*
-
-* Time.get_zone refactored to private method, given that the encapsulated logic is only useful internally *Geoff Buesing*
-
-* Time.zone uses thread-local variable for thread safety. Adding Time.use_zone, for overriding Time.zone locally inside a block. Removing unneeded Time.zone_reset! *Geoff Buesing*
-
-* TimeZone#to_s uses UTC rather than GMT; reapplying change that was undone in [8679]. #1689 *Cheah Chu Yeow*
-
-* Time.days_in_month defaults to current year if no year is supplied as argument #10799 [Radar], uses Date.gregorian_leap? to determine leap year, and uses constant lookup to determine days in month *Geoff Buesing*
-
-* Adding Time and DateTime #compare_with_coercion, which layers behavior on #<=> so that any combination of Time, DateTime and ActiveSupport::TimeWithZone instances can be chronologically compared *Geoff Buesing*
-
-* TimeZone#now returns an ActiveSupport::TimeWithZone *Geoff Buesing*
-
-* Time #in_current_time_zone and #change_time_zone_to_current return self when Time.zone is nil *Geoff Buesing*
-
-* Remove unneeded #to_datetime_default_s alias for DateTime#to_s, given that we inherit a #to_default_s from Date that does exactly the same thing *Geoff Buesing*
-
-* Refactor Time and DateTime #to_formatted_s: use ternary instead of nested if/else *Geoff Buesing*
-
-* Adding Time and DateTime #formatted_offset, for outputting +HH:MM utc offset strings with cross-platform consistency *Geoff Buesing*
-
-* Adding alternate_utc_string option to TimeZone#formatted_offset. Removing unneeded TimeZone#offset. *Geoff Buesing*
-
-* Introduce ActiveSupport::TimeWithZone, for wrapping Time instances with a TimeZone. Introduce instance methods to Time for creating TimeWithZone instances, and class methods for managing a global time zone. *Geoff Buesing*
-
-* Replace non-dst-aware TimeZone class with dst-aware class from tzinfo_timezone plugin. TimeZone#adjust and #unadjust are no longer available; tzinfo gem must now be present in order to perform time zone calculations, via #local_to_utc and #utc_to_local methods. *Geoff Buesing*
-
-* Extract ActiveSupport::Callbacks from Active Record, test case setup and teardown, and ActionController::Dispatcher. #10727 *Josh Peek*
-
-* Introducing DateTime #utc, #utc? and #utc_offset, for duck-typing compatibility with Time. Closes #10002 *Geoff Buesing*
-
-* Time#to_json uses Numeric#to_utc_offset_s to output a cross-platform-consistent representation without having to convert to DateTime. References #9750 *Geoff Buesing*
-
-* Refactor number-to-HH:MM-string conversion logic from TimeZone#formatted_offset to a reusable Numeric#to_utc_offset_s method. *Geoff Buesing*
-
-* Continue evolution toward ActiveSupport::TestCase. #10679 *Josh Peek*
-
-* TestCase: introduce declared setup and teardown callbacks. Pass a list of methods and an optional block to call before setup or after teardown. Setup callbacks are run in the order declared; teardown callbacks are run in reverse. *Jeremy Kemper*
-
-* Added ActiveSupport::Gzip.decompress/compress(source) as an easy wrapper for Zlib *Tobias Lütke*
-
-* Included MemCache-Client to make the improved ActiveSupport::Cache::MemCacheStore work out of the box *Bob Cottrell, Eric Hodel*
-
-## Added ActiveSupport::Cache:: framework as an extraction from ActionController::Caching::Fragments:: David Heinemeier Hansson ##
-
-* Fixed String#titleize to work for strings with 's too #10571 *trek*
-
-* Changed the implementation of Enumerable#group_by to use a double array approach instead of a hash such that the insert order is honored *David Heinemeier Hansson/Marcel Molina Jr.*
-
-* remove multiple enumerations from ActiveSupport::JSON#convert_json_to_yaml when dealing with date/time values. *Rick Olson*
-
-* Hash#symbolize_keys skips keys that can't be symbolized. #10500 *Brad Greenlee*
-
-* Ruby 1.9 compatibility. #1689, #10466, #10468, #10554, #10594, #10632 *Cheah Chu Yeow, Pratik Naik, Jeremy Kemper, Dirkjan Bussink, Xavier Noria*
-
-* TimeZone#to_s uses UTC rather than GMT. #1689 *Cheah Chu Yeow*
-
-* Refactor of Hash#symbolize_keys! to use Hash#replace. Closes #10420 *ReinH*
-
-* Fix HashWithIndifferentAccess#to_options! so it doesn't clear the options hash. Closes #10419 *ReinH*
-
-
-## 2.0.1 (December 7th, 2007) ##
-
-* Added Array#from and Array#to that behaves just from String#from and String#to *David Heinemeier Hansson*
-
-* Fix that empty collections should be treated as empty arrays regardless of whitespace for Hash#from_xml #10255 *adamj*
-
-* Time#time_with_datetime_fallback, Time#to_datetime, Date#to_datetime and String#to_datetime honor Ruby's default calendar reform setting. #10201 *Geoff Buesing*
-
-* Change Time and DateTime #end_of_month to return last second of month instead of beginning of last day of month. Closes #10200 *Geoff Buesing*
-
-* Speedup String#blank? *Jeremy Kemper, Michael Koziarski*
-
-* Add documentation for Hash#diff. Closes #9306 *Tarmo Tänav*
-
-* Add new superclass_delegating_accessors. Similar to class inheritable attributes but with subtly different semantics. *Michael Koziarski, Tarmo Tänav*
-
-* Change JSON to encode %w(< > &) as 4 digit hex codes to be in compliance with the JSON spec. Closes #9975 *Josh Peek, Cheah Chu Yeow, Tim Pope*
-
-* Fix JSON encoding/decoding bugs dealing with /'s. Closes #9990 *Rick Olson, theamazingrando*
-
-* Introduce a base class for all test cases used by rails applications. ActiveSupport::TestCase *Michael Koziarski*
-
- The intention is to use this to reduce the amount of monkeypatching / overriding that
- is done to test/unit's classes.
-
-* Document Enumerable and Hash #to_json. #9970 *Cheah Chu Yeow*
-
-* Hash#to_xml handles symbol values. #9954 *Assaf*
-
-* Hash#symbolize_keys behaves well with integer keys. #9890 *PotatoSalad*
-
-* Multibyte: String#slice supports regexp argument. #9646 *yob*
-
-* object.duplicable? returns true if object.dup is safe. False for nil, true, false, symbols, and numbers; true otherwise. #9333 *sur*
-
-* Time, Date and DateTime #advance accept :weeks option. #9866 *Geoff Buesing*
-
-* Fix Time#years_ago and #years_since from leap days. #9865 *Geoff Buesing*
-
-* Time and DateTime#advance accept :hours, :minutes, and :seconds options. #9825 *Geoff Buesing*
-
-* Fix Date#years_ago and #years_since from leap days. #9864 *Geoff Buesing*
-
-* Refactor Time and Date#months_since and #months_ago to use #advance. #9863 *Geoff Buesing*
-
-* Rebundle Builder 2.1.2 but prefer a newer RubyGem if available. *Jeremy Kemper*
-
-* Add Range#overlaps?(range), Range#include?(range), and Range#step without a block. *brandon*
-
-* Correct BufferedLogger#level? checks. #9806 *wildchild, Johan Sorensen*
-
-* String#to_xs uses Eric Wong's fast_xs extension, if available, for Builder speedup. http://bogomips.org/fast_xs/ *Jeremy Kemper*
-
-* Introduce BasicObject as Builder::BlankSlate for Ruby 1.9 forward compatibility. *Jeremy Kemper*
-
-* Unbundle Builder in favor of a gem dependency. *Jeremy Kemper*
-
-* Disambiguate Time, Date, and DateTime#to_json formatting. #9750 *Geoff Buesing, Cheah Chu Yeow*
-
-* Hash#to_json takes :only or :except options to specific or omit certain hash keys. Enumerable#to_json passes through its options to each element. #9751 *Cheah Chu Yeow*
-
-* BufferedLogger#auto_flushing = N flushes the log every N messages. Buffers with an array instead of string. Disabling auto_flushing still flushes when the buffer hits a maximum size, as a failsafe against memory-gobbling. *Jeremy Kemper*
-
-* Fixed Date#xmlschema for dates outside the range of what can be created with Time #9744 *Geoff Buesing*
-
-* Fixed that La Paz was included in -25200 and -14400 offsets when it should only be in -14400 #9735 *bermi*
-
-* Fixed JSON encoding to use quoted keys according to the JSON standard. #8762 *choonkat, Cheah Chu Yeow*
-
-* Alias Object#send to send! for Ruby 1.9 forward compatibility. *Jeremy Kemper*
-
-* Backport Object#instance_variable_defined? for Ruby < 1.8.6. *Jeremy Kemper*
-
-* BufferedLogger#add converts the message to a string. #9702, #9724 *eigentone, DrMark, Tom Ward*
-
-* Added ActiveSupport::BufferedLogger as a duck-typing alternative (albeit with no formatter) to the Ruby Logger, which provides a very nice speed bump (inspired by Ezra's buffered logger) *David Heinemeier Hansson*
-
-* Object#instance_exec produces fewer garbage methods. *Mauricio Fernandez*
-
-* Decode json strings as Dates/Times if they're using a YAML-compatible format. Closes #9614 *Rick Olson*
-
-* Fixed cache_page to use the request url instead of the routing options when picking a save path. #8614 *Josh Peek*
-
-* Object.subclasses_of includes anonymous subclasses. *Jeremy Kemper*
-
-* Fixed that pluralizing an empty string should return the same empty string, not "s". #7720 *Josh Peek*
-
-* Added call to inspect on non-string classes for the logger #8533 *Coda Hale*
-
-* Deprecation: remove deprecated :mday option from Time, Date, and DateTime#change. *Jeremy Kemper*
-
-* Fix JSON decoder with nested quotes and commas. #9579 *Zach Dennis*
-
-* Hash#to_xml doesn't double-unescape. #8806 *Ezran*
-
-* Added Array#rand #9170 [Norbert Crombach]. Examples:
-
- [].rand # => nil
- ['a'].rand # => 'a'
- [1,2,3].rand # => 1 or 2 or 3
-
-* Deprecation: removed Reloadable. *Jeremy Kemper*
-
-* Make the utf-handler return the correct value for non-matching regular expressions. Closes #9049 *Manfred Stienstra*
-
-* Add ljust, rjust and center to utf8-handler. Closes #9165 *Manfred Stienstra*
-
-* Fix Time#advance bug when trying to advance a year from leap day. Closes #8655 *Geoff Buesing*
-
-* Add support for []= on ActiveSupport::Multibyte::Chars. Closes #9142. *ewan, Manfred Stienstra*
-
-* Added Array#extract_options! to encapsulate the pattern of getting an options hash out of a variable number of parameters. #8759 *Norbert Crombach*
-
-* Let alias_attribute work with attributes with initial capital letters (legacy columns etc). Closes #8596 *mpalmer*
-
-* Added Hash#except which is the inverse of Hash#slice -- return the hash except the keys that are specified *David Heinemeier Hansson*
-
-* Added support for pluralization with a different starting letter than the singular version (cow/kine) #4929 *norri_b/Josh Susser*
-
-* Demote Hash#to_xml to use XmlSimple#xml_in_string so it can't read files or stdin. #8453 *candlerb, Jeremy Kemper*
-
-* Backport clean_logger changes to support ruby 1.8.2 *Mislav Marohnić*
-
-* Added proper handling of arrays #8537 *Josh Susser*
-
- Before:
- Hash.from_xml '<images></images>'
- # => {:images => nil}
-
- Hash.from_xml '<images><image>foo.jpg</image></images>'
- # => {:images => {:image => "foo.jpg"}}
-
- Hash.from_xml '<images><image>foo.jpg</image><image>bar.jpg</image></images>'
- # => {:images => {:image => ["foo.jpg", "bar.jpg"]}}
-
- After:
- Hash.from_xml '<images type="array"></images>'
- # => {:images => []}
-
- Hash.from_xml '<images type="array"><image>foo.jpg</image></images>'
- # => {:images => ["foo.jpg"]}
-
- Hash.from_xml '<images type="array"><image>foo.jpg</image><image>bar.jpg</image></images>'
- # => {:images => ["foo.jpg", "bar.jpg"]}
-
-* Improve Time and Date test coverage. #8646 *Josh Peek*
-
-* Add Date#since, ago, beginning_of_day, and end_of_day. Date + seconds works now. #8575 *Geoff Buesing*
-
-* String#to_time overflows to DateTime. Add String#to_datetime. #8572 *Geoff Buesing*
-
-* Date.yesterday and .tomorrow. #8571 *Geoff Buesing*
-
-* Readable Date and DateTime#inspect. #8570 *Geoff Buesing*
-
-* Move common DateTime calculations to Date. #8536 *Geoff Buesing*
-
-* Added Date#change (like Time#change) *David Heinemeier Hansson*
-
-* DateTime#to_time converts to Time unless out of range. #8512 *Geoff Buesing*
-
-* Date#to_datetime, #to_s(:rfc822). #8512 *Geoff Buesing*
-
-* Time durations use since instead of + for accuracy. #8513 *Geoff Buesing*
-
-* escape <'s and >'s in JSON strings. #8371 *Rick Olson*
-
-* Inflections: MatrixTest -> MatrixTests instead of MatricesTest. #8496 *jbwiv*
-
-* Multibyte strings respond_to the String methods they proxy so they can be duck-typed. #6549 *Tuxie*
-
-* Array#to_xml yields the builder just like Hash and ActiveRecord::Base. #8472 *seth*
-
-* Date, Time, and DateTime support formatting blocks in addition to strftime strings. Introduce :long_ordinal format, e.g. "February 21st, 2005". #8191 *Coda Hale*
-
-* Document Object#blank?. #6491 *Chris Mear*
-
-* Date, Time, and DateTime#to_json. #8399 *wycats*
-
-* Simplify API of assert_difference by passing in an expression that is evaluated before and after the passed in block. See documenation for examples of new API. *Marcel Molina Jr.*
-
-* Added assert_difference and assert_no_difference to test/unit assertions *Tobias Lütke*
-
-* Removed breakpointer and Binding.of_caller in favor of relying on ruby-debug by Kent Sibilev since the breakpointer has been broken since Ruby 1.8.4 and will not be coming back *David Heinemeier Hansson*
-
-* Added parsing of file type in Hash.xml_in so you can easily do file uploads with base64 from an API *David Heinemeier Hansson*
-
- <person>
- <name>David</name>
- <avatar type="file" name="me.jpg" content_type="image/jpg">R0lGODlhkACZAPUAAM5lcfjrtMQCG=\n</avatar>
- </person>
-
- ...becomes:
-
- attributes = { :person => { :name => "David", :avatar => #<StringIO> } }
- attributes[:person][:avatar].content_type # => "image/jpg"
- attributes[:person][:avatar].original_filename # => "me.jpg"
- attributes[:person][:avatar].read # => binary data of the file
-
- Which is duck-type compatible with the files that you get when doing multipart uploads through HTML.
-
-* Improved multibyte performance by relying less on exception raising #8159 *Blaine*
-
-* Use XSD-compatible type names for Hash#to_xml and make the converters extendable #8047 *Tim Pope*
-
-* Added yielding of builder in Hash#to_xml *David Heinemeier Hansson*
-
-* Hash#with_indifferent_access now also converts hashes kept in arrays to indifferent access (makes it easier to treat HTML and XML parameters the same) *David Heinemeier Hansson*
-
-* Hash#to_xml supports YAML attributes. #7502 *jonathan*
-
-* Refactor ActiveSupport::JSON to be less obtuse. Add support for JSON decoding by way of Syck with ActiveSupport::JSON.decode(json_string). Prevent hash keys that are JavaScript reserved words from being unquoted during encoding. *Sam Stephenson*
-
-* alias_method_chain preserves the original method's visibility. #7854 *Jonathan Viney*
-
-* Update Dependencies to ignore constants inherited from ancestors. Closes #6951. *Nicholas Seckar*
-
-* Array#to_query preserves its ordering. #7756 *Greg Spurrier*
-
-* Out-of-range Time calculations transparently overflow to DateTime. Introduce Time#to_datetime. #7706, #7715 *Geoff Buesing*
-
-* DateTime calculations analogous to the Date and Time extensions. #7693 *Geoff Buesing*
-
-* Give DateTime correct .to_s implementations, lets it play nice with ActiveRecord quoting. #7649 *Geoff Buesing*
-
-* Add File.atomic_write, allows you to write large files in an atomic manner, preventing users from seeing half written files. *Michael Koziarski*
-
-* Allow users to provide custom formatters to Logger. *Anthony Eden*
-
-* Hash#to_query CGI-escapes its keys. *Jeremy Kemper*
-
-* Optimize Class Inheritable Attributes so that unnecessary hashes are not created. Closes #7472 *Bruce Perens*
-
-* :db format for Date#to_s *Jeremy Kemper*
- Date.new(2007, 1, 27).to_s(:db) # => '2007-01-27'
-
-* Added :instance_writer option to #mattr_writer/accessor, #cattr_writer/accessor, and #class_inheritable_writer to skip the creation of the instance writer. *Rick Olson*
-
-* Added Hash#to_query to turn a hash of values into a form-encoded query string *Nicholas Seckar*
-
-* Increase test coverage for subclasses_of. Closes #7335. *Roman2K, Nicholas Seckar*
-
-* Remove unused code from Duration#inspect. Closes #7180. *Rich Collins*
-
-* Added test coverage for Inflector.inflections.clear. Closes #7179. *Rich Collins*
-
-* ActiveSupport::Multibyte::Handlers::UTF8Handler should raise when a range and an integer are passed in (just like the native implementation). Closes #7176 *Rich Collins*
-
-* A couple extra tests for #classify. Closes #7273. *Josh Susser*
-
-* Better docs for Object extensions *zackchandler, Jamis Buck*
-
-* Fix that Dates couldn't be subtracted from Dates after [5940]. *Sam Stephenson*
-
-* Add Object#acts_like? and Time#acts_like_time? and Date#acts_like_date? to facilitate duck-typing. *Jamis Buck*
-
-* Make 1.months and friends accurate by introducing a Duration class. #6835 *eventualbuddha*
-
-
-## 1.4.2 (March 12th, 2007) ##
-
-* Ruby 1.8.6 and 1.9 define private Time#to_date and #to_datetime; make them
- public for compatibility. *Jeremy Kemper*
-
-* Deprecation: warn on stderr if RAILS_DEFAULT_LOGGER isn't set yet. *Jeremy Kemper*
-
-
-## 1.4.1 (February 5th, 2007) ##
-
-* Optimize Class Inheritable Attributes so that unnecessary hashes are not created. Closes #7472 *Bruce Perens*
-
-* Added :instance_writer option to #mattr_writer/accessor, #cattr_writer/accessor, and #class_inheritable_writer to skip the creation of the instance writer. *Rick Olson*
-
-* Full test coverage for Inflector. #7228 *Dan Kubb*
-
-
-## 1.4.0 (January 16th, 2007) ##
-
-* Document Inflector.ordinalize and merge docs from String inflections. #7023 *smeade*
-
-* Unbundle flexmock. *Jeremy Kemper*
-
-* Fix Dependencies.autoloaded? to ignore anonymous modules. Closes #6561. *Nicholas Seckar*
-
-* Update load once paths to prevent nested once constants from being detected and claimed by an external non-once load. *Nicholas Seckar*
-
-* Deprecation: silence warnings when reporting test errors. *Jeremy Kemper*
-
-* Hash#slice(*keys) returns a new hash with only the given keys. #slice! replaces the hash with only the given keys. Works with HashWithIndifferentAccess also. *Jeremy Kemper*
-
-* HashWithIndifferentAccess#to_hash converts to a Hash with String keys and the same default value. *Jeremy Kemper*
-
-* Fix remove_constant to correctly handle constant names of the form "::A::...". References #6720. *Nicholas Seckar*
-
-* Fixed Array#to_xml when it contains a series of hashes (each piece would get its own XML declaration) #6610 *thkarcher/cyu*
-
-* Added Time#to_s(:time) which will just return H:M, like 17:44 *David Heinemeier Hansson*
-
-* Add Module#attr_accessor_with_default to initialize value of attribute before setting it. Closes #6538. *Stuart Halloway, Marcel Molina Jr.*
-
-* Hash#to_xml handles keys with the same name as Kernel methods. #6613 *Jonathan del Strother*
-
-* Added Time#end_of_day to get 23:59:59 of that day *David Heinemeier Hansson*
-
-* Don't quote hash keys in Hash#to_json if they're valid JavaScript identifiers. Disable this with ActiveSupport::JSON.unquote_hash_key_identifiers = false if you need strict JSON compliance. *Sam Stephenson*
-
-* Lazily load the Unicode Database in the UTF-8 Handler *Rick Olson*
-
-* Update dependencies to delete partially loaded constants. *Nicholas Seckar*
-
-* Fix unicode JSON regexp for Onigurama compatibility. #6494 *whitley*
-
-* update XmlSimple to 1.0.10. Closes #6532. *Nick Sieger*
-
-* Update dependencies to allow constants to be defined alongside their siblings. A common case for this is AR model classes with STI; user.rb might define User, Administrator and Guest for example. *Nicholas Seckar*
-
-* next_week respects DST changes. #6483, #5617, #2353, #2509, #4551 *marclove, Rob Biedenharn, rails@roetzel.de, jsolson@damogran.org, drbrain@segment7.net*
-
-* Expose methods added to Enumerable in the documentation, such as group_by. Closes #6170. *sergeykojin@gmail.com, Marcel Molina Jr.*
-
-* Ensure Chars#tidy_bytes only tidies broken bytes. Closes #6397 *Manfred Stienstra*
-
-* Add 'unloadable', a method used to mark any constant as requiring an unload after each request. *Nicholas Seckar*
-
-* Make core_ext/string/access.rb multibyte safe. Closes #6388 *Manfred Stienstra*
-
-* Make String#chars slicing behaviour consistent with String. Closes #6387 *Manfred Stienstra*
-
-* Pull in latest multibyte patch. Closes #6346 *Manfred Stienstra*
-
-* Add ActiveSupport::Multibyte. Provides String#chars which lets you deal with strings as a sequence of chars, not of bytes. Closes #6242 *Julian Tarkhanov, Manfred Stienstra, Thijs van der Vossen & Jan Behrens*
-
-* Fix issue with #class_inheritable_accessor saving updates to the parent class when initialized with an Array or Hash *mojombo*
-
-* Hash#to_xml supports Bignum and BigDecimal. #6313 *edibiase*
-
-* Don't undefine #class in OptionMerger *Rick Olson*
-
-* Hash.create_from_xml has been renamed to Hash.from_xml, alias will exist until Rails 2.0 *David Heinemeier Hansson*
-
-* alias_method_chain works with accessor= methods also. #6153 *Caio Chassot*
-
-* Fix loadable_constants_for_path to handle load paths that do not end with a slash. *Nicholas Seckar*
-
-* Fix logic error in determining what was loaded by a given file. Closes #6039. *Nicholas Seckar*
-
-* Equate Kernel.const_missing with Object.const_missing. Fixes #5988. *Nicholas Seckar*
-
-* Add ApplicationController special case to Dependencies. *Nicholas Seckar*
-
-* Don't pad remaining places with in_groups_of if specified padding value is false. *Marcel Molina Jr.*
-
-* Fix cases where empty xml nodes weren't being translated to nil in Hash.create_from_xml *Rick Olso n*
-
- <written-on type="date"></written-on> # => { :type => 'date' } # WRONG
- <written-on type="date"></written-on> # => nil # RIGHT
-
-* Tighten rescue clauses. #5985 *james@grayproductions.net*
-
-* Inflections: don't singularize -ies plurals. *foamdino@gmail.com, Mark Van Holstyn*
-
-* Update Initializer to use load_once_paths to avoid plugin reloading. References #5852. *Nicholas Seckar*
-
-* Use Array#assoc in ActiveSupport::OrderedHash. *Mauricio Fernandez*
-
-* Greatly increased performance of String.to_json, which speeds up RJS considerably on large pages, fixes #3473 *Shugo Maeda*
-
-* Detect missing_constants calls from removed modules and fail accordingly. *Nicholas Seckar*
-
-* Stop using defined? in Dependencies.qualified_const_defined? since defined? may invoke const_missing. *Nicholas Seckar*
-
-* Dependencies can autoload directories of nested classes. *Jeremy Kemper*
- Example:
- invoice.rb class Invoice
- invoice/lineitem.rb class Invoice::Lineitem
-
-* Add Deprecation.silence so that Reloadable does not scold itself. *Nicholas Seckar*
-
-* Add debugging logging to Dependencies. Currently can be enabled with Dependencies.log_activity = true; adding to Initializer and documenting is forthcoming. *Nicholas Seckar*
-
-* Replace Reloadable with improvements to the Dependencies mechanism. *Nicholas Seckar*
-
-* DateTime#to_time gives hour/minute/second resolution. #5747 *jon.evans@pobox.com*
-
-* attr_internal to support namespacing and deprecation. Like attr_* except backed by internally-named instance variable. Set attr_internal_naming_format to change the format from the default '@_%s'. *Jeremy Kemper*
- # def foo() @foo__rofl end
- # def foo=(v) @foo__rofl = v end
- self.attr_internal_naming_format = '@%s__rofl'
- attr_internal :foo
-
-* Raise fully qualified names upon name errors. #5533 *Lars Pind, Nicholas Seckar*
-
-* Add extention to obtain the missing constant from NameError instances. *Nicholas Seckar*
-
-* Thoroughly document inflections. #5700 *petermichaux@gmail.com*
-
-* Added Module#alias_attribute [Jamis/David Heinemeier Hansson]. Example:
-
- class Content < ActiveRecord::Base
- # has a title attribute
- end
-
- class Email < ActiveRecord::Base
- alias_attribute :subject, :title
- end
-
- e = Email.find(1)
- e.title # => "Superstars"
- e.subject # => "Superstars"
- e.subject? # => true
- e.subject = "Megastars"
- e.title # => "Megastars"
-
-* Deprecation: easier to work with warning behavior as procs; default behaviors for each environment so users needn't update env.rb; and testing pleasure with assert_deprecated, assert_not_deprecated. *Jeremy Kemper*
- By default, test prints to $stderr, dev logs, production ignores.
- Provide your own per-environment in e.g. config/environments/development.rb:
- ActiveSupport::Deprecation.behavior = Proc.new { |message| raise message }
-
-* First cut of the Rails Deprecation system. *Michael Koziarski*
-
-* Strip boolean XML content before checking for 'true' *Rick Olson*
-
-* Customize default BigDecimal formatting. References #5672 *Dave Thomas*
-
-* Correctly convert <foo nil="true"> to nil when using Hash.create_from_xml. *Rick Olson*
-
-* Optional identity for Enumerable#sum defaults to zero. #5657 *gensym@mac.com*
-
-* HashWithIndifferentAccess shouldn't confuse false and nil. #5601 *Shugo Maeda*
-
-* Fixed HashWithIndifferentAccess#default #5586 *chris@seagul.co.uk*
-
-* More compatible Hash.create_from_xml. #5523 *nunemaker@gmail.com*
-
-* Added Enumerable#sum for calculating a sum from the elements [David Heinemeier Hansson, jonathan@daikini.com]. Examples:
-
- [1, 2, 3].sum
- payments.sum { |p| p.price * p.tax_rate }
- payments.sum(&:price)
-
- This is instead of payments.inject(0) { |sum, p| sum + p.price }
-
-* Correct and clarify Array#to_sentence docs. #5458 *brad@madriska.com*
-
-* alias_method_chain preserves method punctuation so foo, foo?, and foo! may be chained with the same feature. *Jeremy Kemper*
- Example:
- alias_method_chain :save!, :validation
- is equivalent to
- alias_method :save_without_validation!, :save!
- alias_method :save!, :save_with_validation!
-
-* Enhance Symbol#to_proc so it works with list objects, such as multi-dimensional arrays. Closes #5295 [nov@yo.rim.or.jp]. Example:
-
- {1 => "one", 2 => "two", 3 => "three"}.sort_by(&:first).map(&:last)
- # => ["one", "two", "three"]
-
-* Added Hash.create_from_xml(string) which will create a hash from a XML string and even typecast if possible [David Heinemeier Hansson]. Example:
-
- Hash.create_from_xml <<-EOT
- <note>
- <title>This is a note</title>
- <created-at type="date">2004-10-10</created-at>
- </note>
- EOT
-
- ...would return:
-
- { :note => { :title => "This is a note", :created_at => Date.new(2004, 10, 10) } }
-
-* Added Jim Weirich's excellent FlexMock class to vendor (Copyright 2003, 2004 by Jim Weirich (jim@weriichhouse.org)) -- it's not automatically required, though, so require 'flexmock' is still necessary *David Heinemeier Hansson*
-
-* Fixed that Module#alias_method_chain should work with both foo? foo! and foo at the same time #4954 *anna@wota.jp*
-
-* to_xml fixes, features, and speedup: introduce :dasherize option that converts updated_at to updated-at if true (the existing default); binary columns get encoding="base64" attribute; nil values get nil="true" attribute to distinguish empty values; add type information for float columns; allow arbitrarily deep :include; include SQL type information as the type attribute. #4989 *Blair Zajac <blair@orcaware.com>*
-
-* Add OrderedHash#values. *Sam Stephenson*
-
-* Added Array#to_s(:db) that'll produce a comma-separated list of ids [David Heinemeier Hansson]. Example:
-
- Purchase.find(:all, :conditions => "product_id IN (#{shops.products.to_s(:db)})"
-
-* Normalize classify's argument to a String so that it plays nice with Symbols. *Marcel Molina Jr.*
-
-* Strip out leading schema name in classify. References #5139. *Michael Schoen*
-
-* Remove Enumerable#first_match since break(value) handles the use case well enough. *Nicholas Seckar*
-
- Enumerable#first_match was like detect, but instead of returning the matching element, the yielded value returned. For example:
-
- user_xml = adapters(:from => User, :to => Xml).first_match do |adapter|
- adapter.adapt @user
- end
-
- But this is just as easily done with:
-
- user_xml = adapters(:from => User, :to => Xml).each do
- break adapter.adapt(@user)
- end
-
-* Make Array#in_groups_of just return the grouped collection if a block isn't given. *Marcel Molina Jr.*
-
-* Don't destroy a HashWithIndifferentAccess if symbolize_keys! or stringify_keys! is called on it. Closes #5076. *Marcel Molina Jr., guy.naor@famundo.com*
-
-* Document Module::delegate. #5002 *pergesu@gmail.com*
-
-* Replace alias method chaining with Module#alias_method_chain. *Marcel Molina Jr.*
-
-* Strip out punctuation on predicates or bang methods being aliased with alias_method_chain since target?_without_feature is not a valid method name. Add tests for Module#alias_method_chain. *Marcel Molina Jr.*
-
-* Replace Ruby's deprecated append_features in favor of included. *Marcel Molina Jr.*
-
-* Allow default options in with_options to be overridden. Closes #4480. *murphy@cYcnus.de*
-
-* Added Module#alias_method_chain *Jamis Buck*
-
-* Updated to Builder 2.0 *David Heinemeier Hansson*
-
-* Add Array#split for dividing arrays into one or more subarrays by value or block. *Sam Stephenson*
-
-## 1.3.1 (April 6th, 2006) ##
-
-* Clean paths inside of exception messages and traces. *Nicholas Seckar*
-
-* Add Pathname.clean_within for cleaning all the paths inside of a string. *Nicholas Seckar*
-
-* provide an empty Dependencies::LoadingModule.load which prints deprecation warnings. Lets 1.0 applications function with .13-style environment.rb.
-
-
-## 1.3.0 (March 27th, 2006) ##
-
-* When possible, avoid incorrectly obtaining constants from parent modules. Fixes #4221. *Nicholas Seckar*
-
-* Add more tests for dependencies; refactor existing cases. *Nicholas Seckar*
-
-* Move Module#parent and Module#as_load_path into core_ext. Add Module#parent. *Nicholas Seckar*
-
-* Add CachingTools::HashCaching to simplify the creation of nested, autofilling hashes. *Nicholas Seckar*
-
-* Remove a hack intended to avoid unloading the same class twice, but which would not work anyways. *Nicholas Seckar*
-
-* Update Object.subclasses_of to locate nested classes. This affects Object.remove_subclasses_of in that nested classes will now be unloaded. *Nicholas Seckar*
-
-* Update Object.remove_subclasses_of to use Class.remove_class, reducing duplication. *Nicholas Seckar*
-
-* Added Fixnum#seconds for consistency, so you can say 5.minutes + 30.seconds instead of 5.minutes + 30 #4389 *François Beausoleil*
-
-* Added option to String#camelize to generate lower-cased camel case by passing in :lower, like "super_man".camelize(:lower) # => "superMan" *David Heinemeier Hansson*
-
-* Added Hash#diff to show the difference between two hashes *Chris McGrath*
-
-* Added Time#advance to do precise time time calculations for cases where a month being approximated to 30 days won't do #1860 *Rick Olson*
-
-* Enhance Inflector.underscore to convert '-' into '_' (as the inverse of Inflector.dasherize) *Jamis Buck*
-
-* Switched to_xml to use the xml schema format for datetimes. This allows the encoding of time zones and should improve operability. *Michael Koziarski*
-
-* Added a note to the documentation for the Date related Numeric extensions to indicate that they're
- approximations and shouldn't be used for critical calculations. *Michael Koziarski*
-
-* Added Hash#to_xml and Array#to_xml that makes it much easier to produce XML from basic structures [David Heinemeier Hansson]. Examples:
-
- { :name => "David", :street_name => "Paulina", :age => 26, :moved_on => Date.new(2005, 11, 15) }.to_xml
-
- ...returns:
-
- <person>
- <street-name>Paulina</street-name>
- <name>David</name>
- <age type="integer">26</age>
- <moved-on type="date">2005-11-15</moved-on>
- </person>
-
-* Moved Jim Weirich's wonderful Builder from Action Pack to Active Support (it's simply too useful to be stuck in AP) *David Heinemeier Hansson*
-
-* Fixed that Array#to_sentence will return "" on an empty array instead of ", and" #3842, #4031 *rubyonrails@beautifulpixel.com*
-
-* Add Enumerable#group_by for grouping collections based on the result of some
- block. Useful, for example, for grouping records by date.
-
- ex.
-
- latest_transcripts.group_by(&:day).each do |day, transcripts|
- p "#{day} -> #{transcripts.map(&:class) * ', '}"
- end
- "2006-03-01 -> Transcript"
- "2006-02-28 -> Transcript"
- "2006-02-27 -> Transcript, Transcript"
- "2006-02-26 -> Transcript, Transcript"
-
- Add Array#in_groups_of, for iterating over an array in groups of a certain
- size.
-
- ex.
-
- %w(1 2 3 4 5 6 7).in_groups_of(3) {|g| p g}
- ["1", "2", "3"]
- ["4", "5", "6"]
- ["7", nil, nil]
-
- *Marcel Molina Jr., Sam Stephenson*
-
-* Added Kernel#daemonize to turn the current process into a daemon that can be killed with a TERM signal *David Heinemeier Hansson*
-
-* Add 'around' methods to Logger, to make it easy to log before and after messages for a given block as requested in #3809. [Michael Koziarski] Example:
-
- logger.around_info("Start rendering component (#{options.inspect}): ",
- "\n\nEnd of component rendering") { yield }
-
-* Added Time#beginning_of_quarter #3607 *cohen.jeff@gmail.com*
-
-* Fix Object.subclasses_of to only return currently defined objects *Jonathan Viney <jonathan@bluewire.net.nz>*
-
-* Fix constantize to properly handle names beginning with '::'. *Nicholas Seckar*
-
-* Make String#last return the string instead of nil when it is shorter than the limit [Scott Barron].
-
-* Added delegation support to Module that allows multiple delegations at once (unlike Forwardable in the stdlib) [David Heinemeier Hansson]. Example:
-
- class Account < ActiveRecord::Base
- has_one :subscription
- delegate :free?, :paying?, :to => :subscription
- delegate :overdue?, :to => "subscription.last_payment"
- end
-
- account.free? # => account.subscription.free?
- account.overdue? # => account.subscription.last_payment.overdue?
-
-* Fix Reloadable to handle the case where a class that has been 'removed' has not yet been garbage collected. *Nicholas Seckar*
-
-* Don't allow Reloadable to be included into Modules.
-
-* Remove LoadingModule. *Nicholas Seckar*
-
-* Add documentation for Reloadable::Subclasses. *Nicholas Seckar*
-
-* Add Reloadable::Subclasses which handles the common case where a base class should not be reloaded, but its subclasses should be. *Nicholas Seckar*
-
-* Further improvements to reloading code *Nicholas Seckar, Trevor Squires*
-
- - All classes/modules which include Reloadable can define reloadable? for fine grained control of reloading
- - Class.remove_class uses Module#parent to access the parent module
- - Class.remove_class expanded to handle multiple classes in a single call
- - LoadingModule.clear! has been removed as it is no longer required
- - Module#remove_classes_including has been removed in favor of Reloadable.reloadable_classes
-
-* Added reusable reloading support through the inclusion of the Relodable module that all subclasses of ActiveRecord::Base, ActiveRecord::Observer, ActiveController::Base, and ActionMailer::Base automatically gets. This means that these classes will be reloaded by the dispatcher when Dependencies.mechanism = :load. You can make your own models reloadable easily:
-
- class Setting
- include Reloadable
- end
-
- Reloading a class is done by removing its constant which will cause it to be loaded again on the next reference. *David Heinemeier Hansson*
-
-* Added auto-loading support for classes in modules, so Conductor::Migration will look for conductor/migration.rb and Conductor::Database::Settings will look for conductor/database/settings.rb *Nicholas Seckar*
-
-* Add Object#instance_exec, like instance_eval but passes its arguments to the block. (Active Support will not override the Ruby 1.9 implementation of this method.) *Sam Stephenson*
-
-* Add Proc#bind(object) for changing a proc or block's self by returning a Method bound to the given object. Based on why the lucky stiff's "cloaker" method. *Sam Stephenson*
-
-* Fix merge and dup for hashes with indifferent access #3404 *Ken Miller*
-
-* Fix the requires in option_merger_test to unbreak AS tests. *Sam Stephenson*
-
-* Make HashWithIndifferentAccess#update behave like Hash#update by returning the hash. #3419, #3425 *asnem@student.ethz.ch, JanPrill@blauton.de, Marcel Molina Jr.*
-
-* Add ActiveSupport::JSON and Object#to_json for converting Ruby objects to JSON strings. *Sam Stephenson*
-
-* Add Object#with_options for DRYing up multiple calls to methods having shared options. [Sam Stephenson] Example:
-
- ActionController::Routing::Routes.draw do |map|
- # Account routes
- map.with_options(:controller => 'account') do |account|
- account.home '', :action => 'dashboard'
- account.signup 'signup', :action => 'new'
- account.logout 'logout', :action => 'logout'
- end
- end
-
-* Introduce Dependencies.warnings_on_first_load setting. If true, enables warnings on first load of a require_dependency. Otherwise, loads without warnings. Disabled (set to false) by default. *Jeremy Kemper*
-
-* Active Support is warnings-safe. #1792 *Eric Hodel*
-
-* Introduce enable_warnings counterpart to silence_warnings. Turn warnings on when loading a file for the first time if Dependencies.mechanism == :load. Common mistakes such as redefined methods will print warnings to stderr. *Jeremy Kemper*
-
-* Add Symbol#to_proc, which allows for, e.g. [:foo, :bar].map(&:to_s). *Marcel Molina Jr.*
-
-* Added the following methods [Marcel Molina Jr., Sam Stephenson]:
- * Object#copy_instance_variables_from(object) to copy instance variables from one object to another
- * Object#extended_by to get an instance's included/extended modules
- * Object#extend_with_included_modules_from(object) to extend an instance with the modules from another instance
-
-## 1.2.5 (December 13th, 2005) ##
-
-* Become part of Rails 1.0
-
-* Rename Version constant to VERSION. #2802 *Marcel Molina Jr.*
-
-## 1.2.3 (November 7th, 2005) ##
-
-* Change Inflector#constantize to use eval instead of const_get. *Nicholas Seckar*
-
-* Fix const_missing handler to ignore the trailing '.rb' on files when comparing paths. *Nicholas Seckar*
-
-* Define kernel.rb methods in "class Object" instead of "module Kernel" to work around a Windows peculiarity *Sam Stephenson*
-
-* Fix broken tests caused by incomplete loading of active support. *Nicholas Seckar*
-
-* Fix status pluralization bug so status_codes doesn't get pluralized as statuses_code. #2758 *keithm@infused.org*
-
-* Added Kernel#silence_stderr to silence stderr for the duration of the given block *Sam Stephenson*
-
-* Changed Kernel#` to print a message to stderr (like Unix) instead of raising Errno::ENOENT on Win32 *Sam Stephenson*
-
-* Changed 0.blank? to false rather than true since it violates everyone's expectation of blankness. #2518, #2705 *rails@jeffcole.net*
-
-* When loading classes using const_missing, raise a NameError if and only if the file we tried to load was not present. *Nicholas Seckar*
-
-* Added petabytes and exebytes to numeric extensions #2397 *timct@mac.com*
-
-* Added Time#end_of_month to accompany Time#beginning_of_month #2514 *Jens-Christian Fischer*
-
-
-## 1.2.2 (October 26th, 2005) ##
-
-* Set Logger.silencer = false to disable Logger#silence. Useful for debugging fixtures.
-
-* Add title case method to String to do, e.g., 'action_web_service'.titlecase # => 'Action Web Service'. *Marcel Molina Jr.*
-
-
-## 1.2.1 (October 19th, 2005) ##
-
-* Classify generated routing code as framework code to avoid appearing in application traces. *Nicholas Seckar*
-
-* Show all framework frames in the framework trace. *Nicholas Seckar*
-
-
-## 1.2.0 (October 16th, 2005) ##
-
-* Update Exception extension to show the first few framework frames in an application trace. *Nicholas Seckar*
-
-* Added Exception extension to provide support for clean backtraces. *Nicholas Seckar*
-
-* Updated whiny nil to be more concise and useful. *Nicholas Seckar*
-
-* Added Enumerable#first_match *Nicholas Seckar*
-
-* Fixed that Time#change should also reset usec when also resetting minutes #2459 *ikeda@dream.big.or.jp*
-
-* Fix Logger compatibility for distributions that don't keep Ruby and its standard library in sync.
-
-* Replace '%e' from long and short time formats as Windows does not support it. #2344. *Tom Ward <tom@popdog.net>*
-
-* Added to_s(:db) to Range, so you can get "BETWEEN '2005-12-10' AND '2005-12-12'" from Date.new(2005, 12, 10)..Date.new(2005, 12, 12) (and likewise with Times)
-
-* Moved require_library_or_gem into Kernel. #1992 *Michael Schuerig <michael@schuerig.de>*
-
-* Add :rfc822 as an option for Time#to_s (to get rfc822-formatted times)
-
-* Chain the const_missing hook to any previously existing hook so rails can play nicely with rake
-
-* Clean logger is compatible with both 1.8.2 and 1.8.3 Logger. #2263 *Michael Schuerig <michael@schuerig.de>*
-
-* Added native, faster implementations of .blank? for the core types #2286 *skae*
-
-* Fixed clean logger to work with Ruby 1.8.3 Logger class #2245
-
-* Fixed memory leak with Active Record classes when Dependencies.mechanism = :load #1704 *Chris McGrath*
-
-* Fixed Inflector.underscore for use with acronyms, so HTML becomes html instead of htm_l #2173 *k@v2studio.com*
-
-* Fixed dependencies related infinite recursion bug when a controller file does not contain a controller class. Closes #1760. *rcolli2@tampabay.rr.com*
-
-* Fixed inflections for status, quiz, move #2056 *deirdre@deirdre.net*
-
-* Added Hash#reverse_merge, Hash#reverse_merge!, and Hash#reverse_update to ease the use of default options
-
-* Added Array#to_sentence that'll turn ['one', 'two', 'three'] into "one, two, and three" #2157 *Manfred Stienstra*
-
-* Added Kernel#silence_warnings to turn off warnings temporarily for the passed block
-
-* Added String#starts_with? and String#ends_with? #2118 *Thijs van der Vossen*
-
-* Added easy extendability to the inflector through Inflector.inflections (using the Inflector::Inflections singleton class). Examples:
-
- Inflector.inflections do |inflect|
- inflect.plural /^(ox)$/i, '\1\2en'
- inflect.singular /^(ox)en/i, '\1'
-
- inflect.irregular 'octopus', 'octopi'
-
- inflect.uncountable "equipment"
- end
-
-* Added String#at, String#from, String#to, String#first, String#last in ActiveSupport::CoreExtensions::String::Access to ease access to individual characters and substrings in a string serving basically as human names for range access.
-
-* Make Time#last_month work when invoked on the 31st of a month.
-
-* Add Time.days_in_month, and make Time#next_month work when invoked on the 31st of a month
-
-* Fixed that Time#midnight would have a non-zero usec on some platforms #1836
-
-* Fixed inflections of "index/indices" #1766 *damn_pepe@gmail.com*
-
-* Added stripping of _id to String#humanize, so "employee_id" becomes "Employee" #1574 *Justin French*
-
-* Factor Fixnum and Bignum extensions into Integer extensions *Nicholas Seckar*
-
-* Hooked #ordinalize into Fixnum and Bignum classes. *Nicholas Seckar, danp*
-
-* Added Fixnum#ordinalize to turn 1.ordinalize to "1st", 3.ordinalize to "3rd", and 10.ordinalize to "10th" and so on #1724 *paul@cnt.org*
-
-
-## 1.1.1 (11 July, 2005) ##
-
-* Added more efficient implementation of the development mode reset of classes #1638 *Chris McGrath*
-
-
-## 1.1.0 (6 July, 2005) ##
-
-* Fixed conflict with Glue gem #1606 *Rick Olson*
-
-* Added new rules to the Inflector to deal with more unusual plurals mouse/louse => mice/lice, information => information, ox => oxen, virus => viri, archive => archives #1571, #1583, #1490, #1599, #1608 *foamdino@gmail.com/others*
-
-* Fixed memory leak with Object#remove_subclasses_of, which inflicted a Rails application running in development mode with a ~20KB leak per request #1289 *Chris McGrath*
-
-* Made 1.year == 365.25.days to account for leap years. This allows you to do User.find(:all, :conditions => ['birthday > ?', 50.years.ago]) without losing a lot of days. #1488 *tuxie@dekadance.se*
-
-* Added an exception if calling id on nil to WhinyNil #584 *kevin-temp@writesoon.com*
-
-* Added Fix/Bignum#multiple_of? which returns true on 14.multiple_of?(7) and false on 16.multiple_of?(7) #1464 *Thomas Fuchs*
-
-* Added even? and odd? to work with Bignums in addition to Fixnums #1464 *Thomas Fuchs*
-
-* Fixed Time#at_beginning_of_week returned the next Monday instead of the previous one when called on a Sunday #1403 *jean.helou@gmail.com*
-
-* Increased the speed of indifferent hash access by using Hash#default. #1436 *Nicholas Seckar*
-
-* Added that " " is now also blank? (using strip if available)
-
-* Fixed Dependencies so all modules are able to load missing constants #1173 *Nicholas Seckar*
-
-* Fixed the Inflector to underscore strings containing numbers, so Area51Controller becomes area51_controller #1176 *Nicholas Seckar*
-
-* Fixed that HashWithIndifferentAccess stringified all keys including symbols, ints, objects, and arrays #1162 *Nicholas Seckar*
-
-* Fixed Time#last_year to go back in time, not forward #1278 *fabien@odilat.com*
-
-* Fixed the pluralization of analysis to analyses #1295 *seattle@rootimage.msu.edu*
-
-* Fixed that Time.local(2005,12).months_since(1) would raise "ArgumentError: argument out of range" #1311 *jhahn@niveon.com*
-
-* Added silencing to the default Logger class
-
-
-## 1.0.4 (19th April, 2005) ##
-
-* Fixed that in some circumstances controllers outside of modules may have hidden ones inside modules. For example, admin/content might have been hidden by /content. #1075 *Nicholas Seckar*
-
-* Fixed inflection of perspectives and similar words #1045 *Thijs van der Vossen*
-
-* Added Fixnum#even? and Fixnum#odd?
-
-* Fixed problem with classes being required twice. Object#const_missing now uses require_dependency to load files. It used to use require_or_load which would cause models to be loaded twice, which was not good for validations and other class methods #971 *Nicholas Seckar*
-
-
-## 1.0.3 (27th March, 2005) ##
-
-* Fixed Inflector.pluralize to handle capitalized words #932 *Jeremy Kemper*
-
-* Added Object#suppress which allows you to make a saner choice around with exceptions to swallow #980. Example:
-
- suppress(ZeroDivisionError) { 1/0 }
-
- ...instead of:
-
- 1/0 rescue nil # BAD, EVIL, DIRTY.
-
-
-## 1.0.2 (22th March, 2005) ##
-
-* Added Kernel#returning -- a Ruby-ized realization of the K combinator, courtesy of Mikael Brockman.
-
- def foo
- returning values = [] do
- values << 'bar'
- values << 'baz'
- end
- end
-
- foo # => ['bar', 'baz']
-
-
-## 1.0.1 (7th March, 2005) ##
-
-* Fixed Hash#indifferent_access to also deal with include? and fetch and nested hashes #726 *Nicholas Seckar*
-
-* Added Object#blank? -- see http://redhanded.hobix.com/inspect/objectBlank.html #783 *_why the lucky stiff*
-
-* Added inflection rules for "sh" words, like "wish" and "fish" #755 *phillip@pjbsoftware.com*
-
-* Fixed an exception when using Ajax based requests from Safari because Safari appends a \000 to the post body. Symbols can't have \000 in them so indifferent access would throw an exception in the constructor. Indifferent hashes now use strings internally instead. #746 *Tobias Lütke*
-
-* Added String#to_time and String#to_date for wrapping ParseDate
-
-
-## 1.0.0 (24th February, 2005) ##
-
-* Added TimeZone as the first of a number of value objects that among others Active Record can use rich value objects using composed_of #688 *Jamis Buck*
-
-* Added Date::Conversions for getting dates in different convenient string representations and other objects
-
-* Added Time::Conversions for getting times in different convenient string representations and other objects
-
-* Added Time::Calculations to ask for things like Time.now.tomorrow, Time.now.yesterday, Time.now.months_ago(4) #580 [DP|Flurin]. Examples:
-
- "Later today" => now.in(3.hours),
- "Tomorrow morning" => now.tomorrow.change(:hour => 9),
- "Tomorrow afternoon" => now.tomorrow.change(:hour => 14),
- "In a couple of days" => now.tomorrow.tomorrow.change(:hour => 9),
- "Next monday" => now.next_week.change(:hour => 9),
- "In a month" => now.next_month.change(:hour => 9),
- "In 6 months" => now.months_since(6).change(:hour => 9),
- "In a year" => now.in(1.year).change(:hour => 9)
-
-* Upgraded to breakpoint 92 which fixes:
-
- * overload IRB.parse_opts(), fixes #443
- => breakpoints in tests work even when running them via rake
- * untaint handlers, might fix an issue discussed on the Rails ML
- * added verbose mode to breakpoint_client
- * less noise caused by breakpoint_client by default
- * ignored TerminateLineInput exception in signal handler
- => quiet exit on Ctrl-C
-
-* Fixed Inflector for words like "news" and "series" that are the same in plural and singular #603 [echion], #615 *marcenuc*
-
-* Added Hash#stringify_keys and Hash#stringify_keys!
-
-* Added IndifferentAccess as a way to wrap a hash by a symbol-based store that also can be accessed by string keys
-
-* Added Inflector.constantize to turn "Admin::User" into a reference for the constant Admin::User
-
-* Added that Inflector.camelize and Inflector.underscore can deal with modules like turning "Admin::User" into "admin/user" and back
-
-* Added Inflector.humanize to turn attribute names like employee_salary into "Employee salary". Used by automated error reporting in AR.
-
-* Added availability of class inheritable attributes to the masses #477 *Jeremy Kemper*
-
- class Foo
- class_inheritable_reader :read_me
- class_inheritable_writer :write_me
- class_inheritable_accessor :read_and_write_me
- class_inheritable_array :read_and_concat_me
- class_inheritable_hash :read_and_update_me
- end
-
- # Bar gets a clone of (not a reference to) Foo's attributes.
- class Bar < Foo
- end
-
- Bar.read_and_write_me == Foo.read_and_write_me
- Bar.read_and_write_me = 'bar'
- Bar.read_and_write_me != Foo.read_and_write_me
-
-* Added Inflections as an extension on String, so Inflector.pluralize(Inflector.classify(name)) becomes name.classify.pluralize #476 *Jeremy Kemper*
-
-* Added Byte operations to Numeric, so 5.5.megabytes + 200.kilobytes #461 *Marcel Molina Jr.*
-
-* Fixed that Dependencies.reload can't load the same file twice #420 *Kent Sibilev*
-
-* Added Fixnum#ago/until, Fixnum#since/from_now #450 *Jeremy Kemper*
-
-* Added that Inflector now accepts Symbols and Classes by calling .to_s on the word supplied
-
-* Added time unit extensions to Fixnum that'll return the period in seconds, like 2.days + 4.hours.
+Please check [3-2-stable](https://github.com/rails/rails/blob/3-2-stable/activesupport/CHANGELOG.md) for previous changes.
diff --git a/activesupport/lib/active_support.rb b/activesupport/lib/active_support.rb
index 56d6676961..41d77ab6c1 100644
--- a/activesupport/lib/active_support.rb
+++ b/activesupport/lib/active_support.rb
@@ -37,7 +37,6 @@ module ActiveSupport
autoload :LogSubscriber
autoload :Notifications
- # TODO: Narrow this list down
eager_autoload do
autoload :BacktraceCleaner
autoload :BasicObject
@@ -55,12 +54,12 @@ module ActiveSupport
autoload :OptionMerger
autoload :OrderedHash
autoload :OrderedOptions
- autoload :Rescuable
autoload :StringInquirer
autoload :TaggedLogging
autoload :XmlMini
end
+ autoload :Rescuable
autoload :SafeBuffer, "active_support/core_ext/string/output_safety"
autoload :TestCase
end
diff --git a/activesupport/lib/active_support/cache/file_store.rb b/activesupport/lib/active_support/cache/file_store.rb
index 5be63af342..2c1ad60d44 100644
--- a/activesupport/lib/active_support/cache/file_store.rb
+++ b/activesupport/lib/active_support/cache/file_store.rb
@@ -1,6 +1,5 @@
require 'active_support/core_ext/file/atomic'
require 'active_support/core_ext/string/conversions'
-require 'active_support/core_ext/object/inclusion'
require 'uri/common'
module ActiveSupport
@@ -23,7 +22,7 @@ module ActiveSupport
end
def clear(options = nil)
- root_dirs = Dir.entries(cache_path).reject{|f| f.in?(EXCLUDED_DIRS + [".gitkeep"])}
+ root_dirs = Dir.entries(cache_path).reject {|f| (EXCLUDED_DIRS + [".gitkeep"]).include?(f)}
FileUtils.rm_r(root_dirs.collect{|f| File.join(cache_path, f)})
end
@@ -151,7 +150,7 @@ module ActiveSupport
# Delete empty directories in the cache.
def delete_empty_directories(dir)
return if dir == cache_path
- if Dir.entries(dir).reject{|f| f.in?(EXCLUDED_DIRS)}.empty?
+ if Dir.entries(dir).reject {|f| EXCLUDED_DIRS.include?(f)}.empty?
File.delete(dir) rescue nil
delete_empty_directories(File.dirname(dir))
end
@@ -165,7 +164,7 @@ module ActiveSupport
def search_dir(dir, &callback)
return if !File.exist?(dir)
Dir.foreach(dir) do |d|
- next if d.in?(EXCLUDED_DIRS)
+ next if EXCLUDED_DIRS.include?(d)
name = File.join(dir, d)
if File.directory?(name)
search_dir(name, &callback)
diff --git a/activesupport/lib/active_support/cache/mem_cache_store.rb b/activesupport/lib/active_support/cache/mem_cache_store.rb
index 2e1ccb72d8..5aa78cc9f3 100644
--- a/activesupport/lib/active_support/cache/mem_cache_store.rb
+++ b/activesupport/lib/active_support/cache/mem_cache_store.rb
@@ -1,7 +1,7 @@
begin
- require 'memcache'
+ require 'dalli'
rescue LoadError => e
- $stderr.puts "You don't have memcache-client installed in your application. Please add it to your Gemfile and run bundle install"
+ $stderr.puts "You don't have dalli installed in your application. Please add it to your Gemfile and run bundle install"
raise e
end
@@ -22,21 +22,13 @@ module ActiveSupport
# MemCacheStore implements the Strategy::LocalCache strategy which implements
# an in-memory cache inside of a block.
class MemCacheStore < Store
- module Response # :nodoc:
- STORED = "STORED\r\n"
- NOT_STORED = "NOT_STORED\r\n"
- EXISTS = "EXISTS\r\n"
- NOT_FOUND = "NOT_FOUND\r\n"
- DELETED = "DELETED\r\n"
- end
-
ESCAPE_KEY_CHARS = /[\x00-\x20%\x7F-\xFF]/n
def self.build_mem_cache(*addresses)
addresses = addresses.flatten
options = addresses.extract_options!
addresses = ["localhost:11211"] if addresses.empty?
- MemCache.new(addresses, options)
+ Dalli::Client.new(addresses, options)
end
# Creates a new MemCacheStore object, with the given memcached server
@@ -90,11 +82,11 @@ module ActiveSupport
# to zero.
def increment(name, amount = 1, options = nil) # :nodoc:
options = merged_options(options)
- response = instrument(:increment, name, :amount => amount) do
+ instrument(:increment, name, :amount => amount) do
@data.incr(escape_key(namespaced_key(name, options)), amount)
end
- response == Response::NOT_FOUND ? nil : response.to_i
- rescue MemCache::MemCacheError
+ rescue Dalli::DalliError
+ logger.error("DalliError (#{e}): #{e.message}") if logger
nil
end
@@ -104,11 +96,11 @@ module ActiveSupport
# to zero.
def decrement(name, amount = 1, options = nil) # :nodoc:
options = merged_options(options)
- response = instrument(:decrement, name, :amount => amount) do
+ instrument(:decrement, name, :amount => amount) do
@data.decr(escape_key(namespaced_key(name, options)), amount)
end
- response == Response::NOT_FOUND ? nil : response.to_i
- rescue MemCache::MemCacheError
+ rescue Dalli::DalliError
+ logger.error("DalliError (#{e}): #{e.message}") if logger
nil
end
@@ -116,6 +108,9 @@ module ActiveSupport
# be used with care when shared cache is being used.
def clear(options = nil)
@data.flush_all
+ rescue Dalli::DalliError => e
+ logger.error("DalliError (#{e}): #{e.message}") if logger
+ nil
end
# Get the statistics from the memcached servers.
@@ -126,9 +121,9 @@ module ActiveSupport
protected
# Read an entry from the cache.
def read_entry(key, options) # :nodoc:
- deserialize_entry(@data.get(escape_key(key), true))
- rescue MemCache::MemCacheError => e
- logger.error("MemCacheError (#{e}): #{e.message}") if logger
+ deserialize_entry(@data.get(escape_key(key), options))
+ rescue Dalli::DalliError => e
+ logger.error("DalliError (#{e}): #{e.message}") if logger
nil
end
@@ -137,23 +132,17 @@ module ActiveSupport
method = options && options[:unless_exist] ? :add : :set
value = options[:raw] ? entry.value.to_s : entry
expires_in = options[:expires_in].to_i
- if expires_in > 0 && !options[:raw]
- # Set the memcache expire a few minutes in the future to support race condition ttls on read
- expires_in += 5.minutes
- end
- response = @data.send(method, escape_key(key), value, expires_in, options[:raw])
- response == Response::STORED
- rescue MemCache::MemCacheError => e
- logger.error("MemCacheError (#{e}): #{e.message}") if logger
+ @data.send(method, escape_key(key), value, expires_in, options)
+ rescue Dalli::DalliError => e
+ logger.error("DalliError (#{e}): #{e.message}") if logger
false
end
# Delete an entry from the cache.
def delete_entry(key, options) # :nodoc:
- response = @data.delete(escape_key(key))
- response == Response::DELETED
- rescue MemCache::MemCacheError => e
- logger.error("MemCacheError (#{e}): #{e.message}") if logger
+ @data.delete(escape_key(key))
+ rescue Dalli::DalliError => e
+ logger.error("DalliError (#{e}): #{e.message}") if logger
false
end
diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb
index 6cc875c69a..3f7d0e401a 100644
--- a/activesupport/lib/active_support/callbacks.rb
+++ b/activesupport/lib/active_support/callbacks.rb
@@ -3,7 +3,6 @@ require 'active_support/descendants_tracker'
require 'active_support/core_ext/class/attribute'
require 'active_support/core_ext/kernel/reporting'
require 'active_support/core_ext/kernel/singleton_class'
-require 'active_support/core_ext/object/inclusion'
module ActiveSupport
# \Callbacks are code hooks that are run at key points in an object's lifecycle.
@@ -78,7 +77,7 @@ module ActiveSupport
private
# A hook invoked everytime a before callback is halted.
- # This can be overriden in AS::Callback implementors in order
+ # This can be overridden in AS::Callback implementors in order
# to provide better debugging/logging.
def halted_callback_hook(filter)
end
@@ -353,7 +352,7 @@ module ActiveSupport
# CallbackChain.
#
def __update_callbacks(name, filters = [], block = nil) #:nodoc:
- type = filters.first.in?([:before, :after, :around]) ? filters.shift : :before
+ type = [:before, :after, :around].include?(filters.first) ? filters.shift : :before
options = filters.last.is_a?(Hash) ? filters.pop : {}
filters.unshift(block) if block
diff --git a/activesupport/lib/active_support/concurrency/latch.rb b/activesupport/lib/active_support/concurrency/latch.rb
new file mode 100644
index 0000000000..1507de433e
--- /dev/null
+++ b/activesupport/lib/active_support/concurrency/latch.rb
@@ -0,0 +1,27 @@
+require 'thread'
+require 'monitor'
+
+module ActiveSupport
+ module Concurrency
+ class Latch
+ def initialize(count = 1)
+ @count = count
+ @lock = Monitor.new
+ @cv = @lock.new_cond
+ end
+
+ def release
+ @lock.synchronize do
+ @count -= 1 if @count > 0
+ @cv.broadcast if @count.zero?
+ end
+ end
+
+ def await
+ @lock.synchronize do
+ @cv.wait_while { @count > 0 }
+ end
+ end
+ end
+ end
+end
diff --git a/activesupport/lib/active_support/core_ext/date.rb b/activesupport/lib/active_support/core_ext/date.rb
new file mode 100644
index 0000000000..465fedda80
--- /dev/null
+++ b/activesupport/lib/active_support/core_ext/date.rb
@@ -0,0 +1,5 @@
+require 'active_support/core_ext/date/acts_like'
+require 'active_support/core_ext/date/calculations'
+require 'active_support/core_ext/date/conversions'
+require 'active_support/core_ext/date/zones'
+
diff --git a/activesupport/lib/active_support/core_ext/date/calculations.rb b/activesupport/lib/active_support/core_ext/date/calculations.rb
index 7fe4161fb4..86badf4d29 100644
--- a/activesupport/lib/active_support/core_ext/date/calculations.rb
+++ b/activesupport/lib/active_support/core_ext/date/calculations.rb
@@ -3,17 +3,10 @@ require 'active_support/duration'
require 'active_support/core_ext/object/acts_like'
require 'active_support/core_ext/date/zones'
require 'active_support/core_ext/time/zones'
+require 'active_support/core_ext/date_and_time/calculations'
class Date
- DAYS_INTO_WEEK = {
- :monday => 0,
- :tuesday => 1,
- :wednesday => 2,
- :thursday => 3,
- :friday => 4,
- :saturday => 5,
- :sunday => 6
- }
+ include DateAndTime::Calculations
class << self
# Returns a new Date representing the date 1 day ago (i.e. yesterday's date).
@@ -32,21 +25,6 @@ class Date
end
end
- # Returns true if the Date object's date lies in the past. Otherwise returns false.
- def past?
- self < ::Date.current
- end
-
- # Returns true if the Date object's date is today.
- def today?
- to_date == ::Date.current # we need the to_date because of DateTime
- end
-
- # Returns true if the Date object's date lies in the future.
- def future?
- self > ::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)
@@ -106,6 +84,7 @@ class Date
end
# Returns a new Date where one or more of the elements have been changed according to the +options+ parameter.
+ # The +options+ parameter is a hash with a combination of these keys: <tt>:year</tt>, <tt>:month</tt>, <tt>:day</tt>.
#
# Date.new(2007, 5, 12).change(:day => 1) # => Date.new(2007, 5, 1)
# Date.new(2007, 5, 12).change(:year => 2005, :month => 1) # => Date.new(2005, 1, 12)
@@ -116,161 +95,4 @@ class Date
options.fetch(:day, day)
)
end
-
- # Returns a new Date/DateTime representing the time a number of specified weeks ago.
- def weeks_ago(weeks)
- advance(:weeks => -weeks)
- end
-
- # Returns a new Date/DateTime representing the time a number of specified months ago.
- def months_ago(months)
- advance(:months => -months)
- end
-
- # Returns a new Date/DateTime representing the time a number of specified months in the future.
- def months_since(months)
- advance(:months => months)
- end
-
- # Returns a new Date/DateTime representing the time a number of specified years ago.
- def years_ago(years)
- advance(:years => -years)
- end
-
- # Returns a new Date/DateTime representing the time a number of specified years in the future.
- def years_since(years)
- advance(:years => years)
- end
-
- # Returns number of days to start of this week. Week is assumed to start on
- # +start_day+, default is +:monday+.
- def days_to_week_start(start_day = :monday)
- start_day_number = DAYS_INTO_WEEK[start_day]
- current_day_number = wday != 0 ? wday - 1 : 6
- (current_day_number - start_day_number) % 7
- end
-
- # Returns a new +Date+/+DateTime+ representing the start of this week. Week is
- # assumed to start on +start_day+, default is +:monday+. +DateTime+ objects
- # have their time set to 0:00.
- def beginning_of_week(start_day = :monday)
- days_to_start = days_to_week_start(start_day)
- result = self - days_to_start
- acts_like?(:time) ? result.midnight : result
- end
- alias :at_beginning_of_week :beginning_of_week
-
- # Returns a new +Date+/+DateTime+ representing the start of this week. Week is
- # assumed to start on a Monday. +DateTime+ objects have their time set to 0:00.
- def monday
- beginning_of_week
- end
-
- # Returns a new +Date+/+DateTime+ representing the end of this week. Week is
- # assumed to start on +start_day+, default is +:monday+. +DateTime+ objects
- # have their time set to 23:59:59.
- def end_of_week(start_day = :monday)
- days_to_end = 6 - days_to_week_start(start_day)
- result = self + days_to_end.days
- acts_like?(:time) ? result.end_of_day : result
- end
- alias :at_end_of_week :end_of_week
-
- # Returns a new +Date+/+DateTime+ representing the end of this week. Week is
- # assumed to start on a Monday. +DateTime+ objects have their time set to 23:59:59.
- def sunday
- end_of_week
- end
-
- # Returns a new +Date+/+DateTime+ representing the given +day+ in the previous
- # week. Default is +:monday+. +DateTime+ objects have their time set to 0:00.
- def prev_week(day = :monday)
- result = (self - 7).beginning_of_week + DAYS_INTO_WEEK[day]
- acts_like?(:time) ? result.change(:hour => 0) : result
- end
- alias :last_week :prev_week
-
- # Alias of prev_month
- alias :last_month :prev_month
-
- # Alias of prev_year
- alias :last_year :prev_year
-
- # Returns a new Date/DateTime representing the start of the given day in next week (default is :monday).
- def next_week(day = :monday)
- result = (self + 7).beginning_of_week + DAYS_INTO_WEEK[day]
- acts_like?(:time) ? result.change(:hour => 0) : result
- end
-
- # Short-hand for months_ago(3)
- def prev_quarter
- months_ago(3)
- end
- alias_method :last_quarter, :prev_quarter
-
- # Short-hand for months_since(3)
- def next_quarter
- months_since(3)
- end
-
- # Returns a new Date/DateTime representing the start of the month (1st of the month; DateTime objects will have time set to 0:00)
- def beginning_of_month
- acts_like?(:time) ? change(:day => 1, :hour => 0) : change(:day => 1)
- end
- alias :at_beginning_of_month :beginning_of_month
-
- # Returns a new Date/DateTime representing the end of the month (last day of the month; DateTime objects will have time set to 0:00)
- def end_of_month
- last_day = ::Time.days_in_month(month, year)
- if acts_like?(:time)
- change(:day => last_day, :hour => 23, :min => 59, :sec => 59)
- else
- change(:day => last_day)
- end
- end
- alias :at_end_of_month :end_of_month
-
- # Returns a new Date/DateTime representing the start of the quarter (1st of january, april, july, october; DateTime objects will have time set to 0:00)
- def beginning_of_quarter
- first_quarter_month = [10, 7, 4, 1].detect { |m| m <= month }
- beginning_of_month.change(:month => first_quarter_month)
- end
- alias :at_beginning_of_quarter :beginning_of_quarter
-
- # Returns a new Date/DateTime representing the end of the quarter (last day of march, june, september, december; DateTime objects will have time set to 23:59:59)
- def end_of_quarter
- last_quarter_month = [3, 6, 9, 12].detect { |m| m >= month }
- beginning_of_month.change(:month => last_quarter_month).end_of_month
- end
- alias :at_end_of_quarter :end_of_quarter
-
- # Returns a new Date/DateTime representing the start of the year (1st of january; DateTime objects will have time set to 0:00)
- def beginning_of_year
- if acts_like?(:time)
- change(:month => 1, :day => 1, :hour => 0)
- else
- change(:month => 1, :day => 1)
- end
- end
- alias :at_beginning_of_year :beginning_of_year
-
- # Returns a new Time representing the end of the year (31st of december; DateTime objects will have time set to 23:59:59)
- def end_of_year
- if acts_like?(:time)
- change(:month => 12, :day => 31, :hour => 23, :min => 59, :sec => 59)
- else
- change(:month => 12, :day => 31)
- end
- end
- alias :at_end_of_year :end_of_year
-
- # Convenience method which returns a new Date/DateTime representing the time 1 day ago
- def yesterday
- self - 1
- end
-
- # Convenience method which returns a new Date/DateTime representing the time 1 day since the instance time
- def tomorrow
- self + 1
- end
end
diff --git a/activesupport/lib/active_support/core_ext/date_and_time/calculations.rb b/activesupport/lib/active_support/core_ext/date_and_time/calculations.rb
new file mode 100644
index 0000000000..e703fca7a7
--- /dev/null
+++ b/activesupport/lib/active_support/core_ext/date_and_time/calculations.rb
@@ -0,0 +1,213 @@
+module DateAndTime
+ module Calculations
+ DAYS_INTO_WEEK = {
+ :monday => 0,
+ :tuesday => 1,
+ :wednesday => 2,
+ :thursday => 3,
+ :friday => 4,
+ :saturday => 5,
+ :sunday => 6
+ }
+
+ # Returns a new date/time representing yesterday.
+ def yesterday
+ advance(:days => -1)
+ end
+
+ # Returns a new date/time representing tomorrow.
+ def tomorrow
+ advance(:days => 1)
+ end
+
+ # Returns true if the date/time is today.
+ def today?
+ to_date == ::Date.current
+ end
+
+ # Returns true if the date/time is in the past.
+ def past?
+ self < self.class.current
+ end
+
+ # Returns true if the date/time is in the future.
+ def future?
+ self > self.class.current
+ end
+
+ # Returns a new date/time the specified number of days ago.
+ def days_ago(days)
+ advance(:days => -days)
+ end
+
+ # Returns a new date/time the specified number of days in the future.
+ def days_since(days)
+ advance(:days => days)
+ end
+
+ # Returns a new date/time the specified number of weeks ago.
+ def weeks_ago(weeks)
+ advance(:weeks => -weeks)
+ end
+
+ # Returns a new date/time the specified number of weeks in the future.
+ def weeks_since(weeks)
+ advance(:weeks => weeks)
+ end
+
+ # Returns a new date/time the specified number of months ago.
+ def months_ago(months)
+ advance(:months => -months)
+ end
+
+ # Returns a new date/time the specified number of months in the future.
+ def months_since(months)
+ advance(:months => months)
+ end
+
+ # Returns a new date/time the specified number of years ago.
+ def years_ago(years)
+ advance(:years => -years)
+ end
+
+ # Returns a new date/time the specified number of years in the future.
+ def years_since(years)
+ advance(:years => years)
+ end
+
+ # Returns a new date/time at the start of the month.
+ # DateTime objects will have a time set to 0:00.
+ def beginning_of_month
+ first_hour{ change(:day => 1) }
+ end
+ alias :at_beginning_of_month :beginning_of_month
+
+ # Returns a new date/time at the start of the quarter.
+ # Example: 1st January, 1st July, 1st October.
+ # DateTime objects will have a time set to 0:00.
+ def beginning_of_quarter
+ first_quarter_month = [10, 7, 4, 1].detect { |m| m <= month }
+ beginning_of_month.change(:month => first_quarter_month)
+ end
+ alias :at_beginning_of_quarter :beginning_of_quarter
+
+ # Returns a new date/time at the end of the quarter.
+ # Example: 31st March, 30th June, 30th September.
+ # DateTIme objects will have a time set to 23:59:59.
+ def end_of_quarter
+ last_quarter_month = [3, 6, 9, 12].detect { |m| m >= month }
+ beginning_of_month.change(:month => last_quarter_month).end_of_month
+ end
+ alias :at_end_of_quarter :end_of_quarter
+
+ # Return a new date/time at the beginning of the year.
+ # Example: 1st January.
+ # DateTime objects will have a time set to 0:00.
+ def beginning_of_year
+ change(:month => 1).beginning_of_month
+ end
+ alias :at_beginning_of_year :beginning_of_year
+
+ # Returns a new date/time representing the given day in the next week.
+ # Default is :monday.
+ # DateTime objects have their time set to 0:00.
+ def next_week(day = :monday)
+ first_hour{ weeks_since(1).beginning_of_week.days_since(DAYS_INTO_WEEK[day]) }
+ end
+
+ # Short-hand for months_since(1).
+ def next_month
+ months_since(1)
+ end
+
+ # Short-hand for months_since(3)
+ def next_quarter
+ months_since(3)
+ end
+
+ # Short-hand for years_since(1).
+ def next_year
+ years_since(1)
+ end
+
+ # Returns a new date/time representing the given day in the previous week.
+ # Default is :monday.
+ # DateTime objects have their time set to 0:00.
+ def prev_week(day = :monday)
+ first_hour{ weeks_ago(1).beginning_of_week.days_since(DAYS_INTO_WEEK[day]) }
+ end
+ alias_method :last_week, :prev_week
+
+ # Short-hand for months_ago(1).
+ def prev_month
+ months_ago(1)
+ end
+ alias_method :last_month, :prev_month
+
+ # Short-hand for months_ago(3).
+ def prev_quarter
+ months_ago(3)
+ end
+ alias_method :last_quarter, :prev_quarter
+
+ # Short-hand for years_ago(1).
+ def prev_year
+ years_ago(1)
+ end
+ alias_method :last_year, :prev_year
+
+ # Returns the number of days to the start of the week on the given day.
+ # Default is :monday.
+ def days_to_week_start(start_day = :monday)
+ start_day_number = DAYS_INTO_WEEK[start_day]
+ current_day_number = wday != 0 ? wday - 1 : 6
+ (current_day_number - start_day_number) % 7
+ end
+
+ # Returns a new date/time representing the start of this week on the given day.
+ # Default is :monday.
+ # DateTime objects have their time set to 0:00.
+ def beginning_of_week(start_day = :monday)
+ result = days_ago(days_to_week_start(start_day))
+ acts_like?(:time) ? result.midnight : result
+ end
+ alias :at_beginning_of_week :beginning_of_week
+ alias :monday :beginning_of_week
+
+ # Returns a new date/time representing the end of this week on the given day.
+ # Default is :monday (i.e end of Sunday).
+ # DateTime objects have their time set to 23:59:59.
+ def end_of_week(start_day = :monday)
+ last_hour{ days_since(6 - days_to_week_start(start_day)) }
+ end
+ alias :at_end_of_week :end_of_week
+ alias :sunday :end_of_week
+
+ # Returns a new date/time representing the end of the month.
+ # DateTime objects will have a time set to 23:59:59.
+ def end_of_month
+ last_day = ::Time.days_in_month(month, year)
+ last_hour{ days_since(last_day - day) }
+ end
+ alias :at_end_of_month :end_of_month
+
+ # Returns a new date/time representing the end of the year.
+ # DateTime objects will have a time set to 23:59:59.
+ def end_of_year
+ change(:month => 12).end_of_month
+ end
+ alias :at_end_of_year :end_of_year
+
+ private
+
+ def first_hour
+ result = yield
+ acts_like?(:time) ? result.change(:hour => 0) : result
+ end
+
+ def last_hour
+ result = yield
+ acts_like?(:time) ? result.end_of_day : result
+ end
+ end
+end
diff --git a/activesupport/lib/active_support/core_ext/date_time.rb b/activesupport/lib/active_support/core_ext/date_time.rb
new file mode 100644
index 0000000000..e8a27b9f38
--- /dev/null
+++ b/activesupport/lib/active_support/core_ext/date_time.rb
@@ -0,0 +1,4 @@
+require 'active_support/core_ext/date_time/acts_like'
+require 'active_support/core_ext/date_time/calculations'
+require 'active_support/core_ext/date_time/conversions'
+require 'active_support/core_ext/date_time/zones'
diff --git a/activesupport/lib/active_support/core_ext/date_time/calculations.rb b/activesupport/lib/active_support/core_ext/date_time/calculations.rb
index fd78044b5d..5fb19f2e6e 100644
--- a/activesupport/lib/active_support/core_ext/date_time/calculations.rb
+++ b/activesupport/lib/active_support/core_ext/date_time/calculations.rb
@@ -31,8 +31,13 @@ class DateTime
end
# Returns a new DateTime where one or more of the elements have been changed according to the +options+ parameter. The time options
- # (hour, minute, sec) reset cascadingly, so if only the hour is passed, then minute and sec is set to 0. If the hour and
- # minute is passed, then sec is set to 0.
+ # (<tt>:hour</tt>, <tt>:minute</tt>, <tt>:sec</tt>) reset cascadingly, so if only the hour is passed, then minute and sec is set to 0. If the hour and
+ # minute is passed, then sec is set to 0. The +options+ parameter takes a hash with any of these keys: <tt>:year</tt>, <tt>:month</tt>, <tt>:day</tt>,
+ # <tt>:hour</tt>, <tt>:min</tt>, <tt>:sec</tt>, <tt>:offset</tt>, <tt>:start</tt>.
+ #
+ # DateTime.new(2012, 8, 29, 22, 35, 0).change(:day => 1) # => DateTime.new(2012, 8, 1, 22, 35, 0)
+ # DateTime.new(2012, 8, 29, 22, 35, 0).change(:year => 1981, :day => 1) # => DateTime.new(1981, 8, 1, 22, 35, 0)
+ # DateTime.new(2012, 8, 29, 22, 35, 0).change(:year => 1981, :hour => 0) # => DateTime.new(1981, 8, 29, 0, 0, 0)
def change(options)
::DateTime.civil(
options.fetch(:year, year),
diff --git a/activesupport/lib/active_support/core_ext/file/atomic.rb b/activesupport/lib/active_support/core_ext/file/atomic.rb
index 9e504851e7..81beb4e85d 100644
--- a/activesupport/lib/active_support/core_ext/file/atomic.rb
+++ b/activesupport/lib/active_support/core_ext/file/atomic.rb
@@ -1,3 +1,5 @@
+require 'fileutils'
+
class File
# Write to a file atomically. Useful for situations where you don't
# want other processes or threads to see half-written files.
@@ -25,17 +27,9 @@ class File
# Get original file permissions
old_stat = stat(file_name)
rescue Errno::ENOENT
- # No old permissions, write a temp file to determine the defaults
- temp_file_name = [
- '.permissions_check',
- Thread.current.object_id,
- Process.pid,
- rand(1000000)
- ].join('.')
- check_name = join(dirname(file_name), temp_file_name)
- open(check_name, 'w') { }
- old_stat = stat(check_name)
- unlink(check_name)
+ # If not possible, probe which are the default permissions in the
+ # destination directory.
+ old_stat = probe_stat_in(dirname(file_name))
end
# Overwrite original file with temp file
@@ -45,4 +39,20 @@ class File
chown(old_stat.uid, old_stat.gid, file_name)
chmod(old_stat.mode, file_name)
end
+
+ # Private utility method.
+ def self.probe_stat_in(dir) #:nodoc:
+ basename = [
+ '.permissions_check',
+ Thread.current.object_id,
+ Process.pid,
+ rand(1000000)
+ ].join('.')
+
+ file_name = join(dir, basename)
+ FileUtils.touch(file_name)
+ stat(file_name)
+ ensure
+ FileUtils.rm_f(file_name) if file_name
+ end
end
diff --git a/activesupport/lib/active_support/core_ext/object/to_param.rb b/activesupport/lib/active_support/core_ext/object/to_param.rb
index e5f81078ee..0d5f3501e5 100644
--- a/activesupport/lib/active_support/core_ext/object/to_param.rb
+++ b/activesupport/lib/active_support/core_ext/object/to_param.rb
@@ -6,18 +6,21 @@ class Object
end
class NilClass
+ # Returns +self+.
def to_param
self
end
end
class TrueClass
+ # Returns +self+.
def to_param
self
end
end
class FalseClass
+ # Returns +self+.
def to_param
self
end
@@ -35,12 +38,12 @@ class Hash
# Returns a string representation of the receiver suitable for use as a URL
# query string:
#
- # {:name => 'David', :nationality => 'Danish'}.to_param
+ # {name: 'David', nationality: 'Danish'}.to_param
# # => "name=David&nationality=Danish"
#
# An optional namespace can be passed to enclose the param names:
#
- # {:name => 'David', :nationality => 'Danish'}.to_param('user')
+ # {name: 'David', nationality: 'Danish'}.to_param('user')
# # => "user[name]=David&user[nationality]=Danish"
#
# The string pairs "key=value" that conform the query string
diff --git a/activesupport/lib/active_support/core_ext/object/try.rb b/activesupport/lib/active_support/core_ext/object/try.rb
index 16a799ec03..1079ddde98 100644
--- a/activesupport/lib/active_support/core_ext/object/try.rb
+++ b/activesupport/lib/active_support/core_ext/object/try.rb
@@ -5,6 +5,9 @@ class Object
# *Unlike* that method however, a +NoMethodError+ exception will *not* be raised
# and +nil+ will be returned instead, if the receiving object is a +nil+ object or NilClass.
#
+ # This is also true if the receiving object does not implemented the tried method. It will
+ # return +nil+ in that case as well.
+ #
# If try is called without a method to call, it will yield any given block with the object.
#
# Please also note that +try+ is defined on +Object+, therefore it won't work with
@@ -31,6 +34,16 @@ class Object
if a.empty? && block_given?
yield self
else
+ public_send(*a, &b) if respond_to?(a.first)
+ end
+ end
+
+ # Same as #try, but will raise a NoMethodError exception if the receiving is not nil and
+ # does not implemented the tried method.
+ def try!(*a, &b)
+ if a.empty? && block_given?
+ yield self
+ else
public_send(*a, &b)
end
end
@@ -50,4 +63,8 @@ class NilClass
def try(*args)
nil
end
+
+ def try!(*args)
+ nil
+ end
end
diff --git a/activesupport/lib/active_support/core_ext/string.rb b/activesupport/lib/active_support/core_ext/string.rb
index fb36262528..ad864765a3 100644
--- a/activesupport/lib/active_support/core_ext/string.rb
+++ b/activesupport/lib/active_support/core_ext/string.rb
@@ -10,3 +10,4 @@ require 'active_support/core_ext/string/output_safety'
require 'active_support/core_ext/string/exclude'
require 'active_support/core_ext/string/strip'
require 'active_support/core_ext/string/inquiry'
+require 'active_support/core_ext/string/indent'
diff --git a/activesupport/lib/active_support/core_ext/string/indent.rb b/activesupport/lib/active_support/core_ext/string/indent.rb
new file mode 100644
index 0000000000..afc3032272
--- /dev/null
+++ b/activesupport/lib/active_support/core_ext/string/indent.rb
@@ -0,0 +1,43 @@
+class String
+ # Same as +indent+, except it indents the receiver in-place.
+ #
+ # Returns the indented string, or +nil+ if there was nothing to indent.
+ def indent!(amount, indent_string=nil, indent_empty_lines=false)
+ indent_string = indent_string || self[/^[ \t]/] || ' '
+ re = indent_empty_lines ? /^/ : /^(?!$)/
+ gsub!(re, indent_string * amount)
+ end
+
+ # Indents the lines in the receiver:
+ #
+ # <<EOS.indent(2)
+ # def some_method
+ # some_code
+ # end
+ # EOS
+ # # =>
+ # def some_method
+ # some_code
+ # end
+ #
+ # The second argument, +indent_string+, specifies which indent string to
+ # use. The default is +nil+, which tells the method to make a guess by
+ # peeking at the first indented line, and fallback to a space if there is
+ # none.
+ #
+ # " foo".indent(2) # => " foo"
+ # "foo\n\t\tbar".indent(2) # => "\t\tfoo\n\t\t\t\tbar"
+ # "foo".indent(2, "\t") # => "\t\tfoo"
+ #
+ # While +indent_string+ is tipically one space or tab, it may be any string.
+ #
+ # The third argument, +indent_empty_lines+, is a flag that says whether
+ # empty lines should be indented. Default is false.
+ #
+ # "foo\n\nbar".indent(2) # => " foo\n\n bar"
+ # "foo\n\nbar".indent(2, nil, true) # => " foo\n \n bar"
+ #
+ def indent(amount, indent_string=nil, indent_empty_lines=false)
+ dup.tap {|_| _.indent!(amount, indent_string, indent_empty_lines)}
+ end
+end
diff --git a/activesupport/lib/active_support/core_ext/string/inflections.rb b/activesupport/lib/active_support/core_ext/string/inflections.rb
index efa2d43f20..6edfcd7493 100644
--- a/activesupport/lib/active_support/core_ext/string/inflections.rb
+++ b/activesupport/lib/active_support/core_ext/string/inflections.rb
@@ -13,6 +13,11 @@ class String
# the singular form will be returned if <tt>count == 1</tt>.
# For any other value of +count+ the plural will be returned.
#
+ # If the optional parameter +locale+ is specified,
+ # the word will be pluralized as a word of that language.
+ # By default, this parameter is set to <tt>:en</tt>.
+ # You must define your own inflection rules for languages other than English.
+ #
# 'post'.pluralize # => "posts"
# 'octopus'.pluralize # => "octopi"
# 'sheep'.pluralize # => "sheep"
@@ -21,15 +26,23 @@ class String
# 'CamelOctopus'.pluralize # => "CamelOctopi"
# 'apple'.pluralize(1) # => "apple"
# 'apple'.pluralize(2) # => "apples"
- def pluralize(count = nil)
+ # 'ley'.pluralize(:es) # => "leyes"
+ # 'ley'.pluralize(1, :es) # => "ley"
+ def pluralize(count = nil, locale = :en)
+ locale = count if count.is_a?(Symbol)
if count == 1
self
else
- ActiveSupport::Inflector.pluralize(self)
+ ActiveSupport::Inflector.pluralize(self, locale)
end
end
# The reverse of +pluralize+, returns the singular form of a word in a string.
+ #
+ # If the optional parameter +locale+ is specified,
+ # the word will be singularized as a word of that language.
+ # By default, this paramter is set to <tt>:en</tt>.
+ # You must define your own inflection rules for languages other than English.
#
# 'posts'.singularize # => "post"
# 'octopi'.singularize # => "octopus"
@@ -37,8 +50,9 @@ class String
# 'word'.singularize # => "word"
# 'the blue mailmen'.singularize # => "the blue mailman"
# 'CamelOctopi'.singularize # => "CamelOctopus"
- def singularize
- ActiveSupport::Inflector.singularize(self)
+ # 'leyes'.singularize(:es) # => "ley"
+ def singularize(locale = :en)
+ ActiveSupport::Inflector.singularize(self, locale)
end
# +constantize+ tries to find a declared constant with the name specified
diff --git a/activesupport/lib/active_support/core_ext/string/output_safety.rb b/activesupport/lib/active_support/core_ext/string/output_safety.rb
index 5226ff0cbe..dad4b29d46 100644
--- a/activesupport/lib/active_support/core_ext/string/output_safety.rb
+++ b/activesupport/lib/active_support/core_ext/string/output_safety.rb
@@ -3,9 +3,9 @@ require 'active_support/core_ext/kernel/singleton_class'
class ERB
module Util
- HTML_ESCAPE = { '&' => '&amp;', '>' => '&gt;', '<' => '&lt;', '"' => '&quot;' }
+ HTML_ESCAPE = { '&' => '&amp;', '>' => '&gt;', '<' => '&lt;', '"' => '&quot;', "'" => '&#x27;' }
JSON_ESCAPE = { '&' => '\u0026', '>' => '\u003E', '<' => '\u003C' }
- HTML_ESCAPE_ONCE_REGEXP = /[\"><]|&(?!([a-zA-Z]+|(#\d+));)/
+ HTML_ESCAPE_ONCE_REGEXP = /["><']|&(?!([a-zA-Z]+|(#\d+));)/
JSON_ESCAPE_REGEXP = /[&"><]/
# A utility method for escaping HTML tag characters.
@@ -21,7 +21,7 @@ class ERB
if s.html_safe?
s
else
- s.encode(s.encoding, :xml => :attr)[1...-1].html_safe
+ s.gsub(/[&"'><]/, HTML_ESCAPE).html_safe
end
end
@@ -60,18 +60,11 @@ class ERB
# json_escape('{"name":"john","created_at":"2010-04-28T01:39:31Z","id":1}')
# # => {name:john,created_at:2010-04-28T01:39:31Z,id:1}
#
- # This method is also aliased as +j+, and available as a helper
- # in Rails templates:
- #
- # <%=j @person.to_json %>
- #
def json_escape(s)
result = s.to_s.gsub(JSON_ESCAPE_REGEXP) { |special| JSON_ESCAPE[special] }
s.html_safe? ? result.html_safe : result
end
- alias j json_escape
- module_function :j
module_function :json_escape
end
end
diff --git a/activesupport/lib/active_support/core_ext/time.rb b/activesupport/lib/active_support/core_ext/time.rb
new file mode 100644
index 0000000000..32cffe237d
--- /dev/null
+++ b/activesupport/lib/active_support/core_ext/time.rb
@@ -0,0 +1,5 @@
+require 'active_support/core_ext/time/acts_like'
+require 'active_support/core_ext/time/calculations'
+require 'active_support/core_ext/time/conversions'
+require 'active_support/core_ext/time/marshal'
+require 'active_support/core_ext/time/zones'
diff --git a/activesupport/lib/active_support/core_ext/time/calculations.rb b/activesupport/lib/active_support/core_ext/time/calculations.rb
index 0a71fc117c..148f2c27f1 100644
--- a/activesupport/lib/active_support/core_ext/time/calculations.rb
+++ b/activesupport/lib/active_support/core_ext/time/calculations.rb
@@ -1,18 +1,13 @@
require 'active_support/duration'
require 'active_support/core_ext/time/conversions'
require 'active_support/time_with_zone'
+require 'active_support/core_ext/time/zones'
+require 'active_support/core_ext/date_and_time/calculations'
class Time
+ include DateAndTime::Calculations
+
COMMON_YEAR_DAYS_IN_MONTH = [nil, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
- DAYS_INTO_WEEK = {
- :monday => 0,
- :tuesday => 1,
- :wednesday => 2,
- :thursday => 3,
- :friday => 4,
- :saturday => 5,
- :sunday => 6
- }
class << self
# Overriding case equality method so that it returns true for ActiveSupport::TimeWithZone instances
@@ -62,29 +57,19 @@ class Time
end
end
- # Tells whether the Time object's time lies in the past
- def past?
- self < ::Time.current
- end
-
- # Tells whether the Time object's time is today
- def today?
- to_date == ::Date.current
- end
-
- # Tells whether the Time object's time lies in the future
- def future?
- self > ::Time.current
- end
-
# Seconds since midnight: Time.now.seconds_since_midnight
def seconds_since_midnight
to_i - change(:hour => 0).to_i + (usec / 1.0e+6)
end
# Returns a new Time where one or more of the elements have been changed according to the +options+ parameter. The time options
- # (hour, min, sec, usec) reset cascadingly, so if only the hour is passed, then minute, sec, and usec is set to 0. If the hour and
- # minute is passed, then sec and usec is set to 0.
+ # (<tt>:hour</tt>, <tt>:min</tt>, <tt>:sec</tt>, <tt>:usec</tt>) reset cascadingly, so if only the hour is passed, then minute, sec, and usec is set to 0.
+ # If the hour and minute is passed, then sec and usec is set to 0. The +options+ parameter takes a hash with any of these keys: <tt>:year</tt>,
+ # <tt>:month</tt>, <tt>:day</tt>, <tt>:hour</tt>, <tt>:min</tt>, <tt>:sec</tt>, <tt>:usec</tt>.
+ #
+ # Time.new(2012, 8, 29, 22, 35, 0).change(:day => 1) # => Time.new(2012, 8, 1, 22, 35, 0)
+ # Time.new(2012, 8, 29, 22, 35, 0).change(:year => 1981, :day => 1) # => Time.new(1981, 8, 1, 22, 35, 0)
+ # Time.new(2012, 8, 29, 22, 35, 0).change(:year => 1981, :hour => 0) # => Time.new(1981, 8, 29, 0, 0, 0)
def change(options)
new_year = options.fetch(:year, year)
new_month = options.fetch(:month, month)
@@ -145,116 +130,6 @@ class Time
end
alias :in :since
- # Returns a new Time representing the time a number of specified weeks ago.
- def weeks_ago(weeks)
- advance(:weeks => -weeks)
- end
-
- # Returns a new Time representing the time a number of specified months ago
- def months_ago(months)
- advance(:months => -months)
- end
-
- # Returns a new Time representing the time a number of specified months in the future
- def months_since(months)
- advance(:months => months)
- end
-
- # Returns a new Time representing the time a number of specified years ago
- def years_ago(years)
- advance(:years => -years)
- end
-
- # Returns a new Time representing the time a number of specified years in the future
- def years_since(years)
- advance(:years => years)
- end
-
- # Short-hand for years_ago(1)
- def prev_year
- years_ago(1)
- end
- alias_method :last_year, :prev_year
-
- # Short-hand for years_since(1)
- def next_year
- years_since(1)
- end
-
- # Short-hand for months_ago(1)
- def prev_month
- months_ago(1)
- end
- alias_method :last_month, :prev_month
-
- # Short-hand for months_since(1)
- def next_month
- months_since(1)
- end
-
- # Short-hand for months_ago(3)
- def prev_quarter
- months_ago(3)
- end
- alias_method :last_quarter, :prev_quarter
-
- # Short-hand for months_since(3)
- def next_quarter
- months_since(3)
- end
-
- # Returns number of days to start of this week, week starts on start_day (default is :monday).
- def days_to_week_start(start_day = :monday)
- start_day_number = DAYS_INTO_WEEK[start_day]
- current_day_number = wday != 0 ? wday - 1 : 6
- days_span = current_day_number - start_day_number
-
- days_span >= 0 ? days_span : 7 + days_span
- end
-
- # Returns a new Time representing the "start" of this week, week starts on start_day (default is :monday, i.e. Monday, 0:00).
- def beginning_of_week(start_day = :monday)
- days_to_start = days_to_week_start(start_day)
- (self - days_to_start.days).midnight
- end
- alias :at_beginning_of_week :beginning_of_week
-
- # Returns a new +Date+/+DateTime+ representing the start of this week. Week is
- # assumed to start on a Monday. +DateTime+ objects have their time set to 0:00.
- def monday
- beginning_of_week
- end
-
- # Returns a new Time representing the end of this week, week starts on start_day (default is :monday, i.e. end of Sunday).
- def end_of_week(start_day = :monday)
- days_to_end = 6 - days_to_week_start(start_day)
- (self + days_to_end.days).end_of_day
- end
- alias :at_end_of_week :end_of_week
-
- # Returns a new +Date+/+DateTime+ representing the end of this week. Week is
- # assumed to start on a Monday. +DateTime+ objects have their time set to 23:59:59.
- def sunday
- end_of_week
- end
-
- # Returns a new Time representing the start of the given day in the previous week (default is :monday).
- def prev_week(day = :monday)
- ago(1.week).
- beginning_of_week.
- since(DAYS_INTO_WEEK[day].day).
- change(:hour => 0)
- end
- alias_method :last_week, :prev_week
-
- # Returns a new Time representing the start of the given day in next week (default is :monday).
- def next_week(day = :monday)
- since(1.week).
- beginning_of_week.
- since(DAYS_INTO_WEEK[day].day).
- change(:hour => 0)
- end
-
# Returns a new Time representing the start of the day (0:00)
def beginning_of_day
#(self - seconds_since_midnight).change(:usec => 0)
@@ -289,70 +164,6 @@ class Time
)
end
- # Returns a new Time representing the start of the month (1st of the month, 0:00)
- def beginning_of_month
- #self - ((self.mday-1).days + self.seconds_since_midnight)
- change(:day => 1, :hour => 0)
- end
- alias :at_beginning_of_month :beginning_of_month
-
- # Returns a new Time representing the end of the month (end of the last day of the month)
- def end_of_month
- #self - ((self.mday-1).days + self.seconds_since_midnight)
- last_day = ::Time.days_in_month(month, year)
- change(
- :day => last_day,
- :hour => 23,
- :min => 59,
- :sec => 59,
- :usec => Rational(999999999, 1000)
- )
- 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
- first_quarter_month = [10, 7, 4, 1].detect { |m| m <= month }
- beginning_of_month.change(:month => first_quarter_month)
- end
- alias :at_beginning_of_quarter :beginning_of_quarter
-
- # Returns a new Time representing the end of the quarter (end of the last day of march, june, september, december)
- def end_of_quarter
- last_quarter_month = [3, 6, 9, 12].detect { |m| m >= month }
- beginning_of_month.change(:month => last_quarter_month).end_of_month
- end
- alias :at_end_of_quarter :end_of_quarter
-
- # Returns a new Time representing the start of the year (1st of january, 0:00)
- def beginning_of_year
- change(:month => 1, :day => 1, :hour => 0)
- end
- alias :at_beginning_of_year :beginning_of_year
-
- # Returns a new Time representing the end of the year (end of the 31st of december)
- def end_of_year
- change(
- :month => 12,
- :day => 31,
- :hour => 23,
- :min => 59,
- :sec => 59,
- :usec => Rational(999999999, 1000)
- )
- end
- alias :at_end_of_year :end_of_year
-
- # Convenience method which returns a new Time representing the time 1 day ago
- def yesterday
- advance(:days => -1)
- end
-
- # Convenience method which returns a new Time representing the time 1 day since the instance time
- def tomorrow
- advance(:days => 1)
- end
-
# Returns a Range representing the whole day of the current time.
def all_day
beginning_of_day..end_of_day
diff --git a/activesupport/lib/active_support/core_ext/time/zones.rb b/activesupport/lib/active_support/core_ext/time/zones.rb
index e48866abe3..37bc3fae24 100644
--- a/activesupport/lib/active_support/core_ext/time/zones.rb
+++ b/activesupport/lib/active_support/core_ext/time/zones.rb
@@ -1,4 +1,3 @@
-require 'active_support/core_ext/time/calculations'
require 'active_support/time_with_zone'
class Time
@@ -27,11 +26,11 @@ class Time
# around_filter :set_time_zone
#
# def set_time_zone
- # old_time_zone = Time.zone
- # Time.zone = current_user.time_zone if logged_in?
- # yield
- # ensure
- # Time.zone = old_time_zone
+ # if logged_in?
+ # Time.use_zone(current_user.time_zone) { yield }
+ # else
+ # yield
+ # end
# end
# end
def zone=(time_zone)
diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb
index c9071a73d8..d6bc95a522 100644
--- a/activesupport/lib/active_support/dependencies.rb
+++ b/activesupport/lib/active_support/dependencies.rb
@@ -168,16 +168,30 @@ module ActiveSupport #:nodoc:
end
end
- def const_missing(const_name, nesting = nil)
+ def const_missing(const_name)
klass_name = name.presence || "Object"
- unless nesting
- # We'll assume that the nesting of Foo::Bar is ["Foo::Bar", "Foo"]
- # even though it might not be, such as in the case of
- # class Foo::Bar; Baz; end
- nesting = []
- klass_name.to_s.scan(/::|$/) { nesting.unshift $` }
- end
+ # Since Ruby does not pass the nesting at the point the unknown
+ # constant triggered the callback we cannot fully emulate constant
+ # name lookup and need to make a trade-off: we are going to assume
+ # that the nesting in the body of Foo::Bar is [Foo::Bar, Foo] even
+ # though it might not be. Counterexamples are
+ #
+ # class Foo::Bar
+ # Module.nesting # => [Foo::Bar]
+ # end
+ #
+ # or
+ #
+ # module M::N
+ # module S::T
+ # Module.nesting # => [S::T, M::N]
+ # end
+ # end
+ #
+ # for example.
+ nesting = []
+ klass_name.to_s.scan(/::|$/) { nesting.unshift $` }
# If there are multiple levels of nesting to search under, the top
# level is the one we want to report as the lookup fail.
@@ -287,13 +301,11 @@ module ActiveSupport #:nodoc:
Object.class_eval { include Loadable }
Module.class_eval { include ModuleConstMissing }
Exception.class_eval { include Blamable }
- true
end
def unhook!
ModuleConstMissing.exclude_from(Module)
Loadable.exclude_from(Object)
- true
end
def load?
@@ -319,7 +331,7 @@ module ActiveSupport #:nodoc:
def require_or_load(file_name, const_path = nil)
log_call file_name, const_path
- file_name = $1 if file_name =~ /^(.*)\.rb$/
+ file_name = $` if file_name =~ /\.rb\z/
expanded = File.expand_path(file_name)
return if loaded.include?(expanded)
@@ -363,7 +375,7 @@ module ActiveSupport #:nodoc:
# Given +path+, a filesystem path to a ruby file, return an array of constant
# paths which would cause Dependencies to attempt to load this file.
def loadable_constants_for_path(path, bases = autoload_paths)
- path = $1 if path =~ /\A(.*)\.rb\Z/
+ path = $` if path =~ /\.rb\z/
expanded_path = File.expand_path(path)
paths = []
@@ -431,7 +443,7 @@ module ActiveSupport #:nodoc:
def load_file(path, const_paths = loadable_constants_for_path(path))
log_call path, const_paths
const_paths = [const_paths].compact unless const_paths.is_a? Array
- parent_paths = const_paths.collect { |const_path| /(.*)::[^:]+\Z/ =~ const_path ? $1 : :Object }
+ parent_paths = const_paths.collect { |const_path| const_path[/.*(?=::)/] || :Object }
result = nil
newly_defined_paths = new_constants_in(*parent_paths) do
@@ -467,10 +479,17 @@ module ActiveSupport #:nodoc:
file_path = search_for_file(path_suffix)
- if file_path && ! loaded.include?(File.expand_path(file_path)) # We found a matching file to load
- require_or_load file_path
- raise LoadError, "Expected #{file_path} to define #{qualified_name}" unless from_mod.const_defined?(const_name, false)
- return from_mod.const_get(const_name)
+ if file_path
+ expanded = File.expand_path(file_path)
+ expanded.sub!(/\.rb\z/, '')
+
+ if loaded.include?(expanded)
+ raise "Circular dependency detected while autoloading constant #{qualified_name}"
+ else
+ require_or_load(expanded)
+ raise LoadError, "Unable to autoload constant #{qualified_name}, expected #{file_path} to define it" unless from_mod.const_defined?(const_name, false)
+ return from_mod.const_get(const_name)
+ end
elsif mod = autoload_module!(from_mod, const_name, qualified_name, path_suffix)
return mod
elsif (parent = from_mod.parent) && parent != from_mod &&
diff --git a/activesupport/lib/active_support/dependencies/autoload.rb b/activesupport/lib/active_support/dependencies/autoload.rb
index 4045db3232..df490ae298 100644
--- a/activesupport/lib/active_support/dependencies/autoload.rb
+++ b/activesupport/lib/active_support/dependencies/autoload.rb
@@ -1,52 +1,78 @@
require "active_support/inflector/methods"
module ActiveSupport
+ # Autoload and eager load conveniences for your library.
+ #
+ # This module allows you to define autoloads based on
+ # Rails conventions (i.e. no need to define the path
+ # it is automatically guessed based on the filename)
+ # and also define a set of constants that needs to be
+ # eager loaded:
+ #
+ # module MyLib
+ # extend ActiveSupport::Autoload
+ #
+ # autoload :Model
+ #
+ # eager_autoload do
+ # autoload :Cache
+ # end
+ # end
+ #
+ # Then your library can be eager loaded by simply calling:
+ #
+ # MyLib.eager_load!
+ #
module Autoload
- @@autoloads = {}
- @@under_path = nil
- @@at_path = nil
- @@eager_autoload = false
+ def self.extended(base)
+ base.class_eval do
+ @_autoloads = {}
+ @_under_path = nil
+ @_at_path = nil
+ @_eager_autoload = false
+ end
+ end
- def autoload(const_name, path = @@at_path)
+ def autoload(const_name, path = @_at_path)
unless path
- full = [name, @@under_path, const_name.to_s, path].compact.join("::")
+ full = [name, @_under_path, const_name.to_s, path].compact.join("::")
path = Inflector.underscore(full)
end
- if @@eager_autoload
- @@autoloads[const_name] = path
+ if @_eager_autoload
+ @_autoloads[const_name] = path
end
super const_name, path
end
def autoload_under(path)
- @@under_path, old_path = path, @@under_path
+ @_under_path, old_path = path, @_under_path
yield
ensure
- @@under_path = old_path
+ @_under_path = old_path
end
def autoload_at(path)
- @@at_path, old_path = path, @@at_path
+ @_at_path, old_path = path, @_at_path
yield
ensure
- @@at_path = old_path
+ @_at_path = old_path
end
def eager_autoload
- old_eager, @@eager_autoload = @@eager_autoload, true
+ old_eager, @_eager_autoload = @_eager_autoload, true
yield
ensure
- @@eager_autoload = old_eager
+ @_eager_autoload = old_eager
end
- def self.eager_autoload!
- @@autoloads.values.each { |file| require file }
+ def eager_load!
+ @_autoloads.values.each { |file| require file }
end
def autoloads
- @@autoloads
+ @_autoloads
end
end
end
diff --git a/activesupport/lib/active_support/duration.rb b/activesupport/lib/active_support/duration.rb
index 2cdc991120..a0139b7d8e 100644
--- a/activesupport/lib/active_support/duration.rb
+++ b/activesupport/lib/active_support/duration.rb
@@ -70,7 +70,7 @@ module ActiveSupport
alias :until :ago
def inspect #:nodoc:
- consolidated = parts.inject(::Hash.new(0)) { |h,part| h[part.first] += part.last; h }
+ consolidated = parts.inject(::Hash.new(0)) { |h,(l,r)| h[l] += r; h }
parts = [:years, :months, :days, :minutes, :seconds].map do |length|
n = consolidated[length]
"#{n} #{n == 1 ? length.to_s.singularize : length.to_s}" if n.nonzero?
diff --git a/activesupport/lib/active_support/hash_with_indifferent_access.rb b/activesupport/lib/active_support/hash_with_indifferent_access.rb
index 3e6c8893e9..71713644a7 100644
--- a/activesupport/lib/active_support/hash_with_indifferent_access.rb
+++ b/activesupport/lib/active_support/hash_with_indifferent_access.rb
@@ -1,12 +1,46 @@
require 'active_support/core_ext/hash/keys'
module ActiveSupport
- # This class has dubious semantics and we only have it so that
- # people can write <tt>params[:key]</tt> instead of <tt>params['key']</tt>
- # and they get the same value for both keys.
+ # Implements a hash where keys <tt>:foo</tt> and <tt>"foo"</tt> are considered to be the same.
+ #
+ # rgb = ActiveSupport::HashWithIndifferentAccess.new
+ #
+ # rgb[:black] = '#000000'
+ # rgb[:black] # => '#000000'
+ # rgb['black'] # => '#000000'
+ #
+ # rgb['white'] = '#FFFFFF'
+ # rgb[:white] # => '#FFFFFF'
+ # rgb['white'] # => '#FFFFFF'
+ #
+ # Internally symbols are mapped to strings when used as keys in the entire
+ # writing interface (calling <tt>[]=</tt>, <tt>merge</tt>, etc). This
+ # mapping belongs to the public interface. For example, given
+ #
+ # hash = ActiveSupport::HashWithIndifferentAccess.new(:a => 1)
+ #
+ # you are guaranteed that the key is returned as a string:
+ #
+ # hash.keys # => ["a"]
+ #
+ # Technically other types of keys are accepted:
+ #
+ # hash = ActiveSupport::HashWithIndifferentAccess.new(:a => 1)
+ # hash[0] = 0
+ # hash # => {"a"=>1, 0=>0}
+ #
+ # but this class is intended for use cases where strings or symbols are the
+ # expected keys and it is convenient to understand both as the same. For
+ # example the +params+ hash in Ruby on Rails.
+ #
+ # Note that core extensions define <tt>Hash#with_indifferent_access</tt>:
+ #
+ # rgb = {:black => '#000000', :white => '#FFFFFF'}.with_indifferent_access
+ #
+ # which may be handy.
class HashWithIndifferentAccess < Hash
-
- # Always returns true, so that <tt>Array#extract_options!</tt> finds members of this class.
+ # Returns true so that <tt>Array#extract_options!</tt> finds members of
+ # this class.
def extractable_options?
true
end
@@ -51,30 +85,52 @@ module ActiveSupport
# Assigns a new value to the hash:
#
- # hash = HashWithIndifferentAccess.new
+ # hash = ActiveSupport::HashWithIndifferentAccess.new
# hash[:key] = "value"
#
+ # This value can be later fetched using either +:key+ or +"key"+.
def []=(key, value)
regular_writer(convert_key(key), convert_value(value))
end
alias_method :store, :[]=
- # Updates the instantized hash with values from the second:
+ # Updates the receiver in-place, merging in the hash passed as argument:
#
- # hash_1 = HashWithIndifferentAccess.new
+ # hash_1 = ActiveSupport::HashWithIndifferentAccess.new
# hash_1[:key] = "value"
#
- # hash_2 = HashWithIndifferentAccess.new
+ # hash_2 = ActiveSupport::HashWithIndifferentAccess.new
# hash_2[:key] = "New Value!"
#
# hash_1.update(hash_2) # => {"key"=>"New Value!"}
#
+ # The argument can be either an
+ # <tt>ActiveSupport::HashWithIndifferentAccess</tt> or a regular +Hash+.
+ # In either case the merge respects the semantics of indifferent access.
+ #
+ # If the argument is a regular hash with keys +:key+ and +"key"+ only one
+ # of the values end up in the receiver, but which one is unspecified.
+ #
+ # When given a block, the value for duplicated keys will be determined
+ # by the result of invoking the block with the duplicated key, the value
+ # in the receiver, and the value in +other_hash+. The rules for duplicated
+ # keys follow the semantics of indifferent access:
+ #
+ # hash_1[:key] = 10
+ # hash_2['key'] = 12
+ # hash_1.update(hash_2) { |key, old, new| old + new } # => {"key"=>22}
+ #
def update(other_hash)
if other_hash.is_a? HashWithIndifferentAccess
super(other_hash)
else
- other_hash.each_pair { |key, value| regular_writer(convert_key(key), convert_value(value)) }
+ other_hash.each_pair do |key, value|
+ if block_given? && key?(key)
+ value = yield(convert_key(key), self[key], value)
+ end
+ regular_writer(convert_key(key), convert_value(value))
+ end
self
end
end
@@ -83,10 +139,10 @@ module ActiveSupport
# Checks the hash for a key matching the argument passed in:
#
- # hash = HashWithIndifferentAccess.new
+ # hash = ActiveSupport::HashWithIndifferentAccess.new
# hash["key"] = "value"
- # hash.key? :key # => true
- # hash.key? "key" # => true
+ # hash.key?(:key) # => true
+ # hash.key?("key") # => true
#
def key?(key)
super(convert_key(key))
@@ -96,14 +152,24 @@ module ActiveSupport
alias_method :has_key?, :key?
alias_method :member?, :key?
- # Fetches the value for the specified key, same as doing hash[key]
+ # Same as <tt>Hash#fetch</tt> where the key passed as argument can be
+ # either a string or a symbol:
+ #
+ # counters = ActiveSupport::HashWithIndifferentAccess.new
+ # counters[:foo] = 1
+ #
+ # counters.fetch("foo") # => 1
+ # counters.fetch(:bar, 0) # => 0
+ # counters.fetch(:bar) {|key| 0} # => 0
+ # counters.fetch(:zoo) # => KeyError: key not found: "zoo"
+ #
def fetch(key, *extras)
super(convert_key(key), *extras)
end
# Returns an array of the values at the specified indices:
#
- # hash = HashWithIndifferentAccess.new
+ # hash = ActiveSupport::HashWithIndifferentAccess.new
# hash[:a] = "x"
# hash[:b] = "y"
# hash.values_at("a", "b") # => ["x", "y"]
@@ -119,23 +185,30 @@ module ActiveSupport
end
end
- # Merges the instantized and the specified hashes together, giving precedence to the values from the second hash.
- # Does not overwrite the existing hash.
- def merge(hash)
- self.dup.update(hash)
+ # This method has the same semantics of +update+, except it does not
+ # modify the receiver but rather returns a new hash with indifferent
+ # access with the result of the merge.
+ def merge(hash, &block)
+ self.dup.update(hash, &block)
end
- # Performs the opposite of merge, with the keys and values from the first hash taking precedence over the second.
- # This overloaded definition prevents returning a regular hash, if reverse_merge is called on a <tt>HashWithDifferentAccess</tt>.
+ # Like +merge+ but the other way around: Merges the receiver into the
+ # argument and returns a new hash with indifferent access as result:
+ #
+ # hash = ActiveSupport::HashWithIndifferentAccess.new
+ # hash['a'] = nil
+ # hash.reverse_merge(:a => 0, :b => 1) # => {"a"=>nil, "b"=>1}
+ #
def reverse_merge(other_hash)
- super self.class.new_from_hash_copying_default(other_hash)
+ super(self.class.new_from_hash_copying_default(other_hash))
end
+ # Same semantics as +reverse_merge+ but modifies the receiver in-place.
def reverse_merge!(other_hash)
replace(reverse_merge( other_hash ))
end
- # Removes a specified key from the hash.
+ # Removes the specified key from the hash.
def delete(key)
super(convert_key(key))
end
@@ -150,7 +223,7 @@ module ActiveSupport
def deep_symbolize_keys; to_hash.deep_symbolize_keys end
def to_options!; self end
- # Convert to a Hash with String keys.
+ # Convert to a regular hash with string keys.
def to_hash
Hash.new(default).merge!(self)
end
diff --git a/activesupport/lib/active_support/inflections.rb b/activesupport/lib/active_support/inflections.rb
index ca2d8cb270..ef882ebd09 100644
--- a/activesupport/lib/active_support/inflections.rb
+++ b/activesupport/lib/active_support/inflections.rb
@@ -1,7 +1,7 @@
require 'active_support/inflector/inflections'
module ActiveSupport
- Inflector.inflections do |inflect|
+ Inflector.inflections(:en) do |inflect|
inflect.plural(/$/, 's')
inflect.plural(/s$/i, 's')
inflect.plural(/^(ax|test)is$/i, '\1es')
diff --git a/activesupport/lib/active_support/inflector/inflections.rb b/activesupport/lib/active_support/inflector/inflections.rb
index c9e50a9462..091692e5a4 100644
--- a/activesupport/lib/active_support/inflector/inflections.rb
+++ b/activesupport/lib/active_support/inflector/inflections.rb
@@ -1,13 +1,15 @@
require 'active_support/core_ext/array/prepend_and_append'
+require 'active_support/i18n'
module ActiveSupport
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.
+ # inflection rules. If passed an optional locale, rules for other languages can be specified. The default locale is
+ # <tt>:en</tt>. Only rules for English are provided.
#
- # ActiveSupport::Inflector.inflections do |inflect|
+ # ActiveSupport::Inflector.inflections(:en) do |inflect|
# inflect.plural /^(ox)$/i, '\1\2en'
# inflect.singular /^(ox)en/i, '\1'
#
@@ -20,8 +22,9 @@ module ActiveSupport
# pluralization and singularization rules that is runs. This guarantees that your rules run before any of the rules that may
# already have been loaded.
class Inflections
- def self.instance
- @__instance__ ||= new
+ def self.instance(locale = :en)
+ @__instance__ ||= Hash.new { |h, k| h[k] = new }
+ @__instance__[locale]
end
attr_reader :plurals, :singulars, :uncountables, :humans, :acronyms, :acronym_regex
@@ -160,16 +163,18 @@ module ActiveSupport
end
# Yields a singleton instance of Inflector::Inflections so you can specify additional
- # inflector rules.
+ # inflector rules. If passed an optional locale, rules for other languages can be specified.
+ # If not specified, defaults to <tt>:en</tt>. Only rules for English are provided.
+ #
#
- # ActiveSupport::Inflector.inflections do |inflect|
+ # ActiveSupport::Inflector.inflections(:en) do |inflect|
# inflect.uncountable "rails"
# end
- def inflections
+ def inflections(locale = :en)
if block_given?
- yield Inflections.instance
+ yield Inflections.instance(locale)
else
- Inflections.instance
+ Inflections.instance(locale)
end
end
end
diff --git a/activesupport/lib/active_support/inflector/methods.rb b/activesupport/lib/active_support/inflector/methods.rb
index c14a43de0d..44214d16fa 100644
--- a/activesupport/lib/active_support/inflector/methods.rb
+++ b/activesupport/lib/active_support/inflector/methods.rb
@@ -10,31 +10,41 @@ module ActiveSupport
#
# The Rails core team has stated patches for the inflections library will not be accepted
# in order to avoid breaking legacy applications which may be relying on errant inflections.
- # If you discover an incorrect inflection and require it for your application, you'll need
- # to correct it yourself (explained below).
+ # If you discover an incorrect inflection and require it for your application or wish to
+ # define rules for languages other than English, please correct or add them yourself (explained below).
module Inflector
extend self
# Returns the plural form of the word in the string.
#
+ # If passed an optional +locale+ parameter, the word will be
+ # pluralized using rules defined for that language. By default,
+ # this parameter is set to <tt>:en</tt>.
+ #
# "post".pluralize # => "posts"
# "octopus".pluralize # => "octopi"
# "sheep".pluralize # => "sheep"
# "words".pluralize # => "words"
# "CamelOctopus".pluralize # => "CamelOctopi"
- def pluralize(word)
- apply_inflections(word, inflections.plurals)
+ # "ley".pluralize(:es) # => "leyes"
+ def pluralize(word, locale = :en)
+ apply_inflections(word, inflections(locale).plurals)
end
# The reverse of +pluralize+, returns the singular form of a word in a string.
#
+ # If passed an optional +locale+ parameter, the word will be
+ # pluralized using rules defined for that language. By default,
+ # this parameter is set to <tt>:en</tt>.
+ #
# "posts".singularize # => "post"
# "octopi".singularize # => "octopus"
# "sheep".singularize # => "sheep"
# "word".singularize # => "word"
# "CamelOctopi".singularize # => "CamelOctopus"
- def singularize(word)
- apply_inflections(word, inflections.singulars)
+ # "leyes".singularize(:es) # => "ley"
+ def singularize(word, locale = :en)
+ apply_inflections(word, inflections(locale).singulars)
end
# By default, +camelize+ converts strings to UpperCamelCase. If the argument to +camelize+
diff --git a/activesupport/lib/active_support/json/encoding.rb b/activesupport/lib/active_support/json/encoding.rb
index c319e94bc6..1a95bd63e6 100644
--- a/activesupport/lib/active_support/json/encoding.rb
+++ b/activesupport/lib/active_support/json/encoding.rb
@@ -1,5 +1,6 @@
require 'active_support/core_ext/object/to_json'
require 'active_support/core_ext/module/delegation'
+require 'active_support/json/variable'
require 'bigdecimal'
require 'active_support/core_ext/big_decimal/conversions' # for #to_s
@@ -161,38 +162,67 @@ class Struct #:nodoc:
end
class TrueClass
- def as_json(options = nil) self end #:nodoc:
- def encode_json(encoder) to_s end #:nodoc:
+ def as_json(options = nil) #:nodoc:
+ self
+ end
+
+ def encode_json(encoder) #:nodoc:
+ to_s
+ end
end
class FalseClass
- def as_json(options = nil) self end #:nodoc:
- def encode_json(encoder) to_s end #:nodoc:
+ def as_json(options = nil) #:nodoc:
+ self
+ end
+
+ def encode_json(encoder) #:nodoc:
+ to_s
+ end
end
class NilClass
- def as_json(options = nil) self end #:nodoc:
- def encode_json(encoder) 'null' end #:nodoc:
+ def as_json(options = nil) #:nodoc:
+ self
+ end
+
+ def encode_json(encoder) #:nodoc:
+ 'null'
+ end
end
class String
- def as_json(options = nil) self end #:nodoc:
- def encode_json(encoder) encoder.escape(self) end #:nodoc:
+ def as_json(options = nil) #:nodoc:
+ self
+ end
+
+ def encode_json(encoder) #:nodoc:
+ encoder.escape(self)
+ end
end
class Symbol
- def as_json(options = nil) to_s end #:nodoc:
+ def as_json(options = nil) #:nodoc:
+ to_s
+ end
end
class Numeric
- def as_json(options = nil) self end #:nodoc:
- def encode_json(encoder) to_s end #:nodoc:
+ def as_json(options = nil) #:nodoc:
+ self
+ end
+
+ def encode_json(encoder) #:nodoc:
+ to_s
+ end
end
class Float
# Encoding Infinity or NaN to JSON should return "null". The default returns
# "Infinity" or "NaN" which breaks parsing the JSON. E.g. JSON.parse('[NaN]').
- def as_json(options = nil) finite? ? self : nil end #:nodoc:
+ def as_json(options = nil) #:nodoc:
+ finite? ? self : nil
+ end
end
class BigDecimal
@@ -216,7 +246,9 @@ class BigDecimal
end
class Regexp
- def as_json(options = nil) to_s end #:nodoc:
+ def as_json(options = nil) #:nodoc:
+ to_s
+ end
end
module Enumerable
@@ -226,7 +258,9 @@ module Enumerable
end
class Range
- def as_json(options = nil) to_s end #:nodoc:
+ def as_json(options = nil) #:nodoc:
+ to_s
+ end
end
class Array
@@ -262,7 +296,7 @@ class Hash
Hash[subset.map { |k, v| [k.to_s, encoder.as_json(v, options)] }]
end
- def encode_json(encoder)
+ def encode_json(encoder) #:nodoc:
# values are encoded with use_options = false, because we don't want hash representations from ActiveModel to be
# processed once again with as_json with options, as this could cause unexpected results (i.e. missing fields);
diff --git a/activesupport/lib/active_support/json/variable.rb b/activesupport/lib/active_support/json/variable.rb
new file mode 100644
index 0000000000..8af661a795
--- /dev/null
+++ b/activesupport/lib/active_support/json/variable.rb
@@ -0,0 +1,17 @@
+require 'active_support/deprecation'
+
+module ActiveSupport
+ module JSON
+ # Deprecated: A string that returns itself as its JSON-encoded form.
+ class Variable < String
+ def initialize(*args)
+ ActiveSupport::Deprecation.warn 'ActiveSupport::JSON::Variable is deprecated and will be removed in Rails 4.1. ' \
+ 'For your own custom JSON literals, define #as_json and #encode_json yourself.'
+ super
+ end
+
+ def as_json(options = nil) self end #:nodoc:
+ def encode_json(encoder) self end #:nodoc:
+ end
+ end
+end
diff --git a/activesupport/lib/active_support/locale/en.yml b/activesupport/lib/active_support/locale/en.yml
index 18c7d47026..f4900dc935 100644
--- a/activesupport/lib/active_support/locale/en.yml
+++ b/activesupport/lib/active_support/locale/en.yml
@@ -49,7 +49,7 @@ en:
significant: false
# If set, the zeros after the decimal separator will always be stripped (eg.: 1.200 will be 1.2)
strip_insignificant_zeros: false
-
+
# Used in NumberHelper.number_to_currency()
currency:
format:
@@ -62,7 +62,7 @@ en:
precision: 2
significant: false
strip_insignificant_zeros: false
-
+
# Used in NumberHelper.number_to_percentage()
percentage:
format:
@@ -73,7 +73,7 @@ en:
# significant: false
# strip_insignificant_zeros: false
format: "%n%"
-
+
# Used in NumberHelper.number_to_rounded()
precision:
format:
@@ -83,7 +83,7 @@ en:
# precision:
# significant: false
# strip_insignificant_zeros: false
-
+
# Used in NumberHelper.number_to_human_size() and NumberHelper.number_to_human()
human:
format:
@@ -131,5 +131,3 @@ en:
billion: Billion
trillion: Trillion
quadrillion: Quadrillion
-
- \ No newline at end of file
diff --git a/activesupport/lib/active_support/notifications/fanout.rb b/activesupport/lib/active_support/notifications/fanout.rb
index 6ffc091233..2e5bcf4639 100644
--- a/activesupport/lib/active_support/notifications/fanout.rb
+++ b/activesupport/lib/active_support/notifications/fanout.rb
@@ -59,10 +59,10 @@ module ActiveSupport
module Subscribers # :nodoc:
def self.new(pattern, listener)
- if listener.respond_to?(:call)
- subscriber = Timed.new pattern, listener
- else
+ if listener.respond_to?(:start) and listener.respond_to?(:finish)
subscriber = Evented.new pattern, listener
+ else
+ subscriber = Timed.new pattern, listener
end
unless pattern
diff --git a/activesupport/lib/active_support/number_helper.rb b/activesupport/lib/active_support/number_helper.rb
index 99f6489adb..3849f94a31 100644
--- a/activesupport/lib/active_support/number_helper.rb
+++ b/activesupport/lib/active_support/number_helper.rb
@@ -7,12 +7,108 @@ module ActiveSupport
module NumberHelper
extend self
+ DEFAULTS = {
+ # Used in number_to_delimited
+ # These are also the defaults for 'currency', 'percentage', 'precision', and 'human'
+ format: {
+ # Sets the separator between the units, for more precision (e.g. 1.0 / 2.0 == 0.5)
+ separator: ".",
+ # Delimits thousands (e.g. 1,000,000 is a million) (always in groups of three)
+ delimiter: ",",
+ # Number of decimals, behind the separator (the number 1 with a precision of 2 gives: 1.00)
+ precision: 3,
+ # If set to true, precision will mean the number of significant digits instead
+ # of the number of decimal digits (1234 with precision 2 becomes 1200, 1.23543 becomes 1.2)
+ significant: false,
+ # If set, the zeros after the decimal separator will always be stripped (eg.: 1.200 will be 1.2)
+ strip_insignificant_zeros: false
+ },
+
+ # Used in number_to_currency
+ currency: {
+ format: {
+ format: "%u%n",
+ negative_format: "-%u%n",
+ unit: "$",
+ # These five are to override number.format and are optional
+ separator: ".",
+ delimiter: ",",
+ precision: 2,
+ significant: false,
+ strip_insignificant_zeros: false
+ }
+ },
+
+ # Used in number_to_percentage
+ percentage: {
+ format: {
+ delimiter: "",
+ format: "%n%"
+ }
+ },
+
+ # Used in number_to_rounded
+ precision: {
+ format: {
+ delimiter: ""
+ }
+ },
+
+ # Used in number_to_human_size and number_to_human
+ human: {
+ format: {
+ # These five are to override number.format and are optional
+ delimiter: "",
+ precision: 3,
+ significant: true,
+ strip_insignificant_zeros: true
+ },
+ # Used in number_to_human_size
+ storage_units: {
+ # Storage units output formatting.
+ # %u is the storage unit, %n is the number (default: 2 MB)
+ format: "%n %u",
+ units: {
+ byte: "Bytes",
+ kb: "KB",
+ mb: "MB",
+ gb: "GB",
+ tb: "TB"
+ }
+ },
+ # Used in number_to_human
+ decimal_units: {
+ format: "%n %u",
+ # Decimal units output formatting
+ # By default we will only quantify some of the exponents
+ # but the commented ones might be defined or overridden
+ # by the user.
+ units: {
+ # femto: Quadrillionth
+ # pico: Trillionth
+ # nano: Billionth
+ # micro: Millionth
+ # mili: Thousandth
+ # centi: Hundredth
+ # deci: Tenth
+ unit: "",
+ # ten:
+ # one: Ten
+ # other: Tens
+ # hundred: Hundred
+ thousand: "Thousand",
+ million: "Million",
+ billion: "Billion",
+ trillion: "Trillion",
+ quadrillion: "Quadrillion"
+ }
+ }
+ }
+ }
+
DECIMAL_UNITS = { 0 => :unit, 1 => :ten, 2 => :hundred, 3 => :thousand, 6 => :million, 9 => :billion, 12 => :trillion, 15 => :quadrillion,
-1 => :deci, -2 => :centi, -3 => :mili, -6 => :micro, -9 => :nano, -12 => :pico, -15 => :femto }
- DEFAULT_CURRENCY_VALUES = { :format => "%u%n", :negative_format => "-%u%n", :unit => "$", :separator => ".", :delimiter => ",",
- :precision => 2, :significant => false, :strip_insignificant_zeros => false }
-
STORAGE_UNITS = [:byte, :kb, :mb, :gb, :tb]
# Formats a +number+ into a US phone number (e.g., (555)
@@ -106,10 +202,10 @@ module ActiveSupport
return unless number
options = options.symbolize_keys
- currency = translations_for('currency', options[:locale])
+ currency = i18n_format_options(options[:locale], :currency)
currency[:negative_format] ||= "-" + currency[:format] if currency[:format]
- defaults = DEFAULT_CURRENCY_VALUES.merge(defaults_translations(options[:locale])).merge!(currency)
+ defaults = default_format_options(:currency).merge!(currency)
defaults[:negative_format] = "-" + options[:format] if options[:format]
options = defaults.merge!(options)
@@ -160,7 +256,7 @@ module ActiveSupport
return unless number
options = options.symbolize_keys
- defaults = format_translations('percentage', options[:locale])
+ defaults = format_options(options[:locale], :percentage)
options = defaults.merge!(options)
format = options[:format] || "%n%"
@@ -197,7 +293,7 @@ module ActiveSupport
return number unless valid_float?(number)
- options = defaults_translations(options[:locale]).merge(options)
+ options = format_options(options[:locale]).merge!(options)
parts = number.to_s.to_str.split('.')
parts[0].gsub!(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1#{options[:delimiter]}")
@@ -248,7 +344,7 @@ module ActiveSupport
number = Float(number)
options = options.symbolize_keys
- defaults = format_translations('precision', options[:locale])
+ defaults = format_options(options[:locale], :precision)
options = defaults.merge!(options)
precision = options.delete :precision
@@ -328,18 +424,18 @@ module ActiveSupport
return number unless valid_float?(number)
number = Float(number)
- defaults = format_translations('human', options[:locale])
+ defaults = format_options(options[:locale], :human)
options = defaults.merge!(options)
#for backwards compatibility with those that didn't add strip_insignificant_zeros to their locale files
options[:strip_insignificant_zeros] = true if not options.key?(:strip_insignificant_zeros)
- storage_units_format = I18n.translate(:'number.human.storage_units.format', :locale => options[:locale], :raise => true)
+ storage_units_format = translate_number_value_with_default('human.storage_units.format', :locale => options[:locale], :raise => true)
base = options[:prefix] == :si ? 1000 : 1024
if number.to_i < base
- unit = I18n.translate(:'number.human.storage_units.units.byte', :locale => options[:locale], :count => number.to_i, :raise => true)
+ unit = translate_number_value_with_default('human.storage_units.units.byte', :locale => options[:locale], :count => number.to_i, :raise => true)
storage_units_format.gsub(/%n/, number.to_i.to_s).gsub(/%u/, unit)
else
max_exp = STORAGE_UNITS.size - 1
@@ -348,7 +444,7 @@ module ActiveSupport
number /= base ** exponent
unit_key = STORAGE_UNITS[exponent]
- unit = I18n.translate(:"number.human.storage_units.units.#{unit_key}", :locale => options[:locale], :count => number, :raise => true)
+ unit = translate_number_value_with_default("human.storage_units.units.#{unit_key}", :locale => options[:locale], :count => number, :raise => true)
formatted_number = self.number_to_rounded(number, options)
storage_units_format.gsub(/%n/, formatted_number).gsub(/%u/, unit)
@@ -458,7 +554,7 @@ module ActiveSupport
return number unless valid_float?(number)
number = Float(number)
- defaults = format_translations('human', options[:locale])
+ defaults = format_options(options[:locale], :human)
options = defaults.merge!(options)
#for backwards compatibility with those that didn't add strip_insignificant_zeros to their locale files
@@ -473,7 +569,7 @@ module ActiveSupport
when String, Symbol
I18n.translate(:"#{units}", :locale => options[:locale], :raise => true)
when nil
- I18n.translate(:"number.human.decimal_units.units", :locale => options[:locale], :raise => true)
+ translate_number_value_with_default("human.decimal_units.units", :locale => options[:locale], :raise => true)
else
raise ArgumentError, ":units must be a Hash or String translation scope."
end.keys.map{|e_name| inverted_du[e_name] }.sort_by{|e| -e}
@@ -488,34 +584,47 @@ module ActiveSupport
when String, Symbol
I18n.translate(:"#{units}.#{DECIMAL_UNITS[display_exponent]}", :locale => options[:locale], :count => number.to_i)
else
- I18n.translate(:"number.human.decimal_units.units.#{DECIMAL_UNITS[display_exponent]}", :locale => options[:locale], :count => number.to_i)
+ translate_number_value_with_default("human.decimal_units.units.#{DECIMAL_UNITS[display_exponent]}", :locale => options[:locale], :count => number.to_i)
end
- decimal_format = options[:format] || I18n.translate(:'number.human.decimal_units.format', :locale => options[:locale], :default => "%n %u")
+ decimal_format = options[:format] || translate_number_value_with_default('human.decimal_units.format', :locale => options[:locale])
formatted_number = self.number_to_rounded(number, options)
decimal_format.gsub(/%n/, formatted_number).gsub(/%u/, unit).strip
end
- def self.private_module_and_instance_method(method_name)
+ def self.private_module_and_instance_method(method_name) #:nodoc:
private method_name
private_class_method method_name
end
private_class_method :private_module_and_instance_method
- def format_translations(namespace, locale) #:nodoc:
- defaults_translations(locale).merge(translations_for(namespace, locale))
+ def format_options(locale, namespace = nil) #:nodoc:
+ default_format_options(namespace).merge!(i18n_format_options(locale, namespace))
+ end
+ private_module_and_instance_method :format_options
+
+ def default_format_options(namespace = nil) #:nodoc:
+ options = DEFAULTS[:format].dup
+ options.merge!(DEFAULTS[namespace][:format]) if namespace
+ options
end
- private_module_and_instance_method :format_translations
+ private_module_and_instance_method :default_format_options
- def defaults_translations(locale) #:nodoc:
- I18n.translate(:'number.format', :locale => locale, :default => {})
+ def i18n_format_options(locale, namespace = nil) #:nodoc:
+ options = I18n.translate(:'number.format', locale: locale, default: {}).dup
+ if namespace
+ options.merge!(I18n.translate(:"number.#{namespace}.format", locale: locale, default: {}))
+ end
+ options
end
- private_module_and_instance_method :defaults_translations
+ private_module_and_instance_method :i18n_format_options
+
+ def translate_number_value_with_default(key, i18n_options = {}) #:nodoc:
+ default = key.split('.').reduce(DEFAULTS) { |defaults, k| defaults[k.to_sym] }
- def translations_for(namespace, locale) #:nodoc:
- I18n.translate(:"number.#{namespace}.format", :locale => locale, :default => {})
+ I18n.translate(key, { default: default, scope: :number }.merge!(i18n_options))
end
- private_module_and_instance_method :translations_for
+ private_module_and_instance_method :translate_number_value_with_default
def valid_float?(number) #:nodoc:
Float(number)
diff --git a/activesupport/lib/active_support/rails.rb b/activesupport/lib/active_support/rails.rb
new file mode 100644
index 0000000000..b05c3ff126
--- /dev/null
+++ b/activesupport/lib/active_support/rails.rb
@@ -0,0 +1,27 @@
+# This is private interface.
+#
+# Rails components cherry pick from Active Support as needed, but there are a
+# few features that are used for sure some way or another and it is not worth
+# to put individual requires absolutely everywhere. Think blank? for example.
+#
+# This file is loaded by every Rails component except Active Support itself,
+# but it does not belong to the Rails public interface. It is internal to
+# Rails and can change anytime.
+
+# Defines Object#blank? and Object#present?.
+require 'active_support/core_ext/object/blank'
+
+# Rails own autoload, eager_load, etc.
+require 'active_support/dependencies/autoload'
+
+# Support for ClassMethods and the included macro.
+require 'active_support/concern'
+
+# Defines Class#class_attribute.
+require 'active_support/core_ext/class/attribute'
+
+# Defines Module#delegate.
+require 'active_support/core_ext/module/delegation'
+
+# Defines ActiveSupport::Deprecation.
+require 'active_support/deprecation'
diff --git a/activesupport/lib/active_support/railtie.rb b/activesupport/lib/active_support/railtie.rb
index 30ac881090..aa8d408da9 100644
--- a/activesupport/lib/active_support/railtie.rb
+++ b/activesupport/lib/active_support/railtie.rb
@@ -5,6 +5,8 @@ module ActiveSupport
class Railtie < Rails::Railtie
config.active_support = ActiveSupport::OrderedOptions.new
+ config.eager_load_namespaces << ActiveSupport
+
initializer "active_support.deprecation_behavior" do |app|
if deprecation = app.config.active_support.deprecation
ActiveSupport::Deprecation.behavior = deprecation
diff --git a/activesupport/lib/active_support/string_inquirer.rb b/activesupport/lib/active_support/string_inquirer.rb
index f3f3909a90..5f20bfa7bc 100644
--- a/activesupport/lib/active_support/string_inquirer.rb
+++ b/activesupport/lib/active_support/string_inquirer.rb
@@ -10,12 +10,18 @@ module ActiveSupport
# Rails.env.production?
#
class StringInquirer < String
- def method_missing(method_name, *arguments)
- if method_name[-1, 1] == "?"
- self == method_name[0..-2]
- else
- super
+ private
+
+ def respond_to_missing?(method_name, include_private = false)
+ method_name[-1] == '?'
+ end
+
+ def method_missing(method_name, *arguments)
+ if method_name[-1] == '?'
+ self == method_name[0..-2]
+ else
+ super
+ end
end
- end
end
end
diff --git a/activesupport/lib/active_support/test_case.rb b/activesupport/lib/active_support/test_case.rb
index a6f3b43792..d2b8e602f9 100644
--- a/activesupport/lib/active_support/test_case.rb
+++ b/activesupport/lib/active_support/test_case.rb
@@ -3,25 +3,19 @@ require 'minitest/spec'
require 'active_support/testing/setup_and_teardown'
require 'active_support/testing/assertions'
require 'active_support/testing/deprecation'
-require 'active_support/testing/declarative'
require 'active_support/testing/isolation'
require 'active_support/testing/mocha_module'
require 'active_support/core_ext/kernel/reporting'
+require 'active_support/deprecation'
module ActiveSupport
class TestCase < ::MiniTest::Spec
include ActiveSupport::Testing::MochaModule
- if MiniTest::Unit::VERSION < '2.6.1'
- class << self
- alias :name :to_s
- end
- end
-
# Use AS::TestCase for the base class when describing a model
register_spec_type(self) do |desc|
- desc < ActiveRecord::Model
+ Class === desc && desc < ActiveRecord::Model
end
Assertion = MiniTest::Assertion
@@ -41,7 +35,24 @@ module ActiveSupport
include ActiveSupport::Testing::SetupAndTeardown
include ActiveSupport::Testing::Assertions
include ActiveSupport::Testing::Deprecation
- extend ActiveSupport::Testing::Declarative
+
+ def self.describe(text)
+ if block_given?
+ super
+ else
+ ActiveSupport::Deprecation.warn("`describe` without a block is deprecated, please switch to: `def self.name; #{text.inspect}; end`\n")
+
+ class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
+ def self.name
+ "#{text}"
+ end
+ RUBY_EVAL
+ end
+ end
+
+ class << self
+ alias :test :it
+ end
# test/unit backwards compatibility methods
alias :assert_raise :assert_raises
diff --git a/activesupport/lib/active_support/testing/declarative.rb b/activesupport/lib/active_support/testing/declarative.rb
deleted file mode 100644
index 508e37254a..0000000000
--- a/activesupport/lib/active_support/testing/declarative.rb
+++ /dev/null
@@ -1,40 +0,0 @@
-module ActiveSupport
- module Testing
- module Declarative
-
- def self.extended(klass) #:nodoc:
- klass.class_eval do
-
- unless method_defined?(:describe)
- def self.describe(text)
- class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
- def self.name
- "#{text}"
- end
- RUBY_EVAL
- end
- end
-
- end
- end
-
- unless defined?(Spec)
- # test "verify something" do
- # ...
- # end
- def test(name, &block)
- test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym
- defined = instance_method(test_name) rescue false
- raise "#{test_name} is already defined in #{self}" if defined
- if block_given?
- define_method(test_name, &block)
- else
- define_method(test_name) do
- flunk "No implementation provided for #{name}"
- end
- end
- end
- end
- end
- end
-end
diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb
index 451520ac5c..93c2d614f5 100644
--- a/activesupport/lib/active_support/time_with_zone.rb
+++ b/activesupport/lib/active_support/time_with_zone.rb
@@ -1,6 +1,5 @@
require 'active_support/values/time_zone'
require 'active_support/core_ext/object/acts_like'
-require 'active_support/core_ext/object/inclusion'
module ActiveSupport
# A Time-like class that can represent a time in any time zone. Necessary because standard Ruby Time instances are
@@ -339,7 +338,7 @@ module ActiveSupport
end
def duration_of_variable_length?(obj)
- ActiveSupport::Duration === obj && obj.parts.any? {|p| p[0].in?([:years, :months, :days]) }
+ ActiveSupport::Duration === obj && obj.parts.any? {|p| [:years, :months, :days].include?(p[0]) }
end
def wrap_with_time_zone(time)
diff --git a/activesupport/test/abstract_unit.rb b/activesupport/test/abstract_unit.rb
index 25ed962c23..8a67b148c3 100644
--- a/activesupport/test/abstract_unit.rb
+++ b/activesupport/test/abstract_unit.rb
@@ -21,15 +21,5 @@ require 'empty_bool'
ENV['NO_RELOAD'] = '1'
require 'active_support'
-def uses_memcached(test_name)
- require 'memcache'
- begin
- MemCache.new('localhost:11211').stats
- yield
- rescue MemCache::MemCacheError
- $stderr.puts "Skipping #{test_name} tests. Start memcached and try again."
- end
-end
-
# Show backtraces for deprecated behavior for quicker cleanup.
ActiveSupport::Deprecation.debug = true
diff --git a/activesupport/test/autoload.rb b/activesupport/test/autoload_test.rb
index 5d8026a9ca..7d02d835a8 100644
--- a/activesupport/test/autoload.rb
+++ b/activesupport/test/autoload_test.rb
@@ -28,15 +28,6 @@ class TestAutoloadModule < ActiveSupport::TestCase
assert_nothing_raised { ::Fixtures::Autoload::SomeClass }
end
- test ":eager constants can be triggered via ActiveSupport::Autoload.eager_autoload!" do
- module ::Fixtures::Autoload
- autoload :SomeClass, "fixtures/autoload/some_class"
- end
- ActiveSupport::Autoload.eager_autoload!
- assert $LOADED_FEATURES.include?("fixtures/autoload/some_class.rb")
- assert_nothing_raised { ::Fixtures::Autoload::SomeClass }
- end
-
test "the location of autoloaded constants defaults to :name.underscore" do
module ::Fixtures::Autoload
autoload :SomeClass
@@ -51,8 +42,7 @@ class TestAutoloadModule < ActiveSupport::TestCase
autoload :SomeClass
end
- ActiveSupport::Autoload.eager_autoload!
- assert $LOADED_FEATURES.include?("fixtures/autoload/some_class.rb")
+ ::Fixtures::Autoload.eager_load!
assert_nothing_raised { ::Fixtures::Autoload::SomeClass }
end
diff --git a/activesupport/test/autoloading_fixtures/circular1.rb b/activesupport/test/autoloading_fixtures/circular1.rb
new file mode 100644
index 0000000000..a45761f066
--- /dev/null
+++ b/activesupport/test/autoloading_fixtures/circular1.rb
@@ -0,0 +1,6 @@
+silence_warnings do
+ Circular2
+end
+
+class Circular1
+end
diff --git a/activesupport/test/autoloading_fixtures/circular2.rb b/activesupport/test/autoloading_fixtures/circular2.rb
new file mode 100644
index 0000000000..c847fa5001
--- /dev/null
+++ b/activesupport/test/autoloading_fixtures/circular2.rb
@@ -0,0 +1,4 @@
+Circular1
+
+class Circular2
+end
diff --git a/activesupport/test/autoloading_fixtures/class_folder/class_folder_subclass.rb b/activesupport/test/autoloading_fixtures/class_folder/class_folder_subclass.rb
index ef66ddaac7..402609c583 100644
--- a/activesupport/test/autoloading_fixtures/class_folder/class_folder_subclass.rb
+++ b/activesupport/test/autoloading_fixtures/class_folder/class_folder_subclass.rb
@@ -1,3 +1,3 @@
class ClassFolder::ClassFolderSubclass < ClassFolder
- ConstantInClassFolder
+ ConstantInClassFolder = 'indeed'
end
diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb
index a75db47be8..71cd9d81b3 100644
--- a/activesupport/test/caching_test.rb
+++ b/activesupport/test/caching_test.rb
@@ -83,20 +83,20 @@ class CacheStoreSettingTest < ActiveSupport::TestCase
end
def test_mem_cache_fragment_cache_store
- MemCache.expects(:new).with(%w[localhost], {})
+ Dalli::Client.expects(:new).with(%w[localhost], {})
store = ActiveSupport::Cache.lookup_store :mem_cache_store, "localhost"
assert_kind_of(ActiveSupport::Cache::MemCacheStore, store)
end
def test_mem_cache_fragment_cache_store_with_given_mem_cache
- mem_cache = MemCache.new
- MemCache.expects(:new).never
+ mem_cache = Dalli::Client.new
+ Dalli::Client.expects(:new).never
store = ActiveSupport::Cache.lookup_store :mem_cache_store, mem_cache
assert_kind_of(ActiveSupport::Cache::MemCacheStore, store)
end
def test_mem_cache_fragment_cache_store_with_given_mem_cache_like_object
- MemCache.expects(:new).never
+ Dalli::Client.expects(:new).never
memcache = Object.new
def memcache.get() true end
store = ActiveSupport::Cache.lookup_store :mem_cache_store, memcache
@@ -104,13 +104,13 @@ class CacheStoreSettingTest < ActiveSupport::TestCase
end
def test_mem_cache_fragment_cache_store_with_multiple_servers
- MemCache.expects(:new).with(%w[localhost 192.168.1.1], {})
+ Dalli::Client.expects(:new).with(%w[localhost 192.168.1.1], {})
store = ActiveSupport::Cache.lookup_store :mem_cache_store, "localhost", '192.168.1.1'
assert_kind_of(ActiveSupport::Cache::MemCacheStore, store)
end
def test_mem_cache_fragment_cache_store_with_options
- MemCache.expects(:new).with(%w[localhost 192.168.1.1], { :timeout => 10 })
+ Dalli::Client.expects(:new).with(%w[localhost 192.168.1.1], { :timeout => 10 })
store = ActiveSupport::Cache.lookup_store :mem_cache_store, "localhost", '192.168.1.1', :namespace => 'foo', :timeout => 10
assert_kind_of(ActiveSupport::Cache::MemCacheStore, store)
assert_equal 'foo', store.options[:namespace]
@@ -447,6 +447,7 @@ module CacheIncrementDecrementBehavior
assert_equal 2, @cache.read('foo').to_i
assert_equal 3, @cache.increment('foo')
assert_equal 3, @cache.read('foo').to_i
+ assert_nil @cache.increment('bar')
end
def test_decrement
@@ -456,6 +457,7 @@ module CacheIncrementDecrementBehavior
assert_equal 2, @cache.read('foo').to_i
assert_equal 1, @cache.decrement('foo')
assert_equal 1, @cache.read('foo').to_i
+ assert_nil @cache.decrement('bar')
end
end
@@ -702,53 +704,65 @@ class MemoryStoreTest < ActiveSupport::TestCase
end
end
-uses_memcached 'memcached backed store' do
- class MemCacheStoreTest < ActiveSupport::TestCase
- def setup
- @cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, :expires_in => 60)
- @peek = ActiveSupport::Cache.lookup_store(:mem_cache_store)
- @data = @cache.instance_variable_get(:@data)
- @cache.clear
- @cache.silence!
- @cache.logger = ActiveSupport::Logger.new("/dev/null")
- end
+class MemCacheStoreTest < ActiveSupport::TestCase
+ require 'dalli'
+
+ begin
+ ss = Dalli::Client.new('localhost:11211').stats
+ raise Dalli::DalliError unless ss['localhost:11211']
+
+ MEMCACHE_UP = true
+ rescue Dalli::DalliError
+ $stderr.puts "Skipping memcached tests. Start memcached and try again."
+ MEMCACHE_UP = false
+ end
+
+ def setup
+ skip "memcache server is not up" unless MEMCACHE_UP
+
+ @cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, :expires_in => 60)
+ @peek = ActiveSupport::Cache.lookup_store(:mem_cache_store)
+ @data = @cache.instance_variable_get(:@data)
+ @cache.clear
+ @cache.silence!
+ @cache.logger = ActiveSupport::Logger.new("/dev/null")
+ end
+
+ include CacheStoreBehavior
+ include LocalCacheBehavior
+ include CacheIncrementDecrementBehavior
+ include EncodedKeyCacheBehavior
+
+ def test_raw_values
+ cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, :raw => true)
+ cache.clear
+ cache.write("foo", 2)
+ assert_equal "2", cache.read("foo")
+ end
- include CacheStoreBehavior
- include LocalCacheBehavior
- include CacheIncrementDecrementBehavior
- include EncodedKeyCacheBehavior
+ def test_raw_values_with_marshal
+ cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, :raw => true)
+ cache.clear
+ cache.write("foo", Marshal.dump([]))
+ assert_equal [], cache.read("foo")
+ end
- def test_raw_values
- cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, :raw => true)
- cache.clear
+ def test_local_cache_raw_values
+ cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, :raw => true)
+ cache.clear
+ cache.with_local_cache do
cache.write("foo", 2)
assert_equal "2", cache.read("foo")
end
+ end
- def test_raw_values_with_marshal
- cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, :raw => true)
- cache.clear
+ def test_local_cache_raw_values_with_marshal
+ cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, :raw => true)
+ cache.clear
+ cache.with_local_cache do
cache.write("foo", Marshal.dump([]))
assert_equal [], cache.read("foo")
end
-
- def test_local_cache_raw_values
- cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, :raw => true)
- cache.clear
- cache.with_local_cache do
- cache.write("foo", 2)
- assert_equal "2", cache.read("foo")
- end
- end
-
- def test_local_cache_raw_values_with_marshal
- cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, :raw => true)
- cache.clear
- cache.with_local_cache do
- cache.write("foo", Marshal.dump([]))
- assert_equal [], cache.read("foo")
- end
- end
end
end
diff --git a/activesupport/test/core_ext/date_and_time_behavior.rb b/activesupport/test/core_ext/date_and_time_behavior.rb
new file mode 100644
index 0000000000..014935b0c0
--- /dev/null
+++ b/activesupport/test/core_ext/date_and_time_behavior.rb
@@ -0,0 +1,186 @@
+require 'abstract_unit'
+
+module DateAndTimeBehavior
+ def test_yesterday
+ assert_equal date_time_init(2005,2,21,10,10,10), date_time_init(2005,2,22,10,10,10).yesterday
+ assert_equal date_time_init(2005,2,28,10,10,10), date_time_init(2005,3,2,10,10,10).yesterday.yesterday
+ end
+
+ def test_tomorrow
+ assert_equal date_time_init(2005,2,23,10,10,10), date_time_init(2005,2,22,10,10,10).tomorrow
+ assert_equal date_time_init(2005,3,2,10,10,10), date_time_init(2005,2,28,10,10,10).tomorrow.tomorrow
+ end
+
+ def test_days_ago
+ assert_equal date_time_init(2005,6,4,10,10,10), date_time_init(2005,6,5,10,10,10).days_ago(1)
+ assert_equal date_time_init(2005,5,31,10,10,10), date_time_init(2005,6,5,10,10,10).days_ago(5)
+ end
+
+ def test_days_since
+ assert_equal date_time_init(2005,6,6,10,10,10), date_time_init(2005,6,5,10,10,10).days_since(1)
+ assert_equal date_time_init(2005,1,1,10,10,10), date_time_init(2004,12,31,10,10,10).days_since(1)
+ end
+
+ def test_weeks_ago
+ assert_equal date_time_init(2005,5,29,10,10,10), date_time_init(2005,6,5,10,10,10).weeks_ago(1)
+ assert_equal date_time_init(2005,5,1,10,10,10), date_time_init(2005,6,5,10,10,10).weeks_ago(5)
+ assert_equal date_time_init(2005,4,24,10,10,10), date_time_init(2005,6,5,10,10,10).weeks_ago(6)
+ assert_equal date_time_init(2005,2,27,10,10,10), date_time_init(2005,6,5,10,10,10).weeks_ago(14)
+ assert_equal date_time_init(2004,12,25,10,10,10), date_time_init(2005,1,1,10,10,10).weeks_ago(1)
+ end
+
+ def test_weeks_since
+ assert_equal date_time_init(2005,7,14,10,10,10), date_time_init(2005,7,7,10,10,10).weeks_since(1)
+ assert_equal date_time_init(2005,7,14,10,10,10), date_time_init(2005,7,7,10,10,10).weeks_since(1)
+ assert_equal date_time_init(2005,7,4,10,10,10), date_time_init(2005,6,27,10,10,10).weeks_since(1)
+ assert_equal date_time_init(2005,1,4,10,10,10), date_time_init(2004,12,28,10,10,10).weeks_since(1)
+ end
+
+ def test_months_ago
+ assert_equal date_time_init(2005,5,5,10,10,10), date_time_init(2005,6,5,10,10,10).months_ago(1)
+ assert_equal date_time_init(2004,11,5,10,10,10), date_time_init(2005,6,5,10,10,10).months_ago(7)
+ assert_equal date_time_init(2004,12,5,10,10,10), date_time_init(2005,6,5,10,10,10).months_ago(6)
+ assert_equal date_time_init(2004,6,5,10,10,10), date_time_init(2005,6,5,10,10,10).months_ago(12)
+ assert_equal date_time_init(2003,6,5,10,10,10), date_time_init(2005,6,5,10,10,10).months_ago(24)
+ end
+
+ def test_months_since
+ assert_equal date_time_init(2005,7,5,10,10,10), date_time_init(2005,6,5,10,10,10).months_since(1)
+ assert_equal date_time_init(2006,1,5,10,10,10), date_time_init(2005,12,5,10,10,10).months_since(1)
+ assert_equal date_time_init(2005,12,5,10,10,10), date_time_init(2005,6,5,10,10,10).months_since(6)
+ assert_equal date_time_init(2006,6,5,10,10,10), date_time_init(2005,12,5,10,10,10).months_since(6)
+ assert_equal date_time_init(2006,1,5,10,10,10), date_time_init(2005,6,5,10,10,10).months_since(7)
+ assert_equal date_time_init(2006,6,5,10,10,10), date_time_init(2005,6,5,10,10,10).months_since(12)
+ assert_equal date_time_init(2007,6,5,10,10,10), date_time_init(2005,6,5,10,10,10).months_since(24)
+ assert_equal date_time_init(2005,4,30,10,10,10), date_time_init(2005,3,31,10,10,10).months_since(1)
+ assert_equal date_time_init(2005,2,28,10,10,10), date_time_init(2005,1,29,10,10,10).months_since(1)
+ assert_equal date_time_init(2005,2,28,10,10,10), date_time_init(2005,1,30,10,10,10).months_since(1)
+ assert_equal date_time_init(2005,2,28,10,10,10), date_time_init(2005,1,31,10,10,10).months_since(1)
+ end
+
+ def test_years_ago
+ assert_equal date_time_init(2004,6,5,10,10,10), date_time_init(2005,6,5,10,10,10).years_ago(1)
+ assert_equal date_time_init(1998,6,5,10,10,10), date_time_init(2005,6,5,10,10,10).years_ago(7)
+ assert_equal date_time_init(2003,2,28,10,10,10), date_time_init(2004,2,29,10,10,10).years_ago(1) # 1 year ago from leap day
+ end
+
+ def test_years_since
+ assert_equal date_time_init(2006,6,5,10,10,10), date_time_init(2005,6,5,10,10,10).years_since(1)
+ assert_equal date_time_init(2012,6,5,10,10,10), date_time_init(2005,6,5,10,10,10).years_since(7)
+ assert_equal date_time_init(2005,2,28,10,10,10), date_time_init(2004,2,29,10,10,10).years_since(1) # 1 year since leap day
+ assert_equal date_time_init(2182,6,5,10,10,10), date_time_init(2005,6,5,10,10,10).years_since(177)
+ end
+
+ def test_beginning_of_month
+ assert_equal date_time_init(2005,2,1,0,0,0), date_time_init(2005,2,22,10,10,10).beginning_of_month
+ end
+
+ def test_beginning_of_quarter
+ assert_equal date_time_init(2005,1,1,0,0,0), date_time_init(2005,2,15,10,10,10).beginning_of_quarter
+ assert_equal date_time_init(2005,1,1,0,0,0), date_time_init(2005,1,1,0,0,0).beginning_of_quarter
+ assert_equal date_time_init(2005,10,1,0,0,0), date_time_init(2005,12,31,10,10,10).beginning_of_quarter
+ assert_equal date_time_init(2005,4,1,0,0,0), date_time_init(2005,6,30,23,59,59).beginning_of_quarter
+ end
+
+ def test_end_of_quarter
+ assert_equal date_time_init(2007,3,31,23,59,59,Rational(999999999, 1000)), date_time_init(2007,2,15,10,10,10).end_of_quarter
+ assert_equal date_time_init(2007,3,31,23,59,59,Rational(999999999, 1000)), date_time_init(2007,3,31,0,0,0).end_of_quarter
+ assert_equal date_time_init(2007,12,31,23,59,59,Rational(999999999, 1000)), date_time_init(2007,12,21,10,10,10).end_of_quarter
+ assert_equal date_time_init(2007,6,30,23,59,59,Rational(999999999, 1000)), date_time_init(2007,4,1,0,0,0).end_of_quarter
+ assert_equal date_time_init(2008,6,30,23,59,59,Rational(999999999, 1000)), date_time_init(2008,5,31,0,0,0).end_of_quarter
+ end
+
+ def test_beginning_of_year
+ assert_equal date_time_init(2005,1,1,0,0,0), date_time_init(2005,2,22,10,10,10).beginning_of_year
+ end
+
+ def test_next_week
+ assert_equal date_time_init(2005,2,28,0,0,0), date_time_init(2005,2,22,15,15,10).next_week
+ assert_equal date_time_init(2005,3,4,0,0,0), date_time_init(2005,2,22,15,15,10).next_week(:friday)
+ assert_equal date_time_init(2006,10,30,0,0,0), date_time_init(2006,10,23,0,0,0).next_week
+ assert_equal date_time_init(2006,11,1,0,0,0), date_time_init(2006,10,23,0,0,0).next_week(:wednesday)
+ end
+
+ def test_next_month_on_31st
+ assert_equal date_time_init(2005,9,30,15,15,10), date_time_init(2005,8,31,15,15,10).next_month
+ end
+
+ def test_next_quarter_on_31st
+ assert_equal date_time_init(2005,11,30,15,15,10), date_time_init(2005,8,31,15,15,10).next_quarter
+ end
+
+ def test_next_year
+ assert_equal date_time_init(2006,6,5,10,10,10), date_time_init(2005,6,5,10,10,10).next_year
+ end
+
+ def test_prev_week
+ assert_equal date_time_init(2005,2,21,0,0,0), date_time_init(2005,3,1,15,15,10).prev_week
+ assert_equal date_time_init(2005,2,22,0,0,0), date_time_init(2005,3,1,15,15,10).prev_week(:tuesday)
+ assert_equal date_time_init(2005,2,25,0,0,0), date_time_init(2005,3,1,15,15,10).prev_week(:friday)
+ assert_equal date_time_init(2006,10,30,0,0,0), date_time_init(2006,11,6,0,0,0).prev_week
+ assert_equal date_time_init(2006,11,15,0,0,0), date_time_init(2006,11,23,0,0,0).prev_week(:wednesday)
+ end
+
+ def test_prev_month_on_31st
+ assert_equal date_time_init(2004,2,29,10,10,10), date_time_init(2004,3,31,10,10,10).prev_month
+ end
+
+ def test_prev_quarter_on_31st
+ assert_equal date_time_init(2004,2,29,10,10,10), date_time_init(2004,5,31,10,10,10).prev_quarter
+ end
+
+ def test_prev_year
+ assert_equal date_time_init(2004,6,5,10,10,10), date_time_init(2005,6,5,10,10,10).prev_year
+ end
+
+ def test_days_to_week_start
+ assert_equal 0, date_time_init(2011,11,01,0,0,0).days_to_week_start(:tuesday)
+ assert_equal 1, date_time_init(2011,11,02,0,0,0).days_to_week_start(:tuesday)
+ assert_equal 2, date_time_init(2011,11,03,0,0,0).days_to_week_start(:tuesday)
+ assert_equal 3, date_time_init(2011,11,04,0,0,0).days_to_week_start(:tuesday)
+ assert_equal 4, date_time_init(2011,11,05,0,0,0).days_to_week_start(:tuesday)
+ assert_equal 5, date_time_init(2011,11,06,0,0,0).days_to_week_start(:tuesday)
+ assert_equal 6, date_time_init(2011,11,07,0,0,0).days_to_week_start(:tuesday)
+
+ assert_equal 3, date_time_init(2011,11,03,0,0,0).days_to_week_start(:monday)
+ assert_equal 3, date_time_init(2011,11,04,0,0,0).days_to_week_start(:tuesday)
+ assert_equal 3, date_time_init(2011,11,05,0,0,0).days_to_week_start(:wednesday)
+ assert_equal 3, date_time_init(2011,11,06,0,0,0).days_to_week_start(:thursday)
+ assert_equal 3, date_time_init(2011,11,07,0,0,0).days_to_week_start(:friday)
+ assert_equal 3, date_time_init(2011,11,8,0,0,0).days_to_week_start(:saturday)
+ assert_equal 3, date_time_init(2011,11,9,0,0,0).days_to_week_start(:sunday)
+ end
+
+ def test_beginning_of_week
+ assert_equal date_time_init(2005,1,31,0,0,0), date_time_init(2005,2,4,10,10,10).beginning_of_week
+ assert_equal date_time_init(2005,11,28,0,0,0), date_time_init(2005,11,28,0,0,0).beginning_of_week #monday
+ assert_equal date_time_init(2005,11,28,0,0,0), date_time_init(2005,11,29,0,0,0).beginning_of_week #tuesday
+ assert_equal date_time_init(2005,11,28,0,0,0), date_time_init(2005,11,30,0,0,0).beginning_of_week #wednesday
+ assert_equal date_time_init(2005,11,28,0,0,0), date_time_init(2005,12,01,0,0,0).beginning_of_week #thursday
+ assert_equal date_time_init(2005,11,28,0,0,0), date_time_init(2005,12,02,0,0,0).beginning_of_week #friday
+ assert_equal date_time_init(2005,11,28,0,0,0), date_time_init(2005,12,03,0,0,0).beginning_of_week #saturday
+ assert_equal date_time_init(2005,11,28,0,0,0), date_time_init(2005,12,04,0,0,0).beginning_of_week #sunday
+ end
+
+ def test_end_of_week
+ assert_equal date_time_init(2008,1,6,23,59,59,Rational(999999999, 1000)), date_time_init(2007,12,31,10,10,10).end_of_week
+ assert_equal date_time_init(2007,9,2,23,59,59,Rational(999999999, 1000)), date_time_init(2007,8,27,0,0,0).end_of_week #monday
+ assert_equal date_time_init(2007,9,2,23,59,59,Rational(999999999, 1000)), date_time_init(2007,8,28,0,0,0).end_of_week #tuesday
+ assert_equal date_time_init(2007,9,2,23,59,59,Rational(999999999, 1000)), date_time_init(2007,8,29,0,0,0).end_of_week #wednesday
+ assert_equal date_time_init(2007,9,2,23,59,59,Rational(999999999, 1000)), date_time_init(2007,8,30,0,0,0).end_of_week #thursday
+ assert_equal date_time_init(2007,9,2,23,59,59,Rational(999999999, 1000)), date_time_init(2007,8,31,0,0,0).end_of_week #friday
+ assert_equal date_time_init(2007,9,2,23,59,59,Rational(999999999, 1000)), date_time_init(2007,9,01,0,0,0).end_of_week #saturday
+ assert_equal date_time_init(2007,9,2,23,59,59,Rational(999999999, 1000)), date_time_init(2007,9,02,0,0,0).end_of_week #sunday
+ end
+
+ def test_end_of_month
+ assert_equal date_time_init(2005,3,31,23,59,59,Rational(999999999, 1000)), date_time_init(2005,3,20,10,10,10).end_of_month
+ assert_equal date_time_init(2005,2,28,23,59,59,Rational(999999999, 1000)), date_time_init(2005,2,20,10,10,10).end_of_month
+ assert_equal date_time_init(2005,4,30,23,59,59,Rational(999999999, 1000)), date_time_init(2005,4,20,10,10,10).end_of_month
+ end
+
+ def test_end_of_year
+ assert_equal date_time_init(2007,12,31,23,59,59,Rational(999999999, 1000)), date_time_init(2007,2,22,10,10,10).end_of_year
+ assert_equal date_time_init(2007,12,31,23,59,59,Rational(999999999, 1000)), date_time_init(2007,12,31,10,10,10).end_of_year
+ end
+end
diff --git a/activesupport/test/core_ext/date_ext_test.rb b/activesupport/test/core_ext/date_ext_test.rb
index 088b74a29a..7ae1f67785 100644
--- a/activesupport/test/core_ext/date_ext_test.rb
+++ b/activesupport/test/core_ext/date_ext_test.rb
@@ -1,7 +1,22 @@
require 'abstract_unit'
require 'active_support/time'
+require 'core_ext/date_and_time_behavior'
class DateExtCalculationsTest < ActiveSupport::TestCase
+ def date_time_init(year,month,day,*args)
+ Date.new(year,month,day)
+ end
+
+ include DateAndTimeBehavior
+
+ def test_yesterday_in_calendar_reform
+ assert_equal Date.new(1582,10,4), Date.new(1582,10,15).yesterday
+ end
+
+ def test_tomorrow_in_calendar_reform
+ assert_equal Date.new(1582,10,15), Date.new(1582,10,4).tomorrow
+ end
+
def test_to_s
date = Date.new(2005, 2, 21)
assert_equal "2005-02-21", date.to_s
@@ -46,22 +61,6 @@ class DateExtCalculationsTest < ActiveSupport::TestCase
assert_equal Date.new(2005,6,22), Date.new(2005,2,22).change(:month => 6)
end
- def test_beginning_of_week
- assert_equal Date.new(2005,1,31), Date.new(2005,2,4).beginning_of_week
- assert_equal Date.new(2005,11,28), Date.new(2005,11,28).beginning_of_week #monday
- assert_equal Date.new(2005,11,28), Date.new(2005,11,29).beginning_of_week #tuesday
- assert_equal Date.new(2005,11,28), Date.new(2005,11,30).beginning_of_week #wednesday
- assert_equal Date.new(2005,11,28), Date.new(2005,12,01).beginning_of_week #thursday
- assert_equal Date.new(2005,11,28), Date.new(2005,12,02).beginning_of_week #friday
- assert_equal Date.new(2005,11,28), Date.new(2005,12,03).beginning_of_week #saturday
- assert_equal Date.new(2005,11,28), Date.new(2005,12,04).beginning_of_week #sunday
- end
-
- def test_monday
- assert_equal Date.new(2005,11,28), Date.new(2005,11,28).monday
- assert_equal Date.new(2005,11,28), Date.new(2005,12,01).monday
- end
-
def test_sunday
assert_equal Date.new(2008,3,2), Date.new(2008,3,02).sunday
assert_equal Date.new(2008,3,2), Date.new(2008,2,29).sunday
@@ -71,41 +70,10 @@ class DateExtCalculationsTest < ActiveSupport::TestCase
assert_equal Date.new(1582,10,1), Date.new(1582,10,15).beginning_of_week #friday
end
- def test_beginning_of_month
- assert_equal Date.new(2005,2,1), Date.new(2005,2,22).beginning_of_month
- end
-
- def test_beginning_of_quarter
- assert_equal Date.new(2005,1,1), Date.new(2005,2,15).beginning_of_quarter
- assert_equal Date.new(2005,1,1), Date.new(2005,1,1).beginning_of_quarter
- assert_equal Date.new(2005,10,1), Date.new(2005,12,31).beginning_of_quarter
- assert_equal Date.new(2005,4,1), Date.new(2005,6,30).beginning_of_quarter
- end
-
- def test_end_of_week
- assert_equal Date.new(2008,2,24), Date.new(2008,2,22).end_of_week
- assert_equal Date.new(2008,3,2), Date.new(2008,2,25).end_of_week #monday
- assert_equal Date.new(2008,3,2), Date.new(2008,2,26).end_of_week #tuesday
- assert_equal Date.new(2008,3,2), Date.new(2008,2,27).end_of_week #wednesday
- assert_equal Date.new(2008,3,2), Date.new(2008,2,28).end_of_week #thursday
- assert_equal Date.new(2008,3,2), Date.new(2008,2,29).end_of_week #friday
- assert_equal Date.new(2008,3,2), Date.new(2008,3,01).end_of_week #saturday
- assert_equal Date.new(2008,3,2), Date.new(2008,3,02).end_of_week #sunday
- end
-
def test_end_of_week_in_calendar_reform
assert_equal Date.new(1582,10,17), Date.new(1582,10,4).end_of_week #thursday
end
- def test_end_of_quarter
- assert_equal Date.new(2008,3,31), Date.new(2008,2,15).end_of_quarter
- assert_equal Date.new(2008,3,31), Date.new(2008,3,31).end_of_quarter
- assert_equal Date.new(2008,12,31), Date.new(2008,10,8).end_of_quarter
- assert_equal Date.new(2008,6,30), Date.new(2008,4,14).end_of_quarter
- assert_equal Date.new(2008,6,30), Date.new(2008,5,31).end_of_quarter
- assert_equal Date.new(2008,9,30), Date.new(2008,8,21).end_of_quarter
- end
-
def test_end_of_year
assert_equal Date.new(2008,12,31).to_s, Date.new(2008,2,22).end_of_year.to_s
end
@@ -116,57 +84,6 @@ class DateExtCalculationsTest < ActiveSupport::TestCase
assert_equal Date.new(2005,4,30), Date.new(2005,4,20).end_of_month
end
- def test_beginning_of_year
- assert_equal Date.new(2005,1,1).to_s, Date.new(2005,2,22).beginning_of_year.to_s
- end
-
- def test_weeks_ago
- assert_equal Date.new(2005,5,10), Date.new(2005,5,17).weeks_ago(1)
- assert_equal Date.new(2005,5,10), Date.new(2005,5,24).weeks_ago(2)
- assert_equal Date.new(2005,5,10), Date.new(2005,5,31).weeks_ago(3)
- assert_equal Date.new(2005,5,10), Date.new(2005,6,7).weeks_ago(4)
- assert_equal Date.new(2006,12,31), Date.new(2007,2,4).weeks_ago(5)
- end
-
- def test_months_ago
- assert_equal Date.new(2005,5,5), Date.new(2005,6,5).months_ago(1)
- assert_equal Date.new(2004,11,5), Date.new(2005,6,5).months_ago(7)
- assert_equal Date.new(2004,12,5), Date.new(2005,6,5).months_ago(6)
- assert_equal Date.new(2004,6,5), Date.new(2005,6,5).months_ago(12)
- assert_equal Date.new(2003,6,5), Date.new(2005,6,5).months_ago(24)
- end
-
- def test_months_since
- assert_equal Date.new(2005,7,5), Date.new(2005,6,5).months_since(1)
- assert_equal Date.new(2006,1,5), Date.new(2005,12,5).months_since(1)
- assert_equal Date.new(2005,12,5), Date.new(2005,6,5).months_since(6)
- assert_equal Date.new(2006,6,5), Date.new(2005,12,5).months_since(6)
- assert_equal Date.new(2006,1,5), Date.new(2005,6,5).months_since(7)
- assert_equal Date.new(2006,6,5), Date.new(2005,6,5).months_since(12)
- assert_equal Date.new(2007,6,5), Date.new(2005,6,5).months_since(24)
- assert_equal Date.new(2005,4,30), Date.new(2005,3,31).months_since(1)
- assert_equal Date.new(2005,2,28), Date.new(2005,1,29).months_since(1)
- assert_equal Date.new(2005,2,28), Date.new(2005,1,30).months_since(1)
- assert_equal Date.new(2005,2,28), Date.new(2005,1,31).months_since(1)
- end
-
- def test_years_ago
- assert_equal Date.new(2004,6,5), Date.new(2005,6,5).years_ago(1)
- assert_equal Date.new(1998,6,5), Date.new(2005,6,5).years_ago(7)
- assert_equal Date.new(2003,2,28), Date.new(2004,2,29).years_ago(1) # 1 year ago from leap day
- end
-
- def test_years_since
- assert_equal Date.new(2006,6,5), Date.new(2005,6,5).years_since(1)
- assert_equal Date.new(2012,6,5), Date.new(2005,6,5).years_since(7)
- assert_equal Date.new(2182,6,5), Date.new(2005,6,5).years_since(177)
- assert_equal Date.new(2005,2,28), Date.new(2004,2,29).years_since(1) # 1 year since leap day
- end
-
- def test_prev_year
- assert_equal Date.new(2004,6,5), Date.new(2005,6,5).prev_year
- end
-
def test_prev_year_in_leap_years
assert_equal Date.new(1999,2,28), Date.new(2000,2,29).prev_year
end
@@ -187,10 +104,6 @@ class DateExtCalculationsTest < ActiveSupport::TestCase
assert_equal Date.new(1582,10,4), Date.new(1583,10,14).last_year
end
- def test_next_year
- assert_equal Date.new(2006,6,5), Date.new(2005,6,5).next_year
- end
-
def test_next_year_in_leap_years
assert_equal Date.new(2001,2,28), Date.new(2000,2,29).next_year
end
@@ -199,24 +112,6 @@ class DateExtCalculationsTest < ActiveSupport::TestCase
assert_equal Date.new(1582,10,4), Date.new(1581,10,10).next_year
end
- def test_yesterday
- assert_equal Date.new(2005,2,21), Date.new(2005,2,22).yesterday
- assert_equal Date.new(2005,2,28), Date.new(2005,3,2).yesterday.yesterday
- end
-
- def test_yesterday_in_calendar_reform
- assert_equal Date.new(1582,10,4), Date.new(1582,10,15).yesterday
- end
-
- def test_tomorrow
- assert_equal Date.new(2005,2,23), Date.new(2005,2,22).tomorrow
- assert_equal Date.new(2005,3,2), Date.new(2005,2,28).tomorrow.tomorrow
- end
-
- def test_tomorrow_in_calendar_reform
- assert_equal Date.new(1582,10,15), Date.new(1582,10,4).tomorrow
- end
-
def test_advance
assert_equal Date.new(2006,2,28), Date.new(2005,2,28).advance(:years => 1)
assert_equal Date.new(2005,6,28), Date.new(2005,2,28).advance(:months => 4)
@@ -249,14 +144,6 @@ class DateExtCalculationsTest < ActiveSupport::TestCase
end
end
- def test_prev_week
- assert_equal Date.new(2005,5,9), Date.new(2005,5,17).prev_week
- assert_equal Date.new(2006,12,25), Date.new(2007,1,7).prev_week
- assert_equal Date.new(2010,2,12), Date.new(2010,2,19).prev_week(:friday)
- assert_equal Date.new(2010,2,13), Date.new(2010,2,19).prev_week(:saturday)
- assert_equal Date.new(2010,2,27), Date.new(2010,3,4).prev_week(:saturday)
- end
-
def test_last_week
assert_equal Date.new(2005,5,9), Date.new(2005,5,17).last_week
assert_equal Date.new(2006,12,25), Date.new(2007,1,7).last_week
@@ -265,38 +152,15 @@ class DateExtCalculationsTest < ActiveSupport::TestCase
assert_equal Date.new(2010,2,27), Date.new(2010,3,4).last_week(:saturday)
end
- def test_next_week
- assert_equal Date.new(2005,2,28), Date.new(2005,2,22).next_week
- assert_equal Date.new(2005,3,4), Date.new(2005,2,22).next_week(:friday)
- assert_equal Date.new(2006,10,30), Date.new(2006,10,23).next_week
- assert_equal Date.new(2006,11,1), Date.new(2006,10,23).next_week(:wednesday)
- end
-
def test_next_week_in_calendar_reform
assert_equal Date.new(1582,10,15), Date.new(1582,9,30).next_week(:friday)
assert_equal Date.new(1582,10,18), Date.new(1582,10,4).next_week
end
- def test_next_month_on_31st
- assert_equal Date.new(2005, 9, 30), Date.new(2005, 8, 31).next_month
- end
-
- def test_prev_month_on_31st
- assert_equal Date.new(2004, 2, 29), Date.new(2004, 3, 31).prev_month
- end
-
def test_last_month_on_31st
assert_equal Date.new(2004, 2, 29), Date.new(2004, 3, 31).last_month
end
- def test_next_quarter_on_31st
- assert_equal Date.new(2005, 11, 30), Date.new(2005, 8, 31).next_quarter
- end
-
- def test_prev_quarter_on_31st
- assert_equal Date.new(2004, 2, 29), Date.new(2004, 5, 31).prev_quarter
- end
-
def test_last_quarter_on_31st
assert_equal Date.new(2004, 2, 29), Date.new(2004, 5, 31).last_quarter
end
@@ -420,13 +284,6 @@ class DateExtCalculationsTest < ActiveSupport::TestCase
end
end
- def test_today
- Date.stubs(:current).returns(Date.new(2000, 1, 1))
- assert_equal false, Date.new(1999, 12, 31).today?
- assert_equal true, Date.new(2000,1,1).today?
- assert_equal false, Date.new(2000,1,2).today?
- end
-
def test_past
Date.stubs(:current).returns(Date.new(2000, 1, 1))
assert_equal true, Date.new(1999, 12, 31).past?
diff --git a/activesupport/test/core_ext/date_time_ext_test.rb b/activesupport/test/core_ext/date_time_ext_test.rb
index 21b7efdc73..b1d1e8ecb4 100644
--- a/activesupport/test/core_ext/date_time_ext_test.rb
+++ b/activesupport/test/core_ext/date_time_ext_test.rb
@@ -1,7 +1,14 @@
require 'abstract_unit'
require 'active_support/time'
+require 'core_ext/date_and_time_behavior'
class DateTimeExtCalculationsTest < ActiveSupport::TestCase
+ def date_time_init(year,month,day,hour,minute,second,*args)
+ DateTime.civil(year,month,day,hour,minute,second)
+ end
+
+ include DateAndTimeBehavior
+
def test_to_s
datetime = DateTime.new(2005, 2, 21, 14, 30, 0, 0)
assert_equal "2005-02-21 14:30:00", datetime.to_s(:db)
@@ -54,35 +61,6 @@ class DateTimeExtCalculationsTest < ActiveSupport::TestCase
assert_equal 86399,DateTime.civil(2005,1,1,23,59,59).seconds_since_midnight
end
- def test_days_to_week_start
- assert_equal 0, Time.local(2011,11,01,0,0,0).days_to_week_start(:tuesday)
- assert_equal 1, Time.local(2011,11,02,0,0,0).days_to_week_start(:tuesday)
- assert_equal 2, Time.local(2011,11,03,0,0,0).days_to_week_start(:tuesday)
- assert_equal 3, Time.local(2011,11,04,0,0,0).days_to_week_start(:tuesday)
- assert_equal 4, Time.local(2011,11,05,0,0,0).days_to_week_start(:tuesday)
- assert_equal 5, Time.local(2011,11,06,0,0,0).days_to_week_start(:tuesday)
- assert_equal 6, Time.local(2011,11,07,0,0,0).days_to_week_start(:tuesday)
-
- assert_equal 3, Time.local(2011,11,03,0,0,0).days_to_week_start(:monday)
- assert_equal 3, Time.local(2011,11,04,0,0,0).days_to_week_start(:tuesday)
- assert_equal 3, Time.local(2011,11,05,0,0,0).days_to_week_start(:wednesday)
- assert_equal 3, Time.local(2011,11,06,0,0,0).days_to_week_start(:thursday)
- assert_equal 3, Time.local(2011,11,07,0,0,0).days_to_week_start(:friday)
- assert_equal 3, Time.local(2011,11,8,0,0,0).days_to_week_start(:saturday)
- assert_equal 3, Time.local(2011,11,9,0,0,0).days_to_week_start(:sunday)
- end
-
- def test_beginning_of_week
- assert_equal DateTime.civil(2005,1,31), DateTime.civil(2005,2,4,10,10,10).beginning_of_week
- assert_equal DateTime.civil(2005,11,28), DateTime.civil(2005,11,28,0,0,0).beginning_of_week #monday
- assert_equal DateTime.civil(2005,11,28), DateTime.civil(2005,11,29,0,0,0).beginning_of_week #tuesday
- assert_equal DateTime.civil(2005,11,28), DateTime.civil(2005,11,30,0,0,0).beginning_of_week #wednesday
- assert_equal DateTime.civil(2005,11,28), DateTime.civil(2005,12,01,0,0,0).beginning_of_week #thursday
- assert_equal DateTime.civil(2005,11,28), DateTime.civil(2005,12,02,0,0,0).beginning_of_week #friday
- assert_equal DateTime.civil(2005,11,28), DateTime.civil(2005,12,03,0,0,0).beginning_of_week #saturday
- assert_equal DateTime.civil(2005,11,28), DateTime.civil(2005,12,04,0,0,0).beginning_of_week #sunday
- end
-
def test_beginning_of_day
assert_equal DateTime.civil(2005,2,4,0,0,0), DateTime.civil(2005,2,4,10,10,10).beginning_of_day
end
@@ -99,82 +77,16 @@ class DateTimeExtCalculationsTest < ActiveSupport::TestCase
assert_equal DateTime.civil(2005,2,4,19,59,59), DateTime.civil(2005,2,4,19,30,10).end_of_hour
end
- def test_beginning_of_month
- assert_equal DateTime.civil(2005,2,1,0,0,0), DateTime.civil(2005,2,22,10,10,10).beginning_of_month
- end
-
- def test_beginning_of_quarter
- assert_equal DateTime.civil(2005,1,1,0,0,0), DateTime.civil(2005,2,15,10,10,10).beginning_of_quarter
- assert_equal DateTime.civil(2005,1,1,0,0,0), DateTime.civil(2005,1,1,0,0,0).beginning_of_quarter
- assert_equal DateTime.civil(2005,10,1,0,0,0), DateTime.civil(2005,12,31,10,10,10).beginning_of_quarter
- assert_equal DateTime.civil(2005,4,1,0,0,0), DateTime.civil(2005,6,30,23,59,59).beginning_of_quarter
- end
-
def test_end_of_month
assert_equal DateTime.civil(2005,3,31,23,59,59), DateTime.civil(2005,3,20,10,10,10).end_of_month
assert_equal DateTime.civil(2005,2,28,23,59,59), DateTime.civil(2005,2,20,10,10,10).end_of_month
assert_equal DateTime.civil(2005,4,30,23,59,59), DateTime.civil(2005,4,20,10,10,10).end_of_month
end
- def test_beginning_of_year
- assert_equal DateTime.civil(2005,1,1,0,0,0), DateTime.civil(2005,2,22,10,10,10).beginning_of_year
- end
-
- def test_weeks_ago
- assert_equal DateTime.civil(2005,5,29,10), DateTime.civil(2005,6,5,10,0,0).weeks_ago(1)
- assert_equal DateTime.civil(2005,5,1,10), DateTime.civil(2005,6,5,10,0,0).weeks_ago(5)
- assert_equal DateTime.civil(2005,4,24,10), DateTime.civil(2005,6,5,10,0,0).weeks_ago(6)
- assert_equal DateTime.civil(2005,2,27,10), DateTime.civil(2005,6,5,10,0,0).weeks_ago(14)
- assert_equal DateTime.civil(2004,12,25,10), DateTime.civil(2005,1,1,10,0,0).weeks_ago(1)
- end
-
- def test_months_ago
- assert_equal DateTime.civil(2005,5,5,10), DateTime.civil(2005,6,5,10,0,0).months_ago(1)
- assert_equal DateTime.civil(2004,11,5,10), DateTime.civil(2005,6,5,10,0,0).months_ago(7)
- assert_equal DateTime.civil(2004,12,5,10), DateTime.civil(2005,6,5,10,0,0).months_ago(6)
- assert_equal DateTime.civil(2004,6,5,10), DateTime.civil(2005,6,5,10,0,0).months_ago(12)
- assert_equal DateTime.civil(2003,6,5,10), DateTime.civil(2005,6,5,10,0,0).months_ago(24)
- end
-
- def test_months_since
- assert_equal DateTime.civil(2005,7,5,10), DateTime.civil(2005,6,5,10,0,0).months_since(1)
- assert_equal DateTime.civil(2006,1,5,10), DateTime.civil(2005,12,5,10,0,0).months_since(1)
- assert_equal DateTime.civil(2005,12,5,10), DateTime.civil(2005,6,5,10,0,0).months_since(6)
- assert_equal DateTime.civil(2006,6,5,10), DateTime.civil(2005,12,5,10,0,0).months_since(6)
- assert_equal DateTime.civil(2006,1,5,10), DateTime.civil(2005,6,5,10,0,0).months_since(7)
- assert_equal DateTime.civil(2006,6,5,10), DateTime.civil(2005,6,5,10,0,0).months_since(12)
- assert_equal DateTime.civil(2007,6,5,10), DateTime.civil(2005,6,5,10,0,0).months_since(24)
- assert_equal DateTime.civil(2005,4,30,10), DateTime.civil(2005,3,31,10,0,0).months_since(1)
- assert_equal DateTime.civil(2005,2,28,10), DateTime.civil(2005,1,29,10,0,0).months_since(1)
- assert_equal DateTime.civil(2005,2,28,10), DateTime.civil(2005,1,30,10,0,0).months_since(1)
- assert_equal DateTime.civil(2005,2,28,10), DateTime.civil(2005,1,31,10,0,0).months_since(1)
- end
-
- def test_years_ago
- assert_equal DateTime.civil(2004,6,5,10), DateTime.civil(2005,6,5,10,0,0).years_ago(1)
- assert_equal DateTime.civil(1998,6,5,10), DateTime.civil(2005,6,5,10,0,0).years_ago(7)
- assert_equal DateTime.civil(2003,2,28,10), DateTime.civil(2004,2,29,10,0,0).years_ago(1) # 1 year ago from leap day
- end
-
- def test_years_since
- assert_equal DateTime.civil(2006,6,5,10), DateTime.civil(2005,6,5,10,0,0).years_since(1)
- assert_equal DateTime.civil(2012,6,5,10), DateTime.civil(2005,6,5,10,0,0).years_since(7)
- assert_equal DateTime.civil(2182,6,5,10), DateTime.civil(2005,6,5,10,0,0).years_since(177)
- assert_equal DateTime.civil(2005,2,28,10), DateTime.civil(2004,2,29,10,0,0).years_since(1) # 1 year since leap day
- end
-
- def test_prev_year
- assert_equal DateTime.civil(2004,6,5,10), DateTime.civil(2005,6,5,10,0,0).prev_year
- end
-
def test_last_year
assert_equal DateTime.civil(2004,6,5,10), DateTime.civil(2005,6,5,10,0,0).last_year
end
- def test_next_year
- assert_equal DateTime.civil(2006,6,5,10), DateTime.civil(2005,6,5,10,0,0).next_year
- end
-
def test_ago
assert_equal DateTime.civil(2005,2,22,10,10,9), DateTime.civil(2005,2,22,10,10,10).ago(1)
assert_equal DateTime.civil(2005,2,22,9,10,10), DateTime.civil(2005,2,22,10,10,10).ago(3600)
@@ -191,16 +103,6 @@ class DateTimeExtCalculationsTest < ActiveSupport::TestCase
assert_equal DateTime.civil(2005,2,22,10,10,12), DateTime.civil(2005,2,22,10,10,10).since(1.667)
end
- def test_yesterday
- assert_equal DateTime.civil(2005,2,21,10,10,10), DateTime.civil(2005,2,22,10,10,10).yesterday
- assert_equal DateTime.civil(2005,2,28,10,10,10), DateTime.civil(2005,3,2,10,10,10).yesterday.yesterday
- end
-
- def test_tomorrow
- assert_equal DateTime.civil(2005,2,23,10,10,10), DateTime.civil(2005,2,22,10,10,10).tomorrow
- assert_equal DateTime.civil(2005,3,2,10,10,10), DateTime.civil(2005,2,28,10,10,10).tomorrow.tomorrow
- end
-
def test_change
assert_equal DateTime.civil(2006,2,22,15,15,10), DateTime.civil(2005,2,22,15,15,10).change(:year => 2006)
assert_equal DateTime.civil(2005,6,22,15,15,10), DateTime.civil(2005,2,22,15,15,10).change(:month => 6)
@@ -236,14 +138,6 @@ class DateTimeExtCalculationsTest < ActiveSupport::TestCase
assert_equal DateTime.civil(2010, 3, 29), DateTime.civil(2010, 2, 28, 22, 58, 59).advance(:months => 1, :hours => 1, :minutes => 1, :seconds => 1)
end
- def test_prev_week
- assert_equal DateTime.civil(2005,2,21), DateTime.civil(2005,3,1,15,15,10).prev_week
- assert_equal DateTime.civil(2005,2,22), DateTime.civil(2005,3,1,15,15,10).prev_week(:tuesday)
- assert_equal DateTime.civil(2005,2,25), DateTime.civil(2005,3,1,15,15,10).prev_week(:friday)
- assert_equal DateTime.civil(2006,10,30), DateTime.civil(2006,11,6,0,0,0).prev_week
- assert_equal DateTime.civil(2006,11,15), DateTime.civil(2006,11,23,0,0,0).prev_week(:wednesday)
- end
-
def test_last_week
assert_equal DateTime.civil(2005,2,21), DateTime.civil(2005,3,1,15,15,10).last_week
assert_equal DateTime.civil(2005,2,22), DateTime.civil(2005,3,1,15,15,10).last_week(:tuesday)
@@ -252,33 +146,10 @@ class DateTimeExtCalculationsTest < ActiveSupport::TestCase
assert_equal DateTime.civil(2006,11,15), DateTime.civil(2006,11,23,0,0,0).last_week(:wednesday)
end
- def test_next_week
- assert_equal DateTime.civil(2005,2,28), DateTime.civil(2005,2,22,15,15,10).next_week
- assert_equal DateTime.civil(2005,3,4), DateTime.civil(2005,2,22,15,15,10).next_week(:friday)
- assert_equal DateTime.civil(2006,10,30), DateTime.civil(2006,10,23,0,0,0).next_week
- assert_equal DateTime.civil(2006,11,1), DateTime.civil(2006,10,23,0,0,0).next_week(:wednesday)
- end
-
- def test_next_month_on_31st
- assert_equal DateTime.civil(2005, 9, 30), DateTime.civil(2005, 8, 31).next_month
- end
-
- def test_prev_month_on_31st
- assert_equal DateTime.civil(2004, 2, 29), DateTime.civil(2004, 3, 31).prev_month
- end
-
def test_last_month_on_31st
assert_equal DateTime.civil(2004, 2, 29), DateTime.civil(2004, 3, 31).last_month
end
- def test_next_quarter_on_31st
- assert_equal DateTime.civil(2005, 11, 30), DateTime.civil(2005, 8, 31).next_quarter
- end
-
- def test_prev_quarter_on_31st
- assert_equal DateTime.civil(2004, 2, 29), DateTime.civil(2004, 5, 31).prev_quarter
- end
-
def test_last_quarter_on_31st
assert_equal DateTime.civil(2004, 2, 29), DateTime.civil(2004, 5, 31).last_quarter
end
diff --git a/activesupport/test/core_ext/file_test.rb b/activesupport/test/core_ext/file_test.rb
index 128e956a8c..2c04e9687c 100644
--- a/activesupport/test/core_ext/file_test.rb
+++ b/activesupport/test/core_ext/file_test.rb
@@ -51,7 +51,7 @@ class AtomicWriteTest < ActiveSupport::TestCase
assert !File.exist?(file_name)
end
assert File.exist?(file_name)
- assert_equal 0100666 & ~File.umask, file_mode
+ assert_equal File.probe_stat_in(Dir.pwd).mode, file_mode
assert_equal contents, File.read(file_name)
ensure
File.unlink(file_name) rescue nil
diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb
index 4dc9f57038..37fdf1c0af 100644
--- a/activesupport/test/core_ext/hash_ext_test.rb
+++ b/activesupport/test/core_ext/hash_ext_test.rb
@@ -428,6 +428,29 @@ class HashExtTest < ActiveSupport::TestCase
assert_equal 2, hash['b']
end
+ def test_indifferent_merging_with_block
+ hash = HashWithIndifferentAccess.new
+ hash[:a] = 1
+ hash['b'] = 3
+
+ other = { 'a' => 4, :b => 2, 'c' => 10 }
+
+ merged = hash.merge(other) { |key, old, new| old > new ? old : new }
+
+ assert_equal HashWithIndifferentAccess, merged.class
+ assert_equal 4, merged[:a]
+ assert_equal 3, merged['b']
+ assert_equal 10, merged[:c]
+
+ other_indifferent = HashWithIndifferentAccess.new('a' => 9, :b => 2)
+
+ merged = hash.merge(other_indifferent) { |key, old, new| old + new }
+
+ assert_equal HashWithIndifferentAccess, merged.class
+ assert_equal 10, merged[:a]
+ assert_equal 5, merged[:b]
+ end
+
def test_indifferent_reverse_merging
hash = HashWithIndifferentAccess.new('some' => 'value', 'other' => 'value')
hash.reverse_merge!(:some => 'noclobber', :another => 'clobber')
diff --git a/activesupport/test/core_ext/module/qualified_const_test.rb b/activesupport/test/core_ext/module/qualified_const_test.rb
index 8af0b9a023..343a848a42 100644
--- a/activesupport/test/core_ext/module/qualified_const_test.rb
+++ b/activesupport/test/core_ext/module/qualified_const_test.rb
@@ -67,17 +67,24 @@ class QualifiedConstTest < ActiveSupport::TestCase
end
test "qualified_const_set" do
- m = Module.new
- assert_equal m, Object.qualified_const_set("QualifiedConstTestMod2", m)
- assert_equal m, ::QualifiedConstTestMod2
-
- # We are going to assign to existing constants on purpose, so silence warnings.
- silence_warnings do
- assert_equal true, QualifiedConstTestMod.qualified_const_set("QualifiedConstTestMod::X", true)
- assert_equal true, QualifiedConstTestMod::X
-
- assert_equal 10, QualifiedConstTestMod::M.qualified_const_set("X", 10)
- assert_equal 10, QualifiedConstTestMod::M::X
+ begin
+ m = Module.new
+ assert_equal m, Object.qualified_const_set("QualifiedConstTestMod2", m)
+ assert_equal m, ::QualifiedConstTestMod2
+
+ # We are going to assign to existing constants on purpose, so silence warnings.
+ silence_warnings do
+ assert_equal true, QualifiedConstTestMod.qualified_const_set("QualifiedConstTestMod::X", true)
+ assert_equal true, QualifiedConstTestMod::X
+
+ assert_equal 10, QualifiedConstTestMod::M.qualified_const_set("X", 10)
+ assert_equal 10, QualifiedConstTestMod::M::X
+ end
+ ensure
+ silence_warnings do
+ QualifiedConstTestMod.qualified_const_set('QualifiedConstTestMod::X', false)
+ QualifiedConstTestMod::M.qualified_const_set('X', 1)
+ end
end
end
diff --git a/activesupport/test/core_ext/object_and_class_ext_test.rb b/activesupport/test/core_ext/object_and_class_ext_test.rb
index 98ab82609e..ec7dd6d4fb 100644
--- a/activesupport/test/core_ext/object_and_class_ext_test.rb
+++ b/activesupport/test/core_ext/object_and_class_ext_test.rb
@@ -99,13 +99,25 @@ class ObjectTryTest < ActiveSupport::TestCase
def test_nonexisting_method
method = :undefined_method
assert !@string.respond_to?(method)
- assert_raise(NoMethodError) { @string.try(method) }
+ assert_nil @string.try(method)
end
def test_nonexisting_method_with_arguments
method = :undefined_method
assert !@string.respond_to?(method)
- assert_raise(NoMethodError) { @string.try(method, 'llo', 'y') }
+ assert_nil @string.try(method, 'llo', 'y')
+ end
+
+ def test_nonexisting_method_bang
+ method = :undefined_method
+ assert !@string.respond_to?(method)
+ assert_raise(NoMethodError) { @string.try!(method) }
+ end
+
+ def test_nonexisting_method_with_arguments_bang
+ method = :undefined_method
+ assert !@string.respond_to?(method)
+ assert_raise(NoMethodError) { @string.try!(method, 'llo', 'y') }
end
def test_valid_method
@@ -139,6 +151,18 @@ class ObjectTryTest < ActiveSupport::TestCase
assert_equal false, ran
end
+ def test_try_with_private_method_bang
+ klass = Class.new do
+ private
+
+ def private_method
+ 'private method'
+ end
+ end
+
+ assert_raise(NoMethodError) { klass.new.try!(:private_method) }
+ end
+
def test_try_with_private_method
klass = Class.new do
private
@@ -148,6 +172,6 @@ class ObjectTryTest < ActiveSupport::TestCase
end
end
- assert_raise(NoMethodError) { klass.new.try(:private_method) }
+ assert_nil klass.new.try(:private_method)
end
end
diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb
index e5b774425e..dc5ae0eafc 100644
--- a/activesupport/test/core_ext/string_ext_test.rb
+++ b/activesupport/test/core_ext/string_ext_test.rb
@@ -9,6 +9,7 @@ require 'active_support/core_ext/string'
require 'active_support/time'
require 'active_support/core_ext/string/strip'
require 'active_support/core_ext/string/output_safety'
+require 'active_support/core_ext/string/indent'
module Ace
module Base
@@ -498,8 +499,8 @@ class OutputSafetyTest < ActiveSupport::TestCase
end
test "ERB::Util.html_escape should escape unsafe characters" do
- string = '<>&"'
- expected = '&lt;&gt;&amp;&quot;'
+ string = '<>&"\''
+ expected = '&lt;&gt;&amp;&quot;&#x27;'
assert_equal expected, ERB::Util.html_escape(string)
end
@@ -521,3 +522,58 @@ class StringExcludeTest < ActiveSupport::TestCase
assert_equal true, 'foo'.exclude?('p')
end
end
+
+class StringIndentTest < ActiveSupport::TestCase
+ test 'does not indent strings that only contain newlines (edge cases)' do
+ ['', "\n", "\n" * 7].each do |str|
+ assert_nil str.indent!(8)
+ assert_equal str, str.indent(8)
+ assert_equal str, str.indent(1, "\t")
+ end
+ end
+
+ test "by default, indents with spaces if the existing indentation uses them" do
+ assert_equal " foo\n bar", "foo\n bar".indent(4)
+ end
+
+ test "by default, indents with tabs if the existing indentation uses them" do
+ assert_equal "\tfoo\n\t\t\bar", "foo\n\t\bar".indent(1)
+ end
+
+ test "by default, indents with spaces as a fallback if there is no indentation" do
+ assert_equal " foo\n bar\n baz", "foo\nbar\nbaz".indent(3)
+ end
+
+ # Nothing is said about existing indentation that mixes spaces and tabs, so
+ # there is nothing to test.
+
+ test 'uses the indent char if passed' do
+ assert_equal <<EXPECTED, <<ACTUAL.indent(4, '.')
+.... def some_method(x, y)
+.... some_code
+.... end
+EXPECTED
+ def some_method(x, y)
+ some_code
+ end
+ACTUAL
+
+ assert_equal <<EXPECTED, <<ACTUAL.indent(2, '&nbsp;')
+&nbsp;&nbsp;&nbsp;&nbsp;def some_method(x, y)
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;some_code
+&nbsp;&nbsp;&nbsp;&nbsp;end
+EXPECTED
+&nbsp;&nbsp;def some_method(x, y)
+&nbsp;&nbsp;&nbsp;&nbsp;some_code
+&nbsp;&nbsp;end
+ACTUAL
+ end
+
+ test "does not indent blank lines by default" do
+ assert_equal " foo\n\n bar", "foo\n\nbar".indent(1)
+ end
+
+ test 'indents blank lines if told so' do
+ assert_equal " foo\n \n bar", "foo\n\nbar".indent(1, nil, true)
+ end
+end
diff --git a/activesupport/test/core_ext/time_ext_test.rb b/activesupport/test/core_ext/time_ext_test.rb
index 412aef9301..6d6757a1b6 100644
--- a/activesupport/test/core_ext/time_ext_test.rb
+++ b/activesupport/test/core_ext/time_ext_test.rb
@@ -1,7 +1,14 @@
require 'abstract_unit'
require 'active_support/time'
+require 'core_ext/date_and_time_behavior'
class TimeExtCalculationsTest < ActiveSupport::TestCase
+ def date_time_init(year,month,day,hour,minute,second,usec=0)
+ Time.local(year,month,day,hour,minute,second,usec)
+ end
+
+ include DateAndTimeBehavior
+
def test_seconds_since_midnight
assert_equal 1,Time.local(2005,1,1,0,0,1).seconds_since_midnight
assert_equal 60,Time.local(2005,1,1,0,1,0).seconds_since_midnight
@@ -50,37 +57,6 @@ class TimeExtCalculationsTest < ActiveSupport::TestCase
end
end
- def test_beginning_of_week
- assert_equal Time.local(2005,1,31), Time.local(2005,2,4,10,10,10).beginning_of_week
- assert_equal Time.local(2005,11,28), Time.local(2005,11,28,0,0,0).beginning_of_week #monday
- assert_equal Time.local(2005,11,28), Time.local(2005,11,29,0,0,0).beginning_of_week #tuesday
- assert_equal Time.local(2005,11,28), Time.local(2005,11,30,0,0,0).beginning_of_week #wednesday
- assert_equal Time.local(2005,11,28), Time.local(2005,12,01,0,0,0).beginning_of_week #thursday
- assert_equal Time.local(2005,11,28), Time.local(2005,12,02,0,0,0).beginning_of_week #friday
- assert_equal Time.local(2005,11,28), Time.local(2005,12,03,0,0,0).beginning_of_week #saturday
- assert_equal Time.local(2005,11,28), Time.local(2005,12,04,0,0,0).beginning_of_week #sunday
-
- end
-
- def test_days_to_week_start
- assert_equal 0, Time.local(2011,11,01,0,0,0).days_to_week_start(:tuesday)
- assert_equal 1, Time.local(2011,11,02,0,0,0).days_to_week_start(:tuesday)
- assert_equal 2, Time.local(2011,11,03,0,0,0).days_to_week_start(:tuesday)
- assert_equal 3, Time.local(2011,11,04,0,0,0).days_to_week_start(:tuesday)
- assert_equal 4, Time.local(2011,11,05,0,0,0).days_to_week_start(:tuesday)
- assert_equal 5, Time.local(2011,11,06,0,0,0).days_to_week_start(:tuesday)
- assert_equal 6, Time.local(2011,11,07,0,0,0).days_to_week_start(:tuesday)
-
- assert_equal 3, Time.local(2011,11,03,0,0,0).days_to_week_start(:monday)
- assert_equal 3, Time.local(2011,11,04,0,0,0).days_to_week_start(:tuesday)
- assert_equal 3, Time.local(2011,11,05,0,0,0).days_to_week_start(:wednesday)
- assert_equal 3, Time.local(2011,11,06,0,0,0).days_to_week_start(:thursday)
- assert_equal 3, Time.local(2011,11,07,0,0,0).days_to_week_start(:friday)
- assert_equal 3, Time.local(2011,11,8,0,0,0).days_to_week_start(:saturday)
- assert_equal 3, Time.local(2011,11,9,0,0,0).days_to_week_start(:sunday)
- end
-
-
def test_beginning_of_day
assert_equal Time.local(2005,2,4,0,0,0), Time.local(2005,2,4,10,10,10).beginning_of_day
with_env_tz 'US/Eastern' do
@@ -97,17 +73,6 @@ class TimeExtCalculationsTest < ActiveSupport::TestCase
assert_equal Time.local(2005,2,4,19,0,0), Time.local(2005,2,4,19,30,10).beginning_of_hour
end
- def test_beginning_of_month
- assert_equal Time.local(2005,2,1,0,0,0), Time.local(2005,2,22,10,10,10).beginning_of_month
- end
-
- def test_beginning_of_quarter
- assert_equal Time.local(2005,1,1,0,0,0), Time.local(2005,2,15,10,10,10).beginning_of_quarter
- assert_equal Time.local(2005,1,1,0,0,0), Time.local(2005,1,1,0,0,0).beginning_of_quarter
- assert_equal Time.local(2005,10,1,0,0,0), Time.local(2005,12,31,10,10,10).beginning_of_quarter
- assert_equal Time.local(2005,4,1,0,0,0), Time.local(2005,6,30,23,59,59).beginning_of_quarter
- end
-
def test_end_of_day
assert_equal Time.local(2007,8,12,23,59,59,Rational(999999999, 1000)), Time.local(2007,8,12,10,10,10).end_of_day
with_env_tz 'US/Eastern' do
@@ -120,100 +85,14 @@ class TimeExtCalculationsTest < ActiveSupport::TestCase
end
end
- def test_end_of_week
- assert_equal Time.local(2008,1,6,23,59,59,Rational(999999999, 1000)), Time.local(2007,12,31,10,10,10).end_of_week
- assert_equal Time.local(2007,9,2,23,59,59,Rational(999999999, 1000)), Time.local(2007,8,27,0,0,0).end_of_week #monday
- assert_equal Time.local(2007,9,2,23,59,59,Rational(999999999, 1000)), Time.local(2007,8,28,0,0,0).end_of_week #tuesday
- assert_equal Time.local(2007,9,2,23,59,59,Rational(999999999, 1000)), Time.local(2007,8,29,0,0,0).end_of_week #wednesday
- assert_equal Time.local(2007,9,2,23,59,59,Rational(999999999, 1000)), Time.local(2007,8,30,0,0,0).end_of_week #thursday
- assert_equal Time.local(2007,9,2,23,59,59,Rational(999999999, 1000)), Time.local(2007,8,31,0,0,0).end_of_week #friday
- assert_equal Time.local(2007,9,2,23,59,59,Rational(999999999, 1000)), Time.local(2007,9,01,0,0,0).end_of_week #saturday
- assert_equal Time.local(2007,9,2,23,59,59,Rational(999999999, 1000)), Time.local(2007,9,02,0,0,0).end_of_week #sunday
- end
-
def test_end_of_hour
assert_equal Time.local(2005,2,4,19,59,59,Rational(999999999, 1000)), Time.local(2005,2,4,19,30,10).end_of_hour
end
- def test_end_of_month
- assert_equal Time.local(2005,3,31,23,59,59,Rational(999999999, 1000)), Time.local(2005,3,20,10,10,10).end_of_month
- assert_equal Time.local(2005,2,28,23,59,59,Rational(999999999, 1000)), Time.local(2005,2,20,10,10,10).end_of_month
- assert_equal Time.local(2005,4,30,23,59,59,Rational(999999999, 1000)), Time.local(2005,4,20,10,10,10).end_of_month
- end
-
- def test_end_of_quarter
- assert_equal Time.local(2007,3,31,23,59,59,Rational(999999999, 1000)), Time.local(2007,2,15,10,10,10).end_of_quarter
- assert_equal Time.local(2007,3,31,23,59,59,Rational(999999999, 1000)), Time.local(2007,3,31,0,0,0).end_of_quarter
- assert_equal Time.local(2007,12,31,23,59,59,Rational(999999999, 1000)), Time.local(2007,12,21,10,10,10).end_of_quarter
- assert_equal Time.local(2007,6,30,23,59,59,Rational(999999999, 1000)), Time.local(2007,4,1,0,0,0).end_of_quarter
- assert_equal Time.local(2008,6,30,23,59,59,Rational(999999999, 1000)), Time.local(2008,5,31,0,0,0).end_of_quarter
- end
-
- def test_end_of_year
- assert_equal Time.local(2007,12,31,23,59,59,Rational(999999999, 1000)), Time.local(2007,2,22,10,10,10).end_of_year
- assert_equal Time.local(2007,12,31,23,59,59,Rational(999999999, 1000)), Time.local(2007,12,31,10,10,10).end_of_year
- end
-
- def test_beginning_of_year
- assert_equal Time.local(2005,1,1,0,0,0), Time.local(2005,2,22,10,10,10).beginning_of_year
- end
-
- def test_weeks_ago
- assert_equal Time.local(2005,5,29,10), Time.local(2005,6,5,10,0,0).weeks_ago(1)
- assert_equal Time.local(2005,5,1,10), Time.local(2005,6,5,10,0,0).weeks_ago(5)
- assert_equal Time.local(2005,4,24,10), Time.local(2005,6,5,10,0,0).weeks_ago(6)
- assert_equal Time.local(2005,2,27,10), Time.local(2005,6,5,10,0,0).weeks_ago(14)
- assert_equal Time.local(2004,12,25,10), Time.local(2005,1,1,10,0,0).weeks_ago(1)
- end
-
- def test_months_ago
- assert_equal Time.local(2005,5,5,10), Time.local(2005,6,5,10,0,0).months_ago(1)
- assert_equal Time.local(2004,11,5,10), Time.local(2005,6,5,10,0,0).months_ago(7)
- assert_equal Time.local(2004,12,5,10), Time.local(2005,6,5,10,0,0).months_ago(6)
- assert_equal Time.local(2004,6,5,10), Time.local(2005,6,5,10,0,0).months_ago(12)
- assert_equal Time.local(2003,6,5,10), Time.local(2005,6,5,10,0,0).months_ago(24)
- end
-
- def test_months_since
- assert_equal Time.local(2005,7,5,10), Time.local(2005,6,5,10,0,0).months_since(1)
- assert_equal Time.local(2006,1,5,10), Time.local(2005,12,5,10,0,0).months_since(1)
- assert_equal Time.local(2005,12,5,10), Time.local(2005,6,5,10,0,0).months_since(6)
- assert_equal Time.local(2006,6,5,10), Time.local(2005,12,5,10,0,0).months_since(6)
- assert_equal Time.local(2006,1,5,10), Time.local(2005,6,5,10,0,0).months_since(7)
- assert_equal Time.local(2006,6,5,10), Time.local(2005,6,5,10,0,0).months_since(12)
- assert_equal Time.local(2007,6,5,10), Time.local(2005,6,5,10,0,0).months_since(24)
- assert_equal Time.local(2005,4,30,10), Time.local(2005,3,31,10,0,0).months_since(1)
- assert_equal Time.local(2005,2,28,10), Time.local(2005,1,29,10,0,0).months_since(1)
- assert_equal Time.local(2005,2,28,10), Time.local(2005,1,30,10,0,0).months_since(1)
- assert_equal Time.local(2005,2,28,10), Time.local(2005,1,31,10,0,0).months_since(1)
- end
-
- def test_years_ago
- assert_equal Time.local(2004,6,5,10), Time.local(2005,6,5,10,0,0).years_ago(1)
- assert_equal Time.local(1998,6,5,10), Time.local(2005,6,5,10,0,0).years_ago(7)
- assert_equal Time.local(2003,2,28,10), Time.local(2004,2,29,10,0,0).years_ago(1) # 1 year ago from leap day
- end
-
- def test_years_since
- assert_equal Time.local(2006,6,5,10), Time.local(2005,6,5,10,0,0).years_since(1)
- assert_equal Time.local(2012,6,5,10), Time.local(2005,6,5,10,0,0).years_since(7)
- assert_equal Time.local(2005,2,28,10), Time.local(2004,2,29,10,0,0).years_since(1) # 1 year since leap day
- # Failure because of size limitations of numeric?
- # assert_equal Time.local(2182,6,5,10), Time.local(2005,6,5,10,0,0).years_since(177)
- end
-
- def test_prev_year
- assert_equal Time.local(2004,6,5,10), Time.local(2005,6,5,10,0,0).prev_year
- end
-
def test_last_year
assert_equal Time.local(2004,6,5,10), Time.local(2005,6,5,10,0,0).last_year
end
- def test_next_year
- assert_equal Time.local(2006,6,5,10), Time.local(2005,6,5,10,0,0).next_year
- end
-
def test_ago
assert_equal Time.local(2005,2,22,10,10,9), Time.local(2005,2,22,10,10,10).ago(1)
assert_equal Time.local(2005,2,22,9,10,10), Time.local(2005,2,22,10,10,10).ago(3600)
@@ -426,16 +305,6 @@ class TimeExtCalculationsTest < ActiveSupport::TestCase
end
end
- def test_yesterday
- assert_equal Time.local(2005,2,21,10,10,10), Time.local(2005,2,22,10,10,10).yesterday
- assert_equal Time.local(2005,2,28,10,10,10), Time.local(2005,3,2,10,10,10).yesterday.yesterday
- end
-
- def test_tomorrow
- assert_equal Time.local(2005,2,23,10,10,10), Time.local(2005,2,22,10,10,10).tomorrow
- assert_equal Time.local(2005,3,2,10,10,10), Time.local(2005,2,28,10,10,10).tomorrow.tomorrow
- end
-
def test_change
assert_equal Time.local(2006,2,22,15,15,10), Time.local(2005,2,22,15,15,10).change(:year => 2006)
assert_equal Time.local(2005,6,22,15,15,10), Time.local(2005,2,22,15,15,10).change(:month => 6)
@@ -539,16 +408,6 @@ class TimeExtCalculationsTest < ActiveSupport::TestCase
assert_equal t, t.advance(:months => 0)
end
- def test_prev_week
- with_env_tz 'US/Eastern' do
- assert_equal Time.local(2005,2,21), Time.local(2005,3,1,15,15,10).prev_week
- assert_equal Time.local(2005,2,22), Time.local(2005,3,1,15,15,10).prev_week(:tuesday)
- assert_equal Time.local(2005,2,25), Time.local(2005,3,1,15,15,10).prev_week(:friday)
- assert_equal Time.local(2006,10,30), Time.local(2006,11,6,0,0,0).prev_week
- assert_equal Time.local(2006,11,15), Time.local(2006,11,23,0,0,0).prev_week(:wednesday)
- end
- end
-
def test_last_week
with_env_tz 'US/Eastern' do
assert_equal Time.local(2005,2,21), Time.local(2005,3,1,15,15,10).last_week
@@ -559,16 +418,6 @@ class TimeExtCalculationsTest < ActiveSupport::TestCase
end
end
- def test_next_week
- with_env_tz 'US/Eastern' do
- assert_equal Time.local(2005,2,28), Time.local(2005,2,22,15,15,10).next_week
- assert_equal Time.local(2005,3,1), Time.local(2005,2,22,15,15,10).next_week(:tuesday)
- assert_equal Time.local(2005,3,4), Time.local(2005,2,22,15,15,10).next_week(:friday)
- assert_equal Time.local(2006,10,30), Time.local(2006,10,23,0,0,0).next_week
- assert_equal Time.local(2006,11,1), Time.local(2006,10,23,0,0,0).next_week(:wednesday)
- end
- end
-
def test_next_week_near_daylight_start
with_env_tz 'US/Eastern' do
assert_equal Time.local(2006,4,3), Time.local(2006,4,2,23,1,0).next_week, 'just crossed standard => daylight'
@@ -709,14 +558,6 @@ class TimeExtCalculationsTest < ActiveSupport::TestCase
end
end
- def test_next_month_on_31st
- assert_equal Time.local(2005, 9, 30), Time.local(2005, 8, 31).next_month
- end
-
- def test_prev_month_on_31st
- assert_equal Time.local(2004, 2, 29), Time.local(2004, 3, 31).prev_month
- end
-
def test_last_month_on_31st
assert_equal Time.local(2004, 2, 29), Time.local(2004, 3, 31).last_month
end
@@ -938,15 +779,6 @@ class TimeExtMarshalingTest < ActiveSupport::TestCase
assert_equal t, unmarshaled
end
-
- def test_next_quarter_on_31st
- assert_equal Time.local(2005, 11, 30), Time.local(2005, 8, 31).next_quarter
- end
-
- def test_prev_quarter_on_31st
- assert_equal Time.local(2004, 2, 29), Time.local(2004, 5, 31).prev_quarter
- end
-
def test_last_quarter_on_31st
assert_equal Time.local(2004, 2, 29), Time.local(2004, 5, 31).last_quarter
end
diff --git a/activesupport/test/dependencies_test.rb b/activesupport/test/dependencies_test.rb
index 69829bcda5..e5bc806397 100644
--- a/activesupport/test/dependencies_test.rb
+++ b/activesupport/test/dependencies_test.rb
@@ -145,6 +145,12 @@ class DependenciesTest < ActiveSupport::TestCase
end
end
+ def test_circular_autoloading_detection
+ with_autoloading_fixtures do
+ assert_raise(RuntimeError, "Circular dependency detected while autoloading constant Circular1") { Circular1 }
+ end
+ end
+
def test_module_loading
with_autoloading_fixtures do
assert_kind_of Module, A
@@ -679,6 +685,8 @@ class DependenciesTest < ActiveSupport::TestCase
assert_equal true, M.unloadable
assert_equal false, M.unloadable
end
+ ensure
+ Object.class_eval { remove_const :M }
end
def test_unloadable_constants_should_receive_callback
diff --git a/activesupport/test/inflector_test.rb b/activesupport/test/inflector_test.rb
index 1f32e4ff92..aa41e57928 100644
--- a/activesupport/test/inflector_test.rb
+++ b/activesupport/test/inflector_test.rb
@@ -169,11 +169,11 @@ class InflectorTest < ActiveSupport::TestCase
def test_underscore_acronym_sequence
ActiveSupport::Inflector.inflections do |inflect|
inflect.acronym("API")
- inflect.acronym("HTML5")
+ inflect.acronym("JSON")
inflect.acronym("HTML")
end
- assert_equal("html5_html_api", ActiveSupport::Inflector.underscore("HTML5HTMLAPI"))
+ assert_equal("json_html_api", ActiveSupport::Inflector.underscore("JSONHTMLAPI"))
end
def test_underscore
@@ -354,6 +354,35 @@ class InflectorTest < ActiveSupport::TestCase
RUBY
end
+ def test_inflector_locality
+ ActiveSupport::Inflector.inflections(:es) do |inflect|
+ inflect.plural(/$/, 's')
+ inflect.plural(/z$/i, 'ces')
+
+ inflect.singular(/s$/, '')
+ inflect.singular(/es$/, '')
+
+ inflect.irregular('el', 'los')
+ end
+
+ assert_equal('hijos', 'hijo'.pluralize(:es))
+ assert_equal('luces', 'luz'.pluralize(:es))
+ assert_equal('luzs', 'luz'.pluralize)
+
+ assert_equal('sociedad', 'sociedades'.singularize(:es))
+ assert_equal('sociedade', 'sociedades'.singularize)
+
+ assert_equal('los', 'el'.pluralize(:es))
+ assert_equal('els', 'el'.pluralize)
+
+ ActiveSupport::Inflector.inflections(:es) { |inflect| inflect.clear }
+
+ assert ActiveSupport::Inflector.inflections(:es).plurals.empty?
+ assert ActiveSupport::Inflector.inflections(:es).singulars.empty?
+ assert !ActiveSupport::Inflector.inflections.plurals.empty?
+ assert !ActiveSupport::Inflector.inflections.singulars.empty?
+ end
+
def test_clear_all
with_dup do
ActiveSupport::Inflector.inflections do |inflect|
@@ -467,7 +496,7 @@ class InflectorTest < ActiveSupport::TestCase
# there are module functions that access ActiveSupport::Inflector.inflections,
# so we need to replace the singleton itself.
def with_dup
- original = ActiveSupport::Inflector.inflections
+ original = ActiveSupport::Inflector::Inflections.instance_variable_get(:@__instance__)
ActiveSupport::Inflector::Inflections.instance_variable_set(:@__instance__, original.dup)
ensure
ActiveSupport::Inflector::Inflections.instance_variable_set(:@__instance__, original)
diff --git a/activesupport/test/json/encoding_test.rb b/activesupport/test/json/encoding_test.rb
index a947635f4a..7ed71f9abc 100644
--- a/activesupport/test/json/encoding_test.rb
+++ b/activesupport/test/json/encoding_test.rb
@@ -85,6 +85,13 @@ class TestJSONEncoding < ActiveSupport::TestCase
end
end
+ def test_json_variable
+ assert_deprecated do
+ assert_equal ActiveSupport::JSON::Variable.new('foo'), 'foo'
+ assert_equal ActiveSupport::JSON::Variable.new('alert("foo")'), 'alert("foo")'
+ end
+ end
+
def test_hash_encoding
assert_equal %({\"a\":\"b\"}), ActiveSupport::JSON.encode(:a => :b)
assert_equal %({\"a\":1}), ActiveSupport::JSON.encode('a' => 1)
diff --git a/activesupport/test/multibyte_chars_test.rb b/activesupport/test/multibyte_chars_test.rb
index a8d69d0ec3..ef289692bc 100644
--- a/activesupport/test/multibyte_chars_test.rb
+++ b/activesupport/test/multibyte_chars_test.rb
@@ -110,7 +110,7 @@ class MultibyteCharsUTF8BehaviourTest < ActiveSupport::TestCase
end
%w{capitalize downcase lstrip reverse rstrip swapcase upcase}.each do |method|
- class_eval(<<-EOTESTS)
+ class_eval(<<-EOTESTS, __FILE__, __LINE__ + 1)
def test_#{method}_bang_should_return_self_when_modifying_wrapped_string
chars = ' él piDió Un bUen café '
assert_equal chars.object_id, chars.send("#{method}!").object_id
diff --git a/activesupport/test/notifications/evented_notification_test.rb b/activesupport/test/notifications/evented_notification_test.rb
index f77a0eb3fa..f690ad43fc 100644
--- a/activesupport/test/notifications/evented_notification_test.rb
+++ b/activesupport/test/notifications/evented_notification_test.rb
@@ -19,6 +19,12 @@ module ActiveSupport
end
end
+ class ListenerWithTimedSupport < Listener
+ def call(name, start, finish, id, payload)
+ @events << [:call, name, start, finish, id, payload]
+ end
+ end
+
def test_evented_listener
notifier = Fanout.new
listener = Listener.new
@@ -62,6 +68,20 @@ module ActiveSupport
[:finish, 'hello', 1, {}],
], listener.events
end
+
+ def test_evented_listener_priority
+ notifier = Fanout.new
+ listener = ListenerWithTimedSupport.new
+ notifier.subscribe 'hi', listener
+
+ notifier.start 'hi', 1, {}
+ notifier.finish 'hi', 1, {}
+
+ assert_equal [
+ [:start, 'hi', 1, {}],
+ [:finish, 'hi', 1, {}]
+ ], listener.events
+ end
end
end
end
diff --git a/activesupport/test/number_helper_i18n_test.rb b/activesupport/test/number_helper_i18n_test.rb
index e07198027b..65aecece71 100644
--- a/activesupport/test/number_helper_i18n_test.rb
+++ b/activesupport/test/number_helper_i18n_test.rb
@@ -56,6 +56,13 @@ module ActiveSupport
assert_equal("-$10.00", number_to_currency(-10, :locale => 'empty'))
end
+ def test_locale_default_format_has_precedence_over_helper_defaults
+ I18n.backend.store_translations 'ts',
+ { :number => { :format => { :separator => ";" } } }
+
+ assert_equal("&$ - 10;00", number_to_currency(10, :locale => 'ts'))
+ end
+
def test_number_to_currency_without_currency_negative_format
I18n.backend.store_translations 'no_negative_format', :number => {
:currency => { :format => { :unit => '@', :format => '%n %u' } }
@@ -72,11 +79,24 @@ module ActiveSupport
assert_equal("1.00", number_to_rounded(1.0, :locale => 'ts'))
end
+ def test_number_with_i18n_precision_and_empty_i18n_store
+ I18n.backend.store_translations 'empty', {}
+
+ assert_equal("123456789.123", number_to_rounded(123456789.123456789, :locale => 'empty'))
+ assert_equal("1.000", number_to_rounded(1.0000, :locale => 'empty'))
+ end
+
def test_number_with_i18n_delimiter
#Delimiter "," and separator "."
assert_equal("1,000,000.234", number_to_delimited(1000000.234, :locale => 'ts'))
end
+ def test_number_with_i18n_delimiter_and_empty_i18n_store
+ I18n.backend.store_translations 'empty', {}
+
+ assert_equal("1,000,000.234", number_to_delimited(1000000.234, :locale => 'empty'))
+ end
+
def test_number_to_i18n_percentage
# to see if strip_insignificant_zeros is true
assert_equal("1%", number_to_percentage(1, :locale => 'ts'))
@@ -86,12 +106,27 @@ module ActiveSupport
assert_equal("12434%", number_to_percentage(12434, :locale => 'ts'))
end
+ def test_number_to_i18n_percentage_and_empty_i18n_store
+ I18n.backend.store_translations 'empty', {}
+
+ assert_equal("1.000%", number_to_percentage(1, :locale => 'empty'))
+ assert_equal("1.243%", number_to_percentage(1.2434, :locale => 'empty'))
+ assert_equal("12434.000%", number_to_percentage(12434, :locale => 'empty'))
+ end
+
def test_number_to_i18n_human_size
#b for bytes and k for kbytes
assert_equal("2 k", number_to_human_size(2048, :locale => 'ts'))
assert_equal("42 b", number_to_human_size(42, :locale => 'ts'))
end
+ def test_number_to_i18n_human_size_with_empty_i18n_store
+ I18n.backend.store_translations 'empty', {}
+
+ assert_equal("2 KB", number_to_human_size(2048, :locale => 'empty'))
+ assert_equal("42 Bytes", number_to_human_size(42, :locale => 'empty'))
+ end
+
def test_number_to_human_with_default_translation_scope
#Using t for thousand
assert_equal "2 t", number_to_human(2000, :locale => 'ts')
@@ -106,6 +141,13 @@ module ActiveSupport
assert_equal "2 Tens", number_to_human(20, :locale => 'ts')
end
+ def test_number_to_human_with_empty_i18n_store
+ I18n.backend.store_translations 'empty', {}
+
+ assert_equal "2 Thousand", number_to_human(2000, :locale => 'empty')
+ assert_equal "1.23 Billion", number_to_human(1234567890, :locale => 'empty')
+ end
+
def test_number_to_human_with_custom_translation_scope
#Significant was set to true with precision 2, with custom translated units
assert_equal "4.3 cm", number_to_human(0.0432, :locale => 'ts', :units => :custom_units_for_number_to_human)
diff --git a/activesupport/test/number_helper_test.rb b/activesupport/test/number_helper_test.rb
index 9b7d7f020c..5f54587f93 100644
--- a/activesupport/test/number_helper_test.rb
+++ b/activesupport/test/number_helper_test.rb
@@ -4,7 +4,7 @@ require 'active_support/number_helper'
module ActiveSupport
module NumberHelper
class NumberHelperTest < ActiveSupport::TestCase
-
+
class TestClassWithInstanceNumberHelpers
include ActiveSupport::NumberHelper
end
@@ -16,7 +16,7 @@ module ActiveSupport
def setup
@instance_with_helpers = TestClassWithInstanceNumberHelpers.new
end
-
+
def kilobytes(number)
number * 1024
end
@@ -362,14 +362,13 @@ module ActiveSupport
assert_equal "x", number_helper.number_to_human('x')
end
end
-
+
def test_extending_or_including_number_helper_correctly_hides_private_methods
[@instance_with_helpers, TestClassWithClassNumberHelpers, ActiveSupport::NumberHelper].each do |number_helper|
assert !number_helper.respond_to?(:valid_float?)
assert number_helper.respond_to?(:valid_float?, true)
end
end
-
end
end
end
diff --git a/activesupport/test/ordered_hash_test.rb b/activesupport/test/ordered_hash_test.rb
index e8defd396b..ac85ba1f21 100644
--- a/activesupport/test/ordered_hash_test.rb
+++ b/activesupport/test/ordered_hash_test.rb
@@ -226,12 +226,8 @@ class OrderedHashTest < ActiveSupport::TestCase
end
def test_alternate_initialization_raises_exception_on_odd_length_args
- begin
+ assert_raises ArgumentError do
ActiveSupport::OrderedHash[1,2,3,4,5]
- flunk "Hash::[] should have raised an exception on initialization " +
- "with an odd number of parameters"
- rescue ArgumentError => e
- assert_equal "odd number of arguments for Hash", e.message
end
end
diff --git a/activesupport/test/string_inquirer_test.rb b/activesupport/test/string_inquirer_test.rb
index bb15916e9e..94d5fe197d 100644
--- a/activesupport/test/string_inquirer_test.rb
+++ b/activesupport/test/string_inquirer_test.rb
@@ -1,15 +1,23 @@
require 'abstract_unit'
class StringInquirerTest < ActiveSupport::TestCase
+ def setup
+ @string_inquirer = ActiveSupport::StringInquirer.new('production')
+ end
+
def test_match
- assert ActiveSupport::StringInquirer.new("production").production?
+ assert @string_inquirer.production?
end
def test_miss
- assert !ActiveSupport::StringInquirer.new("production").development?
+ refute @string_inquirer.development?
end
def test_missing_question_mark
- assert_raise(NoMethodError) { ActiveSupport::StringInquirer.new("production").production }
+ assert_raise(NoMethodError) { @string_inquirer.production }
+ end
+
+ def test_respond_to
+ assert_respond_to @string_inquirer, :development?
end
end
diff --git a/activesupport/test/tagged_logging_test.rb b/activesupport/test/tagged_logging_test.rb
index 0751c2469e..43cf1a8e4f 100644
--- a/activesupport/test/tagged_logging_test.rb
+++ b/activesupport/test/tagged_logging_test.rb
@@ -29,6 +29,11 @@ class TaggedLoggingTest < ActiveSupport::TestCase
assert_equal "[BCX] [Jason] [New] Funky time\n", @output.string
end
+ test "does not strip message content" do
+ @logger.info " Hello"
+ assert_equal " Hello\n", @output.string
+ end
+
test "provides access to the logger instance" do
@logger.tagged("BCX") { |logger| logger.info "Funky time" }
assert_equal "[BCX] Funky time\n", @output.string
diff --git a/activesupport/test/transliterate_test.rb b/activesupport/test/transliterate_test.rb
index b7076e9e58..b5d8142458 100644
--- a/activesupport/test/transliterate_test.rb
+++ b/activesupport/test/transliterate_test.rb
@@ -1,7 +1,6 @@
# encoding: utf-8
require 'abstract_unit'
require 'active_support/inflector/transliterate'
-require 'active_support/core_ext/object/inclusion'
class TransliterateTest < ActiveSupport::TestCase
@@ -16,7 +15,7 @@ class TransliterateTest < ActiveSupport::TestCase
# create string with range of Unicode"s western characters with
# diacritics, excluding the division and multiplication signs which for
# some reason or other are floating in the middle of all the letters.
- string = (0xC0..0x17E).to_a.reject {|c| c.in?([0xD7, 0xF7])}.pack("U*")
+ string = (0xC0..0x17E).to_a.reject {|c| [0xD7, 0xF7].include?(c)}.pack("U*")
string.each_char do |char|
assert_match %r{^[a-zA-Z']*$}, ActiveSupport::Inflector.transliterate(string)
end