Skip to content

Commit

Permalink
Per review , Simplify creation of Voucher
Browse files Browse the repository at this point in the history
We now check against known type to instanciate the correct voucher
instead of using a case
  • Loading branch information
rioug committed Jul 18, 2023
1 parent f399686 commit 7e2b104
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions app/controllers/admin/vouchers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ def new
end

def create
case params[:voucher][:voucher_type]
when "Vouchers::FlatRate"
@voucher =
Vouchers::FlatRate.create(permitted_resource_params.merge(enterprise: @enterprise))
when "Vouchers::PercentageRate"
@voucher =
Vouchers::PercentageRate.create(permitted_resource_params.merge(enterprise: @enterprise))
voucher_type = params[:voucher][:voucher_type]
if Voucher::TYPES.include?(voucher_type)
@voucher = voucher_type.constantize.create(

Check failure

Code scanning / Brakeman

Unsafe reflection method constantize called on parameter value. Error

Unsafe reflection method constantize called on parameter value.
permitted_resource_params.merge(enterprise: @enterprise)
)
else
@voucher.errors.add(:type)
return render_error
Expand Down

0 comments on commit 7e2b104

Please sign in to comment.