mongoid_misc 0.0.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.
Files changed (42) hide show
  1. data/Rakefile +10 -0
  2. data/lib/carrierwave_ext/fixes.rb +12 -0
  3. data/lib/carrierwave_ext/micelaneous.rb +26 -0
  4. data/lib/carrierwave_ext/mongoid_embedded.rb +37 -0
  5. data/lib/carrierwave_ext/spec.rb +25 -0
  6. data/lib/carrierwave_ext.rb +17 -0
  7. data/lib/mongo_ext/spec.rb +11 -0
  8. data/lib/mongo_ext/upsert.rb +12 -0
  9. data/lib/mongo_ext.rb +3 -0
  10. data/lib/mongo_migration/adapters/mongoid.rb +9 -0
  11. data/lib/mongo_migration/definition.rb +19 -0
  12. data/lib/mongo_migration/migration.rb +71 -0
  13. data/lib/mongo_migration/tasks.rb +19 -0
  14. data/lib/mongo_migration.rb +14 -0
  15. data/lib/mongoid_misc/attribute_cache.rb +16 -0
  16. data/lib/mongoid_misc/attribute_convertors.rb +71 -0
  17. data/lib/mongoid_misc/belongs_to_with_counter_cache.rb +43 -0
  18. data/lib/mongoid_misc/gems.rb +16 -0
  19. data/lib/mongoid_misc/hacks.rb +43 -0
  20. data/lib/mongoid_misc/micelaneous.rb +91 -0
  21. data/lib/mongoid_misc/simple_finders.rb +44 -0
  22. data/lib/mongoid_misc/spec.rb +37 -0
  23. data/lib/mongoid_misc/support.rb +13 -0
  24. data/lib/mongoid_misc.rb +38 -0
  25. data/readme.md +85 -0
  26. data/spec/carrierwave_ext/mount_uploader_spec/plane.jpg +0 -0
  27. data/spec/carrierwave_ext/mount_uploader_spec/plane2.jpg +0 -0
  28. data/spec/carrierwave_ext/mount_uploader_spec.rb +158 -0
  29. data/spec/carrierwave_ext/spec_helper.rb +7 -0
  30. data/spec/carrierwave_ext/uploader_spec/ship.jpg +0 -0
  31. data/spec/carrierwave_ext/uploader_spec//321/204/320/260/320/270/314/206/320/273 /321/201 /320/277/321/200/320/276/320/261/320/265/320/273/320/260/320/274/320/270.txt" +1 -0
  32. data/spec/carrierwave_ext/uploader_spec.rb +61 -0
  33. data/spec/mongo_ext/spec_helper.rb +4 -0
  34. data/spec/mongo_ext/upsert_spec.rb +20 -0
  35. data/spec/mongo_migration/basic_spec.rb +110 -0
  36. data/spec/mongo_migration/spec_helper.rb +5 -0
  37. data/spec/mongoid_misc/attribute_convertors_spec.rb +70 -0
  38. data/spec/mongoid_misc/belongs_to_with_counter_cache_spec.rb +41 -0
  39. data/spec/mongoid_misc/micelaneous_spec.rb +92 -0
  40. data/spec/mongoid_misc/simple_finders_spec.rb +56 -0
  41. data/spec/mongoid_misc/spec_helper.rb +4 -0
  42. metadata +208 -0
