diff --git a/.github/workflows/tests-legacy.yml b/.github/workflows/tests-legacy.yml index c6b3eb4d2..3ce5c2d89 100644 --- a/.github/workflows/tests-legacy.yml +++ b/.github/workflows/tests-legacy.yml @@ -27,6 +27,8 @@ jobs: features: enabled - rspec: system/*_spec.rb features: enabled + - rspec: system/awesome_map + features: enabled fail-fast: false services: diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 910e1faff..c5bc6018c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -27,6 +27,8 @@ jobs: features: enabled - rspec: system/*_spec.rb features: enabled + - rspec: system/awesome_map + features: enabled fail-fast: false services: diff --git a/README.md b/README.md index 24ea5f56b..5b1478a44 100644 --- a/README.md +++ b/README.md @@ -294,12 +294,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) @@ -316,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 | @@ -330,6 +329,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/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..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.weight_cache&.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_weight_cache.rb b/app/models/concerns/decidim/decidim_awesome/has_proposal_extra_fields.rb similarity index 66% 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..626ce988d 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_weight_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_weight_totals = {} votes.each do |vote| - weight_cache.totals[vote.weight] ||= 0 - weight_cache.totals[vote.weight] += 1 + extra_fields.vote_weight_totals[vote.weight] ||= 0 + extra_fields.vote_weight_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..9f3f26b8b 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_weight_totals = extra.vote_weight_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_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 - 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_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 end 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 55% rename from db/migrate/20231006113841_create_decidim_awesome_weight_caches.rb rename to db/migrate/20231006113841_create_decidim_awesome_proposal_extra_fields.rb index 778cf166d..b80098ad9 100644 --- a/db/migrate/20231006113841_create_decidim_awesome_weight_caches.rb +++ b/db/migrate/20231006113841_create_decidim_awesome_proposal_extra_fields.rb @@ -1,12 +1,12 @@ # frozen_string_literal: true -class CreateDecidimAwesomeWeightCaches < ActiveRecord::Migration[6.0] +class CreateDecidimAwesomeProposalExtraFields < 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.references :decidim_proposal, null: false, index: { name: "decidim_awesome_extra_fields_on_proposal" } - t.jsonb :totals + t.jsonb :vote_weight_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..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_weight_cache, class: "Decidim::DecidimAwesome::WeightCache" do + factory :awesome_proposal_extra_fields, class: "Decidim::DecidimAwesome::ProposalExtraField" do proposal { create :proposal } trait :with_votes do diff --git a/lib/tasks/decidim_awesome_upgrade_tasks.rake b/lib/tasks/decidim_awesome_upgrade_tasks.rake new file mode 100644 index 000000000..5558bba17 --- /dev/null +++ b/lib/tasks/decidim_awesome_upgrade_tasks.rake @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +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 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/proposal_extra_field_spec.rb similarity index 69% rename from spec/models/weight_cache_spec.rb rename to spec/models/proposal_extra_field_spec.rb index ef3b4c5b4..8c2227557 100644 --- a/spec/models/weight_cache_spec.rb +++ b/spec/models/proposal_extra_field_spec.rb @@ -3,24 +3,24 @@ require "spec_helper" module Decidim::DecidimAwesome - describe VoteWeight do - subject { weight_cache } + describe ProposalExtraField do + 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_weight_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_weight_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_weight_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_weight_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_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(weight_cache.totals).to eq({ "1" => 2 }) - expect(weight_cache.weight_total).to eq(2) + expect(extra_fields.vote_weight_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_weight_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(vote_weight_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_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.weight_cache.totals).to eq({ "1" => 1 }) - expect(another_proposal.weight_cache.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 88e26a27a..bfd99c0e9 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_weight_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/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 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