diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2017-01-17 23:53:27 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-17 23:53:27 -0500 |
commit | f5f81be73df89011fe9bc89915b99d81e0c9a67f (patch) | |
tree | bd238ddda782d8918d9b798761cc7696e3ec6d94 | |
parent | ab109d3bf1c773da5e78ddc93bb6b55aebbb1c2a (diff) | |
parent | 33d0d962b777a98f3bdda0be41ee03acc0410676 (diff) | |
download | rails-f5f81be73df89011fe9bc89915b99d81e0c9a67f.tar.gz rails-f5f81be73df89011fe9bc89915b99d81e0c9a67f.tar.bz2 rails-f5f81be73df89011fe9bc89915b99d81e0c9a67f.zip |
Merge pull request #467 from composerinteralia/custom-errors
Raise custom error on empty join
-rw-r--r-- | lib/arel.rb | 2 | ||||
-rw-r--r-- | lib/arel/errors.rb | 7 | ||||
-rw-r--r-- | lib/arel/select_manager.rb | 2 | ||||
-rw-r--r-- | lib/arel/table.rb | 2 | ||||
-rw-r--r-- | test/test_select_manager.rb | 10 | ||||
-rw-r--r-- | test/test_table.rb | 6 |
6 files changed, 27 insertions, 2 deletions
diff --git a/lib/arel.rb b/lib/arel.rb index e04999ed92..710914a2e3 100644 --- a/lib/arel.rb +++ b/lib/arel.rb @@ -1,3 +1,5 @@ +require 'arel/errors' + require 'arel/crud' require 'arel/factory_methods' diff --git a/lib/arel/errors.rb b/lib/arel/errors.rb new file mode 100644 index 0000000000..c8a6af9f77 --- /dev/null +++ b/lib/arel/errors.rb @@ -0,0 +1,7 @@ +module Arel + class ArelError < StandardError + end + + class EmptyJoinError < ArelError + end +end diff --git a/lib/arel/select_manager.rb b/lib/arel/select_manager.rb index eae3bc8cbc..6af9b6fbe6 100644 --- a/lib/arel/select_manager.rb +++ b/lib/arel/select_manager.rb @@ -106,7 +106,7 @@ module Arel case relation when String, Nodes::SqlLiteral - raise if relation.empty? + raise EmptyJoinError if relation.empty? klass = Nodes::StringJoin end diff --git a/lib/arel/table.rb b/lib/arel/table.rb index 3e06f94272..130b7ea028 100644 --- a/lib/arel/table.rb +++ b/lib/arel/table.rb @@ -37,7 +37,7 @@ module Arel case relation when String, Nodes::SqlLiteral - raise if relation.empty? + raise EmptyJoinError if relation.empty? klass = Nodes::StringJoin end diff --git a/test/test_select_manager.rb b/test/test_select_manager.rb index 9a225edeec..e88f0e8e11 100644 --- a/test/test_select_manager.rb +++ b/test/test_select_manager.rb @@ -618,6 +618,16 @@ module Arel manager = Arel::SelectManager.new manager.join(nil).must_equal manager end + + it 'raises EmptyJoinError on empty' do + left = Table.new :users + manager = Arel::SelectManager.new + + manager.from left + assert_raises(EmptyJoinError) do + manager.join("") + end + end end describe 'outer join' do diff --git a/test/test_table.rb b/test/test_table.rb index 168fde370d..e36a6e3a41 100644 --- a/test/test_table.rb +++ b/test/test_table.rb @@ -71,6 +71,12 @@ module Arel mgr.to_sql.must_be_like %{ SELECT FROM "users" } end + it 'raises EmptyJoinError on empty' do + assert_raises(EmptyJoinError) do + @relation.join "" + end + end + it 'takes a second argument for join type' do right = @relation.alias predicate = @relation[:id].eq(right[:id]) |