data_tables-responder 0.4.3 → 0.4.4rc1

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: 6d6521ba0906582dd0c35d5a654f516ab46c1e906e7b55268c6b33b2cc3c0a0e
4
- data.tar.gz: 58fb522483dc1af6bac2b7204326b17ebacecef2b94f5ebaa07be02ea6da4815
3
+ metadata.gz: 5faa27861eee2591709eae8eb5eb1b6e24a4e35b56bc6f03fa6edb5d53584094
4
+ data.tar.gz: 59dd8eec6c905047b663cc511cf704e9f2501b0d30ae9a3ae825de21594ba088
5
5
  SHA512:
6
- metadata.gz: f1d283ac5f9e594b3fe56656d1b27f30f8cc3f3414fde80c6c19ee7cfb59ef8e40e0246d8c3e6bfa5c9c47f5d64eff337f7e6fe1d113a3f5b510eb92ea52c4de
7
- data.tar.gz: 4210d07b780dfa981d6d5d532ade9eaa174f73bcbdcb8f41c65d8909d230589492ad969b699d88a137dab4b11a01e11a782068badd28cfc565a7ac83c2d71fe5
6
+ metadata.gz: 1fbb2fd0cda0f0870d40371275f9483ab6601296b63ccc21cb92d19974f250af9d81a89471b27d74e3bac17862759c66fd1d0314d80e5512751afd12f5349343
7
+ data.tar.gz: 0f09e4c09b931f285c05333dc9f77528b935d32edbd012794a2c6b514645c2f04e3134843490cc49e6de69f3cd3a5c1e0a394481aa4e7f5a69bf030e4d6f72f1
data/.travis.yml CHANGED
@@ -22,21 +22,18 @@ addons:
22
22
  postgresql: 9.4
23
23
 
24
24
  rvm:
25
+ - 2.6
25
26
  - 2.5
26
27
  - 2.4
27
- - 2.3
28
28
 
29
29
  gemfile:
30
- - gemfiles/activerecord-5.1.Gemfile
31
- - gemfiles/activerecord-5.0.Gemfile
32
30
  - gemfiles/activerecord-4.2.Gemfile
33
- - gemfiles/activerecord-4.1.Gemfile
31
+ - gemfiles/activerecord-5.0.Gemfile
32
+ - gemfiles/activerecord-5.1.Gemfile
33
+ - gemfiles/activerecord-5.2.Gemfile
34
34
 
35
35
  matrix:
36
36
  exclude:
37
37
 
38
- - rvm: 2.4
39
- gemfile: gemfiles/activerecord-4.1.Gemfile
40
-
41
- - rvm: 2.5
42
- gemfile: gemfiles/activerecord-4.1.Gemfile
38
+ - rvm: 2.6
39
+ gemfile: gemfiles/activerecord-4.2.Gemfile
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2016 Dale Stevens
3
+ Copyright (c) 2019 Dale Stevens
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -36,10 +36,10 @@ Gem::Specification.new do |spec|
36
36
  spec.add_runtime_dependency 'railties', rails_versions
37
37
 
38
38
  spec.add_development_dependency 'activerecord', rails_versions
39
- spec.add_development_dependency 'pg', '~> 0'
40
- spec.add_development_dependency 'pry-byebug', '~> 3'
41
- spec.add_development_dependency 'bundler', '~> 1.3'
42
- spec.add_development_dependency 'rake', '~> 12.0'
39
+ spec.add_development_dependency 'pg'
40
+ spec.add_development_dependency 'pry-byebug'
41
+ spec.add_development_dependency 'bundler'
42
+ spec.add_development_dependency 'rake'
43
43
  spec.add_development_dependency 'combustion', '~> 0.7'
44
44
 
45
45
  end
@@ -0,0 +1,3 @@
1
+ eval_gemfile File.join(File.dirname(__FILE__), "../Gemfile")
2
+
3
+ gem 'activerecord', '~> 5.2.0'
@@ -49,12 +49,19 @@ module DataTables
49
49
 
50
50
  def search_by_type(model, column, query, &block)
51
51
  arel_column = model.arel_table[column]
52
- result = case model.columns_hash[column.to_s]&.type
52
+ column_type = model.columns_hash[column.to_s]&.type
53
+
54
+ result = case column_type
53
55
  when :string
56
+ query = Array.wrap(query)
54
57
  # I'm pretty sure this is safe from SQL Injection
55
- arel_column.matches("%#{query}%")
58
+ arel_column.matches_any(query.map { |q| "%#{q}%" })
56
59
  when :integer
57
- value = query&.to_i and arel_column.eq(value)
60
+ query = Array.wrap(query)
61
+ arel_column.eq_any(query.map(&:to_i))
62
+ when :float
63
+ query = Array.wrap(query)
64
+ arel_column.eq_any(query.map(&:to_f))
58
65
  when :datetime
59
66
  datetime = Time.parse(query)
60
67
  range = (datetime-1.second)..(datetime+1.second)
@@ -1,5 +1,5 @@
1
1
  module DataTables
