-
Notifications
You must be signed in to change notification settings - Fork 20
Feature: Validate change without needing an event #28
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
base: master
Are you sure you want to change the base?
Feature: Validate change without needing an event #28
Conversation
Repoless way
Ignore .idea
Validate changeset instead of raising exception on prohibited actions
Force ex 1.3 & ecto 2.0 to avoid conflicts
List of all possible states
fix function calls ambiguities in mix config
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@joffotron Hello Joe!
Thanks for proposition - it looks promising and definitely missing in the package functionality. I made couple of comments to the codebase - wdyt about them?
Plus, could you rebase your commits into 1, please?
test/ecto_state_machine_test.exs
Outdated
test "changeset without state change" do | ||
changeset = %User{} |> Ecto.Changeset.change(%{foo: "bar"}) | ||
|> User.validate_rules_change | ||
assert changeset.valid? == true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be valid, since this bar
state doesn't present in the states
list.
test/ecto_state_machine_test.exs
Outdated
assert changeset.valid? == true | ||
end | ||
|
||
test "invalid state change", context do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please test all of the possible transitions. It's a little bit paranoic, but it's the testing convention right now
7afde42
to
b515721
Compare
@asiniy Hi! Sorry this has taken a while! I think we have a more comprehensive set of tests now - let me know if there's anything else you need :-) |
ae477a8
to
69abe29
Compare
We came into a case where we needed to do state transitions on our Ecto models, but the new state would be received from user input (e.g an API call)
So instead of using a large conditional, and then using the can_x? / event functions to change state, we put together a simple ecto validation to check that the transition was a valid one.
It would be great if this could be considered for inclusion in the main repo - any feedback is welcome!
Thanks!
Joff