mongoid-data_table 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +9 -9
- data/lib/mongoid/data_table.rb +0 -2
- data/lib/mongoid/data_table/proxy.rb +1 -4
- data/lib/mongoid/data_table/version.rb +1 -1
- data/mongoid-data_table.gemspec +4 -4
- data/spec/spec_helper.rb +7 -0
- data/spec/unit/mongoid/data_table/proxy_spec.rb +48 -3
- metadata +8 -12
- data/lib/mongoid/data_table/criteria.rb +0 -31
- data/spec/unit/mongoid/data_table/criteria_spec.rb +0 -56
data/Gemfile.lock
CHANGED
@@ -2,8 +2,8 @@ PATH
|
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
4
|
mongoid-data_table (1.0.3)
|
5
|
-
|
6
|
-
|
5
|
+
kaminari (~> 0.12.4)
|
6
|
+
rails (>= 3.0.0)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: http://rubygems.org/
|
@@ -43,6 +43,8 @@ GEM
|
|
43
43
|
erubis (2.6.6)
|
44
44
|
abstract (>= 1.0.0)
|
45
45
|
i18n (0.5.0)
|
46
|
+
kaminari (0.12.4)
|
47
|
+
rails (>= 3.0.0)
|
46
48
|
mail (2.2.19)
|
47
49
|
activesupport (>= 2.3.6)
|
48
50
|
i18n (>= 0.4.0)
|
@@ -52,13 +54,12 @@ GEM
|
|
52
54
|
mocha (0.9.12)
|
53
55
|
mongo (1.3.1)
|
54
56
|
bson (>= 1.3.1)
|
55
|
-
mongoid (2.0.
|
57
|
+
mongoid (2.0.2)
|
56
58
|
activemodel (~> 3.0)
|
57
59
|
mongo (~> 1.3)
|
58
60
|
tzinfo (~> 0.3.22)
|
59
|
-
will_paginate (~> 3.0.pre)
|
60
61
|
polyglot (0.3.1)
|
61
|
-
rack (1.2.
|
62
|
+
rack (1.2.3)
|
62
63
|
rack-mount (0.6.14)
|
63
64
|
rack (>= 1.0.0)
|
64
65
|
rack-test (0.5.7)
|
@@ -76,7 +77,7 @@ GEM
|
|
76
77
|
activesupport (= 3.0.7)
|
77
78
|
rake (>= 0.8.7)
|
78
79
|
thor (~> 0.14.4)
|
79
|
-
rake (0.
|
80
|
+
rake (0.9.0)
|
80
81
|
rspec (2.6.0)
|
81
82
|
rspec-core (~> 2.6.0)
|
82
83
|
rspec-expectations (~> 2.6.0)
|
@@ -91,15 +92,14 @@ GEM
|
|
91
92
|
polyglot (>= 0.3.1)
|
92
93
|
tzinfo (0.3.27)
|
93
94
|
watchr (0.7)
|
94
|
-
will_paginate (3.0.pre2)
|
95
95
|
|
96
96
|
PLATFORMS
|
97
97
|
ruby
|
98
98
|
|
99
99
|
DEPENDENCIES
|
100
|
-
bson_ext (~> 1.3.
|
100
|
+
bson_ext (~> 1.3.1)
|
101
101
|
mocha (~> 0.9.12)
|
102
|
-
mongoid (~> 2.0.
|
102
|
+
mongoid (~> 2.0.2)
|
103
103
|
mongoid-data_table!
|
104
104
|
rspec (~> 2.6.0)
|
105
105
|
shoulda (~> 2.11.3)
|
data/lib/mongoid/data_table.rb
CHANGED
@@ -6,10 +6,8 @@ require 'active_support/core_ext/string/inflections'
|
|
6
6
|
require 'active_support/core_ext/class/inheritable_attributes'
|
7
7
|
require 'active_support/concern'
|
8
8
|
|
9
|
-
require 'mongoid/criteria'
|
10
9
|
require 'mongoid/relations/proxy'
|
11
10
|
|
12
|
-
require 'mongoid/data_table/criteria'
|
13
11
|
require 'mongoid/data_table/proxy'
|
14
12
|
require 'mongoid/data_table/version'
|
15
13
|
|
@@ -19,10 +19,7 @@ module Mongoid
|
|
19
19
|
|
20
20
|
def collection(force = false)
|
21
21
|
reload if force
|
22
|
-
@collection ||= conditions.
|
23
|
-
:page => current_page,
|
24
|
-
:per_page => per_page
|
25
|
-
})
|
22
|
+
@collection ||= conditions.page(current_page).per(per_page)
|
26
23
|
end
|
27
24
|
|
28
25
|
def reload
|
data/mongoid-data_table.gemspec
CHANGED
@@ -16,11 +16,11 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
17
|
s.require_paths = ["lib"]
|
18
18
|
|
19
|
-
s.add_dependency "rails", "
|
20
|
-
s.add_dependency "
|
19
|
+
s.add_dependency "rails", ">= 3.0.0"
|
20
|
+
s.add_dependency "kaminari", "~> 0.12.4"
|
21
21
|
|
22
|
-
s.add_development_dependency "bson_ext", "~>1.3.
|
23
|
-
s.add_development_dependency "mongoid", "~>2.0.
|
22
|
+
s.add_development_dependency "bson_ext", "~>1.3.1"
|
23
|
+
s.add_development_dependency "mongoid", "~>2.0.2"
|
24
24
|
s.add_development_dependency "mocha", "~>0.9.12"
|
25
25
|
s.add_development_dependency "rspec", "~>2.6.0"
|
26
26
|
s.add_development_dependency "shoulda", "~>2.11.3"
|
data/spec/spec_helper.rb
CHANGED
@@ -12,6 +12,7 @@ require 'mongoid'
|
|
12
12
|
require 'mongoid-data_table'
|
13
13
|
require 'mocha'
|
14
14
|
require 'rspec'
|
15
|
+
require 'kaminari'
|
15
16
|
|
16
17
|
LOGGER = ActiveSupport::BufferedLogger.new($stdout)
|
17
18
|
|
@@ -21,6 +22,12 @@ Mongoid.configure do |config|
|
|
21
22
|
config.logger = nil
|
22
23
|
end
|
23
24
|
|
25
|
+
if defined? ::Mongoid
|
26
|
+
require 'kaminari/models/mongoid_extension'
|
27
|
+
::Mongoid::Document.send :include, Kaminari::MongoidExtension::Document
|
28
|
+
::Mongoid::Criteria.send :include, Kaminari::MongoidExtension::Criteria
|
29
|
+
end
|
30
|
+
|
24
31
|
Dir[ File.join(MODELS, "*.rb") ].sort.each { |file| require File.basename(file) }
|
25
32
|
Dir[ File.join(SUPPORT, "*.rb") ].each { |file| require File.basename(file) }
|
26
33
|
|
@@ -2,12 +2,22 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Mongoid::DataTable::Proxy do
|
4
4
|
|
5
|
-
|
5
|
+
before do
|
6
|
+
Rails.stubs(:logger).returns(LOGGER)
|
7
|
+
end
|
8
|
+
|
9
|
+
let(:controller) do
|
6
10
|
Class.new(ActionController::Base).new.tap do |c|
|
7
11
|
c.stubs(:params).returns({})
|
8
12
|
end
|
9
13
|
end
|
10
14
|
|
15
|
+
let(:custom_array) { %w(custom) }
|
16
|
+
|
17
|
+
let(:custom_block) do
|
18
|
+
lambda { |object| custom_array }
|
19
|
+
end
|
20
|
+
|
11
21
|
describe "#new" do
|
12
22
|
|
13
23
|
it "creates a new Mongoid::DataTable::Proxy object" do
|
@@ -34,8 +44,8 @@ describe Mongoid::DataTable::Proxy do
|
|
34
44
|
|
35
45
|
describe "#collection" do
|
36
46
|
|
37
|
-
it "should
|
38
|
-
proxy.collection.should
|
47
|
+
it "should be paged to page 1" do
|
48
|
+
proxy.collection.current_page.should == proxy.current_page
|
39
49
|
end
|
40
50
|
|
41
51
|
it "should reload when passed true" do
|
@@ -66,4 +76,39 @@ describe Mongoid::DataTable::Proxy do
|
|
66
76
|
|
67
77
|
end
|
68
78
|
|
79
|
+
context "with custom block" do
|
80
|
+
|
81
|
+
let(:bob) do
|
82
|
+
Person.find_or_create_by(:name => 'Bob')
|
83
|
+
end
|
84
|
+
|
85
|
+
let(:dt) do
|
86
|
+
bob
|
87
|
+
Person.criteria.to_data_table(controller, {}, &custom_block)
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should store it as an @extension" do
|
91
|
+
dt.extension.should == custom_block
|
92
|
+
end
|
93
|
+
|
94
|
+
describe "#to_hash" do
|
95
|
+
|
96
|
+
it "should run the custom block" do
|
97
|
+
dt.to_hash[:aaData].first.should == custom_array
|
98
|
+
end
|
99
|
+
|
100
|
+
context "with inline block" do
|
101
|
+
|
102
|
+
it "should run the inline block" do
|
103
|
+
a = custom_array.push('inline')
|
104
|
+
h = dt.to_hash { |object| a }
|
105
|
+
h[:aaData].first.should == a
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
69
114
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: mongoid-data_table
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.0.
|
5
|
+
version: 1.0.4
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Jason Dew
|
@@ -11,7 +11,7 @@ autorequire:
|
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
13
|
|
14
|
-
date: 2011-05-
|
14
|
+
date: 2011-05-23 00:00:00 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rails
|
@@ -19,20 +19,20 @@ dependencies:
|
|
19
19
|
requirement: &id001 !ruby/object:Gem::Requirement
|
20
20
|
none: false
|
21
21
|
requirements:
|
22
|
-
- -
|
22
|
+
- - ">="
|
23
23
|
- !ruby/object:Gem::Version
|
24
24
|
version: 3.0.0
|
25
25
|
type: :runtime
|
26
26
|
version_requirements: *id001
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: kaminari
|
29
29
|
prerelease: false
|
30
30
|
requirement: &id002 !ruby/object:Gem::Requirement
|
31
31
|
none: false
|
32
32
|
requirements:
|
33
33
|
- - ~>
|
34
34
|
- !ruby/object:Gem::Version
|
35
|
-
version:
|
35
|
+
version: 0.12.4
|
36
36
|
type: :runtime
|
37
37
|
version_requirements: *id002
|
38
38
|
- !ruby/object:Gem::Dependency
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
requirements:
|
44
44
|
- - ~>
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: 1.3.
|
46
|
+
version: 1.3.1
|
47
47
|
type: :development
|
48
48
|
version_requirements: *id003
|
49
49
|
- !ruby/object:Gem::Dependency
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
requirements:
|
55
55
|
- - ~>
|
56
56
|
- !ruby/object:Gem::Version
|
57
|
-
version: 2.0.
|
57
|
+
version: 2.0.2
|
58
58
|
type: :development
|
59
59
|
version_requirements: *id004
|
60
60
|
- !ruby/object:Gem::Dependency
|
@@ -122,7 +122,6 @@ files:
|
|
122
122
|
- Rakefile
|
123
123
|
- lib/mongoid-data_table.rb
|
124
124
|
- lib/mongoid/data_table.rb
|
125
|
-
- lib/mongoid/data_table/criteria.rb
|
126
125
|
- lib/mongoid/data_table/proxy.rb
|
127
126
|
- lib/mongoid/data_table/version.rb
|
128
127
|
- mongoid-data_table.gemspec
|
@@ -132,7 +131,6 @@ files:
|
|
132
131
|
- spec/models/user_agent.rb
|
133
132
|
- spec/spec_helper.rb
|
134
133
|
- spec/unit/mongoid-data_table_spec.rb
|
135
|
-
- spec/unit/mongoid/data_table/criteria_spec.rb
|
136
134
|
- spec/unit/mongoid/data_table/proxy_spec.rb
|
137
135
|
- spec/unit/mongoid/data_table_spec.rb
|
138
136
|
homepage: http://rubygems.org/gems/mongoid-data_table
|
@@ -158,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
158
156
|
requirements: []
|
159
157
|
|
160
158
|
rubyforge_project:
|
161
|
-
rubygems_version: 1.
|
159
|
+
rubygems_version: 1.8.3
|
162
160
|
signing_key:
|
163
161
|
specification_version: 3
|
164
162
|
summary: Simple data preparation from Mongoid to the jQuery DataTables plugin
|
@@ -169,7 +167,5 @@ test_files:
|
|
169
167
|
- spec/models/user_agent.rb
|
170
168
|
- spec/spec_helper.rb
|
171
169
|
- spec/unit/mongoid-data_table_spec.rb
|
172
|
-
- spec/unit/mongoid/data_table/criteria_spec.rb
|
173
170
|
- spec/unit/mongoid/data_table/proxy_spec.rb
|
174
171
|
- spec/unit/mongoid/data_table_spec.rb
|
175
|
-
has_rdoc:
|
@@ -1,31 +0,0 @@
|
|
1
|
-
module Mongoid
|
2
|
-
module DataTable
|
3
|
-
module Criteria
|
4
|
-
# do nothing
|
5
|
-
end
|
6
|
-
end
|
7
|
-
|
8
|
-
class Criteria
|
9
|
-
|
10
|
-
# Used for chaining +Criteria+ scopes together in the for of class methods
|
11
|
-
# on the +Document+ the criteria is for.
|
12
|
-
#
|
13
|
-
# Options:
|
14
|
-
#
|
15
|
-
# name: The name of the class method on the +Document+ to chain.
|
16
|
-
# args: The arguments passed to the method.
|
17
|
-
# block: Optional block to pass
|
18
|
-
#
|
19
|
-
# Returns: <tt>Criteria</tt>
|
20
|
-
def method_missing(name, *args, &block)
|
21
|
-
if @klass.respond_to?(name)
|
22
|
-
@klass.send(:with_scope, self) do
|
23
|
-
@klass.send(name, *args, &block)
|
24
|
-
end
|
25
|
-
else
|
26
|
-
return entries.send(name, *args)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Mongoid::DataTable::Criteria do
|
4
|
-
|
5
|
-
before do
|
6
|
-
Rails.stubs(:logger).returns(LOGGER)
|
7
|
-
end
|
8
|
-
|
9
|
-
let(:controller) do
|
10
|
-
Class.new(ActionController::Base).new.tap do |c|
|
11
|
-
c.stubs(:params).returns({})
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
let(:custom_array) { %w(custom) }
|
16
|
-
|
17
|
-
let(:custom_block) do
|
18
|
-
lambda { |object| custom_array }
|
19
|
-
end
|
20
|
-
|
21
|
-
context "with custom block" do
|
22
|
-
|
23
|
-
let(:bob) do
|
24
|
-
Person.find_or_create_by(:name => 'Bob')
|
25
|
-
end
|
26
|
-
|
27
|
-
let(:dt) do
|
28
|
-
bob
|
29
|
-
Person.criteria.to_data_table(controller, {}, &custom_block)
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should store it as an @extension" do
|
33
|
-
dt.extension.should == custom_block
|
34
|
-
end
|
35
|
-
|
36
|
-
describe "#to_hash" do
|
37
|
-
|
38
|
-
it "should run the custom block" do
|
39
|
-
dt.to_hash[:aaData].first.should == custom_array
|
40
|
-
end
|
41
|
-
|
42
|
-
context "with inline block" do
|
43
|
-
|
44
|
-
it "should run the inline block" do
|
45
|
-
a = custom_array.push('inline')
|
46
|
-
h = dt.to_hash { |object| a }
|
47
|
-
h[:aaData].first.should == a
|
48
|
-
end
|
49
|
-
|
50
|
-
end
|
51
|
-
|
52
|
-
end
|
53
|
-
|
54
|
-
end
|
55
|
-
|
56
|
-
end
|