Commit Graph

260 Commits

Author SHA1 Message Date
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
grosser
c17bd7476a support :unless_exist for FileCache 2013-08-30 12:53:35 +02: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
Andrew White
0423d9c6c5 Add CHANGELOG entry for inflection removal 2013-07-30 12:00:40 +01:00