-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): introduce MiddlewareCreator
- Loading branch information
Showing
3 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...t_service/core/entities/config/entities/method_middlewares/entities/middleware_creator.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# frozen_string_literal: true | ||
|
||
module ConvenientService | ||
module Core | ||
module Entities | ||
class Config | ||
module Entities | ||
class MethodMiddlewares | ||
module Entities | ||
class MiddlewareCreator | ||
## | ||
# @!attribute [r] middleware | ||
# @return [Class] | ||
# | ||
attr_reader :middleware | ||
|
||
## | ||
# @!attribute [r] arguments | ||
# @return [ConvenientService::Support::Arguments] | ||
# | ||
attr_reader :arguments | ||
|
||
## | ||
# @param middleware [Class] | ||
# @param arguments [ConvenientService::Support::Arguments] | ||
# @return [void] | ||
# | ||
def initialize(middleware:, arguments:) | ||
@middleware = middleware | ||
@arguments = arguments | ||
end | ||
|
||
## | ||
# @param other [Object] | ||
# @return [Boolean, nil] | ||
# | ||
def ==(other) | ||
return unless other.instance_of?(self.class) | ||
|
||
return false if middleware != other.middleware | ||
return false if arguments != other.arguments | ||
|
||
true | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
62 changes: 62 additions & 0 deletions
62
...vice/core/entities/config/entities/method_middlewares/entities/middleware_creator_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
require "convenient_service" | ||
|
||
# rubocop:disable RSpec/NestedGroups | ||
RSpec.describe ConvenientService::Core::Entities::Config::Entities::MethodMiddlewares::Entities::MiddlewareCreator do | ||
include ConvenientService::RSpec::Matchers::DelegateTo | ||
|
||
let(:middleware_creator) { described_class.new(middleware: middleware, arguments: arguments) } | ||
let(:middleware) { Class.new(ConvenientService::Core::Entities::Config::Entities::MethodMiddlewares::Entities::Middleware) } | ||
let(:arguments) { ConvenientService::Support::Arguments.new(:foo, foo: :bar) { :foo } } | ||
|
||
example_group "attributes" do | ||
include ConvenientService::RSpec::Matchers::HaveAttrReader | ||
|
||
subject { middleware_creator } | ||
|
||
it { is_expected.to have_attr_reader(:middleware) } | ||
it { is_expected.to have_attr_reader(:arguments) } | ||
end | ||
|
||
example_group "instance methods" do | ||
example_group "comparison" do | ||
describe "#==" do | ||
context "when `other` has different class" do | ||
let(:other) { 42 } | ||
|
||
it "returns `nil`" do | ||
expect(middleware_creator == other).to be_nil | ||
end | ||
end | ||
|
||
context "when `other` has different `middleware`" do | ||
let(:other) { described_class.new(middleware: Class.new(ConvenientService::Core::Entities::Config::Entities::MethodMiddlewares::Entities::Middleware), arguments: arguments) } | ||
|
||
it "returns `false`" do | ||
expect(middleware_creator == other).to eq(false) | ||
end | ||
end | ||
|
||
context "when `other` has different `arguments`" do | ||
let(:other) { described_class.new(middleware: middleware, arguments: ConvenientService::Support::Arguments.null_arguments) } | ||
|
||
it "returns `false`" do | ||
expect(middleware_creator == other).to eq(false) | ||
end | ||
end | ||
|
||
context "when `other` has same attributes" do | ||
let(:other) { described_class.new(middleware: middleware, arguments: arguments) } | ||
|
||
it "returns `true`" do | ||
expect(middleware_creator == other).to eq(true) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
# rubocop:enable RSpec/NestedGroups |