From 9116e8c04a14e06ed16c18b0d2e2a67592b1e187 Mon Sep 17 00:00:00 2001 From: Peng DU Date: Tue, 5 Jul 2016 12:15:26 +0200 Subject: [PATCH] wallet transaction type must be credit/debit --- app/models/wallet_transaction.rb | 2 ++ test/models/wallet_transaction_test.rb | 12 +++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app/models/wallet_transaction.rb b/app/models/wallet_transaction.rb index 040c4d4d3..df5868839 100644 --- a/app/models/wallet_transaction.rb +++ b/app/models/wallet_transaction.rb @@ -3,4 +3,6 @@ class WalletTransaction < ActiveRecord::Base belongs_to :wallet belongs_to :reservation belongs_to :transactable, polymorphic: true + + validates_inclusion_of :transaction_type, in: %w( credit debit ) end diff --git a/test/models/wallet_transaction_test.rb b/test/models/wallet_transaction_test.rb index 01796026f..3763f85bd 100644 --- a/test/models/wallet_transaction_test.rb +++ b/test/models/wallet_transaction_test.rb @@ -1,7 +1,13 @@ require 'test_helper' class WalletTransactionTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end + test 'transaction type must be credit or debit' do + transaction = WalletTransaction.new + transaction.transaction_type = 'credit' + assert transaction.valid? + transaction.transaction_type = 'debit' + assert transaction.valid? + transaction.transaction_type = 'other' + assert_not transaction.valid? + end end