mongoid_ext 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +20 -0
- data/Gemfile.lock +50 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +44 -0
- data/VERSION +1 -0
- data/bin/mongoid_console +85 -0
- data/lib/mongoid_ext.rb +71 -0
- data/lib/mongoid_ext/criteria_ext.rb +15 -0
- data/lib/mongoid_ext/document_ext.rb +29 -0
- data/lib/mongoid_ext/file.rb +86 -0
- data/lib/mongoid_ext/file_list.rb +74 -0
- data/lib/mongoid_ext/file_server.rb +69 -0
- data/lib/mongoid_ext/filter.rb +266 -0
- data/lib/mongoid_ext/filter/parser.rb +71 -0
- data/lib/mongoid_ext/filter/result_set.rb +75 -0
- data/lib/mongoid_ext/js/filter.js +41 -0
- data/lib/mongoid_ext/js/find_tags.js +26 -0
- data/lib/mongoid_ext/js/tag_cloud.js +28 -0
- data/lib/mongoid_ext/modifiers.rb +93 -0
- data/lib/mongoid_ext/mongo_mapper.rb +63 -0
- data/lib/mongoid_ext/paranoia.rb +100 -0
- data/lib/mongoid_ext/patches.rb +17 -0
- data/lib/mongoid_ext/random.rb +23 -0
- data/lib/mongoid_ext/slugizer.rb +84 -0
- data/lib/mongoid_ext/storage.rb +110 -0
- data/lib/mongoid_ext/tags.rb +26 -0
- data/lib/mongoid_ext/types/embedded_hash.rb +25 -0
- data/lib/mongoid_ext/types/open_struct.rb +15 -0
- data/lib/mongoid_ext/types/timestamp.rb +15 -0
- data/lib/mongoid_ext/types/translation.rb +51 -0
- data/lib/mongoid_ext/update.rb +11 -0
- data/lib/mongoid_ext/versioning.rb +189 -0
- data/lib/mongoid_ext/voteable.rb +104 -0
- data/mongoid_ext.gemspec +129 -0
- data/test/helper.rb +30 -0
- data/test/models.rb +80 -0
- data/test/support/custom_matchers.rb +55 -0
- data/test/test_filter.rb +51 -0
- data/test/test_modifiers.rb +65 -0
- data/test/test_paranoia.rb +40 -0
- data/test/test_random.rb +57 -0
- data/test/test_slugizer.rb +66 -0
- data/test/test_storage.rb +110 -0
- data/test/test_tags.rb +47 -0
- data/test/test_update.rb +16 -0
- data/test/test_versioning.rb +55 -0
- data/test/test_voteable.rb +77 -0
- data/test/types/test_open_struct.rb +22 -0
- data/test/types/test_set.rb +26 -0
- data/test/types/test_timestamp.rb +40 -0
- metadata +301 -0
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestVoteable < Test::Unit::TestCase
|
4
|
+
context "working with votes" do
|
5
|
+
setup do
|
6
|
+
User.delete_all
|
7
|
+
@user = User.create!(:login => "foo", :email => "foo@bar.baz")
|
8
|
+
end
|
9
|
+
|
10
|
+
should "store the votes average" do
|
11
|
+
@user.vote!(1, "voter_id1")
|
12
|
+
@user.vote!(1, "voter_id2")
|
13
|
+
@user.vote!(-1, "voter_id3")
|
14
|
+
|
15
|
+
@user.reload
|
16
|
+
@user.votes_average.should == 1
|
17
|
+
end
|
18
|
+
|
19
|
+
should "store the votes count" do
|
20
|
+
@user.vote!(1, "voter_id1")
|
21
|
+
@user.vote!(1, "voter_id2")
|
22
|
+
@user.vote!(-1, "voter_id3")
|
23
|
+
@user.vote!(-1, "voter_id4")
|
24
|
+
|
25
|
+
@user.reload
|
26
|
+
@user.votes_count.should == 4
|
27
|
+
end
|
28
|
+
|
29
|
+
should "only store one vote by voter_id" do
|
30
|
+
@user.vote!(1, "voter_id1")
|
31
|
+
@user.vote!(1, "voter_id1")
|
32
|
+
@user.vote!(1, "voter_id1")
|
33
|
+
@user.reload
|
34
|
+
@user.votes_count.should == 1
|
35
|
+
end
|
36
|
+
|
37
|
+
should "allow to change the vote" do
|
38
|
+
@user.vote!(1, "voter_id1")
|
39
|
+
@user.vote!(-1, "voter_id1")
|
40
|
+
|
41
|
+
@user.reload
|
42
|
+
@user.votes_count.should == 1
|
43
|
+
@user.votes_average.should == -1
|
44
|
+
end
|
45
|
+
|
46
|
+
should "count the votes" do
|
47
|
+
@user.vote!(1, "voter_id1")
|
48
|
+
@user.vote!(1, "voter_id2")
|
49
|
+
@user.vote!(-1, "voter_id3")
|
50
|
+
@user.vote!(-1, "voter_id4")
|
51
|
+
@user.vote!(-1, "voter_id5")
|
52
|
+
|
53
|
+
@user.reload
|
54
|
+
@user.votes_average.should == -1
|
55
|
+
@user.votes_up.should == 2
|
56
|
+
@user.votes_down.should == 3
|
57
|
+
end
|
58
|
+
|
59
|
+
should "check if a voter_id already voted" do
|
60
|
+
@user.vote!("1", "voter_id1")
|
61
|
+
@user.vote!("1", "voter_id2")
|
62
|
+
|
63
|
+
@user.voted?("voter_id1").should be_true
|
64
|
+
@user.reload
|
65
|
+
@user.voted?("voter_id1").should be_true
|
66
|
+
@user.voted?("voter_id3").should be_false
|
67
|
+
end
|
68
|
+
|
69
|
+
should "check the voter id even if votes was not loaded" do
|
70
|
+
@user.vote!("1", "voter_id1")
|
71
|
+
@user = User.without(:votes).find(@user.id)
|
72
|
+
@user.voted?("voter_id1").should be_true
|
73
|
+
@user.voted?("voter_id2").should be_false
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class OpenStructTest < Test::Unit::TestCase
|
4
|
+
def from_db
|
5
|
+
UserConfig.find(@config.id)
|
6
|
+
end
|
7
|
+
|
8
|
+
context "working with sets" do
|
9
|
+
setup do
|
10
|
+
@config = UserConfig.create!()
|
11
|
+
end
|
12
|
+
|
13
|
+
should "allow to add new keys" do
|
14
|
+
entries = OpenStruct.new()
|
15
|
+
entries.new_key = "my new key"
|
16
|
+
@config.entries = entries
|
17
|
+
@config.save
|
18
|
+
|
19
|
+
from_db.entries["new_key"].should == "my new key"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class SetTest < Test::Unit::TestCase
|
4
|
+
def from_db
|
5
|
+
Recipe.find(@recipe.id)
|
6
|
+
end
|
7
|
+
|
8
|
+
context "working with sets" do
|
9
|
+
setup do
|
10
|
+
@recipe = Recipe.create!(:ingredients => %w[salt sugar water salt sugar water])
|
11
|
+
end
|
12
|
+
|
13
|
+
should "not have duplicates" do
|
14
|
+
from_db.ingredients.size.should == 3
|
15
|
+
from_db.ingredients.should include("salt")
|
16
|
+
from_db.ingredients.should include("sugar")
|
17
|
+
from_db.ingredients.should include("water")
|
18
|
+
end
|
19
|
+
|
20
|
+
should "not add duplicates" do
|
21
|
+
original_size = @recipe.ingredients.size
|
22
|
+
@recipe.ingredients << "salt"
|
23
|
+
@recipe.ingredients.size.should == original_size
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TimestampTest < Test::Unit::TestCase
|
4
|
+
def from_db
|
5
|
+
Event.find(@event.id)
|
6
|
+
end
|
7
|
+
|
8
|
+
context "working with timestamps" do
|
9
|
+
setup do
|
10
|
+
Event.delete_all
|
11
|
+
|
12
|
+
Time.zone = 'UTC'
|
13
|
+
@start_time = Time.zone.parse('01-01-2009')
|
14
|
+
@end_time = @start_time.tomorrow
|
15
|
+
|
16
|
+
@event = Event.create!(:start_date => @start_time.to_i, :end_date => @end_time.to_i)
|
17
|
+
end
|
18
|
+
|
19
|
+
should "store the date" do
|
20
|
+
from_db.start_date.to_s.should == @start_time.to_s
|
21
|
+
end
|
22
|
+
|
23
|
+
should "be able to convert the time to the given timezone" do
|
24
|
+
Time.zone = 'Hawaii'
|
25
|
+
from_db.start_date.to_s.should == "2008-12-31 14:00:00 -1000"
|
26
|
+
end
|
27
|
+
|
28
|
+
should "be able to compare dates" do
|
29
|
+
start_time = @start_time.tomorrow.tomorrow
|
30
|
+
end_time = start_time.tomorrow
|
31
|
+
|
32
|
+
@event2 = Event.create!(:start_date => start_time.utc, :end_datime => end_time.utc)
|
33
|
+
|
34
|
+
Event.count.should == 2
|
35
|
+
events = Event.all(:conditions => {:$where => ("this.start_date >= %d && this.start_date <= %d" % [@event.start_date.yesterday.to_i, @event2.start_date.yesterday.to_i])})
|
36
|
+
|
37
|
+
events.should == [@event]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
metadata
ADDED
@@ -0,0 +1,301 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mongoid_ext
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 6
|
8
|
+
- 1
|
9
|
+
version: 0.6.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- David A. Cuadrado
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-06-25 00:00:00 -05:00
|
18
|
+
default_executable: mongoid_console
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: mongoid
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 2
|
29
|
+
version: "2"
|
30
|
+
type: :runtime
|
31
|
+
prerelease: false
|
32
|
+
version_requirements: *id001
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: uuidtools
|
35
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
segments:
|
41
|
+
- 2
|
42
|
+
- 1
|
43
|
+
- 1
|
44
|
+
version: 2.1.1
|
45
|
+
type: :runtime
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: i18n
|
50
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
segments:
|
56
|
+
- 0
|
57
|
+
version: "0"
|
58
|
+
type: :runtime
|
59
|
+
prerelease: false
|
60
|
+
version_requirements: *id003
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: tzinfo
|
63
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
segments:
|
69
|
+
- 0
|
70
|
+
version: "0"
|
71
|
+
type: :runtime
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: *id004
|
74
|
+
- !ruby/object:Gem::Dependency
|
75
|
+
name: differ
|
76
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
segments:
|
82
|
+
- 0
|
83
|
+
- 1
|
84
|
+
- 2
|
85
|
+
version: 0.1.2
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: *id005
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: yard
|
91
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
92
|
+
none: false
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
segments:
|
97
|
+
- 0
|
98
|
+
- 6
|
99
|
+
- 0
|
100
|
+
version: 0.6.0
|
101
|
+
type: :development
|
102
|
+
prerelease: false
|
103
|
+
version_requirements: *id006
|
104
|
+
- !ruby/object:Gem::Dependency
|
105
|
+
name: bundler
|
106
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
107
|
+
none: false
|
108
|
+
requirements:
|
109
|
+
- - ~>
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
segments:
|
112
|
+
- 1
|
113
|
+
- 0
|
114
|
+
- 0
|
115
|
+
version: 1.0.0
|
116
|
+
type: :development
|
117
|
+
prerelease: false
|
118
|
+
version_requirements: *id007
|
119
|
+
- !ruby/object:Gem::Dependency
|
120
|
+
name: jeweler
|
121
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
123
|
+
requirements:
|
124
|
+
- - ~>
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
segments:
|
127
|
+
- 1
|
128
|
+
- 5
|
129
|
+
- 2
|
130
|
+
version: 1.5.2
|
131
|
+
type: :development
|
132
|
+
prerelease: false
|
133
|
+
version_requirements: *id008
|
134
|
+
- !ruby/object:Gem::Dependency
|
135
|
+
name: shoulda
|
136
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ~>
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
segments:
|
142
|
+
- 2
|
143
|
+
- 11
|
144
|
+
- 3
|
145
|
+
version: 2.11.3
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: *id009
|
149
|
+
- !ruby/object:Gem::Dependency
|
150
|
+
name: jnunemaker-matchy
|
151
|
+
requirement: &id010 !ruby/object:Gem::Requirement
|
152
|
+
none: false
|
153
|
+
requirements:
|
154
|
+
- - ~>
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
segments:
|
157
|
+
- 0
|
158
|
+
- 4
|
159
|
+
version: "0.4"
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: *id010
|
163
|
+
- !ruby/object:Gem::Dependency
|
164
|
+
name: shoulda
|
165
|
+
requirement: &id011 !ruby/object:Gem::Requirement
|
166
|
+
none: false
|
167
|
+
requirements:
|
168
|
+
- - ~>
|
169
|
+
- !ruby/object:Gem::Version
|
170
|
+
segments:
|
171
|
+
- 2
|
172
|
+
- 11
|
173
|
+
- 3
|
174
|
+
version: 2.11.3
|
175
|
+
type: :development
|
176
|
+
prerelease: false
|
177
|
+
version_requirements: *id011
|
178
|
+
- !ruby/object:Gem::Dependency
|
179
|
+
name: mocha
|
180
|
+
requirement: &id012 !ruby/object:Gem::Requirement
|
181
|
+
none: false
|
182
|
+
requirements:
|
183
|
+
- - ~>
|
184
|
+
- !ruby/object:Gem::Version
|
185
|
+
segments:
|
186
|
+
- 0
|
187
|
+
- 9
|
188
|
+
- 4
|
189
|
+
version: 0.9.4
|
190
|
+
type: :development
|
191
|
+
prerelease: false
|
192
|
+
version_requirements: *id012
|
193
|
+
- !ruby/object:Gem::Dependency
|
194
|
+
name: timecop
|
195
|
+
requirement: &id013 !ruby/object:Gem::Requirement
|
196
|
+
none: false
|
197
|
+
requirements:
|
198
|
+
- - ">="
|
199
|
+
- !ruby/object:Gem::Version
|
200
|
+
segments:
|
201
|
+
- 0
|
202
|
+
version: "0"
|
203
|
+
type: :development
|
204
|
+
prerelease: false
|
205
|
+
version_requirements: *id013
|
206
|
+
description: mongoid plugins
|
207
|
+
email: krawek@gmail.com
|
208
|
+
executables:
|
209
|
+
- mongoid_console
|
210
|
+
extensions: []
|
211
|
+
|
212
|
+
extra_rdoc_files:
|
213
|
+
- LICENSE
|
214
|
+
- README.rdoc
|
215
|
+
files:
|
216
|
+
- .document
|
217
|
+
- Gemfile
|
218
|
+
- Gemfile.lock
|
219
|
+
- LICENSE
|
220
|
+
- README.rdoc
|
221
|
+
- Rakefile
|
222
|
+
- VERSION
|
223
|
+
- bin/mongoid_console
|
224
|
+
- lib/mongoid_ext.rb
|
225
|
+
- lib/mongoid_ext/criteria_ext.rb
|
226
|
+
- lib/mongoid_ext/document_ext.rb
|
227
|
+
- lib/mongoid_ext/file.rb
|
228
|
+
- lib/mongoid_ext/file_list.rb
|
229
|
+
- lib/mongoid_ext/file_server.rb
|
230
|
+
- lib/mongoid_ext/filter.rb
|
231
|
+
- lib/mongoid_ext/filter/parser.rb
|
232
|
+
- lib/mongoid_ext/filter/result_set.rb
|
233
|
+
- lib/mongoid_ext/js/filter.js
|
234
|
+
- lib/mongoid_ext/js/find_tags.js
|
235
|
+
- lib/mongoid_ext/js/tag_cloud.js
|
236
|
+
- lib/mongoid_ext/modifiers.rb
|
237
|
+
- lib/mongoid_ext/mongo_mapper.rb
|
238
|
+
- lib/mongoid_ext/paranoia.rb
|
239
|
+
- lib/mongoid_ext/patches.rb
|
240
|
+
- lib/mongoid_ext/random.rb
|
241
|
+
- lib/mongoid_ext/slugizer.rb
|
242
|
+
- lib/mongoid_ext/storage.rb
|
243
|
+
- lib/mongoid_ext/tags.rb
|
244
|
+
- lib/mongoid_ext/types/embedded_hash.rb
|
245
|
+
- lib/mongoid_ext/types/open_struct.rb
|
246
|
+
- lib/mongoid_ext/types/timestamp.rb
|
247
|
+
- lib/mongoid_ext/types/translation.rb
|
248
|
+
- lib/mongoid_ext/update.rb
|
249
|
+
- lib/mongoid_ext/versioning.rb
|
250
|
+
- lib/mongoid_ext/voteable.rb
|
251
|
+
- mongoid_ext.gemspec
|
252
|
+
- test/helper.rb
|
253
|
+
- test/models.rb
|
254
|
+
- test/support/custom_matchers.rb
|
255
|
+
- test/test_filter.rb
|
256
|
+
- test/test_modifiers.rb
|
257
|
+
- test/test_paranoia.rb
|
258
|
+
- test/test_random.rb
|
259
|
+
- test/test_slugizer.rb
|
260
|
+
- test/test_storage.rb
|
261
|
+
- test/test_tags.rb
|
262
|
+
- test/test_update.rb
|
263
|
+
- test/test_versioning.rb
|
264
|
+
- test/test_voteable.rb
|
265
|
+
- test/types/test_open_struct.rb
|
266
|
+
- test/types/test_set.rb
|
267
|
+
- test/types/test_timestamp.rb
|
268
|
+
has_rdoc: true
|
269
|
+
homepage: http://github.com/dcu/mongoid_ext
|
270
|
+
licenses: []
|
271
|
+
|
272
|
+
post_install_message:
|
273
|
+
rdoc_options: []
|
274
|
+
|
275
|
+
require_paths:
|
276
|
+
- lib
|
277
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
278
|
+
none: false
|
279
|
+
requirements:
|
280
|
+
- - ">="
|
281
|
+
- !ruby/object:Gem::Version
|
282
|
+
segments:
|
283
|
+
- 0
|
284
|
+
version: "0"
|
285
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
286
|
+
none: false
|
287
|
+
requirements:
|
288
|
+
- - ">="
|
289
|
+
- !ruby/object:Gem::Version
|
290
|
+
segments:
|
291
|
+
- 0
|
292
|
+
version: "0"
|
293
|
+
requirements: []
|
294
|
+
|
295
|
+
rubyforge_project:
|
296
|
+
rubygems_version: 1.3.7
|
297
|
+
signing_key:
|
298
|
+
specification_version: 3
|
299
|
+
summary: mongoid plugins
|
300
|
+
test_files: []
|
301
|
+
|