aboutsummaryrefslogtreecommitdiffstats
path: root/spec/shared/relation_spec.rb
diff options
context:
space:
mode:
authorErnie Miller <ernie@metautonomo.us>2010-05-21 11:45:12 -0400
committerErnie Miller <ernie@metautonomo.us>2010-05-21 11:45:12 -0400
commit43bfd3fae496a2a859aad0a654a91437357c3450 (patch)
treebd95f3b7add4ba7841a6fa9dd717de9c60ea90a8 /spec/shared/relation_spec.rb
parentd144b8d5af11c819b8f70a97006998bf89ee926c (diff)
downloadrails-43bfd3fae496a2a859aad0a654a91437357c3450.tar.gz
rails-43bfd3fae496a2a859aad0a654a91437357c3450.tar.bz2
rails-43bfd3fae496a2a859aad0a654a91437357c3450.zip
Fix tests to work properly on Ruby 1.9, honor multiple calls to #order in memory engine, and make having clauses behave like where clauses in SQL engine (join with AND, allow multiple calls to having to add predicates)
Diffstat (limited to 'spec/shared/relation_spec.rb')
-rw-r--r--spec/shared/relation_spec.rb43
1 files changed, 37 insertions, 6 deletions
diff --git a/spec/shared/relation_spec.rb b/spec/shared/relation_spec.rb
index e0c74fc7ee..b49e79f13d 100644
--- a/spec/shared/relation_spec.rb
+++ b/spec/shared/relation_spec.rb
@@ -154,25 +154,56 @@ share_examples_for 'A Relation' do
describe "#order" do
describe "by one attribute" do
before :all do
- @expected.map! { |r| r[@relation[:age]] }
- @expected.sort!
+ @expected.sort! { |a, b| a[@relation[:age]] <=> b[@relation[:age]]}.map! {|e| e[@relation[:id]]}
end
it "can be specified as ascending order" do
actual = []
- @relation.order(@relation[:age].asc).each { |r| actual << r[@relation[:age]] }
+ @relation.order(@relation[:age].asc).each { |r| actual << r[@relation[:id]] }
actual.should == @expected
end
it "can be specified as descending order" do
actual = []
- @relation.order(@relation[:age].desc).each { |r| actual << r[@relation[:age]] }
+ @relation.order(@relation[:age].desc).each { |r| actual << r[@relation[:id]] }
actual.should == @expected.reverse
end
end
- describe "by two attributes" do
- it "works"
+ describe "by two attributes in two separate calls to #order" do
+ before :all do
+ @expected = @expected.sort_by { |e| [e[@relation[:name]], e[@relation[:age]]]}.map {|e| e[@relation[:id]]}
+ end
+
+ it "can be specified as ascending order" do
+ actual = []
+ @relation.order(@relation[:age].asc).order(@relation[:name].asc).each { |r| actual << r[@relation[:id]] }
+ actual.should == @expected
+ end
+
+ it "can be specified as descending order" do
+ actual = []
+ @relation.order(@relation[:age].desc).order(@relation[:name].desc).each { |r| actual << r[@relation[:id]] }
+ actual.should == @expected.reverse
+ end
+ end
+
+ describe "by two attributes in one call to #order" do
+ before :all do
+ @expected = @expected.sort_by { |e| [e[@relation[:name]], e[@relation[:age]]]}.map {|e| e[@relation[:id]]}
+ end
+
+ it "can be specified as ascending order in one call to #order" do
+ actual = []
+ @relation.order(@relation[:name].asc, @relation[:age].asc).each { |r| actual << r[@relation[:id]] }
+ actual.should == @expected
+ end
+
+ it "can be specified as descending order in one call to #order" do
+ actual = []
+ @relation.order(@relation[:name].desc, @relation[:age].desc).each { |r| actual << r[@relation[:id]] }
+ actual.should == @expected.reverse
+ end
end
end