Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Use prepend instead of include for helpers. Fixes #1213" #1662

Merged
merged 5 commits into from
Nov 11, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Revert "Use prepend instead of include for helpers. Fixes #1213 (#1214)"
This reverts commit 2db247d.
  • Loading branch information
namusyaka authored Nov 4, 2020
commit fb9b2098d7618a5e947fbf622b3b1e7aba9f52cb
2 changes: 1 addition & 1 deletion lib/sinatra/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1441,7 +1441,7 @@ def unlink(path, opts = {}, &bk) route 'UNLINK', path, opts, &bk end
# in `extensions` available to the handlers and templates
def helpers(*extensions, &block)
class_eval(&block) if block_given?
prepend(*extensions) if extensions.any?
include(*extensions) if extensions.any?
end

# Register an extension. Alternatively take a block from which an
Expand Down
2 changes: 1 addition & 1 deletion sinatra-contrib/lib/sinatra/namespace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def self.prefixed(*names)

def helpers(*extensions, &block)
class_eval(&block) if block_given?
prepend(*extensions) if extensions.any?
include(*extensions) if extensions.any?
end

def register(*extensions, &block)
Expand Down
22 changes: 0 additions & 22 deletions test/helpers_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1947,27 +1947,5 @@ def foo
assert ok?
assert_equal '42 < 43', body
end

it 'prepends modules so previously-defined methods can be overridden consistently' do
mock_app do
helpers do
def one; nil end
def two; nil end
end

helpers ::HelperOne do
def two; '2' end
end

get('/one') { one }
get('/two') { two }
end

get '/one'
assert_equal '1', body

get '/two'
assert_equal '2', body
end
end
end