mirror of
https://github.com/internetee/registry.git
synced 2025-06-05 04:07:33 +02:00
57 lines
1.5 KiB
Ruby
57 lines
1.5 KiB
Ruby
require 'test_helper'
|
|
|
|
class DepositTest < ActiveSupport::TestCase
|
|
def setup
|
|
super
|
|
|
|
@deposit = Deposit.new(registrar: registrars(:bestnames))
|
|
@original_minimum_deposit = Setting.minimum_deposit
|
|
Setting.minimum_deposit = 1.00
|
|
end
|
|
|
|
teardown do
|
|
Setting.minimum_deposit = @original_minimum_deposit
|
|
end
|
|
|
|
def test_validate_amount_cannot_be_lower_than_0_01
|
|
Setting.minimum_deposit = 0.0
|
|
@deposit.amount = -10
|
|
refute(@deposit.valid?)
|
|
assert(@deposit.errors.full_messages.include?("Amount is too small. Minimum deposit is 0.01 EUR"))
|
|
end
|
|
|
|
def test_validate_amount_cannot_be_lower_than_minimum_deposit
|
|
@deposit.amount = 0.10
|
|
refute(@deposit.valid?)
|
|
|
|
assert(@deposit.errors.full_messages.include?("Amount is too small. Minimum deposit is 1.0 EUR"))
|
|
end
|
|
|
|
def test_registrar_must_be_set
|
|
deposit = Deposit.new(amount: 120)
|
|
refute(deposit.valid?)
|
|
|
|
assert(deposit.errors.full_messages.include?("Registrar is missing"))
|
|
end
|
|
|
|
def test_amount_is_converted_from_string
|
|
@deposit.amount = "12.00"
|
|
assert_equal(BigDecimal("12.00"), @deposit.amount)
|
|
|
|
@deposit.amount = "12,11"
|
|
assert_equal(BigDecimal("12.11"), @deposit.amount)
|
|
end
|
|
|
|
def test_amount_is_converted_from_float
|
|
@deposit.amount = 12.0044
|
|
assert_equal(BigDecimal("12.0044"), @deposit.amount)
|
|
|
|
@deposit.amount = 12.0144
|
|
assert_equal(BigDecimal("12.0144"), @deposit.amount)
|
|
end
|
|
|
|
def test_amount_is_converted_from_nil
|
|
@deposit.amount = nil
|
|
assert_equal(BigDecimal("0.00"), @deposit.amount)
|
|
end
|
|
end
|