Skip to content

Add tests for #new and #create in CriteriaController when marks are r… #7521

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

Merged

Conversation

freyazjiner
Copy link
Member

@freyazjiner freyazjiner commented May 11, 2025

Changes

(Describe your changes here. Also describe the motivation for your changes: what problem do they solve, or how do they improve the application or codebase? If this pull request fixes an open issue, use a keyword to link this pull request to the issue.)

Adds tests for the “marks released” edge-case to both #new and #create. The approach is first create an assignment with released results, makes the corresponding request (get_as or post_as), and verifies that the controller returns a flash message with an error and an appropriate response code.

Screenshots of your changes (if applicable)
Associated documentation repository pull request (if applicable)

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)
♻️ Refactoring (internal change to codebase, without changing functionality)
🚦 Test update (change that only adds or modifies tests) X
📦 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.)
I split each controller action into two scenarios:

  1. Marks not released – existing examples remain here.
  2. Marks released – new examples that test the error-path.
    Github tests all pass for now.

@coveralls
Copy link
Collaborator

coveralls commented May 11, 2025

Pull Request Test Coverage Report for Build 15124982480

Details

  • 33 of 33 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.02%) to 91.933%

Totals Coverage Status
Change from base Build 14870512584: 0.02%
Covered Lines: 41867
Relevant Lines: 44856

💛 - Coveralls

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.

@freyazjiner a good start. Here are a few general comments:

  1. You deleted the pull request template that pre-populated the description field when making the pull request, which you should not do. You can find the pull request template under the .github folder; please use it to update your pull request description, and make sure to read through it and use the checklist to guide other things you need to do when making a pull request.
  2. The tests should be added to the existing tests for #new and #create, rather than being created in a separate block. You can update just the context that involves "An authenticated and authorized instructor doing a GET". You'll need to figure out a good way to combine the setup required for these cases with the existing test cases.

@freyazjiner freyazjiner requested a review from david-yz-liu May 13, 2025 19:56
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.

@freyazjiner Good work! I just left a few minor comments.

Changelog.md Outdated
@@ -12,6 +12,7 @@

- Remove `activerecord-session_store` gem (#7517)
- Upgrade to Rails 8 (#7504)
- Tests added for #new and #create actions for CriteriaController (#7521)
Copy link
Collaborator

Choose a reason for hiding this comment

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

For consistency with other entries, phrase this as "Add tests for..." (i.e., starting with a verb in the imperative tense).

Also use backticks to surround all code names (#new, #create, CriteriaController).

params: { course_id: course.id, assignment_id: assignment.id },
format: :js
end
context 'assignment marks are not released' do
Copy link
Collaborator

Choose a reason for hiding this comment

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

For context blocks, the description should generally start with the word "when"

expect(flash[:error]).to have_message(I18n.t('criteria.errors.released_marks'))
end

it 'responds with appropriate status' do
Copy link
Collaborator

Choose a reason for hiding this comment

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

Be more specific: responds with :bad_request status. Same comment below.

@@ -1,7 +1,7 @@
## Proposed Changes
*(Describe your changes here. Also describe the motivation for your changes: what problem do they solve, or how do they improve the application or codebase? If this pull request fixes an open issue, [use a keyword to link this pull request to the issue](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword).)*

...
Adds tests for the “marks released” edge-case to both `#new` (GET) and `#create` (POST). Each spec builds an assignment with released results, makes the corresponding request (`get_as` or `post_as`), and verifies that the controller flashes the correct error and returns `400 Bad Request`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you accidentally committed changes to this file (you shouldn't change the template file itself, just make sure to fill it out on GitHub).

Changelog.md Outdated
@@ -6,12 +6,14 @@

### ✨ New features and improvements


Copy link
Collaborator

Choose a reason for hiding this comment

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

Revert this change

Copy link
Member Author

Choose a reason for hiding this comment

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

sorry about that, done

Copy link
Collaborator

Choose a reason for hiding this comment

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

This line is still here (you may have reverted this change by accident). To be clear, I'm referring to the blank line that has been added; there should be just one blank line after the "New features and improvements" heading.

@freyazjiner freyazjiner requested a review from david-yz-liu May 17, 2025 20:35
Changelog.md Outdated
@@ -6,12 +6,14 @@

### ✨ New features and improvements


Copy link
Collaborator

Choose a reason for hiding this comment

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

This line is still here (you may have reverted this change by accident). To be clear, I'm referring to the blank line that has been added; there should be just one blank line after the "New features and improvements" heading.

@@ -91,7 +92,7 @@ Horatiu Halmaghi
Huiyu Sun
Ian Smith
Ibrahim Shahin
Ido Ben Haim
Igit revert HEADdo Ben Haim
Copy link
Collaborator

Choose a reason for hiding this comment

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

This line contains an error. Please make sure to check your work carefully when making commits, using git diff (and the GitHub pull request interface).

@david-yz-liu david-yz-liu merged commit b80800e into MarkUsProject:master May 20, 2025
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