2
2
  module Responder
3
- VERSION = '0.4.3'
3
+ VERSION = '0.4.4rc1'
4
4
  end
5
5
  end
@@ -208,7 +208,7 @@ describe DataTables::Responder do
208
208
  expect(response_sql).to include('"comments".* FROM "comments"')
209
209
  expect(response_sql).to include('INNER JOIN "posts" ON "posts"."id" = "comments"."post_id"')
210
210
  expect(response_sql).to include('JOIN "users" ON "users"."id" = "posts"."user_id"')
211
- expect(response_sql).to include('WHERE ("users"."email" ILIKE \'%foo@bar.baz%\')')
211
+ expect(response_sql).to include('"users"."email" ILIKE \'%foo@bar.baz%\'')
212
212
  expect(response_sql).to include('ORDER BY "users"."email" ASC')
213
213
  expect(response_sql).to include('LIMIT 10 OFFSET 0')
214
214
  end
@@ -244,7 +244,7 @@ describe DataTables::Responder do
244
244
  response_sql = response.to_sql
245
245
 
246
246
  expect(response.count).to eq(1)
247
- expect(response_sql).to include('WHERE ("posts"."title" ILIKE \'%foo%\')')
247
+ expect(response_sql).to include('"posts"."title" ILIKE \'%foo%\'')
248
248
  expect(response_sql).to include('ORDER BY "posts"."title" ASC')
249
249
  expect(response_sql).to include('LIMIT 10 OFFSET 0')
250
250
  end
@@ -25,6 +25,13 @@ describe DataTables::Modules::Search do
25
25
  "searchable": true,
26
26
  "orderable": true,
27
27
  "search": { "value": "", "regex": false }
28
+ },
29
+ {
30
+ "data": "engagement_rate",
31
+ "name": "",
32
+ "searchable": true,
33
+ "orderable": true,
34
+ "search": { "value": "", "regex": false }
28
35
  }
29
36
  ],
30
37
  "draw": 3,
@@ -43,8 +50,9 @@ describe DataTables::Modules::Search do
43
50
  before(:each) do
44
51
  User.create(email: 'foo@bar.com')
45
52
  User.create(email: 'foo2@bar.com')
46
- Post.create(title: 'foo', views: 4)
47
- Post.create(title: 'bar', views: 3)
53
+ Post.create(title: 'foo', views: 4, engagement_rate: 0.5)
54
+ Post.create(title: 'bar', views: 3, engagement_rate: 1.0)
55
+ Post.create(title: 'baz', views: 2, engagement_rate: 2.0)
48
56
  end
49
57
 
50
58
  it 'integers' do
@@ -58,12 +66,57 @@ describe DataTables::Modules::Search do
58
66
 
59
67
  posts = dt_module.search
60
68
 
61
- # expect{dt_module.search}.to_not raise_error()
62
69
  expect(posts.count).to eq(1)
63
70
  expect(posts[0].views).to eq(4)
64
71
 
65
72
  end
66
73
 
74
+ it 'integers for any of many values' do
75
+
76
+ complex_params[:columns][2][:search] = {
77
+ "value": ["4", "3", "1"],
78
+ "regex": false
79
+ }
80
+
81
+ dt_module = DataTables::Modules::Search.new(Post, Post.all, complex_params)
82
+
83
+ posts = dt_module.search
84
+
85
+ expect(posts.count).to eq(2)
86
+
87
+ end
88
+
89
+ it 'floats' do
90
+
91
+ complex_params[:columns][3][:search] = {
92
+ "value": ".5",
93
+ "regex": false
94
+ }
95
+
96
+ dt_module = DataTables::Modules::Search.new(Post, Post.all, complex_params)
97
+
98
+ posts = dt_module.search
99
+
100
+ expect(posts.count).to eq(1)
101
+ expect(posts[0].views).to eq(4)
102
+
103
+ end
104
+
105
+ it 'floats for any of many values' do
106
+
107
+ complex_params[:columns][3][:search] = {
108
+ "value": ["1", ".5", "1.5"],
109
+ "regex": false
110
+ }
111
+
112
+ dt_module = DataTables::Modules::Search.new(Post, Post.all, complex_params)
113
+
114
+ posts = dt_module.search
115
+
116
+ expect(posts.count).to eq(2)
117
+
118
+ end
119
+
67
120
  it 'strings' do
68
121
 
