diff options
author | Emilio Tagua <miloops@gmail.com> | 2009-12-28 12:58:30 -0300 |
---|---|---|
committer | Emilio Tagua <miloops@gmail.com> | 2009-12-28 12:58:30 -0300 |
commit | bd00a461e042a77aef48822040897467c544cd1a (patch) | |
tree | 8272c2d78da319bde1ab6d736ce6f66b352a25e6 /spec/arel/engines/sql/unit/relations/having_spec.rb | |
parent | 4fe6bdf195336d54b082ca26b96c5294d8aae3d1 (diff) | |
download | rails-bd00a461e042a77aef48822040897467c544cd1a.tar.gz rails-bd00a461e042a77aef48822040897467c544cd1a.tar.bz2 rails-bd00a461e042a77aef48822040897467c544cd1a.zip |
Added having to use in combination with group to filter records.
Diffstat (limited to 'spec/arel/engines/sql/unit/relations/having_spec.rb')
-rw-r--r-- | spec/arel/engines/sql/unit/relations/having_spec.rb | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/spec/arel/engines/sql/unit/relations/having_spec.rb b/spec/arel/engines/sql/unit/relations/having_spec.rb new file mode 100644 index 0000000000..dd170a256f --- /dev/null +++ b/spec/arel/engines/sql/unit/relations/having_spec.rb @@ -0,0 +1,36 @@ +require 'spec_helper' + +module Arel + describe Having do + before do + @relation = Table.new(:developers) + end + + describe '#to_sql' do + describe 'when given a predicate' do + it "manufactures sql with where clause conditions" do + sql = @relation.group(@relation[:department]).having("MIN(salary) > 1000").to_sql + + adapter_is :mysql do + sql.should be_like(%Q{ + SELECT `developers`.`id`, `developers`.`name`, `developers`.`salary`, `developers`.`department` + FROM `developers` + GROUP BY `developers`.`department` + HAVING MIN(salary) > 1000 + }) + end + + adapter_is_not :mysql do + sql.should be_like(%Q{ + SELECT "developers"."id", "developers"."name", "developers"."salary", "developers"."department" + FROM "developers" + GROUP BY "developers"."department" + HAVING MIN(salary) > 1000 + }) + end + end + end + end + end +end + |