ajax-datatables-rails 1.3.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +15 -15
- data/bin/bundle +114 -0
- data/doc/migrate.md +1 -1
- data/lib/ajax-datatables-rails/base.rb +1 -1
- data/lib/ajax-datatables-rails/datatable/column/search.rb +7 -3
- data/lib/ajax-datatables-rails/datatable/datatable.rb +0 -1
- data/lib/ajax-datatables-rails/version.rb +1 -1
- data/spec/ajax-datatables-rails/base_spec.rb +39 -19
- data/spec/ajax-datatables-rails/datatable/column_spec.rb +30 -33
- data/spec/ajax-datatables-rails/datatable/datatable_spec.rb +11 -9
- data/spec/ajax-datatables-rails/datatable/simple_order_spec.rb +4 -2
- data/spec/ajax-datatables-rails/datatable/simple_search_spec.rb +4 -2
- data/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb +61 -94
- data/spec/ajax-datatables-rails/orm/active_record_paginate_records_spec.rb +4 -2
- data/spec/ajax-datatables-rails/orm/active_record_sort_records_spec.rb +5 -3
- data/spec/factories/user.rb +3 -1
- data/spec/spec_helper.rb +27 -11
- data/spec/support/datatables/complex_datatable.rb +2 -0
- data/spec/support/datatables/complex_datatable_array.rb +2 -0
- data/spec/support/datatables/datatable_cond_date.rb +2 -0
- data/spec/support/datatables/datatable_cond_numeric.rb +2 -0
- data/spec/support/datatables/datatable_cond_proc.rb +2 -0
- data/spec/support/datatables/datatable_cond_string.rb +4 -2
- data/spec/support/datatables/datatable_cond_unknown.rb +2 -0
- data/spec/support/datatables/datatable_order_nulls_last.rb +2 -0
- data/spec/support/helpers/params.rb +7 -5
- data/spec/support/models/user.rb +2 -0
- data/spec/support/schema.rb +3 -1
- metadata +4 -4
- data/spec/ajax-datatables-rails/orm/active_record_spec.rb +0 -24
@@ -1,11 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
|
-
describe AjaxDatatablesRails::ORM::ActiveRecord do
|
5
|
+
RSpec.describe AjaxDatatablesRails::ORM::ActiveRecord do
|
4
6
|
|
5
7
|
let(:datatable) { ComplexDatatable.new(sample_params) }
|
6
8
|
let(:records) { User.all }
|
7
9
|
|
8
|
-
before
|
10
|
+
before do
|
9
11
|
create(:user, username: 'johndoe', email: 'johndoe@example.com')
|
10
12
|
create(:user, username: 'msmith', email: 'mary.smith@example.com')
|
11
13
|
end
|
@@ -1,12 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
|
-
describe AjaxDatatablesRails::ORM::ActiveRecord do
|
5
|
+
RSpec.describe AjaxDatatablesRails::ORM::ActiveRecord do
|
4
6
|
|
5
7
|
let(:datatable) { ComplexDatatable.new(sample_params) }
|
6
8
|
let(:nulls_last_datatable) { DatatableOrderNullsLast.new(sample_params) }
|
7
9
|
let(:records) { User.all }
|
8
10
|
|
9
|
-
before
|
11
|
+
before do
|
10
12
|
create(:user, username: 'johndoe', email: 'johndoe@example.com')
|
11
13
|
create(:user, username: 'msmith', email: 'mary.smith@example.com')
|
12
14
|
end
|
@@ -30,7 +32,7 @@ describe AjaxDatatablesRails::ORM::ActiveRecord do
|
|
30
32
|
)
|
31
33
|
end
|
32
34
|
|
33
|
-
it '
|
35
|
+
it 'does not sort a column which is not orderable' do
|
34
36
|
datatable.params[:order]['0'] = { column: '0', dir: 'asc' }
|
35
37
|
datatable.params[:order]['1'] = { column: '4', dir: 'desc' }
|
36
38
|
|
data/spec/factories/user.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
FactoryBot.define do
|
2
4
|
factory :user do |f|
|
3
5
|
f.username { Faker::Internet.user_name }
|
4
6
|
f.email { Faker::Internet.email }
|
5
7
|
f.first_name { Faker::Name.first_name }
|
6
8
|
f.last_name { Faker::Name.last_name }
|
7
|
-
f.post_id { (
|
9
|
+
f.post_id { (1..100).to_a.sample }
|
8
10
|
end
|
9
11
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'simplecov'
|
2
4
|
require 'rspec'
|
3
5
|
require 'rspec/retry'
|
@@ -36,40 +38,54 @@ RSpec.configure do |config|
|
|
36
38
|
DatabaseCleaner.clean_with(:truncation)
|
37
39
|
end
|
38
40
|
|
39
|
-
config.before
|
41
|
+
config.before do
|
40
42
|
DatabaseCleaner.strategy = :transaction
|
41
43
|
end
|
42
44
|
|
43
|
-
config.before
|
45
|
+
config.before do
|
44
46
|
DatabaseCleaner.start
|
45
47
|
end
|
46
48
|
|
47
|
-
config.after
|
49
|
+
config.after do
|
48
50
|
DatabaseCleaner.clean
|
49
51
|
end
|
50
52
|
|
53
|
+
# disable monkey patching
|
54
|
+
# see: https://relishapp.com/rspec/rspec-core/v/3-8/docs/configuration/zero-monkey-patching-mode
|
55
|
+
config.disable_monkey_patching!
|
56
|
+
|
51
57
|
if ENV.key?('GITHUB_ACTIONS')
|
52
|
-
config.around
|
58
|
+
config.around do |ex|
|
53
59
|
ex.run_with_retry retry: 3
|
54
60
|
end
|
55
61
|
end
|
56
62
|
end
|
57
63
|
|
58
|
-
|
59
|
-
|
64
|
+
# Configure ActiveRecord
|
60
65
|
adapter = ENV.fetch('DB_ADAPTER', 'postgresql')
|
61
66
|
|
62
67
|
options = {
|
63
68
|
adapter: adapter,
|
64
69
|
database: 'ajax_datatables_rails',
|
65
|
-
encoding: 'utf8'
|
70
|
+
encoding: 'utf8',
|
66
71
|
}
|
67
72
|
|
68
|
-
options =
|
69
|
-
|
70
|
-
|
71
|
-
options
|
73
|
+
options =
|
74
|
+
case adapter
|
75
|
+
when 'postgresql'
|
76
|
+
options.merge(host: '127.0.0.1', port: 5432, username: 'postgres', password: 'postgres')
|
77
|
+
when 'mysql2'
|
78
|
+
options.merge(host: '127.0.0.1', port: 3306, username: 'root', password: 'root')
|
79
|
+
when 'oracle_enhanced'
|
80
|
+
options.merge(host: '127.0.0.1/xe', username: ENV['USER'], password: ENV['USER'], database: 'xe')
|
81
|
+
when 'sqlite3'
|
82
|
+
options.merge(database: ':memory:')
|
83
|
+
end
|
72
84
|
|
73
85
|
ActiveRecord::Base.establish_connection(options)
|
74
86
|
|
87
|
+
# Require our gem
|
88
|
+
require 'ajax-datatables-rails'
|
89
|
+
|
90
|
+
# Load test helpers
|
75
91
|
Dir[File.dirname(__FILE__) + '/support/**/*.rb'].sort.each { |f| require f }
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class DatatableCondStartWith < ComplexDatatable
|
2
4
|
def view_columns
|
3
5
|
super.deep_merge(first_name: { cond: :start_with })
|
@@ -24,7 +26,7 @@ end
|
|
24
26
|
|
25
27
|
class DatatableCondStringIn < ComplexDatatable
|
26
28
|
def view_columns
|
27
|
-
super.deep_merge(email: { cond: :string_in, formatter: ->
|
29
|
+
super.deep_merge(email: { cond: :string_in, formatter: ->(o) { o.split('|') } })
|
28
30
|
end
|
29
31
|
end
|
30
32
|
|
@@ -36,6 +38,6 @@ end
|
|
36
38
|
|
37
39
|
class DatatableWithFormater < ComplexDatatable
|
38
40
|
def view_columns
|
39
|
-
super.deep_merge(last_name: { formatter: ->
|
41
|
+
super.deep_merge(last_name: { formatter: ->(o) { o.upcase } })
|
40
42
|
end
|
41
43
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# rubocop:disable Metrics/MethodLength
|
2
4
|
def sample_params
|
3
5
|
ActionController::Parameters.new(
|
@@ -42,7 +44,7 @@ def sample_params
|
|
42
44
|
},
|
43
45
|
},
|
44
46
|
'order' => {
|
45
|
-
'0' => {'column' => '0', 'dir' => 'asc'}
|
47
|
+
'0' => { 'column' => '0', 'dir' => 'asc' },
|
46
48
|
},
|
47
49
|
'start' => '0', 'length' => '10', 'search' => {
|
48
50
|
'value' => '', 'regex' => 'false'
|
@@ -54,8 +56,8 @@ end
|
|
54
56
|
|
55
57
|
def sample_params_json
|
56
58
|
hash_params = sample_params.to_unsafe_h
|
57
|
-
hash_params[
|
58
|
-
hash_params[
|
59
|
+
hash_params['columns'] = hash_params['columns'].values
|
60
|
+
hash_params['order'] = hash_params['order'].values
|
59
61
|
ActionController::Parameters.new(hash_params)
|
60
62
|
end
|
61
63
|
# rubocop:enable Metrics/MethodLength
|
@@ -63,9 +65,9 @@ end
|
|
63
65
|
def nulls_last_sql(datatable)
|
64
66
|
case datatable.db_adapter
|
65
67
|
when :pg, :postgresql, :postgres, :oracle
|
66
|
-
|
68
|
+
'NULLS LAST'
|
67
69
|
when :mysql, :mysql2, :sqlite, :sqlite3
|
68
|
-
|
70
|
+
'IS NULL'
|
69
71
|
else
|
70
72
|
raise 'unsupported database adapter'
|
71
73
|
end
|
data/spec/support/models/user.rb
CHANGED
data/spec/support/schema.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ajax-datatables-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joel Quenneville
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-
|
12
|
+
date: 2021-02-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: zeitwerk
|
@@ -259,6 +259,7 @@ files:
|
|
259
259
|
- ajax-datatables-rails.gemspec
|
260
260
|
- bin/_guard-core
|
261
261
|
- bin/appraisal
|
262
|
+
- bin/bundle
|
262
263
|
- bin/guard
|
263
264
|
- bin/rake
|
264
265
|
- bin/rspec
|
@@ -293,7 +294,6 @@ files:
|
|
293
294
|
- spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb
|
294
295
|
- spec/ajax-datatables-rails/orm/active_record_paginate_records_spec.rb
|
295
296
|
- spec/ajax-datatables-rails/orm/active_record_sort_records_spec.rb
|
296
|
-
- spec/ajax-datatables-rails/orm/active_record_spec.rb
|
297
297
|
- spec/factories/user.rb
|
298
298
|
- spec/install_oracle.sh
|
299
299
|
- spec/spec_helper.rb
|
@@ -331,7 +331,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
331
331
|
- !ruby/object:Gem::Version
|
332
332
|
version: '0'
|
333
333
|
requirements: []
|
334
|
-
rubygems_version: 3.2.
|
334
|
+
rubygems_version: 3.2.7
|
335
335
|
signing_key:
|
336
336
|
specification_version: 4
|
337
337
|
summary: A gem that simplifies using datatables and hundreds of records via ajax
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe AjaxDatatablesRails::ORM::ActiveRecord do
|
4
|
-
context 'Private API' do
|
5
|
-
let(:datatable) { ComplexDatatable.new(sample_params) }
|
6
|
-
|
7
|
-
before(:each) do
|
8
|
-
create(:user, username: 'johndoe', email: 'johndoe@example.com')
|
9
|
-
create(:user, username: 'msmith', email: 'mary.smith@example.com')
|
10
|
-
end
|
11
|
-
|
12
|
-
describe '#fetch_records' do
|
13
|
-
it 'calls #get_raw_records' do
|
14
|
-
expect(datatable).to receive(:get_raw_records) { User.all }
|
15
|
-
datatable.fetch_records
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'returns a collection of records' do
|
19
|
-
expect(datatable).to receive(:get_raw_records) { User.all }
|
20
|
-
expect(datatable.fetch_records).to be_a(ActiveRecord::Relation)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|