Skip to content

Commit 1fd1c91

Browse files
committed
Enable Symbol keyed hash parameters for relationships matcher
Add support for symbol keyed hashes to the have_relationship matcher and create related spec tests.
1 parent 9fdac57 commit 1fd1c91

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/jsonapi/rspec/relationships.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module Relationships
55
match do |actual|
66
return false unless (actual['relationships'] || {}).key?(rel.to_s)
77

8-
!@data_set || actual['relationships'][rel.to_s]['data'] == @data_val
8+
!@data_set || actual['relationships'][rel.to_s]['data'] == JSON.parse(JSON.generate(@data_val))
99
end
1010

1111
chain :with_data do |val|

spec/jsonapi/relationships_spec.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,39 @@
2323

2424
describe '#have_jsonapi_attributes' do
2525
it { expect(doc).to have_relationship(:posts) }
26+
it { expect(doc).to have_relationship('posts') }
2627
it { expect(doc).not_to have_relationship(:mails) }
28+
it { expect(doc).not_to have_relationship('mails') }
2729
it { expect(doc).to have_relationship(:posts).with_data({ 'id' => '1', 'type' => 'posts' }) }
30+
it { expect(doc).to have_relationship('posts').with_data({ 'id' => '1', 'type' => 'posts' }) }
31+
it { expect(doc).to have_relationship(:posts).with_data({ id: '1', type: 'posts' }) }
32+
it { expect(doc).to have_relationship('posts').with_data({ id: '1', type: 'posts' }) }
2833
it do
2934
expect(doc).to have_relationship(:comments).with_data(
3035
[{ 'id' => '1', 'type' => 'posts' }, { 'id' => '2', 'type' => 'hides' }]
3136
)
3237
end
38+
it do
39+
expect(doc).to have_relationship('comments').with_data(
40+
[{ 'id' => '1', 'type' => 'posts' }, { 'id' => '2', 'type' => 'hides' }]
41+
)
42+
end
43+
it do
44+
expect(doc).to have_relationship(:comments).with_data(
45+
[{ id: '1', type: 'posts' }, { id: '2', type: 'hides' }]
46+
)
47+
end
48+
it do
49+
expect(doc).to have_relationship('comments').with_data(
50+
[{ id: '1', type: 'posts' }, { id: '2', type: 'hides' }]
51+
)
52+
end
3353
end
3454

3555
describe '#have_relationships' do
3656
it { expect(doc).to have_relationships(:posts, :comments) }
3757
it { expect(doc).to have_relationships('posts', 'comments') }
3858
it { expect(doc).not_to have_relationships(:posts, :comments, :mails) }
59+
it { expect(doc).not_to have_relationships('posts', 'comments', 'mails') }
3960
end
4061
end

0 commit comments

Comments
 (0)