diff options
author | Bryan Helmkamp <bryan@brynary.com> | 2009-05-19 21:36:34 -0400 |
---|---|---|
committer | Bryan Helmkamp <bryan@brynary.com> | 2009-05-19 21:36:34 -0400 |
commit | 86364591af807ed3fa4a7304f53e6f3458cb4961 (patch) | |
tree | e92b1df3d89a1fb0fdefa1134e29c54343d63fcb | |
parent | 976fb01a5dd812bcb50cc7b576941c76657908f9 (diff) | |
download | rails-86364591af807ed3fa4a7304f53e6f3458cb4961.tar.gz rails-86364591af807ed3fa4a7304f53e6f3458cb4961.tar.bz2 rails-86364591af807ed3fa4a7304f53e6f3458cb4961.zip |
Adding SqlLiteral with spec for counts
-rw-r--r-- | lib/arel/engines/sql/primitives.rb | 10 | ||||
-rw-r--r-- | spec/arel/engines/sql/unit/primitives/literal_spec.rb | 23 |
2 files changed, 33 insertions, 0 deletions
diff --git a/lib/arel/engines/sql/primitives.rb b/lib/arel/engines/sql/primitives.rb index f2e8e8dabe..bb3bed78e6 100644 --- a/lib/arel/engines/sql/primitives.rb +++ b/lib/arel/engines/sql/primitives.rb @@ -1,4 +1,14 @@ module Arel + class SqlLiteral < String + def relation + nil + end + + def to_sql(formatter = nil) + self + end + end + class Attribute def column original_relation.column_for(self) diff --git a/spec/arel/engines/sql/unit/primitives/literal_spec.rb b/spec/arel/engines/sql/unit/primitives/literal_spec.rb new file mode 100644 index 0000000000..c7ff1cf879 --- /dev/null +++ b/spec/arel/engines/sql/unit/primitives/literal_spec.rb @@ -0,0 +1,23 @@ +require File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'spec_helper') + +module Arel + describe SqlLiteral do + before do + @relation = Table.new(:users) + end + + describe '#to_sql' do + it "manufactures sql with a literal SQL fragment" do + sql = @relation.project(Count.new(SqlLiteral.new("*"))).to_sql + + adapter_is :mysql do + sql.should be_like(%Q{SELECT COUNT(*) AS count_id FROM `users`}) + end + + adapter_is_not :mysql do + sql.should be_like(%Q{SELECT COUNT(*) AS count_id FROM "users"}) + end + end + end + end +end |