Assignment model requires a due_at
This is one piece of SIS-2636 Refs: SIS-2636 Test Plan: Verify that an assignment requires a due date under certain conditions: assignment.post_to_sis = true account's sis_require_assignment_due_date is true the new_sis_integrations feature flag is on Change-Id: Id614b6606127cad630b7c622c94893289aad59e6 Reviewed-on: https://gerrit.instructure.com/99181 Reviewed-by: Brad Humphrey <brad@instructure.com> QA-Review: Steven Shepherd <sshepherd@instructure.com> Tested-by: Jenkins Product-Review: Oxana
This commit is contained in:
parent
6c72aef3e6
commit
5b0d053da2
|
@ -269,7 +269,6 @@ class Account < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
def mfa_settings
|
||||
settings[:mfa_settings].try(:to_sym) || :disabled
|
||||
end
|
||||
|
|
|
@ -77,6 +77,7 @@ class Assignment < ActiveRecord::Base
|
|||
has_one :external_tool_tag, :class_name => 'ContentTag', :as => :context, :inverse_of => :context, :dependent => :destroy
|
||||
validates_associated :external_tool_tag, :if => :external_tool?
|
||||
validate :group_category_changes_ok?
|
||||
validate :due_date_ok?
|
||||
validate :discussion_group_ok?
|
||||
validate :positive_points_possible?
|
||||
validate :moderation_setting_ok?
|
||||
|
@ -136,6 +137,12 @@ class Assignment < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def due_date_ok?
|
||||
if sis_require_assignment_due_date? && self.post_to_sis.present? && self.due_at.blank?
|
||||
errors.add(:due_at, I18n.t("due_at", "The Due date cannot be blank when Post to Sis is checked"))
|
||||
end
|
||||
end
|
||||
|
||||
def secure_params
|
||||
body = {}
|
||||
body[:lti_assignment_id] = self.lti_context_id || SecureRandom.uuid
|
||||
|
@ -2299,4 +2306,12 @@ class Assignment < ActiveRecord::Base
|
|||
self.send_later_if_production_enqueue_args(:run_if_overrides_changed!, {:singleton => "assignment_overrides_changed_#{self.global_id}"})
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def sis_require_assignment_due_date?
|
||||
self.try(:context).try(:account).try(:sis_require_assignment_due_date).try(:[], :value) &&
|
||||
self.try(:context).try(:feature_enabled?, 'new_sis_integrations').present?
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -262,6 +262,7 @@ class Course < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.skip_updating_account_associations?
|
||||
!!@skip_updating_account_associations
|
||||
end
|
||||
|
|
|
@ -137,5 +137,5 @@ module FeatureFlags
|
|||
|
||||
@feature_flag_cache[feature] = retval
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
|
@ -28,7 +28,11 @@ describe AssignmentsController do
|
|||
def course_assignment(course = nil)
|
||||
course ||= @course
|
||||
@group = course.assignment_groups.create(:name => "some group")
|
||||
@assignment = course.assignments.create(:title => "some assignment", :assignment_group => @group)
|
||||
@assignment = course.assignments.create(
|
||||
:title => "some assignment",
|
||||
:assignment_group => @group,
|
||||
:due_at => Time.zone.now + 1.week
|
||||
)
|
||||
expect(@assignment.assignment_group).to eql(@group)
|
||||
expect(@group.assignments).to be_include(@assignment)
|
||||
@assignment
|
||||
|
|
|
@ -3414,6 +3414,49 @@ describe Assignment do
|
|||
end
|
||||
end
|
||||
|
||||
describe "due_date" do
|
||||
let(:assignment) do
|
||||
@course.assignments.create!(assignment_valid_attributes)
|
||||
end
|
||||
|
||||
describe "when sis_require_assignment_due_date is true" do
|
||||
it "is required when post_to_sis is true and feature_enabled(post_grades) is true" do
|
||||
assignment.post_to_sis = true
|
||||
assignment.due_at = nil
|
||||
assignment.context.account.stubs(:sis_require_assignment_due_date).returns({value: true})
|
||||
assignment.context.stubs(:feature_enabled?).with('new_sis_integrations').returns(true)
|
||||
expect(assignment.valid?).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
describe "when sis_require_assignment_due_date is false" do
|
||||
before do
|
||||
assignment.context.account.stubs(:sis_require_assignment_due_date).returns({value: false})
|
||||
end
|
||||
|
||||
it "is not required when post_to_sis is true and feature_enabled(post_grades) is false" do
|
||||
assignment.post_to_sis = true
|
||||
assignment.due_at = nil
|
||||
assignment.context.stubs(:feature_enabled?).with('new_sis_integrations').returns(false)
|
||||
expect(assignment.valid?).to eq(true)
|
||||
end
|
||||
|
||||
it "is not required when post_to_sis is false and feature_enabled(post_grades) is true" do
|
||||
assignment.post_to_sis = false
|
||||
assignment.due_at = nil
|
||||
assignment.context.stubs(:feature_enabled?).with('new_sis_integrations').returns(true)
|
||||
expect(assignment.valid?).to eq(true)
|
||||
end
|
||||
|
||||
it "is not required when post_to_sis is false and feature_enabled(post_grades) is false" do
|
||||
assignment.post_to_sis = false
|
||||
assignment.due_at = nil
|
||||
assignment.context.stubs(:feature_enabled?).with('new_sis_integrations').returns(false)
|
||||
expect(assignment.valid?).to eq(true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "external_tool_tag" do
|
||||
it "should update the existing tag when updating the assignment" do
|
||||
a = @course.assignments.create!(title: "test",
|
||||
|
|
Loading…
Reference in New Issue