aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/support/fake_record.rb14
-rw-r--r--test/visitors/test_to_sql.rb22
2 files changed, 32 insertions, 4 deletions
diff --git a/test/support/fake_record.rb b/test/support/fake_record.rb
index 54f73489c9..babf5fa25b 100644
--- a/test/support/fake_record.rb
+++ b/test/support/fake_record.rb
@@ -6,20 +6,26 @@ module FakeRecord
attr_reader :tables, :columns_hash
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)
]
}
@columns_hash = {
- 'users' => Hash[@columns['users'].map { |x| [x.name, x] }]
+ 'users' => Hash[@columns['users'].map { |x| [x.name, x] }],
+ 'products' => Hash[@columns['products'].map { |x| [x.name, x] }]
}
@primary_keys = {
- 'users' => 'id'
+ 'users' => 'id',
+ 'products' => 'id'
}
end
diff --git a/test/visitors/test_to_sql.rb b/test/visitors/test_to_sql.rb
index 2d5549ca43..c47fd57a28 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]