From ac68052dbc7696680eeb98f2943f7b63968c2c0a Mon Sep 17 00:00:00 2001 From: Stephen Chudleigh Date: Thu, 14 Nov 2024 09:09:55 -0800 Subject: [PATCH] [182] add Bullet gem config (#272) * add Bullet gem config --- Gemfile | 1 + Gemfile.lock | 5 +++++ .../evaluation_forms_controller.rb | 2 +- app/helpers/evaluation_forms_helper.rb | 2 +- app/helpers/phases_helper.rb | 4 ++-- config/environments/development.rb | 9 +++++++++ config/environments/test.rb | 6 ++++++ spec/helpers/phases_helper_spec.rb | 4 ++-- spec/models/evaluation_form_spec.rb | 2 +- spec/requests/evaluation_forms_spec.rb | 20 ++++++++++++------- 10 files changed, 41 insertions(+), 14 deletions(-) diff --git a/Gemfile b/Gemfile index b46742e6..1dcb097f 100644 --- a/Gemfile +++ b/Gemfile @@ -68,6 +68,7 @@ group :development, :test do gem "rubocop-capybara", require: false gem "codeclimate-test-reporter" + gem "bullet" end group :development do diff --git a/Gemfile.lock b/Gemfile.lock index 3592b0c6..cb94e698 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -96,6 +96,9 @@ GEM bootsnap (1.18.4) msgpack (~> 1.2) builder (3.3.0) + bullet (8.0.0) + activesupport (>= 3.0.0) + uniform_notifier (~> 1.11) capybara (3.40.0) addressable matrix @@ -338,6 +341,7 @@ GEM tzinfo (2.0.6) concurrent-ruby (~> 1.0) unicode-display_width (2.6.0) + uniform_notifier (1.16.0) uri (0.13.1) useragent (0.16.10) virtus (2.0.0) @@ -374,6 +378,7 @@ DEPENDENCIES annotate axe-core-rspec bootsnap + bullet capybara codeclimate-test-reporter cssbundling-rails (~> 1.4) diff --git a/app/controllers/evaluation_forms_controller.rb b/app/controllers/evaluation_forms_controller.rb index d8c5fed0..a7760e1b 100644 --- a/app/controllers/evaluation_forms_controller.rb +++ b/app/controllers/evaluation_forms_controller.rb @@ -72,7 +72,7 @@ def set_evaluation_form end def set_evaluation_forms - @evaluation_forms = EvaluationForm.by_user(current_user) + @evaluation_forms = EvaluationForm.by_user(current_user).includes([:challenge, :phase]) end # Only allow a list of trusted parameters through. diff --git a/app/helpers/evaluation_forms_helper.rb b/app/helpers/evaluation_forms_helper.rb index ebd809bc..6164fe39 100644 --- a/app/helpers/evaluation_forms_helper.rb +++ b/app/helpers/evaluation_forms_helper.rb @@ -6,7 +6,7 @@ def challenge_with_phase(evaluation_form) end def challenge_phase_title(challenge, phase) - "#{challenge.title} - Phase #{phase_number(phase)}" + "#{challenge.title} - Phase #{phase_number(challenge, phase)}" end def evaluation_period(evaluation_form) diff --git a/app/helpers/phases_helper.rb b/app/helpers/phases_helper.rb index 16a28526..b6b49041 100644 --- a/app/helpers/phases_helper.rb +++ b/app/helpers/phases_helper.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module PhasesHelper - def phase_number(phase) - phase.challenge.phase_ids.index(phase.id) + 1 + def phase_number(challenge, phase) + challenge.phase_ids.index(phase.id) + 1 end end diff --git a/config/environments/development.rb b/config/environments/development.rb index cd4e78a2..7cd5367f 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -3,6 +3,15 @@ require "active_support/core_ext/integer/time" Rails.application.configure do + config.after_initialize do + Bullet.enable = true + Bullet.alert = true + Bullet.bullet_logger = true + Bullet.console = true + Bullet.rails_logger = true + Bullet.add_footer = true + end + # Settings specified here will take precedence over those in config/application.rb. # In the development environment your application's code is reloaded any time diff --git a/config/environments/test.rb b/config/environments/test.rb index 4b491ee0..8f33c9ac 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -8,6 +8,12 @@ # and recreated between test runs. Don't rely on the data there! Rails.application.configure do + config.after_initialize do + Bullet.enable = true + Bullet.bullet_logger = true + Bullet.raise = true # raise an error if n+1 query occurs + end + # Settings specified here will take precedence over those in config/application.rb. # While tests run files are not watched, reloading is not necessary. diff --git a/spec/helpers/phases_helper_spec.rb b/spec/helpers/phases_helper_spec.rb index ff30aa6d..8d38dc39 100644 --- a/spec/helpers/phases_helper_spec.rb +++ b/spec/helpers/phases_helper_spec.rb @@ -6,8 +6,8 @@ c = create_challenge p2 = create_phase(challenge_id: c.id, start_date: 1.month.from_now, end_date: 6.weeks.from_now) p1 = create_phase(challenge_id: c.id, start_date: 1.week.from_now, end_date: 2.weeks.from_now) - expect(helper.phase_number(p1)).to eq(1) - expect(helper.phase_number(p2)).to eq(2) + expect(helper.phase_number(c, p1)).to eq(1) + expect(helper.phase_number(c, p2)).to eq(2) end end end diff --git a/spec/models/evaluation_form_spec.rb b/spec/models/evaluation_form_spec.rb index 67b698c1..4beb2295 100644 --- a/spec/models/evaluation_form_spec.rb +++ b/spec/models/evaluation_form_spec.rb @@ -56,7 +56,7 @@ challenge_user = create_user(role: :challenge_manager, email: "user1@example.com") different_user = create_user(role: :challenge_manager, email: "user2@example.com") challenge = create_challenge(user: challenge_user) - evaluation_form = create_evaluation_form(challenge_id: challenge.id, challenge_phase: 1) + evaluation_form = create_evaluation_form(challenge_id: challenge.id) expect(challenge.challenge_manager_users).not_to include(different_user) expect(described_class.by_user(different_user)).not_to include(evaluation_form) end diff --git a/spec/requests/evaluation_forms_spec.rb b/spec/requests/evaluation_forms_spec.rb index c69c9bd8..591a4c0a 100644 --- a/spec/requests/evaluation_forms_spec.rb +++ b/spec/requests/evaluation_forms_spec.rb @@ -47,9 +47,11 @@ agency = Agency.create!(name: "Gandalf and Sons", acronym: "GAD") challenge = Challenge.create!(user:, agency:, title: "Turning red bull into water") ChallengeManager.create(user:, challenge:) + ph1 = create_phase(challenge_id: challenge.id) + ph2 = create_phase(challenge_id: challenge.id) - create_evaluation_form(title: "Frodo", challenge_id: challenge.id, challenge_phase: 1) - create_evaluation_form(title: "Sam", challenge_id: challenge.id, challenge_phase: 2) + create_evaluation_form(title: "Frodo", challenge_id: challenge.id, phase_id: ph1.id) + create_evaluation_form(title: "Sam", challenge_id: challenge.id, phase_id: ph2.id) get evaluation_forms_path expect(response.body).to include("Sam") expect(response.body).to include("Frodo") @@ -63,11 +65,15 @@ user2 = create_user(role: "challenge_manager", email: "testwizard@example.gov") challenge2 = Challenge.create!(user: user2, agency:, title: "Turning frogs into princes") ChallengeManager.create(user: user2, challenge:) + ph1 = create_phase(challenge_id: challenge.id) + ph2 = create_phase(challenge_id: challenge.id) + ph3 = create_phase(challenge_id: challenge2.id) + ph4 = create_phase(challenge_id: challenge2.id) - create_evaluation_form(title: "Shrek", challenge_id: challenge.id, challenge_phase: 1) - create_evaluation_form(title: "Fiona", challenge_id: challenge.id, challenge_phase: 2) - create_evaluation_form(title: "Donkey", challenge_id: challenge2.id, challenge_phase: 1) - create_evaluation_form(title: "Farquad", challenge_id: challenge2.id, challenge_phase: 2) + create_evaluation_form(title: "Shrek", challenge_id: challenge.id, phase_id: ph1.id) + create_evaluation_form(title: "Fiona", challenge_id: challenge.id, phase_id: ph2.id) + create_evaluation_form(title: "Donkey", challenge_id: challenge2.id, phase_id: ph3.id) + create_evaluation_form(title: "Farquad", challenge_id: challenge2.id, phase_id: ph4.id) get evaluation_forms_path expect(response.body).to include("Shrek") @@ -105,7 +111,7 @@ describe "PATCH /evaluation_forms/:id" do let(:challenge_user) { create_user(role: "challenge_manager") } let(:challenge) { create_challenge(user: challenge_user) } - let(:evaluation_form) { create_evaluation_form(challenge_id: challenge.id, challenge_phase: 1) } + let(:evaluation_form) { create_evaluation_form(challenge_id: challenge.id) } before { log_in_user(challenge_user) }