Skip to content

Commit

Permalink
Only show speakers with talks on speakers index
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoroth committed Aug 15, 2024
1 parent a6823a9 commit bcdf577
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/controllers/speakers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ class SpeakersController < ApplicationController
def index
respond_to do |format|
format.html do
@speakers = Speaker.all.order(:name).select(:id, :name, :slug, :talks_count, :github)
@speakers = Speaker.with_talks.order(:name).select(:id, :name, :slug, :talks_count, :github)
@speakers = @speakers.where("lower(name) LIKE ?", "#{params[:letter].downcase}%") if params[:letter].present?
end
format.json do
@pagy, @speakers = pagy(Speaker.all.order(:name), limit: params[:per_page])
@pagy, @speakers = pagy(Speaker.with_talks.order(:name), limit: params[:per_page])
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/speakers/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
<% end %>
</div>
<div id="speakers" class="grid sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-x-8 lg:gap-x-12 gap-y-2 min-w-full">
<%= render @speakers %>
<%= render @speakers %>
</div>
</div>
11 changes: 10 additions & 1 deletion test/controllers/speakers_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@
class SpeakersControllerTest < ActionDispatch::IntegrationTest
setup do
@speaker = speakers(:one)
@speaker_with_talk = speakers(:two)

@speaker_with_talk.talks << talks(:one)
end

test "should get index" do
get speakers_url
assert_response :success

assert_select "##{dom_id(@speaker)}", 0
assert_select "##{dom_id(@speaker_with_talk)}", 1
end

test "should show speaker" do
Expand All @@ -30,6 +36,9 @@ class SpeakersControllerTest < ActionDispatch::IntegrationTest
assert_response :success

json_response = JSON.parse(response.body)
assert_includes json_response["speakers"].map { |speaker_data| speaker_data["name"] }, @speaker.name
speakers = json_response["speakers"].map { |speaker_data| speaker_data["name"] }

assert_includes speakers, @speaker_with_talk.name
assert_equal 1, speakers.length
end
end

0 comments on commit bcdf577

Please sign in to comment.