From 9082ddf455942639f02f43f7870a3f4cac347edf Mon Sep 17 00:00:00 2001 From: Albert Yi Date: Thu, 26 Jul 2018 15:28:34 -0700 Subject: [PATCH] potential fix for #3783 --- app/models/post.rb | 2 +- test/unit/post_test.rb | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/models/post.rb b/app/models/post.rb index 90ee52c6f..acbcdac99 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -542,7 +542,7 @@ class Post < ApplicationRecord end def tag_array_was - @tag_array_was ||= Tag.scan_tags(tag_string_before_last_save || tag_string_was) + @tag_array_was ||= Tag.scan_tags(tag_string_in_database.presence || tag_string_before_last_save || "") end def tags diff --git a/test/unit/post_test.rb b/test/unit/post_test.rb index 2269498e0..57c70d6f9 100644 --- a/test/unit/post_test.rb +++ b/test/unit/post_test.rb @@ -1603,6 +1603,16 @@ class PostTest < ActiveSupport::TestCase end context "Updating:" do + context "an existing post" do + setup { @post = FactoryBot.create(:post) } + + should "call Tag.increment_post_counts with the correct params" do + @post.reload + Tag.expects(:increment_post_counts).once.with(["abc"]) + @post.update(tag_string: "tag1 abc") + end + end + context "A rating unlocked post" do setup { @post = FactoryBot.create(:post) } subject { @post } @@ -1823,6 +1833,15 @@ class PostTest < ActiveSupport::TestCase assert_equal(user2.name, post.uploader_name) end + context "tag post counts" do + setup { @post = FactoryBot.build(:post) } + + should "call Tag.increment_post_counts with the correct params" do + Tag.expects(:increment_post_counts).once.with(["tag1", "tag2"]) + @post.save + end + end + should "increment the uploaders post_upload_count" do assert_difference(-> { CurrentUser.user.post_upload_count }) do post = FactoryBot.create(:post, uploader: CurrentUser.user)