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

owner_class_has_initial_state?'s warning should not be shown if the initial_value and the machine's default are the same #185

Closed
fruwe opened this issue May 16, 2012 · 3 comments
Assignees

Comments

@fruwe
Copy link

fruwe commented May 16, 2012

    # Sets the initial state of the machine.  This can be either the static name
    # of a state or a lambda block which determines the initial state at
    # creation time.
    def initial_state=(new_initial_state)
      @initial_state = new_initial_state
      add_states([@initial_state]) unless dynamic_initial_state?

      # Update all states to reflect the new initial state
      states.each {|state| state.initial = (state.name == @initial_state)}

      # Output a warning if there are conflicting initial states for the machine's
      # attribute
      if owner_class_has_initial_state?
        warn(
          "Both #{owner_class.name} and its #{name.inspect} machine have defined "\
          "a default for \"#{attribute}\". Use only one or the other for defining "\
          "defaults to avoid unexpected behaviors."
        )
      end
    end

this shows the warning even if the initial value set in the model is the same as in the machine (in my case ActiveRecord).

The database design is quite strict, so I can not remove the default, but would anyway like to have the default in the code, to make the code more readable. How about checking the values against the defaults? If the default is the same, then do not show the message.

Thanks

@ghost ghost assigned obrie May 17, 2012
@obrie
Copy link
Member

obrie commented May 17, 2012

That's a fair point. It should only give a warning if the values are different. I'll take a look at this in the next release. Thanks :)

@fruwe
Copy link
Author

fruwe commented May 18, 2012

Thanks! Great!

@obrie obrie closed this as completed in 6db0898 May 23, 2012
@obrie
Copy link
Member

obrie commented May 23, 2012

Thanks again for reporting this!

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

2 participants