FIX: Changing owner of small action post failed

FIX: Changing owner of small action post failed

Small action posts for invites (CC from email) have a blank raw and revising of posts with blank raw didn’t work anymore.

diff --git a/lib/post_revisor.rb b/lib/post_revisor.rb
index 90a5c2f..defefe9 100644
--- a/lib/post_revisor.rb
+++ b/lib/post_revisor.rb
@@ -121,8 +121,6 @@ class PostRevisor
 
     @topic_changes = TopicChanges.new(@topic, editor)
 
-    return false if @fields.has_key?(:raw) && @fields[:raw].blank?
-
     # some normalization
     @fields[:raw] = cleanup_whitespaces(@fields[:raw]) if @fields.has_key?(:raw)
     @fields[:user_id] = @fields[:user_id].to_i if @fields.has_key?(:user_id)
@@ -207,7 +205,7 @@ class PostRevisor
   end
 
   def cleanup_whitespaces(raw)
-    TextCleaner.normalize_whitespaces(raw).gsub(/\s+\z/, "")
+    raw.present? ? TextCleaner.normalize_whitespaces(raw).gsub(/\s+\z/, "") : ""
   end
 
   def should_revise?
diff --git a/spec/services/user_merger_spec.rb b/spec/services/user_merger_spec.rb
index 552936b..e53cb9f 100644
--- a/spec/services/user_merger_spec.rb
+++ b/spec/services/user_merger_spec.rb
@@ -36,19 +36,31 @@ describe UserMerger do
   end
 
   it "changes owner of personal messages" do
-    pm_topic = Fabricate(:private_message_topic)
+    pm_topic = Fabricate(:private_message_topic, topic_allowed_users: [
+      Fabricate.build(:topic_allowed_user, user: target_user),
+      Fabricate.build(:topic_allowed_user, user: walter),
+      Fabricate.build(:topic_allowed_user, user: source_user)
+    ])
 
     post1 = Fabricate(:post, topic: pm_topic, user: source_user)
     post2 = Fabricate(:post, topic: pm_topic, user: walter)
     post3 = Fabricate(:post, topic: pm_topic, user: target_user)
     post4 = Fabricate(:post, topic: pm_topic, user: source_user, deleted_at: Time.now)
 
+    small1 = pm_topic.add_small_action(source_user, "invited_user", "carol")
+    small2 = pm_topic.add_small_action(target_user, "invited_user", "david")
+    small3 = pm_topic.add_small_action(walter, "invited_user", "eve")
+
     merge_users!
 
     expect(post1.reload.user).to eq(target_user)
     expect(post2.reload.user).to eq(walter)
     expect(post3.reload.user).to eq(target_user)
     expect(post4.reload.user).to eq(target_user)
+
+    expect(small1.reload.user).to eq(target_user)
+    expect(small2.reload.user).to eq(target_user)
+    expect(small3.reload.user).to eq(walter)
   end
 
   it "changes owner of categories" do

GitHub sha: f8ded9ce

1 Like

This more or less reverts the changes in 4f81bb83033154bb631ed54019092789a30ac986.

@pmusaraj Do you happen to know why you completely prevented revisions when raw is blank? Unfortunately I couldn’t find an explanation for the reason of your change other than that the revise method failed when raw was nil.

1 Like

This commit has been mentioned on Discourse Meta. There might be relevant details there:

Yes, the only reason for this fix was a log error outputted when raw was blank.

2 Likes