2018-11-15 04:50:04 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-08-18 14:10:07 -04:00
|
|
|
require 'rubocop_spec_helper'
|
2018-11-15 04:50:04 -05:00
|
|
|
require_relative '../../../rubocop/cop/safe_params'
|
|
|
|
|
2021-01-07 13:10:38 -05:00
|
|
|
RSpec.describe RuboCop::Cop::SafeParams do
|
2018-11-15 04:50:04 -05:00
|
|
|
it 'flags the params as an argument of url_for' do
|
|
|
|
expect_offense(<<~SOURCE)
|
|
|
|
url_for(params)
|
|
|
|
^^^^^^^^^^^^^^^ Use `safe_params` instead of `params` in url_for.
|
|
|
|
SOURCE
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'flags the merged params as an argument of url_for' do
|
|
|
|
expect_offense(<<~SOURCE)
|
|
|
|
url_for(params.merge(additional_params))
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `safe_params` instead of `params` in url_for.
|
|
|
|
SOURCE
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'flags the merged params arg as an argument of url_for' do
|
|
|
|
expect_offense(<<~SOURCE)
|
|
|
|
url_for(something.merge(additional).merge(params))
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `safe_params` instead of `params` in url_for.
|
|
|
|
SOURCE
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not flag other argument of url_for' do
|
|
|
|
expect_no_offenses(<<~SOURCE)
|
|
|
|
url_for(something)
|
|
|
|
SOURCE
|
|
|
|
end
|
|
|
|
end
|