canvas-lms/spec/factories/assignment_factory.rb

75 lines
2.5 KiB
Ruby
Raw Normal View History

2011-02-01 09:57:29 +08:00
#
# Copyright (C) 2011 - present Instructure, Inc.
2011-02-01 09:57:29 +08:00
#
# 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/>.
#
module Factories
def assignment_model(opts = {})
course = opts.delete(:course) || opts[:context] || course_model(reusable: true)
# turn the group_category title into a group category "object"
group_category = opts.delete(:group_category)
@group_category = course.group_categories.create!(name: group_category) if group_category
opts[:group_category] = @group_category if @group_category
@assignment = factory_with_protected_attributes(course.assignments, assignment_valid_attributes.merge(opts))
@a = @assignment
@c = course
@a
end
2011-02-01 09:57:29 +08:00
def assignment_valid_attributes
{
title: "value for title",
description: "value for description",
due_at: Time.zone.now,
points_possible: "1.5"
}
end
VDD: notifications; closes #10896 The following changes have been made: - Assignment Created - students see the due date that applies to them - admins see "Multiple Dates" - Assignment Due Date Changed - students see the due date that applies to them; they receive no notification if their date doesn't change - admins receive a separate notification for each due date that changes, that they have access to; the message indicates which section or group applies (section-limited TAs will not get messages about due dates in sections they can't see) - Assignment Submitted Late - the message text does not change, but the student's overridden due date is checked - Group Assignment Submitted Late - same as previous There were some bugs fixed along the way: - no longer send duplicate Assignment Submitted and Assignment Resubmitted notifications when an assignment is resubmitted - Group Assignment Submitted Late actually goes out (there was a typo in the whenever clause) Test plan: - Create a course with two sections and a teacher - Enroll a student in each section - Enroll a section-limited TA in each section - Make sure everybody involved is signed up for "Due Date" notifications, ASAP - Using the API, Create an assignment with a default due date (in the past) and an overridden due date for section 2 (in the future). the assignment and override must be created in the same request (use the "Create an assignment" API and supply assignment[assignment_overrides]; it may be easier to use a JSON request body) - Verify that everybody got an "Assignment Created" message (use /users/X/messages) - the teacher should see "Multiple Dates", as should the TA in section 2 (because the default date is still visible to him) - the student and the TA in section 1 should see the default due date - the student in section 2 should see the overridden due date - "Due Date Changed" messages will not go out for assignments that were created less than 3 hours ago (by design, and not new with this changeset), so for the remaining items, you either need to wait 3 hours, or falsify created_at for the assignment you just made... - Change the default due date for the assignment, leaving it in the past - Everybody except the student in section 2 should get a notification with the new date - Change the overridden due date for section 2, leaving it in the future - everybody except the teacher and TA in section 1 should get a notification about the new date - the teacher and section-2 TA's notifications should indicate that they apply to section 2 (the student's should not) - submit the assignment as each student - the teacher should get one notification about each submission: the one about the student in section 1 should say it's late; the one about the student in section 2 should not - submit again - the teacher should get one notification about each submission: the one about the student in section 1 should say it's late; the one about the student in section 2 should not, and should be identified as a resubmission (there is no late-re-submission notification) Change-Id: I26e57807ea0c83b69e2b532ec8822f6570ba1701 Reviewed-on: https://gerrit.instructure.com/14662 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Jeremy Stanley <jeremy@instructure.com>
2012-10-27 04:10:08 +08:00
def assignment_with_override(opts={})
assignment_model(opts)
@override = @a.assignment_overrides.build
@override.set = @c.default_section
@override.save!
@override
end
def differentiated_assignment(opts={})
course_section = opts.delete(:course_section)
@assignment = opts[:assignment] || assignment_model(opts)
@assignment.only_visible_to_overrides = true
@assignment.save!
@override = @assignment.assignment_overrides.build
@override.set = course_section || @course.default_section
@override.save!
@override
end
def create_assignments(course_ids, count_per_course = 1, fields = {})
account = Account.default
course_ids = Array(course_ids)
course_ids *= count_per_course
records = course_ids.each_with_index.map do |id, i|
{
context_id: id, context_type: 'Course', context_code: "course_#{id}",
title: "#{id}:#{i}", grading_type: "points", submission_types: "none",
workflow_state: 'published',
root_account_id: account.id,
}.merge(fields)
end
create_records(Assignment, records)
end
end