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

Problem with parent-child relations in tests #11

Closed
obrie opened this issue Aug 6, 2011 · 6 comments
Closed

Problem with parent-child relations in tests #11

obrie opened this issue Aug 6, 2011 · 6 comments
Assignees

Comments

@obrie
Copy link
Member

obrie commented Aug 6, 2011

Dennis Theisen opened this issue

  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):

    @@@ ruby
    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?

original LH ticket

This ticket has 0 attachment(s).

@obrie
Copy link
Member Author

obrie commented Aug 6, 2011

Dennis Theisen commented

It is also not possible for me to use
@@@ ruby
Article.create
@@@

anymore, it throws the same kind of exception:

@NoMethodError: undefined method `create’ for PluginAWeek::StateMachine::Event:Class@

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... :(

@obrie
Copy link
Member Author

obrie commented Aug 6, 2011

Hi soleone,

Thanks for reporting the problem. It sounds like #create is getting called from within an event block like so:

@@@ ruby
state_machine do
event :do_something do
create :id => 1 # or something like that
...
end
end
@@@

Is this a problem you’re still running into or has it since been resolved?

@ghost ghost assigned obrie Aug 6, 2011
@obrie
Copy link
Member Author

obrie commented Aug 6, 2011

Dennis Theisen commented

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 Event class with a create() method, which was listening for Blogs and Comments creation. But somehow because the StateMachine’s Event-Class was used in one of the child classes, whenever a Blog got created, it tried to call Event.create (of our Event class), but ended up calling StateMachine::Event.create - which obviously wasn’t there.

I fixed the problem by changing the Listener in our system from Event.create to ::Event.create

Sorry for wasting your time, I thought I already updated this ticket.

Greetings, Dennis

@obrie
Copy link
Member Author

obrie commented Aug 6, 2011

Dennis Theisen commented

Btw, it seems I screwed up the layout because there is an unclosed code-tag. I tried to close it with this post :)

@obrie
Copy link
Member Author

obrie commented Aug 6, 2011

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 :)

@obrie
Copy link
Member Author

obrie commented Aug 6, 2011

(from [a3cbd33]) Change how the base module is included to prevent namespacing conflicts [#1 state:resolved] http://github.com/pluginaweek/state_machine/commit/a3cbd3308f37deb083d277c1b253837e93e3407a

@obrie obrie closed this as completed Aug 6, 2011
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