Skip to content

Commit

Permalink
Merge pull request #509 from TechforgoodCAST/develop
Browse files Browse the repository at this point in the history
v1.6.3
  • Loading branch information
drkane authored Oct 24, 2017
2 parents a02b5b5 + 7b0eba0 commit fbca79b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/admin/fund.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
:country_distribution, :sources, :national,
:org_type_distribution, :income_distribution, :slug,
:beneficiary_distribution, :grant_examples,
:geographic_scale_limited, :geo_area,
:geographic_scale_limited, :geo_area_id,
:min_amount_awarded_limited, :min_amount_awarded,
:max_amount_awarded_limited, :max_amount_awarded,
:min_duration_awarded_limited, :min_duration_awarded,
Expand Down Expand Up @@ -181,7 +181,7 @@ def find_resource
end

inputs 'Geography' do
f.input :geo_area, collection: GeoArea.pluck(:name, :id)
f.input :geo_area, input_html: { class: 'chosen-select' }
f.input :geographic_scale_limited
f.input :national
end
Expand Down
12 changes: 12 additions & 0 deletions app/models/geo_area.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,19 @@ class GeoArea < ApplicationRecord
validates :name, presence: true, uniqueness: true
validates :countries, presence: true

validate :validate_districts

def short_name
self[:short_name].present? ? self[:short_name] : self[:name]
end

private

def validate_districts
return if districts.empty?
districts.each do |district|
errors.add(:districts, "Country '#{district.country.name}' for #{district.name} not selected") if
country_ids.exclude?(district.country_id)
end
end
end
10 changes: 10 additions & 0 deletions spec/models/geo_areas_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,15 @@
@area.update(name: nil)
expect(@area).not_to be_valid
end

it 'districts must be from countries' do
@area.update(districts: @db[:uk_districts], countries: [@db[:kenya]])
expect(@area).not_to be_valid
end

it 'districts must be from countries valid' do
@area.update(districts: @db[:uk_districts], countries: [@db[:uk]])
expect(@area).to be_valid
end
end
end
2 changes: 1 addition & 1 deletion spec/services/check/eligibility/location_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
end

it '#call countries_ineligible?' do
@local.geo_area.update!(countries: [@db[:kenya]])
@local.geo_area.update!(countries: [@db[:kenya]], districts: [@db[:kenya_districts].first])
expect(subject.call(@proposal, @local)).to eq 'eligible' => false
end

Expand Down

0 comments on commit fbca79b

Please sign in to comment.