Skip to content
Browse files

Added column to user table: forem_auto_subscribe. True if user replie…

…s should automatically subscribe users, false otherwise. Set to false by default but can be changed in another migration
  • Loading branch information...
1 parent 3c3e61c commit 375b25393201bf450cfc244eaa13a728bde62173 @jeremyongplaymesh jeremyongplaymesh committed Apr 14, 2012
View
2 app/models/forem/post.rb
@@ -93,7 +93,7 @@ def approved?
protected
def subscribe_replier
- if self.topic && self.user
+ if self.topic && self.user && self.user.forem_auto_subscribe
self.topic.subscribe_user(self.user.id)
end
end
View
5 db/migrate/20120414183053_add_forem_auto_subscribe_to_user.rb
@@ -0,0 +1,5 @@
+class AddForemAutoSubscribeToUser < ActiveRecord::Migration
+ def change
+ add_column :users, :forem_auto_subscribe, :boolean, :default => false
+ end
+end
View
12 spec/models/post_spec.rb
@@ -16,11 +16,21 @@
end
context "after creation" do
- it "subscribes the current poster" do
+ it "subscribes the current poster if forem_auto_subscribe is set to true" do
@topic = FactoryGirl.create(:topic)
@post = FactoryGirl.create(:post, :topic => @topic)
@topic.subscriptions.last.subscriber.should == @post.user
end
+
+ it "doesn't subscribe the current poster if forem_auto_subscribe is set to false" do
+ @topic = FactoryGirl.create(:topic)
+ @post = FactoryGirl.create(:post, :topic => @topic)
+
+ @user_not_autosubscribed = FactoryGirl.create(:not_autosubscribed)
+ @post = FactoryGirl.build(:approved_post, :topic => @topic, :user => @user_not_autosubscribed)
+
+ @topic.subscriptions.last.subscriber.should_not == @post.user_not_autosubscribed
+ end
it "does not email subscribers after post creation if not approved" do
@post = FactoryGirl.build(:post, :topic => topic)
View
5 spec/support/factories/users.rb
@@ -4,10 +4,15 @@
f.email { "bob#{rand(100000)}@boblaw.com" }
f.password "password"
f.password_confirmation "password"
+ f.forem_auto_subscribe true
factory :admin do |f|
f.forem_admin true
end
+
+ factory :not_autosubscribed do |f|
+ f.forem_auto_subscribe false
+ end
end
end

0 comments on commit 375b253

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