carrierwave-mongoid 0.6.1 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -2
- data/lib/carrierwave/mongoid.rb +8 -0
- data/lib/carrierwave/mongoid/version.rb +1 -1
- data/spec/mongoid_spec.rb +39 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 213d8790d4c5ce59989b25b2a7cf381c32999565
|
4
|
+
data.tar.gz: 4bf5807ca58f0508eca2abb2fb732cb40ea181ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f0b95117e0a82f6a39d406ccbe97cc026ab73de9536c39e0b48b2a72d683dfb4301b1d3895326291fe11045dcc4cc0550d5b0a33b2ea66cd87d9b76f3b3bc8f
|
7
|
+
data.tar.gz: d351d3ff807fdbdddabcf0e7f49c188a0b9fe11615003523a7832e145d75e9be7a9fb214a11f323d03996aa91e729fe9d4f733969de83208a63079e65bb58e17
|
data/README.md
CHANGED
@@ -24,6 +24,13 @@ Or, in Rails you can add it to your Gemfile:
|
|
24
24
|
gem 'carrierwave-mongoid', :require => 'carrierwave/mongoid'
|
25
25
|
```
|
26
26
|
|
27
|
+
Note: If using Rails 4, you'll need to make sure `mongoind-grid_fs` is `>= 1.9.0`.
|
28
|
+
If in doubt, run `bundle update mongoind-grid_fs`
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
gem 'mongoid-grid_fs', github: 'ahoward/mongoid-grid_fs'
|
32
|
+
```
|
33
|
+
|
27
34
|
## Getting Started
|
28
35
|
|
29
36
|
Follow the "Getting Started" directions in the main
|
@@ -153,14 +160,14 @@ match '/uploads/grid/user/avatar/:id/:filename' => 'gridfs#thumb_avatar', constr
|
|
153
160
|
| ~> 0.2.0 | ([compare][compare-0.2], [dependencies][deps-0.2]) Rails >= 3.2, Mongoid ~> 2.0 |
|
154
161
|
| ~> 0.1.0 | ([compare][compare-0.1], [dependencies][deps-0.1]) Rails <= 3.1 |
|
155
162
|
|
156
|
-
[compare-0.6]: https://github.com/carrierwaveuploader/carrierwave-mongoid/compare/v0.5.0...v0.6.
|
163
|
+
[compare-0.6]: https://github.com/carrierwaveuploader/carrierwave-mongoid/compare/v0.5.0...v0.6.2
|
157
164
|
[compare-0.5]: https://github.com/carrierwaveuploader/carrierwave-mongoid/compare/v0.4.0...v0.5.0
|
158
165
|
[compare-0.4]: https://github.com/carrierwaveuploader/carrierwave-mongoid/compare/v0.3.1...v0.4.0
|
159
166
|
[compare-0.3]: https://github.com/carrierwaveuploader/carrierwave-mongoid/compare/v0.2.1...v0.3.1
|
160
167
|
[compare-0.2]: https://github.com/carrierwaveuploader/carrierwave-mongoid/compare/v0.1.7...v0.2.2
|
161
168
|
[compare-0.1]: https://github.com/carrierwaveuploader/carrierwave-mongoid/compare/v0.1.1...v0.1.7
|
162
169
|
|
163
|
-
[deps-0.6]: https://rubygems.org/gems/carrierwave-mongoid/versions/0.6.
|
170
|
+
[deps-0.6]: https://rubygems.org/gems/carrierwave-mongoid/versions/0.6.2
|
164
171
|
[deps-0.5]: https://rubygems.org/gems/carrierwave-mongoid/versions/0.5.0
|
165
172
|
[deps-0.4]: https://rubygems.org/gems/carrierwave-mongoid/versions/0.4.0
|
166
173
|
[deps-0.3]: https://rubygems.org/gems/carrierwave-mongoid/versions/0.3.1
|
data/lib/carrierwave/mongoid.rb
CHANGED
@@ -57,6 +57,14 @@ module CarrierWave
|
|
57
57
|
changed_attributes.has_key?("#{column}")
|
58
58
|
end
|
59
59
|
|
60
|
+
# The default Mongoid attribute_will_change! method is not enough
|
61
|
+
# when we want to upload a new file in an existing embedded document.
|
62
|
+
# The custom version of that method forces the callbacks to be
|
63
|
+
# ran and so does the upload.
|
64
|
+
def #{column}_will_change!
|
65
|
+
changed_attributes["#{column}"] = '_new_'
|
66
|
+
end
|
67
|
+
|
60
68
|
def find_previous_model_for_#{column}
|
61
69
|
if self.embedded?
|
62
70
|
ancestors = [[ self.metadata.key, self._parent ]].tap { |x| x.unshift([ x.first.last.metadata.key, x.first.last._parent ]) while x.first.last.embedded? }
|
data/spec/mongoid_spec.rb
CHANGED
@@ -569,6 +569,7 @@ describe CarrierWave::Mongoid do
|
|
569
569
|
|
570
570
|
@class.class_eval do
|
571
571
|
embeds_many :mongo_locations, cascade_callbacks: true
|
572
|
+
accepts_nested_attributes_for :mongo_locations
|
572
573
|
end
|
573
574
|
|
574
575
|
@doc = @class.new
|
@@ -592,6 +593,12 @@ describe CarrierWave::Mongoid do
|
|
592
593
|
doc.mongo_locations.first[:image].should == 'test.jpeg'
|
593
594
|
end
|
594
595
|
|
596
|
+
it "changes the file" do
|
597
|
+
@doc.update_attributes mongo_locations_attributes: { '0' => { _id: @embedded_doc._id, image: stub_file('test.jpeg') } }
|
598
|
+
@doc.reload
|
599
|
+
@doc.mongo_locations.first[:image].should == 'test.jpeg'
|
600
|
+
end
|
601
|
+
|
595
602
|
describe 'with double embedded documents' do
|
596
603
|
|
597
604
|
before do
|
@@ -666,6 +673,38 @@ describe CarrierWave::Mongoid do
|
|
666
673
|
include_examples "double embedded documents"
|
667
674
|
end
|
668
675
|
end
|
676
|
+
|
677
|
+
describe 'with embedded documents and nested attributes' do
|
678
|
+
before do
|
679
|
+
@embedded_doc_class = define_mongo_class('MongoLocation') do
|
680
|
+
include Mongoid::Document
|
681
|
+
mount_uploader :image, @uploader
|
682
|
+
embedded_in :mongo_user
|
683
|
+
end
|
684
|
+
|
685
|
+
@class.class_eval do
|
686
|
+
embeds_many :mongo_locations, cascade_callbacks: true
|
687
|
+
accepts_nested_attributes_for :mongo_locations
|
688
|
+
end
|
689
|
+
|
690
|
+
@doc = @class.new(mongo_locations_attributes: [{image: stub_file("old.jpeg")}])
|
691
|
+
@doc.save.should be_true
|
692
|
+
@embedded_doc = @doc.mongo_locations.first
|
693
|
+
end
|
694
|
+
|
695
|
+
it "should set the image on a save" do
|
696
|
+
@doc.reload
|
697
|
+
@doc.mongo_locations.first.image.path.should match(/old\.jpeg$/)
|
698
|
+
@embedded_doc.image.path.should match(/old\.jpeg$/)
|
699
|
+
end
|
700
|
+
|
701
|
+
it "should update the image on update_attributes" do
|
702
|
+
@doc.update_attributes(mongo_locations_attributes: [{id: @embedded_doc.id, image: stub_file("new.jpeg")}]).should be_true
|
703
|
+
@doc.reload
|
704
|
+
@doc.mongo_locations.first.image.path.should match(/new\.jpeg$/)
|
705
|
+
@embedded_doc.image.path.should match(/new\.jpeg$/)
|
706
|
+
end
|
707
|
+
end
|
669
708
|
end
|
670
709
|
|
671
710
|
describe '#mount_uploader removing old files with versions' do
|
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.6.
|
4
|
+
version: 0.6.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonas Nicklas
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-08-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: carrierwave
|