lml / ost

OpenStax Tutor
Other
7 stars 8 forks source link

Presentation and Feedback Condition ".*" regex fails to match tagless AssignmentExercises #300

Open kevinburleigh75 opened 11 years ago

kevinburleigh75 commented 11 years ago

When a PresentationCondition or FeedbackCondition has the .* regex, the intent is to match ANY AssignmentExercise. However, when the AE has no tags at all, the following PresentationCondition/LearningCondition test fails when labels.any? returns []:

  def applies_to?(student_or_assignment_exercise)
    label_regex_array = label_regex.split(",").collect{|lr| lr.strip}

    if student_or_assignment_exercise.instance_of? StudentExercise
      assignment_exercise = student_or_assignment_exercise.assignment_exercise
    else
      assignment_exercise = student_or_assignment_exercise
    end

    labels = assignment_exercise.tag_list

    label_regex_array.any? do |regex|
      labels.any? do |label|
        label == regex || label.match(Regexp.new(regex, Regexp::IGNORECASE))
      end
    end
  end
kevinburleigh75 commented 10 years ago

It is possible that this is now the desired behavior, now that the default PC/FC can be easily viewed and edited. However, it should still be made clear to users that unlabeled exercises will not be matched by any regex.