diff options
author | Emilio Tagua <miloops@gmail.com> | 2009-05-28 18:41:20 -0300 |
---|---|---|
committer | Emilio Tagua <miloops@gmail.com> | 2009-05-28 18:41:20 -0300 |
commit | c55226bac0cfac67081b01860baa61f3acbb2ca9 (patch) | |
tree | d07f143d6b60c21d7e7d183f05bdb580d0902e62 | |
parent | dc09a633c37ca0b214e4d1dd1572cdb9070fc38d (diff) | |
download | rails-c55226bac0cfac67081b01860baa61f3acbb2ca9.tar.gz rails-c55226bac0cfac67081b01860baa61f3acbb2ca9.tar.bz2 rails-c55226bac0cfac67081b01860baa61f3acbb2ca9.zip |
Allow expressions on literal SQL fragments
-rw-r--r-- | lib/arel/engines/sql/primitives.rb | 4 | ||||
-rw-r--r-- | spec/arel/engines/sql/unit/primitives/literal_spec.rb | 12 |
2 files changed, 15 insertions, 1 deletions
diff --git a/lib/arel/engines/sql/primitives.rb b/lib/arel/engines/sql/primitives.rb index bb3bed78e6..a08ca11c12 100644 --- a/lib/arel/engines/sql/primitives.rb +++ b/lib/arel/engines/sql/primitives.rb @@ -3,10 +3,12 @@ module Arel def relation nil end - + def to_sql(formatter = nil) self end + + include Attribute::Expressions end class Attribute diff --git a/spec/arel/engines/sql/unit/primitives/literal_spec.rb b/spec/arel/engines/sql/unit/primitives/literal_spec.rb index c7ff1cf879..ed8bea339b 100644 --- a/spec/arel/engines/sql/unit/primitives/literal_spec.rb +++ b/spec/arel/engines/sql/unit/primitives/literal_spec.rb @@ -18,6 +18,18 @@ module Arel sql.should be_like(%Q{SELECT COUNT(*) AS count_id FROM "users"}) end end + + it "manufactures expressions on literal SQL fragment" do + sql = @relation.project(SqlLiteral.new("2 * credit_limit").sum).to_sql + + adapter_is :mysql do + sql.should be_like(%Q{SELECT SUM(2 * credit_limit) AS sum_id FROM `users`}) + end + + adapter_is_not :mysql do + sql.should be_like(%Q{SELECT SUM(2 * credit_limit) AS sum_id FROM "users"}) + end + end end end end |