Mysql and Auto_Increment woes

I’ve had to deal with this from the beginning of my work with Rails and
Mysql, but now it’s really putting me on full stop. I’ve started using
Selenium and Selenium IDE to do system testing of my rails site (highly
recommended, pick up selenium_on_rails plugin). Selenium IDE, when you
click
on a link, basically grabs the entire a tag to make sure it knows what
link
to click on. For this situation, it’s:

//a[@onclick=“new Ajax.Request(’
http://localhost:5000/portal_tables/14/records/1’, {asynchronous:true,
evalScripts:true, method:‘get’}); return false;”]

The problem is “portal_tables/14”. The portal_tables table is rebuilt
before
each test (fixtures), which means in MySQL that the id each portal_table
gets is now different. So when Selenium goes to click on this link I
told it
to look for, it can’t find it because the link is now:

//a[@onclick=“new Ajax.Request(’
http://localhost:5000/portal_tables/26/records/1’, {asynchronous:true,
evalScripts:true, method:‘get’}); return false;”]

So, how do I stop this from happening? Is there a mysql server
configuration
I can set that resets auto_increment when a table is cleared? This is
one of
the more annoying “features” of MySQL vs Postgres (in which I’ve never
seen
this problem before).

I’m sure others have hit this problem, is it easily solvable?

Jason

On Apr 20, 2:14 pm, “Jason R.” [email protected] wrote:

The problem is “portal_tables/14”. The portal_tables table is rebuilt before
each test (fixtures), which means in MySQL that the id each portal_table
gets is now different. So when Selenium goes to click on this link I told it
to look for, it can’t find it because the link is now:

So, how do I stop this from happening? Is there a mysql server configuration
I can set that resets auto_increment when a table is cleared? This is one of
the more annoying “features” of MySQL vs Postgres (in which I’ve never seen

You have IDs hard coded in your fixtures, right? You could try using
a snippet like this:

ActiveRecord::Base.connection.tables.each do |table|
  max_id = ActiveRecord::Base.connection.select_value("SELECT

MAX(id) FROM #{table}").to_i
ActiveRecord::Base.connection.execute “ALTER TABLE #{table} SET
auto_increment = #{max_id+1}”
end

Dan M.
http://www.dcmanges.com/blog