diff options
author | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-03-16 17:27:40 -0700 |
---|---|---|
committer | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-03-16 17:27:40 -0700 |
commit | 7bd0d634867ccbdf4537ba3d62b865b1cb7beebf (patch) | |
tree | f469465c385a99722b2263cae5f68a1a961a3c76 /spec/active_relation/unit/relations/order_spec.rb | |
parent | aa5c9a19826c84bbb9c9f75f8d1a4b04b874780c (diff) | |
download | rails-7bd0d634867ccbdf4537ba3d62b865b1cb7beebf.tar.gz rails-7bd0d634867ccbdf4537ba3d62b865b1cb7beebf.tar.bz2 rails-7bd0d634867ccbdf4537ba3d62b865b1cb7beebf.zip |
allowing string passthrough for order clauses
Diffstat (limited to 'spec/active_relation/unit/relations/order_spec.rb')
-rw-r--r-- | spec/active_relation/unit/relations/order_spec.rb | 42 |
1 files changed, 36 insertions, 6 deletions
diff --git a/spec/active_relation/unit/relations/order_spec.rb b/spec/active_relation/unit/relations/order_spec.rb index 6a9ce07024..f37a9f26e9 100644 --- a/spec/active_relation/unit/relations/order_spec.rb +++ b/spec/active_relation/unit/relations/order_spec.rb @@ -22,12 +22,42 @@ module ActiveRelation end describe '#to_sql' do - it "manufactures sql with an order clause" do - Order.new(@relation, @attribute).to_sql.should be_like(" - SELECT `users`.`id`, `users`.`name` - FROM `users` - ORDER BY `users`.`id` - ") + describe "when given an attribute" do + it "manufactures sql with an order clause populated by the attribute" do + Order.new(@relation, @attribute).to_sql.should be_like(" + SELECT `users`.`id`, `users`.`name` + FROM `users` + ORDER BY `users`.`id` + ") + end + end + + describe "when given multiple attributes" do + before do + @another_attribute = @relation[:name] + end + + it "manufactures sql with an order clause populated by comma-separated attributes" do + Order.new(@relation, @attribute, @another_attribute).to_sql.should be_like(" + SELECT `users`.`id`, `users`.`name` + FROM `users` + ORDER BY `users`.`id`, `users`.`name` + ") + end + end + + describe "when given a string" do + before do + @string = "asdf".bind(@relation) + end + + it "passes the string through to the order clause" do + Order.new(@relation, @string).to_sql.should be_like(" + SELECT `users`.`id`, `users`.`name` + FROM `users` + ORDER BY asdf + ") + end end end end |