File tree Expand file tree Collapse file tree 2 files changed +10
-16
lines changed
Expand file tree Collapse file tree 2 files changed +10
-16
lines changed Original file line number Diff line number Diff line change @@ -25,10 +25,11 @@ Add to your `spec/spec_helpers.rb`:
2525require ' jsonapi/rspec'
2626
2727RSpec .configure do |config |
28- # ...
2928 config.include JSONAPI ::RSpec
29+
30+ # Support for documents with mixed string/symbol keys. Disabled by default.
31+ config.jsonapi_indifferent_hash = true
3032end
31- ```
3233
3334# # Usage and documentation
3435
@@ -48,17 +49,6 @@ Available matchers:
4849* ` expect(document).to have_jsonapi_object`
4950* ` expect(document).to have_jsonapi_object('version' => '1.0')`
5051
51- ### Indifferent Matching
52- ``` ruby
53- # spec/spec_helpers.rb
54-
55- RSpec .configure do |config |
56- # ...
57- config.allow_symbolized_jsonapi = true
58- end
59- ```
60- The configuration above allows the RSpec matchers to work with a symbolized jsonapi source document.
61-
6252# # Advanced examples
6353
6454Checking for an included resource:
Original file line number Diff line number Diff line change 1+ require 'json'
12require 'rspec/matchers'
23require 'jsonapi/rspec/id'
34require 'jsonapi/rspec/type'
89require 'jsonapi/rspec/jsonapi_object'
910
1011RSpec . configure do |c |
11- c . add_setting :allow_symbolized_jsonapi , default : false
12+ c . add_setting :jsonapi_indifferent_hash , default : false
1213end
1314
1415module JSONAPI
@@ -22,8 +23,11 @@ module RSpec
2223 include JsonapiObject
2324
2425 def self . as_indifferent_hash ( doc )
25- return doc unless ::RSpec . configuration . allow_symbolized_jsonapi
26- return doc . with_indifferent_access if doc . respond_to? ( :with_indifferent_access )
26+ return doc unless ::RSpec . configuration . jsonapi_indifferent_hash
27+
28+ if doc . respond_to? ( :with_indifferent_access )
29+ return doc . with_indifferent_access
30+ end
2731
2832 JSON . parse ( JSON . generate ( doc ) )
2933 end
You can’t perform that action at this time.
0 commit comments