Skip to content

fix: #students and #coaches return Chapter-specific students and coaches#2579

Open
jonodrew wants to merge 1 commit intomasterfrom
bugfix/fixup-methods-on-chapter
Open

fix: #students and #coaches return Chapter-specific students and coaches#2579
jonodrew wants to merge 1 commit intomasterfrom
bugfix/fixup-methods-on-chapter

Conversation

@jonodrew
Copy link
Copy Markdown
Contributor

@jonodrew jonodrew commented Apr 17, 2026

This fixes a bug where the methods returned all of the students and coaches that the user could access

#coaches query: "SELECT DISTINCT \"members\".* FROM \"members\" INNER JOIN \"subscriptions\" ON \"members\".\"id\" = \"subscriptions\".\"member_id\" INNER JOIN \"groups\" ON \"subscriptions\".\"group_id\" = \"groups\".\"id\" WHERE \"groups\".\"chapter_id\" = 1 AND \"groups\".\"name\" = 'Coaches'"

#students query: "SELECT DISTINCT \"members\".* FROM \"members\" INNER JOIN \"subscriptions\" ON \"members\".\"id\" = \"subscriptions\".\"member_id\" INNER JOIN \"groups\" ON \"subscriptions\".\"group_id\" = \"groups\".\"id\" WHERE \"groups\".\"chapter_id\" = 1 AND \"groups\".\"name\" = 'Students'"

@mikej
Copy link
Copy Markdown
Contributor

mikej commented Apr 17, 2026

I'll give this one a quick test locally, but feels like a nice approach 👍

@mroderick
Copy link
Copy Markdown
Collaborator

Could you add some tests to make sure this stays fixed?

@jonodrew jonodrew force-pushed the bugfix/fixup-methods-on-chapter branch from 78fb645 to aa9a6d8 Compare April 18, 2026 11:00
This fixes a bug where the methods returned _all_ of the students and coaches that the user could access

Signed-off-by: jonathan.kerr <3410350+jonodrew@users.noreply.github.com>
@jonodrew jonodrew force-pushed the bugfix/fixup-methods-on-chapter branch from aa9a6d8 to d5751b5 Compare April 18, 2026 11:24
@jonodrew
Copy link
Copy Markdown
Contributor Author

@mroderick done!

@jonodrew jonodrew requested a review from mroderick April 19, 2026 08:51
Copy link
Copy Markdown
Contributor

@mikej mikej left a comment

Choose a reason for hiding this comment

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

Hi! The actual change to chapter.rb looks good (had a check of the queries that get generated).

Added a comment about how to include the shared examples in the spec though.

expect(this_chapter.public_send(method_name))
.not_to include(that_member)
end
end
Copy link
Copy Markdown
Contributor

@mikej mikej Apr 20, 2026

Choose a reason for hiding this comment

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

Good idea to use some shared examples here, but currently these test cases won't actually get run when running chapter_spec.rb. After defining the shared_examples, you also need to add include_examples lines with the appropriate group_name and method_name for students and coaches.

e.g. inside the describe "helper methods... but after the RSpec.shared_examples you can put:

include_examples "group-scoped members", "Coaches", "coaches"
include_examples "group-scoped members", "Students", "students"

On doing this, the specs then fail with Validation failed: Group has already been taken so looks like the before results in trying to create the groups twice?

Are you OK to take a look at this as I agree having these tests in place is definitely worthwhile.

Lastly, if you want to check which test cases RSpec is running you can use the "documentation" format which lists the passing tests as well as any failures: bin/drspec -fd spec/models/chapter_spec.rb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants