Permalink
Browse files

Relaxed dependencies for future Mongoid 4.0 support

Helps with #94
  • Loading branch information...
1 parent eb04fc4 commit 28b83405d2b1e6a63f2eb1c33bcf63ad67c1e186 @rmm5t rmm5t committed Apr 16, 2013
Showing with 34 additions and 23 deletions.
  1. +1 −0 .travis.yml
  2. +1 −1 carrierwave-mongoid.gemspec
  3. +6 −0 gemfiles/mongoid-4.0.gemfile
  4. +1 −1 lib/carrierwave/mongoid.rb
  5. +25 −21 spec/mongoid_spec.rb
View
1 .travis.yml
@@ -15,3 +15,4 @@ gemfile:
- gemfiles/carrierwave-master.gemfile
- gemfiles/mongoid-3.0.gemfile
- gemfiles/mongoid-3.1.gemfile
+ - gemfiles/mongoid-4.0.gemfile
View
2 carrierwave-mongoid.gemspec
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
s.require_paths = ["lib"]
s.add_dependency "carrierwave", ["~> 0.8.0"]
- s.add_dependency "mongoid", ["~> 3.0"]
+ s.add_dependency "mongoid", [">= 3.0", "< 5.0"]
s.add_dependency "mongoid-grid_fs", ["~> 1.3"]
s.add_development_dependency "rspec", ["~> 2.6"]
s.add_development_dependency "rake", ["~> 10.0"]
View
6 gemfiles/mongoid-4.0.gemfile
@@ -0,0 +1,6 @@
+source "https://rubygems.org"
+
+gem "mongoid-grid_fs", github: "ahoward/mongoid-grid_fs", branch: "master"
+gem "mongoid", github: "mongoid/mongoid", branch: "master"
+
+gemspec path: "../"
View
2 lib/carrierwave/mongoid.rb
@@ -40,7 +40,7 @@ def #{column}=(new_file)
end
def remove_#{column}!
- super unless paranoid? && flagged_for_destroy?
+ super unless respond_to?(:paranoid?) && paranoid? && flagged_for_destroy?
end
# Overrides Mongoid's default dirty behavior to instead work more like
View
46 spec/mongoid_spec.rb
@@ -766,30 +766,34 @@ def filename
end
end
- describe "with paranoia enabled" do
- before do
- @class = reset_mongo_class
- @class.collection.drop
- @class.class_eval do
- include Mongoid::Paranoia
- end
+ # Mongoid::Paranoia support is only part of Mongoid 3.x. It was removed from
+ # Mongoid 4.x.
+ if defined?(Mongoid::Paranoia)
+ describe "with paranoia enabled" do
+ before do
+ @class = reset_mongo_class
+ @class.collection.drop
+ @class.class_eval do
+ include Mongoid::Paranoia
+ end
- @doc = @class.new(image: stub_file("old.jpeg"))
- @doc.save.should be_true
- end
+ @doc = @class.new(image: stub_file("old.jpeg"))
+ @doc.save.should be_true
+ end
- it "should not remove underlying image after #destroy" do
- @doc.destroy.should be_true
- @class.count.should eql(0)
- @class.deleted.count.should eql(1)
- File.exist?(public_path('uploads/old.jpeg')).should be_true
- end
+ it "should not remove underlying image after #destroy" do
+ @doc.destroy.should be_true
+ @class.count.should eql(0)
+ @class.deleted.count.should eql(1)
+ File.exist?(public_path('uploads/old.jpeg')).should be_true
+ end
- it "should remove underlying image after #destroy!" do
- @doc.destroy!.should be_true
- @class.count.should eql(0)
- @class.deleted.count.should eql(0)
- File.exist?(public_path('uploads/old.jpeg')).should be_false
+ it "should remove underlying image after #destroy!" do
+ @doc.destroy!.should be_true
+ @class.count.should eql(0)
+ @class.deleted.count.should eql(0)
+ File.exist?(public_path('uploads/old.jpeg')).should be_false
+ end
end
end

0 comments on commit 28b8340

Please sign in to comment.