diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-11-23 18:22:42 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-11-23 18:22:42 -0800 |
commit | 6667cfb995a49bffe66231a7ffc5a78ca7f5140f (patch) | |
tree | a682d59993e541ee697bfd0e4a5ed7486c22b996 | |
parent | 76932b99d60b28f93c88c9a95873ba8524c9e370 (diff) | |
download | rails-6667cfb995a49bffe66231a7ffc5a78ca7f5140f.tar.gz rails-6667cfb995a49bffe66231a7ffc5a78ca7f5140f.tar.bz2 rails-6667cfb995a49bffe66231a7ffc5a78ca7f5140f.zip |
adding an AS node
-rw-r--r-- | History.txt | 1 | ||||
-rw-r--r-- | Manifest.txt | 2 | ||||
-rw-r--r-- | lib/arel/nodes.rb | 1 | ||||
-rw-r--r-- | lib/arel/nodes/as.rb | 6 | ||||
-rw-r--r-- | lib/arel/predications.rb | 6 | ||||
-rw-r--r-- | lib/arel/visitors/to_sql.rb | 4 | ||||
-rw-r--r-- | test/nodes/test_as.rb | 16 | ||||
-rw-r--r-- | test/visitors/test_to_sql.rb | 6 |
8 files changed, 41 insertions, 1 deletions
diff --git a/History.txt b/History.txt index 328fe6ba8b..5e7ce2ee68 100644 --- a/History.txt +++ b/History.txt @@ -4,6 +4,7 @@ * #lock will lock SELECT statements "FOR UPDATE" on mysql * Nodes::Node#not factory method added for creating Nodes::Not nodes + * Added an As node == 2.0.4 diff --git a/Manifest.txt b/Manifest.txt index c9cd045b75..91de70ff10 100644 --- a/Manifest.txt +++ b/Manifest.txt @@ -17,6 +17,7 @@ lib/arel/expressions.rb lib/arel/insert_manager.rb lib/arel/nodes.rb lib/arel/nodes/and.rb +lib/arel/nodes/as.rb lib/arel/nodes/assignment.rb lib/arel/nodes/avg.rb lib/arel/nodes/between.rb @@ -81,6 +82,7 @@ lib/arel/visitors/visitor.rb lib/arel/visitors/where_sql.rb test/attributes/test_attribute.rb test/helper.rb +test/nodes/test_as.rb test/nodes/test_count.rb test/nodes/test_delete_statement.rb test/nodes/test_equality.rb diff --git a/lib/arel/nodes.rb b/lib/arel/nodes.rb index 2affd01fa8..95dcc0480e 100644 --- a/lib/arel/nodes.rb +++ b/lib/arel/nodes.rb @@ -6,6 +6,7 @@ require 'arel/nodes/not_equal' require 'arel/nodes/assignment' require 'arel/nodes/or' require 'arel/nodes/and' +require 'arel/nodes/as' require 'arel/nodes/not' require 'arel/nodes/greater_than' require 'arel/nodes/greater_than_or_equal' diff --git a/lib/arel/nodes/as.rb b/lib/arel/nodes/as.rb new file mode 100644 index 0000000000..9009fe12f4 --- /dev/null +++ b/lib/arel/nodes/as.rb @@ -0,0 +1,6 @@ +module Arel + module Nodes + class As < Arel::Nodes::Binary + end + end +end diff --git a/lib/arel/predications.rb b/lib/arel/predications.rb index 03cbb7aa3f..5a5c3d4495 100644 --- a/lib/arel/predications.rb +++ b/lib/arel/predications.rb @@ -1,5 +1,9 @@ module Arel module Predications + def as other + Nodes::As.new self, other + end + def not_eq other Nodes::NotEqual.new self, other end @@ -174,4 +178,4 @@ module Arel } end end -end
\ No newline at end of file +end diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb index bbc1eb3105..ae90c0c4b6 100644 --- a/lib/arel/visitors/to_sql.rb +++ b/lib/arel/visitors/to_sql.rb @@ -250,6 +250,10 @@ module Arel end end + def visit_Arel_Nodes_As o + "#{visit o.left} AS #{visit o.right}" + end + def visit_Arel_Nodes_UnqualifiedColumn o "#{quote_column_name o.name}" end diff --git a/test/nodes/test_as.rb b/test/nodes/test_as.rb new file mode 100644 index 0000000000..8585fbc963 --- /dev/null +++ b/test/nodes/test_as.rb @@ -0,0 +1,16 @@ +require 'helper' + +module Arel + module Nodes + describe 'As' do + describe '#as' do + it 'makes an AS node' do + attr = Table.new(:users)[:id] + as = attr.as(Arel.sql('foo')) + assert_equal attr, as.left + assert_equal 'foo', as.right + end + end + end + end +end diff --git a/test/visitors/test_to_sql.rb b/test/visitors/test_to_sql.rb index 89f3f60de2..037fca9931 100644 --- a/test/visitors/test_to_sql.rb +++ b/test/visitors/test_to_sql.rb @@ -38,6 +38,12 @@ module Arel sql.must_be_like "NOT foo" end + it "should visit_As" do + as = Nodes::As.new(Arel.sql("foo"), Arel.sql("bar")) + sql = @visitor.accept as + sql.must_be_like "foo AS bar" + end + it "should visit_Bignum" do @visitor.accept 8787878092 end |