mirror of
https://github.com/internetee/registry.git
synced 2025-08-04 08:52:04 +02:00
Tests
This commit is contained in:
parent
f1962b2f64
commit
3e879eacc7
2 changed files with 53 additions and 0 deletions
|
@ -3,6 +3,8 @@ class Account < ActiveRecord::Base
|
|||
belongs_to :registrar
|
||||
has_many :account_activities
|
||||
|
||||
validates :account_type, presence: true
|
||||
|
||||
CASH = 'cash'
|
||||
|
||||
def activities
|
||||
|
|
51
spec/models/account_spec.rb
Normal file
51
spec/models/account_spec.rb
Normal 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
|
Loading…
Add table
Add a link
Reference in a new issue