aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test
Commit message (Collapse)AuthorAgeFilesLines
* Tidy up previous commit, fix message assertion and improve testsCarlos Antonio da Silva2013-12-031-1/+6
|
* Modify the Hash#assert_valid_keys error message so that it shows the valid ↵Nerian2013-12-031-1/+1
| | | | | | | | | | | | | | | | | | | | 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.
* Merge pull request #13060 from chancancode/change_log_for_json_refactorCarlos Antonio da Silva2013-12-021-0/+16
|\ | | | | CHANGELOG for JSON refactor + added back the `encode_big_decimal_as_string` option with warning
| * Added back the `encode_big_decimal_as_string` option with warningGodfrey Chan2013-12-021-0/+16
| | | | | | | | | | Also added the missing CHANGELOG entry for #12183 @ 80e7552073 and 4d02296cfb.
* | Merge pull request #10996 from mattdbridges/number-helper-refactorRafael Mendonça França2013-12-021-6/+0
|\ \ | | | | | | | | | | | | | | | | | | Refactor and clean up number helpers Conflicts: activesupport/lib/active_support/number_helper.rb
| * | Extract ActiveSupport::NumberHelper methods to classesMatt Bridges2013-07-011-6/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Due to the overall complexity of each method individually as well as the global shared private module methods, this pulls each helper into it's own converter class inheriting from a generic `NumberBuilder` class. * The `NumberBuilder` class contains the private methods needed for each helper method an eliminates the need for special definition of specialized private module methods. * The `ActiveSupport::NumberHelper::DEFAULTS` constant has been moved into the `NumberBuilder` class because the `NumberBuilder` is the only class which needs access to it. * For each of the builders, the `#convert` method is broken down to smaller parts and extracted into private methods for clarity of purpose. * Most of the mutation that once was necessary has now been eliminated. * Several of the mathematical operations for percentage, delimited, and rounded have been moved into private methods to ease readability and clarity. * Internationalization is still a bit crufty, and definitely could be improved, but it is functional and a bit easier to follow. The following helpers were extracted into their respective classes. * `#number_to_percentage` -> `NumberToPercentageConverter` * `#number_to_delimited` -> `NumberToDelimitedConverter` * `#number_to_phone` -> `NumberToPhoneConverter` * `#number_to_currency` -> `NumberToCurrencyConverter` * `#number_to_rounded` -> `NumberToRoundedConverter` * `#number_to_human_size` -> `NumberToHumanSizeConverter` * `#number_to_human` -> `NumberToHumanConverter`
* | | Merge pull request #11197 from gsamokovarov/unify-mattr-cattrGuillermo Iguaran2013-12-022-74/+22
|\ \ \ | | | | | | | | Unify cattr and mattr accessors declarations
| * | | Unify cattr and mattr accessors declarationsGenadi Samokovarov2013-12-022-74/+22
| | |/ | |/|
* / | :scissors:Rafael Mendonça França2013-12-021-4/+4
|/ / | | | | | | [ci skip]
* | Fix segmentation fault in Ruby 2.0.0-p353.Dmitriy Kiriyenko2013-11-301-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | In Ruby 2.0.0-p353 there was a [commit](https://github.com/ruby/ruby/commit/66915c507777c5e3a978fa73de25db763efd9206) that switched case matching from actual sending `===` method to magic lookup, that does not see it in `method_missing`. It's hard to predict how exactly and when exactly this bug will be solved so here I suggest a solution of defining it in Duration directly. In Ruby 2.0.0-p353 without the added fix added test crashes to segmentation fault.
* | Typo fixAkshay Vishnoi2013-11-291-1/+1
| |
* | wrap test that changes inflections in with_dupLihan Li2013-11-282-4/+6
| |
* | Deprecated Numeric#{ago,until,since,from_now}Godfrey Chan2013-11-262-31/+39
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | Be explicit and use the actual unicode sequenceGodfrey Chan2013-11-261-1/+1
| |
* | Removed the Ruby encoder and switched to using the JSON gemGodfrey Chan2013-11-261-2/+2
| | | | | | | | | | | | | | | | | | Got all the tests passing again. Support for `encode_json` has been removed (and consequently the ability to encode `BigDecimal`s as numbers, as mentioned in the previous commit). Install the `activesupport-json_encoder` gem to get it back.
* | Removed support for encoding BigDecimal as a JSON numberGodfrey Chan2013-11-261-11/+0
| | | | | | | | | | | | | | | | | | | | This is because the new encoder will no longer support encode_json. Therefore our only choice is to return `to_i` or `to_s` in `BigDecimal#as_json`. Since casting a BigDecimal to an integer is most likely a lossy operation, we chose to encode it as a string. Support for encoding BigDecimal as a string will return via the `activesupport-json_encoder` gem.
* | Expanded coverage on JSON encodingGodfrey Chan2013-11-261-2/+12
| |
* | Added some failing tests where the JSON encoder is not resolving as_json ↵Godfrey Chan2013-11-261-2/+12
| | | | | | | | correctly
* | When Array#as_json and Hash#as_json are called without options, theyGodfrey Chan2013-11-221-0/+16
| | | | | | | | | | should also call #as_json on the children without options (instead of nil)
* | Add `#travel` and `#travel_to` to AS::TestCasePrem Sichanugrist2013-11-201-2/+48
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | Unify `cattr_*` interface: allow to pass a block to `cattr_reader`.Alexey Chernenkov2013-11-151-0/+9
| | | | | | | | | | | | | | | | | | Example: class A cattr_reader(:defr) { 'default_reader_value' } end A.defr # => 'default_reader_value'
* | Improved compatibility with the stdlib JSON gem.Godfrey Chan2013-11-141-0/+45
| | | | | | | | | | | | | | | | | | | | | | | | 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)`.
* | Array#split preserving the calling arrayKD2013-11-111-6/+12
| |
* | Standardize all JSON encoded times to use 3 decimal fractional secondsRyan Glover2013-11-073-5/+5
| |
* | Do not expose internal state in the public encoder API (i.e. as_json)Godfrey Chan2013-11-061-3/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* | Add +capitalize+ option to Inflector.humanizeclaudiob2013-11-063-1/+19
| | | | | | | | | | | | | | So strings can be humanized without being capitalized: 'employee_salary'.humanize # => "Employee salary" 'employee_salary'.humanize(capitalize: false) # => "employee salary"
* | Eliminate `JSON.{parse,load,generate,dump}` and `def to_json`Godfrey Chan2013-11-051-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | JSON.{dump,generate} offered by the JSON gem is not compatiable with Rails at the moment and can cause a lot of subtle bugs when passed certain data structures. This changed all direct usage of the JSON gem in internal Rails code to always go through AS::JSON.{decode,encode}. We also shouldn't be implementing `to_json` most of the time, and these occurances are replaced with an equivilent `as_json` implementation to avoid problems down the road. See [1] for all the juicy details. [1]: intridea/multi_json#138 (comment)
* | Fixed Object#as_json and Struct#as_json with optionsGodfrey Chan2013-11-051-2/+27
| | | | | | | | | | | | | | | | | | | | | | | | 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.
* | Added Numeric#in_milliseconds, like 1.hour.in_milliseconds, so we can feed ↵David Heinemeier Hansson2013-11-021-0/+4
| | | | | | | | them to JavaScript functions like getTime().
* | Raise an error when AS::JSON.decode is called with optionsGodfrey Chan2013-10-301-4/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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).
* | Merge pull request #12203 from chancancode/eager_load_jsonJeremy Kemper2013-10-303-1/+18
|\ \ | | | | | | Eagerload active_support/json/encoding in active_support/core_ext/object/to_json
| * | Moved all JSON core extensions into core_ext/object/jsonGodfrey Chan2013-09-133-1/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | TL;DR The primary driver is to remove autoload surprise. This is related to #12106. (The root cause for that ticket is that json/add defines Regexp#to_json among others, but here I'll reproduce the problem without json/add.) Before: >> require 'active_support/core_ext/to_json' => true >> //.as_json NoMethodError: undefined method `as_json' for //:Regexp from (irb):3 from /Users/godfrey/.rvm/rubies/ruby-2.0.0-p195/bin/irb:16:in `<main>' >> //.to_json => "\"(?-mix:)\"" >> //.as_json => "(?-mix:)" After: >> require 'active_support/core_ext/to_json' => true >> //.as_json => "(?-mix:)" This is because ActiveSupport::JSON is autoloaded the first time Object#to_json is called, which causes additional core extentions (previously defined in active_support/json/encoding.rb) to be loaded. When someone require 'active_support/core_ext', the expectation is that it would add certain methods to the core classes NOW. The previous behaviour causes additional methods to be loaded the first time you call `to_json`, which could cause nasty surprises and other unplesant side-effects. This change moves all core extensions in to core_ext/json. AS::JSON is still autoloaded on first #to_json call, but since it nolonger include the core extensions, it should address the aforementioned bug. *Requiring core_ext/object/to_json now causes a deprecation warnning*
* | | Merge pull request #11785 from grosser/grosser/file-unless-existRafael Mendonça França2013-10-281-0/+7
|\ \ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | support :unless_exist for FileCache Conflicts: activesupport/CHANGELOG.md activesupport/test/caching_test.rb
| * | | support :unless_exist for FileCachegrosser2013-08-301-0/+7
| | | |
* | | | Improve the test code for #8422Rafael Mendonça França2013-10-241-4/+4
| | | | | | | | | | | | | | | | | | | | * Remove unneeded comments. * Use key? instead of keys.include?.
* | | | Merge pull request #8491 from igagnidz/masterRafael Mendonça França2013-10-241-0/+10
|\ \ \ \ | | | | | | | | | | | | | | | Issue #8442
| * | | | Added test to ensure that DescendantsTracker does not leak memory on ↵Iuri Gagnidze2012-12-091-0/+10
| | | | | | | | | | | | | | | | | | | | singleton classes
* | | | | slice! should not remove default hash value/procAntonio Santos2013-10-241-0/+18
| | | | |
* | | | | `$SAFE = 4;` has been removed with Ruby 2.1Vipul A M2013-10-141-13/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | For background - https://bugs.ruby-lang.org/issues/8468 Changset - https://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/41259/diff/test/ruby/test_thread.rb
* | | | | Revert "Merge pull request #12480 from iwiznia/master"Jeremy Kemper2013-10-111-15/+0
| | | | | | | | | | | | | | | | | | | | | | | | | This reverts commit e5f5a838b96a362534d9bb60d02334439ed9784c, reversing changes made to d7567f3290a50952494e9213556a1f283a6cf3a0.
* | | | | flatten and flatten! methods for ActiveSupport::DurationIonatan Wiznia2013-10-111-0/+15
| | | | |
* | | | | Merge pull request #12412 from bf4/allow_pathname_for_require_dependencyXavier Noria2013-09-301-0/+11
|\ \ \ \ \ | | | | | | | | | | | | Allow Pathname for require dependency
| * | | | | require_dependency should allow Pathname-like objects, not just StringBenjamin Fleischer2013-09-301-0/+11
| | | | | |
* | | | | | Merge pull request #11474 from bogdan/time-with-zone-succAndrew White2013-09-221-0/+22
|\ \ \ \ \ \ | | | | | | | | | | | | | | Prevent server blow up when iterating over TimeWithZone Range
| * | | | | | Disable ability to iterate over a Range of TimeWithZoneBogdan Gusiev2013-07-191-0/+22
| | | | | | |
* | | | | | | Allow attaching to AS::Notifications namespace up frontDaniel Schierbeck2013-09-201-0/+40
| |_|_|_|/ / |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | | | | | Merge pull request #12196 from h-lame/fix-activesupport-cache-filestore-cleanupRafael Mendonça França2013-09-121-0/+12
|\ \ \ \ \ \ | | | | | | | | | | | | | | Fix FileStore#cleanup to no longer rely on missing each_key method
| * | | | | | Fix FileStore#cleanup to no longer rely on missing each_key methodMurray Steele2013-09-111-0/+12
| | | | | | |
* | | | | | | Enabled quirks mode on JSON.parse, fixes broken test in af9caaeGodfrey Chan2013-09-121-1/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It turns out that ActionPack depends on the decoder to parse JSON "fragments" (e.g. '"a string"', '1', 'null', etc), so we need to enable quirks mode on JSON.parse. Also added coverage on the decoder side to prevent regression.
* | | | | | | Replace JSON.load with JSON.parse, also removed the proc parameterGodfrey Chan2013-09-111-1/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Since we are dealing with untrusted user input, we should not be using JSON.load. According to the docs[1]: BEWARE: This method is meant to serialise data from trusted user input, like from your own database server or clients under your control, it could be dangerous to allow untrusted users to pass JSON sources into it. The default options for the parser can be changed via the ::load_default_options method. [1] http://www.ruby-doc.org/stdlib-2.0/libdoc/json/rdoc/JSON.html#method-i-load