Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jugyo opened this issue Sep 3, 2013 · 0 comments

Comments

@jugyo
Copy link

jugyo commented Sep 3, 2013

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

martyn-w added a commit to CottageLabs/alm that referenced this issue Nov 5, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant