data_tables 0.1.18 → 0.1.19

Sign up to get free protection for your applications and to get access to all the features.
data/data_tables.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'data_tables'
5
- s.version = '0.1.18'
5
+ s.version = '0.1.19'
6
6
  s.date = Time.now.strftime("%Y-%m-%d")
7
7
  s.summary = "Rails friendly interface into DataTables"
8
8
  s.description = "DataTables for Rails"
data/lib/data_tables.rb CHANGED
@@ -313,12 +313,12 @@ module DataTablesController
313
313
 
314
314
  if named_scope
315
315
  objects = modelCls.send(named_scope, *args).paginate(:page => current_page,
316
- :order => order,
316
+ :order => order,
317
317
  :conditions => conditions.join(" AND "),
318
318
  :per_page => params[:iDisplayLength])
319
319
  else
320
320
  objects = modelCls.paginate(:page => current_page,
321
- :order => order,
321
+ :order => order,
322
322
  :conditions => conditions.join(" AND "),
323
323
  :per_page => params[:iDisplayLength])
324
324
  end
@@ -388,8 +388,11 @@ module DataTablesController
388
388
  end
389
389
  elsif column[:attribute]
390
390
  val = instance.send(column[:attribute].to_sym)
391
- return I18n.t(val.to_s.to_sym, :default => val.to_s) if not val.blank?
392
- return ''
391
+ if !val.blank? || val == false
392
+ return I18n.t(val.to_s.to_sym, :default => val.to_s)
393
+ else
394
+ return ''
395
+ end
393
396
  end
394
397
  return "value not found"
395
398
  end
@@ -1,15 +1,18 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'data_tables' do
4
+
4
5
  before :each do
5
- if DEBUG
6
- ExceptOptionController.any_instance.stub_chain(:logger, :debug){ |*args| puts args.first }
7
- ExceptOptionController.any_instance.stub_chain(:logger, :info){ |*args| puts args.first }
8
- else
9
- ExceptOptionController.any_instance.stub(:logger).and_return(double("Logger").as_null_object)
6
+ [ExceptOptionController, SearchTypeController].each do |controller|
7
+ if DEBUG
8
+ controller.any_instance.stub_chain(:logger, :debug){ |*args| puts args.first }
9
+ controller.any_instance.stub_chain(:logger, :info){ |*args| puts args.first }
10
+ else
11
+ controller.any_instance.stub(:logger).and_return(double("Logger").as_null_object)
12
+ end
13
+ controller.any_instance.stub(:params).and_return({iSortCol_0: 1})
14
+ controller.any_instance.stub(:render)
10
15
  end
11
- ExceptOptionController.any_instance.stub(:params).and_return({})
12
- ExceptOptionController.any_instance.stub(:render)
13
16
  ActiveRecord::Base.stub_chain(:connection, :schema_search_path).and_return("public")
14
17
  end
15
18
 
@@ -32,29 +35,64 @@ describe 'data_tables' do
32
35
  end
33
36
 
34
37
  let(:instance){ExceptOptionController.new.dummy_class_source}
38
+ let(:search_type_instance){SearchTypeController.new.search_type_class_source}
35
39
  let(:index_name){ "#{Tire::Model::Search.index_prefix}dummy_class" }
36
40
 
37
- context "Redis Models" do
38
- context "with ElasticSearch" do
39
- {"iTotalDisplayRecords" => 2, "iTotalRecords" => 2}.each do |k,v|
40
- it "respects datatables' except to calculate #{k} (#{v})" do
41
- # create index
42
- data = [{ id: 5002, name: 'not_valid', domain: 'public' },
43
- { id: 561, name: 'Native AP VLAN', domain: 'public' },
44
- { id: 56, name: 'valid', domain: 'public' }]
45
- save_elasticsearch(index_name, data)
46
-
47
- ExceptOptionController.any_instance.should_receive(:render) do |*args|
48
- arg = JSON.parse(args.first[:text])
49
- arg[k].should == v
50
- end
51
- instance
41
+ context "total records" do
42
+ {"iTotalDisplayRecords" => 2, "iTotalRecords" => 2}.each do |k,v|
43
+ it "respects datatables' except to calculate #{k} (#{v})" do
44
+ data = [{ id: 5002, name: 'not_valid', domain: 'public' },
45
+ { id: 561, name: 'Native AP VLAN', domain: 'public' },
46
+ { id: 56, name: 'valid', domain: 'public' }]
47
+ save_elasticsearch(index_name, data)
48
+
49
+ ExceptOptionController.any_instance.should_receive(:render) do |*args|
50
+ arg = JSON.parse(args.first[:text])
51
+ arg[k].should == v
52
52
  end
53
+ instance
53
54
  end
54
55
  end
55
56
  end
56
- context "Elastic Search Models" do
57
- end
58
- context "Postgres Models" do
57
+
58
+ context "mapping types sorting" do
59
+ before do
60
+ @data = %w[192.168.102.36:10.0.0.30 192.168.102.30 192.168.102.47]
61
+ SearchTypeClass.index.delete
62
+ SearchTypeClass.create_elasticsearch_index
63
+ @data.each do |d|
64
+ SearchTypeClass.create ipaddr: d, domain: :public
65
+ end
66
+ index_name = SearchTypeClass.index_name
67
+ Tire.index(index_name){refresh}
68
+ end
69
+
70
+ it "sorts IP addresses asc correctly" do
71
+ SearchTypeController.any_instance.stub(:params).and_return({
72
+ iSortCol_0: 0,
73
+ sSortDir_0: 'asc'
74
+ })
75
+
76
+ SearchTypeController.any_instance.should_receive(:render) do |*args|
77
+ data = JSON.parse(args.first[:text])["aaData"]
78
+ ips = data.map{|i| i[0]}
79
+ ips.should == @data.sort
80
+ end
81
+ search_type_instance
82
+ end
83
+
84
+ it "sorts IP addresses desc correctly" do
85
+ SearchTypeController.any_instance.stub(:params).and_return({
86
+ iSortCol_0: 0,
87
+ sSortDir_0: 'desc'
88
+ })
89
+
90
+ SearchTypeController.any_instance.should_receive(:render) do |*args|
91
+ data = JSON.parse(args.first[:text])["aaData"]
92
+ ips = data.map{|i| i[0]}
93
+ ips.should == @data.sort.reverse
94
+ end
95
+ search_type_instance
96
+ end
59
97
  end
60
98
  end
@@ -1,6 +1,15 @@
1
1
  class DummyClass < Ohm::Model
2
2
  end
3
3
 
4
+ class SearchTypeClass
5
+ include Tire::Model::Search
6
+ include Tire::Model::Persistence
7
+
8
+ property :name, type: 'string'
9
+ property :ipaddr, type: 'string', index: 'not_analyzed'
10
+ property :domain, type: 'string'
11
+ end
12
+
4
13
  class ConditionModel
5
14
  include DataTablesController
6
15
  datatables_source(:dummy_class_source, :dummy_class,
@@ -22,4 +31,11 @@ class ExceptOptionController
22
31
  {:name =>"Access Points",
23
32
  :method => :location_statuses_accesspoint_list}
24
33
  ],:except => [['name','Native AP VLAN']])
25
- end
34
+ end
35
+
36
+ class SearchTypeController
37
+ include DataTablesController
38
+ datatables_source(:search_type_class_source, :search_type_class,
39
+ :columns => [:ipaddr, :name],
40
+ :conditions => ['id!=5002',"name!= 'Native AP VLAN'"])
41
+ end
data/spec/spec_helper.rb CHANGED
@@ -11,7 +11,7 @@ Dir[File.join(APP_ROOT, "spec/models/*.rb")].each {|f| require f}
11
11
 
12
12
  DEBUG = false
13
13
 
14
- Tire.configure { logger STDOUT } if DEBUG
14
+ Tire.configure { logger STDOUT, level: :debug } if DEBUG
15
15
  Tire::Model::Search.index_prefix('test_datatable_')
16
16
 
17
17
  RSpec.configure do |config|
@@ -21,4 +21,4 @@ RSpec.configure do |config|
21
21
  config.after(:each) do
22
22
  #Tire.index("#{Tire::Model::Search.index_prefix}*"){delete}
23
23
  end
24
- end
24
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: data_tables
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.18
5
+ version: 0.1.19
6
6
  platform: ruby
7
7
  authors:
8
8
  - Duane Compton
@@ -13,19 +13,19 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2013-11-06 00:00:00.000000000 Z
16
+ date: 2013-11-22 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  type: :development
20
- version_requirements: !ruby/object:Gem::Requirement
20
+ name: rspec
21
+ prerelease: false
22
+ requirement: !ruby/object:Gem::Requirement
21
23
  requirements:
22
24
  - - ~>
23
25
  - !ruby/object:Gem::Version
24
26
  version: '2.10'
25
27
  none: false
26
- prerelease: false
27
- name: rspec
28
- requirement: !ruby/object:Gem::Requirement
28
+ version_requirements: !ruby/object:Gem::Requirement
29
29
  requirements:
30
30
  - - ~>
31
31
  - !ruby/object:Gem::Version
@@ -74,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
74
  none: false
75
75
  requirements: []
76
76
  rubyforge_project:
77
- rubygems_version: 1.8.26
77
+ rubygems_version: 1.8.24
78
78
  signing_key:
79
79
  specification_version: 3
80
80
  summary: Rails friendly interface into DataTables