don't cross outcome groups and outcomes

a course will have content tags for both learning outcomes and learning
outcome groups. the latter still use a tag_type of
'learning_outcome_association' (maybe a bug?). course.learning_outcomes
could then choose one of these content_tags, and pull in a completely
unrelated outcome that happened to have the same id as the group from
the content_tag row.

fixes #5831

Change-Id: I1be7e579147331165fbfb7c241c224a255561715
Reviewed-on: https://gerrit.instructure.com/5977
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Brian Palmer <brianp@instructure.com>
This commit is contained in:
Jacob Fugal 2011-10-04 12:30:39 -06:00
parent 0b09d5a50c
commit 1dc8f60691
2 changed files with 28 additions and 1 deletions

View File

@ -92,7 +92,7 @@ class Course < ActiveRecord::Base
has_many :participating_admins, :through => :enrollments, :source => :user, :conditions => "(enrollments.type = 'TaEnrollment' or enrollments.type = 'TeacherEnrollment') and enrollments.workflow_state = 'active'"
has_many :learning_outcomes, :through => :learning_outcome_tags, :source => :learning_outcome_content
has_many :learning_outcome_tags, :as => :context, :class_name => 'ContentTag', :conditions => ['content_tags.tag_type = ? AND content_tags.workflow_state != ?', 'learning_outcome_association', 'deleted']
has_many :learning_outcome_tags, :as => :context, :class_name => 'ContentTag', :conditions => ['content_tags.tag_type = ? AND content_tags.content_type = ? AND content_tags.workflow_state != ?', 'learning_outcome_association', 'LearningOutcome', 'deleted']
has_many :created_learning_outcomes, :class_name => 'LearningOutcome', :as => :context
has_many :learning_outcome_groups, :as => :context
has_many :course_account_associations

View File

@ -706,6 +706,33 @@ describe Course, "backup" do
end
end
it "should not cross learning outcomes with learning outcome groups in the association" do
# set up two courses with two outcomes
course = course_model
default_group = LearningOutcomeGroup.default_for(course)
outcome = course.created_learning_outcomes.create!
default_group.add_item(outcome)
other_course = course_model
other_default_group = LearningOutcomeGroup.default_for(other_course)
other_outcome = other_course.created_learning_outcomes.create!
other_default_group.add_item(other_outcome)
# add another group to the first course, which "coincidentally" has the
# same id as the second course's outcome
other_group = course.learning_outcome_groups.build
other_group.id = other_outcome.id
other_group.save!
default_group.add_item(other_group)
# reload and check
course.reload
other_course.reload
course.learning_outcomes.should be_include(outcome)
course.learning_outcomes.should_not be_include(other_outcome)
other_course.learning_outcomes.should be_include(other_outcome)
end
it "should copy learning outcomes into the new course" do
old_course = course_model
lo = old_course.learning_outcomes.new