2018-09-21 14:10:20 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-06-17 06:08:43 +00:00
|
|
|
require 'fast_spec_helper'
|
2018-09-21 14:10:20 +00:00
|
|
|
require 'rubocop'
|
|
|
|
require_relative '../../../rubocop/cop/avoid_route_redirect_leading_slash'
|
|
|
|
|
2020-06-24 06:09:01 +00:00
|
|
|
RSpec.describe RuboCop::Cop::AvoidRouteRedirectLeadingSlash, type: :rubocop do
|
2018-09-21 14:10:20 +00:00
|
|
|
include CopHelper
|
|
|
|
|
|
|
|
subject(:cop) { described_class.new }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(cop).to receive(:in_routes?).and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'registers an offense when redirect has a leading slash' do
|
2020-05-28 21:08:22 +00:00
|
|
|
expect_offense(<<~PATTERN)
|
2018-09-21 14:10:20 +00:00
|
|
|
root to: redirect("/-/route")
|
|
|
|
^^^^^^^^^^^^^^^^^^^^ Do not use a leading "/" in route redirects
|
|
|
|
PATTERN
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not register an offense when redirect does not have a leading slash' do
|
2020-05-28 21:08:22 +00:00
|
|
|
expect_no_offenses(<<~PATTERN)
|
2018-09-21 14:10:20 +00:00
|
|
|
root to: redirect("-/route")
|
|
|
|
PATTERN
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'autocorrect `/-/route` to `-/route`' do
|
|
|
|
expect(autocorrect_source('redirect("/-/route")')).to eq('redirect("-/route")')
|
|
|
|
end
|
|
|
|
end
|