internetee-registry/spec/models/account_spec.rb
Martin Lensment 3e879eacc7 Tests
2015-04-20 09:25:04 +03:00

51 lines
1.2 KiB
Ruby

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