diff --git a/app/helpers/title/title_helper.rb b/app/helpers/title/title_helper.rb index ce1a2ce..cda1145 100644 --- a/app/helpers/title/title_helper.rb +++ b/app/helpers/title/title_helper.rb @@ -15,7 +15,7 @@ def initialize(controller_path, action_name, context) def to_s I18n.t( [:titles, controller_name, action_name].join('.'), - context.merge(default: defaults) + safe_context.merge(default: defaults) ) end @@ -59,6 +59,10 @@ def adjusted_action_name(action_name) action_name end end + + def safe_context + context.except(*I18n::RESERVED_KEYS) + end end end end diff --git a/spec/helpers/title_helper_spec.rb b/spec/helpers/title_helper_spec.rb index 82e11cb..f981b30 100644 --- a/spec/helpers/title_helper_spec.rb +++ b/spec/helpers/title_helper_spec.rb @@ -51,6 +51,15 @@ expect(helper.title(greeting: 'Hello')).to eq('Hello Caleb') end + it 'makes context safe to be used as interpolation options' do + stub_rails + stub_controller_and_action(:users, :show) + load_translations(users: { show: 'User' }) + allow(helper).to receive_message_chain(:controller, :view_assigns).and_return('scope' => 'Foo') + + expect(helper.title).to eq('User') + end + def stub_rails allow(helper).to receive(:controller_path).and_return('dashboards') allow(helper).to receive(:action_name)