Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix notifications where resources are missing #9183

Merged
merged 3 commits into from
Apr 29, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion decidim-core/app/cells/decidim/notification/show.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<span class="text-small"><%= notification.event_class.constantize.model_name.human %></span>
<br>
<span>
<%= notification.event_class_instance.notification_title %>
<%= notification_title %>
</span>
<% if notification.display_resource_text? %>
<p>
Expand Down
6 changes: 6 additions & 0 deletions decidim-core/app/cells/decidim/notification_cell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ def show
render :show
end

def notification_title
notification.event_class_instance.notification_title
rescue StandardError
I18n.t("decidim.notifications.show.missing_event")
end

private

def notification
Expand Down
2 changes: 2 additions & 0 deletions decidim-core/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1111,6 +1111,8 @@ en:
translated_text: 'Automatically translated text:'
notifications:
no_notifications: No notifications yet.
show:
missing_event: 'Missing event: This resource is no longer available.'
microstudi marked this conversation as resolved.
Show resolved Hide resolved
notifications_settings:
show:
administrators: Administrators
Expand Down
33 changes: 33 additions & 0 deletions decidim-core/spec/cells/decidim/notification_cell_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

require "spec_helper"

describe Decidim::NotificationCell, type: :cell do
subject { my_cell.call }

controller Decidim::PagesController
let!(:organization) { create :organization }
let(:user) { create :user, :confirmed, organization: organization }
let(:my_cell) { cell("decidim/notification", notification) }
let(:notification) { create :notification, user: user, resource: resource }
let(:component) { create(:component, manifest_name: "dummy", organization: organization) }
let(:resource) { create(:dummy_resource, component: component) }

context "when resource exists" do
it "Resource title is present" do
expect(my_cell.notification_title).to include("An event occured")
end
end

context "when resource is missing" do
before do
# rubocop:disable Rails/SkipsModelValidations:
notification.update_attribute(:decidim_resource_type, "Decidim::ParticipatoryProcessStep")
# rubocop:enable Rails/SkipsModelValidations:
end

it "Resource title is present" do
expect(my_cell.notification_title).to include("Missing event")
end
end
end