Commit Graph

1943 Commits

Author SHA1 Message Date
Sam Ruby
8efc87c14e switch (and lazily convert) ivar names to 3.x 2013-04-16 13:18:52 -04:00
Vipul A M
afdf279e2f refactor order hash test 2013-04-11 21:55:45 +05:30
Rafael Mendonça França
d716fe05df Revert "Merge pull request #10158 from steveklabnik/issue_10125"
This reverts commit fa3ef8e82ab2f96cf15ef9bc885b2468fad77621, reversing
changes made to e0af93dd3a5eeee2e2a67b05f34afb66cc80c00b.

Reason: Routes, Active Record and the rendering stack should not depend
on the default locale
2013-04-10 12:44:39 -03:00
Anupam Choudhury
ea4cb5d1f3 Removed unused setup 2013-04-10 16:57:12 +05:30
Anupam Choudhury
975234c680 Fixed typo 2013-04-10 15:13:10 +05:30
Nick Cox
8cf88cc75a Fix inflector to respect default locale.
The inflector was made aware of locales in 7db0b073fec6bc3e6f213b58c76e7f43fcc2ab97,
but it defaulted to :en. That should actually be our default
locale instead.

Fixes #10125
2013-04-10 04:22:34 +00:00
Agis-
941986c7db Add option to Class#class_attribute for skipping the query method 2013-04-06 20:34:13 +03:00
Ben McRedmond
8e1d3cd490 Fixes skipping object callback filters
This allows you to skip callbacks that are defined by objects, e.g. for
`ActionController`:

    skip_after_filter MySpecialFilter

Previously this didn't work due to a bug in how Rails compared callbacks
in `Callback#matches?`. When a callback is compiled, if it's an object
filter (i.e. not a method, proc, etc.), `Callback` now defines a method on
`@klass` that is derived from the class name rather than `@callback_id`.
So, when `skip_callback` tries to find the appropriate callback to
remove, `Callback` can regenerate the method name for the filter
object and return the correct value for `Callback#matches?`.
2013-04-04 16:11:13 -07:00
Rafael Mendonça França
49a0f554a6 Revert "Merge pull request #10034 from benofsky/fix_skipping_object_callback_filters"
This reverts commit c79c6980647eb76bfa52178711fb04ba7e9d403b, reversing
changes made to ba4c27479add60b783a0e623c8a5d176c1dc9043.

This broke all the tests. See https://travis-ci.org/rails/rails/builds/6061839
2013-04-04 18:19:55 -03:00
Rafael Mendonça França
c79c698064 Merge pull request #10034 from benofsky/fix_skipping_object_callback_filters
Fixes skipping object callback filters
2013-04-04 13:55:02 -07:00
Ben McRedmond
e377228342 Fixes skipping object callback filters
This allows you to skip callbacks that are defined by objects, e.g. for
`ActionController`:

    skip_after_filter MySpecialFilter

Previously this didn't work due to a bug in how Rails compared callbacks
in `Callback#matches?`. When a callback is compiled, if it's an object
filter (i.e. not a method, proc, etc.), `Callback` now defines a method on
`@klass` that is derived from the class name rather than `@callback_id`.
So, when `skip_callback` tries to find the appropriate callback to
remove, `Callback` can regenerate the method name for the filter
object and return the correct value for `Callback#matches?`.
2013-04-04 11:45:13 -07:00
Carlos Antonio da Silva
363c08fa60 Further simplify enumerable group_by test 2013-04-04 12:36:17 -03:00
Anupam Choudhury
ecdd432f57 Replaced inject with map 2013-04-04 20:36:27 +05:30
Anupam Choudhury
f73140fd47 Removed unused comma after loop variable 2013-04-04 20:36:27 +05:30
Anupam Choudhury
ae984cb1ef Added missing assert 2013-04-02 11:50:25 +05:30
Vipul A M
5a0e583f40 fix some typos in AS 2013-03-30 14:01:42 +05:30
Xavier Noria
341e611547 determine_constant_from_test_name does not swallow NoMethodErrors [Yves Senn] 2013-03-28 10:04:39 +01:00
Rafael Mendonça França
57fbcc5247 Merge pull request #9523 from stopdropandrew/Instrumenter#instrument-yields-payload
ActiveSupport::Notifications::Instrumenter#instrument should yield

Conflicts:
	activesupport/CHANGELOG.md
