Skip to content

Commit

Permalink
Allow filtering by local target in SDG management
Browse files Browse the repository at this point in the history
  • Loading branch information
javierm authored and taitus committed Jan 23, 2021
1 parent 6470ff8 commit 24a35be
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 4 additions & 0 deletions app/models/sdg/local_target.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ class SDG::LocalTarget < ApplicationRecord

belongs_to :target

def self.[](code)
find_by!(code: code)
end

def <=>(any_target)
if any_target.class == self.class
[target, numeric_subcode] <=> [any_target.target, any_target.numeric_subcode]
Expand Down
9 changes: 4 additions & 5 deletions spec/system/sdg_management/relations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,10 @@
end

scenario "local target filter" do
schools = create(:sdg_local_target, code: "4.1.1")
teachers = create(:sdg_local_target, code: "4.1.2")

create(:debate, title: "Rebuild local schools", sdg_local_targets: [schools])
create(:debate, title: "Hire teachers", sdg_local_targets: [teachers])
create(:sdg_local_target, code: "4.1.1")
create(:sdg_local_target, code: "4.1.2")
create(:debate, title: "Rebuild local schools", sdg_local_targets: [SDG::LocalTarget["4.1.1"]])
create(:debate, title: "Hire teachers", sdg_local_targets: [SDG::LocalTarget["4.1.2"]])

visit sdg_management_debates_path
select "4.1.1", from: "target_code"
Expand Down

0 comments on commit 24a35be

Please sign in to comment.