mirror of
https://github.com/internetee/registry.git
synced 2025-05-16 17:37:17 +02:00
51 lines
1.2 KiB
Ruby
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
|