Skip to content

Commit 360f1f1

Browse files
authored
Merge pull request #47 from patterninc/GRO-15761_Incorrect-Sorting-for-Descending-Order
[GRO-15761] Added new attribute on class SqlSort which would keep nul…
2 parents 691b333 + e68a945 commit 360f1f1

File tree

4 files changed

+8
-7
lines changed

4 files changed

+8
-7
lines changed

.github/workflows/brakeman.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
bundler-cache: true
1818

1919
- name: Brakeman install
20-
run: gem install brakeman
20+
run: gem install brakeman -v 5.4.1
2121

2222
- name: brakeman
2323
id: brakeman

Gemfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
query_helper (0.3.5)
4+
query_helper (0.3.6)
55
activerecord (> 5)
66
activesupport (> 5)
77
sqlite3
@@ -89,7 +89,7 @@ GEM
8989
rspec-mocks (~> 3.10)
9090
rspec-support (~> 3.10)
9191
rspec-support (3.10.2)
92-
sqlite3 (1.6.2)
92+
sqlite3 (1.6.4)
9393
mini_portile2 (~> 2.8.0)
9494
thor (1.1.0)
9595
tzinfo (2.0.4)

lib/query_helper/sql_sort.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ class SqlSort
55

66
attr_accessor :column_maps, :select_strings, :sort_tiebreak, :column_sort_order
77

8-
def initialize(sort_string: "", sort_tiebreak: "", column_maps: [], column_sort_order: {})
8+
def initialize(sort_string: "", sort_tiebreak: "", column_maps: [], column_sort_order: {}, keep_nulls_last: false)
99
@sort_string = sort_string
1010
@column_maps = column_maps
1111
@sort_tiebreak = sort_tiebreak
1212
@column_sort_order = column_sort_order
1313
@select_strings = []
14+
@keep_nulls_last = keep_nulls_last
1415
end
1516

1617
def parse_sort_string
@@ -41,12 +42,12 @@ def attributes_sql_expression(sort_attribute)
4142
if direction == "desc"
4243
case ActiveRecord::Base.connection.adapter_name
4344
when "SQLite" # SQLite is used in the test suite
44-
direction = "desc"
45+
direction = @keep_nulls_last ? "desc nulls last" : "desc"
4546
else
4647
direction = "desc nulls last"
4748
end
4849
else
49-
direction = "asc"
50+
direction = @keep_nulls_last ? "asc nulls last" : "asc"
5051
end
5152

5253
case modifier

lib/query_helper/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
class QueryHelper
2-
VERSION = "0.3.5"
2+
VERSION = "0.3.6"
33
end

0 commit comments

Comments
 (0)