2020-01-01 13:55:28 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
require 'rubocop_spec_helper'
|
2020-01-01 13:55:28 +05:30
|
|
|
require_relative '../../../rubocop/cop/put_group_routes_under_scope'
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
RSpec.describe RuboCop::Cop::PutGroupRoutesUnderScope do
|
2020-10-24 23:57:45 +05:30
|
|
|
%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
|
2020-01-01 13:55:28 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
expect_offense(<<~PATTERN)
|
2021-04-17 20:07:23 +05:30
|
|
|
scope(path: 'groups/*group_id/-', module: :groups) do
|
|
|
|
resource :issues
|
|
|
|
end
|
2020-01-01 13:55:28 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
#{offense}
|
|
|
|
#{marker} Put new group routes under /-/ scope
|
2020-10-24 23:57:45 +05:30
|
|
|
PATTERN
|
|
|
|
end
|
2020-01-01 13:55:28 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not register an offense when resource inside the scope' do
|
2020-06-23 00:09:42 +05:30
|
|
|
expect_no_offenses(<<~PATTERN)
|
2020-01-01 13:55:28 +05:30
|
|
|
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-06-23 00:09:42 +05:30
|
|
|
expect_no_offenses(<<~PATTERN)
|
2020-01-01 13:55:28 +05:30
|
|
|
scope(path: 'groups/*group_id/-', module: :groups) do
|
|
|
|
resource :issues
|
|
|
|
resource :projects do
|
|
|
|
resource :issues do
|
|
|
|
resource :notes
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
PATTERN
|
|
|
|
end
|
2020-11-24 15:15:51 +05:30
|
|
|
|
|
|
|
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
|
2020-01-01 13:55:28 +05:30
|
|
|
end
|