populate root_account_id on new LearningOutcomeGroup
* prereq for root_account on ContentTag refs PLAT-5727 flag=none test plan: * specs * if you want, save a LearningOutcomeGroup and observe that its root_account and root_account_id attributes are not nil Change-Id: Id268ea78377574cdb3bd2cef4a53bb6b4ca135b1 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/236478 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> Reviewed-by: Michael Brewer-Davis <mbd@instructure.com> QA-Review: Xander Moffatt <xmoffatt@instructure.com> Product-Review: Xander Moffatt <xmoffatt@instructure.com>
This commit is contained in:
parent
15c065551a
commit
d9c7d3b7cc
|
@ -26,8 +26,10 @@ class LearningOutcomeGroup < ActiveRecord::Base
|
|||
has_many :child_outcome_groups, :class_name => 'LearningOutcomeGroup', :foreign_key => "learning_outcome_group_id"
|
||||
has_many :child_outcome_links, -> { where(tag_type: 'learning_outcome_association', content_type: 'LearningOutcome') }, class_name: 'ContentTag', as: :associated_asset
|
||||
belongs_to :context, polymorphic: [:account, :course]
|
||||
belongs_to :root_account, class_name: 'Account'
|
||||
|
||||
before_save :infer_defaults
|
||||
before_save :set_root_account_id
|
||||
validates :vendor_guid, length: { maximum: maximum_string_length, allow_nil: true }
|
||||
validates_length_of :description, :maximum => maximum_text_length, :allow_nil => true, :allow_blank => true
|
||||
validates_length_of :title, :maximum => maximum_string_length, :allow_nil => true, :allow_blank => true
|
||||
|
@ -204,6 +206,17 @@ class LearningOutcomeGroup < ActiveRecord::Base
|
|||
scope.select(title_order_by_clause).order(title_order_by_clause)
|
||||
end
|
||||
|
||||
def set_root_account_id
|
||||
return if self.root_account_id.present?
|
||||
|
||||
case self.context
|
||||
when Account
|
||||
self.root_account_id = self.context.resolved_root_account_id
|
||||
when Course
|
||||
self.root_account_id = self.context.root_account_id
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def infer_defaults
|
||||
|
|
|
@ -281,4 +281,23 @@ describe LearningOutcomeGroup do
|
|||
expect(active_child_groups).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
describe 'before save' do
|
||||
describe 'set_root_account_id' do
|
||||
it 'sets root_account_id using Account context' do
|
||||
group = LearningOutcomeGroup.create!(title: 'group', context: Account.default)
|
||||
expect(group.root_account).to eq Account.default
|
||||
end
|
||||
|
||||
it 'sets root_account_id using Course context' do
|
||||
group = @course.learning_outcome_groups.create!(title: 'group')
|
||||
expect(group.root_account).to eq @course.root_account
|
||||
end
|
||||
|
||||
it 'leaves root_acount_id nil when global (context is nil)' do
|
||||
group = LearningOutcomeGroup.create!(title: 'group', context_id: nil)
|
||||
expect(group.root_account_id).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue