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

Fix specs

Oliver Günther320ceaf67052
diff --git a/spec/factories/notification_factory.rb b/spec/factories/notification_factory.rb
index 0b2164539c4..70e310cdee7 100644
--- a/spec/factories/notification_factory.rb
+++ b/spec/factories/notification_factory.rb
@@ -3,6 +3,7 @@ FactoryBot.define do
subject { "MyText" } # rubocop:disable RSpec/EmptyLineAfterSubject
read_ian { false }
mail_reminder_sent { false }
+ alert_reminder_sent { false }
reason { :mentioned }
recipient factory: :user
project { association :project }
diff --git a/spec/lib/api/v3/user_preferences/user_preference_representer_rendering_spec.rb b/spec/lib/api/v3/user_preferences/user_preference_representer_rendering_spec.rb
index 5cd3ecb8b7b..d380f80df81 100644
--- a/spec/lib/api/v3/user_preferences/user_preference_representer_rendering_spec.rb
+++ b/spec/lib/api/v3/user_preferences/user_preference_representer_rendering_spec.rb
@@ -52,18 +52,18 @@ describe ::API::V3::UserPreferences::UserPreferenceRepresenter,
subject(:generated) { representer.to_json }
- it { is_expected.to have_json_path('hideMail') }
- it { is_expected.to have_json_path('timeZone') }
- it { is_expected.to have_json_path('commentSortDescending') }
- it { is_expected.to have_json_path('warnOnLeavingUnsaved') }
- it { is_expected.to have_json_path('autoHidePopups') }
+ it { expect(subject).to have_json_path('hideMail') }
+ it { expect(subject).to have_json_path('timeZone') }
+ it { expect(subject).to have_json_path('commentSortDescending') }
+ it { expect(subject).to have_json_path('warnOnLeavingUnsaved') }
+ it { expect(subject).to have_json_path('autoHidePopups') }
describe 'timeZone' do
context 'no time zone set' do
let(:preference) { FactoryBot.build(:user_preference, time_zone: '') }
it 'shows the timeZone as nil' do
- is_expected.to be_json_eql(nil.to_json).at_path('timeZone')
+ expect(subject).to be_json_eql(nil.to_json).at_path('timeZone')
end
end
@@ -71,7 +71,7 @@ describe ::API::V3::UserPreferences::UserPreferenceRepresenter,
let(:preference) { FactoryBot.build(:user_preference, time_zone: 'Berlin') }
it 'shows the canonical time zone' do
- is_expected.to be_json_eql('Europe/Berlin'.to_json).at_path('timeZone')
+ expect(subject).to be_json_eql('Europe/Berlin'.to_json).at_path('timeZone')
end
end
@@ -79,20 +79,21 @@ describe ::API::V3::UserPreferences::UserPreferenceRepresenter,
let(:preference) { FactoryBot.build(:user_preference, time_zone: 'Europe/Paris') }
it 'shows the canonical time zone' do
- is_expected.to be_json_eql('Europe/Paris'.to_json).at_path('timeZone')
+ expect(subject).to be_json_eql('Europe/Paris'.to_json).at_path('timeZone')
end
end
end
describe 'notification_settings' do
it 'renders them as a nested array' do
- is_expected.to have_json_type(Array).at_path('notifications')
- is_expected.to be_json_eql(notification_setting.channel.to_json).at_path('notifications/0/channel')
- is_expected.to be_json_eql(nil.to_json).at_path('notifications/0/_links/project/href')
- is_expected.to be_json_eql(notification_setting.watched.to_json).at_path('notifications/0/watched')
- is_expected.to be_json_eql(notification_setting.involved.to_json).at_path('notifications/0/involved')
- is_expected.to be_json_eql(notification_setting.mentioned.to_json).at_path('notifications/0/mentioned')
- is_expected.to be_json_eql(notification_setting.all.to_json).at_path('notifications/0/all')
+ expect(subject).to have_json_type(Array).at_path('notifications')
+ expect(subject).to be_json_eql(nil.to_json).at_path('notifications/0/_links/project/href')
+
+ NotificationSetting.all_settings.each do |key|
+ expect(subject)
+ .to be_json_eql(notification_setting.send(key).to_json)
+ .at_path("notifications/0/#{key.to_s.camelize(:lower)}")
+ end
end
end
@@ -134,7 +135,7 @@ describe ::API::V3::UserPreferences::UserPreferenceRepresenter,
end
it 'is a patch link' do
- is_expected.to be_json_eql('patch'.to_json).at_path('_links/updateImmediately/method')
+ expect(subject).to be_json_eql('patch'.to_json).at_path('_links/updateImmediately/method')
end
end
end
diff --git a/spec/models/notifications/scopes/unsent_reminders_before_spec.rb b/spec/models/notifications/scopes/unsent_reminders_before_spec.rb
index c4bbe9c5b63..ffd975f862f 100644
--- a/spec/models/notifications/scopes/unsent_reminders_before_spec.rb
+++ b/spec/models/notifications/scopes/unsent_reminders_before_spec.rb
@@ -42,6 +42,7 @@ describe Notifications::Scopes::UnsentRemindersBefore, type: :model do
let(:notification) do
FactoryBot.create(:notification,
recipient: notification_recipient,
+ read_ian: notification_read_ian,
mail_reminder_sent: notification_mail_reminder_sent,
created_at: notification_created_at)
end
diff --git a/spec/models/users/scopes/having_reminder_mail_to_send_spec.rb b/spec/models/users/scopes/having_reminder_mail_to_send_spec.rb
index c04d8052ef8..abf0eb29e90 100644
--- a/spec/models/users/scopes/having_reminder_mail_to_send_spec.rb
+++ b/spec/models/users/scopes/having_reminder_mail_to_send_spec.rb
@@ -321,7 +321,7 @@ describe User, '.having_reminder_mail_to_send', type: :model do
context 'for a user whose local time is matching the configured time but with an already read notification (reminder)' do
let(:notifications) do
- FactoryBot.create(:notification, recipient: paris_user, created_at: 5.minutes.ago, read_mail_digest: true)
+ FactoryBot.create(:notification, recipient: paris_user, created_at: 5.minutes.ago, mail_reminder_sent: true)
end
it 'is empty' do
diff --git a/spec/services/notifications/create_from_model_service_comment_spec.rb b/spec/services/notifications/create_from_model_service_comment_spec.rb
index afca64d0191..663c8b0b1ba 100644
--- a/spec/services/notifications/create_from_model_service_comment_spec.rb
+++ b/spec/services/notifications/create_from_model_service_comment_spec.rb
@@ -66,9 +66,9 @@ describe Notifications::CreateFromModelService, 'comment', with_settings: { jour
it_behaves_like 'creates notification' do
let(:notification_channel_reasons) do
{
- read_ian: nil,
- reason: false,
- mail_reminder_sent: nil
+ read_ian: false,
+ reason: :subscribed,
+ mail_reminder_sent: false
}
end
end
@@ -108,10 +108,9 @@ describe Notifications::CreateFromModelService, 'comment', with_settings: { jour
it_behaves_like 'creates notification' do
let(:notification_channel_reasons) do
{
- read_ian: nil,
- reason: false,
- read_mail: false,
- mail_reminder_sent: nil
+ read_ian: false,
+ reason: :watched,
+ mail_reminder_sent: false
}
end
end
diff --git a/spec/services/notifications/create_from_model_service_news_spec.rb b/spec/services/notifications/create_from_model_service_news_spec.rb
index b37b321c451..c77c23bb190 100644
--- a/spec/services/notifications/create_from_model_service_news_spec.rb
+++ b/spec/services/notifications/create_from_model_service_news_spec.rb
@@ -59,9 +59,9 @@ describe Notifications::CreateFromModelService, 'news', with_settings: { journal
it_behaves_like 'creates notification' do
let(:notification_channel_reasons) do
{
- read_ian: nil,
- reason: false,
- mail_reminder_sent: nil
+ read_ian: false,
+ reason: :subscribed,
+ mail_reminder_sent: false
}
end
end
diff --git a/spec/services/notifications/create_from_model_service_work_package_spec.rb b/spec/services/notifications/create_from_model_service_work_package_spec.rb
index 4361805b3d5..0ae9cfced59 100644
--- a/spec/services/notifications/create_from_model_service_work_package_spec.rb
+++ b/spec/services/notifications/create_from_model_service_work_package_spec.rb
@@ -129,8 +129,8 @@ describe Notifications::CreateFromModelService,
it_behaves_like 'creates notification' do
let(:notification_channel_reasons) do
{
- read_ian: nil,
- reason: nil,
+ read_ian: false,
+ reason: :assigned,
mail_reminder_sent: false
}
end
@@ -235,7 +235,7 @@ describe Notifications::CreateFromModelService,
it_behaves_like 'creates notification' do
let(:notification_channel_reasons) do
{
- read_ian: nil,
+ read_ian: false,
reason: nil,
mail_reminder_sent: false
}
@@ -323,8 +323,8 @@ describe Notifications::CreateFromModelService,
it_behaves_like 'creates notification' do
let(:notification_channel_reasons) do
{
- read_ian: nil,
- reason: nil,
+ read_ian: false,
+ reason: :watched,
mail_reminder_sent: false
}
end
@@ -390,7 +390,7 @@ describe Notifications::CreateFromModelService,
let(:notification_channel_reasons) do
{
read_ian: false,
- reason: :subscribed,
+ reason: :created,
mail_reminder_sent: false
}
end
@@ -406,8 +406,8 @@ describe Notifications::CreateFromModelService,
it_behaves_like 'creates notification' do
let(:notification_channel_reasons) do
{
- read_ian: nil,
- reason: nil,
+ read_ian: false,
+ reason: :created,
mail_reminder_sent: false
}
end
@@ -454,7 +454,7 @@ describe Notifications::CreateFromModelService,
let(:notification_channel_reasons) do
{
read_ian: false,
- reason: :subscribed,
+ reason: :created,
mail_reminder_sent: false
}
end
@@ -703,7 +703,6 @@ describe Notifications::CreateFromModelService,
{
read_ian: false,
reason: :scheduled,
- read_mail: false,
mail_reminder_sent: false
}
end
diff --git a/spec/services/notifications/create_service_intergration_spec.rb b/spec/services/notifications/create_service_intergration_spec.rb
index bf3274b9e05..3f1449b846a 100644
--- a/spec/services/notifications/create_service_intergration_spec.rb
+++ b/spec/services/notifications/create_service_intergration_spec.rb
@@ -52,9 +52,9 @@ describe Notifications::CreateService, 'integration', type: :model do
journal: journal,
actor: actor,
read_ian: false,
- reason_ian: :mentioned,
- read_mail: nil,
- read_mail_digest: nil
+ reason: :mentioned,
+ mail_reminder_sent: nil,
+ mail_alert_sent: nil
}
end
diff --git a/spec/services/user_preferences/update_service_integration_spec.rb b/spec/services/user_preferences/update_service_integration_spec.rb
index ede42f39d22..d2f917aba91 100644
--- a/spec/services/user_preferences/update_service_integration_spec.rb
+++ b/spec/services/user_preferences/update_service_integration_spec.rb
@@ -59,8 +59,6 @@ describe UserPreferences::UpdateService, 'integration', type: :model do
notification_settings: [
{
project_id: nil,
- channel: 'in_app',
- all: false,
watched: false,
involved: true,
work_package_commented: false,
@@ -74,8 +72,7 @@ describe UserPreferences::UpdateService, 'integration', type: :model do
end
it 'updates the existing one, removes the email one' do
- default_mail = current_user.notification_settings.find_by(channel: 'mail')
- default_ian = current_user.notification_settings.find_by(channel: 'in_app')
+ default_ian = current_user.notification_settings.first
expect(default_ian.watched).to eq true
expect(default_ian.mentioned).to eq true
@@ -88,8 +85,6 @@ describe UserPreferences::UpdateService, 'integration', type: :model do
expect(subject.count).to eq 1
expect(subject.first.project_id).to eq nil
- expect(subject.first.channel).to eq 'in_app'
- expect(subject.first.all).to eq false
expect(subject.first.mentioned).to eq false
expect(subject.first.watched).to eq false
expect(subject.first.involved).to eq true
@@ -101,7 +96,7 @@ describe UserPreferences::UpdateService, 'integration', type: :model do
expect(subject.first).to eq(default_ian.reload)
expect(current_user.notification_settings.count).to eq(1)
- expect { default_mail.reload }.to raise_error(ActiveRecord::RecordNotFound)
+ expect { default_ian.reload }.not_to raise_error(ActiveRecord::RecordNotFound)
end
end
@@ -110,32 +105,26 @@ describe UserPreferences::UpdateService, 'integration', type: :model do
let(:attributes) do
{
notification_settings: [
- { project_id: project.id, channel: 'in_app', all: true }
+ { project_id: project.id, mentioned: true }
]
}
end
it 'inserts the setting, removing the old one' do
default = current_user.notification_settings.to_a
- expect(default.count).to eq 3
+ expect(default.count).to eq 1
expect(subject.count).to eq 1
expect(subject.first.project_id).to eq project.id
- expect(subject.first.channel).to eq 'in_app'
- expect(subject.first.all).to eq true
- expect(subject.first.mentioned).to eq false
- expect(subject.first.watched).to eq false
- expect(subject.first.involved).to eq false
- expect(subject.first.work_package_commented).to eq false
- expect(subject.first.work_package_created).to eq false
- expect(subject.first.work_package_processed).to eq false
- expect(subject.first.work_package_prioritized).to eq false
- expect(subject.first.work_package_scheduled).to eq false
+
+ NotificationSetting.all_settings.each do |key|
+ val = subject.first.send key
+ expect(val).to eq(key == :mentioned)
+ end
expect(current_user.notification_settings.count).to eq(1)
expect { default.first.reload }.to raise_error(ActiveRecord::RecordNotFound)
- expect { default.second.reload }.to raise_error(ActiveRecord::RecordNotFound)
end
end
end