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

Track used grace credits (Based on issue #2118) #7226

Merged
merged 12 commits into from
Oct 3, 2024

Conversation

hemmatio
Copy link
Member

@hemmatio hemmatio commented Sep 24, 2024

Proposed Changes

This pull request is based on issue #2118. Currently, there is no accessible way for students to view their grace credit usage, especially on a per-assignment basis. The issue outlined the creation of a new column on the student's home page, but the proposed solution is to add the used grace credits beside the assignment due date, if any.

Screenshots of your changes (if applicable) UPDATE 02/10/24: Grace credits are on a newline, and the number of credits used is bolded. image

Type of Change

(Write an X or a brief description next to the type or types that best describe your changes.)

Type Applies?
🚨 Breaking change (fix or feature that would cause existing functionality to change)
New feature (non-breaking change that adds functionality)
🐛 Bug fix (non-breaking change that fixes an issue)
🎨 User interface change (change to user interface; provide screenshots) X
♻️ Refactoring (internal change to codebase, without changing functionality)
🚦 Test update (change that only adds or modifies tests)
📦 Dependency update (change that updates a dependency)
🔧 Internal (change that only affects developers or continuous integration)

Checklist

(Complete each of the following items for your pull request. Indicate that you have completed an item by changing the [ ] into a [x] in the raw text, or by clicking on the checkbox in the rendered description on GitHub.)

Before opening your pull request:

  • I have performed a self-review of my changes.
    • Check that all changed files included in this pull request are intentional changes.
    • Check that all changes are relevant to the purpose of this pull request, as described above.
  • I have added tests for my changes, if applicable.
    • This is required for all bug fixes and new features.
  • I have updated the project documentation, if applicable.
    • This is required for new features.
  • If this is my first contribution, I have added myself to the list of contributors.

After opening your pull request:

  • I have updated the project Changelog (this is required for all changes).
  • I have verified that the pre-commit.ci checks have passed.
  • I have verified that the CI tests have passed.
  • I have reviewed the test coverage changes reported by Coveralls.
  • I have requested a review from a project maintainer.

Questions and Comments

(Include any questions or comments you have regarding your changes.)
24/09/24:

  • Still need to create test cases for this change before requesting a review. ✅
  • Additionally, unsure about the location of the changes. Seems quite unorganized to add the changes to app/views/assignments/_assignment_date.html.erb, however this was done as the div used in _assignment_date.html.erb seems to force any other text onto another line, rather than remaining inline.

25/09/24:

  • Do I need to update the project documentation? This change isn't really a feature... is it? ✅
  • Still unsure about location of HTML change. ✅

02/10/24:

  • Updated grace_credits_used_for method.
  • Moved string into a locale file.
  • Bolded grace credits used, also on a new line.
  • Updated test cases to mimic behaviour found in grace_period_submission_rule.rb, now works for groupings.

@hemmatio hemmatio marked this pull request as ready for review September 26, 2024 03:20
end

it 'updates remaining grace credits after deductions' do
create(:grace_period_deduction, membership: @membership, deduction: 2)
Copy link
Member Author

Choose a reason for hiding this comment

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

I don't like how I run create(:grace_period_deduction, membership: @membership, deduction: 2) two times. Putting this line in a before-do block causes the other tests in the context block to be affected, however.

Would it be more optimal to create a new context block for these two test cases?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, a context block here is good. Something like context 'where there is a deduction'

Copy link
Collaborator

@david-yz-liu david-yz-liu left a comment

Choose a reason for hiding this comment

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

@hemmatio good work. I left a few inline comments; in response to your questions:

  1. I'd actually like it if the "grace credits used" text were on a separate paragraph (<p>) underneath the due date. So yeah, not in the _assignment_date.html.erb partial.
  2. It's okay not to include a documentation change for this PR.

@@ -250,6 +250,14 @@ def released_result_for?(assessment)
end
end

def grace_credits_used_for(assessment)
grouping = accepted_groupings.find_by(assessment_id: assessment.id) # Find the grouping for this assessment
Copy link
Collaborator

Choose a reason for hiding this comment

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

The querying here is good, but you can make better use of existing methods, in particular accepted_grouping_for.

There may also be a Grouping instance method that you can use to get the number of grace credits used by the grouping. Note that in a grouping, all members have the same grace credit deductions.

@@ -18,4 +18,8 @@
(<%= distance_of_time_in_words_to_now(due_date) %>)
<% end %>
<% end %>
<% grace_credits_used = @current_role.grace_credits_used_for(assignment) %>
<% if grace_credits_used > 0 %>
<span> - Grace Credits Used: <%= grace_credits_used %></span>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Move the string into a locale file (look at how other user-facing strings are defined in this file)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, let's bold the number of grace credits used.

end

it 'updates remaining grace credits after deductions' do
create(:grace_period_deduction, membership: @membership, deduction: 2)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, a context block here is good. Something like context 'where there is a deduction'

@hemmatio hemmatio marked this pull request as draft October 2, 2024 02:01
expect(@student1.remaining_grace_credits).to eq(3)
end

# it 'deducts grace credits from each group member' do # How to make this testcase..?
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm attempting to create a grace credit deduction for a group assignment, and then check that each member in the group has received the deduction. I simulated this on my own, and it works as expected, but I want to be able to explicitly test for this with RSpec.
I'm unable to recreate this scenario within RSpec, as the grace credit deductions are applied to each membership, rather than a group. There may be another method to apply grace credit deductions on a group basis, but I have not found that method. I tried to investigate how the grace credit deductions are applied to a group, but I'm not able to trace it through fully.
I found that the SubmissionsJob method perform in app/jobs/submissions_job.rb runs when an instructor collects assignments and applies the grace deduction. I was hoping to find some sort of for-loop that applies the grace credit deduction equally to each member within a grouping so that I could mimic that behaviour within my test case.

Changelog.md Outdated
@@ -6,6 +6,11 @@

### ✨ New features and improvements

- Add visual indicator on a per-assignment basis for used grace credits (#7226)
- Improve textviewer rendering speed (#7211)
Copy link
Member Author

Choose a reason for hiding this comment

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

Lines 10 through 13 are from a merge

Copy link
Collaborator

Choose a reason for hiding this comment

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

This merge is incorrect. These lines were moved under v2.5.2, and should be removed from the unreleased section.

In general, there shouldn't be any "lines from a merge". If there is code that appears in a diff on GitHub that you didn't mean to include yourself, that means that there was an error in the merge process that should be resolved.

@hemmatio hemmatio marked this pull request as ready for review October 2, 2024 14:35
@coveralls
Copy link
Collaborator

coveralls commented Oct 2, 2024

Pull Request Test Coverage Report for Build 11156833777

Details

  • 21 of 21 (100.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.004%) to 91.596%

Totals Coverage Status
Change from base Build 11155066813: 0.004%
Covered Lines: 40513
Relevant Lines: 43558

💛 - Coveralls

@hemmatio hemmatio requested a review from david-yz-liu October 2, 2024 15:57
Changelog.md Outdated
@@ -6,6 +6,11 @@

### ✨ New features and improvements

- Add visual indicator on a per-assignment basis for used grace credits (#7226)
- Improve textviewer rendering speed (#7211)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This merge is incorrect. These lines were moved under v2.5.2, and should be removed from the unreleased section.

In general, there shouldn't be any "lines from a merge". If there is code that appears in a diff on GitHub that you didn't mean to include yourself, that means that there was an error in the merge process that should be resolved.

<tr>
<td>
<%= link_to assignment_text, route %>
</td>
<td>
<%= render partial: 'assignments/assignment_date',
locals: { assignment: assignment } %>
<% if grace_credits_used > 0 %>
<span><%= I18n.t('assignments.grace_credits_used', grace_credits_used: grace_credits_used).html_safe%></span>
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's a good instinct to use html_safe here, but there's a more idiomatic Rails way to achieve this. See https://guides.rubyonrails.org/i18n.html#using-safe-html-translations

Copy link
Member Author

Choose a reason for hiding this comment

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

This is the kind of insight and maturity that I hope to develop one day! I initially used I18n.t because I saw it being used within _assignment_date.html.erb. When the HTML tags were being escaped, I looked on StackOverflow for an I18n-specific solution! It never came to my mind that I might be overthinking things 😪

Copy link
Collaborator

Choose a reason for hiding this comment

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

@hemmatio oh honestly I'm not sure it was "insight" or "maturity", I just happened to know about this because of experience working with Rails, and I suppose reading through the guide. There's a lot of great info in these guides!

@david-yz-liu david-yz-liu merged commit 5849875 into MarkUsProject:master Oct 3, 2024
6 checks passed
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