Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Repair the stubbed user factory preference assignment logic.

Dombi Attila16f7a7eadd35
diff --git a/spec/factories/user_factory.rb b/spec/factories/user_factory.rb
index 4010ffbeb46..ece978101bc 100644
--- a/spec/factories/user_factory.rb
+++ b/spec/factories/user_factory.rb
@@ -62,7 +62,11 @@ FactoryBot.define do
callback(:after_stub) do |user, evaluator|
if evaluator.preferences.present?
- user.preference = build_stubbed(:user_preference, user:, settings: evaluator.preferences)
+ # The assign_attributes workaround is required, because assigning user.preference will trigger
+ # creating a new database record, which raises an error in the build_stubbed context
+ user.pref.assign_attributes(
+ build_stubbed(:user_preference, user:, settings: evaluator.preferences).attributes
+ )
end
end
diff --git a/spec/services/notifications/mail_service_spec.rb b/spec/services/notifications/mail_service_spec.rb
index a6e1125c325..205ab9a53da 100644
--- a/spec/services/notifications/mail_service_spec.rb
+++ b/spec/services/notifications/mail_service_spec.rb
@@ -35,12 +35,11 @@ RSpec.describe Notifications::MailService, type: :model do
let(:recipient) do
build_stubbed(:user,
- preference: build_stubbed(:user_preference,
- settings: {
- immediate_reminders: {
- mentioned: immediate_reminders_mentioned
- }
- }))
+ preferences: {
+ immediate_reminders: {
+ mentioned: immediate_reminders_mentioned
+ }
+ })
end
let(:actor) do
build_stubbed(:user)