69
122
  complex_params[:columns][1][:search] = {
@@ -75,12 +128,26 @@ describe DataTables::Modules::Search do
75
128
 
76
129
  posts = dt_module.search
77
130
 
78
- # expect{dt_module.search}.to_not raise_error()
79
131
  expect(posts.count).to eq(1)
80
132
  expect(posts[0].title).to eq('foo')
81
133
 
82
134
  end
83
135
 
136
+ it 'strings for any of many values' do
137
+
138
+ complex_params[:columns][1][:search] = {
139
+ "value": ["foo", "bar"],
140
+ "regex": false
141
+ }
142
+
143
+ dt_module = DataTables::Modules::Search.new(Post, Post.all, complex_params)
144
+
145
+ posts = dt_module.search
146
+
147
+ expect(posts.count).to eq(2)
148
+
149
+ end
150
+
84
151
  it 'uuids' do
85
152
 
86
153
  complex_params[:columns][0][:search] = {
@@ -92,7 +159,6 @@ describe DataTables::Modules::Search do
92
159
 
93
160
  users = dt_module.search
94
161
 
95
- # expect{dt_module.search}.to_not raise_error()
96
162
  expect(users.count).to eq(1)
97
163
  expect(users[0].email).to eq('foo@bar.com')
98
164
 
@@ -12,7 +12,8 @@ ActiveRecord::Schema.define do
12
12
  create_table :posts, :force => true do |t|
13
13
  t.uuid :user_id
14
14
  t.string :title
15
- t.integer :views # for testing integers
15
+ t.integer :views
16
+ t.float :engagement_rate
16
17
  t.timestamps
17
18
  end
18
19
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: data_tables-responder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.4rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dale Stevens
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-29 00:00:00.000000000 Z
11
+ date: 2019-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers
@@ -82,58 +82,58 @@ dependencies:
82
82
  name: pg
83
83
  requirement: !ruby/object:Gem::Requirement
84
84
  requirements:
85
- - - "~>"
85
+ - - ">="
86
86
  - !ruby/object:Gem::Version
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
90
  version_requirements: !ruby/object:Gem::Requirement
91
91
  requirements:
92
- - - "~>"
92
+ - - ">="
93
93
  - !ruby/object:Gem::Version
94
94
  version: '0'
95
95
  - !ruby/object:Gem::Dependency
96
96
  name: pry-byebug
97
97
  requirement: !ruby/object:Gem::Requirement
98
98
  requirements:
99
- - - "~>"
99
+ - - ">="
100
100
  - !ruby/object:Gem::Version
101
- version: '3'
101
+ version: '0'
102
102
  type: :development
103
103
  prerelease: false
104
104
  version_requirements: !ruby/object:Gem::Requirement
105
105
  requirements:
106
- - - "~>"
106
+ - - ">="
107
107
  - !ruby/object:Gem::Version
108
- version: '3'
108
+ version: '0'
109
109
  - !ruby/object:Gem::Dependency
110
110
  name: bundler
111
111
  requirement: !ruby/object:Gem::Requirement
112
112
  requirements:
113
- - - "~>"
113
+ - - ">="
114
114
  - !ruby/object:Gem::Version
115
- version: '1.3'
115
+ version: '0'
116
116
  type: :development
117
117
  prerelease: false
118
118
  version_requirements: !ruby/object:Gem::Requirement
119
119
  requirements:
120
- - - "~>"
120
+ - - ">="
121
121
  - !ruby/object:Gem::Version
122
- version: '1.3'
122
+ version: '0'
123
123
  - !ruby/object:Gem::Dependency
124
124
  name: rake
125
125
  requirement: !ruby/object:Gem::Requirement
126
126
  requirements:
127
- - - "~>"
127
+ - - ">="
128
128
  - !ruby/object:Gem::Version
129
- version: '12.0'
129
+ version: '0'
130
130
  type: :development
131
131
  prerelease: false
132
132
  version_requirements: !ruby/object:Gem::Requirement
133
133
  requirements:
134
- - - "~>"
134
+ - - ">="
135
135
  - !ruby/object:Gem::Version
136
- version: '12.0'
136
+ version: '0'
137
137
  - !ruby/object:Gem::Dependency
138
138
  name: combustion
139
139
  requirement: !ruby/object:Gem::Requirement
@@ -159,7 +159,7 @@ files:
159
159
  - ".rspec"
160
160
  - ".travis.yml"
161
161
  - Gemfile
162
- - LICENSE.txt
162
+ - LICENSE
163
163
  - README.md
164
164
  - Rakefile
165
165
  - data_tables-responder.gemspec
@@ -167,6 +167,7 @@ files:
167
167
  - gemfiles/activerecord-4.2.Gemfile
168
168
  - gemfiles/activerecord-5.0.Gemfile
169
169
  - gemfiles/activerecord-5.1.Gemfile
170
+ - gemfiles/activerecord-5.2.Gemfile
170
171
  - lib/data_tables.rb
171
172
  - lib/data_tables/active_model_serializers/adapter.rb
172
173
  - lib/data_tables/active_model_serializers/adapter/meta.rb
@@ -207,12 +208,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
207
208
  version: '2.3'
208
209
  required_rubygems_version: !ruby/object:Gem::Requirement
209
210
  requirements:
210
- - - ">="
211
+ - - ">"
211
212
  - !ruby/object:Gem::Version
212
- version: '0'
213
+ version: 1.3.1
213
214
  requirements: []
214
- rubyforge_project:
215
- rubygems_version: 2.7.7
215
+ rubygems_version: 3.0.3
216
216
  signing_key:
217
217
  specification_version: 4
218
218
  summary: Respond to DataTable requests.