2020-10-27 00:51:19 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-01-04 02:43:55 +08:00
|
|
|
#
|
|
|
|
# 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
|
2019-07-09 04:35:56 +08:00
|
|
|
it { is_expected.to belong_to(:course).required.inverse_of(:post_policies) }
|
2019-01-04 02:43:55 +08:00
|
|
|
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
|
2023-06-02 06:06:09 +08:00
|
|
|
post_policy = PostPolicy.new(course:, assignment:)
|
2019-01-04 02:43:55 +08:00
|
|
|
expect(post_policy).to be_valid
|
|
|
|
end
|
|
|
|
|
|
|
|
it "is valid if a valid course is specified without an assignment" do
|
2023-06-02 06:06:09 +08:00
|
|
|
post_policy = PostPolicy.new(course:)
|
2019-01-04 02:43:55 +08:00
|
|
|
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)
|
2019-01-04 02:43:55 +08:00
|
|
|
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
|
|
|
|
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)
|
|
|
|
|
2024-03-02 04:59:55 +08:00
|
|
|
Timecop.freeze do
|
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
|
2020-06-04 23:37:56 +08:00
|
|
|
|
|
|
|
describe "root account ID" do
|
|
|
|
let_once(:root_account) { Account.create! }
|
2023-06-02 06:06:09 +08:00
|
|
|
let_once(:subaccount) { Account.create(root_account:) }
|
2020-06-04 23:37:56 +08:00
|
|
|
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
|
2019-01-04 02:43:55 +08:00
|
|
|
end
|