Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/mutations/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def execute
end

# add_error("name", :too_short)
# add_error(:name, :too_short)
# add_error("colors.foreground", :not_a_color) # => to create errors = {colors: {foreground: :not_a_color}}
# or, supply a custom message:
# add_error("name", :too_short, "The name 'blahblahblah' is too short!")
Expand All @@ -119,7 +120,7 @@ def add_error(key, kind, message = nil)
inner = path.inject(errs) do |cur_errors,part|
cur_errors[part.to_sym] ||= ErrorHash.new
end
inner[last] = ErrorAtom.new(key, kind, :message => message)
inner[last.to_sym] = ErrorAtom.new(key, kind, :message => message)
end
end

Expand Down
6 changes: 4 additions & 2 deletions spec/command_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ class ErrorfulCommand < Mutations::Command
optional { string :email }

def execute
add_error("bob", :is_a_bob)

add_error(:bob, :is_a_bob)
add_error("jane", :is_a_jane)
1
end
end
Expand All @@ -164,7 +164,9 @@ def execute

assert !outcome.success?
assert_nil outcome.result
assert_equal :is_a_bob, outcome.errors[:bob].symbolic
assert_equal :is_a_bob, outcome.errors.symbolic[:bob]
assert_equal :is_a_jane, outcome.errors.symbolic["jane"]
end
end

Expand Down
13 changes: 13 additions & 0 deletions spec/errors_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,19 @@ def execute
assert_equal "Newsletter Subscription isn't a boolean", atom.message
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_nil(outcome.errors["foo"]) }
it{ assert(outcome.errors[:foo]) }
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