Skip to content

Commit 60f7293

Browse files
committed
minor: removed deprecated @grid.put syntax
1 parent 1e13187 commit 60f7293

File tree

3 files changed

+9
-15
lines changed

3 files changed

+9
-15
lines changed

lib/mongo/gridfs/grid.rb

+2-8
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,8 @@ def initialize(db, fs_name=DEFAULT_FS_NAME)
5656
# will be validated using an md5 hash. If validation fails, an exception will be raised.
5757
#
5858
# @return [Mongo::ObjectID] the file's id.
59-
def put(data, opts={}, old_opts={})
60-
if opts.is_a?(String)
61-
warn "The filename is now optional. Please pass the filename as a hash option: Grid#put(data, :filename => 'file.jpg')."
62-
filename = opts
63-
opts = old_opts
64-
else
65-
filename = opts[:filename]
66-
end
59+
def put(data, opts={})
60+
filename = opts[:filename]
6761
opts.merge!(default_grid_io_opts)
6862
file = GridIO.new(@files, @chunks, filename, 'w', opts=opts)
6963
file.write(data)

test/db_api_test.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ def test_collection_options
275275
def test_index_information
276276
assert_equal @@coll.index_information.length, 1
277277

278-
name = @@db.create_index(@@coll.name, 'a')
278+
name = @@coll.create_index('a')
279279
info = @@db.index_information(@@coll.name)
280280
assert_equal name, "a_1"
281281
assert_equal @@coll.index_information, info
@@ -303,7 +303,7 @@ def test_index_create_with_symbol
303303
end
304304

305305
def test_multiple_index_cols
306-
name = @@db.create_index(@@coll.name, [['a', DESCENDING], ['b', ASCENDING], ['c', DESCENDING]])
306+
name = @@coll.create_index([['a', DESCENDING], ['b', ASCENDING], ['c', DESCENDING]])
307307
info = @@db.index_information(@@coll.name)
308308
assert_equal 2, info.length
309309

@@ -315,7 +315,7 @@ def test_multiple_index_cols
315315
end
316316

317317
def test_multiple_index_cols_with_symbols
318-
name = @@db.create_index(@@coll.name, [[:a, DESCENDING], [:b, ASCENDING], [:c, DESCENDING]])
318+
name = @@coll.create_index([[:a, DESCENDING], [:b, ASCENDING], [:c, DESCENDING]])
319319
info = @@db.index_information(@@coll.name)
320320
assert_equal 2, info.length
321321

test/grid_test.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class GridTest < Test::Unit::TestCase
1919
setup do
2020
@data = "GRIDDATA" * 50000
2121
@grid = Grid.new(@db, 'test-fs')
22-
@id = @grid.put(@data, 'sample', :metadata => {'app' => 'photos'})
22+
@id = @grid.put(@data, :filename => 'sample', :metadata => {'app' => 'photos'})
2323
end
2424

2525
should "retrieve the stored data" do
@@ -58,7 +58,7 @@ class GridTest < Test::Unit::TestCase
5858
end
5959

6060
should "store the file with the old filename api" do
61-
id = @grid.put(@data, 'sample', :metadata => @metadata)
61+
id = @grid.put(@data, :filename => 'sample', :metadata => @metadata)
6262
file = @grid.get(id)
6363
assert_equal 'sample', file.filename
6464
assert_equal @metadata, file.metadata
@@ -106,7 +106,7 @@ class GridTest < Test::Unit::TestCase
106106
context "Storing data with a length of zero" do
107107
setup do
108108
@grid = Grid.new(@db, 'test-fs')
109-
@id = @grid.put('', 'sample', :metadata => {'app' => 'photos'})
109+
@id = @grid.put('', :filename => 'sample', :metadata => {'app' => 'photos'})
110110
end
111111

112112
should "return the zero length" do
@@ -119,7 +119,7 @@ class GridTest < Test::Unit::TestCase
119119
setup do
120120
def read_and_write_stream(filename, read_length, opts={})
121121
io = File.open(File.join(File.dirname(__FILE__), 'data', filename), 'r')
122-
id = @grid.put(io, filename + read_length.to_s, opts)
122+
id = @grid.put(io, opts.merge!(:filename => filename + read_length.to_s))
123123
file = @grid.get(id)
124124
io.rewind
125125
data = io.read

0 commit comments

Comments
 (0)