Sha256: fa311abdb6931de3d231778034b0c3eb40a3241d7a051a066fc2879727989919

Contents?: true

Size: 1.9 KB

Versions: 3

Compression:

Stored size: 1.9 KB

Contents

require 'test_helper'

module Billing
  class PaymentTest < ActiveSupport::TestCase
    setup do
      @payment = billing_payments(:one)
      @account = @payment.account
    end
    
    # test "args_to_attributes class method" do
      # payment_type = billing_payment_type(:one)
      # assert_equal Billing::Payment.args_to_attributes(), {}
      # assert_equal Billing::Payment.args_to_attributes(payment_type.id), { payment_type_id: payment_type.id }
      # assert_equal Billing::Payment.args_to_attributes(billing_payment_type(:one)), { payment_type_id: payment_type.id }
      # assert_equal Billing::Payment.args_to_attributes(payment_type_id: 2, value: 0.23), { payment_type_id: 2, value: 0.23 }
    # end
    
    test "create" do
      assert_equal 'Billing::PaymentWithType', @account.origin_payment_model
      assert @account.payments.create(type: 'Billing::PaymentWithType', value: 1, payment_type_id: @payment.payment_type_id).persisted?, "Can't create payment"
    end
    
    test "should be instance of account's origin_payment_model" do
      payment = @account.payments.new(type: 'Billing::Payment', value: 1, payment_type_id: @payment.payment_type_id)
      assert !payment.save
      assert payment.errors.messages[:account]
    end
    
    test "should have same fiscal flag as other account payments" do
      payment = @account.payments.new(type: 'Billing::PaymentWithType', value: 1, payment_type_id: billing_payment_types(:fiscal).id)
      assert !payment.save
      assert payment.errors.messages[:account]
    end
    
    test "should be single cash payments" do
      @account.payments.create!(type: 'Billing::PaymentWithType', value: 1, payment_type_id: billing_payment_types(:cash).id)
      payment = @account.payments.new(type: 'Billing::PaymentWithType', value: 1, payment_type_id: billing_payment_types(:cash).id)
      assert !payment.save
      assert payment.errors.messages[:account]
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
billing-0.0.4b test/models/billing/payment_test.rb
billing-0.0.4a test/models/billing/payment_test.rb
billing-0.0.4 test/models/billing/payment_test.rb