Sha256: 937aaa59a113741e8e51cfb8bf7d83734b574a7d0822b37801e5976d317e3c2c

Contents?: true

Size: 1.68 KB

Versions: 2

Compression:

Stored size: 1.68 KB

Contents

# encoding: utf-8
require 'spec_helper'

describe SEPA::Converter do
  include SEPA::Converter::InstanceMethods

  describe :convert_text do
    it 'should convert special chars' do
      expect(convert_text('10€')).to eq('10E')
      expect(convert_text('info@bundesbank.de')).to eq('info(at)bundesbank.de')
      expect(convert_text('abc_def')).to eq('abc-def')
    end

    it 'should not change allowed special character' do
      expect(convert_text('üöäÜÖÄß')).to eq('üöäÜÖÄß')
      expect(convert_text('&*$%')).to eq('&*$%')
    end

    it 'should convert line breaks' do
      expect(convert_text("one\ntwo"))    .to eq('one two')
      expect(convert_text("one\ntwo\n"))  .to eq('one two')
      expect(convert_text("\none\ntwo\n")).to eq('one two')
      expect(convert_text("one\n\ntwo"))  .to eq('one two')
    end

    it 'should convert number' do
      expect(convert_text(1234)).to eq('1234')
    end

    it 'should remove invalid chars' do
      expect(convert_text('"=<>!')).to eq('')
    end

    it 'should not touch valid chars' do
      expect(convert_text("abc-ABC-0123- ':?,-(+.)/")).to eq("abc-ABC-0123- ':?,-(+.)/")
    end

    it 'should not touch nil' do
      expect(convert_text(nil)).to eq(nil)
    end
  end

  describe :convert_decimal do
    it "should convert Integer to BigDecimal" do
      expect(convert_decimal(42)).to eq(BigDecimal('42.00'))
    end

    it "should convert Float to BigDecimal" do
      expect(convert_decimal(42.12)).to eq(BigDecimal('42.12'))
    end

    it 'should round' do
      expect(convert_decimal(1.345)).to eq(BigDecimal('1.35'))
    end

    it 'should not touch nil' do
      expect(convert_decimal(nil)).to eq(nil)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sepa_king-0.9.0 spec/converter_spec.rb
sepa_king-0.8.0 spec/converter_spec.rb