From 3f79cfd1497b36dd9622faa30e0c1f5716090389 Mon Sep 17 00:00:00 2001 From: Elie Gaboriau Date: Tue, 8 Nov 2022 16:21:54 +0100 Subject: [PATCH 1/6] first version --- .../admin/translation_sets_controller.rb | 4 +++- .../admin/translation_set_subject_form.rb | 8 ++++--- .../admin/application_helper.rb | 4 ++++ .../decidim/term_customizer/constraint.rb | 4 +++- .../context/controller_context.rb | 5 +++++ .../admin/application_helper_spec.rb | 7 +++++++ .../context/controller_context_spec.rb | 21 +++++++++++++++++++ 7 files changed, 48 insertions(+), 5 deletions(-) diff --git a/app/controllers/decidim/term_customizer/admin/translation_sets_controller.rb b/app/controllers/decidim/term_customizer/admin/translation_sets_controller.rb index 8a2cba8..6fffa8f 100644 --- a/app/controllers/decidim/term_customizer/admin/translation_sets_controller.rb +++ b/app/controllers/decidim/term_customizer/admin/translation_sets_controller.rb @@ -5,6 +5,7 @@ module TermCustomizer module Admin class TranslationSetsController < TermCustomizer::Admin::ApplicationController include TranslatableAttributes + include ApplicationHelper helper_method :collection, :subject_manifests, :blank_constraint @@ -23,6 +24,7 @@ def new def create enforce_permission_to :create, :translation_set + @form = form(TranslationSetForm).from_params( params, current_organization: current_organization @@ -117,7 +119,7 @@ def sets alias collection sets def subject_manifests - @subject_manifests ||= Decidim.participatory_space_manifests.map do |manifest| + @subject_manifests ||= manifests.map do |manifest| models = manifest.model_class_name.constantize.where(organization: current_organization).map { |p| [translated_attribute(p.title), p.id] } next unless models.count.positive? diff --git a/app/forms/decidim/term_customizer/admin/translation_set_subject_form.rb b/app/forms/decidim/term_customizer/admin/translation_set_subject_form.rb index 49b97bc..9979aa3 100644 --- a/app/forms/decidim/term_customizer/admin/translation_set_subject_form.rb +++ b/app/forms/decidim/term_customizer/admin/translation_set_subject_form.rb @@ -4,6 +4,8 @@ module Decidim module TermCustomizer module Admin class TranslationSetSubjectForm < Decidim::Form + include ApplicationHelper + attribute :subject_manifest, String attribute :subject_id, Integer attribute :component_model, Array[TermCustomizer::Admin::TranslationSetSubjectComponentForm] @@ -16,7 +18,7 @@ def map_model(model) model end - self.subject_manifest = Decidim.participatory_space_manifests.find do |m| + self.subject_manifest = manifests.find do |m| m.model_class_name == subject.class.name end.try(:name) self.subject_id = subject.id @@ -46,8 +48,8 @@ def component end def manifest - @manifest ||= Decidim.participatory_space_manifests.find do |m| - m.name == subject_manifest.to_sym + @manifest ||= manifests.find do |m| + m.name.to_sym == subject_manifest.to_sym end end diff --git a/app/helpers/decidim/term_customizer/admin/application_helper.rb b/app/helpers/decidim/term_customizer/admin/application_helper.rb index d636aeb..748c808 100644 --- a/app/helpers/decidim/term_customizer/admin/application_helper.rb +++ b/app/helpers/decidim/term_customizer/admin/application_helper.rb @@ -7,6 +7,10 @@ module ApplicationHelper def tabs_id_for_constraint(constraint) "constraint_#{constraint.to_param}" end + + def manifests + Decidim.participatory_space_manifests + [Decidim.find_resource_manifest(:participatory_process_group)] + end end end end diff --git a/app/models/decidim/term_customizer/constraint.rb b/app/models/decidim/term_customizer/constraint.rb index 7ae2505..d230914 100644 --- a/app/models/decidim/term_customizer/constraint.rb +++ b/app/models/decidim/term_customizer/constraint.rb @@ -3,6 +3,8 @@ module Decidim module TermCustomizer class Constraint < TermCustomizer::ApplicationRecord + include Decidim::TermCustomizer::Admin::ApplicationHelper + self.table_name = "decidim_term_customizer_constraints" belongs_to :organization, foreign_key: :decidim_organization_id, class_name: "Decidim::Organization" @@ -23,7 +25,7 @@ def space def manifest space_class = space ? space.class.name : subject_type - Decidim.participatory_space_manifests.find do |manifest| + manifests.find do |manifest| manifest.model_class_name == space_class end end diff --git a/lib/decidim/term_customizer/context/controller_context.rb b/lib/decidim/term_customizer/context/controller_context.rb index 34d3bb0..5184369 100644 --- a/lib/decidim/term_customizer/context/controller_context.rb +++ b/lib/decidim/term_customizer/context/controller_context.rb @@ -27,6 +27,11 @@ def resolve! # we take this into account here. end end + + if controller.respond_to?(:set_group, true) + @space = controller.send(:set_group) + end + @space ||= env["decidim.current_participatory_space"] @component = env["decidim.current_component"] diff --git a/spec/helpers/decidim/term_customizer/admin/application_helper_spec.rb b/spec/helpers/decidim/term_customizer/admin/application_helper_spec.rb index 5b2f3c6..703f367 100644 --- a/spec/helpers/decidim/term_customizer/admin/application_helper_spec.rb +++ b/spec/helpers/decidim/term_customizer/admin/application_helper_spec.rb @@ -11,4 +11,11 @@ expect(helper.tabs_id_for_constraint(constraint)).to eq("constraint_test") end end + + describe "#manifests" do + it "returns the expected manifests" do + expect(helper.manifests.size).to equal(Decidim.participatory_space_manifests.size+1) + expect(helper.manifests).to include(Decidim.find_resource_manifest(:participatory_process_group)) + end + end end diff --git a/spec/lib/decidim/term_customizer/context/controller_context_spec.rb b/spec/lib/decidim/term_customizer/context/controller_context_spec.rb index d24f604..4ba698d 100644 --- a/spec/lib/decidim/term_customizer/context/controller_context_spec.rb +++ b/spec/lib/decidim/term_customizer/context/controller_context_spec.rb @@ -100,4 +100,25 @@ expect(subject.component).to be(component) end end + + context "with participatory process group defined in the controller" do + let(:env) do + { + "action_controller.instance" => controller, + "decidim.current_organization" => organization + } + end + + let(:process_group) { double } + + before do + allow(controller).to receive(:current_participatory_space).and_return(process_group) + end + + it "resolves the participatory space as the participatory_process group" do + expect(subject.organization).to be(organization) + expect(subject.space).to be(process_group) + expect(subject.component).to be_nil + end + end end From f26052e432b7659e75991d7f4328cb24ff1dd91e Mon Sep 17 00:00:00 2001 From: Elie Gaboriau Date: Tue, 8 Nov 2022 16:26:41 +0100 Subject: [PATCH 2/6] linter --- lib/decidim/term_customizer/context/controller_context.rb | 4 +--- .../decidim/term_customizer/admin/application_helper_spec.rb | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/decidim/term_customizer/context/controller_context.rb b/lib/decidim/term_customizer/context/controller_context.rb index 5184369..98275da 100644 --- a/lib/decidim/term_customizer/context/controller_context.rb +++ b/lib/decidim/term_customizer/context/controller_context.rb @@ -28,9 +28,7 @@ def resolve! end end - if controller.respond_to?(:set_group, true) - @space = controller.send(:set_group) - end + @space = controller.send(:set_group) if controller.respond_to?(:set_group, true) @space ||= env["decidim.current_participatory_space"] diff --git a/spec/helpers/decidim/term_customizer/admin/application_helper_spec.rb b/spec/helpers/decidim/term_customizer/admin/application_helper_spec.rb index 703f367..81c86c7 100644 --- a/spec/helpers/decidim/term_customizer/admin/application_helper_spec.rb +++ b/spec/helpers/decidim/term_customizer/admin/application_helper_spec.rb @@ -14,7 +14,7 @@ describe "#manifests" do it "returns the expected manifests" do - expect(helper.manifests.size).to equal(Decidim.participatory_space_manifests.size+1) + expect(helper.manifests.size).to equal(Decidim.participatory_space_manifests.size + 1) expect(helper.manifests).to include(Decidim.find_resource_manifest(:participatory_process_group)) end end From c1730e048b30af4a262b6f8dce017a9be8498b3d Mon Sep 17 00:00:00 2001 From: Elie Gaboriau Date: Wed, 9 Nov 2022 16:59:36 +0100 Subject: [PATCH 3/6] refactor context and resolver --- lib/decidim/term_customizer/context/base.rb | 2 +- .../context/controller_context.rb | 4 +- lib/decidim/term_customizer/engine.rb | 6 +- lib/decidim/term_customizer/resolver.rb | 24 ++++++- .../context/controller_context_spec.rb | 10 +-- .../decidim/term_customizer/resolver_spec.rb | 67 ++++++++++++++++++- 6 files changed, 102 insertions(+), 11 deletions(-) diff --git a/lib/decidim/term_customizer/context/base.rb b/lib/decidim/term_customizer/context/base.rb index 77ece27..4e3aa91 100644 --- a/lib/decidim/term_customizer/context/base.rb +++ b/lib/decidim/term_customizer/context/base.rb @@ -15,7 +15,7 @@ module Context # space and component). These are then used to load the correct # translations for each context based on the translation set constraints. class Base - attr_reader :organization, :space, :component + attr_reader :organization, :space, :component, :participatory_process_group def initialize(data) @data = data diff --git a/lib/decidim/term_customizer/context/controller_context.rb b/lib/decidim/term_customizer/context/controller_context.rb index 98275da..361cb45 100644 --- a/lib/decidim/term_customizer/context/controller_context.rb +++ b/lib/decidim/term_customizer/context/controller_context.rb @@ -28,7 +28,9 @@ def resolve! end end - @space = controller.send(:set_group) if controller.respond_to?(:set_group, true) + @participatory_process_group = if controller.instance_of?(Decidim::ParticipatoryProcesses::ParticipatoryProcessGroupsController) + Decidim::ParticipatoryProcessGroup.where(organization: @organization).find(controller.params[:id]) + end @space ||= env["decidim.current_participatory_space"] diff --git a/lib/decidim/term_customizer/engine.rb b/lib/decidim/term_customizer/engine.rb index 82f44ce..d1534fa 100644 --- a/lib/decidim/term_customizer/engine.rb +++ b/lib/decidim/term_customizer/engine.rb @@ -23,7 +23,8 @@ class Engine < ::Rails::Engine resolver = Resolver.new( context.organization, context.space, - context.component + context.component, + context.participatory_process_group ) # Create the loader for the backend to fetch the translations from @@ -53,7 +54,8 @@ class Engine < ::Rails::Engine resolver = Resolver.new( context.organization, context.space, - context.component + context.component, + context.participatory_process_group ) # Create the loader for the backend to fetch the translations from diff --git a/lib/decidim/term_customizer/resolver.rb b/lib/decidim/term_customizer/resolver.rb index 4ce043e..d36a6f7 100644 --- a/lib/decidim/term_customizer/resolver.rb +++ b/lib/decidim/term_customizer/resolver.rb @@ -3,12 +3,13 @@ module Decidim module TermCustomizer class Resolver - attr_reader :organization, :space, :component + attr_reader :organization, :space, :component, :participatory_process_group - def initialize(organization, space, component) + def initialize(organization, space, component, participatory_process_group) @organization = organization @space = space @component = component + @participatory_process_group = participatory_process_group end def translations @@ -54,6 +55,7 @@ def resolve_constraints_query constraints_add_organization_query(query) constraints_add_space_query(query) constraints_add_component_query(query) + constraints_add_participatory_process_group_query(query) query end @@ -93,6 +95,24 @@ def constraints_add_space_query(query) ) end + def constraints_add_participatory_process_group_query(query) + return unless participatory_process_group + + query.or!( + TermCustomizer::Constraint.where( + organization: organization, + subject: participatory_process_group + ) + ) + query.or!( + TermCustomizer::Constraint.where( + organization: organization, + subject_type: participatory_process_group.class.name, + subject_id: nil + ) + ) + end + def constraints_add_component_query(query) return unless component diff --git a/spec/lib/decidim/term_customizer/context/controller_context_spec.rb b/spec/lib/decidim/term_customizer/context/controller_context_spec.rb index 4ba698d..f760d41 100644 --- a/spec/lib/decidim/term_customizer/context/controller_context_spec.rb +++ b/spec/lib/decidim/term_customizer/context/controller_context_spec.rb @@ -7,7 +7,7 @@ let(:data) { { headers: headers } } let(:headers) { double } let(:controller) { double } - let(:organization) { double } + let(:organization) { create(:organization) } before do allow(headers).to receive(:env).and_return(env) @@ -109,15 +109,17 @@ } end - let(:process_group) { double } + let(:process_group) { create(:participatory_process_group, organization: organization) } before do - allow(controller).to receive(:current_participatory_space).and_return(process_group) + allow(controller).to receive(:params).and_return({ id: process_group.id }) + allow(controller).to receive(:instance_of?).with(Decidim::ParticipatoryProcesses::ParticipatoryProcessGroupsController).and_return(true) end it "resolves the participatory space as the participatory_process group" do expect(subject.organization).to be(organization) - expect(subject.space).to be(process_group) + expect(subject.space).to be_nil + expect(subject.participatory_process_group).to eq(process_group) expect(subject.component).to be_nil end end diff --git a/spec/lib/decidim/term_customizer/resolver_spec.rb b/spec/lib/decidim/term_customizer/resolver_spec.rb index 860f234..12dad6c 100644 --- a/spec/lib/decidim/term_customizer/resolver_spec.rb +++ b/spec/lib/decidim/term_customizer/resolver_spec.rb @@ -3,10 +3,11 @@ require "spec_helper" describe Decidim::TermCustomizer::Resolver do - let(:subject) { described_class.new(organization, space, component) } + let(:subject) { described_class.new(organization, space, component, group) } let(:organization) { create(:organization) } let(:space) { nil } let(:component) { nil } + let(:group) { nil } let(:set) { create(:translation_set) } let(:constraint) { set.constraints.create!(organization: organization) } @@ -95,6 +96,70 @@ end end + context "with participatory process group" do + let(:group) { create(:participatory_process_group, organization: organization) } + let(:other_group) { create(:participatory_process_group, organization: organization) } + let(:other_set) { create(:translation_set) } + + let(:constraint) do + set.constraints.create!( + organization: organization, + subject: group + ) + end + let!(:other_constraint) do + other_set.constraints.create!( + organization: organization, + subject: other_group + ) + end + + describe "#constraints" do + it "returns correct constraints" do + expect(subject.constraints).to contain_exactly(constraint) + end + end + + describe "#translations" do + let(:translations) { create_list(:translation, 10, translation_set: set) } + let!(:other_translations) { create_list(:translation, 10, translation_set: other_set) } + + it "returns correct translations" do + expect(subject.translations).to match_array(translations) + end + end + + context "when constraints are set for the subject type" do + let(:constraint) do + set.constraints.create!( + organization: organization, + subject_type: group.class.name + ) + end + let!(:other_constraint) do + other_set.constraints.create!( + organization: organization, + subject_type: other_group.class.name + ) + end + + describe "#constraints" do + it "returns correct constraints" do + expect(subject.constraints).to contain_exactly(constraint, other_constraint) + end + end + + describe "#translations" do + let(:translations) { create_list(:translation, 10, translation_set: set) } + let!(:other_translations) { create_list(:translation, 10, translation_set: other_set) } + + it "returns correct translations" do + expect(subject.translations).to match_array(translations + other_translations) + end + end + end + end + context "with component process" do let(:space) { create(:participatory_process, organization: organization) } let(:component) { create(:proposal_component, participatory_space: space) } From c1ccb0f7e7220da8fd025dd71a55691770135f86 Mon Sep 17 00:00:00 2001 From: Elie Gaboriau Date: Mon, 27 Mar 2023 16:05:42 +0200 Subject: [PATCH 4/6] remove participatory process coupling --- lib/decidim/term_customizer/context/base.rb | 2 +- .../context/controller_context.rb | 8 ++++--- lib/decidim/term_customizer/engine.rb | 6 ++--- lib/decidim/term_customizer/resolver.rb | 22 +------------------ 4 files changed, 9 insertions(+), 29 deletions(-) diff --git a/lib/decidim/term_customizer/context/base.rb b/lib/decidim/term_customizer/context/base.rb index 4e3aa91..77ece27 100644 --- a/lib/decidim/term_customizer/context/base.rb +++ b/lib/decidim/term_customizer/context/base.rb @@ -15,7 +15,7 @@ module Context # space and component). These are then used to load the correct # translations for each context based on the translation set constraints. class Base - attr_reader :organization, :space, :component, :participatory_process_group + attr_reader :organization, :space, :component def initialize(data) @data = data diff --git a/lib/decidim/term_customizer/context/controller_context.rb b/lib/decidim/term_customizer/context/controller_context.rb index 361cb45..63df438 100644 --- a/lib/decidim/term_customizer/context/controller_context.rb +++ b/lib/decidim/term_customizer/context/controller_context.rb @@ -28,9 +28,11 @@ def resolve! end end - @participatory_process_group = if controller.instance_of?(Decidim::ParticipatoryProcesses::ParticipatoryProcessGroupsController) - Decidim::ParticipatoryProcessGroup.where(organization: @organization).find(controller.params[:id]) - end + if defined?(Decidim::ParticipatoryProcesses) + @space = if controller.instance_of?(Decidim::ParticipatoryProcesses::ParticipatoryProcessGroupsController) + Decidim::ParticipatoryProcessGroup.where(organization: @organization).find(controller.params[:id]) + end + end @space ||= env["decidim.current_participatory_space"] diff --git a/lib/decidim/term_customizer/engine.rb b/lib/decidim/term_customizer/engine.rb index d1534fa..82f44ce 100644 --- a/lib/decidim/term_customizer/engine.rb +++ b/lib/decidim/term_customizer/engine.rb @@ -23,8 +23,7 @@ class Engine < ::Rails::Engine resolver = Resolver.new( context.organization, context.space, - context.component, - context.participatory_process_group + context.component ) # Create the loader for the backend to fetch the translations from @@ -54,8 +53,7 @@ class Engine < ::Rails::Engine resolver = Resolver.new( context.organization, context.space, - context.component, - context.participatory_process_group + context.component ) # Create the loader for the backend to fetch the translations from diff --git a/lib/decidim/term_customizer/resolver.rb b/lib/decidim/term_customizer/resolver.rb index d36a6f7..1fca14b 100644 --- a/lib/decidim/term_customizer/resolver.rb +++ b/lib/decidim/term_customizer/resolver.rb @@ -5,11 +5,10 @@ module TermCustomizer class Resolver attr_reader :organization, :space, :component, :participatory_process_group - def initialize(organization, space, component, participatory_process_group) + def initialize(organization, space, component) @organization = organization @space = space @component = component - @participatory_process_group = participatory_process_group end def translations @@ -55,7 +54,6 @@ def resolve_constraints_query constraints_add_organization_query(query) constraints_add_space_query(query) constraints_add_component_query(query) - constraints_add_participatory_process_group_query(query) query end @@ -95,24 +93,6 @@ def constraints_add_space_query(query) ) end - def constraints_add_participatory_process_group_query(query) - return unless participatory_process_group - - query.or!( - TermCustomizer::Constraint.where( - organization: organization, - subject: participatory_process_group - ) - ) - query.or!( - TermCustomizer::Constraint.where( - organization: organization, - subject_type: participatory_process_group.class.name, - subject_id: nil - ) - ) - end - def constraints_add_component_query(query) return unless component From fda37f96e556918a386df08cc2e656fb8a713801 Mon Sep 17 00:00:00 2001 From: Elie Gaboriau Date: Mon, 27 Mar 2023 16:59:27 +0200 Subject: [PATCH 5/6] move manifests from application helper to module methods, and fix specs --- .../admin/translation_sets_controller.rb | 3 +-- .../admin/translation_set_subject_form.rb | 6 ++---- .../term_customizer/admin/application_helper.rb | 2 +- app/models/decidim/term_customizer/constraint.rb | 4 +--- lib/decidim/term_customizer.rb | 4 ++++ .../term_customizer/context/controller_context.rb | 12 ++++++------ .../term_customizer/admin/application_helper_spec.rb | 7 ------- .../context/controller_context_spec.rb | 3 +-- spec/lib/decidim/term_customizer/resolver_spec.rb | 9 ++++----- spec/lib/decidim/term_customizer_spec.rb | 12 ++++++++++++ 10 files changed, 32 insertions(+), 30 deletions(-) create mode 100644 spec/lib/decidim/term_customizer_spec.rb diff --git a/app/controllers/decidim/term_customizer/admin/translation_sets_controller.rb b/app/controllers/decidim/term_customizer/admin/translation_sets_controller.rb index 6fffa8f..10a1330 100644 --- a/app/controllers/decidim/term_customizer/admin/translation_sets_controller.rb +++ b/app/controllers/decidim/term_customizer/admin/translation_sets_controller.rb @@ -5,7 +5,6 @@ module TermCustomizer module Admin class TranslationSetsController < TermCustomizer::Admin::ApplicationController include TranslatableAttributes - include ApplicationHelper helper_method :collection, :subject_manifests, :blank_constraint @@ -119,7 +118,7 @@ def sets alias collection sets def subject_manifests - @subject_manifests ||= manifests.map do |manifest| + @subject_manifests ||= Decidim::TermCustomizer.manifests.map do |manifest| models = manifest.model_class_name.constantize.where(organization: current_organization).map { |p| [translated_attribute(p.title), p.id] } next unless models.count.positive? diff --git a/app/forms/decidim/term_customizer/admin/translation_set_subject_form.rb b/app/forms/decidim/term_customizer/admin/translation_set_subject_form.rb index 9979aa3..060f72e 100644 --- a/app/forms/decidim/term_customizer/admin/translation_set_subject_form.rb +++ b/app/forms/decidim/term_customizer/admin/translation_set_subject_form.rb @@ -4,8 +4,6 @@ module Decidim module TermCustomizer module Admin class TranslationSetSubjectForm < Decidim::Form - include ApplicationHelper - attribute :subject_manifest, String attribute :subject_id, Integer attribute :component_model, Array[TermCustomizer::Admin::TranslationSetSubjectComponentForm] @@ -18,7 +16,7 @@ def map_model(model) model end - self.subject_manifest = manifests.find do |m| + self.subject_manifest = Decidim::TermCustomizer.manifests.find do |m| m.model_class_name == subject.class.name end.try(:name) self.subject_id = subject.id @@ -48,7 +46,7 @@ def component end def manifest - @manifest ||= manifests.find do |m| + @manifest ||= Decidim::TermCustomizer.manifests.find do |m| m.name.to_sym == subject_manifest.to_sym end end diff --git a/app/helpers/decidim/term_customizer/admin/application_helper.rb b/app/helpers/decidim/term_customizer/admin/application_helper.rb index 748c808..b2bfc92 100644 --- a/app/helpers/decidim/term_customizer/admin/application_helper.rb +++ b/app/helpers/decidim/term_customizer/admin/application_helper.rb @@ -9,7 +9,7 @@ def tabs_id_for_constraint(constraint) end def manifests - Decidim.participatory_space_manifests + [Decidim.find_resource_manifest(:participatory_process_group)] + Decidim::TermCustomizer.manifests end end end diff --git a/app/models/decidim/term_customizer/constraint.rb b/app/models/decidim/term_customizer/constraint.rb index d230914..f6e3301 100644 --- a/app/models/decidim/term_customizer/constraint.rb +++ b/app/models/decidim/term_customizer/constraint.rb @@ -3,8 +3,6 @@ module Decidim module TermCustomizer class Constraint < TermCustomizer::ApplicationRecord - include Decidim::TermCustomizer::Admin::ApplicationHelper - self.table_name = "decidim_term_customizer_constraints" belongs_to :organization, foreign_key: :decidim_organization_id, class_name: "Decidim::Organization" @@ -25,7 +23,7 @@ def space def manifest space_class = space ? space.class.name : subject_type - manifests.find do |manifest| + Decidim::TermCustomizer.manifests.find do |manifest| manifest.model_class_name == space_class end end diff --git a/lib/decidim/term_customizer.rb b/lib/decidim/term_customizer.rb index 7e3f234..39e8f6d 100644 --- a/lib/decidim/term_customizer.rb +++ b/lib/decidim/term_customizer.rb @@ -39,5 +39,9 @@ module TermCustomizer class << self attr_accessor :loader end + + def self.manifests + Decidim.participatory_space_manifests + [Decidim.find_resource_manifest(:participatory_process_group)] + end end end diff --git a/lib/decidim/term_customizer/context/controller_context.rb b/lib/decidim/term_customizer/context/controller_context.rb index 63df438..fa854bd 100644 --- a/lib/decidim/term_customizer/context/controller_context.rb +++ b/lib/decidim/term_customizer/context/controller_context.rb @@ -10,6 +10,12 @@ def resolve! @organization = env["decidim.current_organization"] + if defined?(Decidim::ParticipatoryProcesses) + @space ||= if controller.instance_of?(Decidim::ParticipatoryProcesses::ParticipatoryProcessGroupsController) + Decidim::ParticipatoryProcessGroup.where(organization: @organization).find(controller.params[:id]) + end + end + # E.g. at the participatory process controller the # `decidim.current_participatory_space` environment variable has not # been set. Therefore, we need to fetch it directly from the @@ -28,12 +34,6 @@ def resolve! end end - if defined?(Decidim::ParticipatoryProcesses) - @space = if controller.instance_of?(Decidim::ParticipatoryProcesses::ParticipatoryProcessGroupsController) - Decidim::ParticipatoryProcessGroup.where(organization: @organization).find(controller.params[:id]) - end - end - @space ||= env["decidim.current_participatory_space"] @component = env["decidim.current_component"] diff --git a/spec/helpers/decidim/term_customizer/admin/application_helper_spec.rb b/spec/helpers/decidim/term_customizer/admin/application_helper_spec.rb index 81c86c7..5b2f3c6 100644 --- a/spec/helpers/decidim/term_customizer/admin/application_helper_spec.rb +++ b/spec/helpers/decidim/term_customizer/admin/application_helper_spec.rb @@ -11,11 +11,4 @@ expect(helper.tabs_id_for_constraint(constraint)).to eq("constraint_test") end end - - describe "#manifests" do - it "returns the expected manifests" do - expect(helper.manifests.size).to equal(Decidim.participatory_space_manifests.size + 1) - expect(helper.manifests).to include(Decidim.find_resource_manifest(:participatory_process_group)) - end - end end diff --git a/spec/lib/decidim/term_customizer/context/controller_context_spec.rb b/spec/lib/decidim/term_customizer/context/controller_context_spec.rb index f760d41..0a6ea65 100644 --- a/spec/lib/decidim/term_customizer/context/controller_context_spec.rb +++ b/spec/lib/decidim/term_customizer/context/controller_context_spec.rb @@ -118,8 +118,7 @@ it "resolves the participatory space as the participatory_process group" do expect(subject.organization).to be(organization) - expect(subject.space).to be_nil - expect(subject.participatory_process_group).to eq(process_group) + expect(subject.space).to eq(process_group) expect(subject.component).to be_nil end end diff --git a/spec/lib/decidim/term_customizer/resolver_spec.rb b/spec/lib/decidim/term_customizer/resolver_spec.rb index 12dad6c..a433cce 100644 --- a/spec/lib/decidim/term_customizer/resolver_spec.rb +++ b/spec/lib/decidim/term_customizer/resolver_spec.rb @@ -3,11 +3,10 @@ require "spec_helper" describe Decidim::TermCustomizer::Resolver do - let(:subject) { described_class.new(organization, space, component, group) } + let(:subject) { described_class.new(organization, space, component) } let(:organization) { create(:organization) } let(:space) { nil } let(:component) { nil } - let(:group) { nil } let(:set) { create(:translation_set) } let(:constraint) { set.constraints.create!(organization: organization) } @@ -97,14 +96,14 @@ end context "with participatory process group" do - let(:group) { create(:participatory_process_group, organization: organization) } + let(:space) { create(:participatory_process_group, organization: organization) } let(:other_group) { create(:participatory_process_group, organization: organization) } let(:other_set) { create(:translation_set) } let(:constraint) do set.constraints.create!( organization: organization, - subject: group + subject: space ) end let!(:other_constraint) do @@ -133,7 +132,7 @@ let(:constraint) do set.constraints.create!( organization: organization, - subject_type: group.class.name + subject_type: space.class.name ) end let!(:other_constraint) do diff --git a/spec/lib/decidim/term_customizer_spec.rb b/spec/lib/decidim/term_customizer_spec.rb new file mode 100644 index 0000000..1cf4485 --- /dev/null +++ b/spec/lib/decidim/term_customizer_spec.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +require "spec_helper" + +describe Decidim::TermCustomizer do + describe "#manifests" do + it "returns the expected manifests" do + expect(Decidim::TermCustomizer.manifests.size).to equal(Decidim.participatory_space_manifests.size + 1) + expect(Decidim::TermCustomizer.manifests).to include(Decidim.find_resource_manifest(:participatory_process_group)) + end + end +end From 36f8b59e23ed3bcb759eef499e93b33d1d2990a5 Mon Sep 17 00:00:00 2001 From: Elie Gaboriau Date: Mon, 27 Mar 2023 17:05:59 +0200 Subject: [PATCH 6/6] remove uselesss attr reader --- lib/decidim/term_customizer/resolver.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/decidim/term_customizer/resolver.rb b/lib/decidim/term_customizer/resolver.rb index 1fca14b..4ce043e 100644 --- a/lib/decidim/term_customizer/resolver.rb +++ b/lib/decidim/term_customizer/resolver.rb @@ -3,7 +3,7 @@ module Decidim module TermCustomizer class Resolver - attr_reader :organization, :space, :component, :participatory_process_group + attr_reader :organization, :space, :component def initialize(organization, space, component) @organization = organization