Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
putting together notification subscription model
- Loading branch information
1 parent
5515319
commit a8230be
Showing
8 changed files
with
100 additions
and
7 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
class Whoops::NotificationSubscription | ||
include Mongoid::Document | ||
|
||
has_one :filter, :as => :filterable, :class_name => "Whoops::Filter" | ||
validates_presence_of :email | ||
|
||
field :email, :type => String | ||
|
||
before_save :downcase_email | ||
|
||
def downcase_email | ||
self.email.downcase! | ||
end | ||
|
||
class Matcher | ||
attr_accessor :event_group | ||
|
||
# @param [ Whoops::EventGroup ] | ||
def initialize(event_group) | ||
self.event_group = event_group | ||
end | ||
|
||
def matching_emails | ||
Whoops::NotificationSubscription.all.select{ |ns| ns.filter.matches_event_group?(self.event_group) }.collect(&:email) | ||
end | ||
end | ||
end |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require 'spec_helper' | ||
|
||
describe Whoops::NotificationSubscription do | ||
let(:subscription) { | ||
Whoops::NotificationSubscription.create( | ||
:email => "Daniel@Higginbotham.com", | ||
:filter => Whoops::Filter.new(:service => ["test.*"]) | ||
) | ||
} | ||
let(:event_params){ Whoops::Spec::ATTRIBUTES[:event_params] } | ||
let(:event){ Whoops::Event.record(event_params) } | ||
let(:event_group){ event.event_group } | ||
|
||
it "downcases the email on save" do | ||
subscription.email.should == "daniel@higginbotham.com" | ||
end | ||
|
||
describe Whoops::NotificationSubscription::Matcher do | ||
let(:matcher){ Whoops::NotificationSubscription::Matcher.new(event_group) } | ||
|
||
it "should return the email addresses of subscriptions whose filters match an event group" do | ||
subscription.filter.save | ||
|
||
nomatch = Whoops::NotificationSubscription.create( | ||
:email => "does_not@match.com", | ||
:filter => Whoops::Filter.new(:service => ["not_test.*"]) | ||
) | ||
nomatch.filter.save | ||
|
||
matcher.matching_emails.should == ["daniel@higginbotham.com"] | ||
end | ||
end | ||
end |
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