# Problem running unit test

**URL:** <https://www.ruby-forum.com/t/problem-running-unit-test/186549>\
**Category:** Rails\
**Created:** [April 8, 2010, 6:19pm UTC](https://www.ruby-forum.com/t/problem-running-unit-test/186549 "2010-04-08T18:19:05Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Everton\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ed655f/32.png) [@Everton\_L](https://www.ruby-forum.com/u/Everton_L)\
**Post date:** [April 8, 2010, 6:19pm UTC](https://www.ruby-forum.com/t/problem-running-unit-test/186549/1 "2010-04-08T18:19:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Everton\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ed655f/32.png) [@Everton\_L](https://www.ruby-forum.com/u/Everton_L)\
**Post date:** [April 8, 2010, 6:21pm UTC](https://www.ruby-forum.com/t/problem-running-unit-test/186549/2 "2010-04-08T18:21:26Z")

</div>

On Apr 8, 3:35 pm, Everton L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 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)

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

---

<div class="post-metadata">

**Author:** ![Everton\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ed655f/32.png) [@Everton\_L](https://www.ruby-forum.com/u/Everton_L)\
**Post date:** [April 8, 2010, 6:47pm UTC](https://www.ruby-forum.com/t/problem-running-unit-test/186549/3 "2010-04-08T18:47:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Everton\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ed655f/32.png) [@Everton\_L](https://www.ruby-forum.com/u/Everton_L)\
**Post date:** [April 8, 2010, 9:35pm UTC](https://www.ruby-forum.com/t/problem-running-unit-test/186549/4 "2010-04-08T21:35:47Z")

</div>

I’m using PostgreSQL to build the application.

---

<div class="post-metadata">

**Author:** ![Everton\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ed655f/32.png) [@Everton\_L](https://www.ruby-forum.com/u/Everton_L)\
**Post date:** [April 8, 2010, 9:41pm UTC](https://www.ruby-forum.com/t/problem-running-unit-test/186549/5 "2010-04-08T21:41:39Z")

</div>

On 8 April 2010 17:45, Everton L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > ActiveRecord::StatementInvalid: PGError: ERROR: value too long for  
> > > type character varying(2)
> > 
> > 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)

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

---

<div class="post-metadata">

**Author:** ![Everton\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ed655f/32.png) [@Everton\_L](https://www.ruby-forum.com/u/Everton_L)\
**Post date:** [April 8, 2010, 11:56pm UTC](https://www.ruby-forum.com/t/problem-running-unit-test/186549/6 "2010-04-08T23:56:54Z")

</div>

On Apr 8, 9:22 pm, Everton L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 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

---

<div class="post-metadata">

**Author:** ![Everton\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ed655f/32.png) [@Everton\_L](https://www.ruby-forum.com/u/Everton_L)\
**Post date:** [April 8, 2010, 10:24pm UTC](https://www.ruby-forum.com/t/problem-running-unit-test/186549/7 "2010-04-08T22:24:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Everton\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ed655f/32.png) [@Everton\_L](https://www.ruby-forum.com/u/Everton_L)\
**Post date:** [April 9, 2010, 1:41am UTC](https://www.ruby-forum.com/t/problem-running-unit-test/186549/8 "2010-04-09T01:41:04Z")

</div>

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