Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
### 2.6.1 (Next)

* [#45](https://github.com/mongoid/mongoid-grid_fs/pull/45): Encode stored file bytes rather than the model description in Base64 and data URIs - [@yudho](https://github.com/yudho), [@dblock](https://github.com/dblock).
* [#48](https://github.com/mongoid/mongoid-grid_fs/pull/48): Check for the specific legacy BSON classes instead of the Moped namespace - [@jeremy6d](https://github.com/jeremy6d), [@dblock](https://github.com/dblock).
* [#86](https://github.com/mongoid/mongoid-grid_fs/pull/86): Expand persisted GridFS coverage for streaming, upload failures, namespaces, attributes, queries, historical records without `updateDate`, and Rails responses - [@dblock](https://github.com/dblock).
* [#85](https://github.com/mongoid/mongoid-grid_fs/pull/85): Report test coverage to Coveralls and update CI badges - [@dblock](https://github.com/dblock).
* [#84](https://github.com/mongoid/mongoid-grid_fs/pull/84): Migrate Danger to danger-pr-comment workflows - [@dblock](https://github.com/dblock).
Expand Down
4 changes: 2 additions & 2 deletions lib/mongoid/grid_fs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def put(readable, attributes = {})
end

def binary_for(*buf)
if defined?(Moped::BSON)
if defined?(Moped::BSON::Binary)
Moped::BSON::Binary.new(:generic, buf.join)
else
BSON::Binary.new(buf.join, :generic)
Expand Down Expand Up @@ -415,7 +415,7 @@ def self.build_chunk_model_for(namespace)
store_in collection: "#{prefix}.chunks"

field(:n, type: Integer, default: 0)
field(:data, type: (defined?(Moped::BSON) ? Moped::BSON::Binary : BSON::Binary))
field(:data, type: (defined?(Moped::BSON::Binary) ? Moped::BSON::Binary : BSON::Binary))

belongs_to(:file, foreign_key: :files_id, class_name: file_model_name)

Expand Down
25 changes: 25 additions & 0 deletions test/bson_compatibility_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

require_relative 'helper'
require 'open3'
require 'rbconfig'

class BsonCompatibilityTest < Minitest::Test
def test_moped_namespace_without_legacy_binary_uses_modern_bson
script = <<~RUBY
require 'logger'
require 'mongoid'
Object.const_set(:Moped, Module.new) unless defined?(Moped)
Moped.const_set(:BSON, Module.new) unless defined?(Moped::BSON)
require 'mongoid/grid_fs'
namespace = Mongoid::GridFs.namespace_for(:bsoncompatibility)
binary = namespace.binary_for("one", "two")
abort "wrong binary type" unless binary.is_a?(BSON::Binary)
abort "wrong bytes" unless binary.data == "onetwo"
abort "wrong field type" unless namespace.chunk_model.fields.fetch("data").type == BSON::Binary
RUBY

output, status = Open3.capture2e(RbConfig.ruby, '-Ilib', '-e', script)
assert status.success?, output
end
end
2 changes: 1 addition & 1 deletion test/mongoid-grid_fs_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@
protected

def object_id_re
object_id = defined?(Moped::BSON) ? Moped::BSON::ObjectId.new : BSON::ObjectId.new
object_id = defined?(Moped::BSON::ObjectId) ? Moped::BSON::ObjectId.new : BSON::ObjectId.new

/ \w{#{ object_id.to_s.size }} /iomx
end
Expand Down
Loading