From 00aebfd5649405f88f2be601d3a90fae0ab4b853 Mon Sep 17 00:00:00 2001 From: Daniel Aguilar Date: Tue, 20 Jun 2023 23:27:31 -0500 Subject: [PATCH 1/6] Reverting changes from previous branch --- .allow_skipping_tests | 1 - app/controllers/system_settings_controller.rb | 19 -------- app/policies/application_policy.rb | 1 - app/views/layouts/_sidebar.html.erb | 9 ---- app/views/system_settings/index.html.erb | 33 ------------- config/routes.rb | 1 - spec/policies/application_policy_spec.rb | 14 ------ spec/requests/system_settings_spec.rb | 46 ------------------- spec/views/layouts/sidebar.html.erb_spec.rb | 1 - .../system_settings/index.html.erb_spec.rb | 21 --------- 10 files changed, 146 deletions(-) delete mode 100644 app/controllers/system_settings_controller.rb delete mode 100644 app/views/system_settings/index.html.erb delete mode 100644 spec/requests/system_settings_spec.rb delete mode 100644 spec/views/system_settings/index.html.erb_spec.rb diff --git a/.allow_skipping_tests b/.allow_skipping_tests index b8ba3680e2..0d46f29d2b 100644 --- a/.allow_skipping_tests +++ b/.allow_skipping_tests @@ -42,7 +42,6 @@ controllers/placement_reports_controller.rb controllers/reports_controller.rb controllers/supervisor_volunteers_controller.rb controllers/supervisors_controller.rb -controllers/system_settings_controller.rb controllers/users/passwords_controller.rb controllers/users/sessions_controller.rb controllers/users_controller.rb diff --git a/app/controllers/system_settings_controller.rb b/app/controllers/system_settings_controller.rb deleted file mode 100644 index 4b1a83fa4f..0000000000 --- a/app/controllers/system_settings_controller.rb +++ /dev/null @@ -1,19 +0,0 @@ -class SystemSettingsController < ApplicationController - after_action :verify_authorized - - def index - authorize :application, :edit_system_settings? - - @show_additional_expenses = FeatureFlagService.is_enabled?(FeatureFlagService::SHOW_ADDITIONAL_EXPENSES_FLAG) - end - - def create - authorize :application, :edit_system_settings? - - if params[:show_additional_expenses] - FeatureFlagService.enable!(FeatureFlagService::SHOW_ADDITIONAL_EXPENSES_FLAG) - else - FeatureFlagService.disable!(FeatureFlagService::SHOW_ADDITIONAL_EXPENSES_FLAG) - end - end -end diff --git a/app/policies/application_policy.rb b/app/policies/application_policy.rb index 674621027b..f4cc0cc98f 100644 --- a/app/policies/application_policy.rb +++ b/app/policies/application_policy.rb @@ -142,6 +142,5 @@ def current_organization end alias_method :modify_organization?, :is_admin? - alias_method :edit_system_settings?, :is_admin? alias_method :see_import_page?, :is_admin? end diff --git a/app/views/layouts/_sidebar.html.erb b/app/views/layouts/_sidebar.html.erb index 3af013153d..361a44f8e1 100644 --- a/app/views/layouts/_sidebar.html.erb +++ b/app/views/layouts/_sidebar.html.erb @@ -142,15 +142,6 @@ <% end %> - <% if policy(:application).edit_system_settings? %> -
  • - <%= link_to settings_path, class: "#{active_class(settings_path)}" do %> - - System Settings - <% end %> -
  • - <% end %> - <% if policy(:application).see_mileage_rate? %>
  • <%= link_to mileage_rates_path, class: "#{active_class(mileage_rates_path)}" do %> diff --git a/app/views/system_settings/index.html.erb b/app/views/system_settings/index.html.erb deleted file mode 100644 index 3d231119a1..0000000000 --- a/app/views/system_settings/index.html.erb +++ /dev/null @@ -1,33 +0,0 @@ -
    -
    -
    -
    -

    Feature Toggles

    -
    -
    -
    -
    - -
    -
    -
    -

    New Case Contact Form

    -
    - <%= form_with(url: settings_path, local: true) do |form| %> -
    - <%= check_box_tag :show_additional_expenses, 'true', @show_additional_expenses, class: 'form-check-input' %> - <%= form.label :show_additional_expenses, " Volunteers can add Other Expenses", class: 'form-check-label mb-2' %> -
    - -
    - <%= button_tag( - type: "submit", - class: "btn-sm main-btn primary-btn btn-hover" - ) do %> - Submit - <% end %> -
    - <% end %> -
    -
    -
    diff --git a/config/routes.rb b/config/routes.rb index 235e784805..0a7d68cea8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -87,7 +87,6 @@ get :download_failed end end - resources :settings, only: %i[index create], controller: "system_settings" resources :case_contact_reports, only: %i[index] resources :mileage_reports, only: %i[index] resources :mileage_rates, only: %i[index new create edit update] diff --git a/spec/policies/application_policy_spec.rb b/spec/policies/application_policy_spec.rb index df5dc1ee78..300cf10ebc 100644 --- a/spec/policies/application_policy_spec.rb +++ b/spec/policies/application_policy_spec.rb @@ -87,18 +87,4 @@ end end end - - permissions :edit_system_settings? do - it "does not allow volunters" do - is_expected.not_to permit(volunteer) - end - - it "does not allow supervisors" do - is_expected.not_to permit(supervisor) - end - - it "allow casa_admins for same org" do - is_expected.to permit(casa_admin) - end - end end diff --git a/spec/requests/system_settings_spec.rb b/spec/requests/system_settings_spec.rb deleted file mode 100644 index 93185f4f5d..0000000000 --- a/spec/requests/system_settings_spec.rb +++ /dev/null @@ -1,46 +0,0 @@ -require "rails_helper" - -RSpec.describe "/settings", type: :request do - let(:admin) { create(:casa_admin) } - - describe "GET /index" do - it "renders a successful response" do - sign_in admin - - get settings_path - expect(response).to be_successful - end - end - - describe "POST /create" do - before do - sign_in admin - end - - context "with show_additional_expense param" do - let(:params) do - { - show_additional_expenses: "true" - } - end - - it "enables the show additional expense flag" do - FeatureFlagService.disable!(FeatureFlagService::SHOW_ADDITIONAL_EXPENSES_FLAG) - post settings_path, params: params - expect(FeatureFlagService.is_enabled?(FeatureFlagService::SHOW_ADDITIONAL_EXPENSES_FLAG)).to be true - end - end - - context "without show_additional_expense param" do - let(:params) do - {} - end - - it "enables the show additional expense flag" do - FeatureFlagService.enable!(FeatureFlagService::SHOW_ADDITIONAL_EXPENSES_FLAG) - post settings_path, params: params - expect(FeatureFlagService.is_enabled?(FeatureFlagService::SHOW_ADDITIONAL_EXPENSES_FLAG)).to be false - end - end - end -end diff --git a/spec/views/layouts/sidebar.html.erb_spec.rb b/spec/views/layouts/sidebar.html.erb_spec.rb index e9edca8e11..9f07b8e9c0 100644 --- a/spec/views/layouts/sidebar.html.erb_spec.rb +++ b/spec/views/layouts/sidebar.html.erb_spec.rb @@ -142,7 +142,6 @@ def true_user expect(rendered).to have_link("Edit Organization", href: "/casa_org/#{user.casa_org.id}/edit") expect(rendered).to have_link("Generate Court Reports", href: "/case_court_reports") expect(rendered).to have_link("Export Data", href: "/reports") - expect(rendered).to have_link("System Settings", href: "/settings") expect(rendered).to_not have_link("Emancipation Checklist", href: "/emancipation_checklists") end end diff --git a/spec/views/system_settings/index.html.erb_spec.rb b/spec/views/system_settings/index.html.erb_spec.rb deleted file mode 100644 index b4ee041a25..0000000000 --- a/spec/views/system_settings/index.html.erb_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -require "rails_helper" - -RSpec.describe "System Settings", type: :view do - let(:admin) { build_stubbed :casa_admin } - - before do - enable_pundit(view, admin) - allow(view).to receive(:current_user).and_return(admin) - sign_in admin - end - - it "has a Feature Toggles menu option" do - assign :show_additional_expenses, true - - render template: "system_settings/index" - - expect(rendered).to have_text("Feature Toggles") - expect(rendered).to have_text("New Case Contact Form") - expect(rendered).to have_checked_field("show_additional_expenses") - end -end From ab058d1e031bc0603842630582c99bcd19e1a50c Mon Sep 17 00:00:00 2001 From: Daniel Aguilar Date: Wed, 21 Jun 2023 10:14:03 -0500 Subject: [PATCH 2/6] Added spec to ensure that additional expenses can be set at an org level --- .../case_contacts/additional_expenses_spec.rb | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/spec/system/case_contacts/additional_expenses_spec.rb b/spec/system/case_contacts/additional_expenses_spec.rb index f5fcb07c3a..b1d90edcc5 100644 --- a/spec/system/case_contacts/additional_expenses_spec.rb +++ b/spec/system/case_contacts/additional_expenses_spec.rb @@ -1,12 +1,38 @@ require "rails_helper" require "action_view" -RSpec.describe "addtional_expenses", type: :system do +RSpec.describe "additional_expenses", type: :system do + it "can be set per organization" do + FeatureFlagService.enable!(FeatureFlagService::SHOW_ADDITIONAL_EXPENSES_FLAG) + organization = build(:casa_org) + volunteer = create(:volunteer, casa_org: organization) + casa_case = create(:casa_case, casa_org: organization) + create(:case_assignment, casa_case: casa_case, volunteer: volunteer) + + other_organization = build(:casa_org) + other_volunteer = create(:volunteer, casa_org: other_organization) + other_casa_case = create(:casa_case, casa_org: other_organization) + create(:case_assignment, casa_case: other_casa_case, volunteer: other_volunteer) + + sign_in volunteer + visit casa_case_path(casa_case.id) + click_on "New Case Contact" + + expect(page).to have_text("Other Expenses") + + sign_in other_volunteer + visit casa_case_path(other_casa_case.id) + click_on "New Case Contact" + + expect(page).not_to have_text("Other Expenses") + end + it "additional expenses fields appearance", js: true do - FeatureFlagService.enable!("show_additional_expenses") + FeatureFlagService.enable!(FeatureFlagService::SHOW_ADDITIONAL_EXPENSES_FLAG) organization = build(:casa_org) volunteer = create(:volunteer, casa_org: organization) casa_case = create(:casa_case, casa_org: organization) + create(:case_assignment, casa_case: casa_case, volunteer: volunteer) contact_type_group = build(:contact_type_group, casa_org: organization) create(:contact_type) From f900e48e465ddc57479b589eac3fadd78c55fcf4 Mon Sep 17 00:00:00 2001 From: Daniel Aguilar Date: Wed, 21 Jun 2023 11:11:15 -0500 Subject: [PATCH 3/6] Pulled FeatureFlag into a case_contact policy --- app/controllers/case_contacts_controller.rb | 4 ++-- app/policies/case_contact_policy.rb | 4 ++++ app/views/case_contacts/_form.html.erb | 2 +- spec/system/case_contacts/additional_expenses_spec.rb | 8 ++++---- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/app/controllers/case_contacts_controller.rb b/app/controllers/case_contacts_controller.rb index ad48f79b6b..89622b4de8 100644 --- a/app/controllers/case_contacts_controller.rb +++ b/app/controllers/case_contacts_controller.rb @@ -102,7 +102,7 @@ def update @current_organization_groups = current_organization.contact_type_groups if @case_contact.update_cleaning_contact_types(update_case_contact_params) - if additional_expense_params&.any? && FeatureFlagService.is_enabled?(FeatureFlagService::SHOW_ADDITIONAL_EXPENSES_FLAG) + if additional_expense_params&.any? && policy(:case_contact).additional_expenses_allowed? update_or_create_additional_expense(additional_expense_params, @case_contact) end if @case_contact.valid? @@ -156,7 +156,7 @@ def save_or_add_error(obj, case_contact) def create_case_contact_for_every_selected_casa_case(selected_cases) selected_cases.map do |casa_case| - if FeatureFlagService.is_enabled?(FeatureFlagService::SHOW_ADDITIONAL_EXPENSES_FLAG) + if policy(:case_contact).additional_expenses_allowed? new_cc = casa_case.case_contacts.new(create_case_contact_params.except(:casa_case_attributes)) update_or_create_additional_expense(additional_expense_params, new_cc) if new_cc.valid? diff --git a/app/policies/case_contact_policy.rb b/app/policies/case_contact_policy.rb index a0c43c8ec6..28efdabc58 100644 --- a/app/policies/case_contact_policy.rb +++ b/app/policies/case_contact_policy.rb @@ -7,6 +7,10 @@ def is_creator_or_supervisor_or_casa_admin? is_creator? || admin_or_supervisor? end + def additional_expenses_allowed? + FeatureFlagService.is_enabled?(FeatureFlagService::SHOW_ADDITIONAL_EXPENSES_FLAG) + end + alias_method :index?, :admin_or_supervisor_or_volunteer? alias_method :new?, :admin_or_supervisor_or_volunteer? alias_method :show?, :is_creator_or_casa_admin? diff --git a/app/views/case_contacts/_form.html.erb b/app/views/case_contacts/_form.html.erb index 289c70ebee..a95ef6bce1 100644 --- a/app/views/case_contacts/_form.html.erb +++ b/app/views/case_contacts/_form.html.erb @@ -166,7 +166,7 @@ readonly: true %> <% end %> - <% if FeatureFlagService.is_enabled?(FeatureFlagService::SHOW_ADDITIONAL_EXPENSES_FLAG) %> + <% if policy(:case_contact).additional_expenses_allowed? %>
    <%= form.label :additional_expense, "d. Other Expenses" %>
      diff --git a/spec/system/case_contacts/additional_expenses_spec.rb b/spec/system/case_contacts/additional_expenses_spec.rb index b1d90edcc5..4bd98f1f63 100644 --- a/spec/system/case_contacts/additional_expenses_spec.rb +++ b/spec/system/case_contacts/additional_expenses_spec.rb @@ -20,11 +20,11 @@ expect(page).to have_text("Other Expenses") - sign_in other_volunteer - visit casa_case_path(other_casa_case.id) - click_on "New Case Contact" + # sign_in other_volunteer + # visit casa_case_path(other_casa_case.id) + # click_on "New Case Contact" - expect(page).not_to have_text("Other Expenses") + # expect(page).not_to have_text("Other Expenses") end it "additional expenses fields appearance", js: true do From e23243636e7c99d5f5e7b278bf2af27d17e8340c Mon Sep 17 00:00:00 2001 From: Daniel Aguilar Date: Wed, 21 Jun 2023 11:28:34 -0500 Subject: [PATCH 4/6] Added new property to casa org and tied it into casa_contact_policy --- app/models/casa_org.rb | 31 +- app/policies/case_contact_policy.rb | 3 +- ...52_add_additional_expenses_to_casa_orgs.rb | 5 + db/schema.rb | 3 +- .../case_contacts/additional_expenses_spec.rb | 411 +++++++++--------- 5 files changed, 219 insertions(+), 234 deletions(-) create mode 100644 db/migrate/20230621161252_add_additional_expenses_to_casa_orgs.rb diff --git a/app/models/casa_org.rb b/app/models/casa_org.rb index 92dfb1ba4a..6e25a6946e 100644 --- a/app/models/casa_org.rb +++ b/app/models/casa_org.rb @@ -117,21 +117,22 @@ def normalize_phone_number # # Table name: casa_orgs # -# id :bigint not null, primary key -# address :string -# display_name :string -# footer_links :string default([]), is an Array -# name :string not null -# show_driving_reimbursement :boolean default(TRUE) -# show_fund_request :boolean default(FALSE) -# slug :string -# twilio_account_sid :string -# twilio_api_key_secret :string -# twilio_api_key_sid :string -# twilio_enabled :boolean default(FALSE) -# twilio_phone_number :string -# created_at :datetime not null -# updated_at :datetime not null +# id :bigint not null, primary key +# additional_expenses_enabled :boolean default(FALSE) +# address :string +# display_name :string +# footer_links :string default([]), is an Array +# name :string not null +# show_driving_reimbursement :boolean default(TRUE) +# show_fund_request :boolean default(FALSE) +# slug :string +# twilio_account_sid :string +# twilio_api_key_secret :string +# twilio_api_key_sid :string +# twilio_enabled :boolean default(FALSE) +# twilio_phone_number :string +# created_at :datetime not null +# updated_at :datetime not null # # Indexes # diff --git a/app/policies/case_contact_policy.rb b/app/policies/case_contact_policy.rb index 28efdabc58..decad8e1f2 100644 --- a/app/policies/case_contact_policy.rb +++ b/app/policies/case_contact_policy.rb @@ -8,7 +8,8 @@ def is_creator_or_supervisor_or_casa_admin? end def additional_expenses_allowed? - FeatureFlagService.is_enabled?(FeatureFlagService::SHOW_ADDITIONAL_EXPENSES_FLAG) + FeatureFlagService.is_enabled?(FeatureFlagService::SHOW_ADDITIONAL_EXPENSES_FLAG) && + current_organization.additional_expenses_enabled end alias_method :index?, :admin_or_supervisor_or_volunteer? diff --git a/db/migrate/20230621161252_add_additional_expenses_to_casa_orgs.rb b/db/migrate/20230621161252_add_additional_expenses_to_casa_orgs.rb new file mode 100644 index 0000000000..62d75f65c1 --- /dev/null +++ b/db/migrate/20230621161252_add_additional_expenses_to_casa_orgs.rb @@ -0,0 +1,5 @@ +class AddAdditionalExpensesToCasaOrgs < ActiveRecord::Migration[7.0] + def change + add_column :casa_orgs, :additional_expenses_enabled, :boolean, default: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 2c96e03de2..6c59573029 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_06_15_155223) do +ActiveRecord::Schema[7.0].define(version: 2023_06_21_161252) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -141,6 +141,7 @@ t.string "twilio_api_key_sid" t.string "twilio_api_key_secret" t.boolean "twilio_enabled", default: false + t.boolean "additional_expenses_enabled", default: false t.index ["slug"], name: "index_casa_orgs_on_slug", unique: true end diff --git a/spec/system/case_contacts/additional_expenses_spec.rb b/spec/system/case_contacts/additional_expenses_spec.rb index 4bd98f1f63..22bdd938b0 100644 --- a/spec/system/case_contacts/additional_expenses_spec.rb +++ b/spec/system/case_contacts/additional_expenses_spec.rb @@ -2,13 +2,16 @@ require "action_view" RSpec.describe "additional_expenses", type: :system do - it "can be set per organization" do + let(:organization) { build(:casa_org, additional_expenses_enabled: true) } + let(:volunteer) { create(:volunteer, casa_org: organization) } + let(:casa_case) { create(:casa_case, casa_org: organization) } + + before do FeatureFlagService.enable!(FeatureFlagService::SHOW_ADDITIONAL_EXPENSES_FLAG) - organization = build(:casa_org) - volunteer = create(:volunteer, casa_org: organization) - casa_case = create(:casa_case, casa_org: organization) create(:case_assignment, casa_case: casa_case, volunteer: volunteer) + end + it "can be set per organization" do other_organization = build(:casa_org) other_volunteer = create(:volunteer, casa_org: other_organization) other_casa_case = create(:casa_case, casa_org: other_organization) @@ -20,236 +23,210 @@ expect(page).to have_text("Other Expenses") - # sign_in other_volunteer - # visit casa_case_path(other_casa_case.id) - # click_on "New Case Contact" - - # expect(page).not_to have_text("Other Expenses") - end - - it "additional expenses fields appearance", js: true do - FeatureFlagService.enable!(FeatureFlagService::SHOW_ADDITIONAL_EXPENSES_FLAG) - organization = build(:casa_org) - volunteer = create(:volunteer, casa_org: organization) - casa_case = create(:casa_case, casa_org: organization) - - create(:case_assignment, casa_case: casa_case, volunteer: volunteer) - contact_type_group = build(:contact_type_group, casa_org: organization) - create(:contact_type) - create(:contact_type, name: "School", contact_type_group: contact_type_group) - - sign_in volunteer - - visit casa_case_path(casa_case.id) - + sign_in other_volunteer + visit casa_case_path(other_casa_case.id) click_on "New Case Contact" - fill_out_minimum_required_fields_for_case_contact_form - - expect(page).to have_text("Add Another Expense") - expect(page).to have_field("case_contact_additional_expenses_attributes_0_other_expense_amount") - expect(page).to have_no_field("case_contact_additional_expenses_attributes_1_other_expense_amount") - find_by_id("case_contact_additional_expenses_attributes_0_other_expense_amount").fill_in(with: "5.34") - find_by_id("case_contact_additional_expenses_attributes_0_other_expenses_describe").fill_in(with: "Lunch") - - expect { - click_on "Submit" - }.to change(CaseContact, :count).by(1).and change(AdditionalExpense, :count).by(1) - - visit edit_case_contact_path(casa_case.reload.case_contacts.last) - expect(page).to have_text("Editing Case Contact") - expect(page).to have_field("case_contact_additional_expenses_attributes_0_other_expense_amount", with: "5.34") - expect(page).to have_field("case_contact_additional_expenses_attributes_0_other_expenses_describe", with: "Lunch") - expect(page).to have_field("case_contact_additional_expenses_attributes_1_other_expense_amount") - expect(page).to have_no_field("case_contact_additional_expenses_attributes_2_other_expense_amount") - expect(page).to have_text("Add Another Expense") + expect(page).not_to have_text("Other Expenses") end - it "additional expenses for multiple entries", js: true do - FeatureFlagService.enable!("show_additional_expenses") - organization = build(:casa_org) - volunteer = create(:volunteer, casa_org: organization) - casa_case = create(:casa_case, casa_org: organization) - create(:case_assignment, casa_case: casa_case, volunteer: volunteer) - contact_type_group = build(:contact_type_group, casa_org: organization) - create(:contact_type) - create(:contact_type, name: "School", contact_type_group: contact_type_group) - sign_in volunteer + context "when setting additional expenses" do + let(:contact_type_group) { build(:contact_type_group, casa_org: organization) } - visit casa_case_path(casa_case.id) + before do + create(:contact_type) + create(:contact_type, name: "School", contact_type_group: contact_type_group) + end - click_on "New Case Contact" + it "additional expenses fields appearance", js: true do + sign_in volunteer - fill_out_minimum_required_fields_for_case_contact_form - - expect(page).to have_text("Add Another Expense") - expect(page).to have_field("case_contact_additional_expenses_attributes_0_other_expense_amount") - expect(page).to have_no_field("case_contact_additional_expenses_attributes_1_other_expense_amount") - find_by_id("case_contact_additional_expenses_attributes_0_other_expense_amount").fill_in(with: "7.21") - find_by_id("case_contact_additional_expenses_attributes_0_other_expenses_describe").fill_in(with: "Toll") - - find_by_id("add-another-expense").click - expect(page).to have_field("case_contact_additional_expenses_attributes_1_other_expense_amount") - expect(page).to have_no_field("case_contact_additional_expenses_attributes_2_other_expense_amount") - - find_by_id("case_contact_additional_expenses_attributes_1_other_expense_amount").fill_in(with: "7.22") - find_by_id("case_contact_additional_expenses_attributes_1_other_expenses_describe").fill_in(with: "Another Toll") - expect(page).to have_text("Add Another Expense") - - expect { - click_on "Submit" - }.to change(CaseContact, :count).by(1).and change(AdditionalExpense, :count).by(2) - - visit edit_case_contact_path(casa_case.reload.case_contacts.last) - expect(page).to have_text("Editing Case Contact") - expect(page).to have_field("case_contact_additional_expenses_attributes_0_other_expense_amount", with: "7.21") - expect(page).to have_field("case_contact_additional_expenses_attributes_0_other_expenses_describe", with: "Toll") - expect(page).to have_field("case_contact_additional_expenses_attributes_1_other_expense_amount", with: "7.22") - expect(page).to have_field("case_contact_additional_expenses_attributes_1_other_expenses_describe", with: "Another Toll") - expect(page).to have_field("case_contact_additional_expenses_attributes_2_other_expense_amount") - expect(page).to have_text("Add Another Expense") - - find_by_id("case_contact_additional_expenses_attributes_0_other_expenses_describe").fill_in(with: "Breakfast") - find_by_id("case_contact_additional_expenses_attributes_1_other_expense_amount").fill_in(with: "7.23") - find_by_id("case_contact_additional_expenses_attributes_2_other_expense_amount").fill_in(with: "8.23") - find_by_id("case_contact_additional_expenses_attributes_2_other_expenses_describe").fill_in(with: "Yet another toll") - - expect { - click_on "Submit" - }.to change(CaseContact, :count).by(0).and change(AdditionalExpense, :count).by(1) - - visit edit_case_contact_path(casa_case.reload.case_contacts.last) - - expect(page).to have_text("Editing Case Contact") - expect(page).to have_field("case_contact_additional_expenses_attributes_2_other_expense_amount", with: "8.23") - expect(page).to have_field("case_contact_additional_expenses_attributes_2_other_expenses_describe", with: "Yet another toll") - expect(page).to have_field("case_contact_additional_expenses_attributes_0_other_expenses_describe", with: "Breakfast") - expect(page).to have_field("case_contact_additional_expenses_attributes_1_other_expense_amount", with: "7.23") - expect(page).to have_field("case_contact_additional_expenses_attributes_3_other_expense_amount") - expect(page).to have_no_field("case_contact_additional_expenses_attributes_4_other_expense_amount") - find_by_id("add-another-expense").click - expect(page).to have_field("case_contact_additional_expenses_attributes_4_other_expense_amount") - end - it "additional expenses for maximum entries", js: true do - FeatureFlagService.enable!("show_additional_expenses") - organization = build(:casa_org) - volunteer = create(:volunteer, casa_org: organization) - casa_case = create(:casa_case, casa_org: organization) - create(:case_assignment, casa_case: casa_case, volunteer: volunteer) - contact_type_group = build(:contact_type_group, casa_org: organization) - create(:contact_type) - create(:contact_type, name: "School", contact_type_group: contact_type_group) + visit casa_case_path(casa_case.id) - sign_in volunteer + click_on "New Case Contact" - visit casa_case_path(casa_case.id) - - click_on "New Case Contact" + fill_out_minimum_required_fields_for_case_contact_form - fill_out_minimum_required_fields_for_case_contact_form + expect(page).to have_text("Add Another Expense") + expect(page).to have_field("case_contact_additional_expenses_attributes_0_other_expense_amount") + expect(page).to have_no_field("case_contact_additional_expenses_attributes_1_other_expense_amount") + find_by_id("case_contact_additional_expenses_attributes_0_other_expense_amount").fill_in(with: "5.34") + find_by_id("case_contact_additional_expenses_attributes_0_other_expenses_describe").fill_in(with: "Lunch") - expect(page).to have_text("Add Another Expense") + expect { + click_on "Submit" + }.to change(CaseContact, :count).by(1).and change(AdditionalExpense, :count).by(1) - expect(page).to have_field("case_contact_additional_expenses_attributes_0_other_expense_amount") - expect(page).to have_no_field("case_contact_additional_expenses_attributes_1_other_expense_amount") - expect(page).to have_no_field("case_contact_additional_expenses_attributes_1_other_expenses_describe") - find_by_id("case_contact_additional_expenses_attributes_0_other_expense_amount").fill_in(with: "0.11") - find_by_id("case_contact_additional_expenses_attributes_0_other_expenses_describe").fill_in(with: "1 meal") - expect(page).to have_text("Add Another Expense") + visit edit_case_contact_path(casa_case.reload.case_contacts.last) + expect(page).to have_text("Editing Case Contact") + expect(page).to have_field("case_contact_additional_expenses_attributes_0_other_expense_amount", with: "5.34") + expect(page).to have_field("case_contact_additional_expenses_attributes_0_other_expenses_describe", with: "Lunch") + expect(page).to have_field("case_contact_additional_expenses_attributes_1_other_expense_amount") + expect(page).to have_no_field("case_contact_additional_expenses_attributes_2_other_expense_amount") + expect(page).to have_text("Add Another Expense") + end - (1..9).each { |i| - find_by_id("add-another-expense").click - expect(page).to have_field("case_contact_additional_expenses_attributes_#{i}_other_expense_amount") - expect(page).to have_field("case_contact_additional_expenses_attributes_#{i}_other_expenses_describe") - expect(page).to have_no_field("case_contact_additional_expenses_attributes_#{i + 1}_other_expense_amount") - expect(page).to have_no_field("case_contact_additional_expenses_attributes_#{i + 1}_other_expenses_describe") - find_by_id("case_contact_additional_expenses_attributes_#{i}_other_expense_amount").fill_in(with: "#{i}.11") - find_by_id("case_contact_additional_expenses_attributes_#{i}_other_expenses_describe").fill_in(with: "#{i + 1} meal") - } - - expect { - click_on "Submit" - }.to change(CaseContact, :count).by(1).and change(AdditionalExpense, :count).by(10) - - visit edit_case_contact_path(casa_case.reload.case_contacts.last) - expect(page).to have_text("Editing Case Contact") - expect(page).to have_field("case_contact_additional_expenses_attributes_0_other_expense_amount", with: "0.11") - expect(page).to have_field("case_contact_additional_expenses_attributes_0_other_expenses_describe", with: "1 meal") - expect(page).to have_field("case_contact_additional_expenses_attributes_1_other_expense_amount", with: "1.11") - expect(page).to have_field("case_contact_additional_expenses_attributes_1_other_expenses_describe", with: "2 meal") - expect(page).to have_field("case_contact_additional_expenses_attributes_2_other_expense_amount", with: "2.11") - expect(page).to have_field("case_contact_additional_expenses_attributes_2_other_expenses_describe", with: "3 meal") - expect(page).to have_field("case_contact_additional_expenses_attributes_3_other_expense_amount", with: "3.11") - expect(page).to have_field("case_contact_additional_expenses_attributes_3_other_expenses_describe", with: "4 meal") - expect(page).to have_field("case_contact_additional_expenses_attributes_4_other_expense_amount", with: "4.11") - expect(page).to have_field("case_contact_additional_expenses_attributes_4_other_expenses_describe", with: "5 meal") - expect(page).to have_field("case_contact_additional_expenses_attributes_5_other_expense_amount", with: "5.11") - expect(page).to have_field("case_contact_additional_expenses_attributes_5_other_expenses_describe", with: "6 meal") - expect(page).to have_field("case_contact_additional_expenses_attributes_6_other_expense_amount", with: "6.11") - expect(page).to have_field("case_contact_additional_expenses_attributes_6_other_expenses_describe", with: "7 meal") - expect(page).to have_field("case_contact_additional_expenses_attributes_7_other_expense_amount", with: "7.11") - expect(page).to have_field("case_contact_additional_expenses_attributes_7_other_expenses_describe", with: "8 meal") - expect(page).to have_field("case_contact_additional_expenses_attributes_8_other_expense_amount", with: "8.11") - expect(page).to have_field("case_contact_additional_expenses_attributes_8_other_expenses_describe", with: "9 meal") - expect(page).to have_field("case_contact_additional_expenses_attributes_9_other_expense_amount", with: "9.11") - expect(page).to have_field("case_contact_additional_expenses_attributes_9_other_expenses_describe", with: "10 meal") - - expect(page).to have_no_field("case_contact_additional_expenses_attributes_10_other_expense_amount") - expect(page).to have_no_field("case_contact_additional_expenses_attributes_10_other_expenses_describe") - expect(page).to have_no_text("Add Another Expense") - end + it "additional expenses for multiple entries", js: true do + sign_in volunteer - it "verifies that an additional expense without a description will cause an error", js: true do - FeatureFlagService.enable!("show_additional_expenses") - organization = build(:casa_org) - volunteer = create(:volunteer, casa_org: organization) - casa_case = create(:casa_case, casa_org: organization) - create(:case_assignment, casa_case: casa_case, volunteer: volunteer) - contact_type_group = build(:contact_type_group, casa_org: organization) - create(:contact_type) - create(:contact_type, name: "School", contact_type_group: contact_type_group) + visit casa_case_path(casa_case.id) - sign_in volunteer - - visit casa_case_path(casa_case.id) - - click_on "New Case Contact" + click_on "New Case Contact" - fill_out_minimum_required_fields_for_case_contact_form + fill_out_minimum_required_fields_for_case_contact_form - expect(page).to have_text("Add Another Expense") - expect(page).to have_field("case_contact_additional_expenses_attributes_0_other_expense_amount") - expect(page).to have_no_field("case_contact_additional_expenses_attributes_1_other_expense_amount") - find_by_id("case_contact_additional_expenses_attributes_0_other_expense_amount").fill_in(with: "5.34") + expect(page).to have_text("Add Another Expense") + expect(page).to have_field("case_contact_additional_expenses_attributes_0_other_expense_amount") + expect(page).to have_no_field("case_contact_additional_expenses_attributes_1_other_expense_amount") + find_by_id("case_contact_additional_expenses_attributes_0_other_expense_amount").fill_in(with: "7.21") + find_by_id("case_contact_additional_expenses_attributes_0_other_expenses_describe").fill_in(with: "Toll") - expect { - click_on "Submit" - }.to change(CaseContact, :count).by(0).and change(AdditionalExpense, :count).by(0) - - expect(page).to have_text("error") - - find_by_id("case_contact_additional_expenses_attributes_0_other_expenses_describe").fill_in(with: "1 meal") - - expect { - click_on "Submit" - }.to change(CaseContact, :count).by(1).and change(AdditionalExpense, :count).by(1) - expect(page).not_to have_text("error") - - visit edit_case_contact_path(casa_case.reload.case_contacts.last) - # Confirming validation and correct errors to user for update method - - find_by_id("case_contact_additional_expenses_attributes_1_other_expense_amount").fill_in(with: "7.45") - - expect { - click_on "Submit" - }.to change(CaseContact, :count).by(0).and change(AdditionalExpense, :count).by(0) - expect(page).to have_text("error") - - find_by_id("case_contact_additional_expenses_attributes_1_other_expenses_describe").fill_in(with: "2nd meal") - - expect { - click_on "Submit" - }.to change(CaseContact, :count).by(0).and change(AdditionalExpense, :count).by(1) - expect(page).not_to have_text("error") + find_by_id("add-another-expense").click + expect(page).to have_field("case_contact_additional_expenses_attributes_1_other_expense_amount") + expect(page).to have_no_field("case_contact_additional_expenses_attributes_2_other_expense_amount") + + find_by_id("case_contact_additional_expenses_attributes_1_other_expense_amount").fill_in(with: "7.22") + find_by_id("case_contact_additional_expenses_attributes_1_other_expenses_describe").fill_in(with: "Another Toll") + expect(page).to have_text("Add Another Expense") + + expect { + click_on "Submit" + }.to change(CaseContact, :count).by(1).and change(AdditionalExpense, :count).by(2) + + visit edit_case_contact_path(casa_case.reload.case_contacts.last) + expect(page).to have_text("Editing Case Contact") + expect(page).to have_field("case_contact_additional_expenses_attributes_0_other_expense_amount", with: "7.21") + expect(page).to have_field("case_contact_additional_expenses_attributes_0_other_expenses_describe", with: "Toll") + expect(page).to have_field("case_contact_additional_expenses_attributes_1_other_expense_amount", with: "7.22") + expect(page).to have_field("case_contact_additional_expenses_attributes_1_other_expenses_describe", with: "Another Toll") + expect(page).to have_field("case_contact_additional_expenses_attributes_2_other_expense_amount") + expect(page).to have_text("Add Another Expense") + + find_by_id("case_contact_additional_expenses_attributes_0_other_expenses_describe").fill_in(with: "Breakfast") + find_by_id("case_contact_additional_expenses_attributes_1_other_expense_amount").fill_in(with: "7.23") + find_by_id("case_contact_additional_expenses_attributes_2_other_expense_amount").fill_in(with: "8.23") + find_by_id("case_contact_additional_expenses_attributes_2_other_expenses_describe").fill_in(with: "Yet another toll") + + expect { + click_on "Submit" + }.to change(CaseContact, :count).by(0).and change(AdditionalExpense, :count).by(1) + + visit edit_case_contact_path(casa_case.reload.case_contacts.last) + + expect(page).to have_text("Editing Case Contact") + expect(page).to have_field("case_contact_additional_expenses_attributes_2_other_expense_amount", with: "8.23") + expect(page).to have_field("case_contact_additional_expenses_attributes_2_other_expenses_describe", with: "Yet another toll") + expect(page).to have_field("case_contact_additional_expenses_attributes_0_other_expenses_describe", with: "Breakfast") + expect(page).to have_field("case_contact_additional_expenses_attributes_1_other_expense_amount", with: "7.23") + expect(page).to have_field("case_contact_additional_expenses_attributes_3_other_expense_amount") + expect(page).to have_no_field("case_contact_additional_expenses_attributes_4_other_expense_amount") + find_by_id("add-another-expense").click + expect(page).to have_field("case_contact_additional_expenses_attributes_4_other_expense_amount") + end + + it "additional expenses for maximum entries", js: true do + sign_in volunteer + + visit casa_case_path(casa_case.id) + + click_on "New Case Contact" + + fill_out_minimum_required_fields_for_case_contact_form + + expect(page).to have_text("Add Another Expense") + + expect(page).to have_field("case_contact_additional_expenses_attributes_0_other_expense_amount") + expect(page).to have_no_field("case_contact_additional_expenses_attributes_1_other_expense_amount") + expect(page).to have_no_field("case_contact_additional_expenses_attributes_1_other_expenses_describe") + find_by_id("case_contact_additional_expenses_attributes_0_other_expense_amount").fill_in(with: "0.11") + find_by_id("case_contact_additional_expenses_attributes_0_other_expenses_describe").fill_in(with: "1 meal") + expect(page).to have_text("Add Another Expense") + + (1..9).each { |i| + find_by_id("add-another-expense").click + expect(page).to have_field("case_contact_additional_expenses_attributes_#{i}_other_expense_amount") + expect(page).to have_field("case_contact_additional_expenses_attributes_#{i}_other_expenses_describe") + expect(page).to have_no_field("case_contact_additional_expenses_attributes_#{i + 1}_other_expense_amount") + expect(page).to have_no_field("case_contact_additional_expenses_attributes_#{i + 1}_other_expenses_describe") + find_by_id("case_contact_additional_expenses_attributes_#{i}_other_expense_amount").fill_in(with: "#{i}.11") + find_by_id("case_contact_additional_expenses_attributes_#{i}_other_expenses_describe").fill_in(with: "#{i + 1} meal") + } + + expect { + click_on "Submit" + }.to change(CaseContact, :count).by(1).and change(AdditionalExpense, :count).by(10) + + visit edit_case_contact_path(casa_case.reload.case_contacts.last) + expect(page).to have_text("Editing Case Contact") + expect(page).to have_field("case_contact_additional_expenses_attributes_0_other_expense_amount", with: "0.11") + expect(page).to have_field("case_contact_additional_expenses_attributes_0_other_expenses_describe", with: "1 meal") + expect(page).to have_field("case_contact_additional_expenses_attributes_1_other_expense_amount", with: "1.11") + expect(page).to have_field("case_contact_additional_expenses_attributes_1_other_expenses_describe", with: "2 meal") + expect(page).to have_field("case_contact_additional_expenses_attributes_2_other_expense_amount", with: "2.11") + expect(page).to have_field("case_contact_additional_expenses_attributes_2_other_expenses_describe", with: "3 meal") + expect(page).to have_field("case_contact_additional_expenses_attributes_3_other_expense_amount", with: "3.11") + expect(page).to have_field("case_contact_additional_expenses_attributes_3_other_expenses_describe", with: "4 meal") + expect(page).to have_field("case_contact_additional_expenses_attributes_4_other_expense_amount", with: "4.11") + expect(page).to have_field("case_contact_additional_expenses_attributes_4_other_expenses_describe", with: "5 meal") + expect(page).to have_field("case_contact_additional_expenses_attributes_5_other_expense_amount", with: "5.11") + expect(page).to have_field("case_contact_additional_expenses_attributes_5_other_expenses_describe", with: "6 meal") + expect(page).to have_field("case_contact_additional_expenses_attributes_6_other_expense_amount", with: "6.11") + expect(page).to have_field("case_contact_additional_expenses_attributes_6_other_expenses_describe", with: "7 meal") + expect(page).to have_field("case_contact_additional_expenses_attributes_7_other_expense_amount", with: "7.11") + expect(page).to have_field("case_contact_additional_expenses_attributes_7_other_expenses_describe", with: "8 meal") + expect(page).to have_field("case_contact_additional_expenses_attributes_8_other_expense_amount", with: "8.11") + expect(page).to have_field("case_contact_additional_expenses_attributes_8_other_expenses_describe", with: "9 meal") + expect(page).to have_field("case_contact_additional_expenses_attributes_9_other_expense_amount", with: "9.11") + expect(page).to have_field("case_contact_additional_expenses_attributes_9_other_expenses_describe", with: "10 meal") + + expect(page).to have_no_field("case_contact_additional_expenses_attributes_10_other_expense_amount") + expect(page).to have_no_field("case_contact_additional_expenses_attributes_10_other_expenses_describe") + expect(page).to have_no_text("Add Another Expense") + end + + it "verifies that an additional expense without a description will cause an error", js: true do + sign_in volunteer + + visit casa_case_path(casa_case.id) + + click_on "New Case Contact" + + fill_out_minimum_required_fields_for_case_contact_form + + expect(page).to have_text("Add Another Expense") + expect(page).to have_field("case_contact_additional_expenses_attributes_0_other_expense_amount") + expect(page).to have_no_field("case_contact_additional_expenses_attributes_1_other_expense_amount") + find_by_id("case_contact_additional_expenses_attributes_0_other_expense_amount").fill_in(with: "5.34") + + expect { + click_on "Submit" + }.to change(CaseContact, :count).by(0).and change(AdditionalExpense, :count).by(0) + + expect(page).to have_text("error") + + find_by_id("case_contact_additional_expenses_attributes_0_other_expenses_describe").fill_in(with: "1 meal") + + expect { + click_on "Submit" + }.to change(CaseContact, :count).by(1).and change(AdditionalExpense, :count).by(1) + expect(page).not_to have_text("error") + + visit edit_case_contact_path(casa_case.reload.case_contacts.last) + # Confirming validation and correct errors to user for update method + + find_by_id("case_contact_additional_expenses_attributes_1_other_expense_amount").fill_in(with: "7.45") + + expect { + click_on "Submit" + }.to change(CaseContact, :count).by(0).and change(AdditionalExpense, :count).by(0) + expect(page).to have_text("error") + + find_by_id("case_contact_additional_expenses_attributes_1_other_expenses_describe").fill_in(with: "2nd meal") + + expect { + click_on "Submit" + }.to change(CaseContact, :count).by(0).and change(AdditionalExpense, :count).by(1) + expect(page).not_to have_text("error") + end end end From c5ea9a270931ca434792127ed8a4175f2ca2d0f9 Mon Sep 17 00:00:00 2001 From: Daniel Aguilar Date: Wed, 21 Jun 2023 13:23:22 -0500 Subject: [PATCH 5/6] Added Additional Expeses option to Edit Organization form --- app/controllers/casa_org_controller.rb | 1 + app/views/casa_org/edit.html.erb | 4 ++++ spec/requests/casa_org_spec.rb | 5 ++++- spec/system/casa_org/edit_spec.rb | 4 ++++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/controllers/casa_org_controller.rb b/app/controllers/casa_org_controller.rb index 3a5d3c395f..d6ff7d9a81 100644 --- a/app/controllers/casa_org_controller.rb +++ b/app/controllers/casa_org_controller.rb @@ -46,6 +46,7 @@ def casa_org_update_params :logo, :court_report_template, :show_driving_reimbursement, + :additional_expenses_enabled, :twilio_account_sid, :twilio_phone_number, :twilio_api_key_sid, diff --git a/app/views/casa_org/edit.html.erb b/app/views/casa_org/edit.html.erb index 1b680abd5e..f556367be1 100644 --- a/app/views/casa_org/edit.html.erb +++ b/app/views/casa_org/edit.html.erb @@ -54,6 +54,10 @@ <%= form.check_box :show_driving_reimbursement, class: 'form-check-input' %> <%= form.label :show_driving_reimbursement, "Show driving reimbursement", class: 'form-check-label mb-2' %>
    +
    + <%= form.check_box :additional_expenses_enabled, class: 'form-check-input' %> + <%= form.label :additional_expenses_enabled, "Volunteers can add Other Expenses", class: 'form-check-label mb-2' %> +
    <%= button_tag( type: "submit", diff --git a/spec/requests/casa_org_spec.rb b/spec/requests/casa_org_spec.rb index 361dd634b0..b0d0b64a67 100644 --- a/spec/requests/casa_org_spec.rb +++ b/spec/requests/casa_org_spec.rb @@ -25,7 +25,8 @@ { name: "name", display_name: "display_name", address: "address", twilio_account_sid: "articuno34", twilio_api_key_sid: "Aladdin", - twilio_api_key_secret: "open sesame", twilio_phone_number: "+12223334444" + twilio_api_key_secret: "open sesame", twilio_phone_number: "+12223334444", + show_driving_reimbursement: "1", additional_expenses_enabled: "1" } end @@ -41,6 +42,8 @@ expect(casa_org.display_name).to eq "display_name" expect(casa_org.address).to eq "address" expect(casa_org.twilio_phone_number).to eq "+12223334444" + expect(casa_org.show_driving_reimbursement).to be true + expect(casa_org.additional_expenses_enabled).to be true end describe "on logo update" do diff --git a/spec/system/casa_org/edit_spec.rb b/spec/system/casa_org/edit_spec.rb index bdd0320ce1..bb8edf4e86 100644 --- a/spec/system/casa_org/edit_spec.rb +++ b/spec/system/casa_org/edit_spec.rb @@ -125,6 +125,10 @@ expect(page).to have_text("Twilio Phone Number") end + it "has option to enable additional expenses" do + expect(page).to have_text("Volunteers can add Other Expenses") + end + it "requires name text field" do expect(page).to have_selector("input[required=required]", id: "casa_org_name") end From 962ae9bb8c47cb767a9292d81b90ea8ea921645c Mon Sep 17 00:00:00 2001 From: Daniel Aguilar Date: Wed, 21 Jun 2023 14:09:54 -0500 Subject: [PATCH 6/6] Cleaned up tests --- app/views/case_contacts/_form.html.erb | 2 +- spec/requests/case_contacts_spec.rb | 1 + spec/system/case_contacts/additional_expenses_spec.rb | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/views/case_contacts/_form.html.erb b/app/views/case_contacts/_form.html.erb index a95ef6bce1..ddc95e3148 100644 --- a/app/views/case_contacts/_form.html.erb +++ b/app/views/case_contacts/_form.html.erb @@ -166,7 +166,7 @@ readonly: true %>
    <% end %> - <% if policy(:case_contact).additional_expenses_allowed? %> + <% if Pundit.policy(current_user, case_contact).additional_expenses_allowed? %>
    <%= form.label :additional_expense, "d. Other Expenses" %>
      diff --git a/spec/requests/case_contacts_spec.rb b/spec/requests/case_contacts_spec.rb index 6361d12a9f..bd85aa1628 100644 --- a/spec/requests/case_contacts_spec.rb +++ b/spec/requests/case_contacts_spec.rb @@ -143,6 +143,7 @@ before do FeatureFlagService.enable!(FeatureFlagService::SHOW_ADDITIONAL_EXPENSES_FLAG) + organization.additional_expenses_enabled = true end it "creates an additional expense with correct values", :aggregate_failures do diff --git a/spec/system/case_contacts/additional_expenses_spec.rb b/spec/system/case_contacts/additional_expenses_spec.rb index 22bdd938b0..a6d2e6c7e0 100644 --- a/spec/system/case_contacts/additional_expenses_spec.rb +++ b/spec/system/case_contacts/additional_expenses_spec.rb @@ -30,10 +30,10 @@ expect(page).not_to have_text("Other Expenses") end - context "when setting additional expenses" do + context "when setting additional expenses" do let(:contact_type_group) { build(:contact_type_group, casa_org: organization) } - before do + before do create(:contact_type) create(:contact_type, name: "School", contact_type_group: contact_type_group) end