diff --git a/app/components/sdg_management/relations/index_component.rb b/app/components/sdg_management/relations/index_component.rb index 170fa7573..c6f136ff4 100644 --- a/app/components/sdg_management/relations/index_component.rb +++ b/app/components/sdg_management/relations/index_component.rb @@ -47,7 +47,7 @@ class SDGManagement::Relations::IndexComponent < ApplicationComponent end def goal_options - options_from_collection_for_select(SDG::Goal.all, :code, :code_and_title, params[:goal_code]) + options_from_collection_for_select(SDG::Goal.order(:code), :code, :code_and_title, params[:goal_code]) end def target_options diff --git a/spec/components/sdg_management/relations/index_component_spec.rb b/spec/components/sdg_management/relations/index_component_spec.rb new file mode 100644 index 000000000..e194a4aaf --- /dev/null +++ b/spec/components/sdg_management/relations/index_component_spec.rb @@ -0,0 +1,16 @@ +require "rails_helper" + +describe SDGManagement::Relations::IndexComponent, type: :component do + describe "#goal_options" do + it "orders goals by code in the select" do + component = SDGManagement::Relations::IndexComponent.new(Proposal.none.page(1)) + + render_inline component + options = page.find("#goal_code").all("option") + + expect(options[0]).to have_content "All goals" + expect(options[1]).to have_content "1. " + expect(options[17]).to have_content "17. " + end + end +end