Skip to content

Commit 4a2ad54

Browse files
committed
Rename the config key.
1 parent bd72bea commit 4a2ad54

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

README.md

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ Add to your `spec/spec_helpers.rb`:
2525
require 'jsonapi/rspec'
2626

2727
RSpec.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
3032
end
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

6454
Checking for an included resource:

lib/jsonapi/rspec.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
require 'json'
12
require 'rspec/matchers'
23
require 'jsonapi/rspec/id'
34
require 'jsonapi/rspec/type'
@@ -8,7 +9,7 @@
89
require 'jsonapi/rspec/jsonapi_object'
910

1011
RSpec.configure do |c|
11-
c.add_setting :allow_symbolized_jsonapi, default: false
12+
c.add_setting :jsonapi_indifferent_hash, default: false
1213
end
1314

1415
module 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

0 commit comments

Comments
 (0)