Skip to content

Commit

Permalink
Merge be13d7c into 52c24d5
Browse files Browse the repository at this point in the history
  • Loading branch information
xymbol committed Jan 14, 2018
2 parents 52c24d5 + be13d7c commit aca6e74
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/helpers/title/title_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
9 changes: 9 additions & 0 deletions spec/helpers/title_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit aca6e74

Please sign in to comment.