Commit Graph

615 Commits

Author SHA1 Message Date
Iain Beeston
d2876141d0 Raise ArgumentError if an unrecognised callback is skipped
At present, if you skip a callback that hasn't been defined,
activesupport callbacks silently does nothing. However, it's easy to
mistype the name of a callback and mistakenly think that it's being
skipped, when it is not.

This problem even exists in the current test suite.
CallbacksTest::SkipCallbacksTest#test_skip_person attempts to skip
callbacks that were never set up.

This PR changes `skip_callback` to raise an `ArgumentError` if the
specified callback cannot be found.
2015-04-03 09:37:19 +01:00
Rafael Mendonça França
b5c35023bd Revert "Remove Array#inquiry"
This reverts commit 9420de59f5b7f5ceac77e28e6c326ec145f71f80.

Reason: Turns out we want to keep this method.
2015-03-30 13:38:13 -03:00
Rafael Mendonça França
9420de59f5 Remove Array#inquiry
We are promoting too much a feature that will not be widler used.
So for now lets keep just the ArrayInquirer constructor.
2015-03-27 16:25:13 -03:00
George Claghorn
c64b99ecc9 Add ActiveSupport::ArrayInquirer and Array#inquiry
Wrapping an array in an `ArrayInquirer` gives a friendlier way to check its
string-like contents. For example, `request.variant` returns an `ArrayInquirer`
object. To check a request's variants, you can call:

    request.variant.phone?
    request.variant.any?(:phone, :tablet)

...instead of:

    request.variant.include?(:phone)
    request.variant.any? { |v| v.in?([:phone, :tablet]) }

`Array#inquiry` is a shortcut for wrapping the receiving array in an
`ArrayInquirer`:

    pets = [:cat, :dog]
    pets.cat?    # => true
    pets.ferret? # => false
    pets.any?(:cat, :ferret} # => true
2015-03-24 13:33:01 -05:00
Kir Shatrov
a982a42d76 Deprecate alias_method_chain in favour of Module#prepend
…as discussed #19413
2015-03-22 23:11:19 +02:00
Andrew White
34b27701ee Revert "Take DST into account when locating TimeZone from Numeric."
Reverting this as it's not the implementation that we would like it to be.
This is being used inside of ActiveSUpport::TimeZone[] and it's unaware
of the context in which to find the timezone period so the timezone found
changes depending on whether DST is in effect for the current period.
This means that `'2001-01-01'.in_time_zone(-9)` changes from winter/summer
even though it's the same date that we're trying to convert.

Since finding timezones by numeric offsets is a bit hit and miss we should
introduce a new API for finding them which supplies the date context in
which we want to search and we should probably also deprecate the finding
of timezones via the [] method, though this needs further discussion.

This reverts commit 2cc2fa3633edd96773023c6b09d07c7b9d9b841d.
2015-03-09 13:48:55 +00:00
Robin Dupret
f927591611 Remove a duplicated changelog entry [ci skip]
This entry now lives in the Action View's changelog ; refs 8a3bd089.
2015-03-06 12:03:51 +01:00
Yves Senn
081a3963ea number_to_percentage and precision: 0 work with NAN and INFINITY.
Closes #19227.
2015-03-06 09:04:51 +01:00
Yasyf Mohamedali
2cc2fa3633 Take DST into account when locating TimeZone from Numeric.
When given a specific offset, use the first result found where the
total current offset (including any periodic deviations such as DST)
from UTC is equal.
2015-03-03 15:16:47 -05:00
Todd Bealmear
c7a37c10ad Add Enumerable#without 2015-03-01 18:45:45 -08:00
Henrik Nygren
ece0d25c2b Fix a backtracking problem in String#truncate_words
Fixes #19070.
2015-02-25 17:02:22 +02:00
Yves Senn
e71f5dad4e some indenting and punctuation fixes. [ci skip] 2015-02-23 16:54:40 +01:00
Godfrey Chan
debe7aedda Properly dump primitive-like AS::SafeBuffer strings as YAML
`coder.represent_scalar` means something along the lines of "Here is a quoted
string, you can just add it to the output", which is not the case here. It only
works for simple strings that can appear unquoted in YAML, but causes problems
for e.g. primitive-like strings ("1", "true").

`coder.represent_object` on the other hand, means that "This is the Ruby-object
representation for this thing suitable for use in YAML dumping", which is what
we want here.

Before:

   YAML.load ActiveSupport::SafeBuffer.new("Hello").to_yaml  # => "Hello"
   YAML.load ActiveSupport::SafeBuffer.new("true").to_yaml   # => true
   YAML.load ActiveSupport::SafeBuffer.new("false").to_yaml  # => false
   YAML.load ActiveSupport::SafeBuffer.new("1").to_yaml      # => 1
   YAML.load ActiveSupport::SafeBuffer.new("1.1").to_yaml    # => 1.1

 After:

   YAML.load ActiveSupport::SafeBuffer.new("Hello").to_yaml  # => "Hello"
   YAML.load ActiveSupport::SafeBuffer.new("true").to_yaml   # => "true"
   YAML.load ActiveSupport::SafeBuffer.new("false").to_yaml  # => "false"
   YAML.load ActiveSupport::SafeBuffer.new("1").to_yaml      # => "1"
   YAML.load ActiveSupport::SafeBuffer.new("1.1").to_yaml    # => "1.1"

If we ever want Ruby to behave more like PHP or JavaScript though, this is an
excellent trick to use ;)
2015-02-11 17:08:13 -08:00
Rafael Mendonça França
2d2bcde3cb Merge pull request #12067 from jackxxu/keep_precision
Enable number_to_percentage to keep the number's precision by allowing :precision option value to be nil

Conflicts:
	activesupport/CHANGELOG.md
	activesupport/lib/active_support/number_helper.rb
	activesupport/test/number_helper_test.rb
2015-02-06 16:21:28 -02:00
Akira Matsuda
c2bfe6cbc8 Privatize config_accessor as with attr_accessor 2015-02-06 01:12:07 +09:00
Yuki Nishijima
a57ddc58ac Change AS::Testing::TimeHelpers#travel_to to also stub DateTime.now 2015-02-03 05:23:23 -08:00
Yves Senn
d28e5b94a7 introduce ActiveSupport::Testing::FileFixtures.
It's a thin layer to provide easy access to sample files throughout
test-cases. This adds the directory `test/fixtures/files` to newly
generated applications.
2015-01-28 12:29:34 +01:00
Yves Senn
71a84206ab Merge pull request #18709 from ianks/atomic-write
Return value of yielded block in File.atomic_write
2015-01-28 08:58:16 +01:00
Aditya Kapoor
584931d749 Fix assignment for frozen value in HWIA 2015-01-17 00:53:17 +05:30
Andrey Novikov
f996dcf7ef Add missing time zone definitions for Russian Federation
Also sync Russian Federation time zones with `zone.tab` file from tzdata version 2014j.
2015-01-13 20:11:13 +03:00
Yves Senn
a7621d7d53 formatting pass over CHANGELOGs. [ci skip] 2015-01-10 12:17:57 +01:00
Guillermo Iguaran
b109397711 Add SecureRandom.base58 2015-01-09 17:51:46 -05:00
George Claghorn
4c53f58a0f Add #prev_day and #next_day as counterparts to #yesterday and #tomorrow for Date, Time, and DateTime 2015-01-06 05:43:41 -05:00
George Claghorn
b6d0d0d106 Add same_time option to #prev_week and #next_week for Date, Time, and DateTime 2015-01-06 05:43:06 -05:00
George Claghorn
adf5fc3b3c Add #on_weekend?, #next_weekday, and #prev_weekday methods to Date, Time, and DateTime
`#on_weekend?` returns true if the receiving date/time falls on a Saturday or
Sunday.

`#next_weekday` returns a new date/time representing the next day that does
not fall on a Saturday or Sunday.

