Skip to content

Commit fc3796c

Browse files
committed
test(api): cover Alchemy::Node guest and member ability rules
The nodes#index authorization fix is exercised through accessible_by, which builds its query from the ability's SQL scope and never runs the per-instance can? block. That left the guest and member Node rule blocks in Permissions uncovered. Add ability specs that check can? directly for both roles, asserting guests are denied nodes linking to restricted or unpublished pages while members may still see restricted ones.
1 parent 02c46b7 commit fc3796c

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

spec/libraries/permissions_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
let(:published_element) { mock_model(Alchemy::Element, restricted?: false, public?: true) }
1818
let(:restricted_element) { mock_model(Alchemy::Element, restricted?: true, public?: true) }
1919
let(:language) { build(:alchemy_language) }
20+
let(:public_node) { build(:alchemy_node, name: nil, page: public_page) }
21+
let(:external_node) { build(:alchemy_node, :with_url) }
22+
let(:restricted_node) { build(:alchemy_node, name: nil, page: restricted_page) }
23+
let(:unpublished_node) { build(:alchemy_node, name: nil, page: unpublic_page) }
2024

2125
context "A guest user" do
2226
let(:user) { nil }
@@ -44,6 +48,13 @@
4448
is_expected.to be_able_to(:index, published_element)
4549
is_expected.not_to be_able_to(:index, restricted_element)
4650
end
51+
52+
it "can only see nodes linking to public not restricted pages or external urls" do
53+
is_expected.to be_able_to(:read, public_node)
54+
is_expected.to be_able_to(:read, external_node)
55+
is_expected.not_to be_able_to(:read, restricted_node)
56+
is_expected.not_to be_able_to(:read, unpublished_node)
57+
end
4758
end
4859

4960
context "A member" do
@@ -72,6 +83,13 @@
7283
is_expected.to be_able_to(:index, published_element)
7384
is_expected.to be_able_to(:index, restricted_element)
7485
end
86+
87+
it "can also see nodes linking to restricted pages" do
88+
is_expected.to be_able_to(:read, public_node)
89+
is_expected.to be_able_to(:read, external_node)
90+
is_expected.to be_able_to(:read, restricted_node)
91+
is_expected.not_to be_able_to(:read, unpublished_node)
92+
end
7593
end
7694

7795
context "An author" do

0 commit comments

Comments
 (0)