summaryrefslogtreecommitdiff
path: root/spec/rubocop/cop/safe_params_spec.rb
blob: 4f02b8e9008e41c02ccc55086f663d895590264f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# frozen_string_literal: true

require 'spec_helper'
require 'rubocop'
require 'rubocop/rspec/support'
require_relative '../../../rubocop/cop/safe_params'

describe RuboCop::Cop::SafeParams do
  include CopHelper

  subject(:cop) { described_class.new }

  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