Skip to content

Add tests for our policies - #989

Open
chvp wants to merge 1 commit into
chore/make-dependencies-job-more-lightweightfrom
chore/policy-tests
Open

Add tests for our policies#989
chvp wants to merge 1 commit into
chore/make-dependencies-job-more-lightweightfrom
chore/policy-tests

Conversation

@chvp

@chvp chvp commented Aug 21, 2026

Copy link
Copy Markdown
Member

The only changes to our actual app code is some hardening in the permitted attributes. This shouldn't result in any behaviour changes.

  • I've added tests relevant to my changes.

@chvp chvp self-assigned this Aug 21, 2026
@chvp chvp added the chore Repository or build maintenance label Aug 21, 2026
@chvp
chvp force-pushed the chore/policy-tests branch from dc18516 to cc894bc Compare August 21, 2026 14:37
@chvp
chvp marked this pull request as ready for review August 21, 2026 14:38
@chvp
chvp requested a review from robbevp as a code owner August 21, 2026 14:38

@robbevp robbevp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All for hardening and testing the policies! I'll keep this open, until we resolve the PR earlier in the stack.

A few open suggestions:

  • There's a gem (that I wrote) that provides some custom assertions for policies, so we can just write assert_permitted .... Though I also understand not wanting to add a gem for rather trivial things like this
  • I would avoid the confusion of anonymous user and use something like guest (since an anonymous user is in fact the absence of a user)
  • I have the habit of checking all user types for each action/scope/method, just for clarity. So often do something like:
    test 'should allow index for users and moderators' do
      assert_predicate Pundit.policy!(@user, Album), :index?
      assert_predicate Pundit.policy!(@moderator, Album), :index?
      assert_not_predicate Pundit.policy!(nil, Album), :index?

@chvp
chvp force-pushed the fix/resource-level-policy-check branch 2 times, most recently from 9ddea37 to 0ca9e46 Compare August 22, 2026 09:32
@chvp
chvp marked this pull request as draft August 22, 2026 09:39
@chvp
chvp force-pushed the chore/policy-tests branch 3 times, most recently from fb27792 to 5ac792a Compare August 22, 2026 10:15
@chvp

chvp commented Aug 22, 2026

Copy link
Copy Markdown
Member Author

@robbevp I updated the AlbumPolicyTest as you suggested (although I kept the test for permitted attributes separate per user class, since they felt quite disparate). Can you check that one to see if it matches what you would expect before I do the rest?

@chvp
chvp force-pushed the chore/policy-tests branch from 5ac792a to 79ad1f6 Compare August 22, 2026 10:19
@chvp
chvp force-pushed the fix/resource-level-policy-check branch from 0ca9e46 to ac16eef Compare August 22, 2026 10:24
@chvp
chvp force-pushed the chore/policy-tests branch from 79ad1f6 to 577037b Compare August 22, 2026 10:31
Base automatically changed from fix/resource-level-policy-check to main August 22, 2026 10:37
@chvp
chvp force-pushed the chore/policy-tests branch from 577037b to def507c Compare August 22, 2026 10:41
@robbevp

robbevp commented Aug 22, 2026

Copy link
Copy Markdown
Member

@robbevp I updated the AlbumPolicyTest as you suggested (although I kept the test for permitted attributes separate per user class, since they felt quite disparate). Can you check that one to see if it matches what you would expect before I do the rest?

Yes, I think is going in the right direction. I don't have a strong opinion about which assertions to group together, but I can now better orientate myself in the test file than before

@chvp
chvp force-pushed the chore/policy-tests branch 4 times, most recently from d813a25 to 80bcb10 Compare August 22, 2026 12:32
@chvp
chvp requested a review from robbevp August 22, 2026 12:33
@chvp
chvp marked this pull request as ready for review August 22, 2026 12:33

@robbevp robbevp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I'd just split off the changes in the workflows and flake to keep the PR focused on one thing

Comment thread .github/workflows/cachix.yml
@chvp
chvp force-pushed the chore/policy-tests branch from 80bcb10 to a950ed8 Compare August 23, 2026 14:19
@chvp
chvp changed the base branch from main to chore/make-dependencies-job-more-lightweight August 23, 2026 14:19
@chvp
chvp requested a review from robbevp August 23, 2026 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore Repository or build maintenance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants