Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pulling in pilots for maker homepage course selection #45156

Merged
merged 4 commits into from
Mar 7, 2022

Conversation

hannahbergam
Copy link
Contributor

@hannahbergam hannahbergam commented Mar 4, 2022

Current Behavior: The maker app populates the most recent script in the maker homepage by pulling in 'visible_units' from script.rb. Because pilot scripts are not "visible", these scripts are excluded.

This PR updates the maker controller to add to that initial pull of scripts a list of all pilots a student is enrolled in. These scripts are then sorted by most recent, and the most recent is displayed as the single course on the maker homepage.

Here is what my screen looked like before the changes (I'm enrolled in the pilot, but the last year of the course displays instead):
Screen Shot 2022-03-04 at 11 22 19 AM

And now that I have pulled in pilots, the 2022 pilot shows here:
Screen Shot 2022-03-04 at 11 06 14 AM

I tested this by adding myself to the pilot locally and ensuring that the pilot is pulled in accordingly.

Links

Testing story

I added two unit tests for this update: one where the student is enrolled in a pilot and that pilot displays on the homepage instead of the 2019 course, and one where the pilot exists (and the user_script exists too), but the student isn't enrolled in the pilot so the 2019 course displays instead.

Deployment strategy

Follow-up work

https://codedotorg.atlassian.net/browse/LP-2228

Privacy

Security

Caching

PR Checklist:

  • Tests provide adequate coverage
  • Privacy and Security impacts have been assessed
  • Code is well-commented
  • New features are translatable or updates will not break translations
  • Relevant documentation has been added or updated
  • User impact is well-understood and desirable
  • Pull Request is labeled appropriately
  • Follow-up work items (including potential tech debt) are tracked and linked

@hannahbergam hannahbergam requested a review from a team March 4, 2022 19:29
Copy link
Contributor

@jamescodeorg jamescodeorg left a comment

Choose a reason for hiding this comment

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

There are some interesting questions here around how we factor this new logic. Ping me if you'd like to pair!

Also, we should add some unit tests to cover these scenarios.

dashboard/app/models/script.rb Outdated Show resolved Hide resolved
@@maker_units ||= visible_units.select(&:is_maker_unit?)
def self.maker_units(user)
total_units = visible_units
total_units += all_scripts.select {|s| s.has_pilot_access?(user)}
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you know if this line will cause any db queries (once all_scripts is cached)? It seems a bit expensive to me to have to iterate through all scripts (but we probably do this elsewhere too).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for chatting with me about this- I've made a ticket for our backlog to fix this in all places: https://codedotorg.atlassian.net/browse/LP-2228

Copy link
Contributor

@jamescodeorg jamescodeorg left a comment

Choose a reason for hiding this comment

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

A few more comments. (And I take it you're still working on unit tests?)

dashboard/app/models/script.rb Outdated Show resolved Hide resolved
def self.maker_units
@@maker_units ||= visible_units.select(&:is_maker_unit?)
def self.maker_units(user)
return_units = @@maker_units ||= visible_units.select(&:is_maker_unit?)
Copy link
Contributor

Choose a reason for hiding this comment

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

(minor, up to you) Now that I see this, I'm wondering whether this would be clearer as two separate functions maker_units and maker_units_for_user or visible_maker_units and maker_units or something like that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see what you mean here. I think if this were used in more places, the clarity would help/make sense. That said, the function is only called from one place so I think it's fine to keep them combined.

@hannahbergam
Copy link
Contributor Author

A few more comments. (And I take it you're still working on unit tests?)

Yes! I just pushed two tests: one where a student is enrolled in a pilot and it displays, and another where a pilot experiment (and even a user_script) exists for a student but the student isn't enrolled in the pilot, so it doesn't display.

Copy link
Contributor

@jamescodeorg jamescodeorg left a comment

Choose a reason for hiding this comment

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

Looks good!

As advice for the future, I encourage you to write unit tests at the smallest meaningful scope (e.g. maker_units in this change). This makes it clearer what the test is testing and reduces maintenance costs by having the test only need to be changed when the logic for that specific scenario changes.

@hannahbergam
Copy link
Contributor Author

Looks good!

As advice for the future, I encourage you to write unit tests at the smallest meaningful scope (e.g. maker_units in this change). This makes it clearer what the test is testing and reduces maintenance costs by having the test only need to be changed when the logic for that specific scenario changes.

Thank you for this! This is a good reminder.

@hannahbergam hannahbergam merged commit 39914d3 into staging Mar 7, 2022
@hannahbergam hannahbergam deleted the hbergam/maker-pilots branch March 7, 2022 20:19
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.

None yet

2 participants