mongo_mapper_ext 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (26) hide show
  1. data/Rakefile +2 -2
  2. data/lib/mongo_mapper_ext/carrier_wave.rb +4 -2
  3. data/lib/mongo_mapper_ext/carrier_wave/mongo_mapper/plugins/mount_uploader.rb +31 -0
  4. data/lib/mongo_mapper_ext/carrier_wave/mongo_mapper/plugins/mount_uploaders.rb +137 -0
  5. data/lib/mongo_mapper_ext/gems.rb +6 -7
  6. data/lib/mongo_mapper_ext/mongo_mapper.rb +12 -9
  7. data/lib/mongo_mapper_ext/mongo_mapper/fixes.rb +13 -21
  8. data/lib/mongo_mapper_ext/mongo_mapper/hacks.rb +59 -0
  9. data/lib/mongo_mapper_ext/mongo_mapper/plugins/attribute_cache.rb +14 -18
  10. data/lib/mongo_mapper_ext/mongo_mapper/plugins/attribute_convertors.rb +69 -73
  11. data/lib/mongo_mapper_ext/mongo_mapper/plugins/belongs_to_with_counter_cache.rb +33 -37
  12. data/lib/mongo_mapper_ext/mongo_mapper/plugins/custom_scope.rb +67 -71
  13. data/lib/mongo_mapper_ext/mongo_mapper/plugins/db_config.rb +27 -24
  14. data/lib/mongo_mapper_ext/mongo_mapper/plugins/micelaneous.rb +46 -50
  15. data/lib/mongo_mapper_ext/rad.rb +3 -0
  16. data/lib/mongo_mapper_ext/rad/file_uploader.rb +21 -23
  17. data/readme.md +1 -1
  18. data/spec/carrier_wave/carrier_wave_spec.rb +82 -27
  19. data/spec/mongo_mapper/mongo_mapper_spec.rb +28 -27
  20. data/spec/rad/uploading_spec.rb +1 -1
  21. metadata +106 -112
  22. data/lib/mongo_mapper_ext/carrier_wave/mongo_mapper/plugins/carrier_wave.rb +0 -41
  23. data/lib/mongo_mapper_ext/mongo_mapper/locales/activemodel/ru.yml +0 -27
  24. data/lib/mongo_mapper_ext/mongo_mapper/locales/mongo_mapper/en.yml +0 -4
  25. data/lib/mongo_mapper_ext/mongo_mapper/locales/mongo_mapper/ru.yml +0 -4
  26. data/lib/mongo_mapper_ext/mongo_mapper/logging.rb +0 -75
data/readme.md CHANGED
@@ -63,7 +63,7 @@ For editing complex objects in forms:
63
63
  File attachments (stored on File System, S3, MongoDB-GridFS)
64
64
 
65
65
  class User
66
- mount_uploader :avatar, AvatarUploader
66
+ file_key :avatar, AvatarUploader
67
67
  end
68
68
 
69
69
  ## more
@@ -5,57 +5,112 @@ describe "MongoMapper & CarrierWave" do
5
5
  with_tmp_spec_dir
6
6
 
7
7
  before :all do
8
- class PlaneUploader < CarrierWave::Uploader::Base
8
+ class PlaneImageUploader < CarrierWave::Uploader::Base
9
9
  require 'carrierwave/processing/mini_magick'
10
10
 
11
11
  include CarrierWave::MiniMagick
12
-
12
+
13
13
  storage :file
14
-
14
+
15
15
  version :icon do
16
16
  process convert: :png
17
17
  process resize_to_fit: [50, 50]
18
18
  end
19
-
19
+
20
20
  class << self
21
21
  attr_accessor :store_dir
22
22
  end
23
-
23
+
24
24
  def store_dir
25
- PlaneUploader.store_dir
25
+ PlaneImageUploader.store_dir
26
26
  end
27
-
27
+
28
28
  def root
29
- PlaneUploader.store_dir
29
+ PlaneImageUploader.store_dir
30
30
  end
31
- end
32
-
33
- class Plane
34
- include MongoMapper::Document
35
-
36
- mount_uploader :image, PlaneUploader
37
31
  end
38
32
  end
39
- after(:all){remove_constants :Plane, :PlaneUploader}
33
+ after(:all){remove_constants :PlaneImageUploader}
40
34
 
41
35
  before do
42
- PlaneUploader.store_dir = "#{spec_dir}/data"
36
+ PlaneImageUploader.store_dir = "#{spec_dir}/data"
43
37
  @file = File.new "#{spec_dir}/plane.jpg"
44
38
  end
45
39
  after{@file.close}
46
40
 
47
- it "basic" do
48
- plane = Plane.create! image: @file
49
- plane.image.current_path.should =~ /\/plane.jpg/
50
- File.should exist("#{spec_dir}/data/plane.jpg")
51
- end
41
+ describe "Document" do
42
+ before :all do
43
+ class Plane
44
+ include MongoMapper::Document
45
+
46
+ mount_uploader :image, PlaneImageUploader
47
+ end
48
+ end
49
+ after(:all){remove_constants :Plane}
50
+
51
+ it "basic" do
52
+ plane = Plane.create! image: @file
53
+ plane.image.current_path.should =~ /\/plane.jpg/
54
+ File.should exist("#{spec_dir}/data/plane.jpg")
55
+ end
56
+
57
+ it "should works without model" do
58
+ # writing
59
+ uploader = PlaneImageUploader.new
60
+ uploader.store!(@file)
61
+ uploader.identifier.should == 'plane.jpg'
62
+ uploader.url.should == '/plane.jpg'
63
+ uploader.icon.url.should == '/plane.icon.jpg'
64
+ File.should exist("#{spec_dir}/data/plane.icon.jpg")
65
+
66
+ # reading
67
+ uploader = PlaneImageUploader.new
68
+ uploader.retrieve_from_store! 'plane.jpg'
69
+ uploader.url.should == '/plane.jpg'
70
+ uploader.icon.url.should == '/plane.icon.jpg'
71
+
72
+ # destroying
73
+ uploader = PlaneImageUploader.new
74
+ uploader.retrieve_from_store! 'plane.jpg'
75
+ uploader.remove!
76
+ File.should_not exist("#{spec_dir}/data/plane.icon.jpg")
77
+ end
52
78
 
53
- it "path format" do
54
- plane = Plane.create! image: @file
55
- plane.image.url.should == '/plane.jpg'
56
- plane.image.icon.url.should =~ /\/plane\.icon\.jpg/
79
+ it "path format" do
80
+ plane = Plane.create! image: @file
81
+ plane.image.url.should == '/plane.jpg'
82
+ plane.image.icon.url.should =~ /\/plane\.icon\.jpg/
57
83
 
58
- plane.image.icon.current_path.should =~ /\/plane\.icon\.jpg/
59
- File.should exist("#{spec_dir}/data/plane.icon.jpg")
84
+ plane.image.icon.current_path.should =~ /\/plane\.icon\.jpg/
85
+ File.should exist("#{spec_dir}/data/plane.icon.jpg")
86
+ end
87
+ end
88
+
89
+ describe "EmbeddedDocument" do
90
+ before :all do
91
+ class PlaneImage
92
+ include MongoMapper::EmbeddedDocument
93
+
94
+ file_key :image, PlaneImageUploader
95
+ end
96
+
97
+ class Plane
98
+ include MongoMapper::Document
99
+
100
+ has_many :images, class_name: 'PlaneImage'
101
+ end
102
+ end
103
+ after(:all){remove_constants :Plane, :PlaneImage, :PlaneImageUploader}
104
+
105
+ it "basic"
106
+ # do
107
+ # plane = Plane.create! images: [PlaneImage.new(image: @file)]
108
+ # plane.images.first.image.current_path.should =~ /\/plane.jpg/
109
+ # File.should exist("#{spec_dir}/data/plane.jpg")
110
+ # end
111
+
112
+ it "path format"
113
+ # do
114
+ # end
60
115
  end
61
116
  end
@@ -1,35 +1,36 @@
1
- require 'mongo_mapper/spec_helper'
1
+ require 'mongo_mapper'
2
2
 
3
- describe "Special test to check some errors in the MongoMapper itself" do
3
+ describe "Special test to check some errors in the MongoMapper" do
4
4
  before :all do
5
5
  MongoMapper.database = 'test'
6
-
7
- class ::AnObject
8
- include MongoMapper::Document
9
-
10
- key :owner_name, String
11
- key :viewers, Array
12
-
13
- def owner_name= owner_name
14
- viewers.delete self.owner_name
15
- viewers << owner_name
16
- # write_attribute :owner_name, owner_name
17
- super owner_name
18
- owner_name
19
- end
20
- end
21
6
  end
