Merge pull request #431 from sfu/fix-alerts_spillover

Fix bug that causes alerts to affect other courses
This commit is contained in:
Cody Cutrer 2014-04-07 09:01:13 -06:00
commit f3f5eeb911
2 changed files with 11 additions and 1 deletions

View File

@ -110,7 +110,7 @@ class Alert < ActiveRecord::Base
def self.evaluate_for_course(course, account_alerts = nil, include_user_notes = nil)
return unless course.available?
alerts = Array(account_alerts)
alerts = Array.new(account_alerts || [])
alerts.concat course.alerts.all
return if alerts.empty?

View File

@ -123,6 +123,16 @@ describe Alert do
Alert.evaluate_for_course(@course)
Alert.sent_alerts.should be_blank
end
it "should not trigger any alerts in subsequent courses" do
course_with_teacher(:active_all => 1)
student_in_course(:active_all => 1)
@course.alerts.create!(:recipients => [:student], :criteria => [{:criterion_type => 'Interaction', :threshold => 7}])
@course.start_at = Time.now - 30.days
account_alerts = []
Alert.evaluate_for_course(@course, account_alerts)
account_alerts.should be_empty
end
end
context 'repetition' do