Skip to content

A platform for community discussion. Free, open, simple.

FIX: match ActiveRecord#reload signature in overrides (#38639)

Samcdb709469257
diff --git a/app/models/user.rb b/app/models/user.rb
index f37294ede88..539a55fe9d0 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -636,7 +636,7 @@ class User < ActiveRecord::Base
User.email_hash(email)
end
- def reload
+ def reload(options = nil)
@unread_notifications = nil
@all_unread_notifications_count = nil
@unread_total_notifications = nil
diff --git a/plugins/discourse-reactions/app/models/discourse_reactions/reaction_user.rb b/plugins/discourse-reactions/app/models/discourse_reactions/reaction_user.rb
index 9bea7b091ba..5359c90787b 100644
--- a/plugins/discourse-reactions/app/models/discourse_reactions/reaction_user.rb
+++ b/plugins/discourse-reactions/app/models/discourse_reactions/reaction_user.rb
@@ -44,7 +44,7 @@ module DiscourseReactions
)
end
- def reload
+ def reload(options = nil)
@post_action_like = nil
super
end
diff --git a/plugins/discourse-reactions/spec/models/reaction_user_spec.rb b/plugins/discourse-reactions/spec/models/reaction_user_spec.rb
index f1c79a01829..f8a172f5ffa 100644
--- a/plugins/discourse-reactions/spec/models/reaction_user_spec.rb
+++ b/plugins/discourse-reactions/spec/models/reaction_user_spec.rb
@@ -6,6 +6,19 @@ require_relative "../fabricators/reaction_user_fabricator"
describe DiscourseReactions::ReactionUser do
before { SiteSetting.discourse_reactions_enabled = true }
+ describe "#reload" do
+ it "accepts options like ActiveRecord's reload" do
+ reaction_user =
+ Fabricate(
+ :reaction_user,
+ user: Fabricate(:user),
+ reaction: Fabricate(:reaction),
+ post: Fabricate(:post),
+ )
+ expect { reaction_user.reload(lock: true) }.not_to raise_error
+ end
+ end
+
describe "delegating methods when the user is nil" do
let(:reaction_user) { described_class.new(user: nil) }
diff --git a/plugins/poll/app/models/poll.rb b/plugins/poll/app/models/poll.rb
index 26c2fc7f508..410a073bd61 100644
--- a/plugins/poll/app/models/poll.rb
+++ b/plugins/poll/app/models/poll.rb
@@ -25,7 +25,7 @@ class Poll < ActiveRecord::Base
after_initialize { @has_voted = {} }
- def reload
+ def reload(options = nil)
@has_voted = {}
super
end
diff --git a/plugins/poll/spec/models/poll_spec.rb b/plugins/poll/spec/models/poll_spec.rb
index 1ffa24c40be..e62c1bd222b 100644
--- a/plugins/poll/spec/models/poll_spec.rb
+++ b/plugins/poll/spec/models/poll_spec.rb
@@ -1,6 +1,13 @@
# frozen_string_literal: true
RSpec.describe DiscoursePoll::Poll do
+ describe "#reload" do
+ it "accepts options like ActiveRecord's reload" do
+ poll = Fabricate(:poll)
+ expect { poll.reload(lock: true) }.not_to raise_error
+ end
+ end
+
describe ".transform_for_user_field_override" do
it "Transforms UserField name if a matching CustomUserField is present" do
user_field_name = "Something Cool"
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index 64f25f2f036..d29257edeba 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -7,6 +7,12 @@ RSpec.describe User do
it_behaves_like "it has custom fields"
+ describe "#reload" do
+ it "accepts options like ActiveRecord's reload" do
+ expect { user.reload(lock: true) }.not_to raise_error
+ end
+ end
+
def user_error_message(*keys)
I18n.t(:"activerecord.errors.models.user.attributes.#{keys.join(".")}")
end