Only send email notifications to members who want them.

This commit is contained in:
Miles Gould
2013-03-27 12:17:46 +00:00
parent 64b957db20
commit 91acf9f878
6 changed files with 36 additions and 22 deletions

View File

@@ -16,7 +16,9 @@ class Notification < ActiveRecord::Base
end
def send_email
Notifier.notify(self).deliver
if self.recipient.send_notification_email
Notifier.notify(self).deliver
end
end
end

View File

@@ -0,0 +1,5 @@
class AddSendEmailToMember < ActiveRecord::Migration
def change
add_column :members, :send_notification_email, :boolean, :default => true
end
end

View File

@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20130326092227) do
ActiveRecord::Schema.define(:version => 20130327120024) do
create_table "comments", :force => true do |t|
t.integer "post_id", :null => false
@@ -45,7 +45,7 @@ ActiveRecord::Schema.define(:version => 20130326092227) do
create_table "gardens", :force => true do |t|
t.string "name", :null => false
t.integer "owner_id"
t.integer "owner_id", :null => false
t.string "slug", :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
@@ -56,12 +56,12 @@ ActiveRecord::Schema.define(:version => 20130326092227) do
add_index "gardens", ["slug"], :name => "index_gardens_on_slug", :unique => true
create_table "members", :force => true do |t|
t.string "email", :default => "", :null => false
t.string "encrypted_password", :default => "", :null => false
t.string "email", :default => "", :null => false
t.string "encrypted_password", :default => "", :null => false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", :default => 0
t.integer "sign_in_count", :default => 0
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
@@ -70,11 +70,11 @@ ActiveRecord::Schema.define(:version => 20130326092227) do
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
t.string "unconfirmed_email"
t.integer "failed_attempts", :default => 0
t.integer "failed_attempts", :default => 0
t.string "unlock_token"
t.datetime "locked_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "login_name"
t.string "slug"
t.boolean "tos_agreement"
@@ -82,6 +82,7 @@ ActiveRecord::Schema.define(:version => 20130326092227) do
t.string "location"
t.float "latitude"
t.float "longitude"
t.boolean "send_notification_email", :default => true
end
add_index "members", ["confirmation_token"], :name => "index_users_on_confirmation_token", :unique => true
@@ -97,22 +98,14 @@ ActiveRecord::Schema.define(:version => 20130326092227) do
create_table "notifications", :force => true do |t|
t.integer "sender_id"
t.integer "recipient_id", :null => false
t.integer "recipient_id", :null => false
t.string "subject"
t.text "body"
t.boolean "read", :default => false
t.boolean "read", :default => false
t.integer "notification_type"
t.integer "post_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "payments", :force => true do |t|
t.integer "payer_id"
t.decimal "amount"
t.date "paid_period_begins"
t.date "paid_period_ends"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "plantings", :force => true do |t|

View File

@@ -72,6 +72,10 @@ FactoryGirl.define do
login_name 'abc_123'
end
factory :no_email_notifications_member do
send_notification_email false
end
end
end

View File

@@ -8,5 +8,9 @@ FactoryGirl.define do
body "MyText"
read false
post
factory :no_email_notification do
recipient { FactoryGirl.create(:no_email_notifications_member) }
end
end
end

View File

@@ -37,6 +37,12 @@ describe Notification do
ActionMailer::Base.deliveries.last.to.should == [@notification2.recipient.email]
end
it "doesn't send email to people who don't want it" do
@notification = FactoryGirl.create(:no_email_notification)
@notification.send_email
ActionMailer::Base.deliveries.last.to.should_not == [@notification.recipient.email]
end
it "sends email on creation" do
@notification2 = FactoryGirl.create(:notification)
ActionMailer::Base.deliveries.last.to.should == [@notification2.recipient.email]