This commit is contained in:
Martin Lensment 2015-04-20 09:25:04 +03:00
parent f1962b2f64
commit 3e879eacc7
2 changed files with 53 additions and 0 deletions

View file

@ -3,6 +3,8 @@ class Account < ActiveRecord::Base
belongs_to :registrar
has_many :account_activities
validates :account_type, presence: true
CASH = 'cash'
def activities

View file

@ -0,0 +1,51 @@
require 'rails_helper'
describe Account do
it { should belong_to(:registrar) }
it { should have_many(:account_activities) }
context 'with invalid attribute' do
before :all do
@account = Account.new
end
it 'should not be valid' do
@account.valid?
@account.errors.full_messages.should match_array(["Account type is missing"])
end
it 'should not have any versions' do
@account.versions.should == []
end
end
context 'with valid attributes' do
before :all do
@account = Fabricate(:account)
end
it 'should be valid' do
@account.valid?
@account.errors.full_messages.should match_array([])
s = 0.0
@account.activities.map { |x| s += x.sum }
@account.balance.should == s
end
it 'should be valid twice' do
@account = Fabricate(:account)
@account.valid?
@account.errors.full_messages.should match_array([])
end
it 'should have one version' do
with_versioning do
@account.versions.should == []
@account.account_type = 'new_type'
@account.save
@account.errors.full_messages.should match_array([])
@account.versions.size.should == 1
end
end
end
end