aboutsummaryrefslogtreecommitdiffstats
path: root/test/visitors/test_to_sql.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-03-07 08:30:09 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2011-03-07 08:30:09 -0800
commit8aa5d7a393e0bbef8cd3ae9ecf64c2358b802b5f (patch)
tree65bf0d13754591494117283ac9b8c076cd5799ea /test/visitors/test_to_sql.rb
parent2644bcec7dbe3a65277b3a6a141853484171535a (diff)
parent2158d592c074813471baa8fa20044b683bb156e6 (diff)
downloadrails-8aa5d7a393e0bbef8cd3ae9ecf64c2358b802b5f.tar.gz
rails-8aa5d7a393e0bbef8cd3ae9ecf64c2358b802b5f.tar.bz2
rails-8aa5d7a393e0bbef8cd3ae9ecf64c2358b802b5f.zip
Merge remote branch 'stiff/master' into omg
* stiff/master: implemented support for math operations in numeric attributes
Diffstat (limited to 'test/visitors/test_to_sql.rb')
-rw-r--r--test/visitors/test_to_sql.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/test/visitors/test_to_sql.rb b/test/visitors/test_to_sql.rb
index c8ad40e242..3af316037a 100644
--- a/test/visitors/test_to_sql.rb
+++ b/test/visitors/test_to_sql.rb
@@ -194,6 +194,28 @@ module Arel
end
end
+ describe "Nodes::MathOperation" 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")
+ end
+
+ it "should handle Division" do
+ node = Arel::Attributes::Decimal.new(Table.new(:products), :price) / 5
+ @visitor.accept(node).must_equal %("products"."price" / 5)
+ end
+
+ it "should handle Addition" do
+ node = Arel::Attributes::Decimal.new(Table.new(:products), :price) + 6
+ @visitor.accept(node).must_equal %(("products"."price" + 6))
+ end
+
+ it "should handle Subtraction" do
+ node = Arel::Attributes::Decimal.new(Table.new(:products), :price) - 7
+ @visitor.accept(node).must_equal %(("products"."price" - 7))
+ end
+ end
+
describe "Nodes::NotIn" do
it "should know how to visit" do
node = @attr.not_in [1, 2, 3]