Commit Graph

1810 Commits

Author SHA1 Message Date
Yves Senn
e68505a41a rewrite order dependent test case. #8185
As reported (https://github.com/rails/rails/pull/8185#issuecomment-11702226)
this test relied on the order a hash was serialized. Comparing the parsed
hash makes the test no longer order dependent.
2012-12-27 17:28:42 +01:00
Jeremy Kemper
b82109495b Make test logs easier to read.
Tagging every message in tests makes the logs really wide. It's great
for grepping, but annoying to open in an editor or a narrow terminal.
Try out a different approach: spit out a heading before each test.
2012-12-26 21:16:05 -07:00
Yves Senn
8787c6e0e5 deprecation warning when BufferedLogger is instantiated 2012-12-25 20:21:14 +01:00
Yves Senn
433ebbdc4c ActiveSupport::BufferedLogger can be subclassed 2012-12-25 15:50:35 +01:00
Zoltan Kiss
c651cc9d50 minor grammar fix 2012-12-24 15:20:05 -06:00
Xavier Noria
26c024e959 silences "possibly useless use of :: in void context" warnings
The AS utility silence_warnings does not really silence this
one, because it is issued at parse-time. It seemed to in
some places because the constant was the only expression in
the block and therefore it was its return value, that could
potentially be used by silence_warnings are return value of
the yield call.

To bypass the warning we assign to a variable. The chosen
variable is "_" because it is special-cased in parse.c not
to issue an "assigned but unused variable" warning in turn.
2012-12-24 21:16:16 +01:00
Jeremy Kemper
f9da785d0b Move background jobs to the 'jobs' branch until fully baked. Not shipping with Rails 4.0. 2012-12-21 16:29:47 -08:00
Steve Klabnik
10c0a3bd11 Merge pull request #8471 from kytrinyx/refactor-xml-to-hash
WIP Refactor xml conversion to hash
2012-12-21 15:54:13 -08:00
Steve Klabnik + Katrina Owen
b02ebe73cf Refactor Hash.from_xml.
Three basic refactors in this PR:

* We extracted the logic into a method object. We now don't define a tone of extraneous methods on Hash, even if they were private.
* Extracted blocks of the case statement into methods that do the work. This makes the logic more clear.
* Extracted complicated if clauses into their own query methods. They often have two or three terms, this makes it much easier to see what they _do_.

We took care not to refactor too much as to not break anything, and put comments where we suspect tests are missing.

We think ActiveSupport::XMLMini might be a good candidate to move to a plugin in the future.
2012-12-21 23:49:43 +00:00
Rafael Mendonça França
ecc7751575 Merge pull request #7376 from dmitriy-kiriyenko/fix-double-callback-in-same-statement
Prevent callback from being set twice.

Conflicts:
	activesupport/CHANGELOG.md
2012-12-21 17:39:03 -03:00
David Heinemeier Hansson
f914454f3a Add ActiveSupport::Logger#silence that works the same as the old Logger#silence extension 2012-12-21 19:15:36 +01:00
Dmitriy Kiriyenko
4a9644a0d9 Prevent callback from being set twice.
When you add one callack in two separate `set_callback` calls - it is
only called once.

When you do it in one `set_callback` call - it is called twice.

This violates the principle of least astonishment for me. Duplicating
callback is usually an error. There is a correct and obvious way to do
anything without this "feature".

If you want to do

    before_save :clear_balance, :calculate_tax, :clear_balance

or whatever, you should better do

    before_save :carefully_calculate_tax

    def carefully_calculate_tax
      clear_balance
      calculate_tax
      clear_balance
    end

And this even opens gates for some advanced refactorings, unlike the
first approach.

My assumptions are:

- Principle of least astonishment is violated, when callbacks are either
  prevented from duplication, or not.
- Duplicating callbacks is usually an error. When it is intentional -
  it's a smell of a bad design and can be approached without abusing
  this "feature".

My suggestion is: do not allow duplicating callbacks in one callback
call, like it is not allowed in separate callbacks call.
2012-12-20 11:06:45 +02:00
Pavel Pravosud
bb1d3c1f8e AS::BasicObject can be inherited from 2012-12-15 20:57:45 +07:00
Brett Carter
8f8397e0a4 Remove unicode character encoding from ActiveSupport::JSON.encode
The encoding scheme (e.g. ☠ -> "\u2620") was broken for characters
not in the Basic Multilingual Plane.  It is possible to escape them
for json using the weird encoding scheme of a twelve-character
sequence representing the UTF-16 surrogate pair (e.g. '𠜎' ->
"\u270e\u263a") but this wasn't properly handled in the escaping code.
Since raw UTF-8 is allowed in json, it was decided to simply pass
through the raw bytes rather than attempt to escape them.
2012-12-14 18:54:32 -05:00
Rafael Mendonça França
a565f80bcb Backport thread-local variables from Ruby 2.0 2012-12-11 18:52:02 -03:00
Andrew White
48583f8bf7 Deprecate obsolete Time to DateTime fallback methods
The Time.time_with_datetime_fallback, Time.utc_time and Time.local_time
methods were added to handle the limitations of Ruby's native Time
implementation. Those limitations no longer apply so we are deprecating
them in 4.0 and they will be removed in 4.1.
2012-12-11 13:57:05 +00:00
Andrew White
45a6f546b6 Beef up tests for String#in_time_zone and Date#in_time_zone 2012-12-11 13:08:08 +00:00
Andrew White
224d82ee59 Deprecate Date#to_time_in_current_zone
The to_time_in_current_zone method doesn't match the naming of the methods
for converting to ActiveSupport::TimeWithZone on Time and DateTime. Since
DateTime inherits from Date that has led to confusion with some users
using the to_time_in_current_zone method with DateTime instances and having
the time part dropped and the UTC offset lost.

This commit fixes this by deprecating the old method and adding a new
in_time_zone method which matches the naming for DateTime and Time. This
should prevent accidently dropping times and UTC offsets when converting
DateTime instances to ActiveSupport::TimeWithZone.
2012-12-11 07:06:34 +00:00
Andrew White
331a82a1c8 Add String#in_time_zone method
This commit adds a convenience method for converting a string to an
ActiveSupport::TimeWithZone instance using the configured Time.zone or
another passed as an argument.
2012-12-11 06:32:28 +00:00
Francesco Rodriguez
6ee03a40bb Rename ActiveSupport::BasicObject to ActiveSupport::ProxyObject
AS::BasicObject is used for proxy classes. Let's give it a less concerning
name. Also, it avoids the confusion with Ruby's Basic Object.
2012-12-07 14:13:56 -05:00
kennyj
180e2e5e9e silence warning: possibly useless use of a constant in void context 2012-12-06 01:10:03 +09:00
Carlos Antonio da Silva
e1ce84b1a9 Merge pull request #8393 from frodsan/fix_dependend_order_test_example
Ensure original encoding does not change in mb_chars test.
2012-12-03 16:19:37 -08:00
Andrew White
c89b6c4cdc Only take the date parts from Time.zone.now
When there are missing components in the Hash returned by
Date._parse only the date components should default to the
value of Time.zone.now, the time components should all
default to zero.
2012-12-01 21:05:42 +00:00
Francesco Rodriguez
86dd2f3276 ensure original encoding doesnt change 2012-12-01 15:41:06 -05:00
Uriel Katz
9ee0ffb360 Patched Marshal#load to work with constant autoloading (active_support/dependecies.rb) (issue #8167) 2012-12-01 14:00:16 +02:00
Andrew White
005d910624 Make Time.zone.parse to work with JavaScript date strings
Chrome, Safari and Firefox serialize Date objects to strings such
as 'Mon May 28 2012 00:00:00 GMT-0700 (PDT)'. When these strings
are parsed the zone is interpreted as 'GMT-0700' which doesn't
exist in the TzInfo list of timezones.

By taking advantage of the improved date/time handling in 1.9.3
we can use `Date._parse` and the `:offset` value which is parsed
correctly.

Three tests were amended to make them pass:

1.  test_parse_with_old_date

    This needed changing to a different value because the original
    value was before EST was adopted so was being changed to a
    LMT (Local Mean Time) value after the change. It didn't before
    because `DateTime` just has offsets from UTC not timezones.

2.  test_parse_should_not_black_out_system_timezone_dst_jump

    Changed the implementation of this test as the stubs were
    dependent on internal implementation details of the test.
    Confirmed that the modified test still failed when the
    implementation of `parse` was restored to pre-#5571.

3.  test_parse_should_black_out_app_timezone_dst_jump

    Ditto.

Closes #5770.
2012-12-01 11:34:21 +00:00
Olek Janiszewski
ce73055139 Add #seconds_until_end_of_day to DateTime and Time 2012-11-29 06:39:32 +01:00
Steve Klabnik
bd852603a1 Simplify String#mb_chars and stop proxying #class
This behavior mattered under Ruby 1.8, but that doesn't matter now
that we don't support it.

In addition, we don't want to proxy the #class method. A test was added
to prevent against regressions.
2012-11-28 13:58:51 -08:00
Xavier Noria
46ebce6b49 prevent Dependencies#remove_const from autoloading parents [fixes #8301] 2012-11-28 00:13:14 +01:00
Carlos Antonio da Silva
92da512125 Properly deprecate #pending from AS::TestCase
Check https://github.com/rails/rails/pull/4575#issuecomment-5765575.
2012-11-18 21:34:00 -02:00
Marc-Andre Lafortune
22edb664cf Use Integer#div instead of Integer#/ to avoid side effects from mathn 2012-11-16 03:20:55 -05:00
Santiago Pastorino
ef8b845de7 Merge pull request #8112 from rails/encrypted_cookies
Encrypted cookies
2012-11-15 12:17:25 -08:00
Rafael Mendonça França
cf3eb6dab0 Merge pull request #8219 from nikitug/threadsafe_xmlmini_with_backend
Make XmlMini.with_backend usable with threads

Conflicts:
	activesupport/CHANGELOG.md
2012-11-15 15:50:39 -02:00
Nikita Afanasenko
1fab2002e3 Make XmlMini.with_backend usable with threads
`XmlMini.with_backend` now may be safely used with threads:

  Thread.new do
    XmlMini.with_backend("REXML") { rexml_power }
  end
  Thread.new do
    XmlMini.with_backend("LibXML") { libxml_power }
  end

Each thread will use it's own backend.
2012-11-15 20:23:05 +04:00
Xavier Noria
a8c3ea90f1 let remove_constant still delete Kernel#autoload constants [rounds #8213]
The method #remove_const does not load the file, so we
can still remove the constant.
2012-11-15 11:10:03 +01:00
Xavier Noria
bff4d8d165 dependencies no longer trigger Kernel#autoload in remove_const [fixes #8213] 2012-11-15 04:36:36 +01:00
Aaron Patterson
8f6ce1a17e backporting Struct#to_h from ruby 2.0 2012-11-13 11:11:11 -08:00
Yves Senn
78dca35103 #as_json isolates options when encoding a hash. Closes #8182
Setting options in a custom `#as_json` method had side effects.
Modifications of the `options` hash leaked outside and influenced
the conversion of other objects contained in the hash.
2012-11-12 16:06:08 +01:00
Nikita Afanasenko
63ee59d48a Test Hash#diff deprecation, also prevent deprecation message in AS tests 2012-11-11 16:08:39 +04:00
Carlos Antonio da Silva
b67a03cf0b Merge pull request #7763 from route/full-capture
Kernel#capture replaced by version which can catch output from subprocesses
2012-11-08 18:10:54 -08:00
Aaron Patterson
4a7679ebca cleaning up constantize tests 2012-11-07 17:13:17 +09:00
Rafael Mendonça França
ae6d2efd84 Make the tests pass with minitest 4.2 2012-11-05 15:12:09 -02:00
Carlos Antonio da Silva
5cdeb5ef7d Fix typo in test name 2012-11-04 12:07:06 -02:00
Santiago Pastorino
38c40dbbc1 Add cookie.encrypted which returns an EncryptedCookieJar
How to use it?

cookies.encrypted[:discount] = 45
=> Set-Cookie: discount=ZS9ZZ1R4cG1pcUJ1bm80anhQang3dz09LS1mbDZDSU5scGdOT3ltQ2dTdlhSdWpRPT0%3D--ab54663c9f4e3bc340c790d6d2b71e92f5b60315; path=/
cookies.encrypted[:discount]
=> 45
2012-11-03 14:57:53 -02:00
Dmitry Vorotilin
346ccf376c Kernel#capture replaced by version which can catch output from subprocesses 2012-11-01 13:36:40 +04:00
Alexey Gaziev
b955939d55 Make caller attribute in deprecation methods optional 2012-10-30 10:23:41 +08:00
Carlos Antonio da Silva
d46f9e3731 Fix some assert_raise calls containing messages in Active Support 2012-10-28 17:54:24 -02:00
Jeremy Kemper
b79444053c Fix queueing tests that should be consuming the queue rather than draining it 2012-10-26 19:11:19 -07:00
Jeremy Kemper
26f52b2ac1 Job worker thread logs failed jobs too 2012-10-26 16:18:52 -07:00
Jeremy Kemper
411378efcf Job worker thread logs to stderr if no logger is provided 2012-10-26 16:18:52 -07:00