Rename #create_with_type to #new_with_type

This commit is contained in:
Karl Erik Õunapuu 2020-02-05 16:28:01 +02:00
parent fe8d1d1f0b
commit 5d8e78f3c6
4 changed files with 16 additions and 14 deletions

View file

@ -12,13 +12,15 @@ class Registrar
invoice = Invoice.find(params[:invoice_id]) invoice = Invoice.find(params[:invoice_id])
channel = params[:bank] channel = params[:bank]
@payment_order = PaymentOrder.create_with_type(type: channel, invoice: invoice) @payment_order = PaymentOrder.new_with_type(type: channel, invoice: invoice)
@payment_order.save && @payment_order.reload @payment_order.save
@payment_order.reload
@payment_order.return_url = registrar_return_payment_with_url(@payment_order) @payment_order.return_url = registrar_return_payment_with_url(@payment_order)
@payment_order.response_url = registrar_response_payment_with_url(@payment_order) @payment_order.response_url = registrar_response_payment_with_url(@payment_order)
@payment_order.save && @payment_order.reload @payment_order.save
@payment_order.reload
end end
def back def back

View file

@ -53,7 +53,7 @@ class BankTransaction < ApplicationRecord
return return
end end
payment_order = PaymentOrder.create_with_type(type: channel, invoice: invoice) payment_order = PaymentOrder.new_with_type(type: channel, invoice: invoice)
payment_order.save! payment_order.save!
if create_activity(registrar, invoice) if create_activity(registrar, invoice)

View file

@ -32,7 +32,7 @@ class PaymentOrder < ApplicationRecord
supported supported
end end
def self.create_with_type(type:, invoice:) def self.new_with_type(type:, invoice:)
channel = ('PaymentOrders::' + type.camelize).constantize channel = ('PaymentOrders::' + type.camelize).constantize
PaymentOrder.new(type: channel, invoice: invoice) PaymentOrder.new(type: channel, invoice: invoice)

View file

@ -44,34 +44,34 @@ class PaymentOrdersTest < ActiveSupport::TestCase
end end
def test_correct_channel_is_assigned def test_correct_channel_is_assigned
everypay_channel = PaymentOrder.create_with_type(type: 'every_pay', invoice: @invoice) everypay_channel = PaymentOrder.new_with_type(type: 'every_pay', invoice: @invoice)
assert_equal everypay_channel.channel, 'EveryPay' assert_equal everypay_channel.channel, 'EveryPay'
assert_equal everypay_channel.class.config_namespace_name, 'every_pay' assert_equal everypay_channel.class.config_namespace_name, 'every_pay'
swed_channel = PaymentOrder.create_with_type(type: 'swed', invoice: @invoice) swed_channel = PaymentOrder.new_with_type(type: 'swed', invoice: @invoice)
assert_equal swed_channel.channel, 'Swed' assert_equal swed_channel.channel, 'Swed'
assert_equal swed_channel.class.config_namespace_name, 'swed' assert_equal swed_channel.class.config_namespace_name, 'swed'
seb_channel = PaymentOrder.create_with_type(type: 'seb', invoice: @invoice) seb_channel = PaymentOrder.new_with_type(type: 'seb', invoice: @invoice)
assert_equal seb_channel.channel, 'Seb' assert_equal seb_channel.channel, 'Seb'
assert_equal seb_channel.class.config_namespace_name, 'seb' assert_equal seb_channel.class.config_namespace_name, 'seb'
lhv_channel = PaymentOrder.create_with_type(type: 'lhv', invoice: @invoice) lhv_channel = PaymentOrder.new_with_type(type: 'lhv', invoice: @invoice)
assert_equal lhv_channel.channel, 'Lhv' assert_equal lhv_channel.channel, 'Lhv'
assert_equal lhv_channel.class.config_namespace_name, 'lhv' assert_equal lhv_channel.class.config_namespace_name, 'lhv'
admin_channel = PaymentOrder.create_with_type(type: 'admin_payment', invoice: @invoice) admin_channel = PaymentOrder.new_with_type(type: 'admin_payment', invoice: @invoice)
assert_equal admin_channel.channel, 'AdminPayment' assert_equal admin_channel.channel, 'AdminPayment'
assert_equal admin_channel.class.config_namespace_name, 'admin_payment' assert_equal admin_channel.class.config_namespace_name, 'admin_payment'
system_channel = PaymentOrder.create_with_type(type: 'system_payment', invoice: @invoice) system_channel = PaymentOrder.new_with_type(type: 'system_payment', invoice: @invoice)
assert_equal system_channel.channel, 'SystemPayment' assert_equal system_channel.channel, 'SystemPayment'
assert_equal system_channel.class.config_namespace_name, 'system_payment' assert_equal system_channel.class.config_namespace_name, 'system_payment'
end end
def test_can_not_create_order_for_paid_invoice def test_can_not_create_order_for_paid_invoice
invoice = invoices(:one) invoice = invoices(:one)
payment_order = PaymentOrder.create_with_type(type: 'every_pay', invoice: invoice) payment_order = PaymentOrder.new_with_type(type: 'every_pay', invoice: invoice)
assert payment_order.invalid? assert payment_order.invalid?
assert_includes payment_order.errors[:invoice], 'is already paid' assert_includes payment_order.errors[:invoice], 'is already paid'
end end
@ -84,7 +84,7 @@ class PaymentOrdersTest < ActiveSupport::TestCase
def test_can_not_create_order_with_invalid_type def test_can_not_create_order_with_invalid_type
assert_raise NameError do assert_raise NameError do
PaymentOrder.create_with_type(type: 'not_implemented', invoice: Invoice.new) PaymentOrder.new_with_type(type: 'not_implemented', invoice: Invoice.new)
end end
end end
@ -97,7 +97,7 @@ class PaymentOrdersTest < ActiveSupport::TestCase
end end
def test_can_create_with_correct_subclass def test_can_create_with_correct_subclass
payment = PaymentOrder.create_with_type(type: 'seb', invoice: Invoice.new) payment = PaymentOrder.new_with_type(type: 'seb', invoice: Invoice.new)
assert_equal PaymentOrders::Seb, payment.class assert_equal PaymentOrders::Seb, payment.class
end end
end end