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

Support for configurable column names #73

Closed
wants to merge 4 commits into from

Conversation

cmw
Copy link
Collaborator

@cmw cmw commented Feb 1, 2013

This should fix #54

I settled for

state_machine :attribute_name => :current_state do
end

instead of :column

I also set mocha to a specific version because newer ones break with the configured version of test-unit

@@ -25,9 +25,29 @@ module Transitions
extend ActiveSupport::Concern

included do
class ::Transitions::Machine
unless instance_methods.include?(:new_initialize)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 questions regarding this:

1.) In case new_initialize is predefined, doesn't this mean the "name your state column how you want functionality" will fail badly at runtime without giving the user a chance to find out what he can actually do about it?
2.) If you test for preventing an accidental overriding new_initialize, shouldn't you do the same as well for new_update?
3.) Are you really sure this test makes sense at all? I can see what you're doing I am just not so sure about it...

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1.) In case new_initialize is predefined, doesn't this mean the "name your state column how you want functionality" will fail badly at runtime without giving the user a chance to find out what he can actually do about it?

My point here was that I'd consider it an application bug in transitions itself if we re-opened Transitions::Machine in multiple places and hence I am not so sure that we should check this at all.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just found that in the tests the code that aliases these functions would be executed more than once, resulting in an endless loop.

I also considered just adding it to the code to Transitions::Machine in general but outside of active record it's not really necessary since every state machine has its own name and tracks its own state.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just found that in the tests the code that aliases these functions would be executed more than once, resulting in an endless loop.

Alright - I assume you'll update you're this PR?
:)

I also considered just adding it to the code to Transitions::Machine in general but outside of active record it's not really necessary since every state machine has its own name and tracks its own state.

Yes, exactly.

Also, you haven't responded to my question from above:
Do we have to check this? Should we?
Right now I'd say no, but perhaps I'm missing something...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like I said, the test is there to make sure the aliasing only happens once.
This seems to happen with the tests reliably for some reason and there is nothing keeping a user from requiring the file twice and then ending up with an endless loop.


Alright - I assume you'll update you're this PR?

This one I didn't get :)


Back to your original questions one and two:

  1. I think if somebody wants to modify Transitions::Machine, they should understand the code first, before doing so. I will add a warning about this in the logs, though, to give people a hint.
  2. Checking both might make more sense if we want to cover all cases. Will add that too.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, let me know when that's finished and I'll merge..;)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be there already. Could you check if you see the commit with 8cdcd1a ?

@troessner
Copy link
Owner

This looks excellent!
Now let's discuss the one comment I brought up and then get this bad boy merged..:)

@troessner
Copy link
Owner

Oh, and one more thing: Could you also please add a short section in the README?

@troessner
Copy link
Owner

Excellent! Going to rebase and squash in a second.

@troessner
Copy link
Owner

@cmw the problem is that you used a rather old version of transitions - could you please rebase your feature branch against current master?

@cmw
Copy link
Collaborator Author

cmw commented Feb 5, 2013

I did? Sorry for that. I thought I had updated the source tree first. I'll do so right away

@cmw
Copy link
Collaborator Author

cmw commented Feb 5, 2013

Alright. So now it should be up to date. Tests still look okay, save for some notifications.

end

def set_initial_state
self.state ||= self.class.get_state_machine.initial_state.to_s if self.respond_to?(:state=)
self[transitions_state_column_name] ||= self.class.get_state_machine.initial_state.to_s if self.has_attribute?(transitions_state_column_name)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be:

.....if self.respond_to?(transitions_state_column_name)

otherwise we would have a regression, see here for details: #68

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-> Fixed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, thanks. Didn't know about that issue. Interesting behavior and good to know. So, is there anything else I can help with or are we all set with this fix?

@troessner
Copy link
Owner

Rebased, squashed and merged into master: 1304a15
Thanks, excellent work!

@troessner troessner closed this Feb 6, 2013
@cmw
Copy link
Collaborator Author

cmw commented Feb 6, 2013

awesome, you're welcome

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

Successfully merging this pull request may close these issues.

Ability to set state column name
2 participants