pluginaweek / state_machine

Adds support for creating state machines for attributes on any Ruby class
http://www.pluginaweek.org
MIT License
3.74k stars 507 forks source link

Weird warning "Both `model class` and its :state machine have defined a different default for "state". #279

Open jugyo opened 11 years ago

jugyo commented 11 years ago

How to reproduce

migration

class CreateBooks < ActiveRecord::Migration
  def change
    create_table :books do |t|
      t.integer :state, :default => 1

      t.timestamps
    end
  end
end

model

class Book < ActiveRecord::Base
  state_machine :state do
    state :foo, :value => 1
  end
end

rails console

% rails console
> Book
> reload!
> Book
Both Book and its :state machine have defined a different default for "state". Use only one or the other for defining defaults to avoid unexpected behaviors.

I think StateMachine::Machine#initial_state method should ignore nil arg. https://github.com/pluginaweek/state_machine/blob/master/lib/state_machine/machine.rb#L629

Thanks