Feature: Validate change without needing an event#28
Open
joffotron wants to merge 31 commits intoasiniy:masterfrom
Open
Feature: Validate change without needing an event#28joffotron wants to merge 31 commits intoasiniy:masterfrom
joffotron wants to merge 31 commits intoasiniy:masterfrom
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
asiniy
requested changes
Feb 23, 2017
Owner
asiniy
left a comment
There was a problem hiding this comment.
@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 "changeset without state change" do | ||
| changeset = %User{} |> Ecto.Changeset.change(%{foo: "bar"}) | ||
| |> User.validate_rules_change | ||
| assert changeset.valid? == true |
Owner
There was a problem hiding this comment.
This shouldn't be valid, since this bar state doesn't present in the states list.
| assert changeset.valid? == true | ||
| end | ||
|
|
||
| test "invalid state change", context do |
Owner
There was a problem hiding this comment.
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
Author
|
@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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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