Fixes #1266
This commit is contained in:
@@ -14,6 +14,7 @@ class UserPromotion
|
|||||||
validate
|
validate
|
||||||
create_transaction_log_item
|
create_transaction_log_item
|
||||||
create_user_feedback
|
create_user_feedback
|
||||||
|
create_dmail
|
||||||
|
|
||||||
user.save
|
user.save
|
||||||
end
|
end
|
||||||
@@ -46,7 +47,32 @@ private
|
|||||||
|
|
||||||
user.feedback.create(
|
user.feedback.create(
|
||||||
:category => "neutral",
|
: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
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -3,7 +3,8 @@ class UserFeedback < ActiveRecord::Base
|
|||||||
belongs_to :user
|
belongs_to :user
|
||||||
belongs_to :creator, :class_name => "User"
|
belongs_to :creator, :class_name => "User"
|
||||||
before_validation :initialize_creator, :on => :create
|
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_presence_of :user, :creator, :body, :category
|
||||||
validates_inclusion_of :category, :in => %w(positive negative neutral)
|
validates_inclusion_of :category, :in => %w(positive negative neutral)
|
||||||
validate :creator_is_gold
|
validate :creator_is_gold
|
||||||
@@ -74,8 +75,10 @@ class UserFeedback < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def create_dmail
|
def create_dmail
|
||||||
body = %{#{creator_name} created a "#{category} record":/user_feedbacks?search[user_id]=#{user_id} for your account. #{body}}
|
unless disable_dmail_notification
|
||||||
Dmail.create_split(:to_id => user_id, :title => "Your user record has been updated", :body => body)
|
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
|
end
|
||||||
|
|
||||||
def creator_is_gold
|
def creator_is_gold
|
||||||
|
|||||||
@@ -32,6 +32,12 @@ class UserTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
assert_equal("Promoted by #{CurrentUser.user.name} from Member to Gold", @user.feedback.last.body)
|
assert_equal("Promoted by #{CurrentUser.user.name} from Member to Gold", @user.feedback.last.body)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "create a dmail" do
|
||||||
|
assert_difference("Dmail.count", 2) do
|
||||||
|
@user.promote_to!(User::Levels::GOLD)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "favoriting a post" do
|
context "favoriting a post" do
|
||||||
|
|||||||
Reference in New Issue
Block a user