diff --git a/Gemfile.lock b/Gemfile.lock index 01c3ca80d..03d3ab585 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -244,7 +244,7 @@ GEM net-ssh (>= 2.6.5) net-ssh (4.2.0) newrelic_rpm (5.0.0.342) - nio4r (2.3.0) + nio4r (2.3.1) nokogiri (1.8.2) mini_portile2 (~> 2.3.0) nokogiri (1.8.2-x64-mingw32) diff --git a/app/controllers/bans_controller.rb b/app/controllers/bans_controller.rb index 2d7fad0bc..f24130339 100644 --- a/app/controllers/bans_controller.rb +++ b/app/controllers/bans_controller.rb @@ -54,6 +54,6 @@ class BansController < ApplicationController permitted_params = %i[reason duration expires_at] permitted_params += %i[user_id user_name] if context == :create - params.require(:ban).permit(permitted_params) + params.fetch(:ban, {}).permit(permitted_params) end end diff --git a/app/helpers/delayed_jobs_helper.rb b/app/helpers/delayed_jobs_helper.rb index a94f37f29..645ab5be2 100644 --- a/app/helpers/delayed_jobs_helper.rb +++ b/app/helpers/delayed_jobs_helper.rb @@ -1,7 +1,7 @@ module DelayedJobsHelper def print_name(job) case job.name - when "PostKeeperManager.check_and_update" + when "PostKeeperManager.check_and_assign" "update post tagger" when "Tag.increment_post_counts" @@ -71,7 +71,7 @@ module DelayedJobsHelper def print_handler(job) case job.name - when "PostKeeperManager.check_and_update" + when "PostKeeperManager.check_and_assign" "" when "Tag.increment_post_counts", "Tag.decrement_post_counts" diff --git a/app/logical/post_keeper_manager.rb b/app/logical/post_keeper_manager.rb index ae90680c3..0fbdcf8f8 100644 --- a/app/logical/post_keeper_manager.rb +++ b/app/logical/post_keeper_manager.rb @@ -15,6 +15,11 @@ class PostKeeperManager end def self.check_and_update(post, updater_id = nil, increment_tags = nil) + check_and_assign(post, updater_id, increment_tags) + post.update_column(:keeper_data, post.keeper_data) + end + + def self.check_and_assign(post, updater_id = nil, increment_tags = nil) post = Post.find(post) unless post.is_a?(Post) keeper_id = check(post, updater_id, increment_tags) post.keeper_data = {uid: keeper_id} diff --git a/app/models/dmail.rb b/app/models/dmail.rb index 3011f7b75..677303268 100644 --- a/app/models/dmail.rb +++ b/app/models/dmail.rb @@ -255,8 +255,8 @@ class Dmail < ApplicationRecord end def mark_as_read! + update_column(:is_read, true) owner.dmails.unread.count.tap do |unread_count| - update_column(:is_read, true) owner.update(has_mail: (unread_count > 0), unread_dmail_count: unread_count) end end diff --git a/app/models/post.rb b/app/models/post.rb index 9dc7e8739..6cd6cc405 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -564,7 +564,7 @@ class Post < ApplicationRecord if PostKeeperManager.enabled? && persisted? # no need to do this check on the initial create - PostKeeperManager.check_and_update(self, CurrentUser.id, increment_tags) + PostKeeperManager.check_and_assign(self, CurrentUser.id, increment_tags) # run this again async to check for race conditions PostKeeperManager.queue_check(self, CurrentUser.id) diff --git a/test/functional/pool_elements_controller_test.rb b/test/functional/pool_elements_controller_test.rb index e9d2d2462..39107c920 100644 --- a/test/functional/pool_elements_controller_test.rb +++ b/test/functional/pool_elements_controller_test.rb @@ -44,6 +44,7 @@ class PoolElementsControllerTest < ActionDispatch::IntegrationTest end should "do nothing if the post is not a member of the pool" do + @pool.reload as_user do @pool.remove!(@post) end diff --git a/test/models/post_keeper_manager_test.rb b/test/models/post_keeper_manager_test.rb index bfa1065e9..d07ba721b 100644 --- a/test/models/post_keeper_manager_test.rb +++ b/test/models/post_keeper_manager_test.rb @@ -3,7 +3,7 @@ require 'test_helper' class PostKeeperManagerTest < ActiveSupport::TestCase subject { PostKeeperManager } - context "#check_and_update" do + context "#check_and_assign" do setup do Timecop.travel(1.month.ago) do @alice = FactoryBot.create(:user) @@ -17,19 +17,21 @@ class PostKeeperManagerTest < ActiveSupport::TestCase end CurrentUser.scoped(@bob) do Timecop.travel(2.hours.from_now) do - @post.update_attributes(tag_string: "aaa bbb ccc") + @post.reload + @post.update(tag_string: "aaa bbb ccc") end end CurrentUser.scoped(@carol) do Timecop.travel(4.hours.from_now) do - @post.update_attributes(tag_string: "ccc ddd eee fff ggg") + @post.reload + @post.update(tag_string: "ccc ddd eee fff ggg") end end end should "update the post" do - subject.check_and_update(@post.id) - @post.reload + assert_equal(3, @post.versions.count) + subject.check_and_assign(@post) assert_equal({"uid" => @carol.id}, @post.keeper_data) end end diff --git a/test/unit/artist_test.rb b/test/unit/artist_test.rb index 85aac6243..c1e7ebf63 100644 --- a/test/unit/artist_test.rb +++ b/test/unit/artist_test.rb @@ -191,7 +191,7 @@ class ArtistTest < ActiveSupport::TestCase context "when finding deviantart artists" do setup do - skip "deviant art is not configured" unless Danbooru.config.deviantart_client_id.present? + skip "DeviantArt API keys not set" unless Danbooru.config.deviantart_client_id.present? FactoryBot.create(:artist, :name => "artgerm", :url_string => "http://artgerm.deviantart.com/") FactoryBot.create(:artist, :name => "trixia", :url_string => "http://trixdraws.deviantart.com/") end diff --git a/test/unit/downloads/deviant_art_test.rb b/test/unit/downloads/deviant_art_test.rb index 7cb58c5bd..729f947dd 100644 --- a/test/unit/downloads/deviant_art_test.rb +++ b/test/unit/downloads/deviant_art_test.rb @@ -4,6 +4,8 @@ module Downloads class DeviantArtTest < ActiveSupport::TestCase context "a download for a deviant art html page" do setup do + skip "DeviantArt API keys not set" unless Danbooru.config.deviantart_client_id.present? + @source = "http://starbitt.deviantart.com/art/09271X-636962118" @download = Downloads::File.new(@source) @tempfile = @download.download! diff --git a/test/unit/moderator/ip_addr_search_test.rb b/test/unit/moderator/ip_addr_search_test.rb index 28b3b3aaf..bb1626e7a 100644 --- a/test/unit/moderator/ip_addr_search_test.rb +++ b/test/unit/moderator/ip_addr_search_test.rb @@ -11,6 +11,7 @@ module Moderator @comment = FactoryBot.create(:comment) PoolArchive.stubs(:enabled?).returns(false) PostArchive.stubs(:enabled?).returns(false) + @user.reload end teardown do diff --git a/test/unit/pool_test.rb b/test/unit/pool_test.rb index fddf0f8d7..5dd24cb06 100644 --- a/test/unit/pool_test.rb +++ b/test/unit/pool_test.rb @@ -73,19 +73,24 @@ class PoolTest < ActiveSupport::TestCase @p3 = FactoryBot.create(:post) CurrentUser.scoped(@user, "1.2.3.4") do @pool.add!(@p1) + @pool.reload end CurrentUser.scoped(@user, "1.2.3.5") do @pool.add!(@p2) + @pool.reload end CurrentUser.scoped(@user, "1.2.3.6") do @pool.add!(@p3) + @pool.reload end CurrentUser.scoped(@user, "1.2.3.7") do @pool.remove!(@p1) + @pool.reload end CurrentUser.scoped(@user, "1.2.3.8") do version = @pool.versions[1] @pool.revert_to!(version) + @pool.reload end end diff --git a/test/unit/sources/deviantart_test.rb b/test/unit/sources/deviantart_test.rb index c5c1a4e66..facb50834 100644 --- a/test/unit/sources/deviantart_test.rb +++ b/test/unit/sources/deviantart_test.rb @@ -2,6 +2,11 @@ require 'test_helper' module Sources class DeviantArtTest < ActiveSupport::TestCase + def setup + super + skip "DeviantArt API keys not set" unless Danbooru.config.deviantart_client_id.present? + end + context "The source for a private DeviantArt image URL" do setup do @site = Sources::Site.new("https://pre00.deviantart.net/423b/th/pre/i/2017/281/e/0/mindflayer_girl01_by_nickbeja-dbpxdt8.png")