Merge pull request #1619 from BuonOmo/fix-namespace-set

[sinatra-contrib][namespace] Do not raise when key is an enumerable
This commit is contained in:
namusyaka 2021-02-13 05:08:59 +09:00 committed by GitHub
commit e79e9e6c56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -284,8 +284,8 @@ module Sinatra
end
def set(key, value = self, &block)
return key.each { |k,v| set(k, v) } if key.respond_to?(:each) and block.nil? and value == self
raise ArgumentError, "may not set #{key}" unless ([:views] + ALLOWED_ENGINES).include?(key)
return key.each { |k,v| set(k, v) } if block.nil? and value == self
block ||= proc { value }
singleton_class.send(:define_method, key, &block)
end

View File

@ -770,6 +770,20 @@ describe Sinatra::Namespace do
expect(last_response.body).to eq('ok')
end
it 'sets hashes correctly' do
mock_app do
namespace '/foo' do
set erb: 'o', sass: 'k'
get '/bar' do
settings.erb + settings.sass
end
end
end
expect(get('/foo/bar').status).to eq(200)
expect(last_response.body).to eq('ok')
end
it 'uses some repro' do
mock_app do
set :foo, 42