Skip to content

Commit

Permalink
Change errors to hash with indifference
Browse files Browse the repository at this point in the history
  • Loading branch information
SeanHealy33 committed Jun 21, 2018
1 parent cb56937 commit abb652c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/mutations/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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:
# {
Expand Down
16 changes: 16 additions & 0 deletions spec/errors_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,22 @@ def execute
end
end

describe "errors as symbols remain symbols" 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"])
Expand Down

0 comments on commit abb652c

Please sign in to comment.