2013-03-27 17:43:33 -03:00
kennyj
445bc3a200 Fix warning: mismatched indentatmmismatched indentations at 'end' with 'def' 2013-03-19 20:52:20 +09:00
Aaron Patterson
2392535f40 Merge branch 'master-sec'
* master-sec:
  fix protocol checking in sanitization [CVE-2013-1857]
  JDOM XXE Protection [CVE-2013-1856]
  fix incorrect ^$ usage leading to XSS in sanitize_css [CVE-2013-1855]
  stop calling to_sym when building arel nodes [CVE-2013-1854]
2013-03-18 10:17:32 -07:00
Andrew White
341f9a0799 Merge pull request #9774 from senny/9772_reraise_no_method_error_in_proper_context
`TimeWithZone` raises `NoMethodError` in proper context.
2013-03-18 09:49:44 -07:00
Yves Senn
836ea9fb42 TimeWithZone raises NoMethodError in proper context.
Closes #9772.

`TimeWithZone` delegates everything to the wrapped `Time` object
using `method_missing`. The result is that `NoMethodError` error
will be raised in the context of `Time` which leads to a misleading
debug output.
2013-03-18 17:41:34 +01:00
Vipul A M
4bd8ccd984 fix repeat of test; remove unused variable by use of each_key 2013-03-18 19:58:02 +05:30
Carlos Antonio da Silva
28cb11045b Merge pull request #9757 from vipulnsward/remove_message_param
remove unused parameter passed to assert_query_equal method
2013-03-17 08:35:06 -07:00
Vipul A M
b9f7e634ad refactor test to drop unnecessary hash creation, test directly instead 2013-03-17 16:21:33 +05:30
Vipul A M
c7ea42c244 remove unused parameter passed to assert_query_equal method 2013-03-17 15:15:00 +05:30
Steve Klabnik
feaa6e2048 Revert "Merge pull request #8156 from fredwu/acronym_fix-master"
This reverts commit 867dc1700f32aae6f98c4651bd501597e6b52bc0, reversing
changes made to 9a421aaa8285cf2a7ecb1af370748b0337818930.

This breaks anyone who's using ForceSSL: https://travis-ci.org/rails-api/rails-api/jobs/5556065

Please see comments on #8156 for some discussion.
2013-03-16 15:25:49 -07:00
Fred Wu
515feb1fd6 Fixed a bug where the inflector would replace camelCase strings and disregarding specified acronyms, fixes #8015 2013-03-17 00:31:00 +11:00
Ben Murphy
db8b636e50 JDOM XXE Protection [CVE-2013-1856] 2013-03-15 17:46:15 -07:00
Steve Klabnik
1a9055073d Revert "make new rails apps log to STDOUT"
This reverts commit b7d9d6e2cd5082d269dafbc0316e2107febe1451.

Per discussion with @jeremy and @rubys on Campfire.
2013-03-15 10:38:00 -07:00
Terence Lee
b7d9d6e2cd make new rails apps log to STDOUT 2013-03-15 10:05:10 -07:00
Andrew White
dff86e6ea0 Add regression tests for #9678
The bug with `ActiveSupport::TimeZone.parse` described in #9678 was
unwittingly fixed in 005d910 so add some tests to prevent regression.
2013-03-13 05:46:34 +00:00
Carlos Antonio da Silva
466ff9310a Merge pull request #9681 from vipulnsward/fix_typo_in_module_name
Fix typo in DependenciesTestHelpers module name
2013-03-12 03:55:30 -07:00
Vipul A M
8778e1c4af Fix typo in DependenciesTestHelpers module name 2013-03-12 10:33:32 +05:30
Vipul A M
647a9abb02 Cleanup tests for unused variables 2013-03-11 16:03:10 +05:30
Paul Nikitochkin
20ae0d0e39 Fixed tests for returning an instance of Time in the local system timezone. 2013-03-10 23:57:11 +02:00
stopdropandrew
a007800a55 ActiveSupport::Notifications::Instrumenter#instrument should yield
its payload the same way that ActiveSupport::Notifications does.
Fix spelling in test name.
2013-03-02 16:05:05 -08:00
Charles Jones
b8837066dc Fix deletion of empty directories:
1. When comparing the directory to delete against the top level
   cache_path, use File.realpath to make sure we aren't comparing two
   unequal strings that point to the same path. This occurs, for
   example, when cache_path has a trailing slash, which it does in the
   default Rails configuration. Since the input to
   delete_empty_directories never has a trailing slash, the comparison
   will never be true and the top level cache directory (and above) may
   be deleted. However…

