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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix user profile timeline activity cards texts showing "New resource" on updates #7558

Merged
merged 1 commit into from
Mar 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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/activity/show.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="card card--activity">
<div class="card card--activity" id="<%= element_id %>">
<div class="card__content">
<div class="card__text">
<div class="text-medium">
Expand Down
6 changes: 6 additions & 0 deletions decidim-core/app/cells/decidim/activity_cell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ def user
model.user_lazy if resource.respond_to?(:user)
end

delegate :action, to: :model

def element_id
"action-#{model.id}"
end

private

def published?
Expand Down
18 changes: 13 additions & 5 deletions decidim-debates/app/cells/decidim/debates/debate_activity_cell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@

module Decidim
module Debates
# A cell to display when Debate has been created.
# A cell to display when actions happen on a debate.
class DebateActivityCell < ActivityCell
def title
I18n.t(
"decidim.debates.last_activity.new_debate_at_html",
link: participatory_space_link
)
case action
when "update"
I18n.t(
"decidim.debates.last_activity.debate_updated_at_html",
link: participatory_space_link
)
else
I18n.t(
"decidim.debates.last_activity.new_debate_at_html",
link: participatory_space_link
)
end
end

def resource_link_text
Expand Down
1 change: 1 addition & 0 deletions decidim-debates/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ en:
versions_list:
back_to_resource: Go back to debate
last_activity:
debate_updated_at_html: "<span>Debate updated at %{link}</span>"
new_debate_at_html: "<span>New debate at %{link}</span>"
models:
debate:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# frozen_string_literal: true

require "spec_helper"

module Decidim
module Debates
describe DebateActivityCell, type: :cell do
controller Decidim::LastActivitiesController

let!(:debate) { create(:debate) }
let(:action) { :publish }
let(:action_log) do
create(
:action_log,
action: action,
resource: debate,
organization: debate.organization,
component: debate.component,
participatory_space: debate.participatory_space
)
end

context "when rendering" do
it "renders the card" do
html = cell("decidim/debates/debate_activity", action_log).call
expect(html).to have_css("#action-#{action_log.id} .card__content")
end

context "when action is update" do
let(:action) { :update }

it "renders the correct title" do
html = cell("decidim/debates/debate_activity", action_log).call
expect(html).to have_css("#action-#{action_log.id} .card__content")
expect(html).to have_content("Debate updated")
end
end

context "when action is create" do
let(:action) { :create }

it "renders the correct title" do
html = cell("decidim/debates/debate_activity", action_log).call
expect(html).to have_css("#action-#{action_log.id} .card__content")
expect(html).to have_content("New debate")
end
end

context "when action is publish" do
it "renders the correct title" do
html = cell("decidim/debates/debate_activity", action_log).call
expect(html).to have_css("#action-#{action_log.id} .card__content")
expect(html).to have_content("New debate")
end
end
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@

module Decidim
module Meetings
# A cell to display when a meeting has been created.
# A cell to display when actions happen on a meeting.
class MeetingActivityCell < ActivityCell
def title
I18n.t(
"decidim.meetings.last_activity.new_meeting_at_html",
link: participatory_space_link
)
case action
when "update"
I18n.t(
"decidim.meetings.last_activity.meeting_updated_at_html",
link: participatory_space_link
)
else
I18n.t(
"decidim.meetings.last_activity.new_meeting_at_html",
link: participatory_space_link
)
end
end

def resource_link_text
Expand Down
1 change: 1 addition & 0 deletions decidim-meetings/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ en:
space_type: Participatory space
upcoming: Upcoming
last_activity:
meeting_updated_at_html: "<span>Meeting updated at %{link}</span>"
new_meeting_at_html: "<span>New meeting at %{link}</span>"
mailer:
invite_join_meeting_mailer:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# frozen_string_literal: true

require "spec_helper"

module Decidim
module Meetings
describe MeetingActivityCell, type: :cell do
controller Decidim::LastActivitiesController

let!(:meeting) { create(:meeting) }
let(:action) { :publish }
let(:action_log) do
create(
:action_log,
action: action,
resource: meeting,
organization: meeting.organization,
component: meeting.component,
participatory_space: meeting.participatory_space
)
end

context "when rendering" do
it "renders the card" do
html = cell("decidim/meetings/meeting_activity", action_log).call
expect(html).to have_css("#action-#{action_log.id} .card__content")
end

context "when action is update" do
let(:action) { :update }

it "renders the correct title" do
html = cell("decidim/meetings/meeting_activity", action_log).call
expect(html).to have_css("#action-#{action_log.id} .card__content")
expect(html).to have_content("Meeting updated")
end
end

context "when action is create" do
let(:action) { :create }

it "renders the correct title" do
html = cell("decidim/meetings/meeting_activity", action_log).call
expect(html).to have_css("#action-#{action_log.id} .card__content")
expect(html).to have_content("New meeting")
end
end

context "when action is publish" do
it "renders the correct title" do
html = cell("decidim/meetings/meeting_activity", action_log).call
expect(html).to have_css("#action-#{action_log.id} .card__content")
expect(html).to have_content("New meeting")
end
end
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@

module Decidim
module Proposals
# A cell to display when a proposal has been published.
# A cell to display when actions happen on a proposal.
class ProposalActivityCell < ActivityCell
def title
I18n.t(
"decidim.proposals.last_activity.new_proposal_at_html",
link: participatory_space_link
)
case action
when "update"
I18n.t(
"decidim.proposals.last_activity.proposal_updated_at_html",
link: participatory_space_link
)
else
I18n.t(
"decidim.proposals.last_activity.new_proposal_at_html",
link: participatory_space_link
)
end
end

def resource_link_text
Expand Down
1 change: 1 addition & 0 deletions decidim-proposals/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,7 @@ en:
success: Proposal draft was successfully deleted.
last_activity:
new_proposal_at_html: "<span>New proposal at %{link}</span>"
proposal_updated_at_html: "<span>Proposal updated at %{link}</span>"
models:
collaborative_draft:
fields:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ module Proposals

let!(:proposal) { create(:proposal) }
let(:hashtag) { create(:hashtag, name: "myhashtag") }
let(:action) { :publish }
let(:action_log) do
create(
:action_log,
action: action,
resource: proposal,
organization: proposal.organization,
component: proposal.component,
Expand All @@ -22,8 +24,35 @@ module Proposals
context "when rendering" do
it "renders the card" do
html = cell("decidim/proposals/proposal_activity", action_log).call
expect(html).to have_css(".card__content")
expect(html).to have_content("New proposal")
expect(html).to have_css("#action-#{action_log.id} .card__content")
end

context "when action is update" do
let(:action) { :update }

it "renders the correct title" do
html = cell("decidim/proposals/proposal_activity", action_log).call
expect(html).to have_css("#action-#{action_log.id} .card__content")
expect(html).to have_content("Proposal updated")
end
end

context "when action is create" do
let(:action) { :create }

it "renders the correct title" do
html = cell("decidim/proposals/proposal_activity", action_log).call
expect(html).to have_css("#action-#{action_log.id} .card__content")
expect(html).to have_content("New proposal")
end
end

context "when action is publish" do
it "renders the correct title" do
html = cell("decidim/proposals/proposal_activity", action_log).call
expect(html).to have_css("#action-#{action_log.id} .card__content")
expect(html).to have_content("New proposal")
end
end

context "when the proposal has a hashtags" do
Expand Down