benzelano / test_lh_import

1 stars 0 forks source link

Using state_machine breaks ActiveRecord::Base.new constructor #153

Closed benzelano closed 13 years ago

benzelano commented 13 years ago

Gareth Adams opened this issue

Now, I don’t really think this is a bug in state_machine because it seems pretty elementary, but using any kind of state_machine in my AR models seem to stop attributes being assigned when set through the class constructor.

The only thing I’m adding is the state_machine line - and I get the same result if I add states/events too:

@@@ ruby

Before

class ActivityBooking < ActiveRecord::Base
  attr_accessible :venue_id, :cyear, :cweek
  validates_presence_of :venue_id, :cyear, :cweek

  belongs_to :venue
  has_many :venue_bookings  
end

>> ActivityBooking.new(:cyear => 2010, :cweek => 27)
=> #<ActivityBooking id: nil, venue_id: nil, cyear: 2010, cweek: 27, created_at: nil, updated_at: nil, booking_confirmation_state: nil>

## After
class ActivityBooking < ActiveRecord::Base

  attr_accessible :venue_id, :cyear, :cweek
  validates_presence_of :venue_id, :cyear, :cweek

  belongs_to :venue
  has_many :venue_bookings

  state_machine :booking_confirmation_state do
  end

end

>> ActivityBooking.new(:cyear => 2010, :cweek => 27)
=> #<ActivityBooking id: nil, venue_id: nil, cyear: nil, cweek: nil, created_at: nil, updated_at: nil, booking_confirmation_state: nil>

@@@

original LH ticket

This ticket has 0 attachment(s).

benzelano commented 13 years ago

Gareth Adams commented

Sorry, to be clear:

@@@ ruby

Rails.version => "2.3.5" @@@

benzelano commented 13 years ago

Hey Gareth -

You’re right, this is pretty elementary and it’s unclear what’s going on. Can you try this is a basic Rails app with no other plugins installed and tell me if you see the same problem? Without a better understanding of what other app environment variables are in play, it’ll be difficult to debug the issue.

For what it’s worth, I can’t reproduce this issue on Ruby 1.8.7 / 1.9.1, Rails 2.3.5, and state_machine 0.9.3.

benzelano commented 13 years ago

Gareth Adams commented

Hey,

Sorry, I just realised this is a machine with Ruby 1.8.5 on it. I’ve now taken the opportunity to upgrade to 1.8.7 (which should have happened a long time ago) and everything works fine.

If you’re still interested in looking at it despite it being an ancient version of Ruby, The problem appeared with the first model I created in a brand new Rails project with no other plugins installed.

benzelano commented 13 years ago

Ah, that would explain it. I’m only supporting 1.8.6 and up. Thanks for the info, though!