Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

halfway through a spin

  • Loading branch information...
commit 0797b6dd8ef00665a1b4c4f3064bf2bd197c67a9 1 parent 6f25400
@steveklabnik steveklabnik authored
View
6 models/discussion.rb
@@ -22,6 +22,8 @@ class Discussion
#this is the slug for the url
key :slug, String
+ key :subscribed_users, Array
+
timestamps!
before_save :make_slug
@@ -55,6 +57,10 @@ def forum_description
end
end
+ def create_subscription! email
+ subscribed_users << email
+ end
+
private
def make_slug
self.slug = self.title.to_slug
View
6 models/reply.rb
@@ -13,8 +13,14 @@ class Reply
#we need to make sure we have an author
validate_on_create :author_check
+ after_save :send_subscription_notice
+
private
+ def send_subscription_notice
+ _root_document.create_subscription! :author_email
+ end
+
def author_check
if author.nil?
errors.add(:author, "Someone must have written this reply!")
View
14 spec/discussion_spec.rb
@@ -0,0 +1,14 @@
+describe Discussion do
+
+ describe "#create_subscription!" do
+
+ it "adds a new email to the subscription list" do
+ discussion = Factory(:discussion)
+ discussion.subscribed_users.count.should == 0
+ discussion.create_subscription! "somebody@example.com"
+ discussion.subscribed_users.count.should == 1
+ end
+
+ end
+
+end
View
15 spec/reply_spec.rb
@@ -0,0 +1,15 @@
+describe Reply do
+
+ describe "subscriptions" do
+ it "adds one to its Discussion upon creation" do
+ email = "someone@example.com"
+ @discussion = Factory(:discussion)
+ @discussion.should_receive(:create_subscription!)
+ @discussion.replies << Factory(:reply, :author_email => email)
+ @discussion.save
+ end
+
+ it "triggers an email to others upon creation"
+ end
+
+end

0 comments on commit 0797b6d

Please sign in to comment.
Something went wrong with that request. Please try again.