-
Notifications
You must be signed in to change notification settings - Fork 244
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
Track used grace credits (Based on issue #2118) #7226
Conversation
…sage to _assignment_date.html.erb view
… track-used-grace-credits
… track-used-grace-credits
spec/models/student_spec.rb
Outdated
end | ||
|
||
it 'updates remaining grace credits after deductions' do | ||
create(:grace_period_deduction, membership: @membership, deduction: 2) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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'
There was a problem hiding this 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:
- 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. - It's okay not to include a documentation change for this PR.
app/models/student.rb
Outdated
@@ -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 |
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
spec/models/student_spec.rb
Outdated
end | ||
|
||
it 'updates remaining grace credits after deductions' do | ||
create(:grace_period_deduction, membership: @membership, deduction: 2) |
There was a problem hiding this comment.
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'
… track-used-grace-credits
spec/models/student_spec.rb
Outdated
expect(@student1.remaining_grace_credits).to eq(3) | ||
end | ||
|
||
# it 'deducts grace credits from each group member' do # How to make this testcase..? |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
Pull Request Test Coverage Report for Build 11156833777Details
💛 - Coveralls |
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) |
There was a problem hiding this comment.
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.
app/views/assignments/_row.html.erb
Outdated
<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> |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 😪
There was a problem hiding this comment.
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!
…ace_credits_used locale tag to be more consistent in HTML safety
… track-used-grace-credits
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.Type of Change
(Write an
X
or a brief description next to the type or types that best describe your changes.)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:
After opening your pull request:
Questions and Comments
(Include any questions or comments you have regarding your changes.)
24/09/24:
25/09/24:
02/10/24: