2019-12-04 21:07:31 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-06-17 06:08:43 +00:00
|
|
|
require 'fast_spec_helper'
|
2019-12-04 21:07:31 +00:00
|
|
|
require_relative '../../../rubocop/cop/put_group_routes_under_scope'
|
|
|
|
|
2021-01-07 18:10:38 +00:00
|
|
|
RSpec.describe RuboCop::Cop::PutGroupRoutesUnderScope do
|
2019-12-04 21:07:31 +00:00
|
|
|
subject(:cop) { described_class.new }
|
|
|
|
|
2020-07-23 18:10:06 +00:00
|
|
|
%w[resource resources get post put patch delete].each do |route_method|
|
|
|
|
it "registers an offense when route is outside scope for `#{route_method}`" do
|
|
|
|
offense = "#{route_method} :notes"
|
|
|
|
marker = '^' * offense.size
|
2019-12-04 21:07:31 +00:00
|
|
|
|
2020-07-23 18:10:06 +00:00
|
|
|
expect_offense(<<~PATTERN)
|
2021-02-17 21:09:06 +00:00
|
|
|
scope(path: 'groups/*group_id/-', module: :groups) do
|
|
|
|
resource :issues
|
|
|
|
end
|
2019-12-04 21:07:31 +00:00
|
|
|
|
2021-02-17 21:09:06 +00:00
|
|
|
#{offense}
|
|
|
|
#{marker} Put new group routes under /-/ scope
|
2020-07-23 18:10:06 +00:00
|
|
|
PATTERN
|
|
|
|
end
|
2019-12-04 21:07:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not register an offense when resource inside the scope' do
|
2020-05-28 21:08:22 +00:00
|
|
|
expect_no_offenses(<<~PATTERN)
|
2019-12-04 21:07:31 +00:00
|
|
|
scope(path: 'groups/*group_id/-', module: :groups) do
|
|
|
|
resource :issues
|
|
|
|
resource :notes
|
|
|
|
end
|
|
|
|
PATTERN
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not register an offense when resource is deep inside the scope' do
|
2020-05-28 21:08:22 +00:00
|
|
|
expect_no_offenses(<<~PATTERN)
|
2019-12-04 21:07:31 +00:00
|
|
|
scope(path: 'groups/*group_id/-', module: :groups) do
|
|
|
|
resource :issues
|
|
|
|
resource :projects do
|
|
|
|
resource :issues do
|
|
|
|
resource :notes
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
PATTERN
|
|
|
|
end
|
2020-09-02 12:10:35 +00:00
|
|
|
|
|
|
|
it 'does not register an offense for the root route' do
|
|
|
|
expect_no_offenses(<<~PATTERN)
|
|
|
|
get '/'
|
|
|
|
PATTERN
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not register an offense for the root route within scope' do
|
|
|
|
expect_no_offenses(<<~PATTERN)
|
|
|
|
scope(path: 'groups/*group_id/-', module: :groups) do
|
|
|
|
get '/'
|
|
|
|
end
|
|
|
|
PATTERN
|
|
|
|
end
|
2019-12-04 21:07:31 +00:00
|
|
|
end
|