Skip to content

Commit

Permalink
Fix notifications where resources are missing (#9183)
Browse files Browse the repository at this point in the history
* fix notifications where resources are missing

* Update decidim-core/config/locales/en.yml

Co-authored-by: Andrés Pereira de Lucena <andreslucena@users.noreply.github.com>

* Update notification_cell_spec.rb

Co-authored-by: Andrés Pereira de Lucena <andreslucena@users.noreply.github.com>
  • Loading branch information
microstudi and andreslucena committed May 6, 2022
1 parent 9fa85fe commit 4b942aa
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
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 @@ -1092,6 +1092,8 @@ en:
translated_text: 'Automatically translated text:'
notifications:
no_notifications: No notifications yet.
show:
missing_event: Oops, this notification belongs to an item that is no longer available. You can discard it.
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("this notification belongs to an item that is no longer available")
end
end
end

0 comments on commit 4b942aa

Please sign in to comment.