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.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -0
  3. data/README.md +15 -15
  4. data/bin/bundle +114 -0
  5. data/doc/migrate.md +1 -1
  6. data/lib/ajax-datatables-rails/base.rb +1 -1
  7. data/lib/ajax-datatables-rails/datatable/column/search.rb +7 -3
  8. data/lib/ajax-datatables-rails/datatable/datatable.rb +0 -1
  9. data/lib/ajax-datatables-rails/version.rb +1 -1
  10. data/spec/ajax-datatables-rails/base_spec.rb +39 -19
  11. data/spec/ajax-datatables-rails/datatable/column_spec.rb +30 -33
  12. data/spec/ajax-datatables-rails/datatable/datatable_spec.rb +11 -9
  13. data/spec/ajax-datatables-rails/datatable/simple_order_spec.rb +4 -2
  14. data/spec/ajax-datatables-rails/datatable/simple_search_spec.rb +4 -2
  15. data/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb +61 -94
  16. data/spec/ajax-datatables-rails/orm/active_record_paginate_records_spec.rb +4 -2
  17. data/spec/ajax-datatables-rails/orm/active_record_sort_records_spec.rb +5 -3
  18. data/spec/factories/user.rb +3 -1
  19. data/spec/spec_helper.rb +27 -11
  20. data/spec/support/datatables/complex_datatable.rb +2 -0
  21. data/spec/support/datatables/complex_datatable_array.rb +2 -0
  22. data/spec/support/datatables/datatable_cond_date.rb +2 -0
  23. data/spec/support/datatables/datatable_cond_numeric.rb +2 -0
  24. data/spec/support/datatables/datatable_cond_proc.rb +2 -0
  25. data/spec/support/datatables/datatable_cond_string.rb +4 -2
  26. data/spec/support/datatables/datatable_cond_unknown.rb +2 -0
  27. data/spec/support/datatables/datatable_order_nulls_last.rb +2 -0
  28. data/spec/support/helpers/params.rb +7 -5
  29. data/spec/support/models/user.rb +2 -0
  30. data/spec/support/schema.rb +3 -1
  31. metadata +4 -4
  32. 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(:each) do
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(:each) do
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 'should not sort a column which is not orderable' do
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
 
@@ -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 { ((1..100).to_a).sample }
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(:each) do
41
+ config.before do
40
42
  DatabaseCleaner.strategy = :transaction
41
43
  end
42
44
 
43
- config.before(:each) do
45
+ config.before do
44
46
  DatabaseCleaner.start
45
47
  end
46
48
 
47
- config.after(:each) do
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(:each) do |ex|
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
- require 'ajax-datatables-rails'
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 = options.merge(host: '127.0.0.1', port: 5432, username: 'postgres', password: 'postgres') if adapter == 'postgresql'
69
- options = options.merge(host: '127.0.0.1', port: 3306, username: 'root', password: 'root') if adapter == 'mysql2'
70
- options = options.merge(username: ENV['USER'], password: ENV['USER'], database: 'xe', host: '127.0.0.1/xe') if adapter == 'oracle_enhanced'
71
- options = options.merge(database: ':memory:') if adapter == 'sqlite3'
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 ComplexDatatable < AjaxDatatablesRails::ActiveRecord
2
4
  def view_columns
3
5
  @view_columns ||= {
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ComplexDatatableArray < ComplexDatatable
2
4
  def data
3
5
  records.map do |record|
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class DatatableCondDate < ComplexDatatable
2
4
  def view_columns
3
5
  super.deep_merge(created_at: { cond: :date_range })
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class DatatableCondEq < ComplexDatatable
2
4
  def view_columns
3
5
  super.deep_merge(post_id: { cond: :eq })
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class DatatableCondProc < ComplexDatatable
2
4
  def view_columns
3
5
  super.deep_merge(username: { cond: custom_filter })
@@ -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: -> (o) { o.split("|") } })
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: -> (o) { o.upcase } })
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
  class DatatableCondUnknown < ComplexDatatable
2
4
  def view_columns
3
5
  super.deep_merge(username: { cond: :foo })
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class DatatableOrderNullsLast < ComplexDatatable
2
4
  def view_columns
3
5
  super.deep_merge(email: { nulls_last: true })
@@ -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["columns"] = hash_params["columns"].values
58
- hash_params["order"] = hash_params["order"].values
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
- "NULLS LAST"
68
+ 'NULLS LAST'
67
69
  when :mysql, :mysql2, :sqlite, :sqlite3
68
- "IS NULL"
70
+ 'IS NULL'
69
71
  else
70
72
  raise 'unsupported database adapter'
71
73
  end
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class User < ActiveRecord::Base
2
4
  end
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  ActiveRecord::Schema.define do
2
4
  self.verbose = false
3
5
 
4
- create_table :users, :force => true do |t|
6
+ create_table :users, force: true do |t|
5
7
  t.string :username
6
8
  t.string :email
7
9
  t.string :first_name
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.0
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-01-04 00:00:00.000000000 Z
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.3
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