* Remove reactions to a user when deleting the user Fixes #15245 --- I have no idea why `create(:vomit_reaction, reactable: user)` gave a validation error about category being invalid, but `build().save` worked fine. * Move relation details to reaction scope `for_user` Add a user method to access this by passing self to reaction scope * Create a moderator when flagging user in factory This might be a missing requirement in the reactions factory - but this suppresses an error about invalid category I was getting when setting a privileged reaction on the user via create(:vomit_reaction, reactable: user) Everywhere else it looks like we do this with `user: moderator` (where there's a trusted user in the surrounding context). * Move trusted user requirement into vomit_reaction factory * Add a data update script to remove reactions to deleted users This cleans up the remaining invalid references and should make the change in #15249 obsolete (i.e. we don't need to limit the view to exclude items that no longer exist).
37 lines
809 B
Ruby
37 lines
809 B
Ruby
FactoryBot.define do
|
|
factory :reaction do
|
|
user
|
|
association :reactable, factory: :article
|
|
category { "like" }
|
|
end
|
|
|
|
factory :reading_reaction, class: "Reaction" do
|
|
user
|
|
association :reactable, factory: :article
|
|
category { "readinglist" }
|
|
end
|
|
|
|
factory :thumbsdown_reaction, class: "Reaction" do
|
|
user
|
|
association :reactable, factory: :article
|
|
category { "thumbsdown" }
|
|
|
|
trait :user do
|
|
association :reactable, factory: :user
|
|
end
|
|
end
|
|
|
|
factory :vomit_reaction, class: "Reaction" do
|
|
user { create(:user, :trusted) }
|
|
association :reactable, factory: :article
|
|
category { "vomit" }
|
|
|
|
trait :user do
|
|
association :reactable, factory: :user
|
|
end
|
|
|
|
trait :comment do
|
|
association :reactable, factory: :comment
|
|
end
|
|
end
|
|
end
|