diff --git a/Gemfile b/Gemfile index 4c96bb4513..410279dc57 100644 --- a/Gemfile +++ b/Gemfile @@ -22,6 +22,7 @@ gem "decidim-anonymous_proposals", DECIDIM_ANONYMOUS_PROPOSALS_VERSION gem "decidim-budget_category_voting", git: "https://github.com/alecslupu-pfa/decidim-budget_category_voting.git", branch: DECIDIM_BRANCH gem "decidim-cache_cleaner" gem "decidim-category_enhanced", "~> 0.0.1" +gem "decidim-custom_proposal_states", git: "https://github.com/alecslupu-pfa/decidim-module-custom_proposal_states", branch: DECIDIM_BRANCH gem "decidim-decidim_awesome", git: "https://github.com/decidim-ice/decidim-module-decidim_awesome", branch: "main" gem "decidim-extended_socio_demographic_authorization_handler", git: "https://github.com/OpenSourcePolitics/decidim-module-extended_socio_demographic_authorization_handler.git", branch: DECIDIM_BRANCH diff --git a/Gemfile.lock b/Gemfile.lock index 60059d8681..de12d9cb69 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -132,6 +132,16 @@ GIT decidim-core (~> 0.27.0) deface (>= 1.9) +GIT + remote: https://github.com/alecslupu-pfa/decidim-module-custom_proposal_states + revision: 66bc4d1a9f00eb66356e583365597e737e1d6917 + branch: release/0.27-stable + specs: + decidim-custom_proposal_states (0.27.5) + decidim-core (~> 0.27) + decidim-proposals (~> 0.27) + deface (>= 1.9) + GIT remote: https://github.com/decidim-ice/decidim-module-decidim_awesome revision: 058af7db47737e3ca108ac8e08efd5ec55d67a44 @@ -1154,6 +1164,7 @@ DEPENDENCIES decidim-cache_cleaner decidim-category_enhanced (~> 0.0.1) decidim-conferences (~> 0.27.0) + decidim-custom_proposal_states! decidim-decidim_awesome! decidim-dev (~> 0.27.0) decidim-extended_socio_demographic_authorization_handler! diff --git a/db/migrate/20240812083116_create_decidim_proposals_proposal_state.decidim_custom_proposal_states.rb b/db/migrate/20240812083116_create_decidim_proposals_proposal_state.decidim_custom_proposal_states.rb new file mode 100644 index 0000000000..518c4faf64 --- /dev/null +++ b/db/migrate/20240812083116_create_decidim_proposals_proposal_state.decidim_custom_proposal_states.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true +# This migration comes from decidim_custom_proposal_states (originally 20231102173159) + +class CreateDecidimProposalsProposalState < ActiveRecord::Migration[6.0] + def change + create_table :decidim_proposals_proposal_states do |t| + t.jsonb :title + t.jsonb :description + t.jsonb :announcement_title + t.string :token, null: false + t.boolean :system, null: false, default: false + t.references :decidim_component, index: true, null: false + t.integer :proposals_count, default: 0, null: false + t.boolean :default, default: false, null: false + t.boolean :answerable, default: false, null: false + t.boolean :notifiable, default: false, null: false + t.boolean :gamified, default: false, null: false + t.json :include_in_stats, default: {}, null: false + t.string :css_class + end + end +end diff --git a/db/migrate/20240812083117_add_state_id_to_decidim_proposals_proposals.decidim_custom_proposal_states.rb b/db/migrate/20240812083117_add_state_id_to_decidim_proposals_proposals.decidim_custom_proposal_states.rb new file mode 100644 index 0000000000..085af81e1e --- /dev/null +++ b/db/migrate/20240812083117_add_state_id_to_decidim_proposals_proposals.decidim_custom_proposal_states.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true +# This migration comes from decidim_custom_proposal_states (originally 20231102173214) + +class AddStateIdToDecidimProposalsProposals < ActiveRecord::Migration[6.0] + def up + add_column :decidim_proposals_proposals, :decidim_proposals_proposal_state_id, :integer, index: true + + add_foreign_key :decidim_proposals_proposals, :decidim_proposals_proposal_states, column: :decidim_proposals_proposal_state_id + end + + def down + remove_foreign_key :decidim_proposals_proposals, column: :decidim_proposals_proposal_state_id + remove_column :decidim_proposals_proposals, :decidim_proposals_proposal_state_id + end +end diff --git a/db/migrate/20240812083118_create_default_proposal_states.decidim_custom_proposal_states.rb b/db/migrate/20240812083118_create_default_proposal_states.decidim_custom_proposal_states.rb new file mode 100644 index 0000000000..9efeb660d8 --- /dev/null +++ b/db/migrate/20240812083118_create_default_proposal_states.decidim_custom_proposal_states.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true +# This migration comes from decidim_custom_proposal_states (originally 20231102234909) + +class CreateDefaultProposalStates < ActiveRecord::Migration[6.0] + class Proposal < ApplicationRecord + belongs_to :proposal_state, + class_name: "Decidim::CustomProposalStates::ProposalState", + foreign_key: "decidim_proposals_proposal_state_id", + inverse_of: :proposals, + optional: true + + self.table_name = :decidim_proposals_proposals + end + + def up + return unless Decidim.version.to_s.include?("0.27") + + states = { + "0" => :not_answered, + "10" => :evaluating, + "20" => :accepted, + "-10" => :rejected, + "-20" => :withdrawn + } + + Proposal.where(state: "").update_all(state: "not_answered") + Proposal.where(state: nil).update_all(state: "not_answered") + + Decidim::Component.where(manifest_name: "proposals").find_each do |component| + admin_user = component.organization.admins.first + default_states = Decidim::CustomProposalStates.create_default_states!(component, admin_user).with_indifferent_access + Proposal.where(decidim_component_id: component.id).find_each do |proposal| + proposal.proposal_state = default_states.dig(proposal.state.to_s, :object) + proposal.save! + end + end + change_column_null :decidim_proposals_proposals, :decidim_proposals_proposal_state_id, false + end + + def down; end +end diff --git a/db/schema.rb b/db/schema.rb index 0459d87603..32ef219836 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2024_04_26_092405) do +ActiveRecord::Schema.define(version: 2024_08_12_083118) do # These are extensions that must be enabled in order to support this database enable_extension "ltree" @@ -1568,6 +1568,23 @@ t.index ["decidim_proposal_id"], name: "decidim_proposals_proposal_note_proposal" end + create_table "decidim_proposals_proposal_states", force: :cascade do |t| + t.jsonb "title" + t.jsonb "description" + t.jsonb "announcement_title" + t.string "token", null: false + t.boolean "system", default: false, null: false + t.bigint "decidim_component_id", null: false + t.integer "proposals_count", default: 0, null: false + t.boolean "default", default: false, null: false + t.boolean "answerable", default: false, null: false + t.boolean "notifiable", default: false, null: false + t.boolean "gamified", default: false, null: false + t.json "include_in_stats", default: {}, null: false + t.string "css_class" + t.index ["decidim_component_id"], name: "index_decidim_proposals_proposal_states_on_decidim_component_id" + end + create_table "decidim_proposals_proposal_votes", id: :serial, force: :cascade do |t| t.integer "decidim_proposal_id", null: false t.integer "decidim_author_id", null: false @@ -1609,6 +1626,7 @@ t.jsonb "body" t.integer "comments_count", default: 0, null: false t.integer "follows_count", default: 0, null: false + t.integer "decidim_proposals_proposal_state_id", null: false t.index "md5((body)::text)", name: "decidim_proposals_proposal_body_search" t.index "md5((title)::text)", name: "decidim_proposals_proposal_title_search" t.index ["created_at"], name: "index_decidim_proposals_proposals_on_created_at" @@ -2130,6 +2148,7 @@ add_foreign_key "decidim_participatory_processes", "decidim_organizations" add_foreign_key "decidim_participatory_processes", "decidim_participatory_process_types" add_foreign_key "decidim_participatory_processes", "decidim_scope_types" + add_foreign_key "decidim_proposals_proposals", "decidim_proposals_proposal_states" add_foreign_key "decidim_reminder_deliveries", "decidim_reminders" add_foreign_key "decidim_reminder_records", "decidim_reminders" add_foreign_key "decidim_reminders", "decidim_components" diff --git a/spec/commands/decidim/budgets/admin/import_proposals_to_budgets_spec.rb b/spec/commands/decidim/budgets/admin/import_proposals_to_budgets_spec.rb index 3e16332152..8dcf5dbc77 100644 --- a/spec/commands/decidim/budgets/admin/import_proposals_to_budgets_spec.rb +++ b/spec/commands/decidim/budgets/admin/import_proposals_to_budgets_spec.rb @@ -7,9 +7,9 @@ module Budgets module Admin describe ImportProposalsToBudgets do describe "call" do - let!(:proposal) { create(:proposal, :accepted) } - let!(:first_proposal) { create(:proposal, :accepted) } - let!(:second_proposal) { create(:proposal, :accepted) } + let!(:proposal) { create(:extended_proposal, :accepted) } + let!(:first_proposal) { create(:extended_proposal, :accepted) } + let!(:second_proposal) { create(:extended_proposal, :accepted) } let!(:current_component) do create( :component, diff --git a/spec/controllers/decidim/proposals/proposals_controller_spec.rb b/spec/controllers/decidim/proposals/proposals_controller_spec.rb index 5e1eedba76..27d690991c 100644 --- a/spec/controllers/decidim/proposals/proposals_controller_spec.rb +++ b/spec/controllers/decidim/proposals/proposals_controller_spec.rb @@ -23,7 +23,7 @@ module Proposals end describe "default_filter_scope_params" do - let!(:component) { create(:proposal_component) } + let!(:component) { create(:extended_proposal_component) } context "when component has no scopes" do it "returns all" do @@ -55,7 +55,7 @@ module Proposals describe "GET index" do context "when participatory texts are disabled" do - let(:component) { create(:proposal_component, :with_geocoding_enabled) } + let(:component) { create(:extended_proposal_component, :with_geocoding_enabled) } it "sorts proposals by search defaults" do get :index @@ -74,8 +74,8 @@ module Proposals end it "sets two different collections" do - geocoded_proposals = create_list :proposal, 10, component: component, latitude: 1.1, longitude: 2.2 - _non_geocoded_proposals = create_list :proposal, 2, component: component, latitude: nil, longitude: nil + geocoded_proposals = create_list :extended_proposal, 10, component: component, latitude: 1.1, longitude: 2.2 + _non_geocoded_proposals = create_list :extended_proposal, 2, component: component, latitude: nil, longitude: nil get :index expect(response).to have_http_status(:ok) @@ -87,7 +87,7 @@ module Proposals end context "when participatory texts are enabled" do - let(:component) { create(:proposal_component, :with_participatory_texts_enabled) } + let(:component) { create(:extended_proposal_component, :with_participatory_texts_enabled) } it "sorts proposals by position" do get :index @@ -97,8 +97,8 @@ module Proposals end context "when emendations exist" do - let!(:amendable) { create(:proposal, component: component) } - let!(:emendation) { create(:proposal, component: component) } + let!(:amendable) { create(:extended_proposal, component: component) } + let!(:emendation) { create(:extended_proposal, component: component) } let!(:amendment) { create(:amendment, amendable: amendable, emendation: emendation, state: "accepted") } it "does not include emendations" do @@ -112,7 +112,7 @@ module Proposals end describe "GET new" do - let(:component) { create(:proposal_component, :with_creation_enabled) } + let(:component) { create(:extended_proposal_component, :with_creation_enabled) } before { sign_in user } @@ -125,7 +125,7 @@ module Proposals end context "when draft proposals exist from other users" do - let!(:others_draft) { create(:proposal, :draft, component: component) } + let!(:others_draft) { create(:extended_proposal, :draft, component: component) } it "renders the empty form" do get :new, params: params @@ -139,7 +139,7 @@ module Proposals before { sign_in user } context "when creation is not enabled" do - let(:component) { create(:proposal_component) } + let(:component) { create(:extended_proposal_component) } it "raises an error" do post :create, params: params @@ -149,7 +149,7 @@ module Proposals end context "when creation is enabled" do - let(:component) { create(:proposal_component, :with_creation_enabled) } + let(:component) { create(:extended_proposal_component, :with_creation_enabled) } let(:proposal_params) do { component_id: component.id, @@ -168,8 +168,8 @@ module Proposals end describe "PATCH update" do - let(:component) { create(:proposal_component, :with_creation_enabled, :with_attachments_allowed) } - let(:proposal) { create(:proposal, component: component, users: [user]) } + let(:component) { create(:extended_proposal_component, :with_creation_enabled, :with_attachments_allowed) } + let(:proposal) { create(:extended_proposal, component: component, users: [user]) } let(:proposal_params) do { title: "Lorem ipsum dolor sit amet, consectetur adipiscing elit", @@ -203,7 +203,7 @@ module Proposals documents: proposal.documents.map { |a| a.id.to_s } } end - let(:proposal) { create(:proposal, :with_photo, :with_document, component: component, users: [user]) } + let(:proposal) { create(:extended_proposal, :with_photo, :with_document, component: component, users: [user]) } it "displays the editing form with errors" do patch :update, params: params @@ -218,9 +218,9 @@ module Proposals end describe "access links from creating proposal steps" do - let!(:component) { create(:proposal_component, :with_creation_enabled) } + let!(:component) { create(:extended_proposal_component, :with_creation_enabled) } let!(:current_user) { create(:user, :confirmed, organization: component.organization) } - let!(:proposal_extra) { create(:proposal, :draft, component: component, users: [current_user]) } + let!(:proposal_extra) { create(:extended_proposal, :draft, component: component, users: [current_user]) } let!(:params) do { id: proposal_extra.id, @@ -260,12 +260,12 @@ module Proposals end describe "withdraw a proposal" do - let(:component) { create(:proposal_component, :with_creation_enabled) } + let(:component) { create(:extended_proposal_component, :with_creation_enabled) } before { sign_in user } context "when an authorized user is withdrawing a proposal" do - let(:proposal) { create(:proposal, component: component, users: [user]) } + let(:proposal) { create(:extended_proposal, component: component, users: [user]) } it "withdraws the proposal" do put :withdraw, params: params.merge(id: proposal.id) @@ -277,7 +277,7 @@ module Proposals end context "and the proposal already has supports" do - let(:proposal) { create(:proposal, :with_votes, component: component, users: [user]) } + let(:proposal) { create(:extended_proposal, :with_votes, component: component, users: [user]) } it "is not able to withdraw the proposal" do put :withdraw, params: params.merge(id: proposal.id) @@ -292,7 +292,7 @@ module Proposals describe "when current user is NOT the author of the proposal" do let(:current_user) { create(:user, :confirmed, organization: component.organization) } - let(:proposal) { create(:proposal, component: component, users: [current_user]) } + let(:proposal) { create(:extended_proposal, component: component, users: [current_user]) } context "and the proposal has no supports" do it "is not able to withdraw the proposal" do @@ -310,9 +310,9 @@ module Proposals end describe "GET show" do - let!(:component) { create(:proposal_component, :with_amendments_enabled) } - let!(:amendable) { create(:proposal, component: component) } - let!(:emendation) { create(:proposal, component: component) } + let!(:component) { create(:extended_proposal_component, :with_amendments_enabled) } + let!(:amendable) { create(:extended_proposal, component: component) } + let!(:emendation) { create(:extended_proposal, component: component) } let!(:amendment) { create(:amendment, amendable: amendable, emendation: emendation) } let(:active_step_id) { component.participatory_space.active_step.id } diff --git a/spec/factories.rb b/spec/factories.rb index 3a7bdad7e9..25c93ab5ed 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -13,3 +13,4 @@ require "decidim/forms/test/factories" require "decidim/surveys/test/factories" require "decidim/initiatives/test/factories" +require "decidim/custom_proposal_states/test/factories" diff --git a/spec/lib/decidim/proposals/import/proposal_answer_creator_spec.rb b/spec/lib/decidim/proposals/import/proposal_answer_creator_spec.rb index 1c4fb72925..076fb02887 100644 --- a/spec/lib/decidim/proposals/import/proposal_answer_creator_spec.rb +++ b/spec/lib/decidim/proposals/import/proposal_answer_creator_spec.rb @@ -5,7 +5,7 @@ describe Decidim::Proposals::Import::ProposalAnswerCreator do subject { described_class.new(data, context) } - let(:proposal) { create(:proposal, state: state, component: component) } + let(:proposal) { create(:extended_proposal, state: state, component: component) } let!(:moment) { Time.current } let(:data) do { @@ -25,7 +25,7 @@ } end let(:participatory_process) { create :participatory_process, organization: organization } - let(:component) { create :component, manifest_name: :proposals, participatory_space: participatory_process } + let(:component) { create :extended_proposal_component, participatory_space: participatory_process } let(:state) { %w(evaluating accepted rejected).sample } describe "#resource_klass" do @@ -51,12 +51,12 @@ expect(record).to be_a(Decidim::Proposals::Proposal) expect(record.id).to eq(data[:id]) expect(record.answer["en"]).to eq(data[:"answer/en"]) - expect(record[:state]).to eq(data[:state]) + expect(record.state).to eq(data[:state]) expect(record.answered_at).to be >= (moment) end context "with an emendation" do - let!(:amendable) { create(:proposal, component: component) } + let!(:amendable) { create(:extended_proposal, component: component) } let!(:amendment) { create(:amendment, amendable: amendable, emendation: proposal, state: "evaluating") } it "does not produce a record" do @@ -83,14 +83,17 @@ expect(log.action).to eq("answer") end - shared_examples "it notifies follower" do + context "when proposal state changes" do + let!(:proposal) { create(:extended_proposal, :evaluating, component: component) } + let(:state) { "accepted" } + it "returns broadcast :ok" do expect(subject.finish!).to eq({ ok: [] }) end context "and notifies followers" do before do - allow(::Decidim::Proposals::Admin::NotifyProposalAnswer).to receive(:call).with(proposal, expected_state) + allow(::Decidim::Proposals::Admin::NotifyProposalAnswer).to receive(:call).with(proposal, proposal.proposal_state) end it "notifies followers" do @@ -100,32 +103,6 @@ end end - context "when proposal state changes" do - context "when proposal had already a state" do - let!(:proposal) { create(:proposal, :evaluating, component: component) } - let(:state) { "accepted" } - let(:expected_state) { "evaluating" } - - include_examples "it notifies follower" - end - - context "when proposal had no state" do - let!(:proposal) { create(:proposal, :not_answered, component: component) } - let(:state) { "accepted" } - let(:expected_state) { "" } - - include_examples "it notifies follower" - end - - context "when proposal was just created and had a state set to nil" do - let!(:proposal) { create(:proposal, component: component, state: nil) } - let(:state) { "accepted" } - let(:expected_state) { "" } - - include_examples "it notifies follower" - end - end - context "when proposal does not exist" do let(:data) do { diff --git a/spec/services/decidim/proposals/proposal_serializer_spec.rb b/spec/services/decidim/proposals/proposal_serializer_spec.rb index 37be70a21b..9a53bc58a7 100644 --- a/spec/services/decidim/proposals/proposal_serializer_spec.rb +++ b/spec/services/decidim/proposals/proposal_serializer_spec.rb @@ -13,7 +13,7 @@ module Proposals create(:organization, available_authorizations: ["phone_authorization_handler"]) end - let!(:proposal) { create(:proposal, :accepted) } + let!(:proposal) { create(:extended_proposal, :accepted) } let!(:category) { create(:category, participatory_space: component.participatory_space) } let!(:scope) { create(:scope, organization: component.participatory_space.organization) } let(:participatory_process) { component.participatory_space } @@ -22,7 +22,7 @@ module Proposals let!(:meetings_component) { create(:component, manifest_name: "meetings", participatory_space: participatory_process) } let(:meetings) { create_list(:meeting, 2, component: meetings_component) } - let!(:proposals_component) { create(:component, manifest_name: "proposals", participatory_space: participatory_process) } + let!(:proposals_component) { create(:extended_proposal_component, manifest_name: "proposals", participatory_space: participatory_process) } let!(:authorization) do create( @@ -191,7 +191,7 @@ module Proposals end context "with proposal having an answer" do - let!(:proposal) { create(:proposal, :with_answer) } + let!(:proposal) { create(:extended_proposal, :with_answer) } it "serializes the answer" do expect(serialized).to include(answer: expected_answer) diff --git a/spec/services/decidim/repair_translations_service_spec.rb b/spec/services/decidim/repair_translations_service_spec.rb index 43f3ac8b4a..580de39fe4 100644 --- a/spec/services/decidim/repair_translations_service_spec.rb +++ b/spec/services/decidim/repair_translations_service_spec.rb @@ -6,7 +6,7 @@ subject { described_class.new } let!(:comments) { create_list(:comment, 10) } - let!(:proposals) { create_list(:proposal, 10) } + let!(:proposals) { create_list(:extended_proposal, 10) } describe "#translatable_resources" do it "returns all translatable resources" do diff --git a/spec/system/participatory_processes_spec.rb b/spec/system/participatory_processes_spec.rb index d5723bf233..cacfdff136 100644 --- a/spec/system/participatory_processes_spec.rb +++ b/spec/system/participatory_processes_spec.rb @@ -295,7 +295,7 @@ let!(:meetings_component) { create(:component, :unpublished, participatory_space: participatory_process, manifest_name: :meetings) } before do - create_list(:proposal, 3, component: proposals_component) + create_list(:extended_proposal, 3, component: proposals_component) allow(Decidim).to receive(:component_manifests).and_return([proposals_component.manifest, meetings_component.manifest]) end diff --git a/spec/system/proposals_spec.rb b/spec/system/proposals_spec.rb index 17e3d7f2ca..cc885ad25b 100644 --- a/spec/system/proposals_spec.rb +++ b/spec/system/proposals_spec.rb @@ -36,7 +36,7 @@ context "when viewing a single proposal" do let!(:component) do - create(:proposal_component, + create(:extended_proposal_component, manifest: manifest, participatory_space: participatory_process, settings: { @@ -45,7 +45,7 @@ }) end - let!(:proposals) { create_list(:proposal, 3, component: component) } + let!(:proposals) { create_list(:extended_proposal, 3, component: component) } let!(:proposal) { proposals.first } it_behaves_like "accessible page" do @@ -68,7 +68,7 @@ end context "when process is not related to any scope" do - let!(:proposal) { create(:proposal, component: component, scope: scope) } + let!(:proposal) { create(:extended_proposal, component: component, scope: scope) } it "can be filtered by scope" do visit_component @@ -78,7 +78,7 @@ end context "when process is related to a child scope" do - let!(:proposal) { create(:proposal, component: component, scope: scope) } + let!(:proposal) { create(:extended_proposal, component: component, scope: scope) } let(:participatory_process) { scoped_participatory_process } it "does not show the scope name" do @@ -90,7 +90,7 @@ context "when it is an official proposal" do let(:content) { generate_localized_title } - let!(:official_proposal) { create(:proposal, :official, body: content, component: component) } + let!(:official_proposal) { create(:extended_proposal, :official, body: content, component: component) } let!(:official_proposal_title) { translated(official_proposal.title) } before do @@ -106,7 +106,7 @@ end context "when rich text editor is enabled for participants" do - let!(:proposal) { create(:proposal, body: content, component: component) } + let!(:proposal) { create(:extended_proposal, body: content, component: component) } before do organization.update(rich_text_editor_in_public_views: true) @@ -118,7 +118,7 @@ end context "when rich text editor is NOT enabled for participants" do - let!(:proposal) { create(:proposal, body: content, component: component) } + let!(:proposal) { create(:extended_proposal, body: content, component: component) } before do visit_component @@ -130,12 +130,12 @@ context "when it is a proposal with image" do let!(:component) do - create(:proposal_component, + create(:extended_proposal_component, manifest: manifest, participatory_space: participatory_process) end - let!(:proposal) { create(:proposal, component: component) } + let!(:proposal) { create(:extended_proposal, component: component) } let!(:image) { create(:attachment, attached_to: proposal) } it "shows the card image" do @@ -148,7 +148,7 @@ context "when it is an official meeting proposal" do include_context "with rich text editor content" - let!(:proposal) { create(:proposal, :official_meeting, body: content, component: component) } + let!(:proposal) { create(:extended_proposal, :official_meeting, body: content, component: component) } before do visit_component @@ -163,7 +163,7 @@ end context "when a proposal has comments" do - let(:proposal) { create(:proposal, component: component) } + let(:proposal) { create(:extended_proposal, component: component) } let(:author) { create(:user, :confirmed, organization: component.organization) } let!(:comments) { create_list(:comment, 3, commentable: proposal) } @@ -180,7 +180,7 @@ context "when a proposal has costs" do let!(:proposal) do create( - :proposal, + :extended_proposal, :accepted, :with_answer, component: component, @@ -210,7 +210,7 @@ end context "when a proposal has been linked in a meeting" do - let(:proposal) { create(:proposal, component: component) } + let(:proposal) { create(:extended_proposal, component: component) } let(:meeting_component) do create(:component, manifest_name: :meetings, participatory_space: proposal.component.participatory_space) end @@ -229,7 +229,7 @@ end context "when a proposal has been linked in a result" do - let(:proposal) { create(:proposal, component: component) } + let(:proposal) { create(:extended_proposal, component: component) } let(:accountability_component) do create(:component, manifest_name: :accountability, participatory_space: proposal.component.participatory_space) end @@ -248,7 +248,7 @@ end context "when a proposal is in evaluation" do - let!(:proposal) { create(:proposal, :with_answer, :evaluating, component: component) } + let!(:proposal) { create(:extended_proposal, :with_answer, :evaluating, component: component) } it "shows a badge and an answer" do visit_component @@ -264,7 +264,7 @@ end context "when a proposal has been rejected" do - let!(:proposal) { create(:proposal, :with_answer, :rejected, component: component) } + let!(:proposal) { create(:extended_proposal, :with_answer, :rejected, component: component) } it "shows the rejection reason" do visit_component @@ -284,7 +284,7 @@ end context "when a proposal has been accepted" do - let!(:proposal) { create(:proposal, :with_answer, :accepted, component: component) } + let!(:proposal) { create(:extended_proposal, :with_answer, :accepted, component: component) } it "shows the acceptance reason" do visit_component @@ -300,7 +300,7 @@ end context "when the proposal answer has not been published" do - let!(:proposal) { create(:proposal, :accepted_not_published, component: component) } + let!(:proposal) { create(:extended_proposal, :accepted_not_published, component: component) } it "shows the acceptance reason" do visit_component @@ -331,11 +331,11 @@ context "when a proposal has been linked in a project" do let(:component) do - create(:proposal_component, + create(:extended_proposal_component, manifest: manifest, participatory_space: participatory_process) end - let(:proposal) { create(:proposal, component: component) } + let(:proposal) { create(:extended_proposal, component: component) } let(:budget_component) do create(:component, manifest_name: :budgets, participatory_space: proposal.component.participatory_space) end @@ -355,8 +355,8 @@ context "when listing proposals in a participatory process" do shared_examples_for "a random proposal ordering" do - let!(:lucky_proposal) { create(:proposal, component: component) } - let!(:unlucky_proposal) { create(:proposal, component: component) } + let!(:lucky_proposal) { create(:extended_proposal, component: component) } + let!(:unlucky_proposal) { create(:extended_proposal, component: component) } let!(:lucky_proposal_title) { translated(lucky_proposal.title) } let!(:unlucky_proposal_title) { translated(unlucky_proposal.title) } @@ -376,11 +376,11 @@ end it "lists all the proposals" do - create(:proposal_component, + create(:extended_proposal_component, manifest: manifest, participatory_space: participatory_process) - create_list(:proposal, 3, component: component) + create_list(:extended_proposal, 3, component: component) visit_component expect(page).to have_css(".card--proposal", count: 3) @@ -393,7 +393,7 @@ end context "when comments have been moderated" do - let(:proposal) { create(:proposal, component: component) } + let(:proposal) { create(:extended_proposal, component: component) } let(:author) { create(:user, :confirmed, organization: component.organization) } let!(:comments) { create_list(:comment, 3, commentable: proposal) } let!(:moderation) { create :moderation, reportable: comments.first, hidden_at: 1.day.ago } @@ -415,20 +415,20 @@ context "when voting phase is over" do let!(:component) do - create(:proposal_component, + create(:extended_proposal_component, :with_votes_blocked, manifest: manifest, participatory_space: participatory_process) end let!(:most_voted_proposal) do - proposal = create(:proposal, component: component) + proposal = create(:extended_proposal, component: component) create_list(:proposal_vote, 3, proposal: proposal) proposal end let!(:most_voted_proposal_title) { translated(most_voted_proposal.title) } - let!(:less_voted_proposal) { create(:proposal, component: component) } + let!(:less_voted_proposal) { create(:extended_proposal, component: component) } let!(:less_voted_proposal_title) { translated(less_voted_proposal.title) } before { visit_component } @@ -447,7 +447,7 @@ context "when voting is disabled" do let!(:component) do - create(:proposal_component, + create(:extended_proposal_component, :with_votes_disabled, manifest: manifest, participatory_space: participatory_process) @@ -458,7 +458,7 @@ end it "shows only links to full proposals" do - create_list(:proposal, 2, component: component) + create_list(:extended_proposal, 2, component: component) visit_component @@ -470,7 +470,7 @@ context "when there are a lot of proposals" do before do - create_list(:proposal, Decidim::Paginable::OPTIONS.first + 5, component: component) + create_list(:extended_proposal, Decidim::Paginable::OPTIONS.first + 5, component: component) end it "paginates them" do @@ -506,14 +506,14 @@ context "when ordering by 'most_voted'" do let!(:component) do - create(:proposal_component, + create(:extended_proposal_component, :with_votes_enabled, manifest: manifest, participatory_space: participatory_process) end - let!(:most_voted_proposal) { create(:proposal, component: component) } + let!(:most_voted_proposal) { create(:extended_proposal, component: component) } let!(:votes) { create_list(:proposal_vote, 3, proposal: most_voted_proposal) } - let!(:less_voted_proposal) { create(:proposal, component: component) } + let!(:less_voted_proposal) { create(:extended_proposal, component: component) } it_behaves_like "ordering proposals by selected option", "Most supported" do let(:first_proposal) { most_voted_proposal } @@ -522,8 +522,8 @@ end context "when ordering by 'recent'" do - let!(:older_proposal) { create(:proposal, component: component, created_at: 1.month.ago) } - let!(:recent_proposal) { create(:proposal, component: component) } + let!(:older_proposal) { create(:extended_proposal, component: component, created_at: 1.month.ago) } + let!(:recent_proposal) { create(:extended_proposal, component: component) } it_behaves_like "ordering proposals by selected option", "Recent" do let(:first_proposal) { recent_proposal } @@ -532,9 +532,9 @@ end context "when ordering by 'most_followed'" do - let!(:most_followed_proposal) { create(:proposal, component: component) } + let!(:most_followed_proposal) { create(:extended_proposal, component: component) } let!(:follows) { create_list(:follow, 3, followable: most_followed_proposal) } - let!(:less_followed_proposal) { create(:proposal, component: component) } + let!(:less_followed_proposal) { create(:extended_proposal, component: component) } it_behaves_like "ordering proposals by selected option", "Most followed" do let(:first_proposal) { most_followed_proposal } @@ -543,9 +543,9 @@ end context "when ordering by 'most_commented'" do - let!(:most_commented_proposal) { create(:proposal, component: component, created_at: 1.month.ago) } + let!(:most_commented_proposal) { create(:extended_proposal, component: component, created_at: 1.month.ago) } let!(:comments) { create_list(:comment, 3, commentable: most_commented_proposal) } - let!(:less_commented_proposal) { create(:proposal, component: component) } + let!(:less_commented_proposal) { create(:extended_proposal, component: component) } it_behaves_like "ordering proposals by selected option", "Most commented" do let(:first_proposal) { most_commented_proposal } @@ -554,13 +554,13 @@ end context "when ordering by 'most_endorsed'" do - let!(:most_endorsed_proposal) { create(:proposal, component: component, created_at: 1.month.ago) } + let!(:most_endorsed_proposal) { create(:extended_proposal, component: component, created_at: 1.month.ago) } let!(:endorsements) do 3.times.collect do create(:endorsement, resource: most_endorsed_proposal, author: build(:user, organization: organization)) end end - let!(:less_endorsed_proposal) { create(:proposal, component: component) } + let!(:less_endorsed_proposal) { create(:extended_proposal, component: component) } it_behaves_like "ordering proposals by selected option", "Most endorsed" do let(:first_proposal) { most_endorsed_proposal } @@ -569,9 +569,9 @@ end context "when ordering by 'with_more_authors'" do - let!(:most_authored_proposal) { create(:proposal, component: component, created_at: 1.month.ago) } + let!(:most_authored_proposal) { create(:extended_proposal, component: component, created_at: 1.month.ago) } let!(:coauthorships) { create_list(:coauthorship, 3, coauthorable: most_authored_proposal) } - let!(:less_authored_proposal) { create(:proposal, component: component) } + let!(:less_authored_proposal) { create(:extended_proposal, component: component) } it_behaves_like "ordering proposals by selected option", "With more authors" do let(:first_proposal) { most_authored_proposal } @@ -582,9 +582,9 @@ context "when searching proposals" do let!(:proposals) do [ - create(:proposal, title: "Lorem ipsum dolor sit amet", component: component), - create(:proposal, title: "Donec vitae convallis augue", component: component), - create(:proposal, title: "Pellentesque habitant morbi", component: component) + create(:extended_proposal, title: "Lorem ipsum dolor sit amet", component: component), + create(:extended_proposal, title: "Donec vitae convallis augue", component: component), + create(:extended_proposal, title: "Pellentesque habitant morbi", component: component) ] end @@ -603,14 +603,14 @@ end context "when paginating" do - let!(:collection) { create_list :proposal, collection_size, component: component } + let!(:collection) { create_list :extended_proposal, collection_size, component: component } let!(:resource_selector) { ".card--proposal" } it_behaves_like "a paginated resource" end context "when component is not commentable" do - let!(:resources) { create_list(:proposal, 3, component: component) } + let!(:resources) { create_list(:extended_proposal, 3, component: component) } it_behaves_like "an uncommentable component" end