-
-
Notifications
You must be signed in to change notification settings - Fork 392
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove duplication of LastActivity queries
- Loading branch information
1 parent
8d96cd8
commit 0a791de
Showing
4 changed files
with
75 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
module Decidim | ||
# This query finds the public ActionLog entries that can be shown in the | ||
# activities views of the application within a Decidim Organization. It is | ||
# intended to be used in the "Last activities" content block in the homepage, | ||
# and also in the "Last activities" page, to retrieve public activity of this | ||
# organization. | ||
class LastActivity < Decidim::Query | ||
def initialize(organization) | ||
@organization = organization | ||
end | ||
|
||
def query | ||
ActionLog | ||
.where( | ||
organization: @organization, | ||
visibility: %w(public-only all) | ||
) | ||
.with_new_resource_type("all") | ||
.order(created_at: :desc) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
describe Decidim::LastActivity do | ||
subject { query.query } | ||
|
||
let(:query) { described_class.new(organization) } | ||
let(:organization) { create(:organization) } | ||
|
||
let(:commentable) { create(:dummy_resource, component:) } | ||
let(:comment) { create(:comment, commentable:) } | ||
let!(:action_log) do | ||
create(:action_log, created_at: 1.day.ago, action: "create", visibility: "public-only", resource: comment, organization:) | ||
end | ||
|
||
let(:component) do | ||
create(:component, :published, organization:) | ||
end | ||
let(:resource) do | ||
create(:dummy_resource, component:, published_at: Time.current) | ||
end | ||
let!(:other_action_log) do | ||
create(:action_log, action: "publish", visibility: "all", resource:, organization:, participatory_space: component.participatory_space) | ||
end | ||
|
||
let(:another_comment) { create(:comment) } | ||
let!(:another_action_log) do | ||
create(:action_log, created_at: 2.days.ago, action: "create", visibility: "public-only", resource: another_comment, organization:) | ||
end | ||
|
||
before do | ||
allow(Decidim::ActionLog).to receive(:public_resource_types).and_return( | ||
%w( | ||
Decidim::Comments::Comment | ||
Decidim::DummyResources::DummyResource | ||
) | ||
) | ||
allow(Decidim::ActionLog).to receive(:publicable_public_resource_types).and_return( | ||
%w(Decidim::DummyResources::DummyResource) | ||
) | ||
end | ||
|
||
describe "#query" do | ||
it "returns the activities" do | ||
expect(subject.count).to eq(3) | ||
end | ||
end | ||
end |