Skip to content

Commit

Permalink
Merge branch 'main' into ik-1055-graph-api-event-filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
kimadactyl authored Mar 16, 2022
2 parents 0a1114e + 53bb83a commit 94f7c99
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Event < ApplicationRecord

# Filter by Site
scope :for_site, lambda { |site|
site_neighbourhood_ids = site.neighbourhoods.map(&:subtree).flatten.map(&:id)
site_neighbourhood_ids = site.owned_neighbourhoods.map(&:id)

joins(:address)
.joins('left join partners on events.partner_id = partners.id')
Expand Down
2 changes: 1 addition & 1 deletion app/models/partner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class Partner < ApplicationRecord
scope :recently_updated, -> { order(updated_at: desc) }

scope :for_site, lambda { |site|
site_neighbourhood_ids = site.neighbourhoods.map(&:subtree).flatten.map(&:id)
site_neighbourhood_ids = site.owned_neighbourhoods.map(&:id)
site_tag_ids = site.tags.map(&:id)

partners = joins('left join addresses on addresses.id = partners.address_id')
Expand Down
8 changes: 6 additions & 2 deletions app/models/site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ def to_s
"#{id}: #{name}"
end

def owned_neighbourhoods
neighbourhoods.map(&:subtree).flatten
end

# ASSUMPTION: There is no row in the sites table for the admin site, hence
# defining the admin subdomain string here.
ADMIN_SUBDOMAIN = 'admin'
Expand All @@ -59,15 +63,15 @@ def local_site?

# Should we show the neighbourhood lozenge out on this site?
def show_neighbourhoods?
neighbourhoods.count > 1
owned_neighbourhoods.count > 1
end

def self.badge_zoom_level_label(value)
value.second.to_s.titleize
end

def join_word
if neighbourhoods.count > 1
if owned_neighbourhoods.count > 1
'near'
else
'in'
Expand Down
6 changes: 3 additions & 3 deletions test/integration/partners_integration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ class PartnersIntegrationTest < ActionDispatch::IntegrationTest
assert_select 'div.hero h4', text: "Neighbourhood's Community Calendar"
assert_select 'div.hero h1', text: 'Partners in your area'
assert_select 'ul.partners li', 5
# Ensure title/summary description is displayed
assert_select '.preview__header', text: @region_site_partners.first.name
assert_select '.preview__details', text: @region_site_partners.first.summary
# Ensure title/summary description is displayed (select the h3 tag to avoid badge selection)
assert_select 'div.preview__header h3', text: @region_site_partners.first.name
assert_select 'div.preview__details', text: @region_site_partners.first.summary
end

test 'tagged site page shows only tagged partners' do
Expand Down

0 comments on commit 94f7c99

Please sign in to comment.