sort_n_params 1.2.3 → 1.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5546d17da19b3cfb15a26cb4cd14fc684545af3f743ea175d28947b0511f9758
4
- data.tar.gz: 449f77325f1afb0e71ba03276bb07d095e9d00348882d50c69788e4c4902685d
3
+ metadata.gz: 0d4ac056564f23114d90e35df4b967adb86fa41078a7ea283b0194bc4185770e
4
+ data.tar.gz: 3d5ef6cb54e2332663f866fb64b4f4129ce71dcb759e7a07d81591f4305d9947
5
5
  SHA512:
6
- metadata.gz: 350e519cb57c72ba5b7541f8802bba8436a57905b8adb2c293c09d1892c50e23c646a5280f1469a0c5b56e34929bc9c745d5c08a348224c95ff588d526691afc
7
- data.tar.gz: 0a314e2fcdc8998dfe14fa42ceead8114474f5dccf101112bc7243d265ba56d3f22dd2f8b6e6f00d0111fa90b8d3281e3eeb8e6dd7d653abec71f9976d596ea3
6
+ metadata.gz: d3958ff1ccc8458fa980a3372f362663be02b5a812641fc55f2e3c8fcc290038c152045538236290f2fb530bb4fd510c9af45e8c6a35c50c4fb14c4bc3fd1172
7
+ data.tar.gz: 0f17254708d77572faa51439bafebac85d8b7276a7b060b78bc1e917b9d7a06095edc534983be0508dada603b432dd4e9eb2cde400235ada34cad226d47c19f9
@@ -9,7 +9,7 @@ module SortNParams
9
9
  def sorting_order(ordering_array, table_name = nil)
10
10
  return all if ordering_array.blank?
11
11
 
12
- all.order(parse_array(ordering_array, table_name))
12
+ all.order(sanitize_sql_for_order(parse_array(ordering_array, table_name)))
13
13
  end
14
14
 
15
15
  def parse_array(ordering_array, table_name = nil)
@@ -2,8 +2,8 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'sort_n_params'
5
- s.version = '1.2.3'
6
- s.date = '2022-06-22'
5
+ s.version = '1.2.4'
6
+ s.date = '2022-06-23'
7
7
  s.summary = 'Sort N Params'
8
8
  s.description = 'Make your html <tables> sortables with N <th> parameters this gem.'
9
9
  s.authors = ['Juan Francisco Ferrari']
@@ -35,6 +35,7 @@ Gem::Specification.new do |s|
35
35
  s.add_development_dependency 'rspec', '~> 3.0'
36
36
  s.add_development_dependency 'rubocop', '~> 1.30'
37
37
  s.add_development_dependency 'rubocop-rails'
38
+ s.add_development_dependency 'sqlite3'
38
39
 
39
40
  s.add_dependency('nokogiri', ['>= 0'])
40
41
  s.add_dependency('rails', ['>= 7.0'])
@@ -1,16 +1,48 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'sort_n_params/concerns/scopes'
4
+ require 'active_record'
4
5
 
5
- CustomTable = Struct.new(:custom_field) do
6
+ class CustomTable < ActiveRecord::Base
6
7
  include SortNParams::Scopes
7
8
  end
8
9
 
9
10
  RSpec.describe SortNParams::Scopes do
11
+ before(:all) { create_tables }
12
+ after(:all) { drop_tables }
13
+
14
+ def create_tables
15
+ ActiveRecord::Base.connection.create_table :custom_tables do |t|
16
+ t.text :test_field
17
+ end
18
+ end
19
+
20
+ def drop_tables
21
+ ActiveRecord::Base.connection.drop_table :custom_tables
22
+ end
23
+
10
24
  let(:test_class) do
11
25
  CustomTable
12
26
  end
13
27
 
28
+ describe '#sorting_order' do
29
+ context 'when you pass only the sorting field with direction asc' do
30
+ subject { test_class.sorting_order(%w[test_field asc]) }
31
+
32
+ it 'builds an order with that field and direction' do
33
+ expect(subject.explain).to include('ORDER BY custom_tables.test_field asc')
34
+ end
35
+ end
36
+
37
+ context 'when you pass only the sorting field direction desc' do
38
+ subject { test_class.sorting_order(%w[test_field desc]) }
39
+
40
+ it 'builds an order with that field and direction' do
41
+ expect(subject.explain).to include('ORDER BY custom_tables.test_field desc')
42
+ end
43
+ end
44
+ end
45
+
14
46
  describe '#parse_array' do
15
47
  context 'when you pass only an ordering array' do
16
48
  subject { test_class.parse_array(%w[test_field asc]) }
data/spec/spec_helper.rb CHANGED
@@ -2,8 +2,15 @@
2
2
 
3
3
  require 'factory_bot'
4
4
  require 'sort_n_params/sortable'
5
+ require 'active_record'
6
+ require 'sqlite3'
5
7
 
6
8
  RSpec.configure do |config|
7
9
  config.include FactoryBot::Syntax::Methods
8
10
  FactoryBot.find_definitions
11
+
12
+ ActiveRecord::Base.establish_connection(
13
+ adapter: 'sqlite3',
14
+ database: ':memory:'
15
+ )
9
16
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sort_n_params
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.3
4
+ version: 1.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Francisco Ferrari
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-22 00:00:00.000000000 Z
11
+ date: 2022-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: sqlite3
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: nokogiri
127
141
  requirement: !ruby/object:Gem::Requirement