diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2015-12-17 17:27:57 -0200 |
---|---|---|
committer | Rafael França <rafaelmfranca@gmail.com> | 2015-12-17 17:27:57 -0200 |
commit | 746e3ad6ef3da9514aa1b1f172af4e5db6dc9797 (patch) | |
tree | ddaa5e04d4e05c673094b959d18caae34d7c6e51 | |
parent | 9ca32a67bbcb24f13303718ca1c63b10fcb761ab (diff) | |
parent | 145f32ad8516f9654bdc469096c65549354829ab (diff) | |
download | rails-746e3ad6ef3da9514aa1b1f172af4e5db6dc9797.tar.gz rails-746e3ad6ef3da9514aa1b1f172af4e5db6dc9797.tar.bz2 rails-746e3ad6ef3da9514aa1b1f172af4e5db6dc9797.zip |
Merge pull request #369 from codeodor/patch-1
Improve error message when passed unsupported type
-rw-r--r-- | lib/arel/visitors/to_sql.rb | 8 | ||||
-rw-r--r-- | test/visitors/test_to_sql.rb | 6 |
2 files changed, 10 insertions, 4 deletions
diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb index f2f9d20f21..ce1fdf80ce 100644 --- a/lib/arel/visitors/to_sql.rb +++ b/lib/arel/visitors/to_sql.rb @@ -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 diff --git a/test/visitors/test_to_sql.rb b/test/visitors/test_to_sql.rb index 04fca8024b..7ae5d5b3af 100644 --- a/test/visitors/test_to_sql.rb +++ b/test/visitors/test_to_sql.rb @@ -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 |