Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions app/jobs/decidim/initiatives/check_published_initiatives.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

module Decidim
module Initiatives
class CheckPublishedInitiatives < ApplicationJob
queue_as :initiatives

def perform
system "rake decidim_initiatives:check_published"
end
end
end
end
13 changes: 13 additions & 0 deletions app/jobs/decidim/initiatives/check_validating_initiatives.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

module Decidim
module Initiatives
class CheckValidatingInitiatives < ApplicationJob
queue_as :initiatives

def perform
system "rake decidim_initiatives:check_validating"
end
end
end
end
13 changes: 13 additions & 0 deletions app/jobs/decidim/initiatives/notify_progress_initiatives.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

module Decidim
module Initiatives
class NotifyProgressInitiatives < ApplicationJob
queue_as :initiatives

def perform
system "rake decidim_initiatives:notify_progress"
end
end
end
end
12 changes: 12 additions & 0 deletions config/sidekiq.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@
cron: "*/15 * * * *"
class: Decidim::ParticipatoryProcesses::ChangeActiveStepJob
queue: scheduled
CheckPublishedInitiatives:
cron: '0 1 * * *'
class: Decidim::Initiatives::CheckPublishedInitiatives
queue: initiatives
CheckValidatingInitiatives:
cron: '0 1 * * *'
class: Decidim::Initiatives::CheckValidatingInitiatives
queue: initiatives
NotifyProgressInitiatives:
cron: '0 1 * * *'
class: Decidim::Initiatives::NotifyProgressInitiatives
queue: initiatives

# Decidim-AI Spam Digest Jobs
AiSpamDigestDaily:
Expand Down
34 changes: 34 additions & 0 deletions spec/jobs/check_published_initatives_job_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# frozen_string_literal: true

require "spec_helper"

module Decidim
module Initiatives
describe CheckPublishedInitiatives do
subject { described_class }

describe "queue" do
it "is queued to initiatives" do
expect(subject.queue_name).to eq "initiatives"
end
end

describe "#perform" do
it "enqueues a job with perform_later" do
expect do
described_class.perform_later
end.to have_enqueued_job(described_class)
end

it "runs the check_published rake task" do
job = described_class.new
allow(job).to receive(:system)

job.perform

expect(job).to have_received(:system).with("rake decidim_initiatives:check_published")
end
end
end
end
end
34 changes: 34 additions & 0 deletions spec/jobs/check_validating_initatives_job_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# frozen_string_literal: true

require "spec_helper"

module Decidim
module Initiatives
describe CheckValidatingInitiatives do
subject { described_class }

describe "queue" do
it "is queued to initiatives" do
expect(subject.queue_name).to eq "initiatives"
end
end

describe "#perform" do
it "enqueues a job with perform_later" do
expect do
described_class.perform_later
end.to have_enqueued_job(described_class)
end

it "runs the check_validating rake task" do
job = described_class.new
allow(job).to receive(:system)

job.perform

expect(job).to have_received(:system).with("rake decidim_initiatives:check_validating")
end
end
end
end
end
34 changes: 34 additions & 0 deletions spec/jobs/notify_progress_initatives_job_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# frozen_string_literal: true

require "spec_helper"

module Decidim
module Initiatives
describe NotifyProgressInitiatives do
subject { described_class }

describe "queue" do
it "is queued to initiatives" do
expect(subject.queue_name).to eq "initiatives"
end
end

describe "#perform" do
it "enqueues a job with perform_later" do
expect do
described_class.perform_later
end.to have_enqueued_job(described_class)
end

it "runs the notify_progress rake task" do
job = described_class.new
allow(job).to receive(:system)

job.perform

expect(job).to have_received(:system).with("rake decidim_initiatives:notify_progress")
end
end
end
end
end
78 changes: 78 additions & 0 deletions spec/tasks/decidim_initiatives_tasks_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# frozen_string_literal: true

require "spec_helper"

describe "decidim_initiatives:check_published", type: :task do
let(:organization) { create(:organization) }
let(:initiative_type) { create(:initiatives_type, organization:) }
let(:initiative_type_scope) { create(:initiatives_type_scope, type: initiative_type) }

context "when the signing period has ended" do
context "when the initiative has NOT reached the signature threshold" do
let!(:initiative) do
create(
:initiative,
:published,
:rejectable,
organization:,
scoped_type: initiative_type_scope,
signature_end_date: 1.day.ago
)
end

it "moves the initiative to rejected state" do
expect { task.execute }.to change { initiative.reload.state }.from("published").to("rejected")
end
end

context "when the initiative HAS reached the signature threshold" do
let!(:initiative) do
create(
:initiative,
:published,
:acceptable,
organization:,
scoped_type: initiative_type_scope,
signature_end_date: 1.day.ago
)
end

it "moves the initiative to accepted state" do
expect { task.execute }.to change { initiative.reload.state }.from("published").to("accepted")
end
end
end

context "when the signing period is still active" do
let!(:initiative) do
create(
:initiative,
:published,
:rejectable,
organization:,
scoped_type: initiative_type_scope,
signature_end_date: 1.day.from_now
)
end

it "does not change the initiative state" do
expect { task.execute }.not_to(change { initiative.reload.state })
end
end

context "when the initiative is not in published state" do
let!(:initiative) do
create(
:initiative,
:created,
organization:,
scoped_type: initiative_type_scope,
signature_end_date: 1.day.ago
)
end

it "does not change the initiative state" do
expect { task.execute }.not_to(change { initiative.reload.state })
end
end
end
Loading