aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-03-21 14:58:15 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2011-03-21 14:58:15 -0700
commit83d045d2d8881e4310f0f54376a5e04d395f3c7a (patch)
treea2e88cd0c5d1aa629ac5702225c5ea48b807cb9f /test
parent856fd75c9b6defb7711f93e6ecda2932e98c4113 (diff)
parent05887fc406820f2e8fecc5cedcc42b87cf9f0ab1 (diff)
downloadrails-83d045d2d8881e4310f0f54376a5e04d395f3c7a.tar.gz
rails-83d045d2d8881e4310f0f54376a5e04d395f3c7a.tar.bz2
rails-83d045d2d8881e4310f0f54376a5e04d395f3c7a.zip
Merge branch 'master' of github.com:rails/arel
* 'master' of github.com:rails/arel: Make as factory method convert alias name to SqlLiteral Replace MathOperation with InfixOperation to support more operators
Diffstat (limited to 'test')
-rw-r--r--test/nodes/test_as.rb6
-rw-r--r--test/visitors/test_to_sql.rb11
2 files changed, 16 insertions, 1 deletions
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
diff --git a/test/visitors/test_to_sql.rb b/test/visitors/test_to_sql.rb
index c47fd57a28..25ff7be3e2 100644
--- a/test/visitors/test_to_sql.rb
+++ b/test/visitors/test_to_sql.rb
@@ -194,7 +194,7 @@ module Arel
end
end
- describe "Nodes::MathOperation" do
+ describe "Nodes::InfixOperation" do
it "should handle Multiplication" do
node = Arel::Attributes::Decimal.new(Table.new(:products), :price) * Arel::Attributes::Decimal.new(Table.new(:currency_rates), :rate)
@visitor.accept(node).must_equal %("products"."price" * "currency_rates"."rate")
@@ -214,6 +214,15 @@ module Arel
node = Arel::Attributes::Decimal.new(Table.new(:products), :price) - 7
@visitor.accept(node).must_equal %(("products"."price" - 7))
end
+
+ it "should handle arbitrary operators" do
+ node = Arel::Nodes::InfixOperation.new(
+ '||',
+ Arel::Attributes::String.new(Table.new(:products), :name),
+ Arel::Attributes::String.new(Table.new(:products), :name)
+ )
+ @visitor.accept(node).must_equal %("products"."name" || "products"."name")
+ end
end
describe "Nodes::NotIn" do