From f50c177cb86e6c049e1da696c5000fcb17520805 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Verg=C3=A9s?= Date: Thu, 9 Nov 2023 12:14:44 +0100 Subject: [PATCH 01/11] generalize extra fields table for future uses --- .../proposal_m_cell_override.rb | 2 +- ..._cache.rb => has_proposal_extra_fields.rb} | 18 ++--- ...eight_cache.rb => proposal_extra_field.rb} | 4 +- .../decidim/decidim_awesome/vote_weight.rb | 16 ++-- ...41_create_decidim_awesome_weight_caches.rb | 4 +- lib/decidim/decidim_awesome/engine.rb | 2 +- lib/decidim/decidim_awesome/test/factories.rb | 2 +- .../voting/voting_cards_base_cell_spec.rb | 2 +- .../voting/voting_cards_counter_cell_spec.rb | 2 +- .../voting/voting_cards_proposal_cell_spec.rb | 2 +- spec/models/weight_cache_spec.rb | 78 +++++++++---------- spec/serializers/proposal_serializer_spec.rb | 8 +- spec/types/proposal_type_spec.rb | 2 +- 13 files changed, 71 insertions(+), 71 deletions(-) rename app/models/concerns/decidim/decidim_awesome/{has_weight_cache.rb => has_proposal_extra_fields.rb} (65%) rename app/models/decidim/decidim_awesome/{weight_cache.rb => proposal_extra_field.rb} (63%) diff --git a/app/cells/concerns/decidim/decidim_awesome/proposal_m_cell_override.rb b/app/cells/concerns/decidim/decidim_awesome/proposal_m_cell_override.rb index ffcf81cfb..88ca82d37 100644 --- a/app/cells/concerns/decidim/decidim_awesome/proposal_m_cell_override.rb +++ b/app/cells/concerns/decidim/decidim_awesome/proposal_m_cell_override.rb @@ -12,7 +12,7 @@ def cache_hash hash << I18n.locale.to_s hash << model.cache_key_with_version hash << model.proposal_votes_count - hash << model.weight_cache&.totals + hash << model.extra_fields&.vote_weights_totals hash << model.endorsements_count hash << model.comments_count hash << Digest::MD5.hexdigest(model.component.cache_key_with_version) diff --git a/app/models/concerns/decidim/decidim_awesome/has_weight_cache.rb b/app/models/concerns/decidim/decidim_awesome/has_proposal_extra_fields.rb similarity index 65% rename from app/models/concerns/decidim/decidim_awesome/has_weight_cache.rb rename to app/models/concerns/decidim/decidim_awesome/has_proposal_extra_fields.rb index 09928a2bf..f2ac9fa37 100644 --- a/app/models/concerns/decidim/decidim_awesome/has_weight_cache.rb +++ b/app/models/concerns/decidim/decidim_awesome/has_proposal_extra_fields.rb @@ -2,14 +2,14 @@ module Decidim module DecidimAwesome - module HasWeightCache + module HasProposalExtraFields extend ActiveSupport::Concern included do - has_one :weight_cache, foreign_key: "decidim_proposal_id", class_name: "Decidim::DecidimAwesome::WeightCache", dependent: :destroy + has_one :extra_fields, foreign_key: "decidim_proposal_id", class_name: "Decidim::DecidimAwesome::ProposalExtraField", dependent: :destroy def weight_count(weight) - (weight_cache && weight_cache.totals[weight.to_s]) || 0 + (extra_fields && extra_fields.vote_weights_totals[weight.to_s]) || 0 end def vote_weights @@ -25,14 +25,14 @@ def all_vote_weights end def update_vote_weights! - weight_cache ||= Decidim::DecidimAwesome::WeightCache.find_or_initialize_by(proposal: self) - weight_cache.totals = {} + extra_fields ||= Decidim::DecidimAwesome::ProposalExtraField.find_or_initialize_by(proposal: self) + extra_fields.vote_weights_totals = {} votes.each do |vote| - weight_cache.totals[vote.weight] ||= 0 - weight_cache.totals[vote.weight] += 1 + extra_fields.vote_weights_totals[vote.weight] ||= 0 + extra_fields.vote_weights_totals[vote.weight] += 1 end - weight_cache.save! - self.weight_cache = weight_cache + extra_fields.save! + self.extra_fields = extra_fields @vote_weights = nil @all_vote_weights = nil end diff --git a/app/models/decidim/decidim_awesome/weight_cache.rb b/app/models/decidim/decidim_awesome/proposal_extra_field.rb similarity index 63% rename from app/models/decidim/decidim_awesome/weight_cache.rb rename to app/models/decidim/decidim_awesome/proposal_extra_field.rb index 3c3d7cb64..d64eb9208 100644 --- a/app/models/decidim/decidim_awesome/weight_cache.rb +++ b/app/models/decidim/decidim_awesome/proposal_extra_field.rb @@ -2,8 +2,8 @@ module Decidim module DecidimAwesome - class WeightCache < ApplicationRecord - self.table_name = "decidim_awesome_weight_caches" + class ProposalExtraField < ApplicationRecord + self.table_name = "decidim_awesome_proposal_extra_fields" belongs_to :proposal, foreign_key: "decidim_proposal_id", class_name: "Decidim::Proposals::Proposal" end diff --git a/app/models/decidim/decidim_awesome/vote_weight.rb b/app/models/decidim/decidim_awesome/vote_weight.rb index 69d5bc032..b3b774b22 100644 --- a/app/models/decidim/decidim_awesome/vote_weight.rb +++ b/app/models/decidim/decidim_awesome/vote_weight.rb @@ -12,18 +12,18 @@ class VoteWeight < ApplicationRecord after_save :update_vote_weight_totals! def update_vote_weight_totals! - cache = Decidim::DecidimAwesome::WeightCache.find_or_initialize_by(proposal: proposal) - cache.totals = cache.totals || {} + extra = Decidim::DecidimAwesome::ProposalExtraField.find_or_initialize_by(proposal: proposal) + extra.vote_weights_totals = extra.vote_weights_totals || {} prev = weight_previous_change&.first if prev.present? - cache.totals[prev.to_s] = Decidim::DecidimAwesome::VoteWeight.where(vote: proposal.votes, weight: prev).count - cache.totals.delete(prev.to_s) if cache.totals[prev.to_s].zero? + extra.vote_weights_totals[prev.to_s] = Decidim::DecidimAwesome::VoteWeight.where(vote: proposal.votes, weight: prev).count + extra.vote_weights_totals.delete(prev.to_s) if extra.vote_weights_totals[prev.to_s].zero? end - cache.totals[weight.to_s] = Decidim::DecidimAwesome::VoteWeight.where(vote: proposal.votes, weight: weight).count - cache.totals.delete(weight.to_s) if cache.totals[weight.to_s].zero? - cache.weight_total = cache.totals.inject(0) { |sum, (weight, count)| sum + (weight.to_i * count) } - cache.save! + extra.vote_weights_totals[weight.to_s] = Decidim::DecidimAwesome::VoteWeight.where(vote: proposal.votes, weight: weight).count + extra.vote_weights_totals.delete(weight.to_s) if extra.vote_weights_totals[weight.to_s].zero? + extra.weight_total = extra.vote_weights_totals.inject(0) { |sum, (weight, count)| sum + (weight.to_i * count) } + extra.save! end end end diff --git a/db/migrate/20231006113841_create_decidim_awesome_weight_caches.rb b/db/migrate/20231006113841_create_decidim_awesome_weight_caches.rb index 778cf166d..484d992e1 100644 --- a/db/migrate/20231006113841_create_decidim_awesome_weight_caches.rb +++ b/db/migrate/20231006113841_create_decidim_awesome_weight_caches.rb @@ -2,11 +2,11 @@ class CreateDecidimAwesomeWeightCaches < ActiveRecord::Migration[6.0] def change - create_table :decidim_awesome_weight_caches do |t| + create_table :decidim_awesome_proposal_extra_fields do |t| # this might be polymorphic in the future (if other types of votes are supported) t.references :decidim_proposal, null: false, index: { name: "decidim_awesome_proposals_weights_cache" } - t.jsonb :totals + t.jsonb :vote_weights_totals t.integer :weight_total, default: 0 t.timestamps end diff --git a/lib/decidim/decidim_awesome/engine.rb b/lib/decidim/decidim_awesome/engine.rb index bfae62870..70ba77af9 100644 --- a/lib/decidim/decidim_awesome/engine.rb +++ b/lib/decidim/decidim_awesome/engine.rb @@ -58,7 +58,7 @@ class Engine < ::Rails::Engine # add vote weight to proposal vote Decidim::Proposals::ProposalVote.include(Decidim::DecidimAwesome::HasVoteWeight) # add vote weight cache to proposal - Decidim::Proposals::Proposal.include(Decidim::DecidimAwesome::HasWeightCache) + Decidim::Proposals::Proposal.include(Decidim::DecidimAwesome::HasProposalExtraFields) Decidim::Proposals::ProposalSerializer.include(Decidim::DecidimAwesome::ProposalSerializerOverride) Decidim::Proposals::ProposalType.include(Decidim::DecidimAwesome::ProposalTypeOverride) Decidim::Proposals::ProposalMCell.include(Decidim::DecidimAwesome::ProposalMCellOverride) diff --git a/lib/decidim/decidim_awesome/test/factories.rb b/lib/decidim/decidim_awesome/test/factories.rb index 09806377c..f10ec34d1 100644 --- a/lib/decidim/decidim_awesome/test/factories.rb +++ b/lib/decidim/decidim_awesome/test/factories.rb @@ -47,7 +47,7 @@ sequence(:weight) { |n| n } end - factory :awesome_weight_cache, class: "Decidim::DecidimAwesome::WeightCache" do + factory :awesome_proposal_extra_field, class: "Decidim::DecidimAwesome::ProposalExtraField" do proposal { create :proposal } trait :with_votes do diff --git a/spec/cells/voting/voting_cards_base_cell_spec.rb b/spec/cells/voting/voting_cards_base_cell_spec.rb index 01c7c8b5b..1a917cea8 100644 --- a/spec/cells/voting/voting_cards_base_cell_spec.rb +++ b/spec/cells/voting/voting_cards_base_cell_spec.rb @@ -13,7 +13,7 @@ module Voting let(:user) { create(:user, :confirmed, organization: organization) } let!(:component) { create :proposal_component, :with_votes_enabled, organization: organization, settings: { awesome_voting_manifest: manifest } } let(:proposal) { create(:proposal, component: component) } - let!(:weight_cache) { create(:awesome_weight_cache, proposal: proposal) } + let!(:extra_fields) { create(:awesome_proposal_extra_fields, proposal: proposal) } let!(:vote_weights) do [ create_list(:awesome_vote_weight, 3, vote: create(:proposal_vote, proposal: proposal), weight: 1), diff --git a/spec/cells/voting/voting_cards_counter_cell_spec.rb b/spec/cells/voting/voting_cards_counter_cell_spec.rb index 47986c1ba..ad2230fd0 100644 --- a/spec/cells/voting/voting_cards_counter_cell_spec.rb +++ b/spec/cells/voting/voting_cards_counter_cell_spec.rb @@ -13,7 +13,7 @@ module Voting let(:user) { create(:user, :confirmed, organization: organization) } let!(:component) { create :proposal_component, :with_votes_enabled, organization: organization, settings: { awesome_voting_manifest: manifest } } let(:proposal) { create(:proposal, component: component) } - let!(:weight_cache) { create(:awesome_weight_cache, proposal: proposal) } + let!(:extra_fields) { create(:awesome_proposal_extra_fields, proposal: proposal) } let!(:vote_weights) do [ create_list(:awesome_vote_weight, 3, vote: create(:proposal_vote, proposal: proposal), weight: 1), diff --git a/spec/cells/voting/voting_cards_proposal_cell_spec.rb b/spec/cells/voting/voting_cards_proposal_cell_spec.rb index 40d9938e1..e20f0b309 100644 --- a/spec/cells/voting/voting_cards_proposal_cell_spec.rb +++ b/spec/cells/voting/voting_cards_proposal_cell_spec.rb @@ -13,7 +13,7 @@ module Voting let(:user) { create(:user, :confirmed, organization: organization) } let!(:component) { create :proposal_component, :with_votes_enabled, organization: organization, settings: { awesome_voting_manifest: manifest } } let(:proposal) { create(:proposal, component: component) } - let!(:weight_cache) { create(:awesome_weight_cache, proposal: proposal) } + let!(:extra_fields) { create(:awesome_proposal_extra_fields, proposal: proposal) } let!(:vote_weights) do [ create_list(:awesome_vote_weight, 3, vote: create(:proposal_vote, proposal: proposal), weight: 1), diff --git a/spec/models/weight_cache_spec.rb b/spec/models/weight_cache_spec.rb index ef3b4c5b4..4ee82328d 100644 --- a/spec/models/weight_cache_spec.rb +++ b/spec/models/weight_cache_spec.rb @@ -4,23 +4,23 @@ module Decidim::DecidimAwesome describe VoteWeight do - subject { weight_cache } + subject { extra_fields } - let(:weight_cache) { create(:awesome_weight_cache) } + let(:extra_fields) { create(:awesome_proposal_extra_fields) } let(:proposal) { create(:proposal) } it { is_expected.to be_valid } it "has a proposal associated" do - expect(weight_cache.proposal).to be_a(Decidim::Proposals::Proposal) + expect(extra_fields.proposal).to be_a(Decidim::Proposals::Proposal) end it "the associated proposal has a weight cache" do - expect(weight_cache.proposal.weight_cache).to eq(weight_cache) + expect(extra_fields.proposal.extra_fields).to eq(extra_fields) end describe "weight_count" do - let!(:weight_cache) { create(:awesome_weight_cache, proposal: proposal) } + let!(:extra_fields) { create(:awesome_proposal_extra_fields, proposal: proposal) } let!(:vote_weights) do [ create(:awesome_vote_weight, vote: create(:proposal_vote, proposal: proposal), weight: 1), @@ -50,8 +50,8 @@ module Decidim::DecidimAwesome end end - context "when weight_cache does not exist" do - let(:weight_cache) { nil } + context "when extra_fields does not exist" do + let(:extra_fields) { nil } let(:vote_weights) { nil } it "returns 0" do @@ -79,18 +79,18 @@ module Decidim::DecidimAwesome end context "when proposal is destroyed" do - let!(:weight_cache) { create(:awesome_weight_cache, proposal: proposal) } + let!(:extra_fields) { create(:awesome_proposal_extra_fields, proposal: proposal) } it "destroys the proposal weight" do - expect { proposal.destroy }.to change(Decidim::DecidimAwesome::WeightCache, :count).by(-1) + expect { proposal.destroy }.to change(Decidim::DecidimAwesome::ProposalExtraField, :count).by(-1) end end context "when proposal weight is destroyed" do - let!(:weight_cache) { create(:awesome_weight_cache, proposal: proposal) } + let!(:extra_fields) { create(:awesome_proposal_extra_fields, proposal: proposal) } it "does not destroy the proposal" do - expect { weight_cache.destroy }.not_to change(Decidim::Proposals::ProposalVote, :count) + expect { extra_fields.destroy }.not_to change(Decidim::Proposals::ProposalVote, :count) end end @@ -98,43 +98,43 @@ module Decidim::DecidimAwesome describe "created" do it "increments the weight cache" do expect { create(:proposal_vote, proposal: proposal) }.to change { proposal.votes.count }.by(1) - expect { create(:awesome_vote_weight, vote: proposal.votes.first, weight: 3) }.to change(Decidim::DecidimAwesome::WeightCache, :count).by(1) - expect(proposal.weight_cache.totals).to eq({ "3" => 1 }) - expect(proposal.weight_cache.weight_total).to eq(3) + expect { create(:awesome_vote_weight, vote: proposal.votes.first, weight: 3) }.to change(Decidim::DecidimAwesome::ProposalExtraField, :count).by(1) + expect(proposal.extra_fields.vote_weights_totals).to eq({ "3" => 1 }) + expect(proposal.extra_fields.weight_total).to eq(3) end context "when cache already exists" do let(:another_proposal) { create :proposal, component: proposal.component } - let!(:weight_cache) { create(:awesome_weight_cache, :with_votes, proposal: proposal) } - let!(:another_weight_cache) { create(:awesome_weight_cache, :with_votes, proposal: another_proposal) } + let!(:extra_fields) { create(:awesome_proposal_extra_fields, :with_votes, proposal: proposal) } + let!(:another_extra_fields) { create(:awesome_proposal_extra_fields, :with_votes, proposal: another_proposal) } it "has weights and votes" do - expect(weight_cache.reload.totals).to eq({ "1" => 1, "2" => 1, "3" => 1, "4" => 1, "5" => 1 }) - expect(weight_cache.weight_total).to eq(15) + expect(extra_fields.reload.vote_weights_totals).to eq({ "1" => 1, "2" => 1, "3" => 1, "4" => 1, "5" => 1 }) + expect(extra_fields.weight_total).to eq(15) end it "increments the weight cache" do create(:awesome_vote_weight, vote: create(:proposal_vote, proposal: proposal), weight: 1) create(:awesome_vote_weight, vote: create(:proposal_vote, proposal: proposal), weight: 3) create(:awesome_vote_weight, vote: create(:proposal_vote, proposal: proposal), weight: 3) - expect(weight_cache.reload.totals).to eq({ "1" => 2, "2" => 1, "3" => 3, "4" => 1, "5" => 1 }) - expect(weight_cache.weight_total).to eq(22) + expect(extra_fields.reload.vote_weights_totals).to eq({ "1" => 2, "2" => 1, "3" => 3, "4" => 1, "5" => 1 }) + expect(extra_fields.weight_total).to eq(22) end end context "when cache does not exist yet" do - let(:weight_cache) { proposal.reload.weight_cache } + let(:extra_fields) { proposal.reload.extra_fields } it "has no weights and votes" do - expect(weight_cache).to be_nil + expect(extra_fields).to be_nil end it "increments the weight cache" do create(:awesome_vote_weight, vote: create(:proposal_vote, proposal: proposal), weight: 1) create(:awesome_vote_weight, vote: create(:proposal_vote, proposal: proposal), weight: 3) create(:awesome_vote_weight, vote: create(:proposal_vote, proposal: proposal), weight: 3) - expect(weight_cache.totals).to eq({ "1" => 1, "3" => 2 }) - expect(weight_cache.weight_total).to eq(7) + expect(extra_fields.vote_weights_totals).to eq({ "1" => 1, "3" => 2 }) + expect(extra_fields.weight_total).to eq(7) end end end @@ -143,40 +143,40 @@ module Decidim::DecidimAwesome describe "updated" do let!(:vote_weight1) { create(:awesome_vote_weight, vote: create(:proposal_vote, proposal: proposal), weight: 1) } let!(:vote_weight2) { create(:awesome_vote_weight, vote: create(:proposal_vote, proposal: proposal), weight: 2) } - let(:weight_cache) { proposal.reload.weight_cache } + let(:extra_fields) { proposal.reload.extra_fields } it "increments the weight cache" do vote_weight1.weight = 3 vote_weight1.save - expect(weight_cache.totals).to eq({ "2" => 1, "3" => 1 }) - expect(weight_cache.weight_total).to eq(5) + expect(extra_fields.vote_weights_totals).to eq({ "2" => 1, "3" => 1 }) + expect(extra_fields.weight_total).to eq(5) end it "decreases the weight cache" do vote_weight2.weight = 1 vote_weight2.save - expect(weight_cache.totals).to eq({ "1" => 2 }) - expect(weight_cache.weight_total).to eq(2) + expect(extra_fields.vote_weights_totals).to eq({ "1" => 2 }) + expect(extra_fields.weight_total).to eq(2) end end describe "destroyed" do let!(:vote_weight1) { create(:awesome_vote_weight, vote: create(:proposal_vote, proposal: proposal), weight: 1) } let!(:vote_weight2) { create(:awesome_vote_weight, vote: create(:proposal_vote, proposal: proposal), weight: 2) } - let(:weight_cache) { proposal.reload.weight_cache } + let(:extra_fields) { proposal.reload.extra_fields } it "decreases the weight cache" do vote_weight1.destroy - expect(weight_cache.totals).to eq({ "2" => 1 }) - expect(weight_cache.weight_total).to eq(2) + expect(extra_fields.vote_weights_totals).to eq({ "2" => 1 }) + expect(extra_fields.weight_total).to eq(2) end end end describe "all_vote_weights" do - let!(:weight_cache) { create(:awesome_weight_cache, proposal: proposal) } - let!(:another_weight_cache) { create(:awesome_weight_cache, proposal: another_proposal) } - let!(:unrelated_another_weight_cache) { create(:awesome_weight_cache, :with_votes) } + let!(:extra_fields) { create(:awesome_proposal_extra_fields, proposal: proposal) } + let!(:another_extra_fields) { create(:awesome_proposal_extra_fields, proposal: another_proposal) } + let!(:unrelated_another_extra_fields) { create(:awesome_proposal_extra_fields, :with_votes) } let(:another_proposal) { create(:proposal, component: proposal.component) } let!(:votes) do vote = create(:proposal_vote, proposal: proposal, author: create(:user, organization: proposal.organization)) @@ -198,18 +198,18 @@ module Decidim::DecidimAwesome before do # rubocop:disable Rails/SkipsModelValidations: # we don't want to trigger the active record hooks - weight_cache.update_columns(totals: { "3" => 1, "4" => 1 }) + extra_fields.update_columns(totals: { "3" => 1, "4" => 1 }) # rubocop:enable Rails/SkipsModelValidations: end it "returns all vote weights for a component" do - expect(proposal.weight_cache.totals).to eq({ "3" => 1, "4" => 1 }) + expect(proposal.extra_fields.vote_weights_totals).to eq({ "3" => 1, "4" => 1 }) expect(proposal.vote_weights).to eq({ "1" => 0, "2" => 0 }) proposal.update_vote_weights! expect(proposal.vote_weights).to eq({ "1" => 1, "2" => 0 }) expect(another_proposal.vote_weights).to eq({ "1" => 0, "2" => 1 }) - expect(proposal.weight_cache.totals).to eq({ "1" => 1 }) - expect(another_proposal.weight_cache.totals).to eq({ "2" => 1 }) + expect(proposal.extra_fields.vote_weights_totals).to eq({ "1" => 1 }) + expect(another_proposal.extra_fields.vote_weights_totals).to eq({ "2" => 1 }) end end end diff --git a/spec/serializers/proposal_serializer_spec.rb b/spec/serializers/proposal_serializer_spec.rb index 88e26a27a..d9713828c 100644 --- a/spec/serializers/proposal_serializer_spec.rb +++ b/spec/serializers/proposal_serializer_spec.rb @@ -10,7 +10,7 @@ module Decidim::Proposals let!(:proposal) { create(:proposal, :accepted, component: component) } let!(:another_proposal) { create(:proposal, :accepted, component: component) } - let!(:weight_cache) { create(:awesome_weight_cache, proposal: proposal) } + let!(:extra_fields) { create(:awesome_proposal_extra_fields, proposal: proposal) } let(:weights) do { "0" => 1, @@ -25,7 +25,7 @@ module Decidim::Proposals end end end - let!(:another_weight_cache) { create(:awesome_weight_cache, :with_votes, proposal: another_proposal) } + let!(:another_extra_fields) { create(:awesome_proposal_extra_fields, :with_votes, proposal: another_proposal) } let(:participatory_process) { component.participatory_space } let(:component) { create :proposal_component, settings: settings } let(:settings) do @@ -81,14 +81,14 @@ module Decidim::Proposals before do # rubocop:disable Rails/SkipsModelValidations: # we don't want to trigger the active record hooks - weight_cache.update_columns(totals: wrong_weights) + extra_fields.update_columns(vote_weights_totals: wrong_weights) # rubocop:enable Rails/SkipsModelValidations: end it "serializes the weights" do expect(proposal.vote_weights).to eq(labeled_wrong_weights) expect(serialized).to include(weights: labeled_weights) - weight_cache.reload + extra_fields.reload expect(proposal.reload.vote_weights).to eq(labeled_weights) end end diff --git a/spec/types/proposal_type_spec.rb b/spec/types/proposal_type_spec.rb index 818129562..e89bde5a6 100644 --- a/spec/types/proposal_type_spec.rb +++ b/spec/types/proposal_type_spec.rb @@ -7,7 +7,7 @@ module Decidim::Proposals describe ProposalType, type: :graphql do include_context "with a graphql class type" let(:component) { create(:proposal_component) } - let!(:weight_cache) { create(:awesome_weight_cache, :with_votes, proposal: model) } + let!(:extra_fields) { create(:awesome_proposal_extra_fields, :with_votes, proposal: model) } let(:model) { create :proposal, component: component } describe "id" do From a5ed8079d249027f7e970b5553ccec22821f7f73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Verg=C3=A9s?= Date: Thu, 9 Nov 2023 12:31:21 +0100 Subject: [PATCH 02/11] fix factory --- lib/decidim/decidim_awesome/test/factories.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/decidim/decidim_awesome/test/factories.rb b/lib/decidim/decidim_awesome/test/factories.rb index f10ec34d1..5a928cd6a 100644 --- a/lib/decidim/decidim_awesome/test/factories.rb +++ b/lib/decidim/decidim_awesome/test/factories.rb @@ -47,7 +47,7 @@ sequence(:weight) { |n| n } end - factory :awesome_proposal_extra_field, class: "Decidim::DecidimAwesome::ProposalExtraField" do + factory :awesome_proposal_extra_fields, class: "Decidim::DecidimAwesome::ProposalExtraField" do proposal { create :proposal } trait :with_votes do From d1a6b5c485869e0336cd6062e825ba3f467ffb0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Verg=C3=A9s?= Date: Thu, 9 Nov 2023 12:42:09 +0100 Subject: [PATCH 03/11] migration name --- .../20231006113841_create_decidim_awesome_weight_caches.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/migrate/20231006113841_create_decidim_awesome_weight_caches.rb b/db/migrate/20231006113841_create_decidim_awesome_weight_caches.rb index 484d992e1..709654ca1 100644 --- a/db/migrate/20231006113841_create_decidim_awesome_weight_caches.rb +++ b/db/migrate/20231006113841_create_decidim_awesome_weight_caches.rb @@ -1,10 +1,10 @@ # frozen_string_literal: true -class CreateDecidimAwesomeWeightCaches < ActiveRecord::Migration[6.0] +class CreateDecidimAwesomeProposalExtraFields < ActiveRecord::Migration[6.0] def change create_table :decidim_awesome_proposal_extra_fields do |t| # this might be polymorphic in the future (if other types of votes are supported) - t.references :decidim_proposal, null: false, index: { name: "decidim_awesome_proposals_weights_cache" } + t.references :decidim_proposal, null: false, index: { name: "decidim_awesome_proposal_extra_fields" } t.jsonb :vote_weights_totals t.integer :weight_total, default: 0 From 360cbaab857ae0091fb0e7a0360655a702dadc61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Verg=C3=A9s?= Date: Thu, 9 Nov 2023 12:51:31 +0100 Subject: [PATCH 04/11] renames --- ...31006113841_create_decidim_awesome_proposal_extra_fields.rb} | 0 .../{weight_cache_spec.rb => proposal_extra_field_spec.rb} | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename db/migrate/{20231006113841_create_decidim_awesome_weight_caches.rb => 20231006113841_create_decidim_awesome_proposal_extra_fields.rb} (100%) rename spec/models/{weight_cache_spec.rb => proposal_extra_field_spec.rb} (99%) diff --git a/db/migrate/20231006113841_create_decidim_awesome_weight_caches.rb b/db/migrate/20231006113841_create_decidim_awesome_proposal_extra_fields.rb similarity index 100% rename from db/migrate/20231006113841_create_decidim_awesome_weight_caches.rb rename to db/migrate/20231006113841_create_decidim_awesome_proposal_extra_fields.rb diff --git a/spec/models/weight_cache_spec.rb b/spec/models/proposal_extra_field_spec.rb similarity index 99% rename from spec/models/weight_cache_spec.rb rename to spec/models/proposal_extra_field_spec.rb index 4ee82328d..632bc0156 100644 --- a/spec/models/weight_cache_spec.rb +++ b/spec/models/proposal_extra_field_spec.rb @@ -3,7 +3,7 @@ require "spec_helper" module Decidim::DecidimAwesome - describe VoteWeight do + describe ProposalExtraField do subject { extra_fields } let(:extra_fields) { create(:awesome_proposal_extra_fields) } From d613ae4a4aef17ebdcd8d460c6ecedb73056d4fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Verg=C3=A9s?= Date: Thu, 9 Nov 2023 12:58:15 +0100 Subject: [PATCH 05/11] index name --- ...231006113841_create_decidim_awesome_proposal_extra_fields.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20231006113841_create_decidim_awesome_proposal_extra_fields.rb b/db/migrate/20231006113841_create_decidim_awesome_proposal_extra_fields.rb index 709654ca1..c7549876c 100644 --- a/db/migrate/20231006113841_create_decidim_awesome_proposal_extra_fields.rb +++ b/db/migrate/20231006113841_create_decidim_awesome_proposal_extra_fields.rb @@ -4,7 +4,7 @@ class CreateDecidimAwesomeProposalExtraFields < ActiveRecord::Migration[6.0] def change create_table :decidim_awesome_proposal_extra_fields do |t| # this might be polymorphic in the future (if other types of votes are supported) - t.references :decidim_proposal, null: false, index: { name: "decidim_awesome_proposal_extra_fields" } + t.references :decidim_proposal, null: false, index: { name: "decidim_awesome_extra_fields_on_proposal"} } t.jsonb :vote_weights_totals t.integer :weight_total, default: 0 From 1cf0a4b177adc6e7ed2e5d55cb37d7c892a55bcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Verg=C3=A9s?= Date: Thu, 9 Nov 2023 14:58:41 +0100 Subject: [PATCH 06/11] fix migration --- .github/workflows/tests-legacy.yml | 4 +++- .github/workflows/tests.yml | 4 +++- ...1006113841_create_decidim_awesome_proposal_extra_fields.rb | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests-legacy.yml b/.github/workflows/tests-legacy.yml index c6b3eb4d2..a86ae1f7d 100644 --- a/.github/workflows/tests-legacy.yml +++ b/.github/workflows/tests-legacy.yml @@ -25,7 +25,9 @@ jobs: features: enabled - rspec: system/admin features: enabled - - rspec: system/*_spec.rb + - rspec: system/*_spec.rb --exclude-pattern 'spec/system/awesome_map_spec.rb' + features: enabled + - rspec: system/awesome_map_spec.rb features: enabled fail-fast: false diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 910e1faff..89fcbac41 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -25,7 +25,9 @@ jobs: features: enabled - rspec: system/admin features: enabled - - rspec: system/*_spec.rb + - rspec: system/*_spec.rb --exclude-pattern 'spec/system/awesome_map_spec.rb' + features: enabled + - rspec: system/awesome_map_spec.rb features: enabled fail-fast: false diff --git a/db/migrate/20231006113841_create_decidim_awesome_proposal_extra_fields.rb b/db/migrate/20231006113841_create_decidim_awesome_proposal_extra_fields.rb index c7549876c..89e2f236e 100644 --- a/db/migrate/20231006113841_create_decidim_awesome_proposal_extra_fields.rb +++ b/db/migrate/20231006113841_create_decidim_awesome_proposal_extra_fields.rb @@ -4,7 +4,7 @@ class CreateDecidimAwesomeProposalExtraFields < ActiveRecord::Migration[6.0] def change create_table :decidim_awesome_proposal_extra_fields do |t| # this might be polymorphic in the future (if other types of votes are supported) - t.references :decidim_proposal, null: false, index: { name: "decidim_awesome_extra_fields_on_proposal"} } + t.references :decidim_proposal, null: false, index: { name: "decidim_awesome_extra_fields_on_proposal" } t.jsonb :vote_weights_totals t.integer :weight_total, default: 0 From c258247f5c72af4f2c9f7e88cac0823b0de21169 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Verg=C3=A9s?= Date: Thu, 9 Nov 2023 15:11:51 +0100 Subject: [PATCH 07/11] fix spec --- .github/workflows/tests.yml | 4 ++-- spec/models/proposal_extra_field_spec.rb | 2 +- spec/system/{ => awesome_map}/awesome_map_spec.rb | 0 3 files changed, 3 insertions(+), 3 deletions(-) rename spec/system/{ => awesome_map}/awesome_map_spec.rb (100%) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 89fcbac41..a325ed8a9 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -25,9 +25,9 @@ jobs: features: enabled - rspec: system/admin features: enabled - - rspec: system/*_spec.rb --exclude-pattern 'spec/system/awesome_map_spec.rb' + - rspec: system/*_spec.rb' features: enabled - - rspec: system/awesome_map_spec.rb + - rspec: system/awesome_map features: enabled fail-fast: false diff --git a/spec/models/proposal_extra_field_spec.rb b/spec/models/proposal_extra_field_spec.rb index 632bc0156..5a1266b32 100644 --- a/spec/models/proposal_extra_field_spec.rb +++ b/spec/models/proposal_extra_field_spec.rb @@ -198,7 +198,7 @@ module Decidim::DecidimAwesome before do # rubocop:disable Rails/SkipsModelValidations: # we don't want to trigger the active record hooks - extra_fields.update_columns(totals: { "3" => 1, "4" => 1 }) + extra_fields.update_columns(vote_weight_totals: { "3" => 1, "4" => 1 }) # rubocop:enable Rails/SkipsModelValidations: end diff --git a/spec/system/awesome_map_spec.rb b/spec/system/awesome_map/awesome_map_spec.rb similarity index 100% rename from spec/system/awesome_map_spec.rb rename to spec/system/awesome_map/awesome_map_spec.rb From ed4620e902e8a25c5e222acc5971d74a47be7cb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Verg=C3=A9s?= Date: Thu, 9 Nov 2023 15:24:21 +0100 Subject: [PATCH 08/11] fix spec --- README.md | 5 +---- .../proposal_m_cell_override.rb | 2 +- .../has_proposal_extra_fields.rb | 8 ++++---- .../decidim/decidim_awesome/vote_weight.rb | 12 +++++------ ...e_decidim_awesome_proposal_extra_fields.rb | 2 +- .../decidim_awesome_webpacker_tasks.rake | 6 ++++++ spec/models/proposal_extra_field_spec.rb | 20 +++++++++---------- spec/serializers/proposal_serializer_spec.rb | 2 +- 8 files changed, 30 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 24ea5f56b..f90aa6315 100644 --- a/README.md +++ b/README.md @@ -293,13 +293,10 @@ And then execute: ```bash bundle -bundle exec rails decidim_decidim_awesome:install:migrations -bundle exec rails decidim_decidim_awesome:webpacker:install +bundle exec rails decidim:upgrade bundle exec rails db:migrate ``` -> NOTE: the `decidim_decidim_awesome:webpacker:install` is only necessary for Decidim versions starting at 0.25. - If you are upgrading from a version prior to 0.8, make sure to visit the URL `/admin/decidim_awesome/checks` and run image migrations for the old images: ![Check image migrations](examples/check_image_migrations.png) diff --git a/app/cells/concerns/decidim/decidim_awesome/proposal_m_cell_override.rb b/app/cells/concerns/decidim/decidim_awesome/proposal_m_cell_override.rb index 88ca82d37..5e1e987fd 100644 --- a/app/cells/concerns/decidim/decidim_awesome/proposal_m_cell_override.rb +++ b/app/cells/concerns/decidim/decidim_awesome/proposal_m_cell_override.rb @@ -12,7 +12,7 @@ def cache_hash hash << I18n.locale.to_s hash << model.cache_key_with_version hash << model.proposal_votes_count - hash << model.extra_fields&.vote_weights_totals + hash << model.extra_fields&.vote_weight_totals hash << model.endorsements_count hash << model.comments_count hash << Digest::MD5.hexdigest(model.component.cache_key_with_version) diff --git a/app/models/concerns/decidim/decidim_awesome/has_proposal_extra_fields.rb b/app/models/concerns/decidim/decidim_awesome/has_proposal_extra_fields.rb index f2ac9fa37..626ce988d 100644 --- a/app/models/concerns/decidim/decidim_awesome/has_proposal_extra_fields.rb +++ b/app/models/concerns/decidim/decidim_awesome/has_proposal_extra_fields.rb @@ -9,7 +9,7 @@ module HasProposalExtraFields has_one :extra_fields, foreign_key: "decidim_proposal_id", class_name: "Decidim::DecidimAwesome::ProposalExtraField", dependent: :destroy def weight_count(weight) - (extra_fields && extra_fields.vote_weights_totals[weight.to_s]) || 0 + (extra_fields && extra_fields.vote_weight_totals[weight.to_s]) || 0 end def vote_weights @@ -26,10 +26,10 @@ def all_vote_weights def update_vote_weights! extra_fields ||= Decidim::DecidimAwesome::ProposalExtraField.find_or_initialize_by(proposal: self) - extra_fields.vote_weights_totals = {} + extra_fields.vote_weight_totals = {} votes.each do |vote| - extra_fields.vote_weights_totals[vote.weight] ||= 0 - extra_fields.vote_weights_totals[vote.weight] += 1 + extra_fields.vote_weight_totals[vote.weight] ||= 0 + extra_fields.vote_weight_totals[vote.weight] += 1 end extra_fields.save! self.extra_fields = extra_fields diff --git a/app/models/decidim/decidim_awesome/vote_weight.rb b/app/models/decidim/decidim_awesome/vote_weight.rb index b3b774b22..9f3f26b8b 100644 --- a/app/models/decidim/decidim_awesome/vote_weight.rb +++ b/app/models/decidim/decidim_awesome/vote_weight.rb @@ -13,16 +13,16 @@ class VoteWeight < ApplicationRecord def update_vote_weight_totals! extra = Decidim::DecidimAwesome::ProposalExtraField.find_or_initialize_by(proposal: proposal) - extra.vote_weights_totals = extra.vote_weights_totals || {} + extra.vote_weight_totals = extra.vote_weight_totals || {} prev = weight_previous_change&.first if prev.present? - extra.vote_weights_totals[prev.to_s] = Decidim::DecidimAwesome::VoteWeight.where(vote: proposal.votes, weight: prev).count - extra.vote_weights_totals.delete(prev.to_s) if extra.vote_weights_totals[prev.to_s].zero? + extra.vote_weight_totals[prev.to_s] = Decidim::DecidimAwesome::VoteWeight.where(vote: proposal.votes, weight: prev).count + extra.vote_weight_totals.delete(prev.to_s) if extra.vote_weight_totals[prev.to_s].zero? end - extra.vote_weights_totals[weight.to_s] = Decidim::DecidimAwesome::VoteWeight.where(vote: proposal.votes, weight: weight).count - extra.vote_weights_totals.delete(weight.to_s) if extra.vote_weights_totals[weight.to_s].zero? - extra.weight_total = extra.vote_weights_totals.inject(0) { |sum, (weight, count)| sum + (weight.to_i * count) } + extra.vote_weight_totals[weight.to_s] = Decidim::DecidimAwesome::VoteWeight.where(vote: proposal.votes, weight: weight).count + extra.vote_weight_totals.delete(weight.to_s) if extra.vote_weight_totals[weight.to_s].zero? + extra.weight_total = extra.vote_weight_totals.inject(0) { |sum, (weight, count)| sum + (weight.to_i * count) } extra.save! end end diff --git a/db/migrate/20231006113841_create_decidim_awesome_proposal_extra_fields.rb b/db/migrate/20231006113841_create_decidim_awesome_proposal_extra_fields.rb index 89e2f236e..b80098ad9 100644 --- a/db/migrate/20231006113841_create_decidim_awesome_proposal_extra_fields.rb +++ b/db/migrate/20231006113841_create_decidim_awesome_proposal_extra_fields.rb @@ -6,7 +6,7 @@ def change # this might be polymorphic in the future (if other types of votes are supported) t.references :decidim_proposal, null: false, index: { name: "decidim_awesome_extra_fields_on_proposal" } - t.jsonb :vote_weights_totals + t.jsonb :vote_weight_totals t.integer :weight_total, default: 0 t.timestamps end diff --git a/lib/tasks/decidim_awesome_webpacker_tasks.rake b/lib/tasks/decidim_awesome_webpacker_tasks.rake index d89fb0845..6718fca64 100644 --- a/lib/tasks/decidim_awesome_webpacker_tasks.rake +++ b/lib/tasks/decidim_awesome_webpacker_tasks.rake @@ -62,3 +62,9 @@ namespace :decidim_decidim_awesome do end end end + + +Rake::Task["decidim:webpacker:upgrade"].enhance do + Rake::Task["decidim_decidim_awesome:webpacker:install"].invoke + Rake::Task["decidim_decidim_awesome:install:migrations"].invoke +end \ No newline at end of file diff --git a/spec/models/proposal_extra_field_spec.rb b/spec/models/proposal_extra_field_spec.rb index 5a1266b32..8c2227557 100644 --- a/spec/models/proposal_extra_field_spec.rb +++ b/spec/models/proposal_extra_field_spec.rb @@ -99,7 +99,7 @@ module Decidim::DecidimAwesome it "increments the weight cache" do expect { create(:proposal_vote, proposal: proposal) }.to change { proposal.votes.count }.by(1) expect { create(:awesome_vote_weight, vote: proposal.votes.first, weight: 3) }.to change(Decidim::DecidimAwesome::ProposalExtraField, :count).by(1) - expect(proposal.extra_fields.vote_weights_totals).to eq({ "3" => 1 }) + expect(proposal.extra_fields.vote_weight_totals).to eq({ "3" => 1 }) expect(proposal.extra_fields.weight_total).to eq(3) end @@ -109,7 +109,7 @@ module Decidim::DecidimAwesome let!(:another_extra_fields) { create(:awesome_proposal_extra_fields, :with_votes, proposal: another_proposal) } it "has weights and votes" do - expect(extra_fields.reload.vote_weights_totals).to eq({ "1" => 1, "2" => 1, "3" => 1, "4" => 1, "5" => 1 }) + expect(extra_fields.reload.vote_weight_totals).to eq({ "1" => 1, "2" => 1, "3" => 1, "4" => 1, "5" => 1 }) expect(extra_fields.weight_total).to eq(15) end @@ -117,7 +117,7 @@ module Decidim::DecidimAwesome create(:awesome_vote_weight, vote: create(:proposal_vote, proposal: proposal), weight: 1) create(:awesome_vote_weight, vote: create(:proposal_vote, proposal: proposal), weight: 3) create(:awesome_vote_weight, vote: create(:proposal_vote, proposal: proposal), weight: 3) - expect(extra_fields.reload.vote_weights_totals).to eq({ "1" => 2, "2" => 1, "3" => 3, "4" => 1, "5" => 1 }) + expect(extra_fields.reload.vote_weight_totals).to eq({ "1" => 2, "2" => 1, "3" => 3, "4" => 1, "5" => 1 }) expect(extra_fields.weight_total).to eq(22) end end @@ -133,7 +133,7 @@ module Decidim::DecidimAwesome create(:awesome_vote_weight, vote: create(:proposal_vote, proposal: proposal), weight: 1) create(:awesome_vote_weight, vote: create(:proposal_vote, proposal: proposal), weight: 3) create(:awesome_vote_weight, vote: create(:proposal_vote, proposal: proposal), weight: 3) - expect(extra_fields.vote_weights_totals).to eq({ "1" => 1, "3" => 2 }) + expect(extra_fields.vote_weight_totals).to eq({ "1" => 1, "3" => 2 }) expect(extra_fields.weight_total).to eq(7) end end @@ -148,14 +148,14 @@ module Decidim::DecidimAwesome it "increments the weight cache" do vote_weight1.weight = 3 vote_weight1.save - expect(extra_fields.vote_weights_totals).to eq({ "2" => 1, "3" => 1 }) + expect(extra_fields.vote_weight_totals).to eq({ "2" => 1, "3" => 1 }) expect(extra_fields.weight_total).to eq(5) end it "decreases the weight cache" do vote_weight2.weight = 1 vote_weight2.save - expect(extra_fields.vote_weights_totals).to eq({ "1" => 2 }) + expect(extra_fields.vote_weight_totals).to eq({ "1" => 2 }) expect(extra_fields.weight_total).to eq(2) end end @@ -167,7 +167,7 @@ module Decidim::DecidimAwesome it "decreases the weight cache" do vote_weight1.destroy - expect(extra_fields.vote_weights_totals).to eq({ "2" => 1 }) + expect(extra_fields.vote_weight_totals).to eq({ "2" => 1 }) expect(extra_fields.weight_total).to eq(2) end end @@ -203,13 +203,13 @@ module Decidim::DecidimAwesome end it "returns all vote weights for a component" do - expect(proposal.extra_fields.vote_weights_totals).to eq({ "3" => 1, "4" => 1 }) + expect(proposal.extra_fields.vote_weight_totals).to eq({ "3" => 1, "4" => 1 }) expect(proposal.vote_weights).to eq({ "1" => 0, "2" => 0 }) proposal.update_vote_weights! expect(proposal.vote_weights).to eq({ "1" => 1, "2" => 0 }) expect(another_proposal.vote_weights).to eq({ "1" => 0, "2" => 1 }) - expect(proposal.extra_fields.vote_weights_totals).to eq({ "1" => 1 }) - expect(another_proposal.extra_fields.vote_weights_totals).to eq({ "2" => 1 }) + expect(proposal.extra_fields.vote_weight_totals).to eq({ "1" => 1 }) + expect(another_proposal.extra_fields.vote_weight_totals).to eq({ "2" => 1 }) end end end diff --git a/spec/serializers/proposal_serializer_spec.rb b/spec/serializers/proposal_serializer_spec.rb index d9713828c..bfd99c0e9 100644 --- a/spec/serializers/proposal_serializer_spec.rb +++ b/spec/serializers/proposal_serializer_spec.rb @@ -81,7 +81,7 @@ module Decidim::Proposals before do # rubocop:disable Rails/SkipsModelValidations: # we don't want to trigger the active record hooks - extra_fields.update_columns(vote_weights_totals: wrong_weights) + extra_fields.update_columns(vote_weight_totals: wrong_weights) # rubocop:enable Rails/SkipsModelValidations: end From ccba9dca380209c9790fb2566c13787fe2914f08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Verg=C3=A9s?= Date: Thu, 9 Nov 2023 15:59:37 +0100 Subject: [PATCH 09/11] fix spec again --- .github/workflows/tests-legacy.yml | 4 ++-- .github/workflows/tests.yml | 2 +- README.md | 1 + lib/tasks/decidim_awesome_upgrade_tasks.rake | 5 +++++ lib/tasks/decidim_awesome_webpacker_tasks.rake | 6 ------ 5 files changed, 9 insertions(+), 9 deletions(-) create mode 100644 lib/tasks/decidim_awesome_upgrade_tasks.rake diff --git a/.github/workflows/tests-legacy.yml b/.github/workflows/tests-legacy.yml index a86ae1f7d..3ce5c2d89 100644 --- a/.github/workflows/tests-legacy.yml +++ b/.github/workflows/tests-legacy.yml @@ -25,9 +25,9 @@ jobs: features: enabled - rspec: system/admin features: enabled - - rspec: system/*_spec.rb --exclude-pattern 'spec/system/awesome_map_spec.rb' + - rspec: system/*_spec.rb features: enabled - - rspec: system/awesome_map_spec.rb + - rspec: system/awesome_map features: enabled fail-fast: false diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a325ed8a9..c5bc6018c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -25,7 +25,7 @@ jobs: features: enabled - rspec: system/admin features: enabled - - rspec: system/*_spec.rb' + - rspec: system/*_spec.rb features: enabled - rspec: system/awesome_map features: enabled diff --git a/README.md b/README.md index f90aa6315..febea1c28 100644 --- a/README.md +++ b/README.md @@ -293,6 +293,7 @@ And then execute: ```bash bundle +bundle exec rails decidim_decidim_awesome:install:migrations bundle exec rails decidim:upgrade bundle exec rails db:migrate ``` diff --git a/lib/tasks/decidim_awesome_upgrade_tasks.rake b/lib/tasks/decidim_awesome_upgrade_tasks.rake new file mode 100644 index 000000000..bd5a4a6bb --- /dev/null +++ b/lib/tasks/decidim_awesome_upgrade_tasks.rake @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +Rake::Task["decidim:upgrade"].enhance do + Rake::Task["decidim_decidim_awesome:webpacker:install"].invoke +end diff --git a/lib/tasks/decidim_awesome_webpacker_tasks.rake b/lib/tasks/decidim_awesome_webpacker_tasks.rake index 6718fca64..d89fb0845 100644 --- a/lib/tasks/decidim_awesome_webpacker_tasks.rake +++ b/lib/tasks/decidim_awesome_webpacker_tasks.rake @@ -62,9 +62,3 @@ namespace :decidim_decidim_awesome do end end end - - -Rake::Task["decidim:webpacker:upgrade"].enhance do - Rake::Task["decidim_decidim_awesome:webpacker:install"].invoke - Rake::Task["decidim_decidim_awesome:install:migrations"].invoke -end \ No newline at end of file From 7db0a11a2ea65e98c48ca5844c34035b660766ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Verg=C3=A9s?= Date: Thu, 9 Nov 2023 16:05:00 +0100 Subject: [PATCH 10/11] readme --- README.md | 1 + lib/tasks/decidim_awesome_upgrade_tasks.rake | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index febea1c28..739b2b257 100644 --- a/README.md +++ b/README.md @@ -328,6 +328,7 @@ Depending on your Decidim version, choose the corresponding Awesome version to e | 0.5.x | 0.21.x, 0.22.x | > *Heads up!* +> * version 0.10.0 requires database migrations! Don't forget the migrations step when updating. > * version 0.8.0 removes CSS Themes for tenants. If you have been using them you will have to manually migrate them to custom styles. > * version 0.8.0 uses ActiveStorage, same as Decidim 0.25. 2 new rake task have been introduced to facilitate the migration: `bin/rails decidim_awesome:active_storage_migrations:check_migration_from_carrierwave` and `bin/rails decidim_awesome:active_storage_migrations:migrate_from_carrierwave` diff --git a/lib/tasks/decidim_awesome_upgrade_tasks.rake b/lib/tasks/decidim_awesome_upgrade_tasks.rake index bd5a4a6bb..5558bba17 100644 --- a/lib/tasks/decidim_awesome_upgrade_tasks.rake +++ b/lib/tasks/decidim_awesome_upgrade_tasks.rake @@ -1,5 +1,9 @@ # frozen_string_literal: true -Rake::Task["decidim:upgrade"].enhance do +Rake::Task["decidim:webpacker:install"].enhance do + Rake::Task["decidim_decidim_awesome:webpacker:install"].invoke +end + +Rake::Task["decidim:webpacker:upgrade"].enhance do Rake::Task["decidim_decidim_awesome:webpacker:install"].invoke end From 13e35380e0e63b3d3751b3d03d1169e62cccba41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Verg=C3=A9s?= Date: Thu, 9 Nov 2023 16:13:07 +0100 Subject: [PATCH 11/11] add 0.10 version --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 739b2b257..5b1478a44 100644 --- a/README.md +++ b/README.md @@ -314,12 +314,13 @@ RAILS_ENV=production bin/rails decidim_awesome:active_storage_migrations:check_m ``` The correct version of Decidim Awesome should resolved automatically by the Bundler. -However you can force some specific version using `gem "decidim-decidim_awesome", "~> 0.8.0"` in the Gemfile. +However you can force some specific version using `gem "decidim-decidim_awesome", "~> 0.10.0"` in the Gemfile. Depending on your Decidim version, choose the corresponding Awesome version to ensure compatibility: | Awesome version | Compatible Decidim versions | |---|---| +| 0.10.0 | >= 0.26.7, >= 0.27.3 | | 0.9.2 | >= 0.26.7, >= 0.27.3 | | 0.9.x | 0.26.x, 0.27.x | | 0.8.x | 0.25.x, 0.26.x |