Sha256: 0758b5bffd3299c0f3d2bdf74db173b3ba22f59e228ccac4a414473a18774f9d

Contents?: true

Size: 1.1 KB

Versions: 1

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

require 'rails_helper'

RSpec.describe User, 'filters:money' do
  before do
    described_class.normalizy_rules = {}
  end

  specify do
    described_class.normalizy :amount_text, with: :money

    expect(described_class.create(amount_text: '$ 42.00').amount_text).to eq '42.00'
    expect(described_class.create(amount_text: '$ 42.10').amount_text).to eq '42.10'
  end

  specify do
    described_class.normalizy :amount_cents, with: { money: { type: :cents } }

    expect(described_class.create(amount_cents: '$ 42.33').amount_cents).to be 4233
  end

  specify do
    described_class.normalizy :amount_cents, with: { money: { cast: :to_i } }

    expect(described_class.create(amount_cents: '$ 42.00').amount_cents).to be 42
  end

  specify do
    described_class.normalizy :amount, with: { money: { cast: :to_d } }

    expect(described_class.create(amount: '$ 1.23').amount).to eq 1.23.to_d
  end

  specify do
    described_class.normalizy :amount, with: { money: { cast: :to_f, type: :cents } }

    expect(described_class.create(amount: '$ 42.00').amount).to eq 4200.0.to_f
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
normalizy-0.2.0 spec/normalizy/extensions/filters/money_spec.rb