22
7
 
23
8
  after :all do
24
- Object.send :remove_const, :AnObject if Object.const_defined? :AnObject
25
- end
26
-
27
- it do
28
- o = AnObject.new
29
- o.owner_name = 'user'
30
- o.save!
31
-
32
- # o = AnObject.first # don't use reload, it willn't catch this error
33
- o.viewers.should == %w{user}
9
+ Object.send :remove_const, :ThePost, :TheComment if Object.const_defined? :AnObject
34
10
  end
11
+
12
+ # it "strange behaviour of EmbeddedDocument" do
13
+ # class TheComment
14
+ # include MongoMapper::EmbeddedDocument
15
+ #
16
+ # key :text, String
17
+ # alias_method :original_text=, :text=
18
+ # def text= text
19
+ # $id_before_save = object_id
20
+ # self.original_text = text
21
+ # end
22
+ #
23
+ # after_save do
24
+ # $id_after_save = object_id
25
+ # end
26
+ # end
27
+ #
28
+ # class ThePost
29
+ # include MongoMapper::Document
30
+ # has_many :comments, class_name: 'TheComment'
31
+ # end
32
+ #
33
+ # ThePost.create! comments: [TheComment.new(text: 'some text')]
34
+ # $id_before_save.should == $id_after_save
35
+ # end
35
36
  end
@@ -15,7 +15,7 @@ describe "Uploading" do
15
15
  key :name
16
16
  validates_uniqueness_of :name
17
17
 
18
- mount_uploader :image, ShipUploader
18
+ file_key :image, ShipUploader
19
19
  end
20
20
  end
21
21
  after(:all){remove_constants :Ship, :ShipUploader}
metadata CHANGED
@@ -1,170 +1,160 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: mongo_mapper_ext
3
- version: !ruby/object:Gem::Version
4
- version: 0.2.4
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.5
5
5
  prerelease:
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Alexey Petrushin
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-05-19 00:00:00.000000000 +04:00
12
+
13
+ date: 2011-07-22 00:00:00 +04:00
13
14
  default_executable:
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: mongo_mapper
17
- requirement: &2795840 !ruby/object:Gem::Requirement
18
- none: false
19
- requirements:
20
- - - =
21
- - !ruby/object:Gem::Version
22
- version: 0.9.0
23
- type: :runtime
24
- prerelease: false
25
- version_requirements: *2795840
26
- - !ruby/object:Gem::Dependency
27
- name: carrierwave
28
- requirement: &2795620 !ruby/object:Gem::Requirement
29
- none: false
30
- requirements:
31
- - - =
32
- - !ruby/object:Gem::Version
33
- version: 0.5.3
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: *2795620
37
- - !ruby/object:Gem::Dependency
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
38
17
  name: i18n
39
- requirement: &2795380 !ruby/object:Gem::Requirement
18
+ requirement: &id001 !ruby/object:Gem::Requirement
40
19
  none: false
41
- requirements:
42
- - - =
43
- - !ruby/object:Gem::Version
20
+ requirements:
21
+ - - "="
22
+ - !ruby/object:Gem::Version
44
23
  version: 0.5.0
45
24
  type: :runtime
46
25
  prerelease: false
47
- version_requirements: *2795380
48
- - !ruby/object:Gem::Dependency
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
49
28
  name: activesupport
50
- requirement: &2795160 !ruby/object:Gem::Requirement
29
+ requirement: &id002 !ruby/object:Gem::Requirement
51
30
  none: false
52
- requirements:
53
- - - =
54
- - !ruby/object:Gem::Version
31
+ requirements:
32
+ - - "="
33
+ - !ruby/object:Gem::Version
55
34
  version: 3.0.7
56
35
  type: :runtime
57
36
  prerelease: false
58
- version_requirements: *2795160
59
- - !ruby/object:Gem::Dependency
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
60
39
  name: activemodel
61
- requirement: &2794940 !ruby/object:Gem::Requirement
40
+ requirement: &id003 !ruby/object:Gem::Requirement
62
41
  none: false
63
- requirements:
64
- - - =
65
- - !ruby/object:Gem::Version
42
+ requirements:
43
+ - - "="
44
+ - !ruby/object:Gem::Version
66
45
  version: 3.0.7
67
46
  type: :runtime
68
47
  prerelease: false
69
- version_requirements: *2794940
70
- - !ruby/object:Gem::Dependency
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
71
50
  name: bson
