Skip to content

Commit 0797b6d

Browse files
committed
halfway through a spin
1 parent 6f25400 commit 0797b6d

4 files changed

Lines changed: 41 additions & 0 deletions

File tree

models/discussion.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class Discussion
2222
#this is the slug for the url
2323
key :slug, String
2424

25+
key :subscribed_users, Array
26+
2527
timestamps!
2628

2729
before_save :make_slug
@@ -55,6 +57,10 @@ def forum_description
5557
end
5658
end
5759

60+
def create_subscription! email
61+
subscribed_users << email
62+
end
63+
5864
private
5965
def make_slug
6066
self.slug = self.title.to_slug

models/reply.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,14 @@ class Reply
1313
#we need to make sure we have an author
1414
validate_on_create :author_check
1515

16+
after_save :send_subscription_notice
17+
1618
private
1719

20+
def send_subscription_notice
21+
_root_document.create_subscription! :author_email
22+
end
23+
1824
def author_check
1925
if author.nil?
2026
errors.add(:author, "Someone must have written this reply!")

spec/discussion_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
describe Discussion do
2+
3+
describe "#create_subscription!" do
4+
5+
it "adds a new email to the subscription list" do
6+
discussion = Factory(:discussion)
7+
discussion.subscribed_users.count.should == 0
8+
discussion.create_subscription! "somebody@example.com"
9+
discussion.subscribed_users.count.should == 1
10+
end
11+
12+
end
13+
14+
end

spec/reply_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
describe Reply do
2+
3+
describe "subscriptions" do
4+
it "adds one to its Discussion upon creation" do
5+
email = "someone@example.com"
6+
@discussion = Factory(:discussion)
7+
@discussion.should_receive(:create_subscription!)
8+
@discussion.replies << Factory(:reply, :author_email => email)
9+
@discussion.save
10+
end
11+
12+
it "triggers an email to others upon creation"
13+
end
14+
15+
end

0 commit comments

Comments
 (0)