From 606b7e7b2b260311a970155ec431b8ae7f7de4a0 Mon Sep 17 00:00:00 2001 From: Jonathan la Cour Date: Wed, 20 Jul 2016 20:42:46 -0600 Subject: [PATCH 1/4] Decrease test noise --- .travis.yml | 5 +++++ test/helper.rb | 2 ++ 2 files changed, 7 insertions(+) diff --git a/.travis.yml b/.travis.yml index e7973db..ef2df0b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,3 +18,8 @@ gemfile: - gemfiles/mongoid-5.0.gemfile matrix: fast_finish: true + +env: + global: + env: + - RUBYOPT='-W0' diff --git a/test/helper.rb b/test/helper.rb index 90cafb9..57dc21c 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -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 From ea1dcea6fe40eae8b11c94a5b431e33b6cb0d84c Mon Sep 17 00:00:00 2001 From: Jonathan la Cour Date: Wed, 20 Jul 2016 20:43:12 -0600 Subject: [PATCH 2/4] Add mongoid 6.0 gemfile --- .travis.yml | 5 +++++ gemfiles/mongoid-6.0.gemfile | 6 ++++++ 2 files changed, 11 insertions(+) create mode 100644 gemfiles/mongoid-6.0.gemfile diff --git a/.travis.yml b/.travis.yml index ef2df0b..8b72b95 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,6 +18,11 @@ 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: diff --git a/gemfiles/mongoid-6.0.gemfile b/gemfiles/mongoid-6.0.gemfile new file mode 100644 index 0000000..789bbb3 --- /dev/null +++ b/gemfiles/mongoid-6.0.gemfile @@ -0,0 +1,6 @@ +source "https://rubygems.org" + +gem "rails", "~> 5.0" +gem "mongoid", "~> 6.0.0.beta" + +gemspec path: "../" From 5ca03f2de1931e8ce761dfd1a48e03d5b40616a5 Mon Sep 17 00:00:00 2001 From: Jonathan la Cour Date: Wed, 20 Jul 2016 20:43:35 -0600 Subject: [PATCH 3/4] Raise max mongoid version --- mongoid-grid_fs.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mongoid-grid_fs.gemspec b/mongoid-grid_fs.gemspec index 0b8705c..30bb723 100644 --- a/mongoid-grid_fs.gemspec +++ b/mongoid-grid_fs.gemspec @@ -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 From cd08d133db3a2ac10ac4b6eba2a316e3d0eeb343 Mon Sep 17 00:00:00 2001 From: Jonathan la Cour Date: Wed, 20 Jul 2016 20:43:47 -0600 Subject: [PATCH 4/4] Persist file model on #put --- lib/mongoid/grid_fs.rb | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/lib/mongoid/grid_fs.rb b/lib/mongoid/grid_fs.rb index 60ed44a..4a5c550 100644 --- a/lib/mongoid/grid_fs.rb +++ b/lib/mongoid/grid_fs.rb @@ -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) @@ -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 @@ -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