Sha256: 0d719edf2ca82d1e4010a6000e13074d9882d90c7019117f8954e6a2a0a68ead

Contents?: true

Size: 1.16 KB

Versions: 48

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

require 'spec_helper'
require 'spree/localized_number'

RSpec.describe Spree::LocalizedNumber do
  context ".parse" do
    before do
      I18n.enforce_available_locales = false
      I18n.locale = I18n.default_locale
      I18n.backend.store_translations(:de, { number: { currency: { format: { delimiter: '.', separator: ',' } } } })
    end

    after do
      I18n.locale = I18n.default_locale
      I18n.enforce_available_locales = true
    end

    context "with an empty string" do
      it "parses to 0" do
        expect(subject.class.parse("")).to eq 0.0
      end
    end

    context "with decimal point" do
      it "captures the proper amount for a formatted price" do
        expect(subject.class.parse('1,599.99')).to eql 1599.99
      end
    end

    context "with decimal comma" do
      it "captures the proper amount for a formatted price" do
        I18n.locale = :de
        expect(subject.class.parse('1.599,99')).to eql 1599.99
      end
    end

    context "with a numeric price" do
      it "uses the price as is" do
        I18n.locale = :de
        expect(subject.class.parse(1599.99)).to eql 1599.99
      end
    end
  end
end

Version data entries

48 entries across 48 versions & 2 rubygems

Version Path
solidus_core-2.8.4 spec/lib/spree/localized_number_spec.rb
solidus_core-2.8.3 spec/lib/spree/localized_number_spec.rb
solidus_core-2.7.2 spec/lib/spree/localized_number_spec.rb
solidus_core-2.6.4 spec/lib/spree/localized_number_spec.rb
solidus_core-2.8.2 spec/lib/spree/localized_number_spec.rb
solidus_core-2.8.1 spec/lib/spree/localized_number_spec.rb
solidus_core-2.6.3 spec/lib/spree/localized_number_spec.rb
solidus_core-2.8.0 spec/lib/spree/localized_number_spec.rb
solidus_core-2.7.1 spec/lib/spree/localized_number_spec.rb
solidus_core-2.6.2 spec/lib/spree/localized_number_spec.rb
solidus_core_devise_token_auth-2.8.0.alpha.14 spec/lib/spree/localized_number_spec.rb
solidus_core_devise_token_auth-2.8.0.alpha.13 spec/lib/spree/localized_number_spec.rb
solidus_core_devise_token_auth-2.8.0.alpha.12 spec/lib/spree/localized_number_spec.rb
solidus_core_devise_token_auth-2.8.0.alpha.11 spec/lib/spree/localized_number_spec.rb
solidus_core_devise_token_auth-2.8.0.alpha.10 spec/lib/spree/localized_number_spec.rb
solidus_core_devise_token_auth-2.8.0.alpha.9 spec/lib/spree/localized_number_spec.rb
solidus_core_devise_token_auth-2.8.0.alpha.8 spec/lib/spree/localized_number_spec.rb
solidus_core_devise_token_auth-2.8.0.alpha.7 spec/lib/spree/localized_number_spec.rb
solidus_core_devise_token_auth-2.8.0.alpha.6 spec/lib/spree/localized_number_spec.rb
solidus_core_devise_token_auth-2.8.0.alpha.5 spec/lib/spree/localized_number_spec.rb