-
Notifications
You must be signed in to change notification settings - Fork 137
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
Fail faster when defining invalidly nested defaults #30
Comments
For what it's worth, Mutations allows nested defaults. As far as I can tell, they don't do anything on arrays: class ArrayMutation < Mutations::Command
optional { array :a do; array default: [] end }
def execute; a end
end
p ArrayMutation.run!
# => nil Default nested hashes get merged with the input, like you'd expect: class HashMutation < Mutations::Command
required do
hash :h do
hash :x, default: { b: false } do
boolean :b
end
end
end
def execute; h end
end
p HashMutation.run!(h: {})
# => {"x"=>{"b"=>false}}
p HashMutation.run!(h: { x: { b: true } })
# => {"x"=>{"b"=>true}} I know I argued against defaults in nested blocks before, but I guess I'm not that opposed to them. I can see how they make sense. |
|
ghost
assigned tfausak
Jul 28, 2013
tfausak
added a commit
that referenced
this issue
Aug 6, 2013
Nested default arrays will be ignored. Nested default hashes will be merged with user input.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For array and hash filters, it's invalid to set defaults on nested attributes. However, we don't catch that error until you call
run
. As noted in the specs, we should raise an error when the class is defined.For instance, this code should raise an
ArgumentError
:As it is, you'd have to call
InvalidInteraction.run(a: [])
to get that to fail.The text was updated successfully, but these errors were encountered: