Merge commit for due date validation
Merge remote-tracking branch 'origin/dev/stewie/2017-02-10-differentiated-assignment-override-due-dates' Due date validation works for differentiated assignments. Quiz and Discussion Topic due date validation will come later. Mastery path assignment due date validation will also come later. Refs: SIS-2636 Test Plan: Due dates for new differentiated assignments should be required when: assignment.post_to_sis = true account's sis_require_assignment_due_date is true the new_sis_integrations feature flag is on Change-Id: I874c37a2acbea6297a80ba2efb953d0ec3e54490
This commit is contained in:
commit
fe79fce0e6
|
@ -80,6 +80,7 @@ class Assignment < ActiveRecord::Base
|
|||
validates_associated :external_tool_tag, :if => :external_tool?
|
||||
validate :group_category_changes_ok?
|
||||
validate :due_date_ok?
|
||||
validate :assignment_overrides_due_date_ok?
|
||||
validate :discussion_group_ok?
|
||||
validate :positive_points_possible?
|
||||
validate :moderation_setting_ok?
|
||||
|
@ -292,6 +293,7 @@ class Assignment < ActiveRecord::Base
|
|||
:maintain_group_category_attribute,
|
||||
:validate_assignment_overrides
|
||||
|
||||
|
||||
after_save :update_grades_if_details_changed,
|
||||
:touch_assignment_group,
|
||||
:touch_context,
|
||||
|
@ -2336,6 +2338,14 @@ class Assignment < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def assignment_overrides_due_date_ok?
|
||||
if AssignmentUtil.due_date_required?(self)
|
||||
if active_assignment_overrides.where(due_at: nil).count > 0
|
||||
errors.add(:due_at, I18n.t("cannot be blank for any assignees when Post to Sis is checked"))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def assignment_name_length_ok?
|
||||
name_length = max_name_length
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ module AssignmentUtil
|
|||
end
|
||||
|
||||
def self.due_date_required_for_account?(assignment)
|
||||
assignment.try(:context).try(:account).try(:sis_syncing).try(:[], :value).present? &&
|
||||
assignment.try(:context).try(:account).try(:sis_require_assignment_due_date).try(:[], :value) &&
|
||||
assignment.try(:context).try(:account).try(:feature_enabled?, 'new_sis_integrations').present?
|
||||
end
|
||||
|
|
|
@ -12,52 +12,62 @@ describe AssignmentUtil do
|
|||
|
||||
let(:assignment_name_length_value){ 15 }
|
||||
|
||||
def account_stub_helper(assignment, require_due_date, sis_syncing, new_sis_integrations)
|
||||
assignment.context.account.stubs(:sis_require_assignment_due_date).returns({value: require_due_date})
|
||||
assignment.context.account.stubs(:sis_syncing).returns({value: sis_syncing})
|
||||
assignment.context.account.stubs(:feature_enabled?).with('new_sis_integrations').returns(new_sis_integrations)
|
||||
end
|
||||
|
||||
def due_date_required_helper(assignment, post_to_sis, require_due_date, sis_syncing, new_sis_integrations)
|
||||
assignment.post_to_sis = post_to_sis
|
||||
account_stub_helper(assignment, require_due_date, sis_syncing, new_sis_integrations)
|
||||
end
|
||||
|
||||
describe "due_date_required?" do
|
||||
it "returns true when all 3 are set to true" do
|
||||
assignment.post_to_sis = true
|
||||
assignment.context.account.stubs(:sis_require_assignment_due_date).returns({value: true})
|
||||
assignment.context.account.stubs(:feature_enabled?).with('new_sis_integrations').returns(true)
|
||||
it "returns true when all 4 are set to true" do
|
||||
due_date_required_helper(assignment, true, true, true, true)
|
||||
expect(described_class.due_date_required?(assignment)).to eq(true)
|
||||
end
|
||||
|
||||
it "returns false when post_to_sis is false" do
|
||||
assignment.post_to_sis = false
|
||||
assignment.context.account.stubs(:sis_require_assignment_due_date).returns({value: true})
|
||||
assignment.context.account.stubs(:feature_enabled?).with('new_sis_integrations').returns(true)
|
||||
due_date_required_helper(assignment, false, true, true, true)
|
||||
expect(described_class.due_date_required?(assignment)).to eq(false)
|
||||
end
|
||||
|
||||
it "returns false when sis_require_assignment_due_date is false" do
|
||||
assignment.post_to_sis = true
|
||||
assignment.context.account.stubs(:sis_require_assignment_due_date).returns({value: false})
|
||||
assignment.context.account.stubs(:feature_enabled?).with('new_sis_integrations').returns(true)
|
||||
due_date_required_helper(assignment, true, false, true, true)
|
||||
expect(described_class.due_date_required?(assignment)).to eq(false)
|
||||
end
|
||||
|
||||
it "returns false when sis_syncing is false" do
|
||||
due_date_required_helper(assignment, true, true, false, true)
|
||||
expect(described_class.due_date_required?(assignment)).to eq(false)
|
||||
end
|
||||
|
||||
it "returns false when new_sis_integrations is false" do
|
||||
assignment.post_to_sis = true
|
||||
assignment.context.account.stubs(:sis_require_assignment_due_date).returns({value: true})
|
||||
assignment.context.account.stubs(:feature_enabled?).with('new_sis_integrations').returns(false)
|
||||
due_date_required_helper(assignment, true, true, true, false)
|
||||
expect(described_class.due_date_required?(assignment)).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
describe "due_date_required_for_account?" do
|
||||
it "returns true both are set to true" do
|
||||
assignment.context.account.stubs(:sis_require_assignment_due_date).returns({value: true})
|
||||
assignment.context.account.stubs(:feature_enabled?).with('new_sis_integrations').returns(true)
|
||||
it "returns true when all 3 are set to true" do
|
||||
account_stub_helper(assignment, true, true, true)
|
||||
expect(described_class.due_date_required_for_account?(assignment)).to eq(true)
|
||||
end
|
||||
|
||||
it "returns false when sis_require_assignment_due_date is false" do
|
||||
assignment.context.account.stubs(:sis_require_assignment_due_date).returns({value: false})
|
||||
assignment.context.account.stubs(:feature_enabled?).with('new_sis_integrations').returns(true)
|
||||
account_stub_helper(assignment, false, true, true)
|
||||
expect(described_class.due_date_required_for_account?(assignment)).to eq(false)
|
||||
end
|
||||
|
||||
it "returns false when sis_syncing is false" do
|
||||
account_stub_helper(assignment, true, false, true)
|
||||
expect(described_class.due_date_required_for_account?(assignment)).to eq(false)
|
||||
end
|
||||
|
||||
it "returns false when new_sis_integrations is false" do
|
||||
assignment.context.account.stubs(:sis_require_assignment_due_date).returns({value: true})
|
||||
assignment.context.account.stubs(:feature_enabled?).with('new_sis_integrations').returns(false)
|
||||
account_stub_helper(assignment, true, true, false)
|
||||
expect(described_class.due_date_required_for_account?(assignment)).to eq(false)
|
||||
end
|
||||
end
|
||||
|
@ -130,4 +140,3 @@ describe AssignmentUtil do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -3435,6 +3435,55 @@ describe Assignment do
|
|||
end
|
||||
end
|
||||
|
||||
describe "validate_assignment_overrides_due_date" do
|
||||
let(:section_1) { @course.course_sections.create!(name: "section 1") }
|
||||
let(:section_2) { @course.course_sections.create!(name: "section 2") }
|
||||
|
||||
let(:assignment) do
|
||||
@course.assignments.create!(assignment_valid_attributes)
|
||||
end
|
||||
|
||||
describe "when an override has no due date" do
|
||||
before do
|
||||
# Create an override with a due date
|
||||
create_section_override_for_assignment(assignment, course_section: section_1)
|
||||
|
||||
# Create an override without a due date
|
||||
override = create_section_override_for_assignment(assignment, course_section: section_2)
|
||||
override.due_at = nil
|
||||
override.save
|
||||
end
|
||||
|
||||
it "is not valid when AssignmentUtil.due_date_required? is true" do
|
||||
AssignmentUtil.stubs(:due_date_required?).returns(true)
|
||||
expect(assignment.valid?).to eq(false)
|
||||
end
|
||||
|
||||
it "is valid when AssignmentUtil.due_date_required? is false" do
|
||||
AssignmentUtil.stubs(:due_date_required?).returns(false)
|
||||
expect(assignment.valid?).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
describe "when all overrides have a due date" do
|
||||
before do
|
||||
# Create 2 overrides with due dates
|
||||
create_section_override_for_assignment(assignment, course_section: section_1)
|
||||
create_section_override_for_assignment(assignment, course_section: section_2)
|
||||
end
|
||||
|
||||
it "is valid when AssignmentUtil.due_date_required? is true and " do
|
||||
AssignmentUtil.stubs(:due_date_required?).returns(true)
|
||||
expect(assignment.valid?).to eq(true)
|
||||
end
|
||||
|
||||
it "is valid when AssignmentUtil.due_date_required? is false" do
|
||||
AssignmentUtil.stubs(:due_date_required?).returns(false)
|
||||
expect(assignment.valid?).to eq(true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "due_date_required?" do
|
||||
let(:assignment) do
|
||||
@course.assignments.create!(assignment_valid_attributes)
|
||||
|
|
Loading…
Reference in New Issue