-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Consolidate organisation options methods
These are essentially doing the same thing, so there's no need to have multiple methods for them. I've deleted a test from a controller than duplicates a helper test added here
- Loading branch information
Showing
11 changed files
with
53 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module OrganisationHelper | ||
def options_for_organisation_select(selected_id: nil) | ||
[{ text: "None", value: nil }] + Organisation.not_closed.map do |organisation| | ||
{ text: organisation.name_with_abbreviation, value: organisation.id }.tap do |option| | ||
option[:selected] = true if option[:value] == selected_id | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
require "test_helper" | ||
|
||
class OrganisationHelperTest < ActionView::TestCase | ||
setup do | ||
@gds = create(:organisation, name: "Government Digital Service", abbreviation: "GDS") | ||
@gas = create(:organisation, name: "Government Analogue Service", abbreviation: "GAS") | ||
@unabbreviated = create(:organisation, name: "unAbbreviaTed") | ||
end | ||
|
||
should "return a select option for each organisation sorted alphabetically, preceded by a 'None' option" do | ||
expected = [ | ||
{ text: "None", value: nil }, | ||
{ text: "Government Analogue Service - GAS", value: @gas.id }, | ||
{ text: "Government Digital Service - GDS", value: @gds.id }, | ||
{ text: "unAbbreviaTed", value: @unabbreviated.id }, | ||
] | ||
|
||
assert_equal expected, options_for_organisation_select | ||
end | ||
|
||
context "when a closed organisation exists" do | ||
setup do | ||
@closed = create(:organisation, name: "Prehistoric Government Service", closed: true) | ||
end | ||
|
||
should "exclude the closed organisation" do | ||
unexpected_closed_option = { text: "Prehistoric Government Service", value: @closed.id } | ||
|
||
assert_not_includes options_for_organisation_select, unexpected_closed_option | ||
end | ||
end | ||
|
||
context "when a selection is provided" do | ||
should "mark the selection as selected" do | ||
selected_option = { text: "Government Analogue Service - GAS", value: @gas.id, selected: true } | ||
|
||
assert_includes options_for_organisation_select(selected_id: @gas.id), selected_option | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters