0
0
Fork 0

Fix Lint/ConstantDefinitionInBlock cop (#24763)

This commit is contained in:
Matt Jankowski 2023-05-03 04:32:30 -04:00 committed by GitHub
parent 8b636a29c6
commit 3df665fd23
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 120 additions and 118 deletions

View file

@ -74,7 +74,11 @@ describe Api::BaseController do
end
describe 'error handling' do
ERRORS_WITH_CODES = {
before do
routes.draw { get 'error' => 'api/base#error' }
end
{
ActiveRecord::RecordInvalid => 422,
Mastodon::ValidationError => 422,
ActiveRecord::RecordNotFound => 404,
@ -82,13 +86,7 @@ describe Api::BaseController do
HTTP::Error => 503,
OpenSSL::SSL::SSLError => 503,
Mastodon::NotPermittedError => 403,
}
before do
routes.draw { get 'error' => 'api/base#error' }
end
ERRORS_WITH_CODES.each do |error, code|
}.each do |error, code|
it "Handles error class of #{error}" do
expect(FakeService).to receive(:new).and_raise(error)

View file

@ -223,14 +223,16 @@ describe ApplicationController, type: :controller do
end
describe 'cache_collection' do
class C < ApplicationController
public :cache_collection
subject do
Class.new(ApplicationController) do
public :cache_collection
end
end
shared_examples 'receives :with_includes' do |fabricator, klass|
it 'uses raw if it is not an ActiveRecord::Relation' do
record = Fabricate(fabricator)
expect(C.new.cache_collection([record], klass)).to eq [record]
expect(subject.new.cache_collection([record], klass)).to eq [record]
end
end
@ -241,13 +243,13 @@ describe ApplicationController, type: :controller do
record = Fabricate(fabricator)
relation = klass.none
allow(relation).to receive(:cache_ids).and_return([record])
expect(C.new.cache_collection(relation, klass)).to eq [record]
expect(subject.new.cache_collection(relation, klass)).to eq [record]
end
end
it 'returns raw unless class responds to :with_includes' do
raw = Object.new
expect(C.new.cache_collection(raw, Object)).to eq raw
expect(subject.new.cache_collection(raw, Object)).to eq raw
end
context 'Status' do

View file

@ -3,18 +3,20 @@
require 'rails_helper'
RSpec.describe AccountableConcern do
class Hoge
include AccountableConcern
attr_reader :current_account
let(:hoge_class) do
Class.new do
include AccountableConcern
attr_reader :current_account
def initialize(current_account)
@current_account = current_account
def initialize(current_account)
@current_account = current_account
end
end
end
let(:user) { Fabricate(:account) }
let(:target) { Fabricate(:account) }
let(:hoge) { Hoge.new(user) }
let(:hoge) { hoge_class.new(user) }
describe '#log_action' do
it 'creates Admin::ActionLog' do

View file

@ -3,14 +3,16 @@
require 'rails_helper'
describe ApplicationController, type: :controller do
class WrappedActor
attr_reader :wrapped_account
let(:wrapped_actor_class) do
Class.new do
attr_reader :wrapped_account
def initialize(wrapped_account)
@wrapped_account = wrapped_account
def initialize(wrapped_account)
@wrapped_account = wrapped_account
end
delegate :uri, :keypair, to: :wrapped_account
end
delegate :uri, :keypair, to: :wrapped_account
end
controller do
@ -93,7 +95,7 @@ describe ApplicationController, type: :controller do
end
context 'with a valid actor that is not an Account' do
let(:actor) { WrappedActor.new(author) }
let(:actor) { wrapped_actor_class.new(author) }
before do
get :success