carrierwave-mongoid 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -68,6 +68,16 @@ end
68
68
 
69
69
  ## Known issues and limitations
70
70
 
71
- Note that files mounted in embedded documents aren't saved when parent documents are saved.
72
- You must explicitly call save on embedded documents in order to save their attached files.
71
+ Note that files mounted in embedded documents aren't saved when parent documents
72
+ are saved. By default, mongoid does not cascade callbacks on embedded
73
+ documents. In order to save the attached files on embedded documents, you must
74
+ either explicitly call save on the embedded documents or you must configure the
75
+ embedded association to cascade the callbacks automatically. For example:
76
+
77
+ ```ruby
78
+ class User
79
+ embeds_many :pictures, cascade_callbacks: true
80
+ end
81
+ ```
82
+
73
83
  You can read more about this [here](https://github.com/jnicklas/carrierwave/issues#issue/81)
data/Rakefile CHANGED
@@ -1,4 +1,4 @@
1
- require 'bundler'
1
+ require 'bundler/setup'
2
2
  Bundler::GemHelper.install_tasks
3
3
 
4
4
  require 'rspec/core/rake_task'
@@ -43,7 +43,8 @@ module CarrierWave
43
43
  ancestors = [[ self.metadata.key, self._parent ]].tap { |x| x.unshift([ x.first.last.metadata.key, x.first.last._parent ]) while x.first.last.embedded? }
44
44
  first_parent = ancestors.first.last
45
45
  reloaded_parent = first_parent.class.find(first_parent.to_key.first)
46
- ancestors.inject(reloaded_parent) { |parent,(key,ancestor)| (parent.is_a?(Array) ? parent.find(ancestor.to_key.first) : parent).send(key) }.find(to_key.first)
46
+ association = ancestors.inject(reloaded_parent) { |parent,(key,ancestor)| (parent.is_a?(Array) ? parent.find(ancestor.to_key.first) : parent).send(key) }
47
+ association.is_a?(Array) ? association.find(to_key.first) : association
47
48
  else
48
49
  self.class.find(to_key.first)
49
50
  end
@@ -1,5 +1,5 @@
1
1
  module Carrierwave
2
2
  module Mongoid
3
- VERSION = "0.1.4"
3
+ VERSION = "0.1.5"
4
4
  end
5
5
  end
@@ -21,16 +21,20 @@ end
21
21
 
22
22
  class MongoUploader < CarrierWave::Uploader::Base; end
23
23
 
24
- class WhiteListUploader < CarrierWave::Uploader::Base
24
+ class IntegrityErrorUploader < CarrierWave::Uploader::Base
25
+ process :monkey
26
+ def monkey
27
+ raise CarrierWave::IntegrityError
28
+ end
25
29
  def extension_white_list
26
- %w(txt)
30
+ %w(jpg)
27
31
  end
28
32
  end
29
33
 
30
34
  class ProcessingErrorUploader < CarrierWave::Uploader::Base
31
35
  process :monkey
32
36
  def monkey
33
- raise CarrierWave::ProcessingError, "Ohh noez!"
37
+ raise CarrierWave::ProcessingError
34
38
  end
35
39
  def extension_white_list
36
40
  %w(jpg)
@@ -142,7 +146,7 @@ describe CarrierWave::Mongoid do
142
146
 
143
147
  context 'when validating integrity' do
144
148
  before do
145
- mongo_user_klass = reset_mongo_class(WhiteListUploader)
149
+ mongo_user_klass = reset_mongo_class(IntegrityErrorUploader)
146
150
  @doc = mongo_user_klass.new
147
151
  @doc.image = stub_file('test.jpg')
148
152
  end
@@ -153,7 +157,7 @@ describe CarrierWave::Mongoid do
153
157
 
154
158
  it "should use I18n for integrity error messages" do
155
159
  @doc.valid?
156
- @doc.errors[:image].should == ['is not an allowed file type']
160
+ @doc.errors[:image].should == ['is not of an allowed file type']
157
161
 
158
162
  change_locale_and_store_translations(:pt, :mongoid => {
159
163
  :errors => {
@@ -252,6 +256,7 @@ describe CarrierWave::Mongoid do
252
256
  end
253
257
 
254
258
  it "should mark image as changed when saving a new image" do
259
+ pending "This isn't working with Mongoid's current Dirty module. Mongoid's *_changed? methods don't behave the same as ActiveModel's *_changed? methods."
255
260
  @doc.image_changed?.should be_false
256
261
  @doc.image = stub_file("test.jpeg")
257
262
  @doc.image_changed?.should be_true
@@ -403,25 +408,7 @@ describe CarrierWave::Mongoid do
403
408
  end
404
409
  end
405
410
 
406
- describe 'with embedded documents' do
407
-
408
- before do
409
- @embedded_doc_class = define_mongo_class('MongoLocation') do
410
- include Mongoid::Document
411
- mount_uploader :image, @uploader
412
- embedded_in :mongo_user
413
- end
414
-
415
- @class.class_eval do
416
- embeds_many :mongo_locations
417
- end
418
-
419
- @doc = @class.new
420
- @embedded_doc = @doc.mongo_locations.build
421
- @embedded_doc.image = stub_file('old.jpeg')
422
- @embedded_doc.save.should be_true
423
- end
424
-
411
+ shared_examples "embedded documents" do
425
412
  it "should remove old file if old file had a different path" do
426
413
  @embedded_doc.image = stub_file('new.jpeg')
427
414
  @embedded_doc.save.should be_true
@@ -457,6 +444,49 @@ describe CarrierWave::Mongoid do
457
444
  @embedded_doc.save.should be_true
458
445
  @doc.title.should == "Title"
459
446
  end
447
+ end
448
+
449
+
450
+ describe 'with document embedded as embeds_one' do
451
+ before do
452
+ @embedded_doc_class = define_mongo_class('MongoLocation') do
453
+ include Mongoid::Document
454
+ mount_uploader :image, @uploader
455
+ embedded_in :mongo_user
456
+ end
457
+
458
+ @class.class_eval do
459
+ embeds_one :mongo_location
460
+ end
461
+
462
+ @doc = @class.new
463
+ @embedded_doc = @doc.build_mongo_location
464
+ @embedded_doc.image = stub_file('old.jpeg')
465
+ @embedded_doc.save.should be_true
466
+ end
467
+
468
+ include_examples "embedded documents"
469
+ end
470
+
471
+ describe 'with embedded documents' do
472
+ before do
473
+ @embedded_doc_class = define_mongo_class('MongoLocation') do
474
+ include Mongoid::Document
475
+ mount_uploader :image, @uploader
476
+ embedded_in :mongo_user
477
+ end
478
+
479
+ @class.class_eval do
480
+ embeds_many :mongo_locations
481
+ end
482
+
483
+ @doc = @class.new
484
+ @embedded_doc = @doc.mongo_locations.build
485
+ @embedded_doc.image = stub_file('old.jpeg')
486
+ @embedded_doc.save.should be_true
487
+ end
488
+
489
+ include_examples "embedded documents"
460
490
 
461
491
  describe 'with double embedded documents' do
462
492
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carrierwave-mongoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-03-28 00:00:00.000000000 Z
13
+ date: 2012-03-29 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: carrierwave
17
- requirement: &70289858492260 !ruby/object:Gem::Requirement
17
+ requirement: &70093414050040 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 0.5.6
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70289858492260
25
+ version_requirements: *70093414050040
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: mongoid
28
- requirement: &70289858490460 !ruby/object:Gem::Requirement
28
+ requirement: &70093414036060 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '2.1'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *70289858490460
36
+ version_requirements: *70093414036060
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: rspec
39
- requirement: &70289858489440 !ruby/object:Gem::Requirement
39
+ requirement: &70093414035240 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: '2.6'
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *70289858489440
47
+ version_requirements: *70093414035240
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: bson_ext
50
- requirement: &70289858488840 !ruby/object:Gem::Requirement
50
+ requirement: &70093414034580 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ~>
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: '1.3'
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *70289858488840
58
+ version_requirements: *70093414034580
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: rake
61
- requirement: &70289858487980 !ruby/object:Gem::Requirement
61
+ requirement: &70093414034080 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ~>
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: '0.9'
67
67
  type: :development
68
68
  prerelease: false
69
- version_requirements: *70289858487980
69
+ version_requirements: *70093414034080
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: mini_magick
72
- requirement: &70289858487300 !ruby/object:Gem::Requirement
72
+ requirement: &70093414033660 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ! '>='
@@ -77,7 +77,7 @@ dependencies:
77
77
  version: '0'
78
78
  type: :development
79
79
  prerelease: false
80
- version_requirements: *70289858487300
80
+ version_requirements: *70093414033660
81
81
  description: Mongoid support for CarrierWave
82
82
  email:
83
83
  - jonas.nicklas@gmail.com
@@ -116,12 +116,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
116
116
  - - ! '>='
117
117
  - !ruby/object:Gem::Version
118
118
  version: '0'
119
+ segments:
120
+ - 0
121
+ hash: 887805465808785246
119
122
  required_rubygems_version: !ruby/object:Gem::Requirement
120
123
  none: false
121
124
  requirements:
122
125
  - - ! '>='
123
126
  - !ruby/object:Gem::Version
124
127
  version: '0'
128
+ segments:
129
+ - 0
130
+ hash: 887805465808785246
125
131
  requirements: []
126
132
  rubyforge_project: carrierwave-mongoid
127
133
  rubygems_version: 1.8.11