Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Payment < ApplicationRecord
- before_create :set_slug
- validates :value, presence: true
- validates_with ValueValidator
- belongs_to :local_committee
- enum program: {}
- enum status: {}
- enum payment_method: {}
- def program_fee
- end
- def to_param
- end
- private
- def set_slug
- end
- end
- ##################################
- class ValueValidator < ActiveModel::Validator
- def validate(record)
- if record.value < record.program_fee
- record.errors.add(:value, 'must be bigger than program fee')
- end
- end
- end
- ##############################################
- describe 'minimum value' do
- let(:payment) { FactoryGirl.build(:payment, value: 500000) }
- it 'is valid when value is higher than program_fee' do
- expect(payment.valid?).to eq(true)
- end
- it 'is invalid when value is lower than program_free' do
- payment.value = payment.program_fee - 1
- expect(payment.valid?).to eq(false)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement