aboutsummaryrefslogblamecommitdiffstats
path: root/activerecord/test/cases/adapters/postgresql/xml_test.rb
blob: 48c6eeb62c6bfd507f3f3580dc027dc3ace88ca3 (plain) (tree)
1
2
                 
                      














                                                        
                                          
       
                                                 

     
             








                                                                            
                                        

     
# encoding: utf-8
require 'cases/helper'

class PostgresqlXMLTest < ActiveRecord::TestCase
  class XmlDataType < ActiveRecord::Base
    self.table_name = 'xml_data_type'
  end

  def setup
    @connection = ActiveRecord::Base.connection
    begin
      @connection.transaction do
        @connection.create_table('xml_data_type') do |t|
          t.xml 'payload', default: {}
        end
      end
    rescue ActiveRecord::StatementInvalid
      skip "do not test on PG without xml"
    end
    @column = XmlDataType.columns_hash['payload']
  end

  teardown do
    @connection.execute 'drop table if exists xml_data_type'
  end

  def test_column
    assert_equal :xml, @column.type
  end

  def test_null_xml
    @connection.execute %q|insert into xml_data_type (payload) VALUES(null)|
    assert_nil XmlDataType.first.payload
  end
end