File tree 3 files changed +21
-5
lines changed
3 files changed +21
-5
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ Metrics/BlockLength:
25
25
Max : 40
26
26
Exclude :
27
27
- spec/execute_queries_spec.rb
28
+ - spec/model_select_distinct_spec.rb
28
29
- spec/model_update_arel_10_spec.rb
29
30
- spec/textual_order_raw_spec.rb
30
31
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ def build_order(arel)
11
11
12
12
adapter_name = Arel ::Table . engine . connection . adapter_name
13
13
return unless Unreliable ::Config . enabled?
14
- return if is_distinct_on_postgres? ( arel , adapter_name )
14
+ return if distinct_on_postgres? ( adapter_name )
15
15
return if from_only_internal_metadata? ( arel )
16
16
return if from_one_table_with_ordered_pk? ( arel )
17
17
@@ -31,7 +31,7 @@ def build_order(arel)
31
31
end
32
32
end
33
33
34
- def is_distinct_on_postgres? ( arel , adapter_name )
34
+ def distinct_on_postgres? ( adapter_name )
35
35
distinct_value && adapter_name == "PostgreSQL"
36
36
end
37
37
Original file line number Diff line number Diff line change 3
3
RSpec . describe Cat do
4
4
it "randomly selects distinctly except on postgres" do
5
5
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
7
12
)
8
13
end
9
14
10
15
it "randomly selects distinctly from some" do
11
16
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
13
23
)
14
24
end
15
25
16
26
it "adds randomness to existing distinct order" do
17
27
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
19
34
)
20
35
end
21
36
You can’t perform that action at this time.
0 commit comments