aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorVladimir Meremyanin <vladimir@meremyanin.com>2011-01-29 14:40:39 +0800
committerVladimir Meremyanin <vladimir@meremyanin.com>2011-01-29 14:40:39 +0800
commit2158d592c074813471baa8fa20044b683bb156e6 (patch)
treee124804a463c55547dd9fe7c4b80e96ce5690065 /test
parent7b445c6dd578277f7313746fc497429a56e4b43c (diff)
downloadrails-2158d592c074813471baa8fa20044b683bb156e6.tar.gz
rails-2158d592c074813471baa8fa20044b683bb156e6.tar.bz2
rails-2158d592c074813471baa8fa20044b683bb156e6.zip
implemented support for math operations in numeric attributes
Diffstat (limited to 'test')
-rw-r--r--test/support/fake_record.rb8
-rw-r--r--test/visitors/test_to_sql.rb22
2 files changed, 28 insertions, 2 deletions
diff --git a/test/support/fake_record.rb b/test/support/fake_record.rb
index 376ed40f2d..cdea690a7b 100644
--- a/test/support/fake_record.rb
+++ b/test/support/fake_record.rb
@@ -6,13 +6,17 @@ module FakeRecord
attr_reader :tables
def initialize
- @tables = %w{ users photos developers }
+ @tables = %w{ users photos developers products}
@columns = {
'users' => [
Column.new('id', :integer),
Column.new('name', :string),
Column.new('bool', :boolean),
- Column.new('created_at', :date),
+ Column.new('created_at', :date)
+ ],
+ 'products' => [
+ Column.new('id', :integer),
+ Column.new('price', :decimal)
]
}
@primary_keys = {
diff --git a/test/visitors/test_to_sql.rb b/test/visitors/test_to_sql.rb
index 0c7baab923..82ad17a82c 100644
--- a/test/visitors/test_to_sql.rb
+++ b/test/visitors/test_to_sql.rb
@@ -188,6 +188,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]