Skip to content

Commit

Permalink
Extract Organisation#not_closed scope
Browse files Browse the repository at this point in the history
  • Loading branch information
chrislo committed Oct 10, 2023
1 parent e7dd6c5 commit 924e00c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/helpers/role_organisations_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module RoleOrganisationsHelper
def options_for_your_organisation_select(current_user)
organisations = Pundit.policy_scope(current_user, Organisation).where(closed: false).order(:name)
organisations = Pundit.policy_scope(current_user, Organisation).not_closed.order(:name)

organisations.map do |organisation|
{ text: organisation.name_with_abbreviation,
Expand Down
2 changes: 2 additions & 0 deletions app/models/organisation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class Organisation < ApplicationRecord

before_save :strip_whitespace_from_name

scope :not_closed, -> { where(closed: false) }

def name_with_abbreviation
return_value = if abbreviation.present? && abbreviation != name
"#{name}#{abbreviation}"
Expand Down
6 changes: 6 additions & 0 deletions test/models/organisation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ def setup
assert_equal "An organisation", organisation.name
end

test "#not_closed" do
create(:organisation, closed: true)

assert_equal [@organisation], Organisation.not_closed.to_a
end

context "displaying name with abbreviation" do
should "use abbreviation when it is not the same as name" do
organisation = build(:organisation, name: "An Organisation", abbreviation: "ABBR")
Expand Down

0 comments on commit 924e00c

Please sign in to comment.