Add account after registrar create

This commit is contained in:
Martin Lensment 2015-05-25 13:32:27 +03:00
parent c1211a0ac5
commit f7a4dee1b6
5 changed files with 16 additions and 4 deletions

View file

@ -53,6 +53,11 @@ class Registrar < ActiveRecord::Base
whois_records.map(&:save) # slow currently
end
after_create :create_cash_account
def create_cash_account
accounts.create(account_type: Account::CASH, currency: 'EUR')
end
class << self
def search_by_query(query)
res = search(name_or_reg_no_cont: query).result

View file

@ -63,6 +63,10 @@ if @api_user2.blank?
)
end
Registrar.all.each do |x|
x.accounts.where(account_type: Account::CASH, currency: 'EUR').first_or_create!
end
admin1 = {
username: 'user1',
password: 'testtest',

View file

@ -9,7 +9,6 @@ Fabricator(:registrar) do
country_code 'EE'
code { sequence(:code) { |i| "REGISTRAR#{i}" } }
reference_no { sequence(:reference_no) { |i| "RF#{i}" } }
accounts(count: 1)
white_ips { [Fabricate(:white_ip)] }
end

View file

@ -62,6 +62,10 @@ describe Registrar do
@registrar.errors.full_messages.should match_array([])
end
it 'should have a cash account' do
@registrar.cash_account.should_not be_nil
end
it 'should validates uniqueness of code' do
registrar = Fabricate.build(:registrar, code: @registrar.code)
registrar.valid?

View file

@ -16,9 +16,9 @@ describe Repp::AccountV1 do
context 'with valid registrar' do
before :all do
@registrar1 = Fabricate(:registrar1, accounts:
[Fabricate(:account, { balance: '324.45', account_activities: [] })]
)
@registrar1 = Fabricate(:registrar1)
@registrar1.accounts = [Fabricate(:account, { balance: '324.45', account_activities: [] })]
@registrar1.save
@api_user = Fabricate(:gitlab_api_user, registrar: @registrar1)
end