Cucumber and jruby on rails

I’m using cucumber.
I have a migration:

class CreateComputers < ActiveRecord::Migration
def self.up
create_table :computers do |t|
t.string :name
t.string :state
t.string :company
t.string :serial_number
t.string :type
t.string :model
t.string :operating_system
t.string :cpu
t.integer :cpu_mhz
t.integer :ram
t.string :position
t.string :contact
t.string :contact_tel
t.string :ath_code
t.datetime :last_modified
t.text :notes

  t.timestamps
end

end

I’ve done some features and scenarios for cucumber.
When I run rake:cucumber I have this error:

rake aborted!
ActiveRecord::JDBCError: ERROR: type modifier is not allowed for type
“text”
Posizione: 418: CREATE TABLE “computers” (“id” serial primary key,
“name” varchar(255), “state” varchar(255), “company” varchar(255),
“serial_number” varchar(255), “type” varchar(255), “model”
varchar(255), “operating_system” varchar(255), “cpu” varchar(255),
“cpu_mhz” bigint, “ram” bigint, “position” varchar(255), “contact”
varchar(255), “contact_tel” varchar(255), “ath_code” varchar(255),
“last_modified” timestamp(29), “notes” text(2147483647), “created_at”
timestamp(29), “updated_at” timestamp(29))

If I modify notes in string rather than text cucumber works.
Why I have that jdbc error?

since this morning I ran into a problem with a “type” field and it did
not work at all since it is a deprecated method on every ruby object
and will always return the classname instead of the database entry.
renaming that helped.

your error seams different that what I saw but the underlying reason
might be the same.

regards, Kristian

On 17 October 2010 05:54, kristian [email protected] wrote:

since this morning I ran into a problem with a “type” field and it did
not work at all since it is a deprecated method on every ruby object
and will always return the classname instead of the database entry.
renaming that helped.

Renaming the table field?
I’ve do that renaming notes in comments but it doesn’t helped, the
error is still:

rake aborted!
ActiveRecord::JDBCError: ERROR: type modifier is not allowed for type
“text”
Posizione: 421: CREATE TABLE “computers” (“id” serial primary key,
“name” varchar(255), “state” varchar(255), “company” varchar(255),
“serial_number” varchar(255), “type” varchar(255), “model”
varchar(255), “operating_system” varchar(255), “cpu” varchar(255),
“cpu_mhz” bigint, “ram” bigint, “position” varchar(255), “contact”
varchar(255), “contact_tel” varchar(255), “ath_code” varchar(255),
“last_modified” timestamp(29), “comments” text(2147483647),
“created_at” timestamp(29), “updated_at” timestamp(29))

OK, I was on the wrong path. I talked about the
t.string :type
entry. but it looks like your database driver does not allow the
length modifier on the text type:
text(2147483647)

so if you can execute the following query
CREATE TABLE “computers” (“id” serial primary key,
“name” varchar(255), “state” varchar(255), “company” varchar(255),
“serial_number” varchar(255), “type” varchar(255), “model”
varchar(255), “operating_system” varchar(255), “cpu” varchar(255),
“cpu_mhz” bigint, “ram” bigint, “position” varchar(255), “contact”
varchar(255), “contact_tel” varchar(255), “ath_code” varchar(255),
“last_modified” timestamp(29), “comments” text,
“created_at” timestamp(29), “updated_at” timestamp(29))

without length in text than you found a bug. which database are you
using ?

is the actual task which fails the cucumber tasks or db:migrate from
rails ?

regards, Kristian

On 17 October 2010 14:02, kristian [email protected] wrote:

varchar(255), “operating_system” varchar(255), “cpu” varchar(255),
“cpu_mhz” bigint, “ram” bigint, “position” varchar(255), “contact”
varchar(255), “contact_tel” varchar(255), “ath_code” varchar(255),
“last_modified” timestamp(29), “comments” text,
“created_at” timestamp(29), “updated_at” timestamp(29))

without length in text than you found a bug. which database are you using ?

I’m using postgres.

is the actual task which fails the cucumber tasks or db:migrate from rails ?

db:migrate is ok, in all my rails applications I have no problems with
fields of type text.
It is the cucumber task that fails.

On 4 November 2010 16:23, Bryan T. [email protected] wrote:

what needs to be fixed is the dump task for PostgreSQL databases and
warning that the maximum precision of 6 will be used for the timestamps.

I have just gotten into Rails, and JRuby especially, so I don’t know if
I
can fix this problem at the appropriate level, but I will attempt to
take a look at it when I get a chance.

I must only delete the :limit specification for text types?

Msan M. wrote in post #959344:

I must only delete the :limit specification for text types?

That’s all I did for now. The issue with the timestamps just gives a
warning but should probably be fixed whenever the underlying issue with
text types is fixed. Note however, that you will need to edit the
schema.rb file each time you run db:migrate because it gets regenerated.

Msan M. wrote in post #954980:

db:migrate is ok, in all my rails applications I have no problems with
fields of type text.
It is the cucumber task that fails.

I ran into a similar problem when running “rake spec”. I am using JRuby,
Rails 3, and activerecord-jdbcpostgresql-adapter 1.0.2. The problem
seems to be that when running db:migrate the db:schema:dump task is
creating a db/schema.rb file that specifies a :limit for “text” column
types and PostgreSQL does not allow specifying such a limit. I think
what needs to be fixed is the dump task for PostgreSQL databases and
possibly only when using the JDBC driver (I haven’t tested using
anything
other than JRuby so I don’t know if this problem exists when using MRI
and the native PostgreSQL driver).

I don’t have time to look into a fix for this right now and simply
modified my schema.rb file in order to get my tests to work. There may
be similar problems with timestamps as well. The schema.rb specifies a
limit of 29 for timestamps but when I run the SQL generated by the
db:schema:load task directly on the PostgreSQL console, Postgres gives a
warning that the maximum precision of 6 will be used for the timestamps.

I have just gotten into Rails, and JRuby especially, so I don’t know if
I
can fix this problem at the appropriate level, but I will attempt to
take a look at it when I get a chance.

I too have just encountered this problem, and it is not a problem with
Cucumber, because I am not using Cucumber. I am using JRuby and
PostgreSQL however.

I hit is when trying to do rake db:test:prepare, and removing the limit
from the text fields does indeed solve the problem. It seems to be an
issue with migrate, which generates the schema.rb file a fresh each time
with this erroneous limit. I am sure earlier versions of Rails did not
(pretty sure this was not a problem in 2.3.8), but 2.3.9 does (would not
care to say about the ones in between).

I would guess this is an issue in schema_dumper or
connection_adapters/postgresql_adapter.rb in active_record, but they
appear to be unchanged between 2.3.8 and 2.3.9.

A fix (not necessarily the best, and only slightly tested) is to modify
jruby-1.5.2\lib\ruby\gems\1.8\gems\activerecord-2.3.9\lib\active_record/schema_dumb.rb,
line 107

From:
spec[:limit] = column.limit.inspect if column.limit !=
@types[column.type][:limit] && column.type != :decimal

To:
spec[:limit] = column.limit.inspect if column.limit !=
@types[column.type][:limit] && ![:decimal, :text].include?(column.type)

Just discovered that date (but not datetime) has the same iissue, so the
change to line 107 should be:

        spec[:limit]     = column.limit.inspect if column.limit !=

@types[column.type][:limit] && ![:decimal, :text,
:date].include?(column.type)