Skip to content

Commit 1abbf3a

Browse files
committed
Added unit tests for jsonapi_indifferent_hash.
1 parent b0a2582 commit 1abbf3a

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

spec/jsonapi/rspec_spec.rb

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
require 'securerandom'
2+
require 'spec_helper'
3+
4+
RSpec.describe JSONAPI::RSpec, '#as_indifferent_hash' do
5+
let(:doc) do
6+
{
7+
id: SecureRandom.uuid,
8+
list: [
9+
{ one: 1, 'one + one' => :two }
10+
],
11+
hash: { key: :value, 'another key' => 'another value' }
12+
}
13+
end
14+
15+
it do
16+
expect(JSONAPI::RSpec.as_indifferent_hash(doc)).not_to eq(
17+
JSON.parse(JSON.generate(doc))
18+
)
19+
end
20+
21+
context 'with jsonapi indifferent hash enabled' do
22+
before(:all) { ::RSpec.configuration.jsonapi_indifferent_hash = true }
23+
after(:all) { ::RSpec.configuration.jsonapi_indifferent_hash = false }
24+
25+
it do
26+
expect(JSONAPI::RSpec.as_indifferent_hash(doc)).to eq(
27+
JSON.parse(JSON.generate(doc))
28+
)
29+
end
30+
end
31+
end

0 commit comments

Comments
 (0)