Skip to content

Commit

Permalink
Merge pull request #5 from OpenSourcePolitics/fix/unexpected_double_s…
Browse files Browse the repository at this point in the history
…copes_displaying

Fix/unexpected double scopes displaying
  • Loading branch information
luciegrau authored Jul 31, 2024
2 parents e5813b1 + d75f206 commit 2c3c9a1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 2c3c9a1

Please sign in to comment.