Sha256: 7468992f87a421c48e53681b0123b1689d7efb0686273449c4bb266b0f69c7fb

Contents?: true

Size: 1.21 KB

Versions: 1

Compression:

Stored size: 1.21 KB

Contents

require "rails_helper"

describe Dorsale::ActiveRecordCommaTypeCast, type: :model do
  let(:line) { create(:billing_machine_invoice_line) }

  it "should accept , as decimal separator" do
    line.update!(quantity: "12,34")
    expect(line.reload.quantity).to eq 12.34
  end

  it "should accept . as decimal separator" do
    line.update!(quantity: "12.34")
    expect(line.reload.quantity).to eq 12.34
  end

  it "should accept space as group separator" do
    line.update!(quantity: "123 456,78")
    expect(line.reload.quantity).to eq 123456.78

    line.update!(quantity: "123 456.78")
    expect(line.reload.quantity).to eq 123456.78
  end

  it "should accept nbsp as group separator" do
    line.update!(quantity: "123 456,78")
    expect(line.reload.quantity).to eq 123456.78

    line.update!(quantity: "123 456.78")
    expect(line.reload.quantity).to eq 123456.78
  end

  it "should accept negative numbers" do
    line.update!(quantity: "-12,34")
    expect(line.reload.quantity).to eq -12.34

    line.update!(quantity: "-12.34")
    expect(line.reload.quantity).to eq -12.34
  end

  it "should accept trailing chars" do
    line.update!(quantity: "abc 12.34 def")
    expect(line.reload.quantity).to eq 12.34
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dorsale-3.4.0 spec/libs/dorsale/active_record_comma_type_cast_spec.rb