summaryrefslogtreecommitdiff
path: root/spec
Commit message (Collapse)AuthorAgeFilesLines
...
| * Add an integration spec for ElasticsearchMichael Herold2018-02-062-0/+46
| | | | | | | | | | | | | | | | | | | | | | | | The Elasticsearch gems heavily integrate with Hashie. This leads people to want to use a Mash as the backer for an Elasticsearch model, but the behavior is different than they expect. By having this integration spec, we're covering two things: 1. It might help ensure that we don't break the Elasticsearch ecosystem with changes in Hashie as has happened in the past. 2. It communicates some gotchas that happen with using a Mash as the backer for an Elasticsearch model.
* | Allow codependent Dash attributes to initializeMichael Herold2018-02-061-0/+25
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | Definition: Codependent properties A set of two or more properties who have "required" validations that are based on each other. Example: ```ruby class OneOrMore < Hashie::Dash property :a, required: -> { b.nil? } property :b, required: -> { a.nil? } end ``` When constructing a Dash via the merge initializer, codependent properties have their "required" validation run too early when their values are set to `nil`, which causes an `ArgumentError` to be raised in the case that the first property is set to `nil`. This is an order-dependence bug that is fixed by this commit. By pruning off `nil` values only during initialization via the merge initializer, we can prevent this problem from occurring for the case of `nil` values. However, this is an indication of a larger problem with the architecture of Dash. We should be setting all the properties before running the validations. Rearchitecting this will be quite an undertaking.
* Ensure IndifferentAccess is injected after mergeMichael Herold2018-02-051-0/+13
| | | | | | | | During non-destructive merges (i.e. `#merge`), the `IndifferentAccess` mixin was failing to inject itself into the resulting Hash. This caused a `NoMethodError` to be thrown when attempting to perform the action. Now, we properly inject the mixin when necessary so the `#merge` method works.
* 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 ```
* Fix Hashie::Rash randomly losing keys (#430)Andrii Dmytrenko2017-12-191-0/+6
|
* Fix "@disable_warnings" spec warning (#416)Alexandre Filipe Campos2017-03-011-0/+1
| | | | | | | | When running rspec specs on the ruby-grape project with warnings enabled this warning is printed hundreds of times. This change fixes the warning. Also, turn on warnings when running rspec to see when this happens.
* 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
* Add performance benchmarks for MashMichael Herold2017-02-242-0/+31
|
* Add an extension to maintain original Mash keys (#326)Michael Herold2017-02-222-0/+72
| | | | | | | | | | | | | | | | | | | | | | | | | | | One of the behaviors of Mash that we see regularly surprise users is that Mash stringifies any keys passed into it. This leads to unexpected lack of synergy between Mash and its cousins (particularly Dash), since the property DSLs do not handle indifferent key access. This extension ensures that the original keys are kept inside the Mash's data structure, at the expense of more costly logic for fetching information indifferently. I have included a benchmark that compares the two. The benchmark shows that when you are passing string keys into a Mash, using this extension will actually be _faster_ than the default implementation, but that the reverse is true when passing symbol keys. In #296, I tried to do this universally for all Mashes, which slowed down the fetching behavior for Mash significantly. I like this attempt much better because it allows users to opt into the new behavior if they want it, while still keeping the default implementation as-is. Fixes #196 by giving the option of keeping the original structure of the Mash when using it with Dash. Fixes #246 by giving the option of opting into keeping the original keys. Closes #296 by giving a more flexible path forward that doesn't change the semantics of the main Mash class.
* Squelch an RSpec warning on an integration testMichael Herold2017-02-221-1/+1
|
* Add Hashie::Extensions::Mash::SymbolizeKeysMichael Herold2017-02-201-0/+39
| | | | | | | | | | | | | | | | We often have requests to make Mash symbolize keys by default. Since Hashie is used across so many different version of Ruby, we have been hesitant to make this behavior the default. However, there are valid use cases for wanting symbol keys. To satisfy both the needs of those on older Rubies and the needs of those who want symbol keys, this extension gives the end-user the ability to toggle on symbolized keys in their Mash subclasses. By adding this ability, we can wait to implement the symbol keys as a default for a while longer. See #341, #342 for more information. This is a half-measure toward the implementation of #342 (which makes Mash symbolize keys by default).
* Ensure Railties available when loading RailtieCallum Dryden2017-02-163-0/+22
| | | | | | | | In some circumstances when a project has the Rails constant defined we may still not be able to require the rails/railtie dependency. Before this change this would raise an exception. This change seeks to add better detection of the railtie dependency and add logging that this dependency is missing but still allow execution to continue.
* Clean up integration specs to test for STDOUT logMichael Herold2017-02-109-140/+164
| | | | | | | | This standardizes the way we're loading the example applications for the integration tests so we're actually testing the behavior of the application in each case. They're also structured in such a way to test that the Hashie logger doesn't accidentally write to the STDOUT during the initialization process of the applications.
* Carry over disabling warnings to subclassesMichael Herold2017-02-101-0/+11
|
* Fix #401: use a Railtie to set Hashie.logger on rails boot.Matthew Rudy Jacobs2017-02-102-4/+7
|
* Added integration spec for omniauth-oauth2.dblock2017-02-105-1/+122
|
* In Rails, set `Hashie.logger` to `Rails.logger`Michael Herold2017-02-103-0/+74
|
* Fix passing Pathname object to Hashie::Mesh.load()Albert Song2017-02-081-0/+14
| | | | With a test that would fail without this patch.
* Merge pull request #395 from michaelherold/toggle-mash-warningDaniel Doubrovkine (dB.) @dblockdotorg2017-02-042-5/+20
|\ | | | | Allow Mash subclasses to disable warnings
| * Allow Mash subclasses to disable warningsMichael Herold2017-02-042-5/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 ```
* | Merge pull request #397 from michaelherold/improve-integration-testsDaniel Doubrovkine (dB.) @dblockdotorg2017-02-042-1/+37
|\ \ | |/ |/| Bring integration tests into main test harness
| * Bring integration tests into main test harnessMichael Herold2017-02-032-1/+37
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We have a nice integration spec harness, so let's make sure we use it when we're working on the gem. I'm making the following changes: * Make `bundle exec rake` run integration specs, except on Travis. * Silence a warning in the OmniAuth integration spec that has nothing to do with Hashie. * Make Guard run integration specs when appropriate. Now, when you run all tasks you will run integration specs. Also, if you modify an integration spec, it will run. Lastly, if you modify anything in `lib` the integration specs will run. * Keeps the extra Travis build that only runs integration specs. Travis didn't like the Rake task that included it and there's extra signal by doing it this way anyway.
* | Fix specs using shared context 'with a logger'Bill Ruddock2017-02-033-11/+14
|/ | | | Correct usage of a shared_context is to use include_context
* Added omniauth integration spec for #391.dblock2017-01-313-0/+47
|
* Support Ruby 2.4.0 (#389)Masahiro Saito2017-01-061-2/+8
|
* Fix #385 - deep merge by reference bug (#386)Joe Marty2016-12-131-2/+7
|
* Update to CodeClimate 1.0.xPaul Bowsher2016-12-041-2/+2
| | | | | | | | CodeClimate > 1.0 uses SimpleCov and requires the test reporter to be called explicitly: https://github.com/codeclimate/ruby-test-reporter/blob/master/CHANGELOG. md#v100-2016-11-03
* Add a logging layer to address common issues (#381)Michael Herold2016-11-024-0/+68
|
* Evaluate procs default values in object initializationsazor2016-10-312-3/+2
|
* failing test for Dash default with proc not working with AS as_jsonJoe Van Dyk2016-10-282-0/+15
|
* Deep find all goes inside all nested hashessazor2016-10-191-0/+25
|
* Check ruby version without rubygemssazor2016-10-181-1/+2
|
* Fix dig bug for Arraysazor2016-10-171-0/+12
|
* Use existing translations when using IndifferentAccess andMatt White2016-09-161-0/+37
| | | | IgnoreUndeclared
* Hashie::Mash.load accepts a Pathname object. Closes #331.Atsushi Ishida2016-07-151-13/+30
| | | | https://github.com/intridea/hashie/issues/331
* Fix support for Array#digjonathan schatz2016-06-014-2/+33
|
* Merge pull request #350 from marshall-lee/fix_ignore_undeclaredDaniel Doubrovkine (dB.) @dblockdotorg2016-02-081-1/+2
|\ | | | | Stringified translations wasn't working in IgnoreUndeclared.
| * Stringified translations wasn't working in IgnoreUndeclared.Vladimir Kochnev2016-02-081-1/+2
| | | | | | | | | | | | Translation from `:symbol` and translation from `'string'` are different translations. No need in coercion to symbol or some other coercions.
* | Convert Mash keys for #digTakashi Kokubun2016-02-081-0/+11
|/
* Fix `#merge` breaking indifferent accessMichael Herold2016-01-311-0/+26
| | | | | | | | | `HashWithDifferentAccess` wasn't properly setting the indifferent access when merging in other hashes. This reruns `#convert!` after calling the superclass implementation of the method, so it preserves indifferent access on the resulting object. Fixes #345
* Make reverse_merge compatible with subclassing.Vladimir Kochnev2015-11-151-0/+9
|
* Clash: multiple bang notation callsBartosz Kopiński2015-10-271-2/+24
| | | | | | | | Added inheritance Added multiple bang notation merging Minor performace improvements - ends_with? is faster than regexp
* Make DeepLocate indifference-aware by defaultbugfix-deep-findMichael Herold2015-10-252-0/+81
| | | | | | | | | | | | | | `Hashie::Extensions::DeepLocate.deep_locate`, when passed a key, did not take into account indifferent access. This lead to a regression in v3.4.1 when `Hashie::Extensions::DeepFind` was modified to be backed by `DeepLocate`. This change makes the default comparator aware of indifferent access by inspecting the object that it is called on. It works with both `ActiveSupport::HashWithIndifferentAccess` and `Hashie::Extensions::IndifferentAccess`. Fixes #309
* Fix: broken cop, for now disabling hash syntax check.dblock2015-10-251-6/+6
|
* Upgraded to RuboCop 0.34.2.dblock2015-10-253-13/+13
|
* Ensure that MethodQuery methods return booleans.Michael Herold2015-10-252-3/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | | The documentation about the MethodQuery module spells out the expected behavior. While the spec suite appeared to be testing the same, the RSpec matchers were not actually checking the behavior properly. This lead to a divergence between the expected behavior, as outlined in the module documentation, and the actual behavior, as tested in the spec suite. This is the reason that #299 is happening: the expected behavior is not the actual behavior. I have included a test for #299 to show that it works as expected in this branch. This change makes the spec suite match the behavior in the module documentation, then modifies the methods to match the documentated specification. Lastly, I took the time to clean up the MethodQuery module for two reasons: 1. The old implementation used Regexps on the stringified method names, which is unnecessary since we have the wonderful `String#end_with?` method to check the suffix of a strings. 2. The old logic was difficult to reason through, so I clarified the intent of the methods by reducing the complexity of the conditionals and extracting meaningful methods where possible.
* - Removed `Hashie::Extensions::MergeInitializer` from `StrictKeyAccess` ↵Peter Boling2015-10-241-19/+30
| | | | | | | Extension - Updated, and enhanced specs - Improved documentation
* SRP: The StrictKeyAccess extension will raise an error whenever a key is ↵Peter Boling2015-10-231-0/+99
| | | | | | | | | | | | | | | | | | | | | | accessed that does not exist in the hash. In Python a "Hash" is called a "Dictionary", and ... > "It is an error to extract a value using a non-existent key." See: https://docs.python.org/2/tutorial/datastructures.html#dictionaries EXAMPLE: class StrictHash < Hash include Hashie::Extensions::StrictKeyAccess end >> hash = StrictHash[foo: "bar"] => {:foo=>"bar"} >> hash[:foo] => "bar" >> hash[:cow] KeyError: key not found: :cow
* @dblockPeter Boling2015-10-223-60/+1
| | | | | - 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-182-9/+56
| | | | - Better paradigm for pending specs due to bugs in interpreter