sort_n_params 1.0.3 → 1.0.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: f8d7d660d21516f59a4a914359a26d53a20fdc3699793e0928957546baee823e
4
- data.tar.gz: 928b68de9c0da24d7d454f445dbfe2b2cdfcd1a55762b9fd226edf86a85ec25f
3
+ metadata.gz: 1699472fa73140a298c054ba1cf30a75c1f08a38cfa991d2b0d738bed8b707a0
4
+ data.tar.gz: fa259494066c8118ce818a88169b771631550bd8b20dbf39c3966230abc24c54
5
5
  SHA512:
6
- metadata.gz: '093b2206de1545750e2da682723fb6c725d6ca907156ccd7068edd827d87923f46ca100887d7a9f8d1f47923c1230214db6aca59a312a8da949291810637861a'
7
- data.tar.gz: 431f0adadd6e5fc19f105afa7eac5a2ed3ea7d0471363473af5ba896e2b6c35f3d3ea4b2963cdb9f72955312c36cc8df1cfe59a01437ab005db6737f2e66ff32
6
+ metadata.gz: 4b7d0e7c550936f4f85a2312935b138490dcce4f252240465b28eac3e4c7268fa87a089607824af3165934abdb1a8e59fdb2f5412e8684c45e6b8980fc666814
7
+ data.tar.gz: 8f406482183c6f110e9eb13a30a0fbbfe85052c5c235b4e0d3366d879632de367c561b06b984184cef0ca01f737aa81a1f2288d2506663beb477d5e061b69eee
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.6.1
4
+ before_install:
5
+ - gem update --system
6
+ - gem install bundler
7
+ script:
8
+ - bundle install
9
+ - bundle exec rake spec
File without changes
@@ -4,15 +4,17 @@ module SortNParams
4
4
  module Scopes
5
5
  extend ActiveSupport::Concern
6
6
  class_methods do
7
- def sorting_order(ordering_array)
7
+ def sorting_order(ordering_array, table_name = nil)
8
8
  return all if ordering_array.blank?
9
9
 
10
- all.order(parse_array(ordering_array))
10
+ all.order(parse_array(ordering_array, table_name))
11
11
  end
12
12
 
13
- def parse_array(ordering_array)
13
+ def parse_array(ordering_array, table_name = nil)
14
+ table = table_name || name.tableize
15
+
14
16
  ordering_array.each_slice(2).map do |order, direction|
15
- "#{name.tableize}.#{order} #{direction}"
17
+ "#{table}.#{order} #{direction}"
16
18
  end.join(', ')
17
19
  end
18
20
  end
@@ -9,7 +9,7 @@ class Sortable
9
9
  end
10
10
 
11
11
  def call
12
- add_previous_order if @params[:order].present?
12
+ add_previous_order unless @params[:order].nil?
13
13
  @sort_params[:order].include?(@column) ? revert_order : add_order
14
14
  build_data
15
15
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'sort_n_params'
3
- s.version = '1.0.3'
3
+ s.version = '1.0.4'
4
4
  s.date = '2019-05-07'
5
5
  s.summary = "Sort N Params"
6
6
  s.description = "Make your html <tables> sortables with N <th> parameters this gem."
@@ -8,14 +8,16 @@ Gem::Specification.new do |s|
8
8
  s.email = 'juannferrari@gmail.com'
9
9
  s.require_paths = ["lib"]
10
10
  s.files = [
11
+ ".travis.yml",
11
12
  "Gemfile",
12
- "MIT-LICENSE",
13
+ "LICENSE",
13
14
  "Rakefile",
14
15
  "sort_n_params.gemspec",
15
16
  "lib/sort_n_params.rb",
16
17
  "lib/sort_n_params/sortable.rb",
17
18
  "lib/sort_n_params/sort_helpers.rb",
18
19
  "lib/sort_n_params/concerns/scopes.rb",
20
+ "spec/concerns/scopes_spec.rb",
19
21
  "spec/spec_helper.rb",
20
22
  "spec/sortable_spec.rb"
21
23
  ]
