From 05887fc406820f2e8fecc5cedcc42b87cf9f0ab1 Mon Sep 17 00:00:00 2001
From: Ernie Miller <ernie@metautonomo.us>
Date: Sat, 12 Mar 2011 10:53:47 +0800
Subject: Make as factory method convert alias name to SqlLiteral

---
 lib/arel/predications.rb | 2 +-
 test/nodes/test_as.rb    | 6 ++++++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/lib/arel/predications.rb b/lib/arel/predications.rb
index 920a9ee374..75c4c75855 100644
--- a/lib/arel/predications.rb
+++ b/lib/arel/predications.rb
@@ -1,7 +1,7 @@
 module Arel
   module Predications
     def as other
-      Nodes::As.new self, other
+      Nodes::As.new self, Nodes::SqlLiteral.new(other)
     end
 
     def not_eq other
diff --git a/test/nodes/test_as.rb b/test/nodes/test_as.rb
index 8585fbc963..02cbe5f7b0 100644
--- a/test/nodes/test_as.rb
+++ b/test/nodes/test_as.rb
@@ -10,6 +10,12 @@ module Arel
           assert_equal attr, as.left
           assert_equal 'foo', as.right
         end
+
+        it 'converts right to SqlLiteral if a string' do
+          attr = Table.new(:users)[:id]
+          as = attr.as('foo')
+          assert_kind_of Arel::Nodes::SqlLiteral, as.right
+        end
       end
     end
   end
-- 
cgit v1.2.3