2. File.delete raises EPERM when trying to delete a directory, so no
   directories have ever been deleted. Changing the code to Dir.delete
   fixes that.
2013-02-25 18:54:44 -06:00
Chris Baynes
fa891a2b9d Keep second fraction when DateTime#change is called. 2013-02-25 11:05:49 +01:00
stopdropandrew
cb100ca02b Added ActiveSupport::TimeWithZone#to_r for Time#at compatibility. 2013-02-24 13:24:50 -08:00
Carlos Antonio da Silva
38f347a825 Move number_to_human test from AP to AS
Since all changes from #9347 are related to AS, it seems proper that the
test is placed there as well.
2013-02-22 19:44:50 -03:00
Gagan Awhad
6f380d3778 Added beginning_of_minute support to core_ext calculations for Time and DateTime 2013-02-21 16:14:16 -06:00
Beyond
d59a877da4 added compress options for gzip
added test for compress options of gzip

update changelog
2013-02-10 20:01:42 +09:00
Jeremy Kemper
c7598134a4 Merge pull request #9128 from jamesotron/iso8601-sub-second-accuracy
Modify TimeWithZone#as_json to return 3DP of sub-second accuracy.
2013-02-06 12:33:28 -08:00
Akira Matsuda
9ec14c223b Missing require extract_options 2013-01-31 15:56:47 +09:00
James Harton
28ab79d7c5 Modify TimeWithZone#as_json to return 3DP of sub-second accuracy by default, since it's allowed by the spec and is very useful. 2013-01-31 14:11:51 +13:00
Xavier Noria
30034dfbc4 Merge pull request #8830 from antoinelyset/master
Improve String#squish whitespaces matching
2013-01-28 13:24:56 -08:00
Akira Matsuda
5f30b547c8 Use Encoding::UTF_8 constant 🚯 2013-01-28 17:06:02 +09:00
Akira Matsuda + Koichi Sasada
b7b27fc2a3 Set Thread.abort_on_exception for the whole AS, AP, and AR tests
this would give us some more clues in case a test silently dies inside Thread
2013-01-24 20:00:45 +09:00
Akira Matsuda
9b0f3faab4 Fix some wrong String extensions tests
* ASCII_STRING was not an ASCII String
* BYTE_STRING was not an in valid UTF-8 String
* added an assertion for non-UTF-8 String
2013-01-23 13:30:55 +09:00
Akira Matsuda
389ae055ae Test String#dasherize 2013-01-23 13:29:40 +09:00
Akira Matsuda
740d363890 Test that rescue_from accepts a class name in String 2013-01-23 13:29:40 +09:00
Akira Matsuda
ffd0dd31f8 Test Kernel#quietly 2013-01-23 13:29:40 +09:00
Akira Matsuda
36ff09d7da Test try! with a block 2013-01-23 13:29:40 +09:00
Akira Matsuda
ce0f977ae9 Test that DeprecatedConstantProxy does not warn when accessing its class 2013-01-23 13:29:40 +09:00
Akira Matsuda
4c5c98d0d3 Missing AS::Deprecation::DeprecatedObjectProxy test 2013-01-23 13:29:40 +09:00
Akira Matsuda
6343227bb0 Test that a DateTime acts_like_date 2013-01-23 13:29:40 +09:00
Antoine Lyset
b5245da94a Improve String#squish whitespaces matching 2013-01-22 22:46:11 +01:00
Xavier Noria
3f18f73c20 Merge pull request #8671 from xuanxu/fix_irregular
Inflector irregular singularize rules
2013-01-21 08:06:26 -08:00
Andrew White
ee3458217b Use DateTime.parse inside String#to_datetime
Use the standard library's `DateTime.parse` because it's marginally
faster and supports partial date/time strings.

Benchmark:
       user     system      total        real
old  3.980000   0.000000   3.980000 (  3.987606)
new  3.640000   0.010000   3.650000 (  3.641342)
2013-01-21 12:33:49 +00:00
Andrew White
b79adc4323 Standardise the return value of to_time
This commit standardises the return value of `to_time` to an instance
of `Time` in the local system timezone, matching the Ruby core and
standard library behavior.

The default form for `String#to_time` has been changed from :utc to
:local but research seems to suggest the latter is the more common form.

Also fix an edge condition with `String#to_time` where the string has
a timezone offset in it and the mode is :local. e.g:

  # Before:
  >> "2000-01-01 00:00:00 -0500".to_time(:local)
  => 2000-01-01 05:00:00 -0500

  # After:
  >> "2000-01-01 00:00:00 -0500".to_time(:local)
  => 2000-01-01 00:00:00 -0500