@@ -27,10 +29,10 @@ Gem::Specification.new do |s|
27
29
  s.add_development_dependency "bundler"
28
30
  s.add_development_dependency "factory_bot", "~> 4.0"
29
31
  s.add_development_dependency "pry-byebug"
30
- s.add_development_dependency "rake", "~> 10.0"
32
+ s.add_development_dependency "rake", ">= 12.3.3"
31
33
  s.add_development_dependency "rspec", "~> 3.0"
32
34
 
33
35
  s.add_dependency(%q<rails>.freeze, ["~> 5.0"])
34
36
  s.add_dependency(%q<nokogiri>.freeze, [">= 0"])
35
- s.add_dependency(%q<rake>.freeze, ["~> 10.1"])
37
+ s.add_dependency(%q<rake>.freeze, [">= 12.3.3"])
36
38
  end
@@ -0,0 +1,25 @@
1
+ require 'sort_n_params/concerns/scopes'
2
+
3
+ RSpec.describe SortNParams::Scopes do
4
+ let(:test_class) do
5
+ CustomTable = Struct.new(:custom_field) do
6
+ include SortNParams::Scopes
7
+ end
8
+ end
9
+
10
+ context 'when you pass only an ordering array' do
11
+ subject { test_class.parse_array(["test_field","asc"]) }
12
+
13
+ it "builds the array correctly without the table_name param passed" do
14
+ expect(subject).to eq("custom_tables.test_field asc")
15
+ end
16
+ end
17
+
18
+ context 'when you pass both ordering array and table name' do
19
+ subject { test_class.parse_array(["test_field","asc"], "another_table_name" ) }
20
+
21
+ it "builds the array correctly with the table_name param passed" do
22
+ expect(subject).to eq("another_table_name.test_field asc")
23
+ end
24
+ end
25
+ end
@@ -1,4 +1,5 @@
1
1
  require 'factory_bot'
2
+ require 'sort_n_params/sortable'
2
3
 
3
4
  RSpec.configure do |config|
4
5
  config.include FactoryBot::Syntax::Methods
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sort_n_params
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Francisco Ferrari
@@ -56,16 +56,16 @@ dependencies:
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '10.0'
61
+ version: 12.3.3
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '10.0'
68
+ version: 12.3.3
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -112,30 +112,32 @@ dependencies:
112
112
  name: rake
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - "~>"
115
+ - - ">="
116
116
  - !ruby/object:Gem::Version
117
- version: '10.1'
117
+ version: 12.3.3
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - "~>"
122
+ - - ">="
123
123
  - !ruby/object:Gem::Version
124
- version: '10.1'
124
+ version: 12.3.3
125
125
  description: Make your html <tables> sortables with N <th> parameters this gem.
126
126
  email: juannferrari@gmail.com
127
127
  executables: []
128
128
  extensions: []
129
129
  extra_rdoc_files: []
130
130
  files:
131
+ - ".travis.yml"
131
132
  - Gemfile
132
- - MIT-LICENSE
133
+ - LICENSE
133
134
  - Rakefile
134
135
  - lib/sort_n_params.rb
135
136
  - lib/sort_n_params/concerns/scopes.rb
136
137
  - lib/sort_n_params/sort_helpers.rb
137
138
  - lib/sort_n_params/sortable.rb
138
139
  - sort_n_params.gemspec
140
+ - spec/concerns/scopes_spec.rb
139
141
  - spec/sortable_spec.rb
140
142
  - spec/spec_helper.rb
141
143
  homepage: https://github.com/JuannFerrari/sort_n_params
@@ -157,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
157
159
  - !ruby/object:Gem::Version
158
160
  version: '0'
159
161
  requirements: []
160
- rubygems_version: 3.0.1
162
+ rubygems_version: 3.0.3
161
163
  signing_key:
162
164
  specification_version: 4
163
165
  summary: Sort N Params