Problem running unit test

Hi Folks

I'm brand new in rails. I'm trying to build a little application, and when I tried to run a unit test, I got an error. The error follows below:

ActiveRecord::StatementInvalid: PGError: ERROR: value too long for type character varying(2)

The migration is:

class CreateParticipantes < ActiveRecord::Migration   def self.up     create_table :participantes do |t|       t.string :cpf, :limit => 11       t.string :nome, :limit => 100       t.string :apelido, :limit => 50       t.string :sexo, :limit => 1       t.string :rg, :limit => 15       t.string :emissor, :limit => 10       t.date :datanascimento       t.string :nomeresponsavel, :limit => 100       t.string :rgresponsavel, :limit => 15       t.string :parentesco, :limit => 50       t.string :endereco, :limit => 100       t.string :cidade, :limit => 100       t.string :estado, :limit => 2       t.string :cep, :limit => 8       t.string :email, :limit => 255       t.string :telefone, :limit => 10       t.string :celular, :limit => 10       t.boolean :possuiplanosaude       t.string :planodesaude, :limit => 50       t.string :clube, :limit => 50       t.string :nomeemergencia, :limit => 100       t.string :telefoneemergencia, :limit => 10       t.text :doenca       t.text :alergias       t.boolean :usacelular       t.boolean :eventoanterior       t.string :senha, :limit => 50

      t.timestamps     end

    add_index(:participantes, :cpf)   end

  def self.down     drop_table :participantes   end end

And the test class is:

require 'test_helper'

class ParticipanteTest < ActiveSupport::TestCase   def test_insercao_correta     participante = Participante.create(:cpf => "93468920059")     assert(participante.valid?);   end end

I could run the code inside test_insercao_correta in a shell script using the test database and the develop database.

When the result had shown in a shell, I saw the following query (I'm calling query, but I don't know if it is really a query); INSERT INTO "participantes" ("doenca", "celular", "updated_at", "alergias", "planodesaude", "eventoanterior", "endereco", "nomeemergencia", "possuiplanosaude", "cep", "datanascimento", "nome", "cpf", "usacelular", "clube", "rgresponsavel", "id", "nomeresponsavel", "cidade", "parentesco", "emissor", "apelido", "sexo", "created_at", "senha", "telefoneemergencia", "telefone", "email", "estado", "rg") VALUES (E'MyString', E'MyString', E'2010-04-08 02:16:38', E'MyString', E'MyString', 'f', E'MyString', E'MyString', 'f', E'MyString', '2010-03-17', E'MyString', E'MyString', 'f', E'MyString', E'MyString', 298486374, E'MyString', E'MyString', E'MyString', E'MyString', E'MyString', NULL, E'2010-04-08 02:16:38', E'MyString', E'MyString', E'MyString', E'MyString', E'MyString', E'MyString')

Is there someone could help me?

Thanks in advance

It looks like the autogenerated fixtures file contains data that is too long for some of your columns (I think rails just puts MyString in all string fields, but some of your columns only have length 2)

Fred

Yes I have the column estado with 2 characters. But if I define :estado => "RS" the error continues.

I'm using PostgreSQL to build the application.

I think Fred meant you to look in the fixtures file that rails may have autogenerated for you (test/fixtures/participantes.yml) and check the lengths of data there.

Colin

I wil see. Even I use the command rake test:units, will fixtures be loaded?

I wil see. Even I use the command rake test:units, will fixtures be loaded?

Yup. Fixtures are loaded no matter how you run the tests.

Fred

It works. I had fixtures automatically generated with 'MyString'. Thanks for all help.