Skip to content

Commit

Permalink
make flash localizable
Browse files Browse the repository at this point in the history
  • Loading branch information
Cameron Hicks committed Apr 13, 2023
1 parent 4da0c1c commit 7a7478e
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 14 deletions.
6 changes: 4 additions & 2 deletions app/controllers/funds_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class FundsController < ApplicationController
before_action :confirm_admin_user
before_action :confirm_data_access, only: [:edit, :update]
before_action :set_fund, only: %i[show edit update destroy]
before_action :set_fund, only: %i[show edit update]
rescue_from ActiveRecord::RecordNotFound, with: -> { head :bad_request }

# GET /funds/id
Expand All @@ -15,8 +15,10 @@ def edit; end
def update
set_fund
if @fund.update(fund_params)
redirect_to @fund, notice: 'Fund was successfully updated.'
flash[:notice] = t('flash.fund_details_updated')
redirect_to @fund
else
flash[:alert] = t('flash.error_saving_fund_details', error: @fund.errors.full_messages.to_sentence)
render :edit, status: :unprocessable_entity
end
end
Expand Down
2 changes: 2 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,9 @@ en:
demote_own_account_warn: For safety reasons, you are not allowed to change your role from an admin to a not-admin. Ask another admin to demote you.
error_saving_clinic: Errors prevented this clinic from being saved - %{error}
error_saving_clinic_details: Error saving clinic details - %{error}
error_saving_fund_details: Error saving fund details - %{error}
fetch_pledge_error: Errors prevented this pledge from generating. Please check that you've filled out any form inputs, and reach out to the DARIA team if the problem persists.
fund_details_updated: Successfully updated fund details.
locked: Locked
new_patient_error: Errors prevented this patient from being saved - %{error}
new_patient_save: A new patient has been successfully saved
Expand Down
2 changes: 2 additions & 0 deletions config/locales/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,9 @@ es:
demote_own_account_warn: Por razones de seguridad, no se le permite cambiar su función de administrador a no administrador. Pídale a otro administrador que lo degraden.
error_saving_clinic: Algúnos errores evitaron que esta clínica se guardara - %{error}
error_saving_clinic_details: Error al guardar los detalles de la clínica - %{error}
error_saving_fund: Algúnos errores evitaron que este fondo se guardara - %{error}
fetch_pledge_error: Los errores impidieron que se generara este compromiso. Verifique que haya completado todas las entradas del formulario y comuníquese con el equipo de DARIA si el problema persiste.
fund_details_updated: Detalles del fondo fueron actualizados exitosamente.
locked: Bloqueada
new_patient_error: Algúnos errores impidieron guardar a este paciente - %{error}
new_patient_save: Un nuevo paciente ha sido guardado con éxito
Expand Down
86 changes: 74 additions & 12 deletions test/controllers/funds_controller_test.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,85 @@
require "test_helper"

class FundsControllerTest < ActionDispatch::IntegrationTest
setup do
@fund = funds(:one)
before do
@user = create :user, role: :admin
sign_in @user
@fund = create :fund
end

# TODO: may need to use current_tenant
test "should show fund" do
get fund_url(@fund)
assert_response :success
describe 'show' do
it 'should render if admin' do
get fund_url(@fund)
assert_response :success
end

it 'should render json' do
get fund_url(@fund), xhr: true
assert_response :success
end
end

test "should get edit" do
get edit_fund_url(@fund)
assert_response :success
describe 'edit' do
it 'should redirect if not admin' do
User.roles.keys.reject { |role| role == 'admin' }.each do |role|
@user.update role: role
get edit_fund_url(@fund)
assert_redirected_to root_path
end
end

it 'should render' do
@user.update role: :admin
get edit_fund_url(@fund)
assert_response :success
end
end

test "should update fund" do
patch fund_url(@fund), params: { fund: { } }
assert_redirected_to fund_url(@fund)
describe 'update' do
before do
@fund_attrs = attributes_for :fund, phone: phone
@phone = Faker::PhoneNumber.cell_phone
end

it 'should redirect if not admin' do
User.roles.keys.reject { |role| role == 'admin' }.each do |role|
@user.update role: role
patch fund_path(@fund), params: { fund: @fund_attrs }
@fund.reload
refute_equal phone, @fund.phone
assert_redirected_to root_path
end
end

it 'should update the fund record' do
patch fund_path(@fund), params: { fund: @fund_attrs }
@fund.reload
assert_equal phone, @fund.phone
assert_redirected_to fund_url(@fund)
end

it 'should not update the fund record if the payload is bad' do
@fund_attrs[:name] = nil

patch fund_path(@fund), params: { fund: @fund_attrs }
@fund.reload
refute_equal phone, @fund.phone
assert_response :success
end
end

# xtest "should show fund" do
# get fund_url(@fund)
# assert_response :success
# end

# xtest "should get edit" do
# get edit_fund_url(@fund)
# assert_response :success
# end

# xtest "should update fund" do
# patch fund_url(@fund), params: { fund: { site_domain: 'foobar.baz' } }
# assert_redirected_to fund_url(@fund)
# end
end

0 comments on commit 7a7478e

Please sign in to comment.