diff --git a/lib/mutations/errors.rb b/lib/mutations/errors.rb index 81131d3..bb07366 100644 --- a/lib/mutations/errors.rb +++ b/lib/mutations/errors.rb @@ -102,7 +102,7 @@ def message_list # state: ErrorAtom(:in) # } # } - class ErrorHash < Hash + class ErrorHash < HashWithIndifferentAccess # Returns a nested HashWithIndifferentAccess where the values are symbols. Eg: # { diff --git a/spec/errors_spec.rb b/spec/errors_spec.rb index e6166e2..99d550b 100644 --- a/spec/errors_spec.rb +++ b/spec/errors_spec.rb @@ -72,6 +72,22 @@ def execute end end + describe "errors can be accessed as strings and symbolicly" do + class Foo < Mutations::Command + def execute + add_error(:foo, :bar, "baz") + end + end + let(:outcome){ Foo.run } + + it{ assert(outcome.errors["foo"]) } + it{ assert(outcome.errors[:foo]) } + it{ assert_equal(outcome.errors["foo"].message, "baz") } + it{ assert_equal(outcome.errors[:foo].message, "baz") } + + end + + describe "Bunch o errors" do before do @outcome = GivesErrors.run(:str1 => "", :str2 => "opt9", :int1 => "zero", :hash1 => {:bool1 => "bob"}, :arr1 => ["bob", 1, "sally"])