Skip to content

Commit

Permalink
Merge branch 'dev' into 80_submission_detail
Browse files Browse the repository at this point in the history
  • Loading branch information
stepchud authored Nov 14, 2024
2 parents 6d3e79a + d04fc54 commit 1af7ab4
Show file tree
Hide file tree
Showing 13 changed files with 73 additions and 17 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ group :development, :test do
gem "rubocop-capybara", require: false

gem "codeclimate-test-reporter"
gem "bullet"
end

group :development do
Expand Down
5 changes: 5 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -374,6 +378,7 @@ DEPENDENCIES
annotate
axe-core-rspec
bootsnap
bullet
capybara
codeclimate-test-reporter
cssbundling-rails (~> 1.4)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/evaluation_forms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/evaluation_forms_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/phases_helper.rb
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions app/javascript/controllers/evaluation_form_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ export default class extends Controller {
}
}

updateMaxPoints(e) {
const form = e.target.closest('form[data-controller="evaluation-form"]');
const pointsWeights = form.querySelectorAll(".points-or-weight");
if (e.target.id == 'weighted_scale') {
pointsWeights.forEach((input) => input.max = "100")
} else {
pointsWeights.forEach((input) => input.max = "9999")
}
}

validatePresence(e) {
if (!e.target.value) {
e.target.classList.add("border-secondary")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@
<%= f.number_field :points_or_weight,
id: criteria_field_id(f, "points_or_weight", is_template),
name: criteria_field_name(f, "points_or_weight", is_template),
class: "usa-input flex-1 margin-top-0 margin-right-2 font-sans-lg",
class: "points-or-weight usa-input flex-1 margin-top-0 margin-right-2 font-sans-lg",
min: 1,
max: f.object.evaluation_form&.weighted_scoring? ? 100 : 9999,
step: 1,
placeholder: "Add criteria points/weight here",
required: true,
Expand Down
22 changes: 20 additions & 2 deletions app/views/evaluation_forms/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,29 @@
</legend>
<div class="display-flex flex-row">
<div class="usa-radio margin-right-205">
<input class="usa-radio__input" id="point_scale" type="radio" name="evaluation_form[weighted_scoring]" value="false" <%= 'checked' unless evaluation_form.weighted_scoring %> <%= 'disabled' unless !disabled %>>
<input
class="usa-radio__input"
id="point_scale"
type="radio"
name="evaluation_form[weighted_scoring]"
value="false"
data-action="input->evaluation-form#updateMaxPoints"
<%= 'checked' unless evaluation_form.weighted_scoring %>
<%= 'disabled' if disabled %>
>
<label class="usa-radio__label font-sans-xs" for="point_scale">Point Scale</label>
</div>
<div class="usa-radio">
<input class="usa-radio__input" id="weighted_scale" type="radio" name="evaluation_form[weighted_scoring]" value="true" <%= 'checked' if evaluation_form.weighted_scoring %> <%= 'disabled' unless !disabled %>>
<input
class="usa-radio__input"
id="weighted_scale"
type="radio"
name="evaluation_form[weighted_scoring]"
value="true"
data-action="input->evaluation-form#updateMaxPoints"
<%= 'checked' if evaluation_form.weighted_scoring %>
<%= 'disabled' if disabled %>
>
<label class="usa-radio__label font-sans-xs" for="weighted_scale">Weighted Scale (%)</label>
</div>
</div>
Expand Down
9 changes: 9 additions & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions spec/helpers/phases_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion spec/models/evaluation_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 13 additions & 7 deletions spec/requests/evaluation_forms_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand Down Expand Up @@ -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) }

Expand Down

0 comments on commit 1af7ab4

Please sign in to comment.