data_tables-responder 0.4.2 → 0.4.3

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
- SHA1:
3
- metadata.gz: a83b526e4f4224368d73806333dff683042e76cc
4
- data.tar.gz: 135113fa38ca6d8df40315a0d5cde7372cf92739
2
+ SHA256:
3
+ metadata.gz: 6d6521ba0906582dd0c35d5a654f516ab46c1e906e7b55268c6b33b2cc3c0a0e
4
+ data.tar.gz: 58fb522483dc1af6bac2b7204326b17ebacecef2b94f5ebaa07be02ea6da4815
5
5
  SHA512:
6
- metadata.gz: a403b7f8443f716245bb1a2c1714586d9f08c899ded9378bd742cc939a667ebd2a9cf0a0c738480ccb55157a0e6dacf5785419daa5964d52b50042341216f0f3
7
- data.tar.gz: 64d5519e436855129d00dd227c79b9fabd39e60fec2676e311338bace7df56620925c2df7d0ad82bbdde4b9b462ff5867f296676e07880f8cab94619d63fb4df
6
+ metadata.gz: f1d283ac5f9e594b3fe56656d1b27f30f8cc3f3414fde80c6c19ee7cfb59ef8e40e0246d8c3e6bfa5c9c47f5d64eff337f7e6fe1d113a3f5b510eb92ea52c4de
7
+ data.tar.gz: 4210d07b780dfa981d6d5d532ade9eaa174f73bcbdcb8f41c65d8909d230589492ad969b699d88a137dab4b11a01e11a782068badd28cfc565a7ac83c2d71fe5
data/.gitignore CHANGED
@@ -1,6 +1,7 @@
1
1
  /.bundle/
2
2
  /.yardoc
3
3
  /Gemfile.lock
4
+ /build/
4
5
  /_yardoc/
5
6
  /coverage/
6
7
  /doc/
@@ -1,18 +1,42 @@
1
1
  language: ruby
2
2
  sudo: false
3
- rvm:
4
- - 2.3.1
5
- - 2.4.0
3
+
6
4
  cache: bundler
5
+
6
+ before_install:
7
+ - gem update --system
8
+ - gem install bundler
9
+
10
+ before_script:
11
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
12
+ - chmod +x ./cc-test-reporter
13
+ - ./cc-test-reporter before-build
14
+
7
15
  script:
8
16
  - bundle exec rspec
9
17
 
10
- after_success:
11
- - bundle exec codeclimate-test-reporter
18
+ after_script:
19
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
12
20
 
13
21
  addons:
14
- postgresql: "9.3"
22
+ postgresql: 9.4
23
+
24
+ rvm:
25
+ - 2.5
26
+ - 2.4
27
+ - 2.3
28
+
29
+ gemfile:
30
+ - gemfiles/activerecord-5.1.Gemfile
31
+ - gemfiles/activerecord-5.0.Gemfile
32
+ - gemfiles/activerecord-4.2.Gemfile
33
+ - gemfiles/activerecord-4.1.Gemfile
34
+
35
+ matrix:
36
+ exclude:
37
+
38
+ - rvm: 2.4
39
+ gemfile: gemfiles/activerecord-4.1.Gemfile
15
40
 
16
- env:
17
- - RSPEC_VERSION="<2.99"
18
- - RSPEC_VERSION="~>3.0
41
+ - rvm: 2.5
42
+ gemfile: gemfiles/activerecord-4.1.Gemfile
data/Gemfile CHANGED
@@ -1,4 +1,19 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in data_tables-responder.gemspec
4
3
  gemspec
