Skip to content

Commit

Permalink
change some code based on @simonoff's suggestion, add a test roo-rb#84
Browse files Browse the repository at this point in the history
  • Loading branch information
nobuf committed Aug 4, 2014
1 parent fdaefec commit 1268bee
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/roo/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,11 @@ def normalize(row,col)
end

def uri?(filename)
filename.is_a? String and filename.start_with?("http://", "https://")
begin
filename.start_with?("http://", "https://")
rescue
false
end
end

def download_uri(uri, tmpdir)
Expand Down
2 changes: 1 addition & 1 deletion lib/roo/excel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def initialize(filename, options = {}, deprecated_file_warning = :error)
file_type_check(filename,'.xls','an Excel', file_warning, packed)
make_tmpdir do |tmpdir|
filename = download_uri(filename, tmpdir) if uri?(filename)
filename = open_from_stream(filename[7..-1], tmpdir) if String === filename && filename[0,7] == "stream:"
filename = open_from_stream(filename[7..-1], tmpdir) if filename.is_a?(::String) && filename[0,7] == "stream:"
filename = unzip(filename, tmpdir) if packed == :zip

@filename = filename
Expand Down
15 changes: 15 additions & 0 deletions test/test_generic_spreadsheet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,21 @@ def sheets
end
end

context 'private method Roo::Base.uri?(filename)' do
should "return true when passed a filename starts with http(s)://" do
assert_equal true, @oo.send(:uri?, 'http://example.com/')
assert_equal true, @oo.send(:uri?, 'https://example.com/')
end

should "return false when passed a filename which does not start with http(s)://" do
assert_equal false, @oo.send(:uri?, 'example.com')
end

should "return false when passed non-String object such as Tempfile" do
assert_equal false, @oo.send(:uri?, Tempfile.new('test'))
end
end

def test_setting_invalid_type_does_not_update_cell
@oo.set(1,1,1)
assert_raise(ArgumentError){@oo.set(1,1, :invalid_type)}
Expand Down

0 comments on commit 1268bee

Please sign in to comment.