Move localize_number from decorator to model

This commit is contained in:
Pau Perez
2020-06-26 18:17:07 +02:00
parent 48910aeb77
commit 861726200c
4 changed files with 7 additions and 8 deletions

View File

@@ -1,6 +1,9 @@
module Spree
class Payment < ActiveRecord::Base
include Spree::Payment::Processing
extend Spree::LocalizedNumber
localize_number :amount
IDENTIFIER_CHARS = (('A'..'Z').to_a + ('0'..'9').to_a - %w(0 1 I O)).freeze

View File

@@ -2,14 +2,10 @@ require 'spree/localized_number'
module Spree
Payment.class_eval do
extend Spree::LocalizedNumber
delegate :line_items, to: :order
has_one :adjustment, as: :source, dependent: :destroy
localize_number :amount
# We bypass this after_rollback callback that is setup in Spree::Payment
# The issues the callback fixes are not experienced in OFN:
# if a payment fails on checkout the state "failed" is persisted correctly

View File

@@ -40,6 +40,10 @@ describe Spree::Payment do
allow(payment).to receive(:record_response)
end
context "extends LocalizedNumber" do
it_behaves_like "a model using the LocalizedNumber module", [:amount]
end
context 'validations' do
it "returns useful error messages when source is invalid" do
payment.source = Spree::CreditCard.new

View File

@@ -108,9 +108,5 @@ module Spree
end
end
end
context "extends LocalizedNumber" do
it_behaves_like "a model using the LocalizedNumber module", [:amount]
end
end
end