canvas-lms/spec/models/post_policy_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

115 lines
3.7 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
#
# Copyright (C) 2018 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
require_relative "../spec_helper"
describe PostPolicy do
describe "relationships" do
it { is_expected.to belong_to(:course).required.inverse_of(:post_policies) }
it { is_expected.to validate_presence_of(:course) }
it { is_expected.to belong_to(:assignment).inverse_of(:post_policy) }
it { is_expected.not_to validate_presence_of(:assignment) }
end
describe "validation" do
let(:course) { Course.create! }
let(:assignment) { course.assignments.create!(title: "!!!") }
it "is valid if a valid course and assignment are specified" do
post_policy = PostPolicy.new(course:, assignment:)
expect(post_policy).to be_valid
end
it "is valid if a valid course is specified without an assignment" do
post_policy = PostPolicy.new(course:)
expect(post_policy).to be_valid
end
it "sets the course based on the associated assignment if no course is specified" do
Set post policies for existing assignments Set post policies on existing assignments and courses as appropriate, and update the posted_at values of submissions belonging to the asignments to match. closes GRADE-1946 Test plan: NOTE: This patchset will enable automatic creation of PostPolicy objects for new assignments and courses. For your test data to be in the proper form (i.e., with no PostPolicy objects attached), you should either create it with a previous patchset or--if you use this patchset--delete the resultant PostPolicy objects via the console. (In the test plan below, a "manual post policy" refers to a PostPolicy object for the specified course or assignment with post_manually set to true, while an "automatic post policy" refers to one with post_manually set to false.) - Set up a course (C1) that: - Does *not* have a default_post_policy object (i.e., no PostPolicy object exists with course_id = C1 and assignment_id = nil) - Has the following assignments: - A non-moderated, non-anonymous assignment (A1) - A non-moderated, non-anonymous MUTED assignment (A2) - A moderated assignment (A3) - Assign grades for some (not all) submissions on each assignment - For A3, have the moderator do some moderating and then post all grades - Set up a course (C2) that *does* have a default_post_policy - Run the migration, and then check the following - For C1: - The course itself should have an automatic post policy created - For A1: - An automatic post policy should be created - The posted_at date of *graded* submissions should be set to their graded_at date - The posted_at date of ungraded submissions should be nil - For A2: - A manual post policy should be created - The posted_at date on all submissions should be nil - For A3: - A manual post policy should be created - The posted_at date on all submissions should be set to their graded_at time (which should be when grades were published) - C2, since it has a post policy already, should be ignored entirely, and all assignments within it should be ignored - On further runs, C1 should be ignored since it has a post policy now Testing new behavior: - With the post policies flag NOT enabled, check that: - Muting an assignment assigns it a manual post policy - Unmuting an assignment assigns it an automatic post policy - ...UNLESS it is anonymous - Creating a new assignment should create a post policy for it - If anonymous/moderated, the policy should be manual - Otherwise it should default to the course's post policy (or to automatic if the course inexplicably has none) - Creating a new course should always create an automatic post policy for the course - Check that the same behavior holds with the flag enabled Change-Id: Ib2fbfc2342a1282c1a6942cc68b2aeccbbc73b70 Reviewed-on: https://gerrit.instructure.com/196237 Tested-by: Jenkins Reviewed-by: Keith Garner <kgarner@instructure.com> Reviewed-by: Gary Mei <gmei@instructure.com> QA-Review: Gary Mei <gmei@instructure.com> Product-Review: Keith Garner <kgarner@instructure.com>
2019-05-31 05:29:43 +08:00
expect(assignment.post_policy.course).to eq(course)
end
end
Move post policies to setting, tie to NG Convert post policies from a garden-variety feature flag into a global setting and remove the old feature flag. Add some helper methods to handle enabling and disabling, and have everywhere in the code that references the feature use the new helper methods instead. Also, have the activation of post policies for a given course depend on whether new gradebook is active for that course. closes GRADE-1974 Test plan: Note that the Post Policies feature flag no longer exists, and instead there's a setting you'll need to turn on. You can do so in the console using: > PostPolicy.enable_feature! To disable it: > PostPolicy.disabled_feature! Note that, even when enabled, it should only apply to courses that have new gradebook turned on. - With the new setting ENABLED: - Courses with new gradebook behave as though post policies is enabled - Do a bit of smoke testing to see if stuff like posting/hiding and changing assignment posting policies hasn't broken - Courses with old gradebook do not - For example, calling a mutation like postAssignmentGrades on an OG course should return an error indicating the feature isn't enabled - With the new setting DISABLED: - Courses with new gradebook behave as though post policies is disabled (e.g., old-style muting is active) - Calling a mutation, as described above, should return an error Change-Id: I5e223d2c4ca4202cce0641f316ecaa505a66298c Reviewed-on: https://gerrit.instructure.com/196062 Tested-by: Jenkins Reviewed-by: Keith Garner <kgarner@instructure.com> Reviewed-by: Gary Mei <gmei@instructure.com> QA-Review: Derek Bender <djbender@instructure.com> Product-Review: Keith Garner <kgarner@instructure.com>
2019-05-31 00:54:57 +08:00
Save post policy in content migrations closes GRADE-2289 Test plan: Course copy: - Have a course with New Gradebook and post policies enabled - Create the following assignments/post policies: - A Manual posting policy for the course overall - An auto-posted assignment (A1) - A manually-posted assignment (A2) - An anonymous assignment (A3) - A moderated assignment (A4) - From the course's Settings screen, make a copy of the course - Enable New Gradebook for the new course if needed - Check that the newly-created copy has retained the overall post policy for the course and the individual post policies for the assignments (i.e., A1 should be auto-posted and A2-A4 should be manually-posted) - Note that A4 should be manually-posted, even if you had previously released grades and set the policy to automatic (course copy does not carry over the grade-publishing status) Blueprint: - Enable the "Blueprint Course" account feature option - Create a new course with the same assignment/post policy loadout as the course in the above step - In the Settings menu, check the "Blueprint Course" checkbox for the course - Set up another course using this one as a blueprint - Change around some of the assignment post policies in the blueprint - Make sure these register as unsynced changes for the assignments, and check that syncing carries them over - Change the course post policy for the blueprint - Make sure that syncing the course carries the new post policy over (it should not apply the new course policy to any assignments, only set it on the course level) - To have the policy transfer over, you'll need to make sure you include course settings in the sync Change-Id: I1fec3d5e88a8aa333ba511780d3934e98a4d7c2c Reviewed-on: https://gerrit.instructure.com/203194 Tested-by: Jenkins Reviewed-by: Rob Orton <rob@instructure.com> Reviewed-by: Jeremy Stanley <jeremy@instructure.com> QA-Review: Gary Mei <gmei@instructure.com> Product-Review: Keith Garner <kgarner@instructure.com>
2019-07-30 22:42:28 +08:00
describe "callbacks" do
let(:course) { Course.create! }
let(:assignment) { course.assignments.create!(title: "!!!") }
context "when the policy is for a specific assignment" do
let(:policy) { assignment.post_policy }
it "updates the assignment's updated_at date when saved" do
assignment.update!(updated_at: 1.day.ago)
save_time = Time.zone.now
Timecop.freeze(save_time) do
expect do
policy.update!(post_manually: true)
end.to change { assignment.updated_at }.to(save_time)
end
end
it "does not update the owning course's updated_at date when saved" do
course.update!(updated_at: 1.day.ago)
Timecop.freeze do
Save post policy in content migrations closes GRADE-2289 Test plan: Course copy: - Have a course with New Gradebook and post policies enabled - Create the following assignments/post policies: - A Manual posting policy for the course overall - An auto-posted assignment (A1) - A manually-posted assignment (A2) - An anonymous assignment (A3) - A moderated assignment (A4) - From the course's Settings screen, make a copy of the course - Enable New Gradebook for the new course if needed - Check that the newly-created copy has retained the overall post policy for the course and the individual post policies for the assignments (i.e., A1 should be auto-posted and A2-A4 should be manually-posted) - Note that A4 should be manually-posted, even if you had previously released grades and set the policy to automatic (course copy does not carry over the grade-publishing status) Blueprint: - Enable the "Blueprint Course" account feature option - Create a new course with the same assignment/post policy loadout as the course in the above step - In the Settings menu, check the "Blueprint Course" checkbox for the course - Set up another course using this one as a blueprint - Change around some of the assignment post policies in the blueprint - Make sure these register as unsynced changes for the assignments, and check that syncing carries them over - Change the course post policy for the blueprint - Make sure that syncing the course carries the new post policy over (it should not apply the new course policy to any assignments, only set it on the course level) - To have the policy transfer over, you'll need to make sure you include course settings in the sync Change-Id: I1fec3d5e88a8aa333ba511780d3934e98a4d7c2c Reviewed-on: https://gerrit.instructure.com/203194 Tested-by: Jenkins Reviewed-by: Rob Orton <rob@instructure.com> Reviewed-by: Jeremy Stanley <jeremy@instructure.com> QA-Review: Gary Mei <gmei@instructure.com> Product-Review: Keith Garner <kgarner@instructure.com>
2019-07-30 22:42:28 +08:00
expect do
policy.update!(post_manually: true)
end.not_to change { course.updated_at }
end
end
end
context "when the policy is the default policy for a course" do
let(:policy) { course.default_post_policy }
it "updates the course's updated_at date when saved" do
course.update!(updated_at: 1.day.ago)
save_time = Time.zone.now
Timecop.freeze(save_time) do
expect do
policy.update!(post_manually: true)
end.to change { course.updated_at }.to(save_time)
end
end
end
end
describe "root account ID" do
let_once(:root_account) { Account.create! }
let_once(:subaccount) { Account.create(root_account:) }
let_once(:course) { Course.create!(account: subaccount) }
context "for a post policy associated with a course" do
it "is set to the course's root account ID" do
expect(course.default_post_policy.root_account_id).to eq root_account.id
end
end
context "for a post policy associated with an assignment" do
it "is set to the associated course's root account ID" do
assignment = course.assignments.create!
expect(assignment.post_policy.root_account_id).to eq root_account.id
end
end
end
end