Handle concurrent destroy / import of outcome groups

Fixes OUT-2336

Test Plan:
- Create or import a group with lots of outcomes and groups.
- Attempt to import that group into another context.
- Immediately open another tab and navigate to the parent group of the
  import.
- Verify that the imported group does not appear currently.
- Reload / wait for the import to finish and group to appear.

Change-Id: Ic97f86201932ff7751914e4cc2f95290b6e1c8b8
Reviewed-on: https://gerrit.instructure.com/157757
Tested-by: Jenkins
Reviewed-by: Michael Brewer-Davis <mbd@instructure.com>
Reviewed-by: Augusto Callejas <acallejas@instructure.com>
QA-Review: Matt Berns <mberns@instructure.com>
Product-Review: Sidharth Oberoi <soberoi@instructure.com>
This commit is contained in:
Frank Murphy 2018-07-17 18:40:15 -04:00
parent 49fe00157e
commit 49dd6e6e46
2 changed files with 32 additions and 28 deletions

View File

@ -79,6 +79,7 @@ class LearningOutcomeGroup < ActiveRecord::Base
# commit!
def add_outcome_group(original, opts={})
# copy group into this group
transaction do
copy = child_outcome_groups.build
copy.title = original.title
copy.description = original.description
@ -101,6 +102,7 @@ class LearningOutcomeGroup < ActiveRecord::Base
# done
copy
end
end
# moves an existing outcome link from the same context to be under this
# group.

View File

@ -138,19 +138,21 @@ describe LearningOutcomeGroup do
end
describe '#add_outcome_group' do
before :each do
@group1 = @course.learning_outcome_groups.create!(:title => 'group1')
@group2 = @course.learning_outcome_groups.create!(:title => 'group2')
@outcome1 = @course.created_learning_outcomes.create!(:title => 'o1')
@group2.add_outcome(@outcome1)
end
it 'adds a child outcome group and copies all contents' do
group1 = @course.learning_outcome_groups.create!(:title => 'group1')
group2 = @course.learning_outcome_groups.create!(:title => 'group2')
outcome1 = @course.created_learning_outcomes.create!(:title => 'o1')
group2.add_outcome(outcome1)
expect(@group1.child_outcome_groups).to be_empty
expect(group1.child_outcome_groups).to be_empty
child_outcome_group = @group1.add_outcome_group(@group2)
child_outcome_group = group1.add_outcome_group(group2)
expect(child_outcome_group.title).to eq(group2.title)
expect(child_outcome_group.title).to eq(@group2.title)
expect(child_outcome_group.child_outcome_links.map(&:content_id)).to eq(
group2.child_outcome_links.map(&:content_id)
@group2.child_outcome_links.map(&:content_id)
)
end
end