Sha256: dbbea62216f6a8ecaea3ddb0226b30cbedff56eeb7742cdd71581f1ee6da0981

Contents?: true

Size: 1.32 KB

Versions: 48

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true

require 'rails_helper'

module Spree
  RSpec.describe DisplayMoney do
    let(:test_class) do
      Class.new do
        extend DisplayMoney
        def total; 10.0; end
      end
    end

    describe ".money_methods" do
      before { test_class.money_methods :total }

      context "currency is not defined" do
        it "generates a display_method that builds a Spree::Money without options" do
          expect(test_class.new.display_total).to eq Spree::Money.new(10.0)
        end
      end

      context "currency is defined" do
        before { test_class.class_eval { def currency; "USD"; end } }

        it "generates a display_* method that builds a Spree::Money with currency" do
          expect(test_class.new.display_total).to eq Spree::Money.new(10.0, currency: "USD")
        end
      end

      context "with multiple + options" do
        before do
          test_class.class_eval { def amount; 20.0; end }
          test_class.money_methods :total, amount: { no_cents: true }
        end

        it "generates a display_* method that builds a Spree::Money with the specified options" do
          expect(test_class.new.display_total).to eq Spree::Money.new(10.0)
          expect(test_class.new.display_amount).to eq Spree::Money.new(20.0, no_cents: true)
        end
      end
    end
  end
end

Version data entries

48 entries across 48 versions & 2 rubygems

Version Path
solidus_core-2.10.5 spec/models/spree/concerns/display_money_spec.rb
solidus_core-2.10.3 spec/models/spree/concerns/display_money_spec.rb
solidus_core-2.10.2 spec/models/spree/concerns/display_money_spec.rb
solidus_core-2.9.6 spec/models/spree/concerns/display_money_spec.rb
solidus_core-2.8.6 spec/models/spree/concerns/display_money_spec.rb
solidus_core-2.10.1 spec/models/spree/concerns/display_money_spec.rb
solidus_core-2.9.5 spec/models/spree/concerns/display_money_spec.rb
solidus_core-2.10.0 spec/models/spree/concerns/display_money_spec.rb
solidus_core-2.9.4 spec/models/spree/concerns/display_money_spec.rb
solidus_core-2.6.6 spec/models/spree/concerns/display_money_spec.rb
solidus_core-2.7.4 spec/models/spree/concerns/display_money_spec.rb
solidus_core-2.8.5 spec/models/spree/concerns/display_money_spec.rb
solidus_core-2.9.3 spec/models/spree/concerns/display_money_spec.rb
solidus_core-2.9.2 spec/models/spree/concerns/display_money_spec.rb
solidus_core-2.10.0.beta1 spec/models/spree/concerns/display_money_spec.rb
solidus_core-2.7.3 spec/models/spree/concerns/display_money_spec.rb
solidus_core-2.6.5 spec/models/spree/concerns/display_money_spec.rb
solidus_core-2.9.1 spec/models/spree/concerns/display_money_spec.rb
solidus_core-2.9.0 spec/models/spree/concerns/display_money_spec.rb
solidus_core-2.9.0.rc.1 spec/models/spree/concerns/display_money_spec.rb