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

Initial state doesn't work with rails 3.2 #150

Closed
morgoth opened this issue Jan 2, 2012 · 15 comments
Closed

Initial state doesn't work with rails 3.2 #150

morgoth opened this issue Jan 2, 2012 · 15 comments
Assignees

Comments

@morgoth
Copy link
Contributor

morgoth commented Jan 2, 2012

Hi.

Setting default state doesn't work in rails 3.2 (branch 3-2-stable).

Sample app reproducing issue:

https://github.com/morgoth/state-machine-rails-3-2

class Post < ActiveRecord::Base
  state_machine :initial => :approved do
    event :approve do
      transition all => :approved
    end
  end
end
Post.new.state
=> nil

I tried rails revision: 6e9cd3846811718611543dae049c000076319587 (it's working fine when using gem 3.2.rc1)

@ghost ghost assigned obrie Jan 2, 2012
@obrie obrie closed this as completed in 91f996f Jan 2, 2012
@obrie
Copy link
Member

obrie commented Jan 2, 2012

Nice catch! Hopefully now that I'm hooking into a public API, this shouldn't break again anytime soon. I'm probably going to wait on releasing this fix until 3.2 is a little closer to be officially released.

@brentkirby
Copy link

Any thoughts on a release now that rails is on 3.2.2? We've been updating a rather large app and would rather not use git for the source :)

@obrie
Copy link
Member

obrie commented Mar 5, 2012

Hi @brentkirby -

This fix was released in state_machine 1.1.2.

@brentkirby
Copy link

hmm. I was having the same issue with 1.1.2, and ended up writing a before_create callback to set the default state, which fixed it.

It was actually working fine until updating from rails 3.1.4 to 3.2.2, which is when I first started having trouble.

@obrie
Copy link
Member

obrie commented Mar 5, 2012

Interesting -- I'll double check against the latest 3.2.x release, but everything is passing on 3.2.1. Could you provide an example of this failing? If you have a basic project that you could share on github that demonstrates the issue, that'd be great!

@brentkirby
Copy link

Heres a gist of the actual state machine functionality. I had it in a separate module since the model that includes it is huge :)

After updating to 3.2.2, tons of specs started to fail with ActiveRecord::RecordInvalid, saying "state" is invalid. Adding the before_validation callback fixed it.

ensure_valid_transition is being called in a before_validation on update only.

@obrie
Copy link
Member

obrie commented Mar 7, 2012

Nothing stands out indicating where the issue might be and I can't reproduce the issue based on your gist. Any chance you could provide a full example (including project) that I can run demonstrating the issue?

@urfolomeus
Copy link

I'm getting the same in 3.2.3 (https://gist.github.com/c13a36cec659a1396e5e).

I tried making attr_accessible in case that was an issue, but no dice. Have used brent's before_validation trick (thanks!).

@obrie
Copy link
Member

obrie commented Apr 4, 2012

I'd love to be able to see a project repo demonstrating this issue so that I can reproduce it locally and get it fixed. Would either of you be able to do that?

@urfolomeus
Copy link

I can't publish the current app public as it's client work but I'll dummy one for you later when I get home :)

@urfolomeus
Copy link

Ok, try this simple example project. It has the behaviour I mentioned. Details are in the README.

https://github.com/urfolomeus/state_machine_test

@obrie
Copy link
Member

obrie commented Apr 30, 2012

Hey @urfolomeus -

That project is bundled with state_machine 1.1.0. The fix for ActiveRecord 3.2+ was in state_machine 1.1.2. Updating the Gemfile to that version fixes the issue.

@urfolomeus
Copy link

I was sure I'd set it to the latest version. Humble apologies.

crawls under rock

cheers,

Alan

On Monday, 30 April 2012 at 12:56, Aaron Pfeifer wrote:

Hey @urfolomeus -

That project is bundled with state_machine 1.1.0. The fix for ActiveRecord 3.2+ was in state_machine 1.1.2. Updating the Gemfile to that version fixes the issue.


Reply to this email directly or view it on GitHub:
#150 (comment)

@obrie
Copy link
Member

obrie commented Apr 30, 2012

Glad we were able to figure it out :)

@pjammer
Copy link

pjammer commented May 18, 2012

Hey all,

I got questions, first of which is I'm using

> bundle list | grep state
  * state_machine (1.1.2)
  * state_machine-audit_trail (0.1.0)
 * railis 3.2.2 #btw

The initial state isn't being set. In my controller, i had to jerry-rig it with @shipment.state = "beginning"; @shipment.save

I was having a big time fail with FactoryGirl, of course seeing the readme after.

I'm going to open up another ticket with what i've got in my model... maybe it's something I'm doing. But i'm following the docs.

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

5 participants