This commit is contained in:
r888888888
2014-03-05 17:47:40 -08:00
parent 56ae78f963
commit 37d75e4a88
3 changed files with 39 additions and 4 deletions

View File

@@ -14,6 +14,7 @@ class UserPromotion
validate
create_transaction_log_item
create_user_feedback
create_dmail
user.save
end
@@ -46,7 +47,32 @@ private
user.feedback.create(
:category => "neutral",
:body => "#{body_prefix} by #{promoter.name} from #{user.level_string_was} to #{user.level_string}"
:body => "#{body_prefix} by #{promoter.name} from #{user.level_string_was} to #{user.level_string}",
:disable_dmail_notification => true
)
end
def create_dmail
if user.level >= user.level_was
create_promotion_dmail
else
create_demotion_dmail
end
end
def create_promotion_dmail
Dmail.create_split(
:to_id => user.id,
:title => "You have been promoted",
:body => "You have been promoted to a #{user.level_string} level account."
)
end
def create_demotion_dmail
Dmail.create_split(
:to_id => user.id,
:title => "You have been demoted",
:body => "You have been demoted to a #{user.level_string} level account."
)
end
end

View File

@@ -3,7 +3,8 @@ class UserFeedback < ActiveRecord::Base
belongs_to :user
belongs_to :creator, :class_name => "User"
before_validation :initialize_creator, :on => :create
attr_accessible :body, :user_id, :category, :user_name
attr_accessor :disable_dmail_notification
attr_accessible :body, :user_id, :category, :user_name, :disable_dmail_notification
validates_presence_of :user, :creator, :body, :category
validates_inclusion_of :category, :in => %w(positive negative neutral)
validate :creator_is_gold
@@ -74,8 +75,10 @@ class UserFeedback < ActiveRecord::Base
end
def create_dmail
body = %{#{creator_name} created a "#{category} record":/user_feedbacks?search[user_id]=#{user_id} for your account. #{body}}
Dmail.create_split(:to_id => user_id, :title => "Your user record has been updated", :body => body)
unless disable_dmail_notification
body = %{#{creator_name} created a "#{category} record":/user_feedbacks?search[user_id]=#{user_id} for your account. #{body}}
Dmail.create_split(:to_id => user_id, :title => "Your user record has been updated", :body => body)
end
end
def creator_is_gold

View File

@@ -32,6 +32,12 @@ class UserTest < ActiveSupport::TestCase
assert_equal("Promoted by #{CurrentUser.user.name} from Member to Gold", @user.feedback.last.body)
end
should "create a dmail" do
assert_difference("Dmail.count", 2) do
@user.promote_to!(User::Levels::GOLD)
end
end
end
context "favoriting a post" do