forked from decidim/decidim
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow deletion of categories when there are no resources associated (d…
…ecidim#12143) * Destroy categorization when resource is being destroyed * Add rake task and RELEASE NOTES * Fix template * Prevent destroy command to remove categories in use * Apply suggestions from code review Co-authored-by: Andrés Pereira de Lucena <[email protected]> * Update decidim-core/lib/decidim/core/test/shared_examples/has_category.rb Co-authored-by: Andrés Pereira de Lucena <[email protected]> * Running linters --------- Co-authored-by: Andrés Pereira de Lucena <[email protected]>
- Loading branch information
1 parent
d8b277e
commit a134dff
Showing
7 changed files
with
70 additions
and
5 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
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
27 changes: 27 additions & 0 deletions
27
decidim-core/lib/decidim/core/test/shared_examples/has_category.rb
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 |
---|---|---|
@@ -1,11 +1,38 @@ | ||
# frozen_string_literal: true | ||
|
||
shared_examples_for "has category" do | ||
let(:participatory_space) { subject.participatory_space } | ||
|
||
context "when the category is from another organization" do | ||
before do | ||
subject.category = create(:category) | ||
end | ||
|
||
it { is_expected.not_to be_valid } | ||
end | ||
|
||
context "when the category is from the same organization" do | ||
before do | ||
subject.category = create(:category, participatory_space:) | ||
end | ||
|
||
it { is_expected.to be_valid } | ||
end | ||
|
||
context "when the resource is being deleted" do | ||
before do | ||
subject.category = create(:category, participatory_space:) | ||
subject.save! | ||
end | ||
|
||
it "persists the categorization" do | ||
expect(subject.categorization).to be_persisted | ||
end | ||
|
||
it "deletes the categorization" do | ||
expect(Decidim::Categorization.count).to eq(1) | ||
expect { subject.destroy }.to change(Decidim::Categorization, :count).by(-1) | ||
expect(Decidim::Categorization.count).to eq(0) | ||
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
15 changes: 15 additions & 0 deletions
15
decidim-core/lib/tasks/upgrade/decidim_fix_categorization.rake
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,15 @@ | ||
# frozen_string_literal: true | ||
|
||
namespace :decidim do | ||
namespace :upgrade do | ||
desc "Remove orphan categorizations" | ||
task fix_orphan_categorizations: :environment do | ||
logger = Logger.new($stdout) | ||
logger.info("Removing orphan categorizations...") | ||
|
||
Decidim::Categorization.find_each do |categorization| | ||
categorization.destroy if categorization.categorizable.nil? | ||
end | ||
end | ||
end | ||
end |