The error below has been encountered using both Rails 2.1.1 and 2.1.2.

I have a strange Time Zone / Active Record persistence error that only
occurs on Windows (it works fine on OS X).  In addition, it only occurs
when I run my entire test suite (units). If I only run a single test, it
works fine.  And the code works fine when I run my application on either
operating system.

It appears Active Record is trying to serialize the entire
TZInfo::DataTimezone object into the database column when my "user"
object is saved.   This results in a "Data too long for column error".

The time zone field is mapped as a string in the database.  I create a
time_zone object in my "user" model object as follows:

  def time_zone_object
    ::ActiveSupport::TimeZone[time_zone]
  end

The error message is:

ActiveRecord::StatementInvalid: Mysql::Error: #22001Data too long for
column 'time_zone' at row 1:  <snip>
!ruby/object:ActiveSupport::TimeZone \nname: Central Time (US &
Canada)\ntzinfo: !ruby/object:TZInfo::DataTimezone \n  info:
!ruby/object:TZInfo::DataTimezoneInfo \n    identifier:
America/Chicago\n    last_month: 11\n    last_year: 2050\n    offsets:
\n      :o4: &id005 !ruby/object:TZInfo::TimezoneOffsetInfo \n
abbreviation: :CWT\n        std_offset: 3600\n        utc_offset:
-21600\n        utc_total_ <and so on...>

Attached is the entire error message.  This is really strange and any
tips on a workaround would be greatly appreciated. Here is the unit test
code that is failing:

require File.dirname(__FILE__) + '/../test_helper'
require "active_support/values/time_zone"

class UserTest < Test::Unit::TestCase
  fixtures :users, :teams, :seasons, :countries

  def setup
    delete_all_users
    @usa = countries(:us)
    @central = ::ActiveSupport::TimeZone["Central Time (US & Canada)"]
  end

  def test_active?
    bob = User.new(:name => Name.new('bob', nil, 'smith'),
      :email => '[EMAIL PROTECTED]',
      :password => 'secret',
      :password_confirmation => 'secret',
      :time_zone => @central,
      :country_flag => @usa)
    bob.admin = true
    bob.save!

    assert !bob.active?

    bob.teams << Team.new(:name => "bob's team", :season =>
Season.current)
    bob.save!
    assert bob.active?
  end

Anyone ever seen anything like this before?  Thanks!

Attachments:
http://www.ruby-forum.com/attachment/2931/error.txt

-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to