-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Inconsistent overriding of previously-defined helpers #1213
Copy link
Copy link
Closed
Description
There's a slight inconsistency with the order in which Sinatra applies helpers when those helpers may have been previously defined. This is probably best explained with an example:
module HelperOne
def one; '1' end
end
class MockApp < Sinatra::Base
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 }
endOne might reasonably expect one of two outcomes from the above:
/onereturns"1"and/tworeturns"2"(i.e. the later-defined helpers override the previously-defined helpers)/onereturnsniland/tworeturnsnil(i.e. the previously-defined helpers are "sticky" and cannot be overridden)
But what actually happens is:
/onereturnsniland/tworeturns"2"
So previously-defined helpers can be overridden in the block, but not in an included helpers module. This is inconsistent and confusing. To fix it, let's prepend the module(s) instead of include-ing them.
Reactions are currently unavailable