summaryrefslogtreecommitdiff
path: root/spec/hashie/mash_spec.rb
Commit message (Collapse)AuthorAgeFilesLines
* Changes to `Mash` initialization key string conversion. (#521)Caroline Artz2020-05-041-9/+13
|
* Don't warn when setting most affixed keys (#500)Michael Herold2020-01-151-0/+22
| | | | | | | | | | | | | | | | | | | | | Due to how we have implemented the bang/underbang/query behavior within Mash, setting keys that have those affixes in them actually allow overwriting the behavior of those affixes. As such, we shouldn't warn when setting a key that matches those patterns. When it comes to setter-like keys, I believe we still _do_ want to warn for two reasons: 1. Trying to access the key via method access is a syntax error. Ruby expects any method ending in `=` to be a 2+-arity method due to the infix notation of setter methods. This is unexpected behavior unless you're very familiar with Ruby parsing. 2. You can still retrieve the key via the normal `Hash#[]` reader, but it prevents setting a similar key without the equal sign. You can see this in the test about setters. I'd say that is unexpected and surprising behavior. Because of these two gotchas, I think we should still warn in cases where you try to set a key that looks like a setter.
* Fix except use in Mash#load (#508)Bobby McDonald2020-01-141-19/+7
|
* Only define compact on ruby >= 2.4Bobby McDonald2020-01-131-21/+21
|
* Ensure that Hashie::Arrays are not deconvertedMichael Herold2019-12-131-0/+9
| | | | | | | In order for `#dig` to work properly, we need Arrays to be `Hashie::Array`s to be aware of the key conversion. Our original `Mash#convert_value` method was deconverting `Hashie::Array`s into normal Arrays and causing `#dig` to behave in an unexpected manner.
* Update github urls to hashie/hashie (#497)Bobby McDonald2019-11-171-1/+1
| | | | | | | | | | | | | | | | * Update github urls to hashie/hashie * Point omniauth in integration tests at master. Until omniauth releases the changes merged from https://github.com/omniauth/omniauth/pull/977 , we must point at master branch. * revert incorrect change of gem email Co-Authored-By: Michael Herold <github@michaeljherold.com> * Reference open issue for release
* Merge pull request #492 from BobbyMcWho/remove-blacklist-whitelistDaniel Doubrovkine (dB.) @dblockdotorg2019-10-281-15/+15
|\ | | | | Remove references to blacklists and whitelists
| * Remove references to blacklists and whitelistsBobby McDonald2019-10-251-15/+15
| |
* | Change rubocop to allow 100 character lines.Bobby McDonald2019-10-171-4/+6
|/ | | | | For accessibility reasons, we should limit our lines to 100 chars max. https://github.com/slack-ruby/slack-ruby-client/pull/293#discussion_r309472083
* Allow mash error silencing (#488)Bobby McDonald2019-10-141-4/+19
|
* Implement ruby 2.6 hash merging.Bobby McDonald2019-08-141-0/+11
| | | | | | As of ruby 2.6, Hash#merge and Hash#merge! allow for multiple hashes to be passed to the method, and will merge each one in the order that they were passed.
* Implement non-destructive hash methodsBobby McDonald2019-08-141-0/+151
| | | | | | | | | | | | | | | When calling the following non-destructive hash methods: :compact :invert :reject :select :slice :transform_keys :transform_values we would be returned an instance of a standard Hash rather than a Mash (or subclass). This changes that behavior to instead return an instance of the class the method was called on.
* Add selective key-conflict warnings for Mash subclasses (#478)Bobby McDonald2019-07-181-1/+72
| | | | | | | | | | | In some cases, you want to be able to ignore Mash warnings for keys that you know you aren't going to access via a method accessor, yet be warned for other keys that you know you might want to access. This change adds the ability to selectively ignore warnings for specific keys instead of globally ignoring the warnings. The change retains the original behavior as well, so if you call `Mash.disable_warnings` without a value it will still globally ignore the warnings.
* Allow options on Mash.load (#474)Daniel Doubrovkine (dB.) @dblockdotorg2019-03-221-5/+41
| | | | | | | | | | | | | | | | | `Mash.load` uses the Ruby standard library to load Yaml-serialized files into a Mash. The original implementation used `YAML.load` for this purpose. However, that method is inherently unsafe so we switched to using `YAML.safe_load`. Safely loading Yaml files has many different domain-specific configuration flags that we did not, by default, expose. This change introduces the ability to configure the safe loading of Yaml files so that all types of Yaml can be loaded when necessary using the flags from the standard library. This implementation preserves the backwards-compatibility with the prior implementation so that it should not require updates from users of the current `Mash.load` behavior. For those who this change affects, we included upgrading documentation to ease the transition.
* Do not call any reader attribute in Mash#update if key does not existLaerti Papa2018-10-021-0/+9
| | | | Refs: https://github.com/intridea/hashie/issues/464
* [rubocop] Improve our RuboCop setupMichael Herold2018-09-301-1/+4
| | | | | | | | | | | Disable Metrics/BlockLength in specs because the length of a block in the test suite isn't something we want to lint. We want the tests to be as long as they need to be. Set an explicit line length metric instead of continually updating this as we go. Let's pick a max line length that we want to see and stick with it. This metric should only ever decrease: we don't want to see it ever increase again.
* Fix a regression with aliases on `Mash.load`Michael Herold2018-08-141-0/+8
| | | | | Also, reorganize the test into the existing file and update the changelog.
* Update Rubocop and address the addressable todosMichael Herold2018-06-171-8/+9
| | | | | | | | | | | | | | | | | | | | | This is a big step forward in our Rubocop setup. I addressed all of the todos from the current version of Rubocop that made sense to. The only things that remain are metrics and one cop that relies on the line length metric to work. I made some judgment calls on disabling a few cops: 1. The `Layout/IndentHeredoc` cop wants you to either use the squiggly heredoc from Ruby 2.3 or introduce a library. Since we are a low-level library that is used as a transitive dependency, we cannot introduce another library as a dependence, so that option is out. Also, we support Rubies back to 2.0 currently, so using the squiggly heredoc isn't an option. Once we remove support for Rubies older than 2.3, we can switch to the squiggly heredoc cop. 2. The `Naming/FileName` cop was reporting false positives for a few files in the repository, so I disabled it on those files. 3. The `Style/DoubleNegation` cop reports lints on a few cases where we use double negation. Given the very generic nature of Hashie, the double-negation is the easiest, clearest way to express that we want an item to be a Boolean. I disabled the cop because we exist in the gray area where this makes sense.
* Propagate Mash `default_proc` to sub-HashesMichael Herold2018-02-041-0/+7
| | | | | | | | | | | | | | | | | | | | In the case where you want to set deeply nested values through chained calls to the `#[]` method or through method accessors (without using the bang methods), you might set a `default_proc` on a Mash that recursively creates the key as you access it. Previously, the `default_proc` was not being propagated down to sub-Hashes because the way that `#dup` was written wasn't passing the `default_proc` do the duplicated object. Now, the `default_proc` is correctly being sent to the duplicated object, which allows this pattern to work: ```ruby h = Hashie::Mash.new { |mash, key| mash[key] = mash.class.new(&mash.default_proc) } h.a.b.c = :xyz h[:a][:b][:c] #=> :xyz h[:x][:y][:z] = :abc h.x.y.z #=> :abc ```
* Don't log when overwriting Mash keysMichael Herold2017-02-241-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When we switched to using `#respond_to?` to detecting whether to log a Mash collision, we started reporting when we were overwriting keys that already exist in the Mash. This is a poor experience because it causes extra warnings (as in #414) or, in the worst case, causes an "undefined method" error (as in #413). This change fixes that problem and benchmarks to ensure we're not appreciably regressing performance. The results of two benchmarks are below: ``` bundle exec ruby benchmark/mash_method_access.rb: Warming up -------------------------------------- before 92.456k i/100ms Calculating ------------------------------------- before 1.290M (± 4.4%) i/s - 6.472M in 5.028183s Pausing here -- run Ruby again to measure the next benchmark... Warming up -------------------------------------- after 92.941k i/100ms Calculating ------------------------------------- after 1.326M (± 5.4%) i/s - 6.692M in 5.060756s Comparison: after: 1326239.2 i/s before: 1289624.0 i/s - same-ish: difference falls within error ``` and ``` within spec/integrations/omniauth, bundle exec rake perf:ips Warming up -------------------------------------- before 1.260k i/100ms Calculating ------------------------------------- before 13.114k (± 4.2%) i/s - 66.780k in 5.101689s Pausing here -- run Ruby again to measure the next benchmark... Warming up -------------------------------------- after 1.299k i/100ms Calculating ------------------------------------- after 13.149k (± 4.0%) i/s - 66.249k in 5.046630s Comparison: after: 13148.9 i/s before: 13113.8 i/s - same-ish: difference falls within error ``` Closes #413 Closes #414
* Carry over disabling warnings to subclassesMichael Herold2017-02-101-0/+11
|
* Fix passing Pathname object to Hashie::Mesh.load()Albert Song2017-02-081-0/+14
| | | | With a test that would fail without this patch.
* Allow Mash subclasses to disable warningsMichael Herold2017-02-041-5/+19
| | | | | | | | | | | | | | | | | Since we are transitively used as a dependency in many projects, we should have given the ability to toggle this behavior off. The logging feature is more of a "help people get started with Mash" feature. If you're using Hashie in a library, it's likely that you already know the tradeoffs of attempting to override methods on the object. To use this feature, you only have to subclass Mash and then call the class method: ```ruby class KeyStore < Hashie::Mash disable_warnings end ```
* Fix specs using shared context 'with a logger'Bill Ruddock2017-02-031-5/+6
| | | | Correct usage of a shared_context is to use include_context
* Add a logging layer to address common issues (#381)Michael Herold2016-11-021-0/+8
|
* Fix support for Array#digjonathan schatz2016-06-011-2/+9
|
* Convert Mash keys for #digTakashi Kokubun2016-02-081-0/+11
|
* Make reverse_merge compatible with subclassing.Vladimir Kochnev2015-11-151-0/+9
|
* @dblockPeter Boling2015-10-221-1/+0
| | | | | - a one liner with no complexity for pending specs by Ruby Engine / Version - removes all complexity from Hashie
* - Restrict pending the spec to only Ruby versions 2.2.0, 2.2.1, 2.2.2Peter Boling2015-10-181-3/+1
| | | | - Better paradigm for pending specs due to bugs in interpreter
* Add a conditional check for 2.2.x specsMichael Herold2015-04-181-12/+16
| | | | | | | | | | | | | | | | | | | | | | | This adds a way to handle the broken spec in MRI 2.2.x that was introduced by a regression in the language. It is slated to be in 2.3.0 and seems partially fixed in 2.2.2. In order to have the full spec suite run on every version of Ruby but keep the brevity of the Mash specs, we needed a way to check for the Ruby version and selectively disable the two errant specs. We need to be testing on the latest Ruby, so this seems to be the best compromise. For more information on the breakage in Ruby, see [issue 285][rubybug]. For more information on this decision, see [issue 294][workaround]. Fixes #294 /cc #285 [rubybug]: https://github.com/intridea/hashie/pull/285 [workaround]: https://github.com/intridea/hashie/pull/294
* MRI 2.2.2 fixes bug, can test #method againJonathan Rochkind2015-04-181-0/+2
|
* Fix comment to link to bugMichael Herold2015-04-091-2/+2
|
* (Fixed) specs to run with ruby 2.2Michael Sievers2015-04-091-2/+12
|
* Add Hashie::Mash#reverse_merge. Increase Rubocop class length.Max Goldstein2015-02-251-0/+13
| | | | Fixes intridea/hashie#270
* add Hashie::Mash#extractable_options?Ryan Buckley2015-01-191-0/+12
|
* Fix handling of default proc values in MashErol Fornoles2014-12-301-0/+32
|
* Merging Hashie::Mash now correctly only calls the block on duplicate valuesAmy Sutedja2014-09-051-0/+6
|
* Add a test to prevent Mash from losing indifferent_access of nested hashKen Ip2014-08-271-0/+10
| | | | See discussion at https://github.com/intridea/hashie/pull/197
* Revert "dont convert keys on initialization"dblock2014-08-261-19/+9
| | | | | | | This reverts commit 33f73e0635fc4d2c9f4726c744b50667c82d7b39. Conflicts: CHANGELOG.md
* dont convert keys on initializationgregory2014-07-221-9/+19
|
* Added Mash#load with YAML file support.gregory2014-07-141-0/+92
|
* Fix Hashie::Mash#values_at.Tom Hulihan2014-06-271-0/+23
| | | | | This method now converts the keys before trying to access them from the Mash.
* Remove active record specific extensions as they are moved to hashie_railsMaxim Filimonov2014-06-031-10/+0
|
* Upgraded to RSpec 3.0.dblock2014-06-031-17/+17
|
* Replaced respond_to with respond_to_missing in Mash and ActiveModel.dblock2014-05-011-6/+15
|
* Upgraded Rubocop, removed broken platforms from Travis.dblock2014-04-301-2/+2
|
* Reorganized extensions, consolidated Hashie StringifyKeys implementation.dblock2014-04-301-0/+8
|
* Added Hashie::Extensions::Mash::ActiveModel for compatibility with Rails 4 ↵dblock2014-04-301-3/+8
| | | | Strong Parameters.
* Fix Rubocop violation introduced by transpecPeter M. Goldstein2014-04-061-3/+2
|