Skip to content

Commit

Permalink
Adding SqlLiteral with spec for counts
Browse files Browse the repository at this point in the history
  • Loading branch information
brynary committed May 20, 2009
1 parent 976fb01 commit 8636459
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/arel/engines/sql/primitives.rb
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
23 changes: 23 additions & 0 deletions spec/arel/engines/sql/unit/primitives/literal_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 8636459

Please sign in to comment.