Closes #2453
2013-01-21 12:33:49 +00:00
Carlos Antonio da Silva
239a97af55 Fix failing test about date.order translation values
Introduced in b718998f3e8e6f3d01ad138e40f08fbcc3736285.
2013-01-19 19:32:33 -02:00
gsphanikumar
0246712bc1 Test to allow Range including DateTime and DateTime::Infinity
Closes #8587
2013-01-14 00:51:43 -02:00
Yves Senn
3e1ed7818b extract PerformanceTest into rails-performance_tests gem 2013-01-10 17:09:06 +01:00
Aaron Patterson
56f3d05f47 adding start / finish on the instrumenter, adding tests for the class 2013-01-09 15:34:58 -08:00
Vijay Dev
f92c2b103e Merge pull request #8859 from tehgeekmeister/master
Fix a typo in a test.
2013-01-09 13:53:24 -08:00
Ezekiel Smithburg
77828e20fc s/messqage/message/ in message_encryptor_test.rb 2013-01-09 13:32:35 -08:00
Jeremy Kemper
46e0d2397e CVE-2013-0156: Safe XML params parsing. Doesn't allow symbols or yaml. 2013-01-08 12:42:29 -08:00
Jeremy Kemper
c31cc963da Revert "Merge branch 'master-sec'"
This reverts commit 88cc1688d0cb828c17706b41a8bd27870f2a2beb, reversing
changes made to f049016cd348627bf8db0d72382d7580bf802a79.
2013-01-08 12:41:04 -08:00
Jeremy Kemper
2ced6f2f8a CVE-2013-0156: Safe XML params parsing. Doesn't allow symbols or yaml. 2013-01-08 12:03:34 -08:00
Akira Matsuda
c8e632bd9f Namespace HashWithIndifferentAccess 2013-01-07 07:37:23 +09:00
Akira Matsuda
70ae89c321 Remove unnecessary begin..rescue..end, use only rescue 2013-01-06 15:41:14 +09:00
Yves Senn
947e1d5e85 deprecate assert_blank and assert_present.
They don't add any benefits over `assert object.blank?`
and `assert object.present?`
2013-01-05 18:04:52 +01:00
Kelly Stannard
ebd27d5714 Better error message for String#to_date
I did this because to_date gives a very unhelpful error message if you
do not pass in a correct date. In the process I think this cleans up the
 code nicely and even better it tends to be slightly faster than the
 current implementation.

Benchmark
https://gist.github.com/4440875
2013-01-04 16:39:18 +00:00
Rafael Mendonça França
59e0c2624a Remove assert_nothing_raised 2013-01-03 23:14:57 -03:00
bUg
38f28dca3a Added ability to compare date/time with infinity
Date, DateTime, Time and TimeWithZone can now be compared to infinity,
  so it's now possible to create ranges with one infinite bound and
  date/time object as another bound.

  Ex.: @range = Range.new(Date.today, Float::INFINITY)

Also it's possible to check inclusion of date/time in range with
  conversion.

  Ex.: @range.include?(Time.now + 1.year) # => true
       @range.include?(DateTime.now + 1.year) # => true

Ability to create date/time ranges with infinite bound is required
  for handling postgresql range types.
2013-01-04 02:41:09 +01:00
Juanjo Bazán
ef4ac7a489 Inflector irregular singularize rules 2013-01-01 12:50:00 +01:00
Rafael Mendonça França
e6e3a64982 Only call MiniTest.autorun if the dependecy is present 2012-12-31 16:25:07 -03:00
Rafael Mendonça França
5294ad82c6 Alias refute methods to assert_not and perfer assert_not on tests 2012-12-31 13:58:52 -03:00
Rafael Mendonça França
d4c94accf7 Remove unneeded tests
These tests are needed only if we are using MiniTest::Spec
2012-12-31 13:57:24 -03:00
Rafael Mendonça França
5da4d5142a Add active_support/testing/autorun
minitest/autorun load minitest/spec polluting the global namespace with
the DSL that we don't want on Rails
2012-12-31 13:57:24 -03:00
Jeremy Kemper
8a130ece7e Test that assert_not returns true. Use assert_raises instead of doing begin/rescue/else. 2012-12-28 21:47:42 -07:00
Jeremy Kemper
f75addd06b Introduce assert_not to replace 'assert !foo' 2012-12-28 10:34:26 -07:00
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