Created
January 9, 2011 17:11
-
-
Save davidyang/771819 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Moved here from Notifications, since we don't really need Visit to do it | |
def create_notifications | |
#eventually if we want to do multiple voice/email notifications, we should have | |
#some has_many relationship between query (or perhaps setting) and notification methods | |
# but for now just check all of them | |
NotificationMethod.all.each do |method| | |
nklass = Module.const_get(method.klass) | |
if self.send("#{method.short_name}_active?") # this maps to some functions in query | |
nklass.visits_needing_notification(self).each do |visit| | |
nklass.create(:visit => visit) | |
end | |
end | |
end | |
end | |
it "should correctly create notifications" do | |
@query = Factory.create(:query, {:email_active => true, :actively_notify => true}) | |
email_mock = mock(EmailNotification) | |
voice_mock = mock(VoiceNotification) | |
Module.stub!(:const_get).with('EmailNotification').and_return(email_mock) | |
Module.stub!(:const_get).with('VoiceNotification').and_return(voice_mock) | |
email_mock.should_receive(:visits_needing_notification).once.and_return([]) | |
voice_mock.should_receive(:visits_needing_notification).once.and_return([]) | |
@query.create_notifications | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment