1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #369 from codeodor/patch-1

Improve error message when passed unsupported type
This commit is contained in:
Rafael França 2015-12-17 17:27:57 -02:00
commit 746e3ad6ef
2 changed files with 10 additions and 4 deletions

View file

@ -4,6 +4,12 @@ require 'arel/visitors/reduce'
module Arel
module Visitors
class UnsupportedVisitError < StandardError
def initialize(object)
super "Unsupported argument type: #{object.class.name}. Construct an Arel node instead."
end
end
class ToSql < Arel::Visitors::Reduce
##
# This is some roflscale crazy stuff. I'm roflscaling this because
@ -737,7 +743,7 @@ module Arel
end
def unsupported o, collector
raise "unsupported: #{o.class.name}"
raise UnsupportedVisitError.new(o)
end
alias :visit_ActiveSupport_Multibyte_Chars :unsupported

View file

@ -273,9 +273,9 @@ module Arel
compile(Nodes.build_quoted(nil)).must_be_like "NULL"
end
it "unsupported input should not raise ArgumentError" do
error = assert_raises(RuntimeError) { compile(nil) }
assert_match(/\Aunsupported/, error.message)
it "unsupported input should raise UnsupportedVisitError" do
error = assert_raises(UnsupportedVisitError) { compile(nil) }
assert_match(/\AUnsupported/, error.message)
end
it "should visit_Arel_SelectManager, which is a subquery" do