Fix personalization (#11)

Fix personalization (#11)

  • Fix personalization

  • Add first and last name personalization

  • Add and change tests

Added tests for first and last name personalization, as well as changed all related tests to check for a message to the second user, which assures that not all users are receiving the same message.

  • Remove first and last name personalization

  • Remove hash cloning

  • Fix spacing

  • Remove spaces

Didn’t realize what the check was looking for originally.

diff --git a/app/jobs/bcc_post.rb b/app/jobs/bcc_post.rb
index 8f0a5fc..2ff5d74 100644
--- a/app/jobs/bcc_post.rb
+++ b/app/jobs/bcc_post.rb
@@ -21,14 +21,15 @@ class ::Jobs::BccPost < ::Jobs::Base
 
   def send_to(targets, targets_key, params, sender)
     targets.each do |target|
-      temp_params = params
-      temp_params["raw"] = temp_params["raw"].gsub(/%{username}/i, target)
-      temp_params["raw"] = temp_params["raw"].gsub(/%{@username}/i, "@" + target)
+      raw = params["raw"].gsub(/%{username}/i, target)
+      raw.gsub!(/%{@username}/i, "@" + target)
+
       user = User.find_by_username_or_email(target)
       if !user.nil? then
-        temp_params["raw"] = temp_params["raw"].gsub(/%{name}/i, user.name)
+        raw.gsub!(/%{name}/i, user.name)
       end
-      creator = PostCreator.new(sender, temp_params.merge(Hash[targets_key, target]))
+
+      creator = PostCreator.new(sender, params.merge(Hash[targets_key, target], raw: raw))
       creator.create
     end
   end
diff --git a/spec/jobs/bcc_post_spec.rb b/spec/jobs/bcc_post_spec.rb
index 5ee8a5e..b5ea971 100644
--- a/spec/jobs/bcc_post_spec.rb
+++ b/spec/jobs/bcc_post_spec.rb
@@ -59,23 +59,24 @@ describe ::Jobs::BccPost do
 
     it 'works with standard personalization' do
       ::Jobs::BccPost.new.execute(user_id: sender.id, create_params: create_params.merge("raw": "this is the content I want to send to %{username}", target_emails: 'test@test.com'))
-      post = Post.find_by(raw: "this is the content I want to send to #{user0.username}")
+      post = Post.find_by(raw: "this is the content I want to send to #{user1.username}")
 
       expect(post).to_not be_nil
     end
 
     it 'works with mention personalization' do
       ::Jobs::BccPost.new.execute(user_id: sender.id, create_params: create_params.merge("raw": "this is the content I want to send to %{@username}", target_emails: 'test@test.com'))
-      post = Post.find_by(raw: "this is the content I want to send to @#{user0.username}")
+      post = Post.find_by(raw: "this is the content I want to send to @#{user1.username}")
 
       expect(post).to_not be_nil
     end
 
     it 'works with name personalization' do
       ::Jobs::BccPost.new.execute(user_id: sender.id, create_params: create_params.merge("raw": "this is the content I want to send to %{name}", target_emails: 'test@test.com'))
-      post = Post.find_by(raw: "this is the content I want to send to #{user0.name}")
+      post = Post.find_by(raw: "this is the content I want to send to #{user1.name}")
 
       expect(post).to_not be_nil
     end
+
   end
 end

GitHub sha: 74442fde

This commit appears in #11 which was approved by eviltrout. It was merged by eviltrout.