Advertisement
Guest User

Untitled

a guest
Feb 20th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.98 KB | None | 0 0
  1. class Payment < ApplicationRecord
  2.   before_create :set_slug
  3.  
  4.   validates :value, presence: true
  5.  
  6.   validates_with ValueValidator
  7.  
  8.   belongs_to :local_committee
  9.  
  10.   enum program: {}
  11.   enum status: {}
  12.  
  13.   enum payment_method: {}
  14.  
  15.   def program_fee
  16.   end
  17.  
  18.     def to_param
  19.     end
  20.  
  21.   private
  22.  
  23.   def set_slug
  24.   end
  25. end
  26.  
  27. ##################################
  28. class ValueValidator < ActiveModel::Validator
  29.   def validate(record)
  30.     if record.value < record.program_fee
  31.       record.errors.add(:value, 'must be bigger than program fee')
  32.     end
  33.   end
  34. end
  35. ##############################################
  36. describe 'minimum value' do
  37.     let(:payment) { FactoryGirl.build(:payment, value: 500000) }
  38.     it 'is valid when value is higher than program_fee' do
  39.       expect(payment.valid?).to eq(true)
  40.     end
  41.  
  42.     it 'is invalid when value is lower than program_free' do
  43.       payment.value = payment.program_fee - 1
  44.  
  45.       expect(payment.valid?).to eq(false)
  46.     end
  47.   end
  48. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement