mongoid_data_table 0.1.0 → 0.1.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.
data/Gemfile CHANGED
@@ -1,7 +1,3 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- gem "rails"
4
- gem "mongoid"
5
- gem "will_paginate"
6
-
7
3
  gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,73 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ mongoid_data_table (0.1.0)
5
+ actionpack (~> 3.0.0)
6
+ activesupport (~> 3.0.0)
7
+ mongoid (~> 2.0.0.beta18)
8
+ will_paginate (~> 3.0.pre2)
9
+
10
+ GEM
11
+ remote: http://rubygems.org/
12
+ specs:
13
+ abstract (1.0.0)
14
+ actionpack (3.0.1)
15
+ activemodel (= 3.0.1)
16
+ activesupport (= 3.0.1)
17
+ builder (~> 2.1.2)
18
+ erubis (~> 2.6.6)
19
+ i18n (~> 0.4.1)
20
+ rack (~> 1.2.1)
21
+ rack-mount (~> 0.6.12)
22
+ rack-test (~> 0.5.4)
23
+ tzinfo (~> 0.3.23)
24
+ activemodel (3.0.1)
25
+ activesupport (= 3.0.1)
26
+ builder (~> 2.1.2)
27
+ i18n (~> 0.4.1)
28
+ activesupport (3.0.1)
29
+ bson (1.1.1)
30
+ builder (2.1.2)
31
+ diff-lcs (1.1.2)
32
+ erubis (2.6.6)
33
+ abstract (>= 1.0.0)
34
+ i18n (0.4.1)
35
+ mongo (1.0.9)
36
+ bson (>= 1.0.5)
37
+ mongoid (2.0.0.beta.19)
38
+ activemodel (~> 3.0)
39
+ mongo (= 1.0.9)
40
+ tzinfo (~> 0.3.22)
41
+ will_paginate (~> 3.0.pre)
42
+ rack (1.2.1)
43
+ rack-mount (0.6.13)
44
+ rack (>= 1.0.0)
45
+ rack-test (0.5.6)
46
+ rack (>= 1.0)
47
+ rr (1.0.0)
48
+ rspec (2.0.1)
49
+ rspec-core (~> 2.0.1)
50
+ rspec-expectations (~> 2.0.1)
51
+ rspec-mocks (~> 2.0.1)
52
+ rspec-core (2.0.1)
53
+ rspec-expectations (2.0.1)
54
+ diff-lcs (>= 1.1.2)
55
+ rspec-mocks (2.0.1)
56
+ rspec-core (~> 2.0.1)
57
+ rspec-expectations (~> 2.0.1)
58
+ shoulda (2.11.1)
59
+ tzinfo (0.3.23)
60
+ will_paginate (3.0.pre2)
61
+
62
+ PLATFORMS
63
+ ruby
64
+
65
+ DEPENDENCIES
66
+ actionpack (~> 3.0.0)
67
+ activesupport (~> 3.0.0)
68
+ mongoid (~> 2.0.0.beta18)
69
+ mongoid_data_table!
70
+ rr (~> 1.0.0)
71
+ rspec (~> 2.0.0)
72
+ shoulda (~> 2.11.0)
73
+ will_paginate (~> 3.0.pre2)
@@ -10,7 +10,7 @@ module Mongoid
10
10
  def json_for_datatables controller, fields, search_fields=nil, &block
11
11
  params = controller.params
12
12
  search_fields ||= fields
13
- objects = self.where(_where_conditions controller, params[:sSearch], search_fields).
13
+ objects = self.where(_where_conditions params[:sSearch], search_fields).
14
14
  order_by(_order_by_fields params, fields).
15
15
  paginate :page => _page(params),
16
16
  :per_page => params[:iDisplayLength]
@@ -36,7 +36,7 @@ module Mongoid
36
36
  end
37
37
  end
38
38
 
39
- def _where_conditions controller, raw_query, search_fields
39
+ def _where_conditions raw_query, search_fields
40
40
  return if (query = escape_javascript(raw_query)).blank?
41
41
 
42
42
  {"$or" => search_fields.map {|field| {field => /#{query}/i} }}
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module DataTable
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
@@ -1 +1,6 @@
1
+ require "active_support/core_ext/object/blank"
2
+ require "active_support/core_ext/object/to_json"
3
+ require "active_support/json/encoding"
4
+ require "active_support/core_ext/string/output_safety"
5
+
1
6
  require "mongoid/data_table/base"
@@ -1,4 +1,3 @@
1
- # -*- encoding: utf-8 -*-
2
1
  $:.push File.expand_path("../lib", __FILE__)
3
2
  require "mongoid/data_table/version"
4
3
 
@@ -18,4 +17,13 @@ Gem::Specification.new do |s|
18
17
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
19
  s.require_paths = ["lib"]
20
+
21
+ s.add_dependency "actionpack", "~>3.0.0"
22
+ s.add_dependency "activesupport", "~>3.0.0"
23
+ s.add_dependency "will_paginate", "~>3.0.pre2"
24
+ s.add_dependency "mongoid", "~>2.0.0.beta18"
25
+
26
+ s.add_development_dependency "rspec", "~>2.0.0"
27
+ s.add_development_dependency "shoulda", "~>2.11.0"
28
+ s.add_development_dependency "rr", "~>1.0.0"
21
29
  end
@@ -0,0 +1,84 @@
1
+ require "mongoid_data_table"
2
+
3
+ RSpec.configure {|config| config.mock_with :rr }
4
+
5
+ describe Mongoid::DataTable do
6
+
7
+ include Mongoid::DataTable::ClassMethods
8
+
9
+ context "on being included" do
10
+ it "should extend ClassMethods"
11
+ it "should extend ActionView::Helpers::JavaScriptHelper"
12
+ end
13
+
14
+ context "#json_for_datatables" do
15
+
16
+ it "should produce JSON for the datatables plugin to consume" do
17
+ params = {:sSearch => "answer", :iSortCol_0 => "0", :sSortDir_0 => "desc", :iDisplayLength => 10, :sEcho => 1}
18
+ controller = mock!.params { params }.subject
19
+
20
+ mock(self)._where_conditions("answer", %w(foo bar)) { "where clause" }
21
+ mock(self)._order_by_fields(params, %w(foo bar baz)) { "order by" }
22
+ mock(self)._page(params) { "page" }
23
+
24
+ objects = mock!.total_entries { 10 }.subject
25
+ mock(objects).map { %([["x"], ["x"]]) }
26
+
27
+ mock(self).where("where clause") { mock!.order_by("order by") { mock!.paginate({:page => "page", :per_page => 10}) { objects } } }
28
+ mock(self).count { 42 }
29
+
30
+ result = json_for_datatables(controller, %w(foo bar baz), %w(foo bar)) {|x| [x] }
31
+ result.should == {:sEcho => 1, :iTotalRecords => 42, :iTotalDisplayRecords => 10, :aaData => %([["x"], ["x"]])}.to_json.html_safe
32
+ end
33
+
34
+ end
35
+
36
+ context "#_yield_and_render_array" do
37
+
38
+ it "should walk through the array and render it, passing in the appropriate local name"
39
+
40
+ end
41
+
42
+ context "#_where_conditions" do
43
+
44
+ it "should return nil if the query is blank" do
45
+ mock(self).escape_javascript("") { "" }
46
+ send(:_where_conditions, "", %w(foo bar baz)).should == nil
47
+ end
48
+
49
+ it "should return a mongoid $or hash with an entry for each search field" do
50
+ mock(self).escape_javascript("q") { "q" }
51
+ send(:_where_conditions, "q", %w(foo bar)).should == {"$or" => [{"foo" => /q/i}, {"bar" => /q/i}]}
52
+ end
53
+
54
+ end
55
+
56
+ context "#_order_by_fields" do
57
+
58
+ it "should find the field name and pass the sort direction" do
59
+ send(:_order_by_fields,
60
+ {:iSortCol_0 => "1", :sSortDir_0 => "asc"},
61
+ %w(foo bar baz)).should == ["bar", "asc"]
62
+ end
63
+
64
+ end
65
+
66
+ context "#_page" do
67
+
68
+ context "with a display length of 10" do
69
+ it "should return 1 when start is blank" do
70
+ send(:_page, {:iDisplayStart => "", :iDisplayLength => "10"}).should == 1
71
+ end
72
+
73
+ it "should return 1 when start is 0" do
74
+ send(:_page, {:iDisplayStart => "0", :iDisplayLength => "10"}).should == 1
75
+ end
76
+
77
+ it "should return 2 when start is 10" do
78
+ send(:_page, {:iDisplayStart => "10", :iDisplayLength => "10"}).should == 2
79
+ end
80
+ end
81
+
82
+ end
83
+
84
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid_data_table
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jason Dew
@@ -17,8 +17,120 @@ cert_chain: []
17
17
 
18
18
  date: 2010-10-22 00:00:00 -04:00
19
19
  default_executable:
20
- dependencies: []
21
-
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: actionpack
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 7
30
+ segments:
31
+ - 3
32
+ - 0
33
+ - 0
34
+ version: 3.0.0
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: activesupport
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ hash: 7
46
+ segments:
47
+ - 3
48
+ - 0
49
+ - 0
50
+ version: 3.0.0
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: will_paginate
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ hash: -1876988247
62
+ segments:
63
+ - 3
64
+ - 0
65
+ - pre2
66
+ version: 3.0.pre2
67
+ type: :runtime
68
+ version_requirements: *id003
69
+ - !ruby/object:Gem::Dependency
70
+ name: mongoid
71
+ prerelease: false
72
+ requirement: &id004 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ hash: -1967355498
78
+ segments:
79
+ - 2
80
+ - 0
81
+ - 0
82
+ - beta18
83
+ version: 2.0.0.beta18
84
+ type: :runtime
85
+ version_requirements: *id004
86
+ - !ruby/object:Gem::Dependency
87
+ name: rspec
88
+ prerelease: false
89
+ requirement: &id005 !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ~>
93
+ - !ruby/object:Gem::Version
94
+ hash: 15
95
+ segments:
96
+ - 2
97
+ - 0
98
+ - 0
99
+ version: 2.0.0
100
+ type: :development
101
+ version_requirements: *id005
102
+ - !ruby/object:Gem::Dependency
103
+ name: shoulda
104
+ prerelease: false
105
+ requirement: &id006 !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ hash: 35
111
+ segments:
112
+ - 2
113
+ - 11
114
+ - 0
115
+ version: 2.11.0
116
+ type: :development
117
+ version_requirements: *id006
118
+ - !ruby/object:Gem::Dependency
119
+ name: rr
120
+ prerelease: false
121
+ requirement: &id007 !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ~>
125
+ - !ruby/object:Gem::Version
126
+ hash: 23
127
+ segments:
128
+ - 1
129
+ - 0
130
+ - 0
131
+ version: 1.0.0
132
+ type: :development
133
+ version_requirements: *id007
22
134
  description: Simple data preparation from Mongoid to the jQuery DataTables plugin
23
135
  email:
24
136
  - jason.dew@gmail.com
@@ -31,11 +143,13 @@ extra_rdoc_files: []
31
143
  files:
32
144
  - .gitignore
33
145
  - Gemfile
146
+ - Gemfile.lock
34
147
  - Rakefile
35
148
  - lib/mongoid/data_table/base.rb
36
149
  - lib/mongoid/data_table/version.rb
37
150
  - lib/mongoid_data_table.rb
38
151
  - mongoid_data_table.gemspec
152
+ - spec/mongoid_data_table_spec.rb
39
153
  has_rdoc: true
40
154
  homepage: http://rubygems.org/gems/mongoid_data_table
41
155
  licenses: []
@@ -70,5 +184,5 @@ rubygems_version: 1.3.7
70
184
  signing_key:
71
185
  specification_version: 3
72
186
  summary: Simple data preparation from Mongoid to the jQuery DataTables plugin
73
- test_files: []
74
-
187
+ test_files:
188
+ - spec/mongoid_data_table_spec.rb