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

Correctly copy all series info when copying courses #6049

Merged
merged 4 commits into from
Jan 8, 2025

Conversation

jorg-vr
Copy link
Contributor

@jorg-vr jorg-vr commented Jan 8, 2025

This pull request fixes multiple bugs related to copying courses.

Firstly a bug in the test for students not being able to copy hidden series. This test also didn't copy visible series as the student wasn't correctly added to the course in the test.

Secondly a bug caused the order of series which have not been manually reordered to be reversed in a copied course.

Thirdly I made sure that advanced series settings are also copied when a course is copied: #5743

  • Tests were added

Closes #5743

@jorg-vr jorg-vr added the bug Something isn't working label Jan 8, 2025
@jorg-vr jorg-vr self-assigned this Jan 8, 2025
@jorg-vr jorg-vr requested a review from bmesuere as a code owner January 8, 2025 13:08
Copy link
Contributor

coderabbitai bot commented Jan 8, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

The pull request modifies the course creation process to improve series copying functionality. The changes focus on preserving advanced series settings when creating a new course based on an existing one. Specifically, the modifications ensure that series are copied with their original advanced options intact, including progress tracking, activity visibility, and activity number settings. The implementation also ensures that series are ordered consistently during the copying process.

Changes

File Change Summary
app/controllers/courses_controller.rb - Modified create method to reorder series by ID when copying
- Added preservation of activities_visible and activity_numbers_enabled attributes when copying series
test/controllers/courses_controller_test.rb - Added test to verify advanced series settings are copied
- Added test to confirm series order is maintained
- Updated course copying test to use staff user

Assessment against linked issues

Objective Addressed Explanation
Copy advanced series options when creating a new course [#5743]
Preserve exercise number settings during course copy [#5743]

The changes directly address the requirements in issue #5743 by ensuring that advanced options like activity visibility and activity number settings are copied when creating a new course from an existing one.

Possibly related PRs

Suggested reviewers

  • bmesuere

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 36f3847 and 0758cef.

📒 Files selected for processing (1)
  • test/controllers/courses_controller_test.rb (1 hunks)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
test/controllers/courses_controller_test.rb (3)

751-760: Test setup could be more explicit about visibility expectations.

While the test correctly verifies that staff users can't copy hidden/closed series, consider adding assertions to explicitly verify which series should and shouldn't be copied, rather than just checking the total count.

-    assert_equal 0, Course.find(response.parsed_body['id']).series.count
+    new_course = Course.find(response.parsed_body['id'])
+    assert_equal 0, new_course.series.count, "Staff user shouldn't be able to copy any series"
+    assert_equal 5, course.series.count, "Original course should still have all series"

769-789: Consider using test data helpers for better readability.

While the test correctly verifies advanced settings, consider extracting the test data setup to helper methods or using a data-driven approach for better maintainability.

+    def create_series_with_settings(course, settings)
+      create(:series, course: course, **settings)
+    end
+
     test 'a copied course should contain all series with the same advanced settings' do
       user = create :user, permission: :staff
       course = create :course
       course.administrating_members << user
-      create :series, course: course, progress_enabled: false, activities_visible: false, activity_numbers_enabled: true, name: 'foo'
-      create :series, course: course, progress_enabled: true, activities_visible: true, activity_numbers_enabled: false, name: 'bar'
+      test_cases = [
+        { name: 'foo', progress_enabled: false, activities_visible: false, activity_numbers_enabled: true },
+        { name: 'bar', progress_enabled: true, activities_visible: true, activity_numbers_enabled: false }
+      ]
+      test_cases.each { |settings| create_series_with_settings(course, settings) }

791-811: Improve test clarity by explicitly documenting the expected order.

While the test correctly verifies series order, consider adding comments or using more explicit test data to clarify the expected ordering.

     test 'a copied course should maintain the same series order' do
       user = create :user, permission: :staff
       course = create :course
       course.administrating_members << user
+      # Expected order after sorting:
+      # 1. first (order: nil, sorted by name)
+      # 2. second (order: nil, sorted by name)
+      # 3. third (order: 1)
+      # 4. fourth (order: 2)
+      # 5. fifth (order: 3)
       create :series, course: course, name: 'second'
       create :series, course: course, name: 'first'
       create :series, course: course, name: 'third', order: 1
       create :series, course: course, name: 'fifth', order: 3
       create :series, course: course, name: 'fourth', order: 2
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a416660 and 36f3847.

📒 Files selected for processing (2)
  • app/controllers/courses_controller.rb (2 hunks)
  • test/controllers/courses_controller_test.rb (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Test System
  • GitHub Check: Test Ruby
🔇 Additional comments (2)
app/controllers/courses_controller.rb (2)

158-158: Ensure deterministic series order during copying.

The addition of .reorder(id: :asc) ensures consistent ordering of series when copying courses, preventing the order from being reversed or randomized.


172-174: Preserve advanced series settings during copying.

The addition of activities_visible and activity_numbers_enabled ensures that all advanced series settings are properly copied to the new course.

test/controllers/courses_controller_test.rb Outdated Show resolved Hide resolved
@jorg-vr jorg-vr marked this pull request as draft January 8, 2025 14:50
@jorg-vr jorg-vr marked this pull request as ready for review January 8, 2025 15:06
@jorg-vr jorg-vr merged commit dc8a7ef into main Jan 8, 2025
12 of 14 checks passed
@jorg-vr jorg-vr deleted the fix/copy-advanced-series-settings branch January 8, 2025 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Copy advanced options from a series when make a new course
2 participants