4
+
5
+ group :test do
6
+
7
+ # Generates coverage stats of specs
8
+ gem 'simplecov'
9
+
10
+ # Gives CircleCI more perspective on our tests
11
+ gem 'rspec_junit_formatter'
12
+
13
+ gem 'rspec'
14
+
15
+ gem 'database_cleaner'
16
+
17
+ gem 'combustion'
18
+
19
+ end
data/README.md CHANGED
@@ -1,3 +1,8 @@
1
+ [![Version ](https://img.shields.io/gem/v/data_tables-responder.svg)](https://rubygems.org/gems/data_tables-responder)
2
+ [![Build Status ](https://travis-ci.org/TwilightCoders/data_tables-responder.svg)](https://travis-ci.org/TwilightCoders/data_tables-responder)
3
+ [![Code Climate ](https://api.codeclimate.com/v1/badges/5032242cc2798697105a/maintainability)](https://codeclimate.com/github/TwilightCoders/data_tables-responder/maintainability)
4
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/5032242cc2798697105a/test_coverage)](https://codeclimate.com/github/TwilightCoders/data_tables-responder/test_coverage)
5
+
1
6
  # DataTables::Responder
2
7
 
3
8
  DataTables Responder assists with responding, filtering, searching, paginating and formatting results from DataTable client requests.
@@ -34,7 +39,7 @@ class UsersController < ApplicationController
34
39
  def index
35
40
  @users = User.all
36
41
  respond_to do |format|
37
- format.dt { render json: @users, adapter: DataTables::Adapter }
42
+ format.dt { render dt: @users }
38
43
  end
39
44
  end
40
45
 
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
3
 
4
- RSpec::Core::RakeTask.new(:spec)
4
+ RSpec::Core::RakeTask.new
5
5
 
6
- task :default => :spec
6
+ task default: :spec
@@ -10,6 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ['dale@twilightcoders.net']
11
11
 
12
12
  spec.summary = 'Respond to DataTable requests.'
13
+ spec.description = "Allows rails to respond to DataTable requests"
13
14
  spec.homepage = "https://github.com/TwilightCoders/data_tables-responder"
14
15
  spec.license = 'MIT'
15
16
 
@@ -21,21 +22,24 @@ Gem::Specification.new do |spec|
21
22
  raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
22
23
  end
23
24
 
24
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
- spec.bindir = 'exe'
26
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
- spec.require_paths = ['lib']
25
+ spec.files = `git ls-files -z`.split("\x0")
26
+ spec.bindir = 'bin'
27
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
28
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
29
+ spec.require_paths = ['lib', 'spec']
28
30
 
29
31
  rails_versions = ['>= 4.1', '< 6']
32
+ spec.required_ruby_version = '>= 2.3'
30
33
 
31
- spec.add_runtime_dependency 'active_model_serializers', '~> 0.10.4'
34
+ spec.add_runtime_dependency 'active_model_serializers', '~> 0'
35
+ spec.add_runtime_dependency 'quick_count', '~> 0.1'
32
36
  spec.add_runtime_dependency 'railties', rails_versions
33
- spec.add_runtime_dependency 'quick_count', ['>= 0.0.3', '< 0.1.0']
34
37
 
35
38
  spec.add_development_dependency 'activerecord', rails_versions
36
- spec.add_development_dependency 'pry-byebug'
37
- spec.add_development_dependency 'database_cleaner'
39
+ spec.add_development_dependency 'pg', '~> 0'
40
+ spec.add_development_dependency 'pry-byebug', '~> 3'
38
41
  spec.add_development_dependency 'bundler', '~> 1.3'
39
- spec.add_development_dependency 'rake', '~> 10.0'
40
- spec.add_development_dependency 'rspec', '~> 3.0'
42
+ spec.add_development_dependency 'rake', '~> 12.0'
43
+ spec.add_development_dependency 'combustion', '~> 0.7'
44
+
41
45
  end
@@ -0,0 +1,4 @@
1
+ eval_gemfile File.join(File.dirname(__FILE__), "../Gemfile")
2
+
3
+ gem 'activerecord', '~> 4.1.0'
4
+ gem 'pg', '~> 0.20.0'
@@ -0,0 +1,4 @@
1
+ eval_gemfile File.join(File.dirname(__FILE__), "../Gemfile")
2
+
3
+ gem 'activerecord', '~> 4.2.0'
4
+ gem 'pg', '~> 0.20.0'
@@ -0,0 +1,3 @@
1
+ eval_gemfile File.join(File.dirname(__FILE__), "../Gemfile")
2
+
3
+ gem 'activerecord', '~> 5.0.0'
@@ -0,0 +1,3 @@
1
+ eval_gemfile File.join(File.dirname(__FILE__), "../Gemfile")
2
+
3
+ gem 'activerecord', '~> 5.1.0'
@@ -45,19 +45,24 @@ module DataTables
45
45
  }, join_hash
46
46
  end
47
47
 
48
- protected
48
+ protected
49
49
 
50
50
  def search_by_type(model, column, query, &block)
51
+ arel_column = model.arel_table[column]
51
52
  result = case model.columns_hash[column.to_s]&.type
52
53
  when :string
53
54
  # I'm pretty sure this is safe from SQL Injection
54
- model.arel_table[column].matches("%#{query}%")
55
+ arel_column.matches("%#{query}%")
55
56
  when :integer
56
- value = query&.to_i and model.arel_table[column].eq(value)
57
+ value = query&.to_i and arel_column.eq(value)
57
58
  when :datetime
58
59
  datetime = Time.parse(query)
59
60
  range = (datetime-1.second)..(datetime+1.second)
60
- model.arel_table[column].between(range)
61
+ arel_column.between(range)
62
+ when :uuid
63
+ lower = query.gsub(/-/, '').ljust(32, '0')
64
+ upper = query.gsub(/-/, '').ljust(32, 'f')
65
+ arel_for_range(arel_column, (lower..upper))
61
66
  end
62
67
 
63
68
  yield(result) if !result.nil? && block_given?
@@ -76,6 +81,21 @@ module DataTables
76
81
  end
77
82
  end
78
83
 
84
+ private
85
+
86
+ def arel_for_range(column, range)
87
+ Arel::Nodes::Between.new(column, Arel::Nodes::And.new([
88
+ arel_casted_node(column, range.first),
89
+ arel_casted_node(column, range.last)
90
+ ]))
91
+ end
92
+
93
+ def arel_casted_node(column, value)
94
+ Arel::Nodes::Casted.new(value, column)
95
+ rescue NameError
96
+ value
97
+ end
98
+
79
99
  end
80
100
  end
81
101
  end
@@ -1,5 +1,5 @@
1
1
  module DataTables
2
2
  module Responder
3
- VERSION = '0.4.2'
3
+ VERSION = '0.4.3'
4
4
  end
5
5
  end
@@ -0,0 +1,62 @@
1
+ require 'spec_helper'
2
+
3
+ require 'pry'
4
+
5
+ describe DataTables::Modules::Order do
6
+
7
+ before(:each) do
8
+ # Make everything public :P
9
+ DataTables::Modules::Order.send(:public, *DataTables::Modules::Order.protected_instance_methods)
10
+ end
11
+
12
+ let!(:complex_params) do
13
+ HashWithIndifferentAccess.new({
14
+ "columns": [
15
+ {
16
+ "data": "id",
17
+ "name": "",
18
+ "orderable": true,
19
+ "search": { "regex": false, "value": "" },
20
+ "searchable": true
21
+ },
22
+ {
23
+ "data": "post.user.email",
24
+ "name": "",
25
+ "orderable": true,
26
+ "search": { "regex": false, "value": "foo@bar.baz" },
27
+ "searchable": true
28
+ },
29
+ {
30
+ "data": nil,
31
+ "name": "",
32
+ "orderable": false,
33
+ "search": { "regex": false, "value": "" },
34
+ "searchable": true
35
+ }
36
+ ],
37
+ "draw": 3,
38
+ "length": 10,
39
+ "order": [
40
+ { "column": 1, "dir": "asc" }
41
+ ],
42
+ "sRangeSeparator": "~",
43
+ "search": { "regex": false, "value": "" },
44
+ "start": 0
45
+ })
46
+ end
47
+
48
+ xit 'handles multi nested requests' do
49
+
50
+ end
51
+
52
+ it 'transmutes datatable order' do
53
+
54
+ order = DataTables::Modules::Order.new(Post, Post.all, complex_params)
55
+
56
+ transmuted = order.orderable_columns(complex_params[:order], complex_params[:columns])
57
+
58
+ expect(transmuted).to eq({"post.user.email"=>"asc"})
59
+ end
60
+
61
+ end
62
+
@@ -0,0 +1,264 @@
1
+ require 'spec_helper'
2
+
3
+ require 'pry'
4
+
5
+ describe DataTables::Responder do
6
+
7
+ before(:each) do
8
+ user = User.create(email: 'foo@bar.baz')
9
+ post = Post.create(user: user, title: 'foo')
10
+ comment = Comment.create(post: post, user: user)
11
+ end
12
+
13
+ let!(:simple_params) do
14
+ HashWithIndifferentAccess.new({
15
+ "columns": [
16
+ {
17
+ "data": "id",
18
+ "name": "",
19
+ "orderable": true,
20
+ "search": { "regex": false, "value": "" },
21
+ "searchable": true
22
+ },
23
+ {
24
+ "data": "title",
25
+ "name": "",
26
+ "orderable": true,
27
+ "search": { "regex": false, "value": "foo" },
28
+ "searchable": true
29
+ },
30
+ {
31
+ "data": nil,
32
+ "name": "",
33
+ "orderable": false,
34
+ "search": { "regex": false, "value": "" },
35
+ "searchable": true
36
+ }
37
+ ],
38
+ "draw": 3,
39
+ "length": 10,
40
+ "order": [
41
+ { "column": 1, "dir": "asc" }
42
+ ],
43
+ "sRangeSeparator": "~",
44
+ "search": { "regex": false, "value": "" },
45
+ "start": 0
46
+ })
47
+ end
48
+
49
+ let!(:simple_bad_params) do
50
+ HashWithIndifferentAccess.new({
51
+ "columns": [
52
+ {
53
+ "data": "id",
54
+ "name": "",
55
+ "orderable": true,
56
+ "search": { "regex": false, "value": "" },
57
+ "searchable": true
58
+ },
59
+ {
60
+ "data": "missing_column",
61
+ "name": "",
62
+ "orderable": true,
63
+ "search": { "regex": false, "value": "foo" },
64
+ "searchable": true
65
+ },
66
+ {
67
+ "data": nil,
68
+ "name": "",
69
+ "orderable": false,
70
+ "search": { "regex": false, "value": "" },
71
+ "searchable": true
72
+ }
73
+ ],
74
+ "draw": 3,
75
+ "length": 10,
76
+ "order": [
77
+ { "column": 1, "dir": "asc" }
78
+ ],
79
+ "sRangeSeparator": "~",
80
+ "search": { "regex": false, "value": "" },
81
+ "start": 0
82
+ })
83
+ end
84
+
85
+ let!(:complex_params) do
86
+ HashWithIndifferentAccess.new({
87
+ "columns": [
88
+ {
89
+ "data": "id",
90
+ "name": "",
91
+ "orderable": true,
92
+ "search": { "regex": false, "value": "" },
93
+ "searchable": true
94
+ },
95
+ {
96
+ "data": "post.user.email",
97
+ "name": "",
98
+ "orderable": true,
99
+ "search": { "regex": false, "value": "foo@bar.baz" },
100
+ "searchable": true
101
+ },
102
+ {
103
+ "data": nil,
104
+ "name": "",
105
+ "orderable": false,
106
+ "search": { "regex": false, "value": "" },
107
+ "searchable": true
108
+ }
109
+ ],
110
+ "draw": 3,
111
+ "length": 10,
112
+ "order": [
113
+ { "column": 1, "dir": "asc" }
114
+ ],
115
+ "sRangeSeparator": "~",
116
+ "search": { "regex": false, "value": "" },
117
+ "start": 0
118
+ })
119
+ end
120
+
121
+ let!(:complex_bad_params) do
122
+ HashWithIndifferentAccess.new({
123
+ "columns": [
124
+ {
125
+ "data": "id",
126
+ "name": "",
127
+ "orderable": true,
128
+ "search": { "regex": false, "value": "" },
129
+ "searchable": true
130
+ },
131
+ {
132
+ "data": "post.foo.email",
133
+ "name": "",
134
+ "orderable": true,
135
+ "search": { "regex": false, "value": "foo@bar.baz" },
136
+ "searchable": true
137
+ },
138
+ {
139
+ "data": nil,
140
+ "name": "",
141
+ "orderable": false,
142
+ "search": { "regex": false, "value": "" },
143
+ "searchable": true
144
+ }
145
+ ],
146
+ "draw": 3,
147
+ "length": 10,
148
+ "order": [
149
+ { "column": 1, "dir": "asc" }
150
+ ],
151
+ "sRangeSeparator": "~",
152
+ "search": { "regex": false, "value": "" },
153
+ "start": 0
154
+ })
155
+ end
156
+
157
+ let!(:complex_params_with_order_and_empty_search) do
158
+ HashWithIndifferentAccess.new({
159
+ "columns": [
160
+ {
161
+ "data": "id",
162
+ "name": "",
163
+ "orderable": true,
164
+ "search": { "regex": false, "value": "" },
165
+ "searchable": true
166
+ },
167
+ {
168
+ "data": "post.user.email",
169
+ "name": "",
170
+ "orderable": true,
171
+ "search": { "regex": false, "value": "" },
172
+ "searchable": true
173
+ },
174
+ {
175
+ "data": nil,
176
+ "name": "",
177
+ "orderable": false,
178
+ "search": { "regex": false, "value": "" },
179
+ "searchable": true
180
+ }
181
+ ],
182
+ "draw": 3,
183
+ "length": 10,
184
+ "order": [
185
+ { "column": 1, "dir": "asc" }
186
+ ],
187
+ "sRangeSeparator": "~",
188
+ "search": { "regex": false, "value": "" },
189
+ "start": 0
190
+ })
191
+ end
192
+
193
+ it 'responds when given activerecord::base model' do
194
+ response = DataTables::Responder.respond(Comment, complex_params)
195
+ response_sql = response.to_sql
196
+
197
+ expect(response.count).to eq(1)
198
+ expect(response_sql).to include('"comments".* FROM "comments"')
199
+ end
200
+
201
+ describe 'handles complex' do
202
+ it 'nested requests' do
203
+
204
+ response = DataTables::Responder.respond(Comment.all, complex_params)
205
+ response_sql = response.to_sql
206
+
207
+ expect(response.count).to eq(1)
208
+ expect(response_sql).to include('"comments".* FROM "comments"')
209
+ expect(response_sql).to include('INNER JOIN "posts" ON "posts"."id" = "comments"."post_id"')
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%\')')
212
+ expect(response_sql).to include('ORDER BY "users"."email" ASC')
213
+ expect(response_sql).to include('LIMIT 10 OFFSET 0')
214
+ end
215
+
216
+ it 'nested requests with bad data' do
217
+
218
+ response = DataTables::Responder.respond(Comment.all, complex_bad_params)
219
+ response_sql = response.to_sql
220
+
221
+ expect(response.count).to eq(1)
222
+ expect(response_sql).to include('"comments".* FROM "comments"')
223
+ expect(response_sql).to include('LIMIT 10 OFFSET 0')
224
+ end
225
+
226
+ it 'nested requests when sorting without searching' do
227
+
228
+ response = DataTables::Responder.respond(Comment.all, complex_params_with_order_and_empty_search)
229
+ response_sql = response.to_sql
230
+
231
+ expect(response.count).to eq(1)
232
+ expect(response_sql).to include('"comments".* FROM "comments"')
233
+ expect(response_sql).to include('INNER JOIN "posts" ON "posts"."id" = "comments"."post_id"')
234
+ expect(response_sql).to include('JOIN "users" ON "users"."id" = "posts"."user_id"')
235
+ expect(response_sql).to include('ORDER BY "users"."email" ASC')
236
+ expect(response_sql).to include('LIMIT 10 OFFSET 0')
237
+ end
238
+ end
239
+
240
+ describe 'handles simple' do
241
+ it 'nested requests' do
242
+
243
+ response = DataTables::Responder.respond(Post.all, simple_params)
244
+ response_sql = response.to_sql
245
+
246
+ expect(response.count).to eq(1)
247
+ expect(response_sql).to include('WHERE ("posts"."title" ILIKE \'%foo%\')')
248
+ expect(response_sql).to include('ORDER BY "posts"."title" ASC')
249
+ expect(response_sql).to include('LIMIT 10 OFFSET 0')
250
+ end
251
+
252
+ it 'nested requests with bad data' do
253
+
254
+ response = DataTables::Responder.respond(Post.all, simple_bad_params)
255
+ response_sql = response.to_sql
256
+
257
+ expect(response.count).to eq(1)
258
+ expect(response_sql).to include('"posts".* FROM "posts"')
259
+ expect(response_sql).to_not include('"posts"."missing_column"')
260
+ expect(response_sql).to include('LIMIT 10 OFFSET 0')
261
+ end
262
+ end
263
+
264
+ end
@@ -0,0 +1,102 @@
1
+ require 'spec_helper'
2
+
3
+ describe DataTables::Modules::Search do
4
+
5
+ let!(:complex_params) do
6
+ HashWithIndifferentAccess.new({
7
+ "columns": [
8
+ {
9
+ "data": "id",
10
+ "name": "",
11
+ "searchable": true,
12
+ "orderable": true,
13
+ "search": { "value": "", "regex": false }
14
+ },
15
+ {
16
+ "data": "title",
17
+ "name": "",
18
+ "searchable": true,
19
+ "orderable": true,
20
+ "search": { "value": "", "regex": false }
21
+ },
22
+ {
23
+ "data": "views",
24
+ "name": "",
25
+ "searchable": true,
26
+ "orderable": true,
27
+ "search": { "value": "", "regex": false }
28
+ }
29
+ ],
30
+ "draw": 3,
31
+ "length": 10,
32
+ "order": [
33
+ { "column": 1, "dir": "asc" }
34
+ ],
35
+ "sRangeSeparator": "~",
36
+ "search": { "regex": false, "value": "" },
37
+ "start": 0
38
+ })
39
+ end
40
+
41
+ context 'can search' do
42
+
43
+ before(:each) do
44
+ User.create(email: 'foo@bar.com')
45
+ User.create(email: 'foo2@bar.com')
46
+ Post.create(title: 'foo', views: 4)
47
+ Post.create(title: 'bar', views: 3)
48
+ end
49
+
50
+ it 'integers' do
51
+
52
+ complex_params[:columns][2][:search] = {
53
+ "value": "4",
54
+ "regex": false
55
+ }
56
+
57
+ dt_module = DataTables::Modules::Search.new(Post, Post.all, complex_params)
58
+
59
+ posts = dt_module.search
60
+
61
+ # expect{dt_module.search}.to_not raise_error()
62
+ expect(posts.count).to eq(1)
63
+ expect(posts[0].views).to eq(4)
64
+
65
+ end
66
+
67
+ it 'strings' do
68
+
69
+ complex_params[:columns][1][:search] = {
70
+ "value": "foo",
71
+ "regex": false
72
+ }
73
+
74
+ dt_module = DataTables::Modules::Search.new(Post, Post.all, complex_params)
75
+
76
+ posts = dt_module.search
77
+
78
+ # expect{dt_module.search}.to_not raise_error()
79
+ expect(posts.count).to eq(1)
80
+ expect(posts[0].title).to eq('foo')
81
+
82
+ end
83
+
84
+ it 'uuids' do
85
+
86
+ complex_params[:columns][0][:search] = {
87
+ "value": User.find_by(email: 'foo@bar.com').id,
88
+ "regex": false
89
+ }
90
+
91
+ dt_module = DataTables::Modules::Search.new(User, User.all, complex_params)
92
+
93
+ users = dt_module.search
94
+
95
+ # expect{dt_module.search}.to_not raise_error()
96
+ expect(users.count).to eq(1)
97
+ expect(users[0].email).to eq('foo@bar.com')
98
+
99
+ end
100
+ end
101
+
102
+ end
@@ -0,0 +1,28 @@
1
+ ENV['RAILS_ENV'] = 'test'
2
+
3
+ require 'database_cleaner'
4
+ require 'combustion'
5
+
6
+ require 'simplecov'
7
+ SimpleCov.start do
8
+ add_filter 'spec'
9
+ end
10
+
11
+ Combustion.path = 'spec/support/rails'
12
+ Combustion.initialize! :active_record
13
+
14
+ RSpec.configure do |config|
15
+ config.order = 'random'
16
+
17
+ # Configure the DatabaseCleaner
18
+ config.before(:suite) do
19
+ DatabaseCleaner.strategy = :transaction
20
+ DatabaseCleaner.clean_with(:truncation)
21
+ end
22
+
23
+ config.around(:each) do |example|
24
+ DatabaseCleaner.cleaning do
25
+ example.run
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,5 @@
1
+ class Comment < ::ActiveRecord::Base
2
+ belongs_to :user
3
+ belongs_to :post
4
+
5
+ end
@@ -0,0 +1,4 @@
1
+ class Post < ::ActiveRecord::Base
2
+ belongs_to :user
3
+ has_many :comments
4
+ end
@@ -0,0 +1,4 @@
1
+ class User < ::ActiveRecord::Base
2
+ has_many :posts
3
+ has_many :comments
4
+ end
@@ -0,0 +1,4 @@
1
+ test:
2
+ adapter: postgresql
3
+ encoding: unicode
4
+ database: data_tables-responder-test
@@ -0,0 +1,3 @@
1
+ Rails.application.routes.draw do
2
+ #
3
+ end
@@ -0,0 +1,25 @@
1
+ ActiveRecord::Schema.define do
2
+ self.verbose = false
3
+
4
+ enable_extension 'pgcrypto'
5
+ enable_extension 'uuid-ossp'
6
+
7
+ create_table :users, id: :uuid, :force => true do |t|
8
+ t.string :email
9
+ t.timestamps
10
+ end
11
+
12
+ create_table :posts, :force => true do |t|
13
+ t.uuid :user_id
14
+ t.string :title
15
+ t.integer :views # for testing integers
16
+ t.timestamps
17
+ end
18
+
19
+ create_table :comments, :force => true do |t|
20
+ t.uuid :user_id
21
+ t.integer :post_id
22
+ t.timestamps
23
+ end
24
+
25
+ end
@@ -0,0 +1 @@
1
+ *.log
File without changes
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.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dale Stevens
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-27 00:00:00.000000000 Z
11
+ date: 2018-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers
@@ -16,54 +16,48 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.10.4
19
+ version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.10.4
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: railties
28
+ name: quick_count
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '4.1'
34
- - - "<"
31
+ - - "~>"
35
32
  - !ruby/object:Gem::Version
36
- version: '6'
33
+ version: '0.1'
37
34
  type: :runtime
38
35
  prerelease: false
39
36
  version_requirements: !ruby/object:Gem::Requirement
40
37
  requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- version: '4.1'
44
- - - "<"
38
+ - - "~>"
45
39
  - !ruby/object:Gem::Version
46
- version: '6'
40
+ version: '0.1'
47
41
  - !ruby/object:Gem::Dependency
48
- name: quick_count
42
+ name: railties
49
43
  requirement: !ruby/object:Gem::Requirement
50
44
  requirements:
51
45
  - - ">="
52
46
  - !ruby/object:Gem::Version
53
- version: 0.0.3
47
+ version: '4.1'
54
48
  - - "<"
55
49
  - !ruby/object:Gem::Version
56
- version: 0.1.0
50
+ version: '6'
57
51
  type: :runtime
58
52
  prerelease: false
59
53
  version_requirements: !ruby/object:Gem::Requirement
60
54
  requirements:
61
55
  - - ">="
62
56
  - !ruby/object:Gem::Version
63
- version: 0.0.3
57
+ version: '4.1'
64
58
  - - "<"
65
59
  - !ruby/object:Gem::Version
66
- version: 0.1.0
60
+ version: '6'
67
61
  - !ruby/object:Gem::Dependency
68
62
  name: activerecord
69
63
  requirement: !ruby/object:Gem::Requirement
@@ -85,33 +79,33 @@ dependencies:
85
79
  - !ruby/object:Gem::Version
86
80
  version: '6'
87
81
  - !ruby/object:Gem::Dependency
88
- name: pry-byebug
82
+ name: pg
89
83
  requirement: !ruby/object:Gem::Requirement
90
84
  requirements:
91
- - - ">="
85
+ - - "~>"
92
86
  - !ruby/object:Gem::Version
93
87
  version: '0'
94
88
  type: :development
95
89
  prerelease: false
96
90
  version_requirements: !ruby/object:Gem::Requirement
97
91
  requirements:
98
- - - ">="
92
+ - - "~>"
99
93
  - !ruby/object:Gem::Version
100
94
  version: '0'
101
95
  - !ruby/object:Gem::Dependency
102
- name: database_cleaner
96
+ name: pry-byebug
103
97
  requirement: !ruby/object:Gem::Requirement
104
98
  requirements:
105
- - - ">="
99
+ - - "~>"
106
100
  - !ruby/object:Gem::Version
107
- version: '0'
101
+ version: '3'
108
102
  type: :development
109
103
  prerelease: false
110
104
  version_requirements: !ruby/object:Gem::Requirement
111
105
  requirements:
112
- - - ">="
106
+ - - "~>"
113
107
  - !ruby/object:Gem::Version
114
- version: '0'
108
+ version: '3'
115
109
  - !ruby/object:Gem::Dependency
116
110
  name: bundler
117
111
  requirement: !ruby/object:Gem::Requirement
@@ -132,29 +126,29 @@ dependencies:
132
126
  requirements:
133
127
  - - "~>"
134
128
  - !ruby/object:Gem::Version
135
- version: '10.0'
129
+ version: '12.0'
136
130
  type: :development
137
131
  prerelease: false
138
132
  version_requirements: !ruby/object:Gem::Requirement
139
133
  requirements:
140
134
  - - "~>"
141
135
  - !ruby/object:Gem::Version
142
- version: '10.0'
136
+ version: '12.0'
143
137
  - !ruby/object:Gem::Dependency
144
- name: rspec
138
+ name: combustion
145
139
  requirement: !ruby/object:Gem::Requirement
146
140
  requirements:
147
141
  - - "~>"
148
142
  - !ruby/object:Gem::Version
149
- version: '3.0'
143
+ version: '0.7'
150
144
  type: :development
151
145
  prerelease: false
152
146
  version_requirements: !ruby/object:Gem::Requirement
153
147
  requirements:
154
148
  - - "~>"
155
149
  - !ruby/object:Gem::Version
156
- version: '3.0'
157
- description:
150
+ version: '0.7'
151
+ description: Allows rails to respond to DataTable requests
158
152
  email:
159
153
  - dale@twilightcoders.net
160
154
  executables: []
@@ -168,9 +162,11 @@ files:
168
162
  - LICENSE.txt
169
163
  - README.md
170
164
  - Rakefile
171
- - bin/console
172
- - bin/setup
173
165
  - data_tables-responder.gemspec
166
+ - gemfiles/activerecord-4.1.Gemfile
167
+ - gemfiles/activerecord-4.2.Gemfile
168
+ - gemfiles/activerecord-5.0.Gemfile
169
+ - gemfiles/activerecord-5.1.Gemfile
174
170
  - lib/data_tables.rb
175
171
  - lib/data_tables/active_model_serializers/adapter.rb
176
172
  - lib/data_tables/active_model_serializers/adapter/meta.rb
@@ -182,6 +178,18 @@ files:
182
178
  - lib/data_tables/responder.rb
183
179
  - lib/data_tables/responder/railtie.rb
184
180
  - lib/data_tables/responder/version.rb
181
+ - spec/data_tables/order_spec.rb
182
+ - spec/data_tables/responder_spec.rb
183
+ - spec/data_tables/search_spec.rb
184
+ - spec/spec_helper.rb
185
+ - spec/support/rails/app/models/comment.rb
186
+ - spec/support/rails/app/models/post.rb
187
+ - spec/support/rails/app/models/user.rb
188
+ - spec/support/rails/config/database.yml
189
+ - spec/support/rails/config/routes.rb
190
+ - spec/support/rails/db/schema.rb
191
+ - spec/support/rails/log/.gitignore
192
+ - spec/support/rails/public/favicon.ico
185
193
  homepage: https://github.com/TwilightCoders/data_tables-responder
186
194
  licenses:
187
195
  - MIT
@@ -191,11 +199,12 @@ post_install_message:
191
199
  rdoc_options: []
192
200
  require_paths:
193
201
  - lib
202
+ - spec
194
203
  required_ruby_version: !ruby/object:Gem::Requirement
195
204
  requirements:
196
205
  - - ">="
197
206
  - !ruby/object:Gem::Version
198
- version: '0'
207
+ version: '2.3'
199
208
  required_rubygems_version: !ruby/object:Gem::Requirement
200
209
  requirements:
201
210
  - - ">="
@@ -203,8 +212,20 @@ required_rubygems_version: !ruby/object:Gem::Requirement
203
212
  version: '0'
204
213
  requirements: []
205
214
  rubyforge_project:
206
- rubygems_version: 2.6.11
215
+ rubygems_version: 2.7.7
207
216
  signing_key:
208
217
  specification_version: 4
209
218
  summary: Respond to DataTable requests.
210
- test_files: []
219
+ test_files:
220
+ - spec/data_tables/order_spec.rb
221
+ - spec/data_tables/responder_spec.rb
222
+ - spec/data_tables/search_spec.rb
223
+ - spec/spec_helper.rb
224
+ - spec/support/rails/app/models/comment.rb
225
+ - spec/support/rails/app/models/post.rb
226
+ - spec/support/rails/app/models/user.rb
227
+ - spec/support/rails/config/database.yml
228
+ - spec/support/rails/config/routes.rb
229
+ - spec/support/rails/db/schema.rb
230
+ - spec/support/rails/log/.gitignore
231
+ - spec/support/rails/public/favicon.ico
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "data_tables/responder"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here