From a09c48c1622c1d6f0e03ea825bd6ee41d4ba25ec Mon Sep 17 00:00:00 2001 From: Geremia Taglialatela Date: Mon, 2 May 2022 10:14:04 +0200 Subject: [PATCH] Add failing specs Ref: #565 --- .../shared_examples/querying_examples.rb | 36 +++++++++++++++---- 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/spec/support/shared_examples/querying_examples.rb b/spec/support/shared_examples/querying_examples.rb index a404af76a..e93951ea3 100644 --- a/spec/support/shared_examples/querying_examples.rb +++ b/spec/support/shared_examples/querying_examples.rb @@ -248,10 +248,10 @@ describe ".order" do let!(:i) do [ - model_class.create(a1 => "foo0"), - model_class.create(a1 => "foo2", a2 => "foo1"), - model_class.create(a1 => "foo1", a2 => "bar2"), - model_class.create(a1 => "foo3", a2 => "bar1") + model_class.create(a1 => "foo0", published: true), + model_class.create(a1 => "foo2", a2 => "foo1", published: true), + model_class.create(a1 => "foo1", a2 => "bar2", published: false), + model_class.create(a1 => "foo3", a2 => "bar1", published: true) ] end @@ -273,14 +273,38 @@ it "orders records correctly with 2-key hash argument" do skip "Not supported by #{backend}" if [:table, :key_value].include?(backend) - added = model_class.create(a1 => "foo2", a2 => "foo2") - expect(query_scope.order(a1 => :desc, a2 => :asc)).to eq([i[3], i[1], added, i[2], i[0]]) + added = [ + model_class.create(a1 => "foo2", a2 => "foo2"), + model_class.create(a1 => "foo3", a2 => "bar0") + ] + expect(query_scope.order(a1 => :desc, a2 => :asc)).to eq([added[1], i[3], i[1], added[0], i[2], i[0]]) + end + + it "orders records correctly with multiple arguments" do + skip "Not supported by #{backend}" if [:table, :key_value].include?(backend) + + added = model_class.create(a1 => "foo2", a2 => "foo0") + expect(query_scope.order(a1, a2)).to eq([i[0], i[2], added, i[1], i[3]]) + end + + it "orders records correctly with multiple hash arguments" do + skip "Not supported by #{backend}" if [:table, :key_value].include?(backend) + + added = [ + model_class.create(a1 => "foo2", a2 => "foo2"), + model_class.create(a1 => "foo3", a2 => "bar0") + ] + expect(query_scope.order({ a1 => :desc }, { a2 => :asc })).to eq([added[1], i[3], i[1], added[0], i[2], i[0]]) end it "handles untranslated attributes" do expect { query_scope.order(published: :desc) }.not_to raise_error end + it "handles mix of translated and untranslated attributes" do + expect(query_scope.order(published: :desc, a1 => :desc)).to eq([i[3], i[1], i[0], i[2]]) + end + it "does not modify original hash" do hash = { a1 => :asc } expect { query_scope.order(hash) }.not_to change { hash }