Skip to content

Commit 9eb0951

Browse files
authored
Spec that GET for a has-one related resource doesn't use policy scopes (#146)
This can be a surprising behavior in jsonapi-authorization version that supports JR 0.9. It will likely change when JR 0.10 is supported at some point, if that time comes.
1 parent 816cd38 commit 9eb0951

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

spec/requests/related_resources_operations_spec.rb

Lines changed: 16 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

@@ -75,5 +80,16 @@
7580
it { is_expected.to be_not_found }
7681
end
7782
end
83+
84+
context 'authorized for show_related_resource while related resource is limited by policy scope' do
85+
# It might be surprising that with jsonapi-authorization that supports JR 0.9, the `related_record`
86+
# is indeed a real record here and not `nil`. If the policy scope was used, then the `related_record`
87+
# should be `nil` but alas, that is not the case.
88+
before { allow_operation('show_related_resource', source_record: article, related_record: article.author) }
89+
90+
let(:user_policy_scope) { User.where.not(id: article.author.id) }
91+
92+
it { is_expected.to be_ok }
93+
end
7894
end
7995
end

0 commit comments

Comments
 (0)