Sha256: 12b360a3a0ea3a3a86d7819b096960aced14ad2803a4a20329274e036606fc75

Contents?: true

Size: 1.49 KB

Versions: 79

Compression:

Stored size: 1.49 KB

Contents

require 'abstract_unit'

class PostgresqlDatatype < ActiveRecord::Base
end

class PGDataTypeTest < Test::Unit::TestCase
  self.use_transactional_fixtures = false

  TABLE_NAME = 'postgresql_datatypes'
  COLUMNS = [
    'id SERIAL PRIMARY KEY',
    'commission_by_quarter INTEGER[]',
    'nicknames TEXT[]'
  ]

  def setup
    @connection = ActiveRecord::Base.connection
    @connection.execute "CREATE TABLE #{TABLE_NAME} (#{COLUMNS.join(',')})"
    @connection.execute "INSERT INTO #{TABLE_NAME} (commission_by_quarter, nicknames) VALUES ( '{35000,21000,18000,17000}', '{foo,bar,baz}' )"
    @first = PostgresqlDatatype.find( 1 )
  end

  def teardown
    @connection.execute "DROP TABLE #{TABLE_NAME}"
  end

  def test_data_type_of_array_types
    assert_equal :string, @first.column_for_attribute("commission_by_quarter").type
    assert_equal :string, @first.column_for_attribute("nicknames").type
  end

  def test_array_values
    assert_equal '{35000,21000,18000,17000}', @first.commission_by_quarter
    assert_equal '{foo,bar,baz}', @first.nicknames
  end

  def test_update_integer_array
    new_value = '{32800,95000,29350,17000}'
    assert @first.commission_by_quarter = new_value
    assert @first.save
    assert @first.reload
    assert_equal @first.commission_by_quarter, new_value
  end

  def test_update_text_array
    new_value = '{robby,robert,rob,robbie}'
    assert @first.nicknames = new_value
    assert @first.save
    assert @first.reload
    assert_equal @first.nicknames, new_value
  end
end

Version data entries

79 entries across 79 versions & 6 rubygems

Version Path
jstorimer-deep-test-2.0.0 sample_rails_project/vendor/rails/activerecord/test/datatype_test_postgresql.rb
jstorimer-deep-test-1.4.0 sample_rails_project/vendor/rails/activerecord/test/datatype_test_postgresql.rb
jstorimer-deep-test-1.3.0 sample_rails_project/vendor/rails/activerecord/test/datatype_test_postgresql.rb
jstorimer-deep-test-1.2.0 sample_rails_project/vendor/rails/activerecord/test/datatype_test_postgresql.rb
jstorimer-deep-test-1.1.0 sample_rails_project/vendor/rails/activerecord/test/datatype_test_postgresql.rb
jstorimer-deep-test-1.0.0 sample_rails_project/vendor/rails/activerecord/test/datatype_test_postgresql.rb
jstorimer-deep-test-0.2.0 sample_rails_project/vendor/rails/activerecord/test/datatype_test_postgresql.rb
jstorimer-deep-test-0.1.0 sample_rails_project/vendor/rails/activerecord/test/datatype_test_postgresql.rb
activerecord-1.15.0 test/datatype_test_postgresql.rb
activerecord-1.15.1 test/datatype_test_postgresql.rb
activerecord-1.15.3 test/datatype_test_postgresql.rb
activerecord-1.15.2 test/datatype_test_postgresql.rb
activerecord-1.15.4 test/datatype_test_postgresql.rb
activerecord-1.15.6 test/datatype_test_postgresql.rb
activerecord-1.15.5 test/datatype_test_postgresql.rb
activerecord_authorails-1.0.0 test/datatype_test_postgresql.rb
backlog-0.0.0 vendor/rails/activerecord/test/datatype_test_postgresql.rb
backlog-0.0.1 vendor/rails/activerecord/test/datatype_test_postgresql.rb
backlog-0.0.2 vendor/rails/activerecord/test/datatype_test_postgresql.rb
backlog-0.0.5 vendor/rails/activerecord/test/datatype_test_postgresql.rb