1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-19 08:52:25 +01:00

(quality) disable Rails/RedundantPresenceValidationOnBelongsTo

This setting was disabled in config/application.rb:
`config.active_record.belongs_to_required_by_default = false`,
so we must configure the linter accordingly.

Also: linting some little bit of code
This commit is contained in:
Sylvain 2022-10-11 11:43:32 +02:00
parent 3e6763f14a
commit 6df9724527
4 changed files with 7 additions and 6 deletions

View File

@ -36,3 +36,5 @@ Style/FormatString:
EnforcedStyle: sprintf EnforcedStyle: sprintf
Style/FormatStringToken: Style/FormatStringToken:
EnforcedStyle: template EnforcedStyle: template
Rails/RedundantPresenceValidationOnBelongsTo:
Enabled: false

View File

@ -18,7 +18,7 @@ class API::WalletController < API::ApiController
end end
def credit def credit
return head 422 unless Setting.get('wallet_module') return head :unprocessable_entity unless Setting.get('wallet_module')
@wallet = Wallet.find(credit_params[:id]) @wallet = Wallet.find(credit_params[:id])
authorize @wallet authorize @wallet
@ -28,7 +28,7 @@ class API::WalletController < API::ApiController
service.create_avoir(transaction, credit_params[:avoir_date], credit_params[:avoir_description]) if credit_params[:avoir] service.create_avoir(transaction, credit_params[:avoir_date], credit_params[:avoir_description]) if credit_params[:avoir]
render :show render :show
else else
head 422 head :unprocessable_entity
end end
end end

View File

@ -11,6 +11,8 @@ class Wallet < ApplicationRecord
validates :invoicing_profile, presence: true validates :invoicing_profile, presence: true
delegate :user, to: :invoicing_profile
def credit(amount) def credit(amount)
if amount.is_a?(Numeric) && amount >= 0 if amount.is_a?(Numeric) && amount >= 0
self.amount += amount self.amount += amount
@ -26,8 +28,4 @@ class Wallet < ApplicationRecord
end end
false false
end end
def user
invoicing_profile.user
end
end end

View File

@ -14,6 +14,7 @@ class WalletTransaction < ApplicationRecord
has_one :invoice_item, as: :object, dependent: :destroy has_one :invoice_item, as: :object, dependent: :destroy
validates :transaction_type, inclusion: { in: %w[credit debit] } validates :transaction_type, inclusion: { in: %w[credit debit] }
validates :invoicing_profile, :wallet, presence: true
delegate :user, to: :invoicing_profile delegate :user, to: :invoicing_profile