Skip to content

Commit

Permalink
Do not raise when key is an enumerable
Browse files Browse the repository at this point in the history
  • Loading branch information
BuonOmo committed Jul 20, 2020
1 parent 91477e6 commit 282fb59
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sinatra-contrib/lib/sinatra/namespace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ def respond_to(*args)
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
Expand Down
14 changes: 14 additions & 0 deletions sinatra-contrib/spec/namespace_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,20 @@ class CError < StandardError;
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
Expand Down

0 comments on commit 282fb59

Please sign in to comment.