Skip to content

Commit c34f748

Browse files
committed
rubocop
1 parent 73b79c1 commit c34f748

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

.rubocop.yml

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Metrics/BlockLength:
2525
Max: 40
2626
Exclude:
2727
- spec/execute_queries_spec.rb
28+
- spec/model_select_distinct_spec.rb
2829
- spec/model_update_arel_10_spec.rb
2930
- spec/textual_order_raw_spec.rb
3031

lib/unreliable/build_order.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def build_order(arel)
1111

1212
adapter_name = Arel::Table.engine.connection.adapter_name
1313
return unless Unreliable::Config.enabled?
14-
return if is_distinct_on_postgres?(arel, adapter_name)
14+
return if distinct_on_postgres?(adapter_name)
1515
return if from_only_internal_metadata?(arel)
1616
return if from_one_table_with_ordered_pk?(arel)
1717

@@ -31,7 +31,7 @@ def build_order(arel)
3131
end
3232
end
3333

34-
def is_distinct_on_postgres?(arel, adapter_name)
34+
def distinct_on_postgres?(adapter_name)
3535
distinct_value && adapter_name == "PostgreSQL"
3636
end
3737

spec/model_select_distinct_spec.rb

+18-3
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,34 @@
33
RSpec.describe Cat do
44
it "randomly selects distinctly except on postgres" do
55
expect(Cat.distinct.all.to_sql).to end_with(
6-
UnreliableTest.find_adapter == "postgresql" ? ' FROM "cats"' : adapter_text("ORDER BY RANDOM()")
6+
case UnreliableTest.find_adapter
7+
when "postgresql"
8+
' FROM "cats"'
9+
else
10+
adapter_text("ORDER BY RANDOM()")
11+
end
712
)
813
end
914

1015
it "randomly selects distinctly from some" do
1116
expect(Cat.where(name: "foo").distinct.to_sql).to end_with(
12-
UnreliableTest.find_adapter == "postgresql" ? %q{ "cats"."name" = 'foo'} : adapter_text("ORDER BY RANDOM()")
17+
case UnreliableTest.find_adapter
18+
when "postgresql"
19+
%q( "cats"."name" = 'foo')
20+
else
21+
adapter_text("ORDER BY RANDOM()")
22+
end
1323
)
1424
end
1525

1626
it "adds randomness to existing distinct order" do
1727
expect(Cat.order(:name).distinct.to_sql).to end_with(
18-
UnreliableTest.find_adapter == "postgresql" ? ' ORDER BY "cats"."name" ASC' : adapter_text('ORDER BY "cats"."name" ASC, RANDOM()')
28+
case UnreliableTest.find_adapter
29+
when "postgresql"
30+
' ORDER BY "cats"."name" ASC'
31+
else
32+
adapter_text('ORDER BY "cats"."name" ASC, RANDOM()')
33+
end
1934
)
2035
end
2136

0 commit comments

Comments
 (0)