`#prev_weekday` returns a new date/time representing the previous day that
does not fall on a Saturday or Sunday.
2015-01-06 05:42:37 -05:00
Rafael Mendonça França
5f777e4b5e Change the default test order from :sorted to :random 2015-01-04 11:58:41 -03:00
Rafael Mendonça França
d6e06ea827 Remove deprecated ActiveSupport::JSON::Encoding::CircularReferenceError. 2015-01-04 11:58:41 -03:00
Rafael Mendonça França
c8019c0611 Remove deprecated ActiveSupport::JSON::Encoding.encode_big_decimal_as_string= 2015-01-04 11:58:40 -03:00
Rafael Mendonça França
e1c8b9f688 Remove deprecated ActiveSupport::SafeBuffer#prepend 2015-01-04 11:58:40 -03:00
Rafael Mendonça França
481e49c64f Remove deprecated methods at Kernel.
`silence_stderr`, `silence_stream`, `capture` and `quietly`.
2015-01-04 11:58:40 -03:00
Rafael Mendonça França
98ea19925d Remove deprecated core_ext/big_decimal/yaml_conversions file 2015-01-04 11:58:40 -03:00
Rafael Mendonça França
a3ce6ca30e Remove deprecated ActiveSupport::Cache::Store.instrument 2015-01-04 11:58:40 -03:00
claudiob
9c65c539e2 Add config to halt callback chain on return false
This stems from [a comment](rails#17227 (comment)) by @dhh.
In summary:

* New Rails 5.0 apps will not accept `return false` as a way to halt callback chains, and will not display a deprecation warning.
* Existing apps ported to Rails 5.0 will still accept `return false` as a way to halt callback chains, albeit with a deprecation warning.

For this purpose, this commit introduces a Rails configuration option:

```ruby
config.active_support.halt_callback_chains_on_return_false
```

For new Rails 5.0 apps, this option will be set to `false` by a new initializer
`config/initializers/callback_terminator.rb`:

```ruby
Rails.application.config.active_support.halt_callback_chains_on_return_false = false
```

For existing apps ported to Rails 5.0, the initializers above will not exist.
Even running `rake rails:update` will not create this initializer.

Since the default value of `halt_callback_chains_on_return_false` is set to
`true`, these apps will still accept `return true` as a way to halt callback
chains, displaying a deprecation warning.

Developers will be able to switch to the new behavior (and stop the warning)
by manually adding the line above to their `config/application.rb`.

A gist with the suggested release notes to add to Rails 5.0 after this
commit is available at https://gist.github.com/claudiob/614c59409fb7d11f2931
2015-01-02 15:31:56 -08:00
claudiob
d217daf6a7 Deprecate false as the way to halt AS callbacks
After this commit, returning `false` in a callback will display a deprecation
warning to make developers aware of the fact that they need to explicitly
`throw(:abort)` if their intention is to halt a callback chain.

This commit also patches two internal uses of AS::Callbacks (inside
ActiveRecord and ActionDispatch) which sometimes return `false` but whose
returned value is not meaningful for the purpose of execution.

In both cases, the returned value is set to `true`, which does not affect the
execution of the callbacks but prevents unrequested deprecation warnings from
showing up.
2015-01-02 15:31:55 -08:00
claudiob
2386daabe7 Throw :abort halts default CallbackChains
This commit changes arguments and default value of CallbackChain's :terminator
option.

After this commit, Chains of callbacks defined **without** an explicit
`:terminator` option will be halted as soon as a `before_` callback throws
`:abort`.

Chains of callbacks defined **with** a `:terminator` option will maintain their
existing behavior of halting as soon as a `before_` callback matches the
terminator's expectation. For instance, ActiveModel's callbacks will still
halt the chain when a `before_` callback returns `false`.
2015-01-02 15:31:55 -08:00
Rafael Mendonça França
734d97d292 Deprecate MissingSourceFile in favor of LoadError.
`MissingSourceFile` was just an alias to `LoadError` and was not
being raised inside the framework.
2015-01-02 19:44:39 -03:00
Robin Dupret
ae08bef428 Changelog edits [ci skip] 2014-12-31 17:35:41 +01:00
Yves Senn
0587070391 cleanup CHANGELOGs. [ci skip] 2014-12-23 08:56:17 +01:00
Genadi Samokovarov
dd96e8e333 Add class level case operator support for error dispatching in Rescuable 2014-12-10 02:34:59 +02:00
claudiob
999603c17f Fix MessageVerifier's #verified in CHANGELOG
[ci skip]

As confirmed by @lleger (the author of `verified`) [in this comment](https://github.com/rails/rails/pull/17727#issuecomment-65488743):

> Actually, it no longer returns false explicitly (bc8cc56), so I guess the CHANGELOG isn't totally accurate. It returns nil instead (but the functionality isn't practically different).
2014-12-04 08:13:22 -08:00
Logan Leger
7ad541f955 Add #verified and #valid_message? to MessageVerifier
This commit adds a `#verified` method to
`ActiveSupport::MessageVerifier` which will return either `false` when
it encounters an error or the message. `#verify` continues to raise an
`InvalidSignature` exception on error.

This commit also adds a convenience boolean method on `MessageVerifier`
as a way to check if a message is valid without performing the
decoding.
2014-12-01 21:43:16 -06:00
Rafael Mendonça França
f25ad07f5a Start Rails 5 development 🎉
We will support only Ruby >= 2.1.

But right now we don't accept pull requests with syntax changes to drop
support to Ruby 1.9.
2014-11-28 15:00:06 -02:00
Xavier Noria
0ed6ebcf90 dependencies.rb: keep the decorated #load and #require private [closes #17553] 2014-11-10 14:29:29 -08:00
Yves Senn
5dd3c3b2a0 docs, synchronize 4.2. release notes. [ci skip]
/cc @chancancode
2014-11-06 12:16:11 +01:00
Rafael Mendonça França
4259cc0c50 Merge pull request #17383 from rwz/string-remove
Make `String#remove` and `String#remove!` accept multiple arguments

Conflicts:
	activesupport/CHANGELOG.md
2014-11-03 12:09:26 -02:00
Pablo Herrero
1897d3a5d2 Optimize TimeWithZoneTest#strftime 2014-10-27 21:43:12 -03:00
Pavel Pravosud
73ad151030 Make String#remove and String#remove! accept multiple arguments 2014-10-25 18:06:02 -04:00
Godfrey Chan
04b40b3deb Update CHANGELOG and release notes for e98f2a7 2014-10-22 16:34:58 -07:00
Yves Senn
400b0818fa some changelog formatting. [ci skip] 2014-10-16 09:11:41 +02:00
Matthew Draper
cf66278301 Merge pull request #14146 from chewi/fix-underscore-acronyms-regex
Fix underscore inflector handling of namespaced and adjacent acronyms
2014-10-04 08:16:55 +09:30
Xavier Noria
c935d6f9b5 fixes typo in AS CHANGELOG [ci skip]
References f92ac24.
2014-09-29 23:06:43 +02:00
Agis-
1a787ebb7e Delegation works with reserved words passed to :to
Fixes #16956.
2014-09-19 11:41:41 +03:00
Abdelkader Boudih
46d168e957 Merge pull request #16950 from akshay-vishnoi/docs-rails-4point2
Grammar correction in ActiveSupport CHANGELOG [ci skip]
2014-09-17 21:59:46 +01:00
Akshay Vishnoi
f92ac245bd Grammar correction in ActiveSupport CHANGELOG [ci skip] 2014-09-18 02:27:18 +05:30
Rafael Mendonça França
026289e28e Merge pull request #16948 from akshay-vishnoi/docs-rails-4point2
[ci skip] ActiveSupport CHANGELOG fixes
2014-09-17 17:28:50 -03:00
Akshay Vishnoi
7a8fb281d8 [ci skip] ActiveSupport CHANGELOG fixes
1. spacing issues
2. spelling correction
3. grammar correction
4. Add missing docs
2014-09-18 01:55:29 +05:30
Rafael Mendonça França
acda46d081 Merge pull request #11794 from yoazt/duration-eql
Added method `#eql?` to `ActiveSupport::Duration`, in addition to `#==`.

Conflicts:
	activesupport/CHANGELOG.md
	activesupport/lib/active_support/duration.rb
	activesupport/test/core_ext/duration_test.rb
2014-09-17 16:15:25 -03:00
Agis-
7a3e5ac298 Time#change can now change nanoseconds (:nsec)
Closes #16392.
2014-09-14 02:24:12 +03:00
Kostiantyn Kahanskyi
4bf9d1938b MessageVerifier raises an appropriate exception if the secret is nil
Otherwise this will lead to another error later on 
when generating a signature:
TypeError (no implicit conversion of nil into String).
2014-09-12 15:09:00 +02:00
Godfrey Chan
2b41343c34 Default to sorting user's test cases for now
Goals:

1. Default to :random for newly generated applications
2. Default to :sorted for existing applications with a warning
3. Only show the warning once
4. Only show the warning if the app actually uses AS::TestCase

Fixes #16769
2014-09-08 05:32:16 -07:00
Matthew Draper
ccbb48196e Fix for inflector's incorrect camelCase replacement for acronyms
Fixes #8015, #9756.

[Fred Wu & Matthew Draper]
2014-09-06 04:56:25 +09:30
Agis-
57b2c371f0 Time#change throws exception with an out-of-range :usec
98b46bf5e2
did not properly handled out-of-range `:usec`s.

Passing a `:usec` that's out of range now throws an `ArgumentError` as it
should.

Fixes #16759.
2014-09-04 22:21:38 +03:00
Peter Jaros
fdc5e768ca Methods are not duplicable. 2014-09-03 16:09:15 -04:00
Yves Senn
97e689a0d7 Merge pull request #16450 from tgxworld/dont_swallow_error_when_identifying_constant_from_test_name
Do not swallow exception on NameError within constant.
2014-09-02 08:44:55 +02:00
Yves Senn
3579120367 remove trailing whitespace. [ci skip] 2014-09-02 08:42:44 +02:00
David Heinemeier Hansson
5e51bdda59 We tenderized the wrong method! Object#try already had the yield option, just needed some tenderloving instance_eval to fit the bill 2014-08-29 15:32:24 -07:00
David Heinemeier Hansson
9619450468 Use instance_eval on @tenderlove's suggestion :trollface: 2014-08-29 15:19:32 -07:00
David Heinemeier Hansson
cc0d8fbec9 Update examples to show real worth 2014-08-29 15:04:37 -07:00
David Heinemeier Hansson
141d864e0e Added yield to Object#presence 2014-08-29 14:58:36 -07:00
Robin Dupret
d5578cd177 Follow-up to #16560
For the sake of backward-compatibility, we need to make #instance_of?
return true for Fixnum. On the other hand, the method should still
give true for ActiveSupport::Duration itself which was not the case
before.
2014-08-24 18:17:46 +02:00
Robin Dupret
eb73d7dafa Define the Duration#instance_of? method
Since Duration is extending from ProxyObject which extends itself from
BasicObject, the Duration object doesn't respond to the #instance_of?
method. Thus, the #method_missing hook get triggered, delegating the
method to its `value` attribute.

However, Rubinius' #eql? definition relies on #instance_of?, thus this
will equal to true with a Fixnum (since its `value` attribute is a
Fixnum) while it should not.

The previous behavior was wrong anyway, no matter the implementation.
2014-08-18 15:43:49 +02:00
David Heinemeier Hansson
9f6e82ee47 Fix rounding errors with #travel_to by resetting the usec on any passed time to zero, so we only travel with per-second precision, not anything deeper than that. 2014-08-17 12:52:54 -07:00
Rafael Mendonça França
e81f3c210e Nobody sucks so nobody should call this awful method name 2014-08-12 10:51:41 -03:00
Akira Matsuda
9424b48d39 CHANGELOG entry for TestCase.i_suck_and_my_tests_are_order_dependent! fix 2014-08-12 19:54:23 +09:00
Rafael Mendonça França
ca9736e78c Fix DateTime comparison with DateTime::Infinity object
Fixes #16406
2014-08-06 22:43:37 -03:00
Carlos Antonio da Silva
ab2a35878b Fix AS docs / changelog with wrong method [ci skip] 2014-08-05 10:19:00 -03:00
David Heinemeier Hansson
64d9112222 Rename Object#self to Object#itself to have parity with matz sanctioned method name for Ruby 2.2 2014-08-01 10:30:13 -07:00
David Heinemeier Hansson
702ad710b5 Added Object#self which returns the object itself 2014-08-01 10:07:38 -07:00
Gordon Chan
6e574e8a11 HashWithIndifferentAccess.new respects the default value or proc on objects that respond to #to_hash.
Builds on the work of #12550 where `.new` will convert the object (that respond to `#to_hash`) to a hash and
add that hash's keys and values to itself.

This change will also make `.new` respect the default value or proc of objects that respond to `#to_hash`.
In other words, this `.new` behaves exactly like `.new_from_hash_copying_default`.

`.new_from_hash_copying_default` now simply invokes `.new` and any references to `.new_from_hash_copying_default`
are replaced with `.new`.

Added tests confirm behavior.
2014-07-31 19:14:12 +12:00
Pavel Pravosud
0cb3cc4ff7 Add implicit receiver support to Object#with_options 2014-07-29 16:11:48 -04:00
Godfrey Chan
bf7fbe64f7 Fixed a compatibility issue with the Oj gem
`Time#as_json`, `Date#as_json` and `DateTime#as_json` incorrectly depends on a
delegation that is set up in `active_support/json/encoding`. We cannot simply
require that file in `core_ext/object/json` because it would cause a circular
dependency problem (see #12203 for background). We should instead rely on AS's
autoload to load that file for us on-demand.

To trigger autoload correctly, we need to reference the `AS::JSON::Encoding`
constant instead of using the delegated version.

Fixes #16131.
2014-07-29 00:04:45 -07:00
Arthur Neves
c17c262cfc
Make HWIA copy the default proc too.
[fixes #16279]
2014-07-24 11:48:24 -04:00
Matthew Draper
41679b2b31 Merge pull request #16190 from oss92/word_truncation
Word truncation
2014-07-17 04:31:53 +09:30
root
a9d3b77e49 Added truncate_words method to activesupport strings 2014-07-16 19:48:07 +02:00
Rafael Mendonça França
19fae86fe0 Move uuid_v5 and uuid_v3 to Digest::UUID
These methods are not random so they should not belings to SecureRandom
module.
2014-07-15 19:51:33 -03:00
Rafael Mendonça França
2b2e041506 Add CHANGELOG entry for #13392 [ci skip] 2014-07-15 18:03:12 -03:00
John Paul Ashenfelter
d75992b0b2 DateTime#to_f now preserves fractional seconds.
Previously this method always returns `.0` in the fractional part. This commit
changes it to preserve the fractional seconds instead.

Fixes #15994.
2014-07-02 15:01:35 -07:00
Sean Griffin
b2cf8b251a Add Hash#map_values to ActiveSupport
Didn't get a chance to convert existing code, I'll skim through the code
base to make use of this later this afternoon.
2014-06-29 13:31:43 -06:00
Robin Dupret
d93ae4fca8 Quick pass through Active Support and guides CHANGELOG
[ci skip]
2014-06-29 20:13:49 +02:00
Rafael Mendonça França
3c19402fc3 Merge pull request #15943 from wagenet/cache-instrumentation
Always instrument ActiveSupport::Cache
2014-06-27 18:24:01 -03:00
Robin Dupret
643409dcb0 Make the apply_inflections method case-sensitive
Since d3071db1, the apply_inflections method check if the downcased
version of a string is contained inside the "whitelist" of uncountable
words. However, if the word is composed of capital letters, it won't be
matched in the list while it should.

We can't simply revert to the previous behavior as there is a
performance concern (benchmarked over /usr/share/dict/words):

Before d3071db1  135.610000   0.290000  135.900000 (137.807081)
Since d3071db1   22.170000    0.020000  22.190000  ( 22.530005)
With the patch   22.060000    0.020000  22.080000  ( 22.125771)

Benchmarked with http://git.io/aFnWig

This way, the solution is to put the down-case version of words inside
the @uncountables array.
2014-06-26 14:03:56 +02:00
Arthur Neves
b36df0f6c8
Make dependencies.rb add a name to NameError 2014-06-20 09:44:45 -04:00
Juanjo Bazán
2c515b337f Formatting fix in AS changelog [ci skip] 2014-06-16 20:30:26 -03:00
Adam Panzer
9010274627 fix error with long keys in ActiveSupport::Cache::FileStore 2014-06-10 10:53:48 -07:00
Matthew Draper
b2d070ddf6 Merge pull request #15421 from gchan/time_with_zone_precision
Fixed `ActiveSupport::TimeWithZone#-` so precision is not unnecessarily lost
2014-06-05 16:23:47 +09:30
Juanjo Bazán
60062cf39a Fix AS::NumberHelper results with rationals
:precision was incorrectly being applied to Rationals

before:
  ActiveSupport::NumberHelper.number_to_rounded Rational(10, 3), precision: 2
  => "3.3"
after:
  ActiveSupport::NumberHelper.number_to_rounded Rational(10, 3), precision: 2
  => "3.33"
2014-05-31 20:07:47 +02:00
Robin Dupret
b1867187d4 Tiny formatting fix in AS change log [ci skip] 2014-05-31 19:08:49 +02:00
Godfrey Chan
f1eddea1e3 ✂️ removed deprecated Numeric#ago and friends
Replacements:

   5.ago   => 5.seconds.ago
   5.until => 5.seconds.until
   5.since => 5.seconds.since
   5.from_now => 5.seconds.from_now

The removed tests does not affect coverage – we have equivalent test cases in
the tests for `AS::Duration`.

See #12389 for the history and rationale behind this.
2014-05-30 02:47:56 -07:00
Gordon Chan
c69baffdf7 Fixed ActiveSupport::TimeWithZone#- so precision is not unnecessarily lost
When working with objects with a nanosecond component, the `-` method may
unnecessarily cause loss of precision.

`ActiveSupport::TimeWithZone#-` should return the same result as if we were
using `Time#-`:

    Time.now.end_of_day - Time.now.beginning_of_day #=> 86399.999999999

Before:

    Time.zone.now.end_of_day.nsec #=> 999999999
    Time.zone.now.end_of_day - Time.zone.now.beginning_of_day #=> 86400.0

After:

    Time.zone.now.end_of_day - Time.zone.now.beginning_of_day
    #=> 86399.999999999
2014-05-30 20:41:39 +12:00
Matthew Draper
086ee1cc13 Merge pull request #12080 from ShayDavidson/fix_datetime_partial_dates
Added partial days support to `DateTime`'s `advance` method.
2014-05-28 03:32:21 +09:30
Rafael Mendonça França
decd719711 Merge pull request #10887 from sakuro/deep_transform_keys_in_nested_arrays
Hash#deep_*_keys(!) recurse into nested arrays.

Conflicts:
	activesupport/CHANGELOG.md
2014-05-20 21:49:58 -03:00
Vladimir Yarotsky
6cc5a86a54 Fix confusing exception in ActiveSupport delegation 2014-05-20 08:10:40 -07:00
Rafael Mendonça França
fd119467b6 Merge pull request #15037 from roccoblues/fix_duplicate_activesupport_subscribers
Fixed duplicate subscribers in ActiveSupport::Subscriber

Conflicts:
	activesupport/CHANGELOG.md
2014-05-16 21:13:34 -03:00
Yves Senn
8109dc8067 formatting pass through CHANGELOGS. [ci skip] 2014-05-16 09:03:26 +02:00
eileencodes
b342d2baef remove deprecation warning
This deprecation was released in 4.1.0 and can be removed for 4.2.0,
deprecation message / handling is no longer necessary.
2014-05-13 19:51:57 -04:00
Mark J. Titorenko
9c8242ee6a Use block parameter rather than $1 during gsub! so ActiveSupport::SafeBuffer values aren't mangled.
Fixes #15064
2014-05-12 17:13:19 +01:00
Ulysse Carion
0e909cd307 Make TimeZone#parse behave more like Time#parse.
Namely, if the mday is omitted but any other upper components are, then instead
of supplying the mday from the current time, it defaults to 1.
2014-05-11 15:04:49 +01:00
Dennis Schoen
b50468d13d Fixed duplicate subscribers in ActiveSupport::Subscriber
ActiveSupport::Subscriber no longer creates multiple subscribers when
you redefine a method.
2014-05-09 11:16:18 +02:00
Xavier Noria
daaa21bc7d several enhancements to humanize [closes #12288]
* Strips leading underscores.
* Changes some unnecessary gsub!s to sub!s.
* Replaces some anchors ^, $ with \A, \z.
* Documents that human inflection rules are applied.
* Documents that words are downcased except acronyms.
* Adds an example with an acronym.
* Rewords docs.
2014-05-06 21:35:40 +02:00
Rafael Mendonça França
d65ab433ae Improve CHANGELOG [ci skip] 2014-05-04 18:35:04 -03:00
Bogdan Gusiev
41bbac6ff4 [Fixes #14948] Hash#to_query: Changed a way how empty hash and empty array are serialized
Empty Hash or Array should not present in serialization result

    {a: []}.to_query # => ""
    {a: {}}.to_query # => ""

For more info see #14948.
2014-05-03 07:40:50 +03:00
Rafael Mendonça França
085ce4f141 Merge branch 'master' into rm-uuid-fixtures
Conflicts:
	activerecord/CHANGELOG.md
	activesupport/CHANGELOG.md
2014-04-10 15:34:55 -03:00
Emily Dobervich
5aeb3cd3ac Fixed problem where 1.day.eql?(1.day) is false
This fixes:
    1.second.eql?(1.second) #=> false

The new `eql?` requires that `other` is an `ActiveSupport::Duration`.
This requirement makes `ActiveSupport::Duration`'s behavior consistent
with other numeric types in Ruby.

    1.eql?(1.0) #=> false
    1.0.eql?(1) #=> false

    1.second.eql?(1) #=> false (was true)
    1.eql?(1.second) #=> false

    { 1 => "foo", 1.0 => "bar" }
    #=> { 1 => "foo", 1.0 => "bar" }

    { 1 => "foo", 1.second => "bar" }
    # now => { 1 => "foo", 1.second => "bar" }
    # was => { 1 => "bar" }

And though the behavior here hasn't changed, for reference:

    1 == 1.0 #=> true
    1.0 == 1 #=> true

    1 == 1.second #=> true
    1.second == 1 #=> true
2014-04-08 16:24:35 -07:00
Rafael Mendonça França
54d8c81fef Merge pull request #12016 from roderickvd/uuid_fixes
Auto-generate stable fixture UUIDs on PostgreSQL

Conflicts:
	activerecord/CHANGELOG.md
	activerecord/lib/active_record/fixtures.rb
	activerecord/test/cases/adapters/postgresql/uuid_test.rb
	activesupport/CHANGELOG.md
2014-04-04 12:52:49 -03:00
Pavel Pravosud
6df507e884 Make AS::SafeBuffer#prepend act like String#prepend
Make `#prepend` method modify instance in-place and return self
instead of just returning modified value. That is exactly what
`#prepend!` method was doing previously, so it's deprecated from
now on.
2014-03-31 22:33:53 -04:00
Peter Jaros
03f35a27dc HashWithIndifferentAccess better respects #to_hash
In particular, `.new`, `#update`, `#merge`, `#replace` all accept
objects which respond to `#to_hash`, even if those objects are not
Hashes directly.
2014-03-28 10:25:06 -04:00
Akshay Vishnoi
41548df342 Deprecate Class#superclass_delegating_accessor 2014-03-20 18:29:09 +05:30
Sammy Larbi
d75eeadf74 Fix #to_json for BasicObject Enumerables 2014-03-14 16:55:34 -05:00
Godfrey Chan
ccf8f27ddd Revert "Merge pull request #14269 from arthurnn/expanded_key_array"
This reverts commit 475c96589ca65282e1a61350271c2f83f0d4044f, reversing
changes made to 705915ab5cf24430892107764b0050c07e1df583.

We decided that this is not worth busting everyone's cache as this
seems like a very unlikely problem. The problem only occurs when the
user is 1) not using a namespace, or 2) using the same namesapce for
different *kinds* of cache items. The recommended "fix" is to put
those cache items into their own namspace:

    id = 1
    Rails.cache.fetch(id, namespace: "user"){ User.find(id) }

    ids = [1]
    Rails.cache.fetch(ids, namespace: "users"){ User.find(ids) }

See the discussion on #14269 for details.
2014-03-04 17:58:58 -08:00
Arthur Neves
7d98247446
Cache key should be different when is Array.
`cache.fetch(['foo'])` and `cache.fetch('foo')` should generate
different cache keys as they are not equivalents.

[related #8615]
[related #8614]
2014-03-03 21:00:15 -05:00
Parker Selbert
c046e60965 Return a hash rather than array from fetch_multi
The current implementation of `fetch_multi` returns an array and has no
means to easily backtrack which names yielded which results. By changing
the return value to a Hash we retain the name information. Hash#values
can be used on the response if only the values are needed.
2014-02-26 20:31:46 -06:00
Carlos Antonio da Silva
71b3910a7d Point master changelogs to 4-1-stable branch
Remove 4-1 related entries from master [ci skip]
2014-02-25 09:14:36 -03:00
David Heinemeier Hansson
d61baee52a Go with #presence_in instead of #present_in -- it doesnt sound quite as good, but the closer relationship to #presence over #present is ultimately worth it 2014-02-24 14:17:47 +01:00
Jeremy Kemper
b16c36e688 Introduce Concern#class_methods and Kernel#concern 2014-02-23 12:06:23 -07:00
Carlos Antonio da Silva
68345d4a1a Move changelog entry to the top, fix examples indent [ci skip] 2014-02-18 12:53:01 -03:00
David Heinemeier Hansson
4edca106da Added Object#present_in to simplify value whitelisting 2014-02-18 16:35:07 +01:00
Xavier Noria
65a7c57105 time helpers honor the application time zone when passed a date
Rails applications are expected to be always aware of the application
time zone.

To be consistent with that contract, we have to assume that a bare
date passed to time helpers is a date in the application time zone,
not in the system time zone. The system time zone is irrelevant, we
should totally ignore it.

For example,

    travel_to user.birth_date + 40.years

should make that user be 40th years old regardless of the system
time zone. Without this patch that may not be true.
2014-02-18 09:42:06 +01:00
Justin Coyne
ae28e4beb3 Fix tidy_bytes for JRuby
The previous implementation was broken because JRuby (1.7.10) doesn't
have a code converter for UTF-8 to UTF8-MAC.
2014-02-10 08:10:44 -06:00
Yves Senn
580f0b61dc synchronize 4.1 release notes with CHANGELOGS. [ci skip]
/cc @chancancode
2014-02-06 11:43:16 +01:00
Rafael Mendonça França
7aa4b7dc6b Add CHANGELOG entry
Closes #13909
2014-02-05 23:55:50 -02:00
Rafael Mendonça França
a60ccadbf0 Merge pull request #13911 from davidcelis/remove-bigdecimal-serialization
Deprecate custom BigDecimal serialization

Conflicts:
	activesupport/CHANGELOG.md
2014-02-01 18:03:21 -02:00
David Celis
85d820b169 Don't require BigDecimal serialization extension
Rails currently provides an extension to BigDecimal that redefines how
it is serialized to YAML. However, as noted in #12467, this does not
work as expected. When ActiveSupport is required, BigDecimal YAML
serialization does not maintain the object type. It instead ends up
serializing the number represented by the BigDecimal itself which, when
loaded by YAML later, becomes a Float:

```ruby
require 'yaml'
require 'bigdecimal'

yaml = BigDecimal('13.37').to_yaml
YAML.load(yaml).class

require 'active_support/all'

yaml = BigDecimal('13.37').to_yaml
YAML.load(yaml).class
```

@tenderlove posits that we should deprecate the custom BigDecimal
serialization and let Ruby handle it. For the time being, users who
require this serialization for backwards compatibility can manually
`require 'active_support/core_ext/big_decimal/yaml_conversions'`.

This will close #12467 and deprecate the custom BigDecimal#to_yaml.

Signed-off-by: David Celis <me@davidcel.is>
2014-02-01 10:45:51 -08:00
Rafael Mendonça França
82701cd61e Merge pull request #12769 from birkirb/master
Boolean parser blows up on a Fixnum.

Conflicts:
	activesupport/CHANGELOG.md
2014-02-01 14:49:32 -02:00
Andrew White
63f8fabe49 Maintain the current timezone in wrap_with_time_zone
Extend the solution from the fix for #12163 to the general case where
`Time` methods are wrapped with a time zone.

Fixes #12596.
2014-01-31 17:13:12 +00:00
Rafael Mendonça França
7abb6e00c0 Remove automatic removal of Date/Time stubs after each test case
This behavior is only work out-of-box with minitest and also add a
downside to run after each test case, even if we don't used the travel
or travel_to methods
2014-01-30 10:17:48 -02:00
Rafael Mendonça França
6b16c27881 Add travel_back to remove stubs from travel and travel_to 2014-01-30 10:17:47 -02:00
Yves Senn
02f9f33142 tidy CHANGELOGs [ci skip] 2014-01-30 11:12:46 +01:00
Kassio Borges
42566626e9 Fix documentation of new controller filters api [ci skip]
The api for filters with classes change and the guides weren't updated.
Now the class must respond for methods with the same name as the filter,
so the `before_action` calls a `before` method, and so on.

The method `#filter` has been deprecated in 4.0.0 and has been removed
in 4.1.0: #7560
2014-01-29 18:47:08 -02:00
Andrew White
9484f4b821 Add CHANGELOG entry for #11464 2014-01-26 21:25:54 +00:00
Andrew White
b594492870 Maintain current timezone when changing time during DST overlap
Currently if a time is changed during DST overlap in the autumn then the
method `period_for_local` will return the DST period. However if the
original time is not DST then this can be surprising and is not what is
generally wanted. This commit changes that behavior to maintain the current
period if it's in the list of periods returned by `periods_for_local`.

It is possible to alter the behavior of `period_for_local` by specifying a
second argument but since we may be change from another time that could be
either DST or not then this would give inconsistent results.

Fixes #12163.
2014-01-26 16:56:33 +00:00
tinogomes
5121593787 Adding Hash#compact and Hash#compact! methods
* Adding Hash#compact and Hash#compact! methods
  * Using Ruby 1.9 syntax on documentation
  * Updating guides for `Hash#compact` and `Hash#compact!` methods
  * Updating CHANGELOG for ActiveSupport
  * Removing unecessary protected method and lambda for `Hash#compact` implementations
  * Performing `Hash#compact` implementation - https://gist.github.com/tinogomes/8332883
  * fixing order position
  * Fixing typo
2014-01-09 16:02:55 -02:00
Roderick van Domburg
9330631888 Auto-generate stable fixture UUIDs on PostgreSQL.
Fixes: #11524
2014-01-07 19:05:50 +01:00
Carlos Antonio da Silva
6bf93b22d5 Fix typo in AS changelog, improve highlight [ci skip] 2014-01-06 10:28:44 -02:00
Yves Senn
535bd55fcd quick formatting pass through CHANGELOGS. [ci skip]. 2014-01-06 10:57:00 +01:00
Andrew White
a1564d470d Add CHANGELOG entry for #10634 [ci skip] 2014-01-05 19:23:53 +00:00
Arthur Neves
e7f56a7fe8 Raise if MemCacheStore doenst receive a Dalli obj
:mem_cache_store should receive a list of hosts or a dalli client,
otherwise raise it.
Also adding a changelog.
2014-01-03 16:39:50 -05:00
Andrew White
75ad0e642c Don't lazy load the tzinfo library
Lazy loading the tzinfo library doesn't really buy us anything because
the gem is installed as a dependency via the gemspec and if a developer
is using Active Support outside of Rails then they can cherry pick which
files to load anyway.

Fixes #13553
2014-01-01 20:29:56 +00:00
Robin Dupret
afc98eadb8 Avoid raising a NameError on FreeBSD using Date
The Date object has a xmlschema method starting with Ruby 1.9 so we were
assuming that we could safely remove this method and redefine it later
but the call to remove_method throws a NameError on FreeBSD so we should
rely on remove_possible_method instead.

This call is actually needed to avoid warnings when running the test
suite.

Fixes #11723
2014-01-01 15:29:24 +01:00
Xavier Noria
126dc47665 blank? and present? commit to return singletons [Xavier Noria & Pavel Pravosud]
The contract of blank? and present? was in principle to return Object, as we
generally do, the test suite and description was consistent with that, but some
examples had comments like "# => true".

This cannot be unclear, we either fix the examples, or update the contract.

Since users may be already assuming singletons due to the examples and the fact
that they were returned before 30ba7ee, the safest option seems to be to revise
the contract and the implementation of String#blank?

The motivation for 30ba7ee was to improve the performance of the predicate, the
refactor based on === is on par regarding speed.

With this commit we start documenting return types using YARD conventions. We
plan to document return types gradually.
2013-12-28 20:03:38 +01:00
Birkir A. Barkarson
8dd4aca485 Fix breakage in XmlMini
- Boolean parsing breaks on non strings (i.e. integer 1|0)
- Symbol parsing breaks on non strings.
- BigDecimal parsing breaks due to missing require.
- Update changelog.
2013-12-23 14:04:16 +09:00
Kenta Murata & Akira Matsuda
9e997e9039 Fix AS::NumberHelper results with large precisions
before:
  ActiveSupport::NumberHelper.number_to_rounded '3.14159', precision: 50
  => "3.14158999999999988261834005243144929409027099609375"
after:
  ActiveSupport::NumberHelper.number_to_rounded '3.14159', precision: 50
  => "3.14159000000000000000000000000000000000000000000000"
2013-12-20 16:26:35 +09:00
Yves Senn
8ac78d81b1 Merge pull request #13367 from abhishekjain16/new_branch
change to DateTime.civil_from_format from DateTime.civil_from_fromat in ...

[ci skip]
2013-12-18 01:12:08 -08:00
abhishek
29712f0cbc change to DateTime.civil_from_format from DateTime.civil_from_fromat in changelog [ci skip] 2013-12-18 14:21:10 +05:30
Carlos Antonio da Silva
8e21ae37ad Add changelog and upgrading notice related to I18n enforce_available_locales handling 2013-12-17 09:06:56 -02:00
Carlos Antonio da Silva
aaa5463cc0 Fix indent on AS changelog [ci skip] 2013-12-17 09:03:12 -02:00
Jeremy Kemper
1eee0ca6de Introduce Module#concerning
A natural, low-ceremony way to separate responsibilities within a class.

Imported from https://github.com/37signals/concerning#readme
2013-12-17 02:31:57 -07:00
Carlos Antonio da Silva
fe24f3560a Changelog improvements [ci skip] 2013-12-12 08:33:46 -02:00
Mario Visic
ffe99774bb Fix issue with Kernel#silence_stream leaking file descriptors
Calling Kernel#silence_stream creates a new file descriptor which isn't
closed after it is used. As a result calling silence_stream multiple
times leads to a build up of loose file descriptors and can cause issues
in environments where garbage collection isn't run often.
2013-12-06 10:24:06 +11:00
Yves Senn
73b57a515f set i18n.enforce_available_locales before i18n.default_locale. 2013-12-05 13:19:51 +01:00
Godfrey Chan
146e95c70d Backfilled CHANGELOG for AS::JSON::Variable removal (6f3e01e8) [ci skip] 2013-12-03 16:10:06 -08:00
Carlos Antonio da Silva
7c20a8b558 Changelog improvements [ci skip] 2013-12-03 14:38:12 -02:00
Dimko
18546d4e35 Added Date#all_week/month/quarter/year for generating date ranges 2013-12-03 20:32:20 +04:00
Colin Bartlett
029f24ede9 Add support for localized date references
Ruby's Date class automatically gives us #yesterday, #today,
and #tomorrow. And ActiveSupport has a handy Time.zone.today
for getting a localized version. But there was no localized
version of #yesterday or #tomorrow. Until now.
2013-12-03 10:37:01 -05:00
Nerian
2ebf47aea2 Modify the Hash#assert_valid_keys error message so that it shows the valid keys. Also, show the wrong value as it was entered.
{ :failore => "stuff", :funny => "business" }.assert_valid_keys([ :failure, :funny ])
=> ArgumentError: Unknown key: failore
{ 'failore' => "stuff", :funny => "business" }.assert_valid_keys([ :failure, :funny ])
=> ArgumentError: Unknown key: failore

{ 'failore' => "stuff", :funny => "business" }.assert_valid_keys([ :failure, :funny ])
=> ArgumentError: Unknown key: "failore". Valid keys are: :failure, :funny

{ :failore => "stuff", :funny => "business" }.assert_valid_keys([ :failure, :funny ])
=> ArgumentError: Unknown key: :failore. Valid keys are: :failure, :funny

Conflicts:
	activerecord/CHANGELOG.md

Closes #11624.
2013-12-03 00:12:04 -02:00
Carlos Antonio da Silva
6e905e21b1 Merge pull request #13060 from chancancode/change_log_for_json_refactor
CHANGELOG for JSON refactor + added back the `encode_big_decimal_as_string` option with warning
2013-12-02 17:47:29 -08:00
Godfrey Chan
fadc02b732 Added back the encode_big_decimal_as_string option with warning
Also added the missing CHANGELOG entry for #12183 @ 80e7552073 and
4d02296cfb.
2013-12-02 17:22:57 -08:00
Genadi Samokovarov
7dfbd91b07 Unify cattr and mattr accessors declarations 2013-12-02 23:57:20 +02:00
Yves Senn
7c6d99e81e first pass through CHANGELOGS to extract 4_1_release_notes. [ci skip]
Extract **notable changes**, **deprecations** and **removals** from
each CHANGELOG.

I tried to reference the commits and pull requests for new features
and deprecations.

In the process I also made some minor changes to the CHANGELOGS.

The 4_1_release_notes guide is declared WIP.
2013-11-28 17:24:15 +01:00
Yves Senn
0173e149b0 remove duplicate sentence from AS changelog. [ci skip]. 2013-11-28 15:43:00 +01:00
Jeremy Kemper
d4016f24fb Merge branch 'deprecate_numeric_since_ago' of https://github.com/chancancode/rails
Conflicts:
	activesupport/CHANGELOG.md
2013-11-27 03:47:35 -07:00
Godfrey Chan
1f16136049 Deprecated Numeric#{ago,until,since,from_now}
The user is expected to explicitly convert the value into an
AS::Duration, i.e. `5.ago` => `5.seconds.ago`

This will help to catch subtle bugs like:

  def recent?(days = 3)
    self.created_at >= days.ago
  end

The above code would check if the model is created within the last 3
**seconds**.

In the future, `Numeric#{ago,until,since,from_now}` should be removed
completely, or throw some sort of errors to indicate there are no
implicit conversion from `Numeric` to `AS::Duration`.

Also fixed & refactor the test cases for Numeric#{ago,since} and
AS::Duration#{ago,since}. The original test case had the assertion
flipped and the purpose of the test wasn't very clear.
2013-11-26 22:24:19 -08:00
Godfrey Chan
78cd3b0e53 Requires JSON gem version 1.7.7 or above as it contains an important
security fix.
2013-11-26 22:17:50 -08:00
Prem Sichanugrist
225cd915cf Add #travel and #travel_to to AS::TestCase
Add `ActiveSupport::Testing::TimeHelpers#travel` and `#travel_to`. These
methods change current time to the given time or time difference by
stubbing `Time.now` and `Date.today` to return the time or date after
the difference calculation, or the time or date that got passed into the
method respectively. These methods also accept a block, which will
return current time back to its original state at the end of the block.

Example for `#travel`:

    Time.now # => 2013-11-09 15:34:49 -05:00
    travel 1.day
    Time.now # => 2013-11-10 15:34:49 -05:00
    Date.today # => Sun, 10 Nov 2013

Example for `#travel_to`:

    Time.now # => 2013-11-09 15:34:49 -05:00
    travel_to Time.new(2004, 11, 24, 01, 04, 44)
    Time.now # => 2004-11-24 01:04:44 -05:00
    Date.today # => Wed, 24 Nov 2004

Both of these methods also accept a block, which will return the current
time back to its original state at the end of the block:

    Time.now # => 2013-11-09 15:34:49 -05:00

    travel 1.day do
      User.create.created_at # => Sun, 10 Nov 2013 15:34:49 EST -05:00
    end

    travel_to Time.new(2004, 11, 24, 01, 04, 44) do
      User.create.created_at # => Wed, 24 Nov 2004 01:04:44 EST -05:00
    end

    Time.now # => 2013-11-09 15:34:49 -05:00

This module is included in `ActiveSupport::TestCase` automatically.
2013-11-20 16:05:02 +07:00
Alexey Chernenkov
0e953c94b1 Unify cattr_* interface: allow to pass a block to cattr_reader.
Example:

    class A
      cattr_reader(:defr) { 'default_reader_value' }
    end
    A.defr # => 'default_reader_value'
2013-11-15 19:54:51 +06:00
Godfrey Chan
0f33d70e89 Improved compatibility with the stdlib JSON gem.
Previously, calling `::JSON.{generate,dump}` sometimes causes
unexpected failures such as intridea/multi_json#86.

`::JSON.{generate,dump}` now bypasses the ActiveSupport JSON encoder
completely and yields the same result with or without ActiveSupport.
This means that it will **not** call `as_json` and will ignore any
options that the JSON gem does not natively understand. To invoke
ActiveSupport's JSON encoder instead, use `obj.to_json(options)` or
`ActiveSupport::JSON.encode(obj, options)`.
2013-11-14 15:46:43 -08:00
Carlos Antonio da Silva
5deec016fe Improve changelogs formatting [ci skip] 2013-11-09 16:44:58 -02:00
Ryan Glover
a64d4e85e3 Standardize all JSON encoded times to use 3 decimal fractional seconds 2013-11-07 10:43:51 -05:00
Godfrey Chan
798881ecd4 Do not expose internal state in the public encoder API (i.e. as_json)
See [1] for why this is not a good idea.

As part of this refactor, circular reference protection in as_json has
been removed and the corresponding error class has been deprecated.

As discussed with @jeremy, circular reference error is considered
programmer errors and protecting against it is out of scope for
the encoder.

This is again based on the excellent work by @sergiocampama in #11728.

[1]: https://github.com/intridea/multi_json/pull/138#issuecomment-24468223
2013-11-06 17:16:11 -08:00
claudiob
c61544c781 Add +capitalize+ option to Inflector.humanize
So strings can be humanized without being capitalized:

    'employee_salary'.humanize                    # => "Employee salary"
    'employee_salary'.humanize(capitalize: false) # => "employee salary"
2013-11-06 13:03:46 -08:00
Carlos Antonio da Silva
dcee010ce8 Fix AS changelog indent, remove tabs and extra spaces [ci skip] 2013-11-06 03:09:01 -02:00
Godfrey Chan
134c1156dd Fixed Object#as_json and Struct#as_json with options
These methods now takes the same options as Hash#as_json, for example:

    struct = Struct.new(:foo, :bar).new
    struct.foo = "hello"
    struct.bar = "world"
    json = struct.as_json(only: [:foo]) # => {foo: "hello"}

This is extracted from PR #11728 from @sergiocampama, see also the
discussion in #11460.
2013-11-05 19:22:03 -08:00
David Heinemeier Hansson
423249504a Added Numeric#in_milliseconds, like 1.hour.in_milliseconds, so we can feed them to JavaScript functions like getTime(). 2013-11-02 15:40:16 -07:00
Godfrey Chan
1fb7969154 Raise an error when AS::JSON.decode is called with options
Rails 4.1 has switched away from MultiJson, and does not currently
support any options on `ActiveSupport::JSON.decode`. Passing in
unsupported options (i.e. any non-empty options hash) will now raise
an ArgumentError.

Rationale:

1. We cannot guarantee the underlying JSON parser won't change in the
   future, hence we cannot guarantee a consistent set of options the
   method could take

2. The `json` gem, which happens to be the current JSON parser, takes
   many dangerous options that is irrelevant to the purpose of AS's
   JSON decoding API

3. To reserve the options hash for future use, e.g. overriding default
   global options like ActiveSupport.parse_json_times

This change *DOES NOT* introduce any changes in the public API. The
signature of the method is still decode(json_text, options). The
difference is this method previously accepted undocumented options
which does different things when the underlying adapter changes. It
now correctly raises an ArgumentError when it encounters options that
it does not recognize (and currently it does not support any options).
2013-10-30 10:56:00 -07:00
Rafael Mendonça França
f18cf8e488 Merge pull request #11785 from grosser/grosser/file-unless-exist
support :unless_exist for FileCache

Conflicts:
	activesupport/CHANGELOG.md
	activesupport/test/caching_test.rb
2013-10-28 19:09:22 -02:00
Antonio Santos
f13fce617d slice! should not remove default hash value/proc 2013-10-24 09:17:35 +02:00
Lucas Mazza
2f1c9c8d60 Fix code blocks identation on AR and AS CHANGELOGs 2013-10-16 10:53:43 -03:00
Jeremy Kemper
365110196a Revert "Merge pull request #12480 from iwiznia/master"
This reverts commit e5f5a838b96a362534d9bb60d02334439ed9784c, reversing
changes made to d7567f3290a50952494e9213556a1f283a6cf3a0.
2013-10-11 13:05:29 -07:00
Ionatan Wiznia
90871f7198 flatten and flatten! methods for ActiveSupport::Duration 2013-10-11 12:50:23 +02:00
Xavier Noria
276956d07c registers 0b0beb7 in the CHANGELOG [ci skip] 2013-10-01 10:07:19 +02:00
Bogdan Gusiev
c31d534da5 Changelog entry for pr #11474 2013-09-23 13:15:57 +03:00
Daniel Schierbeck
d2824a347f Allow attaching to AS::Notifications namespace up front
Before, you were required to attach *after* adding the methods to the
class, since the attachment process needed the methods to be present.

With this change, any new method will also be attached to the configured
namespace.
2013-09-20 10:14:28 +02:00
Rafael Mendonça França
6827451640 Add CHANGELOG entry for #10879
[ci skip]
2013-09-12 18:34:34 -03:00
Murray Steele
accd4926cc Fix FileStore#cleanup to no longer rely on missing each_key method 2013-09-11 13:58:40 +01:00
Shay Davidson
0fb33f3fda Fixed changelog 2013-09-02 09:00:21 +03:00
grosser
c17bd7476a support :unless_exist for FileCache 2013-08-30 12:53:35 +02:00
Shay Davidson
b2ae07f0b2 Added partial days support to DateTime's advance method.
You can now add partial days (e.g. 2.5.days) to `DateTime` with the advance method.
This was acheived by mimicing the `advance` implementation in `Time`.
2013-08-30 12:21:34 +03:00
Jack Xu
24a7e60943 Enable number_to_percentage to keep the number's precision by allowing :precision to be nil
number_helper.number_to_percentage(1000, precision: nil) # => "1000%"
2013-08-28 23:46:53 -05:00
Simon Coffey
b4a9668626 Ensure all-caps nested consts marked as autoloaded
Previously, an autoloaded constant `HTML::SomeClass` would not be marked
as autoloaded by AS::Dependencies. This is because the
`#loadable_constants_for_path` method uses `String#camelize` on the
inferred file path, which in turn means that, unless otherwise directed,
AS::Dependencies watches for loaded constants in the `Html` namespace.

By passing the original qualified constant name to `#load_or_require`,
this inference step is avoided, and the new constant is picked up in the
correct namespace.
2013-08-27 08:20:33 +01:00
David Heinemeier Hansson
5da23a3f92 Add String#remove(pattern) as a short-hand for the common pattern of String#gsub(pattern, '') 2013-08-13 12:16:25 -05:00
Xavier Noria
c7ac0a5b28 renames the :abort deprecation behaviour to :raise
That is a better name, thanks @jeremy.
2013-08-13 01:44:52 +02:00
Xavier Noria
4c1454db22 fixes typo in CHANGELOG 2013-08-13 01:28:28 +02:00
Xavier Noria
73aad75f56 defines a new :abort deprecation behaviour that raises
See the CHANGELONG message in the patch for further details.
2013-08-13 01:27:18 +02:00
Joost Lubach
369a107c8e Added method #eql? to ActiveSupport::Duration, in addition to #==.
Currently, the following returns `false`, contrary to expectation:

    1.minute.eql?(1.minute)

Adding method `#eql?` will make this behave like expected. Method `#eql?` is
just a bit stricter than `#==`, as it checks whether the argument is also a
uration. Their parts may be different though.

    1.minute.eql?(60.seconds)  # => true
    1.minute.eql?(60)          # => false
2013-08-07 16:46:30 +02:00
Andrew White
0423d9c6c5 Add CHANGELOG entry for inflection removal 2013-07-30 12:00:40 +01:00
Andrew White
88c0ef4d4f Fix handling of offsets with Time#to_s(:iso8601)
Use a lambda to ensure that the generated string respects the offset of
the time value. Also add DateTime#to_s(:iso8601) and Date#to_s(:iso8601)
for completeness.
2013-07-29 12:31:20 +01:00
David Heinemeier Hansson
b67a80de9b Add Time#to_s(:iso8601) for easy conversion of times to the iso8601 format for easy Javascript date parsing 2013-07-28 16:34:43 -05:00
Carlos Antonio da Silva
68bbbd470d Move #11546 changelog to the top [ci skip] 2013-07-22 12:51:36 -03:00
Simeon Simeonov
51d9b9a821 [Fixes #11512] improves cache size calculation in ActiveSupport::Cache::MemoryStore
Previously, the cache size of `ActiveSupport::Cache::MemoryStore` was calculated
as the sum of the size of its entries, ignoring the size of keys and any data
structure overhead. This could lead to the calculated cache size sometimes being
10-100x smaller than the memory used, e.g., in the case of small values.

The size of a key/entry pair is now calculated via `#cached_size`:

    def cached_size(key, entry)
      key.to_s.bytesize + entry.size + PER_ENTRY_OVERHEAD
    end

The value of `PER_ENTRY_OVERHEAD` is 240 bytes based on an [empirical
estimation](https://gist.github.com/ssimeonov/6047200) for 64-bit MRI on
1.9.3 and 2.0.

Fixes GH#11512 https://github.com/rails/rails/issues/11512
2013-07-22 09:53:03 -04:00
Andrew White
07a4c76a07 Only raise DelegationError if it's is the source of the exception
This fixes situations where nested NoMethodError exceptions are masked
by delegations. This would cause confusion especially where there was a
problem in the Rails booting process because of a delegation in the
routes reloading code.

Fixes #10559
2013-07-11 09:05:32 +01:00
Andrew White
c42260a325 Return local time for backwards compatibility 2013-07-09 15:50:14 +01:00
Andrew White
1b3873730b Retain UTC offset when using Time.at_with_coercion
The standard Ruby behavior for Time.at is to return the same type of
time when passing an instance of Time as a single argument. Since the
an ActiveSupport::TimeWithZone instance may be a different timezone than
the system timezone and DateTime just understands offsets the best we
can do is to return an instance of Time with the correct offset.

Fixes #11350.
2013-07-09 13:43:56 +01:00
Marc Schütz
20c065594f Make HashWithIndifferentAccess#select always return the hash.
Hash#select! returns nil if the hash didn't change and thus behaves differently
from select, so it's return value can't be used as result for the latter.
2013-07-06 15:56:07 +02:00
Yves Senn
19f842b5fa Revert "remove string based terminators for ActiveSupport::Callbacks."
This reverts commit d108672dada7ba97d3b3b56f0c6001cea621061e.

Conflicts:

	activesupport/CHANGELOG.md
2013-07-05 13:53:10 +02:00
Yves Senn
e94be7b04c fix typo in Active Support CHANGELOG. [ci skip] 2013-07-05 12:43:17 +02:00
Yves Senn
d108672dad remove string based terminators for ActiveSupport::Callbacks. 2013-07-05 12:41:15 +02:00
Arun Agrawal
36321d85e9 Remove deprecated String#encoding_aware?
core extensions (`core_ext/string/encoding`).
2013-07-03 19:50:19 +02:00
Arun Agrawal
c9bbac46dd Remove deprecated Module#local_constant_names
in favor of `Module#local_constants`
2013-07-03 19:42:34 +02:00
Arun Agrawal
028f91277d Remove deprecated DateTime.local_offset 2013-07-03 19:40:24 +02:00
Carlos Antonio da Silva
39475aa350 Remove deprecated Logger core extensions (core_ext/logger.rb) 2013-07-03 13:54:34 -03:00
Yves Senn
f34b3189dd Merge pull request #11265 from vipulnsward/deprecated_time_methods
Remove deprecated `Time` methods
2013-07-03 06:37:35 -07:00
Vipul A M
ec5e03bf67 Remove deprecated Time#time_with_datetime_fallback, Time#utc_time
and `Time#local_time` in favour of `Time#utc` and `Time#local`
2013-07-03 18:52:53 +05:30
Yves Senn
33c61e3265 use American English: "favor" not "favour" [ci skip]
according to http://guides.rubyonrails.org/api_documentation_guidelines.html#english
2013-07-03 11:52:52 +02:00
Carlos Antonio da Silva
01f0c3f308 Remove deprecated Hash#diff with no replacement.
If you're using it to compare hashes for the purpose of testing,
please use MiniTest's assert_equal instead.
2013-07-02 23:32:38 -03:00
Vipul A M
4bec1da79b Remove deprecated Date#to_time_in_current_zone 2013-07-02 11:22:19 +05:30
Carlos Antonio da Silva
f62fb985b6 Remove deprecated Proc#bind with no replacement. 2013-07-01 22:38:28 -03:00
Carlos Antonio da Silva
1c06bd17a9 Remove deprecated Array#uniq_by and Array#uniq_by!
Use native Array#uniq and Array#uniq! instead.
2013-07-01 22:33:42 -03:00
Carlos Antonio da Silva
cad3a13086 Remove deprecated AS::BasicObject, use AS::ProxyObject instead 2013-07-01 22:26:54 -03:00
Yves Senn
cfa35c55bb remove deprecated BufferedLogger. 2013-07-01 22:16:37 +02:00
Yves Senn
74ebc451c9 remove deprecated assert_present and assert_blank. 2013-07-01 22:06:26 +02:00
Mark J. Titorenko
a3678e45ec Fix BacktraceCleaner#noise for multiple silencers.
The previous implementation of BacktraceSilencer#noise did not
work correctly if more than one silencer was configured --
specifically, it would only return noise which was matched by all
silencers.

The new implementation is such that anything that has been matched by
silencers is removed from the backtrace using Array#- (array
difference), ie. we now return all elements within a backtrace that
have been matched by any silencer (and are thus removed by #silence).

Fixes #11030.
2013-06-20 19:54:32 +01:00
Carlos Antonio da Silva
a9a33c59f6 Fix AS changelog [ci skip] 2013-06-14 19:53:58 -03:00
Rafael Mendonça França
6e34601653 Add CHANGELOG entry for #10740
[ci skip]
2013-06-14 17:56:49 -03:00
Andrew White
17f5d8e062 Keep sub-second resolution when wrapping a DateTime value
Add `DateTime#usec` and `DateTime#nsec` so that `ActiveSupport::TimeWithZone`
keeps sub-second resolution when wrapping a `DateTime` value.

Fixes #10855
2013-06-13 12:01:12 +01:00
Andrew Kreiling
a548792aa0 Don't blindly call blame_file! on exceptions in ActiveSupport::Dependencies::Loadable
It is possible under some environments to receive an Exception that is
not extended with Blamable (e.g. JRuby).
ActiveSupport::Dependencies::Loadable#load_dependency blindly call
blame_file! on the exception which throws it's own NoMethodError
exception and hides the original Exception.

This commit fixes #9521
2013-06-09 18:20:10 -04:00
OZAWA Sakuro
ac0b1d835d Hash#deep_*_keys(!) recurse into nested arrays.
Following methods now recursively transform nested arrays, too.

* Hash#deep_transform_keys
* Hash#deep_transform_keys!
* Hash#deep_stringify_keys
* Hash#deep_stringify_keys!
* Hash#deep_symbolize_keys
* Hash#deep_symbolize_keys!
2013-06-08 18:59:56 +09:00
Andrew White
b7f9de27f0 Override Time.at to work with Time-like values
Time.at allows passing a single Time argument which is then converted
to an integer. The conversion code since 1.9.3r429 explicitly checks
for an instance of Time so we need to override it to allow DateTime
and ActiveSupport::TimeWithZone values.
2013-06-08 09:50:15 +01:00
Yves Senn
c44a929f49 Prevent side effects in Hash#with_indifferent_access. 2013-05-29 08:43:35 +02:00
Mike Dillon
2d7a86e179 Raise when multiple included blocks are defined 2013-05-16 11:28:31 -07:00
Rafael Mendonça França
0854ba149a Fix typo: require -> requires
[ci skip]
2013-05-12 15:16:32 -03:00
Rafael Mendonça França
bf8fa7c5c7 Add CHANGELOG entry for #10576
[ci skip]
2013-05-12 15:04:05 -03:00
Rafael Mendonça França
9d6a5b4432 Give credits to all the envolved people [ci skip] 2013-05-10 14:39:29 -03:00
Mario Caropreso
582b44175b Added escaping of U+2028 and U+2029 inside the json encoder.
U+2028 and U+2029 are allowed inside strings in JSON (as all literal
Unicode characters) but JavaScript defines them as newline
seperators. Because no literal newlines are allowed in a string, this
causes a ParseError in the browser. We work around this issue by
replacing them with the escaped version. The resulting JSON is still
valid and can be parsed in the browser.

This commit has been coauthored with Viktor Kelemen @yikulju
2013-05-09 13:41:56 +01:00
Sean Walbran
2ed9ab2ed6 add changelog entry for fix-10502-skip-object-filter 2013-05-07 14:11:52 -05:00
Daniel Schierbeck
36d41a15c3 Allow fetching multiple values from the cache at once
Add a simple API for fetching a list of entries from the cache, where
any missing entries are computed by a supplied block.
2013-05-06 11:38:51 +02:00
Rafael Mendonça França
feb44b9213 rails/master is now 4.1.0.beta 2013-04-29 13:15:24 -03:00
Rafael Mendonça França
07acf7b13d Move CHANGELOG entry to top
[ci skip]
2013-04-22 01:42:30 -03:00
Rafael Mendonça França
dab58bee2a Merge pull request #10096 from benofsky/fix_skipping_object_callback_filters
Fixes skipping object callback filters
2013-04-21 21:19:18 -07:00
Daniel Schierbeck
5f07048dfd Extract a base class from ActiveSupport::LogSubscriber
Adds a ActiveSupport::Subscriber base class that LogSubscriber inherits
from. By inheriting from Subscriber, other kinds of subscribers can take
advantage of the event attachment system.
2013-04-16 14:39:22 +02:00
Yves Senn
c245437de7 use unified and clean formatting in CHANGELOGS. [ci skip] 2013-04-12 15:52:43 +02:00
Vijay Dev
b15ce4a006 Merge branch 'master' of github.com:lifo/docrails
Conflicts:
	guides/source/action_mailer_basics.md
2013-04-11 22:58:14 +05:30