Skip to content

Commit

Permalink
Explicitly sort event sessions on upcoming event cards
Browse files Browse the repository at this point in the history
Even though `event.event_sessions` has an `order` clause,
for some reason it wasn't being used in the context of
rendering the event list. This would cause the event
sessions to be sorted somewhat haphazardly (the sorting
could differ depending on who you were logged in as).

Fixes railsbridge#359
  • Loading branch information
tjgrathwell committed Dec 19, 2016
1 parent 8e465f8 commit 2bcf89c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/views/events/_upcoming_event.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<%= external_links(event) %>
</div>
<div class='event-times'>
<% event.event_sessions.each_with_index do |session, index| %>
<% event.event_sessions.sort_by(&:starts_at).each_with_index do |session, index| %>
<i class='fa fa-calendar'></i><%= formatted_session_fancy_date(session) %><% if index < event.event_sessions.length - 1 %><br /><% end %>
<% if event.has_multiple_locations? %>
<div class='event-session-location'>
Expand Down
27 changes: 27 additions & 0 deletions spec/features/events/event_listing_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,33 @@
expect(page).to have_content("January 31, #{next_year}")
end

describe 'when an upcoming event has many sessions' do
it "shows sessions in date order" do
event = create(:event,
location_id: nil,
title: 'mytitle2',
time_zone: 'Pacific Time (US & Canada)')
create(:event_session, event: event)

session1, session2 = event.event_sessions.to_a
session1.update_attributes(
name: 'SecondSession',
starts_at: 10.days.from_now,
ends_at: 11.days.from_now
)
session2.update_attributes(
name: 'FirstSession',
starts_at: 5.days.from_now,
ends_at: 6.days.from_now
)

visit events_path
within '.event-times' do
expect(page).to have_content(/FirstSession.*SecondSession/)
end
end
end

describe "the past events table", js: true do
before do
event = create(:event, title: 'InternalPastBridge', time_zone: 'Alaska')
Expand Down

0 comments on commit 2bcf89c

Please sign in to comment.