Skip to content

Commit

Permalink
Add failing specs
Browse files Browse the repository at this point in the history
  • Loading branch information
tagliala committed May 2, 2022
1 parent 7683433 commit a09c48c
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions spec/support/shared_examples/querying_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 }
Expand Down

0 comments on commit a09c48c

Please sign in to comment.