Problem with parent-child relations in tests
Reported by Dennis Theisen | August 6th, 2008 @ 12:53 PM
1. Ok, I have a Blog which has Articles which has Comments (all ActiveRecord).
2. The StateMachine is used in the comments (for moderation/trash/spam states).
3. When running the following BlogTest, I get a strange exception (at least for me it's strange):
assert Blog.create(:title => 'hey')
This is the exception:
@NoMethodError: undefined method `create' for PluginAWeek::StateMachine::Event:Class
method log in event.rb at line 31
method send in association_collection.rb at line 259
method method_missing in association_collection.rb at line 259
method with_scope in base.rb at line 1841@
The statemachine isn't used in the Blog at all, only in comments which is a second class child. I also tried to install the plugin_test_helper (which is only needed for running the StateMachineTests themselves anyway, I guess)
Do you have any tip, what I am doing wrong? Or is this really a bug?
Comments and changes to this ticket
-
Dennis Theisen August 7th, 2008 @ 04:34 PM
It is also not possible for me to use
Article.createanymore, it throws the same kind of exception:
NoMethodError: undefined methodcreate' for PluginAWeek::StateMachine::Event:Class</code>I am really going crazy over this, I have no clue what I am doing wrong. But it seems, like it's only me, as I have found no one else having this kind of problem... :(
-
Aaron Pfeifer September 7th, 2008 @ 01:35 AM
- → State changed from new to open
Hi soleone,
Thanks for reporting the problem. It sounds like #create is getting called from within an event block like so:
state_machine do event :do_something do create :id => 1 # or something like that ... end endIs this a problem you're still running into or has it since been resolved?
-
Dennis Theisen September 7th, 2008 @ 02:04 PM
Hey Aaron,
unfortunately I forgot to update this ticket, because the problem is resolved.
There was a namespace clash: in our system we also had an
Eventclass with acreate()method, which was listening forBlogsandCommentscreation. But somehow because the StateMachine's Event-Class was used in one of the child classes, whenever a Blog got created, it tried to callEvent.create(of our Event class), but ended up callingStateMachine::Event.create- which obviously wasn't there.I fixed the problem by changing the Listener in our system from
Event.createto::Event.createSorry for wasting your time, I thought I already updated this ticket.
Greetings, Dennis
-
Dennis Theisen September 7th, 2008 @ 02:07 PM
Btw, it seems I screwed up the layout because there is an unclosed code-tag. I tried to close it with this post :)
-
Aaron Pfeifer September 7th, 2008 @ 04:39 PM
Thanks for the update. It turns out this actually is a problem which could affect other plugins here as well. I didn't think about the fact that including PluginAWeek::StateMachine in ActiveRecord would cause all model references to Event/Machine/Transition to point to those classes under the PluginAWeek::StateMachine namespace instead of the top-level namespace. A very interesting problem!
A fix for this problem should be available within the next few days or so, at which point you should no longer need to use ::Event instead of Event :)
-
Aaron Pfeifer October 4th, 2008 @ 06:18 PM
- → State changed from open to resolved
(from [a3cbd3308f37deb083d277c1b253837e93e3407a]) Change how the base module is included to prevent namespacing conflicts [#1 state:resolved] http://github.com/pluginaweek/st...
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
Adds support for creating state machines for attributes within a model
