Skip to content

Commit

Permalink
Merge pull request #61 from laCour/mongoid-6.0
Browse files Browse the repository at this point in the history
Mongoid 6.0 Support
  • Loading branch information
rmm5t authored Jul 21, 2016
2 parents 563c4f7 + cd08d13 commit 41feadf
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,13 @@ gemfile:
- gemfiles/mongoid-5.0.gemfile
matrix:
fast_finish: true
include:
- rvm: 2.2.2
gemfile: gemfiles/mongoid-6.0.gemfile
- rvm: 2.3.1
gemfile: gemfiles/mongoid-6.0.gemfile

env:
global:
env:
- RUBYOPT='-W0'
6 changes: 6 additions & 0 deletions gemfiles/mongoid-6.0.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
source "https://rubygems.org"

gem "rails", "~> 5.0"
gem "mongoid", "~> 6.0.0.beta"

gemspec path: "../"
12 changes: 3 additions & 9 deletions lib/mongoid/grid_fs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ def namespace
end

def put(readable, attributes = {})
chunks = []
file = file_model.new
file = file_model.create
attributes.to_options!

if attributes.has_key?(:id)
Expand Down Expand Up @@ -147,12 +146,8 @@ def put(readable, attributes = {})
GridFs.chunking(io, chunkSize) do |buf|
md5 << buf
length += buf.size
chunk = file.chunks.build
chunk.data = binary_for(buf)
chunk.n = n
chunk = file.chunks.create(data: binary_for(buf), n: n)
n += 1
chunk.save!
chunks.push(chunk)
end
end

Expand All @@ -162,10 +157,9 @@ def put(readable, attributes = {})

file.update_attributes(attributes)

file.save!
file
rescue
chunks.each{|chunk| chunk.destroy rescue nil}
file.destroy
raise
end

Expand Down
2 changes: 1 addition & 1 deletion mongoid-grid_fs.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Gem::Specification::new do |spec|
spec.test_files = Dir["test/**/*"]
spec.require_path = "lib"

spec.add_dependency "mongoid", ">= 3.0", "< 6.0"
spec.add_dependency "mongoid", ">= 3.0", "< 7.0"
spec.add_dependency "mime-types", ">= 1.0", "< 4.0"
spec.add_development_dependency "minitest", ">= 5.7.0", "< 6.0"
end
2 changes: 2 additions & 0 deletions test/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ def initialize(filename, *args, &block)
config.connect_to('mongoid-grid_fs_test')
end

Mongo::Logger.logger.level = Logger::INFO if defined?(Mongo) == 'constant'

# Avoid annoying deprecation warning
if I18n.respond_to?(:enforce_available_locales=)
I18n.enforce_available_locales = false
Expand Down

0 comments on commit 41feadf

Please sign in to comment.