72
- requirement: &2794690 !ruby/object:Gem::Requirement
51
+ requirement: &id004 !ruby/object:Gem::Requirement
73
52
  none: false
74
- requirements:
75
- - - =
76
- - !ruby/object:Gem::Version
53
+ requirements:
54
+ - - "="
55
+ - !ruby/object:Gem::Version
77
56
  version: 1.3.0
78
57
  type: :runtime
79
58
  prerelease: false
80
- version_requirements: *2794690
81
- - !ruby/object:Gem::Dependency
59
+ version_requirements: *id004
60
+ - !ruby/object:Gem::Dependency
82
61
  name: bson_ext
83
- requirement: &2794480 !ruby/object:Gem::Requirement
62
+ requirement: &id005 !ruby/object:Gem::Requirement
84
63
  none: false
85
- requirements:
86
- - - =
87
- - !ruby/object:Gem::Version
64
+ requirements:
65
+ - - "="
66
+ - !ruby/object:Gem::Version
88
67
  version: 1.3.0
89
68
  type: :runtime
90
69
  prerelease: false
91
- version_requirements: *2794480
92
- - !ruby/object:Gem::Dependency
70
+ version_requirements: *id005
71
+ - !ruby/object:Gem::Dependency
93
72
  name: mongo
94
- requirement: &2794260 !ruby/object:Gem::Requirement
73
+ requirement: &id006 !ruby/object:Gem::Requirement
95
74
  none: false
96
- requirements:
97
- - - =
98
- - !ruby/object:Gem::Version
75
+ requirements:
76
+ - - "="
77
+ - !ruby/object:Gem::Version
99
78
  version: 1.3.0
100
79
  type: :runtime
101
80
  prerelease: false
102
- version_requirements: *2794260
103
- - !ruby/object:Gem::Dependency
81
+ version_requirements: *id006
82
+ - !ruby/object:Gem::Dependency
104
83
  name: plucky
105
- requirement: &2794040 !ruby/object:Gem::Requirement
84
+ requirement: &id007 !ruby/object:Gem::Requirement
106
85
  none: false
107
- requirements:
108
- - - =
109
- - !ruby/object:Gem::Version
86
+ requirements:
87
+ - - "="
88
+ - !ruby/object:Gem::Version
110
89
  version: 0.3.6
111
90
  type: :runtime
112
91
  prerelease: false
113
- version_requirements: *2794040
114
- - !ruby/object:Gem::Dependency
115
- name: jnunemaker-validatable
116
- requirement: &2793820 !ruby/object:Gem::Requirement
117
- none: false
118
- requirements:
119
- - - =
120
- - !ruby/object:Gem::Version
121
- version: 1.8.4
122
- type: :runtime
123
- prerelease: false
124
- version_requirements: *2793820
125
- - !ruby/object:Gem::Dependency
92
+ version_requirements: *id007
93
+ - !ruby/object:Gem::Dependency
126
94
  name: mini_magick
127
- requirement: &2793610 !ruby/object:Gem::Requirement
95
+ requirement: &id008 !ruby/object:Gem::Requirement
128
96
  none: false
129
- requirements:
130
- - - =
131
- - !ruby/object:Gem::Version
97
+ requirements:
98
+ - - "="
99
+ - !ruby/object:Gem::Version
132
100
  version: 3.2.1
133
101
  type: :runtime
134
102
  prerelease: false
135
- version_requirements: *2793610
136
- - !ruby/object:Gem::Dependency
103
+ version_requirements: *id008
104
+ - !ruby/object:Gem::Dependency
137
105
  name: subexec
138
- requirement: &2793400 !ruby/object:Gem::Requirement
106
+ requirement: &id009 !ruby/object:Gem::Requirement
139
107
  none: false
140
- requirements:
141
- - - =
142
- - !ruby/object:Gem::Version
108
+ requirements:
109
+ - - "="
110
+ - !ruby/object:Gem::Version
143
111
  version: 0.0.4
144
112
  type: :runtime
145
113
  prerelease: false
146
- version_requirements: *2793400
114
+ version_requirements: *id009
115
+ - !ruby/object:Gem::Dependency
116
+ name: mongo_mapper
117
+ requirement: &id010 !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - "="
121
+ - !ruby/object:Gem::Version
122
+ version: 0.9.0
123
+ type: :runtime
124
+ prerelease: false
125
+ version_requirements: *id010
126
+ - !ruby/object:Gem::Dependency
127
+ name: carrierwave
128
+ requirement: &id011 !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - "="
132
+ - !ruby/object:Gem::Version
133
+ version: 0.5.3
134
+ type: :runtime
135
+ prerelease: false
136
+ version_requirements: *id011
147
137
  description:
