Skip to content

Commit bda2869

Browse files
committed
Add missing spec coverage for related resources operations
I discovered that these simple scenarios weren't tested properly when working on JR 0.10 support
1 parent 761545b commit bda2869

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

spec/requests/related_resources_operations_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
let(:article) { Article.all.sample }
88
let(:authorizations) { {} }
99
let(:policy_scope) { Article.none }
10+
let(:user_policy_scope) { User.all }
11+
12+
before do
13+
allow_any_instance_of(UserPolicy::Scope).to receive(:resolve).and_return(user_policy_scope)
14+
end
1015

1116
let(:json_data) { JSON.parse(last_response.body)["data"] }
1217

@@ -66,6 +71,7 @@
6671

6772
context 'authorized for show_related_resource' do
6873
before { allow_operation('show_related_resource', source_record: article, related_record: article.author) }
74+
it { is_expected.to be_ok }
6975

7076
# If this happens in real life, it's mostly a bug. We want to document the
7177
# behaviour in that case anyway, as it might be surprising.
@@ -74,5 +80,13 @@
7480
it { is_expected.to be_not_found }
7581
end
7682
end
83+
84+
context 'authorized for show_related_resource while related resource is limited by policy scope' do
85+
before { allow_operation('show_related_resource', source_record: article, related_record: nil) }
86+
87+
let(:user_policy_scope) { User.where.not(id: article.author.id) }
88+
89+
it { is_expected.to be_ok }
90+
end
7791
end
7892
end

0 commit comments

Comments
 (0)