Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#884 - Fix descendants not showing on prospective region site #888

Merged
merged 3 commits into from
Jan 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/components/event/event_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ def neighbourhood_name
def primary_neighbourhood?
# Show everything as primary if primary is not set
return true unless primary_neighbourhood
event.neighbourhood == primary_neighbourhood

event.neighbourhood == primary_neighbourhood || primary_neighbourhood.children.include?(event.neighbourhood)
end

private
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admin/sites_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def set_site
end

def set_variables_for_sites_neighbourhoods_selection
@all_neighbourhoods = policy_scope(Neighbourhood).order(:name).where(unit: 'ward')
@all_neighbourhoods = policy_scope(Neighbourhood).order(:name)
begin
set_site
rescue ActiveRecord::RecordNotFound
Expand Down
7 changes: 6 additions & 1 deletion app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ class Event < ApplicationRecord
}

# Filter by Site
scope :for_site, ->(site) { joins(:address).where( addresses: { neighbourhood: site.neighbourhoods } ) }
scope :for_site, lambda { |site|
joins(:address).where(addresses: {
neighbourhood: site.neighbourhoods.map { |ward| ward.subtree }.flatten
})
}


# Filter by Place
scope :in_place, ->(place) { where(place: place) }
Expand Down
2 changes: 1 addition & 1 deletion test/integration/admin/sites_integration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class AdminSitesIntegrationTest < ActionDispatch::IntegrationTest
@site = create(:site)
@site_admin = @site.site_admin
@neighbourhoods = create_list(:neighbourhood, 5)
@number_of_neighbourhoods = Neighbourhood.where(unit: 'ward').length
@number_of_neighbourhoods = Neighbourhood.all.length
host! 'admin.lvh.me'
end

Expand Down
27 changes: 24 additions & 3 deletions test/integration/events_integration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class EventsIntegrationTest < ActionDispatch::IntegrationTest
# Create a default site and a neighbourhood one
@default_site = create_default_site
@neighbourhood_site = create(:site_local)
@regional_neighbourhood_site = create(:site_local)

# Create one set of events for the default site
date = DateTime.now.beginning_of_day
Expand All @@ -24,21 +25,41 @@ class EventsIntegrationTest < ActionDispatch::IntegrationTest
event.address.update(neighbourhood: @neighbourhood2)
end
@neighbourhood_site.neighbourhoods << @neighbourhood2


# Make a ward, add events to that ward
@ward = create(:neighbourhood)
@regional_ward_events = create_list :event, 5, dtstart: date + 1.hour
@regional_ward_events.each { |event| event.address.update(neighbourhood: @ward) }

# Assign the regional site to have, a region containing the ward, as a neighbourhood
@regional_neighbourhood_site.neighbourhoods << @ward.region
end

test 'site indexs page shows all events that are on today and local info' do
test 'default site index page shows all events that are on today and local info' do
get events_url
assert_response :success
assert_select 'title', count: 1, text: "Events & activities in your area | #{@default_site.name}"
assert_select 'div.hero h4', text: 'The Community Calendar'
assert_select 'div.hero h1', text: 'Events & activities in your area'
assert_select 'ol article', 5
assert_select 'ol article', @default_site_events.length
end

test 'neighbourhood site index page shows all events that are on today and local info' do
get "http://#{@neighbourhood_site.slug}.lvh.me/events"
assert_response :success
assert_select 'title', count: 1, text: "Events & activities in your area | #{@neighbourhood_site.name}"
assert_select 'div.hero h4', text: "Neighbourhood's Community Calendar"
assert_select 'div.hero h1', text: 'Events & activities in your area'
assert_select 'ol article', 5
assert_select 'ol article', @neighbourhood_site_events.length
end

test 'regional site index page shows all events that are on today and local info' do
get "http://#{@regional_neighbourhood_site.slug}.lvh.me/events"
assert_response :success
assert_select 'title', count: 1, text: "Events & activities in your area | #{@regional_neighbourhood_site.name}"
assert_select 'div.hero h4', text: "Neighbourhood's Community Calendar"
assert_select 'div.hero h1', text: 'Events & activities in your area'
assert_select 'ol article', @regional_ward_events.length
end
end
Loading