From 256c7dfde9bb78f7f01879d3c26eb4dfdc53efe1 Mon Sep 17 00:00:00 2001 From: SeanHealy33 Date: Thu, 21 Jun 2018 10:44:58 +0100 Subject: [PATCH] Change errors to hash with indifference --- lib/mutations/errors.rb | 2 +- spec/errors_spec.rb | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) 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"])