DEV: properly namespace chat (#20690)

This commit main goal was to comply with Zeitwerk and properly rely on autoloading. To achieve this, most resources have been namespaced under the `Chat` module.

- Given all models are now namespaced with `Chat::` and would change the stored types in DB when using polymorphism or STI (single table inheritance), this commit uses various Rails methods to ensure proper class is loaded and the stored name in DB is unchanged, eg: `Chat::Message` model will be stored as `"ChatMessage"`, and `"ChatMessage"` will correctly load `Chat::Message` model.
- Jobs are now using constants only, eg: `Jobs::Chat::Foo` and should only be enqueued this way

Notes:
- This commit also used this opportunity to limit the number of registered css files in plugin.rb
- `discourse_dev` support has been removed within this commit and will be reintroduced later

<!-- NOTE: All pull requests should have tests (rspec in Ruby, qunit in JavaScript). If your code does not include test coverage, please include an explanation of why it was omitted. -->
This commit is contained in:
Joffrey JAFFEUX
2023-03-17 14:24:38 +01:00
committed by GitHub
parent 74349e17c9
commit 12a18d4d55
343 changed files with 9077 additions and 8745 deletions

View File

@ -1,12 +1,12 @@
# frozen_string_literal: true
RSpec.describe Chat::ServiceRunner do
RSpec.describe ServiceRunner do
class SuccessService
include Chat::Service::Base
include Service::Base
end
class FailureService
include Chat::Service::Base
include Service::Base
step :fail_step
@ -16,7 +16,7 @@ RSpec.describe Chat::ServiceRunner do
end
class FailedPolicyService
include Chat::Service::Base
include Service::Base
policy :test
@ -26,7 +26,7 @@ RSpec.describe Chat::ServiceRunner do
end
class SuccessPolicyService
include Chat::Service::Base
include Service::Base
policy :test
@ -36,7 +36,7 @@ RSpec.describe Chat::ServiceRunner do
end
class FailedContractService
include Chat::Service::Base
include Service::Base
class Contract
attribute :test
@ -47,13 +47,13 @@ RSpec.describe Chat::ServiceRunner do
end
class SuccessContractService
include Chat::Service::Base
include Service::Base
contract
end
class FailureWithModelService
include Chat::Service::Base
include Service::Base
model :fake_model, :fetch_fake_model
@ -65,7 +65,7 @@ RSpec.describe Chat::ServiceRunner do
end
class SuccessWithModelService
include Chat::Service::Base
include Service::Base
model :fake_model, :fetch_fake_model
@ -77,7 +77,7 @@ RSpec.describe Chat::ServiceRunner do
end
class FailureWithCollectionModelService
include Chat::Service::Base
include Service::Base
model :fake_model, :fetch_fake_model
@ -89,7 +89,7 @@ RSpec.describe Chat::ServiceRunner do
end
class SuccessWithCollectionModelService
include Chat::Service::Base
include Service::Base
model :fake_model, :fetch_fake_model
@ -109,7 +109,7 @@ RSpec.describe Chat::ServiceRunner do
let(:actions) { "proc {}" }
let(:object) do
Class
.new(Chat::Api) do
.new(Chat::ApiController) do
def request
OpenStruct.new
end
@ -126,7 +126,7 @@ RSpec.describe Chat::ServiceRunner do
it "runs the provided service in the context of a controller" do
runner
expect(result).to be_a Chat::Service::Base::Context
expect(result).to be_a Service::Base::Context
expect(result).to be_a_success
end