Initial commit
This commit is contained in:
108
spec/models/operations/account_spec.rb
Normal file
108
spec/models/operations/account_spec.rb
Normal file
@@ -0,0 +1,108 @@
|
||||
# encoding: UTF-8
|
||||
# frozen_string_literal: true
|
||||
|
||||
describe Operations::Account do
|
||||
let(:account) { Operations::Account.find_by(code: '101') }
|
||||
|
||||
describe '#code' do
|
||||
it 'validates presence' do
|
||||
account.code = nil
|
||||
account.valid?
|
||||
expect(account.errors[:code]).to include("can't be blank")
|
||||
end
|
||||
|
||||
it 'validates uniqueness' do
|
||||
account.code = '102' # an already existing code
|
||||
account.valid?
|
||||
expect(account.errors[:code]).to include("has already been taken")
|
||||
|
||||
account.code = '901' # a new code
|
||||
account.valid?
|
||||
expect(account.errors[:code]).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
describe '#type' do
|
||||
it 'validates presence' do
|
||||
account.type = nil
|
||||
account.valid?
|
||||
expect(account.errors[:type]).to include("can't be blank")
|
||||
end
|
||||
|
||||
it 'validates inclusion' do
|
||||
account.type = 'an-nonexistent-type'
|
||||
account.valid?
|
||||
expect(account.errors[:type]).to include("is not included in the list")
|
||||
|
||||
account.type = Operations::Account::TYPES.first # an existent type
|
||||
account.valid?
|
||||
expect(account.errors[:type]).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
describe '#kind' do
|
||||
it 'validates presence' do
|
||||
account.kind = nil
|
||||
account.valid?
|
||||
expect(account.errors[:kind]).to include("can't be blank")
|
||||
end
|
||||
|
||||
it 'validates uniqueness scoped to type and currency_type' do
|
||||
account = Operations::Account.new
|
||||
|
||||
# an already existing (kind, type, currency_type)
|
||||
account.kind = :main
|
||||
account.type = :asset
|
||||
account.currency_type = :fiat
|
||||
account.valid?
|
||||
expect(account.errors[:kind]).to include("has already been taken")
|
||||
|
||||
# a different type
|
||||
account.type = :different_type
|
||||
account.valid?
|
||||
expect(account.errors[:kind]).to be_empty
|
||||
|
||||
# restore existing type, but different currency_type
|
||||
account.type = :asset
|
||||
account.currency_type = :different_currency_type
|
||||
account.valid?
|
||||
expect(account.errors[:kind]).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
describe '#currency_type' do
|
||||
it 'validates presence' do
|
||||
account.currency_type = nil
|
||||
account.valid?
|
||||
expect(account.errors[:currency_type]).to include("can't be blank")
|
||||
end
|
||||
|
||||
it 'validates inclusion' do
|
||||
account.currency_type = 'an-nonexistent-currency-type'
|
||||
account.valid?
|
||||
expect(account.errors[:currency_type]).to include("is not included in the list")
|
||||
|
||||
account.currency_type = Currency.types.first # an existent currency_type
|
||||
account.valid?
|
||||
expect(account.errors[:currency_type]).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
describe '#scope' do
|
||||
it 'validates presence' do
|
||||
account.scope = nil
|
||||
account.valid?
|
||||
expect(account.errors[:scope]).to include("can't be blank")
|
||||
end
|
||||
|
||||
it 'validates inclusion' do
|
||||
account.scope = 'an-nonexistent-scope'
|
||||
account.valid?
|
||||
expect(account.errors[:scope]).to include("is not included in the list")
|
||||
|
||||
account.scope = Operations::Account::SCOPES.first # an existent scope
|
||||
account.valid?
|
||||
expect(account.errors[:scope]).to be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
31
spec/models/operations/liability_spec.rb
Normal file
31
spec/models/operations/liability_spec.rb
Normal file
@@ -0,0 +1,31 @@
|
||||
# encoding: UTF-8
|
||||
# frozen_string_literal: true
|
||||
|
||||
describe Operations::Liability do
|
||||
context :after_commit do
|
||||
let(:member) { create(:member, :level_3, :barong) }
|
||||
|
||||
let(:deposit) { create(:deposit_usd, member: member, amount: 0.1) }
|
||||
|
||||
let(:expected_message) do
|
||||
{ subject: :operation,
|
||||
payload: {
|
||||
code: 201,
|
||||
currency: 'usd',
|
||||
member_id: member.id,
|
||||
reference_id: deposit.id,
|
||||
reference_type: 'deposit',
|
||||
debit: '0.0'.to_d,
|
||||
credit: '0.1'.to_d
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
before { AMQP::Queue.expects(:enqueue).with(:events_processor, expected_message) }
|
||||
|
||||
it 'publishes message to rabbitmq' do
|
||||
# Accept deposit for creation of liability.
|
||||
expect(deposit.accept!).to be_truthy
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user