diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 1e5695d3..1d1d307b 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -64,3 +64,10 @@ jobs: with: name: coverage-report path: coverage + + - name: Upload logs + uses: actions/upload-artifact@master + if: always() + with: + name: bullet-log + path: log diff --git a/Gemfile b/Gemfile index b5090fa0..a4979d80 100644 --- a/Gemfile +++ b/Gemfile @@ -5,6 +5,7 @@ source 'https://rubygems.org' gem 'activerecord-precounter' gem 'awesome_nested_fields' gem 'bootsnap', '>= 1.1.0', require: false +gem 'bullet' gem 'bootstrap', '~> 4.5.0' gem 'bootstrap4-kaminari-views' gem 'carrierwave-postgresql', '< 0.3.0' # Can be upgraded once https://github.com/diogob/carrierwave-postgresql/issues/33 diff --git a/Gemfile.lock b/Gemfile.lock index 8d39f896..1dfe46dd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -81,6 +81,9 @@ GEM rails (>= 3.1) brakeman (4.9.0) builder (3.2.4) + bullet (6.1.0) + activesupport (>= 3.0.0) + uniform_notifier (~> 1.11) bundler-audit (0.7.0.1) bundler (>= 1.2.0, < 3) thor (>= 0.18, < 2) @@ -354,6 +357,7 @@ GEM uglifier (4.2.0) execjs (>= 0.3.0, < 3) unicode-display_width (1.7.0) + uniform_notifier (1.13.0) warden (1.2.8) rack (>= 2.0.6) websocket-driver (0.7.3) @@ -371,6 +375,7 @@ DEPENDENCIES bootstrap (~> 4.5.0) bootstrap4-kaminari-views brakeman + bullet bundler-audit carrierwave-postgresql (< 0.3.0) chartkick diff --git a/config/environments/development.rb b/config/environments/development.rb index ba48a3d5..4695475c 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -67,4 +67,8 @@ # Use an evented file watcher to asynchronously detect changes in source code, # routes, locales, etc. This feature depends on the listen gem. config.file_watcher = ActiveSupport::EventedFileUpdateChecker + config.after_initialize do + Bullet.enable = true + Bullet.bullet_logger = true + end end diff --git a/config/environments/test.rb b/config/environments/test.rb index 76ee95de..c91702ee 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -53,4 +53,9 @@ # Set default URL for mailer to mimic production config.action_mailer.default_url_options = { host: 'test.mitrecyberacademy.org' } + + config.after_initialize do + Bullet.enable = true + Bullet.bullet_logger = true + end end diff --git a/test/integration/team_summary_display_modes_test.rb b/test/integration/team_summary_display_modes_test.rb new file mode 100644 index 00000000..483627e0 --- /dev/null +++ b/test/integration/team_summary_display_modes_test.rb @@ -0,0 +1,30 @@ +require 'test_helper' + +class TeamSummaryDisplayModesTest < ActionDispatch::IntegrationTest + include TeamsHelper + include Devise::Test::IntegrationHelpers + + test "test bullet discovers n+1 query on summary page" do + create(:active_game, board_layout: :jeopardy) + team = create(:team) + + chal1 = create(:standard_challenge, point_value: 100, category_count: 2) + chal2 = create(:standard_challenge, point_value: 100, category_count: 0) + chal3 = create(:standard_challenge, point_value: 150, category_count: 1) + chal4 = create(:standard_challenge, point_value: 100, category_count: 0) + chal5 = create(:standard_challenge, point_value: 100, category_count: 0) + + solved_chal1 = create(:standard_solved_challenge, team: team, challenge: chal1) + solved_chal2 = create(:standard_solved_challenge, team: team, challenge: chal2) + solved_chal3 = create(:standard_solved_challenge, team: team, challenge: chal3) + solved_chal4 = create(:standard_solved_challenge, team: team, challenge: chal4) + solved_chal5 = create(:standard_solved_challenge, team: team, challenge: chal5) + + captain = team.team_captain + + sign_in captain + + get "/teams/#{team.id}/summary" + + end +end