0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-06 13:08:40 +08:00
discourse/plugins/discourse-reactions/spec/models/reaction_user_spec.rb
Sam cdb7094692
FIX: match ActiveRecord#reload signature in overrides (#38639)
The `reload` method overrides in `User`, `ReactionUser`, and
`Poll` did not accept an `options` parameter, diverging from
the `ActiveRecord::Base#reload(options = nil)` signature.

This caused `ArgumentError` when calling `reload(lock: true)`
or passing any other options to these models.

Update all three overrides to accept `options = nil` and add
tests to prevent future regressions.
2026-03-17 09:10:34 +11:00

47 lines
1.4 KiB
Ruby
Vendored

# frozen_string_literal: true
require_relative "../fabricators/reaction_fabricator"
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) }
it "returns nil when delegating the username method with a nil user" do
expect(reaction_user.username).to be_nil
end
it "returns nil when delegating the avatar_template method with a nil user" do
expect(reaction_user.avatar_template).to be_nil
end
end
describe "when a user gets deleted" do
it "deletes all the reactions for that user" do
user = Fabricate(:user)
reaction = Fabricate(:reaction)
post = Fabricate(:post)
user_reaction = Fabricate(:reaction_user, user: user, reaction: reaction, post: post)
user.destroy!
reaction_users = described_class.where(user_id: user.id)
expect(reaction_users).to be_empty
end
end
end