148
138
  email:
149
139
  executables: []
140
+
150
141
  extensions: []
142
+
151
143
  extra_rdoc_files: []
152
- files:
144
+
145
+ files:
153
146
  - Rakefile
154
147
  - readme.md
155
148
  - lib/mongo_mapper_ext/carrier_wave/fixes.rb
156
149
  - lib/mongo_mapper_ext/carrier_wave/micelaneous.rb
157
- - lib/mongo_mapper_ext/carrier_wave/mongo_mapper/plugins/carrier_wave.rb
150
+ - lib/mongo_mapper_ext/carrier_wave/mongo_mapper/plugins/mount_uploader.rb
151
+ - lib/mongo_mapper_ext/carrier_wave/mongo_mapper/plugins/mount_uploaders.rb
158
152
  - lib/mongo_mapper_ext/carrier_wave.rb
159
153
  - lib/mongo_mapper_ext/gems.rb
160
154
  - lib/mongo_mapper_ext/mongo_db/upsert.rb
161
155
  - lib/mongo_mapper_ext/mongo_db.rb
162
156
  - lib/mongo_mapper_ext/mongo_mapper/fixes.rb
163
157
  - lib/mongo_mapper_ext/mongo_mapper/hacks.rb
164
- - lib/mongo_mapper_ext/mongo_mapper/locales/activemodel/ru.yml
165
- - lib/mongo_mapper_ext/mongo_mapper/locales/mongo_mapper/en.yml
166
- - lib/mongo_mapper_ext/mongo_mapper/locales/mongo_mapper/ru.yml
167
- - lib/mongo_mapper_ext/mongo_mapper/logging.rb
168
158
  - lib/mongo_mapper_ext/mongo_mapper/migration.rb
169
159
  - lib/mongo_mapper_ext/mongo_mapper/plugins/attribute_cache.rb
170
160
  - lib/mongo_mapper_ext/mongo_mapper/plugins/attribute_convertors.rb
@@ -195,31 +185,35 @@ files:
195
185
  - spec/mongo_mapper/spec_helper.rb
196
186
  - spec/rad/spec_helper.rb
197
187
  - spec/rad/uploading_spec/ship.jpg
198
- - spec/rad/uploading_spec/файл с пробелами.txt
188
+ - "spec/rad/uploading_spec/\xD1\x84\xD0\xB0\xD0\xB8\xCC\x86\xD0\xBB \xD1\x81 \xD0\xBF\xD1\x80\xD0\xBE\xD0\xB1\xD0\xB5\xD0\xBB\xD0\xB0\xD0\xBC\xD0\xB8.txt"
199
189
  - spec/rad/uploading_spec.rb
200
190
  has_rdoc: true
201
- homepage: http://github.com/alexeypetrushin/mongo_mapper
191
+ homepage: http://github.com/alexeypetrushin/mongo_mapper_ext
202
192
  licenses: []
193
+
203
194
  post_install_message:
204
195
  rdoc_options: []
205
- require_paths:
196
+
197
+ require_paths:
206
198
  - lib
207
- required_ruby_version: !ruby/object:Gem::Requirement
199
+ required_ruby_version: !ruby/object:Gem::Requirement
208
200
  none: false
209
- requirements:
210
- - - ! '>='
211
- - !ruby/object:Gem::Version
212
- version: '0'
213
- required_rubygems_version: !ruby/object:Gem::Requirement
201
+ requirements:
202
+ - - ">="
203
+ - !ruby/object:Gem::Version
204
+ version: "0"
205
+ required_rubygems_version: !ruby/object:Gem::Requirement
214
206
  none: false
215
- requirements:
216
- - - ! '>='
217
- - !ruby/object:Gem::Version
218
- version: '0'
207
+ requirements:
208
+ - - ">="
209
+ - !ruby/object:Gem::Version
210
+ version: "0"
219
211
  requirements: []
212
+
220
213
  rubyforge_project:
221
214
  rubygems_version: 1.5.1
222
215
  signing_key:
223
216
  specification_version: 3
224
217
  summary: Extensions for MongoMapper
225
218
  test_files: []
219
+