Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
mbeckman committed Jul 23, 2014
2 parents a29b1b8 + 32fce6d commit 29a574f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
20 changes: 13 additions & 7 deletions app/models/geographic_area.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,26 @@ def self.ancestors_and_descendants_of(geographic_area)

# TODO: Test
# A scope. Matches GeographicAreas that have name and parent name.
# Like:
# GeographicArea.with_name_and_parent_names(%w{Champaign Illinois})
scope :with_name_and_parent_name, -> (names) {
joins(:parent).
where(name: names[0], parent: {name: names[1]})
joins('join geographic_areas ga on ga.id = geographic_areas.parent_id').
where(name: names[0]).
where(['ga.name = ?', names[1] ])
}

# TODO: Test, or extend a general method
# Matches GeographicAreas that match name, parent name, parent name
# Like:
# GeographicArea.with_name_and_parents(%{United\ States Illinois Champaign})
scope :with_name_and_parents, -> (names) {
joins(parent: :parent).
where(name: names[0].to_s, parent: {name: names[1].to_s, parent: {name: names[2]}})
# GeographicArea.with_name_and_parent_names(%w{Champaign Illinois United\ States})
scope :with_name_and_parent_names, -> (names) {
joins('join geographic_areas ga on ga.id = geographic_areas.parent_id').
joins('join geographic_areas gb on gb.id = ga.parent_id').
where(name: names[0]).
where(['ga.name = ?', names[1] ]).
where(['gb.name = ?', names[2] ])
}

# Route out to a scope given the length of the
# search array. Could be abstracted to
# build nesting on the fly if we actually
Expand Down
2 changes: 1 addition & 1 deletion spec/models/projects_sources_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
specify 'project' do
expect(project_source.errors.include?(:project)).to be_truthy
end
specify 'project' do
specify 'source' do
expect(project_source.errors.include?(:source)).to be_truthy
end
end
Expand Down

0 comments on commit 29a574f

Please sign in to comment.