@@ -0,0 +1,92 @@
1
+ require 'mongoid_misc/spec_helper'
2
+
3
+ describe "Micelaneous" do
4
+ with_mongoid
5
+
6
+ after(:all){remove_constants %w(UpsertSample AsStringSample TranslationCheck Article Post Namespace AliasTest)}
7
+
8
+ # describe "Database aliases" do
9
+ # it "basics" do
10
+ # Mongoid.set_database_aliases default: 'default_production', global: 'global_production'
11
+ #
12
+ # klass = class ::AliasTest
13
+ # include Mongoid::Document
14
+ # end
15
+ #
16
+ # klass.should_receive(:set_database).with('global_production')
17
+ # klass._set_database_alias :global
18
+ #
19
+ # -> {klass._set_database_alias :invalid_alias}.should raise_error(/unknown database alias/)
20
+ # end
21
+ # end
22
+
23
+ describe "i18n" do
24
+ it "should translate error messages" do
25
+ class ::TranslationCheck
26
+ include Mongoid::Document
27
+
28
+ field :name, default: String
29
+ validates_uniqueness_of :name
30
+ end
31
+
32
+ TranslationCheck.destroy_all
33
+ TranslationCheck.create! name: 'a'
34
+ t = TranslationCheck.new name: 'a'
35
+ t.should_not be_valid
36
+ t.errors[:name].first.should =~ /already taken/
37
+ end
38
+ end
39
+
40
+ describe "handy upsert" do
41
+ class ::UpsertSample
42
+ include Mongoid::Document
43
+
44
+ field :counter, type: Integer, default: 1
45
+ end
46
+
47
+ before do
48
+ @model = UpsertSample.create!
49
+ end
50
+
51
+ it "class upsert" do
52
+ UpsertSample.upsert!({id: @model.id}, :$inc => {counter: 1})
53
+ @model.reload
54
+ @model.counter.should == 2
55
+ end
56
+
57
+ it "model upsert" do
58
+ @model.upsert! :$inc => {counter: 1}
59
+ @model.reload
60
+ @model.counter.should == 2
61
+ end
62
+ end
63
+
64
+ describe "model_name" do
65
+ it "basic" do
66
+ class Article
67
+ include Mongoid::Document
68
+ end
69
+
70
+ Article.model_name.should == "Article"
71
+ Article.model_name "SuperArticle"
72
+ Article.model_name.should == "SuperArticle"
73
+ end
74
+
75
+ it "by default should be initialized from class alias" do
76
+ class ::Post
77
+ include Mongoid::Document
78
+
79
+ self.alias 'PostAlias'
80
+ end
81
+
82
+ module ::Namespace
83
+ class Post
84
+ include Mongoid::Document
85
+ end
86
+ end
87
+
88
+ Post.model_name.should == 'PostAlias'
89
+ Namespace::Post.model_name.should == 'Post' # not the Namespace::Post
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,56 @@
1
+ require 'mongoid_misc/spec_helper'
2
+
3
+ describe "Simple Finders" do
4
+ with_mongoid
5
+
6
+ before :all do
7
+ class User
8
+ include Mongoid::Document
9
+
10
+ field :name, default: String
11
+ end
12
+ end
13
+ after(:all){remove_constants :User}
14
+
15
+ it "find, first, by" do
16
+ User.find_by_name('John').should be_nil
17
+ -> {User.find_by_name!('John')}.should raise_error(Mongoid::Errors::DocumentNotFound)
18
+ User.by_name('John').should be_nil
19
+ -> {User.by_name!('John')}.should raise_error(Mongoid::Errors::DocumentNotFound)
20
+ User.first_by_name('John').should be_nil
21
+ -> {User.first_by_name!('John')}.should raise_error(Mongoid::Errors::DocumentNotFound)
22
+
23
+ john = User.create! name: 'John'
24
+
25
+ User.find_by_name('John').should == john
26
+ User.find_by_name!('John').should == john
27
+ User.by_name('John').should == john
28
+ User.by_name!('John').should == john
29
+ User.first_by_name('John').should == john
30
+ User.first_by_name!('John').should == john
31
+ end
32
+
33
+ it "all" do
34
+ User.all_by_name('John').should == []
35
+ john = User.create! name: 'John'
36
+ User.all_by_name('John').should == [john]
37
+ end
38
+
39
+ it "should allow to use bang version only with :first" do
40
+ -> {User.all_by_name!('John')}.should raise_error(/can't use bang/)
41
+ end
42
+
43
+ it "by_id (special case)" do
44
+ User.method(:by_id).should == User.method(:find_by_id)
45
+ User.method(:by_id!).should == User.method(:find_by_id!)
46
+
47
+ User.by_id('4de81858cf26bde569000009').should be_nil
48
+ -> {User.by_id!('4de81858cf26bde569000009')}.should raise_error(Mongoid::Errors::DocumentNotFound)
49
+
50
+ john = User.create! name: 'John'
51
+
52
+ User.by_id(john.id).should == john
53
+ User.by_id(john.id.to_s).should == john
54
+ User.by_id!(john.id).should == john
55
+ end
56
+ end
@@ -0,0 +1,4 @@
1
+ require "mongoid_misc"
2
+
3
+ require 'rspec_ext'
4
+ require "mongoid_misc/spec"
metadata ADDED
@@ -0,0 +1,208 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mongoid_misc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Alexey Petrushin
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-07-04 00:00:00.000000000 +04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: i18n
17
+ requirement: &2956320 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - =
21
+ - !ruby/object:Gem::Version
22
+ version: 0.5.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *2956320
26
+ - !ruby/object:Gem::Dependency
27
+ name: activesupport
28
+ requirement: &2956000 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - =
32
+ - !ruby/object:Gem::Version
33
+ version: 3.0.7
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: *2956000
37
+ - !ruby/object:Gem::Dependency
38
+ name: activemodel
39
+ requirement: &2955750 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - =
43
+ - !ruby/object:Gem::Version
44
+ version: 3.0.7
45
+ type: :runtime
46
+ prerelease: false
47
+ version_requirements: *2955750
48
+ - !ruby/object:Gem::Dependency
49
+ name: bson
50
+ requirement: &2955530 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - =
54
+ - !ruby/object:Gem::Version
55
+ version: 1.3.1
56
+ type: :runtime
57
+ prerelease: false
58
+ version_requirements: *2955530
59
+ - !ruby/object:Gem::Dependency
60
+ name: bson_ext
61
+ requirement: &2955300 !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - =
65
+ - !ruby/object:Gem::Version
66
+ version: 1.3.1
67
+ type: :runtime
68
+ prerelease: false
69
+ version_requirements: *2955300
70
+ - !ruby/object:Gem::Dependency
71
+ name: mongo
72
+ requirement: &2955070 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - =
76
+ - !ruby/object:Gem::Version
77
+ version: 1.3.0
78
+ type: :runtime
79
+ prerelease: false
80
+ version_requirements: *2955070
81
+ - !ruby/object:Gem::Dependency
82
+ name: will_paginate
83
+ requirement: &2954790 !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - =
87
+ - !ruby/object:Gem::Version
88
+ version: 2.3.15
89
+ type: :runtime
90
+ prerelease: false
91
+ version_requirements: *2954790
92
+ - !ruby/object:Gem::Dependency
93
+ name: mini_magick
94
+ requirement: &2954510 !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - =
98
+ - !ruby/object:Gem::Version
99
+ version: 3.2.1
100
+ type: :runtime
101
+ prerelease: false
102
+ version_requirements: *2954510
103
+ - !ruby/object:Gem::Dependency
104
+ name: subexec
105
+ requirement: &2954300 !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - =
109
+ - !ruby/object:Gem::Version
110
+ version: 0.0.4
111
+ type: :runtime
112
+ prerelease: false
113
+ version_requirements: *2954300
114
+ - !ruby/object:Gem::Dependency
115
+ name: mongoid
116
+ requirement: &2954010 !ruby/object:Gem::Requirement
117
+ none: false
118
+ requirements:
119
+ - - =
120
+ - !ruby/object:Gem::Version
121
+ version: 2.0.2
122
+ type: :runtime
123
+ prerelease: false
124
+ version_requirements: *2954010
125
+ - !ruby/object:Gem::Dependency
126
+ name: carrierwave
127
+ requirement: &2953670 !ruby/object:Gem::Requirement
128
+ none: false
129
+ requirements:
130
+ - - =
131
+ - !ruby/object:Gem::Version
132
+ version: 0.5.4
133
+ type: :runtime
134
+ prerelease: false
135
+ version_requirements: *2953670
136
+ description:
137
+ email:
138
+ executables: []
139
+ extensions: []
140
+ extra_rdoc_files: []
141
+ files:
142
+ - Rakefile
143
+ - readme.md
144
+ - lib/carrierwave_ext/fixes.rb
145
+ - lib/carrierwave_ext/micelaneous.rb
146
+ - lib/carrierwave_ext/mongoid_embedded.rb
147
+ - lib/carrierwave_ext/spec.rb
148
+ - lib/carrierwave_ext.rb
149
+ - lib/mongo_ext/spec.rb
150
+ - lib/mongo_ext/upsert.rb
151
+ - lib/mongo_ext.rb
152
+ - lib/mongo_migration/adapters/mongoid.rb
153
+ - lib/mongo_migration/definition.rb
154
+ - lib/mongo_migration/migration.rb
155
+ - lib/mongo_migration/tasks.rb
156
+ - lib/mongo_migration.rb
157
+ - lib/mongoid_misc/attribute_cache.rb
158
+ - lib/mongoid_misc/attribute_convertors.rb
159
+ - lib/mongoid_misc/belongs_to_with_counter_cache.rb
160
+ - lib/mongoid_misc/gems.rb
161
+ - lib/mongoid_misc/hacks.rb
162
+ - lib/mongoid_misc/micelaneous.rb
163
+ - lib/mongoid_misc/simple_finders.rb
164
+ - lib/mongoid_misc/spec.rb
165
+ - lib/mongoid_misc/support.rb
166
+ - lib/mongoid_misc.rb
167
+ - spec/carrierwave_ext/mount_uploader_spec/plane.jpg
168
+ - spec/carrierwave_ext/mount_uploader_spec/plane2.jpg
169
+ - spec/carrierwave_ext/mount_uploader_spec.rb
170
+ - spec/carrierwave_ext/spec_helper.rb
171
+ - spec/carrierwave_ext/uploader_spec/ship.jpg
172
+ - spec/carrierwave_ext/uploader_spec/файл с пробелами.txt
173
+ - spec/carrierwave_ext/uploader_spec.rb
174
+ - spec/mongo_ext/spec_helper.rb
175
+ - spec/mongo_ext/upsert_spec.rb
176
+ - spec/mongo_migration/basic_spec.rb
177
+ - spec/mongo_migration/spec_helper.rb
178
+ - spec/mongoid_misc/attribute_convertors_spec.rb
179
+ - spec/mongoid_misc/belongs_to_with_counter_cache_spec.rb
180
+ - spec/mongoid_misc/micelaneous_spec.rb
181
+ - spec/mongoid_misc/simple_finders_spec.rb
182
+ - spec/mongoid_misc/spec_helper.rb
183
+ has_rdoc: true
184
+ homepage: http://github.com/alexeypetrushin/mongoid_misc
185
+ licenses: []
186
+ post_install_message:
187
+ rdoc_options: []
188
+ require_paths:
189
+ - lib
190
+ required_ruby_version: !ruby/object:Gem::Requirement
191
+ none: false
192
+ requirements:
193
+ - - ! '>='
194
+ - !ruby/object:Gem::Version
195
+ version: '0'
196
+ required_rubygems_version: !ruby/object:Gem::Requirement
197
+ none: false
198
+ requirements:
199
+ - - ! '>='
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ requirements: []
203
+ rubyforge_project:
204
+ rubygems_version: 1.5.1
205
+ signing_key:
206
+ specification_version: 3
207
+ summary: Extensions for Mongoid
208
+ test_files: []