From aa58d4f3751949a4a4c424aacb10c0c043daf599 Mon Sep 17 00:00:00 2001 From: Lodewiges Date: Tue, 10 Feb 2026 17:02:38 +0100 Subject: [PATCH 1/5] Intial commit --- app/models/credit_mutation.rb | 2 +- app/models/payment.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/models/credit_mutation.rb b/app/models/credit_mutation.rb index e15fb9914..cf3191070 100644 --- a/app/models/credit_mutation.rb +++ b/app/models/credit_mutation.rb @@ -4,7 +4,7 @@ class CreditMutation < ApplicationRecord belongs_to :created_by, class_name: 'User' validates :description, presence: true - validates :amount, presence: true, numericality: { less_than_or_equal_to: 1000 } + validates :amount, presence: true, numericality: { less_than_or_equal_to: 5000 } validate :activity_not_locked diff --git a/app/models/payment.rb b/app/models/payment.rb index 76d897d9b..b0c035d11 100644 --- a/app/models/payment.rb +++ b/app/models/payment.rb @@ -17,6 +17,7 @@ class << self validate :user_xor_invoice validate :user_amount + validate :invoice_amount scope :not_completed, -> { where.not(status: COMPLETE_STATUSES) } @@ -78,6 +79,15 @@ def user_amount return unless user min_amount = Rails.application.config.x.min_payment_amount + max_amount = 1000 + errors.add(:amount, "must be bigger than or equal to €#{format('%.2f', min_amount)}") unless amount && (amount >= min_amount) + errors.add(:amount, "must be less than or equal to €#{format('%.2f', max_amount)}") unless amount && (amount <= max_amount) + end + + def invoice_amount + return unless invoice + + min_amount = 1 errors.add(:amount, "must be bigger than or equal to €#{format('%.2f', min_amount)}") unless amount && (amount >= min_amount) end end From 733eba68b6802c43fe0ec13d2ccac087ceaf23c8 Mon Sep 17 00:00:00 2001 From: Lodewiges Date: Tue, 10 Feb 2026 17:14:55 +0100 Subject: [PATCH 2/5] implement suggestions and fix tests --- app/models/payment.rb | 8 +++--- config/application.rb | 2 ++ spec/models/credit_mutation_spec.rb | 16 +++++++++++- spec/models/payment_spec.rb | 40 +++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+), 5 deletions(-) diff --git a/app/models/payment.rb b/app/models/payment.rb index b0c035d11..ed4c523f7 100644 --- a/app/models/payment.rb +++ b/app/models/payment.rb @@ -79,15 +79,15 @@ def user_amount return unless user min_amount = Rails.application.config.x.min_payment_amount - max_amount = 1000 - errors.add(:amount, "must be bigger than or equal to €#{format('%.2f', min_amount)}") unless amount && (amount >= min_amount) + max_amount = Rails.application.config.x.max_payment_amount + errors.add(:amount, "must be greater than or equal to €#{format('%.2f', min_amount)}") unless amount && (amount >= min_amount) errors.add(:amount, "must be less than or equal to €#{format('%.2f', max_amount)}") unless amount && (amount <= max_amount) end def invoice_amount return unless invoice - min_amount = 1 - errors.add(:amount, "must be bigger than or equal to €#{format('%.2f', min_amount)}") unless amount && (amount >= min_amount) + min_amount = Rails.application.config.x.min_invoice_amount + errors.add(:amount, "must be greater than or equal to €#{format('%.2f', min_amount)}") unless amount && (amount >= min_amount) end end diff --git a/config/application.rb b/config/application.rb index 9883b0502..22202c004 100644 --- a/config/application.rb +++ b/config/application.rb @@ -83,6 +83,8 @@ class Application < Rails::Application config.x.deposit_button_enabled = ENV.fetch('DEPOSIT_BUTTON_ENABLED', 'true') == 'true' config.x.min_payment_amount = [ENV.fetch('MIN_PAYMENT_AMOUNT', '21.8').to_f, 0.01].max + config.x.max_payment_amount = ENV.fetch('MAX_PAYMENT_AMOUNT', '1000') + config.x.min_invoice_amount = [ENV.fetch('MIN_INVOICE_AMOUNT', '1').to_f, 0.01].max config.x.codes = { beer: ENV.fetch('CODE_BEER', nil), diff --git a/spec/models/credit_mutation_spec.rb b/spec/models/credit_mutation_spec.rb index 6b3327cb1..f16b4b2f6 100644 --- a/spec/models/credit_mutation_spec.rb +++ b/spec/models/credit_mutation_spec.rb @@ -31,11 +31,25 @@ end context 'when with too high amount' do - subject(:mutation) { build_stubbed(:credit_mutation, amount: 1001) } + subject(:mutation) { build_stubbed(:credit_mutation, amount: 5001) } it { expect(mutation).not_to be_valid } end + context 'when with boundary amounts' do + context 'when at maximum amount' do + subject(:mutation) { build_stubbed(:credit_mutation, amount: 5000) } + + it { expect(mutation).to be_valid } + end + + context 'when just over maximum amount' do + subject(:mutation) { build_stubbed(:credit_mutation, amount: 5000.01) } + + it { expect(mutation).not_to be_valid } + end + end + context 'when with a locked activity' do let(:activity) { build(:activity, :locked) } let(:mutation) { build(:credit_mutation, activity:) } diff --git a/spec/models/payment_spec.rb b/spec/models/payment_spec.rb index 44b644957..5d07b4334 100644 --- a/spec/models/payment_spec.rb +++ b/spec/models/payment_spec.rb @@ -38,6 +38,46 @@ end end + context 'when with too high amount' do + context 'when with user' do + subject(:payment) { build_stubbed(:payment, amount: 1001) } + + it { expect(payment).not_to be_valid } + end + + context 'when with invoice and high amount' do + subject(:payment) { build_stubbed(:payment, :invoice, amount: 1001) } + + it { expect(payment).to be_valid } + end + end + + context 'when with boundary amounts' do + context 'when with user at max amount' do + subject(:payment) { build_stubbed(:payment, amount: 1000) } + + it { expect(payment).to be_valid } + end + + context 'when with user just over max amount' do + subject(:payment) { build_stubbed(:payment, amount: 1000.01) } + + it { expect(payment).not_to be_valid } + end + + context 'when with invoice below minimum' do + subject(:payment) { build_stubbed(:payment, :invoice, amount: 0.99) } + + it { expect(payment).not_to be_valid } + end + + context 'when with invoice at minimum' do + subject(:payment) { build_stubbed(:payment, :invoice, amount: 1) } + + it { expect(payment).to be_valid } + end + end + context 'when without a status' do subject(:payment) { build_stubbed(:payment, status: nil) } From d864712e763a96c9fa050ab6c948b3977866b015 Mon Sep 17 00:00:00 2001 From: lodewiges <131907615+lodewiges@users.noreply.github.com> Date: Tue, 10 Feb 2026 22:30:40 +0100 Subject: [PATCH 3/5] Convert max_payment_amount to float --- config/application.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/application.rb b/config/application.rb index 22202c004..7da1a3e9a 100644 --- a/config/application.rb +++ b/config/application.rb @@ -83,7 +83,7 @@ class Application < Rails::Application config.x.deposit_button_enabled = ENV.fetch('DEPOSIT_BUTTON_ENABLED', 'true') == 'true' config.x.min_payment_amount = [ENV.fetch('MIN_PAYMENT_AMOUNT', '21.8').to_f, 0.01].max - config.x.max_payment_amount = ENV.fetch('MAX_PAYMENT_AMOUNT', '1000') + config.x.max_payment_amount = ENV.fetch('MAX_PAYMENT_AMOUNT', '1000').to_f config.x.min_invoice_amount = [ENV.fetch('MIN_INVOICE_AMOUNT', '1').to_f, 0.01].max config.x.codes = { From d685512429119b15ae9dfdde2afe51fa3d01ba8f Mon Sep 17 00:00:00 2001 From: Lodewiges Date: Tue, 10 Feb 2026 22:47:34 +0100 Subject: [PATCH 4/5] fix lint --- app/models/payment.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/payment.rb b/app/models/payment.rb index ed4c523f7..a77a507eb 100644 --- a/app/models/payment.rb +++ b/app/models/payment.rb @@ -75,7 +75,7 @@ def user_xor_invoice errors.add(:payment, 'must belong to a user xor invoice') unless user.present? ^ invoice.present? end - def user_amount + def user_amount # rubocop:disable Metrics/AbcSize return unless user min_amount = Rails.application.config.x.min_payment_amount From 040472b2b38812845d1403ed429a2ea9e12be0da Mon Sep 17 00:00:00 2001 From: lodewiges <131907615+lodewiges@users.noreply.github.com> Date: Tue, 10 Feb 2026 23:02:03 +0100 Subject: [PATCH 5/5] Remove test for excessive credit mutation amount Removed test case for too high amount in credit mutation. --- spec/models/credit_mutation_spec.rb | 6 ------ 1 file changed, 6 deletions(-) diff --git a/spec/models/credit_mutation_spec.rb b/spec/models/credit_mutation_spec.rb index f16b4b2f6..31749f4a3 100644 --- a/spec/models/credit_mutation_spec.rb +++ b/spec/models/credit_mutation_spec.rb @@ -30,12 +30,6 @@ it { expect(mutation).not_to be_valid } end - context 'when with too high amount' do - subject(:mutation) { build_stubbed(:credit_mutation, amount: 5001) } - - it { expect(mutation).not_to be_valid } - end - context 'when with boundary amounts' do context 'when at maximum amount' do subject(:mutation) { build_stubbed(:credit_mutation, amount: 5000) }