From f23c9ee7eb0752263815600b3ad9ad7d67051d86 Mon Sep 17 00:00:00 2001 From: barbara oliveira Date: Thu, 25 Jul 2024 10:09:22 +0200 Subject: [PATCH 01/10] add tests file --- spec/helpers/decidim/scopes_helper_spec.rb | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 spec/helpers/decidim/scopes_helper_spec.rb diff --git a/spec/helpers/decidim/scopes_helper_spec.rb b/spec/helpers/decidim/scopes_helper_spec.rb new file mode 100644 index 0000000..ae33079 --- /dev/null +++ b/spec/helpers/decidim/scopes_helper_spec.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +require "spec_helper" + +module Decidim + describe ScopesHelper, type: :helper do + describe "scopes_picker_tag" do + let(:scope) { create(:scope) } + + it "works wrong" do + actual = helper.scopes_picker_tag("my_scope_input", scope.id) + + expected = <<~HTML +
+ + +
+ HTML + + expect(actual).to have_equivalent_markup_to(expected) + end + end + end +end From 5b787cb1ab09163e0ffbb52ec2151a2f3650b010 Mon Sep 17 00:00:00 2001 From: barbara oliveira Date: Thu, 25 Jul 2024 12:44:05 +0200 Subject: [PATCH 02/10] fix: specify current_organization in ancestors method --- .../concerns/decidim/simple_proposal/scopes_helper_override.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/concerns/decidim/simple_proposal/scopes_helper_override.rb b/app/helpers/concerns/decidim/simple_proposal/scopes_helper_override.rb index b0b4d2a..ed9490c 100644 --- a/app/helpers/concerns/decidim/simple_proposal/scopes_helper_override.rb +++ b/app/helpers/concerns/decidim/simple_proposal/scopes_helper_override.rb @@ -29,7 +29,7 @@ def simple_scope_options(root: false, options: {}) end def ancestors - @ancestors ||= Decidim::Scope.where(parent_id: nil) + @ancestors ||= current_organization.scopes.where(parent_id: nil) end def children_after_parent(ancestor, array, prefix) From 3513bf9dbe0b210cf79178939c2383585f6c9eb4 Mon Sep 17 00:00:00 2001 From: barbara oliveira Date: Thu, 25 Jul 2024 14:18:50 +0200 Subject: [PATCH 03/10] update rspec --- spec/helpers/decidim/scopes_helper_spec.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/spec/helpers/decidim/scopes_helper_spec.rb b/spec/helpers/decidim/scopes_helper_spec.rb index ae33079..c485935 100644 --- a/spec/helpers/decidim/scopes_helper_spec.rb +++ b/spec/helpers/decidim/scopes_helper_spec.rb @@ -28,5 +28,21 @@ module Decidim expect(actual).to have_equivalent_markup_to(expected) end end + describe "#ancestors" do + let(:organization_1) { create(:organization) } + let(:organization_2) { create(:organization) } + + let(:scope_1_o_1) { create(:scope, organization: organization_1)} + let(:scope_2_o_1) { create(:scope, organization: organization_1)} + let(:scope_1_o_2) { create(:scope, organization: organization_2)} + let(:scope_2_o_2) { create(:scope, organization: organization_2)} + + it "returns only the scopes for the current organization" do + allow(helper).to receive(:current_organization).and_return(organization_1) + result = helper.send(:ancestor) + expect(result).to match_array([:scope_1_o_1,:scope_2_o_1]) + expect(result).not_to include(:scope_1_o_2, :scope_2_o_2) + end + end end end From a5fbe8a1d95cd3dd6e5cea814fd974cc6aefdc88 Mon Sep 17 00:00:00 2001 From: barbara oliveira Date: Thu, 25 Jul 2024 16:39:22 +0200 Subject: [PATCH 04/10] lint rspec --- spec/helpers/decidim/scopes_helper_spec.rb | 31 ++++++++++++---------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/spec/helpers/decidim/scopes_helper_spec.rb b/spec/helpers/decidim/scopes_helper_spec.rb index c485935..58f3523 100644 --- a/spec/helpers/decidim/scopes_helper_spec.rb +++ b/spec/helpers/decidim/scopes_helper_spec.rb @@ -28,21 +28,24 @@ module Decidim expect(actual).to have_equivalent_markup_to(expected) end end + describe "#ancestors" do - let(:organization_1) { create(:organization) } - let(:organization_2) { create(:organization) } - - let(:scope_1_o_1) { create(:scope, organization: organization_1)} - let(:scope_2_o_1) { create(:scope, organization: organization_1)} - let(:scope_1_o_2) { create(:scope, organization: organization_2)} - let(:scope_2_o_2) { create(:scope, organization: organization_2)} - - it "returns only the scopes for the current organization" do - allow(helper).to receive(:current_organization).and_return(organization_1) - result = helper.send(:ancestor) - expect(result).to match_array([:scope_1_o_1,:scope_2_o_1]) - expect(result).not_to include(:scope_1_o_2, :scope_2_o_2) - end + let(:first_organization) { create(:organization) } + let(:second_organization) { create(:organization) } + + let!(:first_scope) { create(:scope, organization: first_organization) } + let!(:second_scope) { create(:scope, organization: first_organization) } + let!(:third_scope) { create(:scope, organization: second_organization) } + let!(:fourth_scope) { create(:scope, organization: second_organization) } + + it "returns only the scopes for the current organization" do + allow(helper).to receive(:current_organization).and_return(first_organization) + + result = helper.send(:ancestors) + + expect(result).to match_array([first_scope, second_scope]) + expect(result).not_to include(third_scope, fourth_scope) end + end end end From 0e2d2a167cb57bb54f01d9642dc99a62b1881320 Mon Sep 17 00:00:00 2001 From: barbara oliveira Date: Fri, 26 Jul 2024 10:09:22 +0200 Subject: [PATCH 05/10] try to include sanitize_helper file to fix CI --- spec/spec_helper.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 8c48087..52890f0 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require "decidim/dev" +require_relative "../decidim-core/app/helpers/decidim/sanitize_helper" ENV["ENGINE_ROOT"] = File.dirname(__dir__) From 4cb884de4cf3db436df0b38737fd411b71571abe Mon Sep 17 00:00:00 2001 From: barbara oliveira Date: Fri, 26 Jul 2024 10:20:36 +0200 Subject: [PATCH 06/10] try to fix CI: how to include sanitize_helper? --- spec/spec_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 52890f0..5754877 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require "decidim/dev" -require_relative "../decidim-core/app/helpers/decidim/sanitize_helper" +require "decidim/sanitize_helper" ENV["ENGINE_ROOT"] = File.dirname(__dir__) From aca2dfea193d59adc193b460e6861b1fed0aef55 Mon Sep 17 00:00:00 2001 From: barbara oliveira Date: Fri, 26 Jul 2024 10:32:01 +0200 Subject: [PATCH 07/10] try to fix CI --- spec/spec_helper.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 5754877..05d0f7a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true require "decidim/dev" +$LOAD_PATH.unshift File.expand_path("../../path/to/external/libraries", __FILE__) + require "decidim/sanitize_helper" ENV["ENGINE_ROOT"] = File.dirname(__dir__) From a6e9be570434e3db1dcdfc7b3fd3f5c400e501a4 Mon Sep 17 00:00:00 2001 From: barbara oliveira Date: Fri, 26 Jul 2024 10:45:21 +0200 Subject: [PATCH 08/10] try to fix CI --- spec/helpers/decidim/scopes_helper_spec.rb | 4 ++++ spec/spec_helper.rb | 2 -- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/spec/helpers/decidim/scopes_helper_spec.rb b/spec/helpers/decidim/scopes_helper_spec.rb index 58f3523..c05e392 100644 --- a/spec/helpers/decidim/scopes_helper_spec.rb +++ b/spec/helpers/decidim/scopes_helper_spec.rb @@ -4,6 +4,10 @@ module Decidim describe ScopesHelper, type: :helper do + include ActionView::Helpers::SanitizeHelper + include ActionView::Helpers::TagHelper + include Decidim::TranslatableAttributes + include Decidim::SanitizeHelper describe "scopes_picker_tag" do let(:scope) { create(:scope) } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 05d0f7a..5754877 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true require "decidim/dev" -$LOAD_PATH.unshift File.expand_path("../../path/to/external/libraries", __FILE__) - require "decidim/sanitize_helper" ENV["ENGINE_ROOT"] = File.dirname(__dir__) From c48f1da22df60c9819b703554de8ceff0091e4c1 Mon Sep 17 00:00:00 2001 From: barbara oliveira Date: Fri, 26 Jul 2024 15:11:49 +0200 Subject: [PATCH 09/10] fix rspec: delete file and override --- .../scopes_helper_override_spec.rb | 26 +++++++++ spec/helpers/decidim/scopes_helper_spec.rb | 55 ------------------- spec/spec_helper.rb | 1 - 3 files changed, 26 insertions(+), 56 deletions(-) create mode 100644 spec/helpers/concerns/decidim/simple_proposal/scopes_helper_override_spec.rb delete mode 100644 spec/helpers/decidim/scopes_helper_spec.rb diff --git a/spec/helpers/concerns/decidim/simple_proposal/scopes_helper_override_spec.rb b/spec/helpers/concerns/decidim/simple_proposal/scopes_helper_override_spec.rb new file mode 100644 index 0000000..beecd37 --- /dev/null +++ b/spec/helpers/concerns/decidim/simple_proposal/scopes_helper_override_spec.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true +require "spec_helper" + +module Decidim + describe ScopesHelper, type: :helper do + + describe "#ancestors" do + let(:first_organization) { create(:organization) } + let(:second_organization) { create(:organization) } + + let!(:first_scope) { create(:scope, organization: first_organization) } + let!(:second_scope) { create(:scope, organization: first_organization) } + let!(:third_scope) { create(:scope, organization: second_organization) } + let!(:fourth_scope) { create(:scope, organization: second_organization) } + + it "returns only the scopes for the current organization" do + allow(helper).to receive(:current_organization).and_return(first_organization) + + result = helper.send(:ancestors) + + expect(result).to match_array([first_scope, second_scope]) + expect(result).not_to include(third_scope, fourth_scope) + end + end + end +end diff --git a/spec/helpers/decidim/scopes_helper_spec.rb b/spec/helpers/decidim/scopes_helper_spec.rb deleted file mode 100644 index c05e392..0000000 --- a/spec/helpers/decidim/scopes_helper_spec.rb +++ /dev/null @@ -1,55 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" - -module Decidim - describe ScopesHelper, type: :helper do - include ActionView::Helpers::SanitizeHelper - include ActionView::Helpers::TagHelper - include Decidim::TranslatableAttributes - include Decidim::SanitizeHelper - describe "scopes_picker_tag" do - let(:scope) { create(:scope) } - - it "works wrong" do - actual = helper.scopes_picker_tag("my_scope_input", scope.id) - - expected = <<~HTML - - HTML - - expect(actual).to have_equivalent_markup_to(expected) - end - end - - describe "#ancestors" do - let(:first_organization) { create(:organization) } - let(:second_organization) { create(:organization) } - - let!(:first_scope) { create(:scope, organization: first_organization) } - let!(:second_scope) { create(:scope, organization: first_organization) } - let!(:third_scope) { create(:scope, organization: second_organization) } - let!(:fourth_scope) { create(:scope, organization: second_organization) } - - it "returns only the scopes for the current organization" do - allow(helper).to receive(:current_organization).and_return(first_organization) - - result = helper.send(:ancestors) - - expect(result).to match_array([first_scope, second_scope]) - expect(result).not_to include(third_scope, fourth_scope) - end - end - end -end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 5754877..8c48087 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require "decidim/dev" -require "decidim/sanitize_helper" ENV["ENGINE_ROOT"] = File.dirname(__dir__) From d75f2069a60861509ea5a83b9d2f6b07657914c3 Mon Sep 17 00:00:00 2001 From: barbara oliveira Date: Fri, 26 Jul 2024 15:15:19 +0200 Subject: [PATCH 10/10] lint --- .../decidim/simple_proposal/scopes_helper_override_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/helpers/concerns/decidim/simple_proposal/scopes_helper_override_spec.rb b/spec/helpers/concerns/decidim/simple_proposal/scopes_helper_override_spec.rb index beecd37..afeebb1 100644 --- a/spec/helpers/concerns/decidim/simple_proposal/scopes_helper_override_spec.rb +++ b/spec/helpers/concerns/decidim/simple_proposal/scopes_helper_override_spec.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true + require "spec_helper" module Decidim describe ScopesHelper, type: :helper do - describe "#ancestors" do let(:first_organization) { create(:organization) } let(:second_organization) { create(:organization) }